PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.7.2
Post Views Counter v1.7.2
1.7.13 1.7.12 1.7.11 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.2 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.2.0 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3 1.3.1 1.3.10 1.3.11 1.3.12 1.3.13 1.3.2 1.3.2.1 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.7 1.4.8 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.5.9 1.6.0 1.6.1 1.7.0 1.7.1 1.7.10 1.7.2 1.7.3 1.7.4 1.7.5 1.7.6 1.7.7 1.7.8 1.7.9
post-views-counter / includes / class-integrations.php
post-views-counter / includes Last commit date
class-admin.php 5 months ago class-columns.php 5 months ago class-counter.php 5 months ago class-crawler-detect.php 5 months ago class-cron.php 5 months ago class-dashboard.php 5 months ago class-frontend.php 5 months ago class-functions.php 5 months ago class-import.php 5 months ago class-integration-gutenberg.php 5 months ago class-integrations.php 5 months ago class-query.php 5 months ago class-settings-api.php 5 months ago class-settings-display.php 5 months ago class-settings-general.php 5 months ago class-settings-integrations.php 5 months ago class-settings-other.php 5 months ago class-settings-reports.php 5 months ago class-settings.php 5 months ago class-toolbar.php 5 months ago class-update.php 5 months ago class-widgets.php 5 months ago functions.php 5 months ago
class-integrations.php
287 lines
1 <?php
2 // exit if accessed directly
3 if ( ! defined( 'ABSPATH' ) )
4 exit;
5
6 /**
7 * Post_Views_Counter_Integrations class.
8 *
9 * Handles loading and management of integrations.
10 *
11 * @class Post_Views_Counter_Integrations
12 */
13 class Post_Views_Counter_Integrations {
14
15 /**
16 * Get all integrations with their definitions and effective status.
17 *
18 * @return array
19 */
20 public static function get_integrations() {
21 // get main instance
22 $pvc = Post_Views_Counter();
23
24 // get saved statuses
25 $saved_statuses = isset( $pvc->options['integrations']['integrations'] ) ? $pvc->options['integrations']['integrations'] : [];
26
27 // base integrations
28 $integrations = self::get_base_integrations();
29
30 // allow filtering
31 $integrations = apply_filters( 'pvc_integrations', $integrations );
32
33 // compute effective status for each
34 foreach ( $integrations as $slug => &$integration ) {
35 $pro_active = ! ( isset( $integration['pro'] ) && $integration['pro'] ) || class_exists( 'Post_Views_Counter_Pro' );
36 $available = self::is_integration_available( $integration );
37 $saved_status = isset( $saved_statuses[$slug] ) ? (bool) $saved_statuses[$slug] : null;
38
39 // default status: saved if set, otherwise true
40 $default_status = $saved_status === null ? true : $saved_status;
41
42 // effective status: available and enabled_check result
43 $enabled_check = isset( $integration['enabled_check'] ) && is_callable( $integration['enabled_check'] )
44 ? $integration['enabled_check']
45 : function( $default_status, $integration, $slug, $saved_status ) { return $default_status; };
46
47 $integration['pro_active'] = $pro_active;
48 $integration['status'] = $available && $pro_active && call_user_func( $enabled_check, $default_status, $integration, $slug, $saved_status );
49 $integration['availability'] = $available;
50 }
51
52 return $integrations;
53 }
54
55 /**
56 * Check if a specific integration is effectively enabled.
57 *
58 * @param string $slug
59 * @return bool
60 */
61 public static function is_integration_enabled( $slug ) {
62 $integrations = self::get_integrations();
63 return isset( $integrations[$slug]['status'] ) ? $integrations[$slug]['status'] : false;
64 }
65
66 /**
67 * Get the status of a specific integration.
68 *
69 * @param string $slug
70 * @return bool
71 */
72 public static function get_integration_status( $slug ) {
73 return self::is_integration_enabled( $slug );
74 }
75
76 /**
77 * Check if an integration is available based on its availability_check.
78 *
79 * @param array $integration
80 * @return bool
81 */
82 private static function is_integration_available( $integration ) {
83 if ( ! isset( $integration['availability_check'] ) )
84 return false;
85
86 if ( is_callable( $integration['availability_check'] ) )
87 return call_user_func( $integration['availability_check'] );
88
89 return false;
90 }
91
92 /**
93 * Get base integrations definitions.
94 *
95 * @return array
96 */
97 public static function get_base_integrations() {
98 return [
99 'gutenberg' => [
100 'name' => 'Gutenberg',
101 'description' => __( 'Integrate with WordPress block editor to order posts by views in Query Loop and Latest Posts blocks.', 'post-views-counter' ),
102 'menu_order' => 5,
103 'pro' => false,
104 'availability_check' => function() { return function_exists( 'register_block_type' ); },
105 'enabled_check' => function( $default_status, $integration, $slug, $saved_status ) { return $default_status; },
106 'items' => [
107 [
108 'name' => __( 'Query Loop Block', 'post-views-counter' ),
109 'description' => __( 'Enables ordering posts by view count in the core Query Loop block.', 'post-views-counter' ),
110 'status' => true
111 ],
112 [
113 'name' => __( 'Latest Posts Block', 'post-views-counter' ),
114 'description' => __( 'Enables ordering posts by view count in the core Latest Posts block.', 'post-views-counter' ),
115 'status' => true
116 ]
117 ]
118 ],
119 'amp' => [
120 'name' => 'AMP',
121 'description' => __( 'Integrate with AMP plugin to handle post views on AMP pages.', 'post-views-counter' ),
122 'menu_order' => 20,
123 'pro' => true,
124 'availability_check' => function() { return function_exists( 'amp_is_request' ); },
125 'enabled_check' => function( $default_status, $integration, $slug, $saved_status ) { return $default_status; },
126 'items' => [
127 [
128 'name' => __( 'AMP Support', 'post-views-counter' ),
129 'description' => __( 'Tracks and displays views on AMP-enabled pages.', 'post-views-counter' ),
130 'status' => true
131 ]
132 ]
133 ],
134 'beaver-builder' => [
135 'name' => 'Beaver Builder',
136 'description' => __( 'Integrate with Beaver Builder to order module posts by views.', 'post-views-counter' ),
137 'menu_order' => 20,
138 'pro' => true,
139 'availability_check' => function() { return class_exists( 'FLBuilder' ); },
140 'enabled_check' => function( $default_status, $integration, $slug, $saved_status ) { return $default_status; },
141 'items' => [
142 [
143 'name' => __( 'Post Grid Module', 'post-views-counter' ),
144 'description' => __( 'Orders posts by views in the Beaver Builder Post Grid module.', 'post-views-counter' ),
145 'status' => true
146 ],
147 [
148 'name' => __( 'Post Carousel Module', 'post-views-counter' ),
149 'description' => __( 'Orders posts by views in the Beaver Builder Post Carousel module.', 'post-views-counter' ),
150 'status' => true
151 ],
152 [
153 'name' => __( 'Post Slider Module', 'post-views-counter' ),
154 'description' => __( 'Orders posts by views in the Beaver Builder Post Slider module.', 'post-views-counter' ),
155 'status' => true
156 ]
157 ]
158 ],
159 'divi' => [
160 'name' => 'Divi',
161 'description' => __( 'Integrate with Divi Theme to order module posts by views when the module uses the "orderby-post-views" CSS class.', 'post-views-counter' ),
162 'menu_order' => 20,
163 'pro' => true,
164 'availability_check' => function() { return defined( 'ET_CORE_VERSION' ); },
165 'enabled_check' => function( $default_status, $integration, $slug, $saved_status ) { return $default_status; },
166 'items' => [
167 [
168 'name' => __( 'Blog Module', 'post-views-counter' ),
169 'description' => __( 'Orders posts by views in the Divi Blog module.', 'post-views-counter' ),
170 'status' => true
171 ],
172 [
173 'name' => __( 'Post Slider Module', 'post-views-counter' ),
174 'description' => __( 'Orders posts by views in the Divi Post Slider module.', 'post-views-counter' ),
175 'status' => true
176 ],
177 [
178 'name' => __( 'Portfolio Module', 'post-views-counter' ),
179 'description' => __( 'Orders posts by views in the Divi Portfolio module.', 'post-views-counter' ),
180 'status' => true
181 ]
182 ]
183 ],
184 'elementor-pro' => [
185 'name' => 'Elementor Pro',
186 'description' => __( 'Integrate with Elementor Pro to order posts by views when a widget query uses the "post_views" Query ID.', 'post-views-counter' ),
187 'menu_order' => 20,
188 'pro' => true,
189 'availability_check' => function() { return defined( 'ELEMENTOR_PRO_VERSION' ); },
190 'enabled_check' => function( $default_status, $integration, $slug, $saved_status ) { return $default_status; },
191 'items' => [
192 [
193 'name' => __( 'Posts Widget', 'post-views-counter' ),
194 'description' => __( 'Orders posts by views in the Elementor Pro Posts widget when its Query ID is set to "post_views".', 'post-views-counter' ),
195 'status' => true
196 ],
197 [
198 'name' => __( 'Portfolio Widget', 'post-views-counter' ),
199 'description' => __( 'Orders items by views in the Elementor Pro Portfolio widget when its Query ID is set to "post_views".', 'post-views-counter' ),
200 'status' => true
201 ],
202 [
203 'name' => __( 'Loop Grid / Loop Carousel', 'post-views-counter' ),
204 'description' => __( 'Orders items by views in the Elementor Pro Loop Grid and Loop Carousel widgets when the Query ID is set to "post_views".', 'post-views-counter' ),
205 'status' => true
206 ]
207 ]
208 ],
209 'generateblocks' => [
210 'name' => 'GenerateBlocks',
211 'description' => __( 'Integrate with GenerateBlocks to order Query block results by views.', 'post-views-counter' ),
212 'menu_order' => 20,
213 'pro' => true,
214 'availability_check' => function() { return defined( 'GENERATEBLOCKS_VERSION' ); },
215 'enabled_check' => function( $default_status, $integration, $slug, $saved_status ) { return $default_status; },
216 'items' => [
217 [
218 'name' => __( 'Dynamic Content', 'post-views-counter' ),
219 'description' => __( 'Adds post_views ordering to the GenerateBlocks Query block.', 'post-views-counter' ),
220 'status' => true
221 ]
222 ]
223 ],
224 'jet-engine' => [
225 'name' => 'JetEngine',
226 'description' => __( 'Integrate with JetEngine plugin to display post views in custom listings and queries.', 'post-views-counter' ),
227 'menu_order' => 20,
228 'pro' => true,
229 'availability_check' => function() { return class_exists( 'Jet_Engine' ); },
230 'enabled_check' => function( $default_status, $integration, $slug, $saved_status ) { return $default_status; },
231 'items' => [
232 [
233 'name' => __( 'Query Builder', 'post-views-counter' ),
234 'description' => __( 'Enables ordering posts by view count in Query Builder posts queries.', 'post-views-counter' ),
235 'status' => true
236 ],
237 [
238 'name' => __( 'Listing Grid', 'post-views-counter' ),
239 'description' => __( 'Enables ordering posts by view count in Listing Grid, Maps Listing and Calendar widgets.', 'post-views-counter' ),
240 'status' => true
241 ]
242 ]
243 ],
244 'polylang' => [
245 'name' => 'Polylang',
246 'description' => __( 'Integrate with Polylang to filter reports, exports, and dashboard widgets by language.', 'post-views-counter' ),
247 'menu_order' => 20,
248 'pro' => true,
249 'availability_check' => function() { return function_exists( 'pll_languages_list' ) || class_exists( 'Polylang' ); },
250 'enabled_check' => function( $default_status, $integration, $slug, $saved_status ) { return $default_status; },
251 'items' => [
252 [
253 'name' => __( 'Reports Language Filters', 'post-views-counter' ),
254 'description' => __( 'Adds language filtering and a language column to Reports tables, charts, and exports.', 'post-views-counter' ),
255 'status' => true
256 ],
257 [
258 'name' => __( 'Dashboard Widgets', 'post-views-counter' ),
259 'description' => __( 'Filters dashboard widgets (site, post, and term views) by the selected language.', 'post-views-counter' ),
260 'status' => true
261 ]
262 ]
263 ],
264 'wpml' => [
265 'name' => 'WPML',
266 'description' => __( 'Integrate with WPML to filter reports, exports, and dashboard widgets by language.', 'post-views-counter' ),
267 'menu_order' => 20,
268 'pro' => true,
269 'availability_check' => function() { return defined( 'WPML_PLUGIN_FILE' ) || class_exists( 'SitePress' ); },
270 'enabled_check' => function( $default_status, $integration, $slug, $saved_status ) { return $default_status; },
271 'items' => [
272 [
273 'name' => __( 'Reports Language Filters', 'post-views-counter' ),
274 'description' => __( 'Adds language filtering and a language column to Reports tables, charts, and exports.', 'post-views-counter' ),
275 'status' => true
276 ],
277 [
278 'name' => __( 'Dashboard Widgets', 'post-views-counter' ),
279 'description' => __( 'Filters dashboard widgets (site, post, and term views) by the selected language.', 'post-views-counter' ),
280 'status' => true
281 ]
282 ]
283 ]
284 ];
285 }
286 }
287