PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.3.7
Post Views Counter v1.3.7
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 / post-views-counter.php
post-views-counter Last commit date
assets 4 years ago css 4 years ago includes 4 years ago js 4 years ago languages 4 years ago index.php 6 years ago post-views-counter.php 4 years ago readme.txt 4 years ago
post-views-counter.php
699 lines
1 <?php
2 /*
3 Plugin Name: Post Views Counter
4 Description: Post Views Counter allows you to display how many times a post, page or custom post type had been viewed in a simple, fast and reliable way.
5 Version: 1.3.7
6 Author: Digital Factory
7 Author URI: http://www.dfactory.eu/
8 Plugin URI: http://www.dfactory.eu/plugins/post-views-counter/
9 License: MIT License
10 License URI: http://opensource.org/licenses/MIT
11 Text Domain: post-views-counter
12 Domain Path: /languages
13
14 Post Views Counter
15 Copyright (C) 2014-2021, Digital Factory - info@digitalfactory.pl
16
17 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
18
19 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24 // exit if accessed directly
25 if ( ! defined( 'ABSPATH' ) )
26 exit;
27
28 if ( ! class_exists( 'Post_Views_Counter' ) ) :
29
30 /**
31 * Post Views Counter final class.
32 *
33 * @class Post_Views_Counter
34 * @version 1.3.7
35 */
36 final class Post_Views_Counter {
37
38 private static $instance;
39 public $options;
40 public $defaults = [
41 'general' => [
42 'post_types_count' => [ 'post' ],
43 'counter_mode' => 'php',
44 'post_views_column' => true,
45 'restrict_edit_views' => false,
46 'time_between_counts' => [
47 'number' => 24,
48 'type' => 'hours'
49 ],
50 'reset_counts' => [
51 'number' => 30,
52 'type' => 'days'
53 ],
54 'flush_interval' => [
55 'number' => 0,
56 'type' => 'minutes'
57 ],
58 'exclude' => [
59 'groups' => [],
60 'roles' => []
61 ],
62 'exclude_ips' => [],
63 'strict_counts' => false,
64 'deactivation_delete' => false,
65 'cron_run' => true,
66 'cron_update' => true,
67 'update_version' => 1,
68 'update_notice' => true,
69 'update_delay_date' => 0
70 ],
71 'display' => [
72 'label' => 'Post Views:',
73 'post_types_display' => [ 'post' ],
74 'page_types_display' => [ 'singular' ],
75 'restrict_display' => [
76 'groups' => [],
77 'roles' => []
78 ],
79 'position' => 'after',
80 'display_style' => [
81 'icon' => true,
82 'text' => true
83 ],
84 'icon_class' => 'dashicons-chart-bar',
85 'toolbar_statistics' => true
86 ],
87 'version' => '1.3.7'
88 ];
89
90 /**
91 * Disable object cloning.
92 *
93 * @return void
94 */
95 public function __clone() {}
96
97 /**
98 * Disable unserializing of the class.
99 *
100 * @return void
101 */
102 public function __wakeup() {}
103
104 /**
105 * Main plugin instance,
106 * Insures that only one instance of the plugin exists in memory at one time.
107 *
108 * @return object
109 */
110 public static function instance() {
111 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Post_Views_Counter ) ) {
112 self::$instance = new Post_Views_Counter;
113 self::$instance->define_constants();
114
115 // minimal setup for Fast AJAX
116 if ( defined( 'SHORTINIT' ) && SHORTINIT ) {
117 include_once( POST_VIEWS_COUNTER_PATH . 'includes/counter.php' );
118 include_once( POST_VIEWS_COUNTER_PATH . 'includes/crawler-detect.php' );
119 include_once( POST_VIEWS_COUNTER_PATH . 'includes/functions.php' );
120
121 self::$instance->counter = new Post_Views_Counter_Counter();
122 self::$instance->crawler_detect = new Post_Views_Counter_Crawler_Detect();
123 // regular setup
124 } else {
125 add_action( 'plugins_loaded', [ self::$instance, 'load_textdomain' ] );
126
127 self::$instance->includes();
128
129 // create settings API
130 self::$instance->settings_api = new Post_Views_Counter_Settings_API(
131 [
132 'object' => self::$instance,
133 'prefix' => 'post_views_counter',
134 'slug' => 'post-views-counter',
135 'domain' => 'post-views-counter',
136 'plugin' => 'Post Views Counter',
137 'plugin_url' => 'POST_VIEWS_COUNTER_URL'
138 ]
139 );
140
141 self::$instance->update = new Post_Views_Counter_Update();
142 self::$instance->settings = new Post_Views_Counter_Settings();
143 self::$instance->query = new Post_Views_Counter_Query();
144 self::$instance->cron = new Post_Views_Counter_Cron();
145 self::$instance->counter = new Post_Views_Counter_Counter();
146 self::$instance->columns = new Post_Views_Counter_Columns();
147 self::$instance->crawler_detect = new Post_Views_Counter_Crawler_Detect();
148 self::$instance->frontend = new Post_Views_Counter_Frontend();
149 self::$instance->dashboard = new Post_Views_Counter_Dashboard();
150 self::$instance->widgets = new Post_Views_Counter_Widgets();
151 }
152 }
153
154 return self::$instance;
155 }
156
157 /**
158 * Setup plugin constants.
159 *
160 * @return void
161 */
162 private function define_constants() {
163 // fix plugin_basename empty $wp_plugin_paths var
164 if ( ! ( defined( 'SHORTINIT' ) && SHORTINIT ) ) {
165 define( 'POST_VIEWS_COUNTER_URL', plugins_url( '', __FILE__ ) );
166 define( 'POST_VIEWS_COUNTER_REL_PATH', dirname( plugin_basename( __FILE__ ) ) . '/' );
167 }
168
169 define( 'POST_VIEWS_COUNTER_PATH', plugin_dir_path( __FILE__ ) );
170 }
171
172 /**
173 * Include required files.
174 *
175 * @return void
176 */
177 private function includes() {
178 include_once( POST_VIEWS_COUNTER_PATH . 'includes/update.php' );
179 include_once( POST_VIEWS_COUNTER_PATH . 'includes/settings-api.php' );
180 include_once( POST_VIEWS_COUNTER_PATH . 'includes/settings.php' );
181 include_once( POST_VIEWS_COUNTER_PATH . 'includes/columns.php' );
182 include_once( POST_VIEWS_COUNTER_PATH . 'includes/query.php' );
183 include_once( POST_VIEWS_COUNTER_PATH . 'includes/cron.php' );
184 include_once( POST_VIEWS_COUNTER_PATH . 'includes/counter.php' );
185 include_once( POST_VIEWS_COUNTER_PATH . 'includes/crawler-detect.php' );
186 include_once( POST_VIEWS_COUNTER_PATH . 'includes/frontend.php' );
187 include_once( POST_VIEWS_COUNTER_PATH . 'includes/dashboard.php' );
188 include_once( POST_VIEWS_COUNTER_PATH . 'includes/widgets.php' );
189 }
190
191 /**
192 * Class constructor.
193 *
194 * @return void
195 */
196 public function __construct() {
197 if ( defined( 'SHORTINIT' ) && SHORTINIT ) {
198 $this->options = [
199 'general' => array_merge( $this->defaults['general'], get_option( 'post_views_counter_settings_general', $this->defaults['general'] ) ),
200 'display' => array_merge( $this->defaults['display'], get_option( 'post_views_counter_settings_display', $this->defaults['display'] ) )
201 ];
202 } else {
203 register_activation_hook( __FILE__, [ $this, 'multisite_activation' ] );
204 register_deactivation_hook( __FILE__, [ $this, 'multisite_deactivation' ] );
205
206 // settings
207 $this->options = [
208 'general' => array_merge( $this->defaults['general'], get_option( 'post_views_counter_settings_general', $this->defaults['general'] ) ),
209 'display' => array_merge( $this->defaults['display'], get_option( 'post_views_counter_settings_display', $this->defaults['display'] ) )
210 ];
211
212 // actions
213 add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
214 add_action( 'wp_loaded', [ $this, 'load_pluggable_functions' ], 10 );
215 // add_action( 'init', [ $this, 'gutenberg_blocks' ] );
216 add_action( 'admin_init', [ $this, 'update_notice' ] );
217 add_action( 'wp_ajax_pvc_dismiss_notice', [ $this, 'dismiss_notice' ] );
218
219 // filters
220 add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 2 );
221 add_filter( 'plugin_action_links', [ $this, 'plugin_action_links' ], 10, 2 );
222 }
223 }
224
225 /**
226 * Update notice.
227 *
228 * @return void
229 */
230 public function update_notice() {
231 if ( ! current_user_can( 'install_plugins' ) )
232 return;
233
234 $current_update = 2;
235
236 // get current time
237 $current_time = time();
238
239 if ( $this->options['general']['update_version'] < $current_update ) {
240 // check version, if update version is lower than plugin version, set update notice to true
241 $this->options['general'] = array_merge(
242 $this->options['general'],
243 [
244 'update_version' => $current_update,
245 'update_notice' => true
246 ]
247 );
248
249 update_option( 'post_views_counter_settings_general', $this->options['general'] );
250
251 // set activation date
252 $activation_date = get_option( 'post_views_counter_activation_date' );
253
254 if ( $activation_date === false )
255 update_option( 'post_views_counter_activation_date', $current_time );
256 }
257
258 // display current version notice
259 if ( $this->options['general']['update_notice'] === true ) {
260 // include notice js, only if needed
261 add_action( 'admin_print_scripts', [ $this, 'admin_inline_js' ], 999 );
262
263 // get activation date
264 $activation_date = get_option( 'post_views_counter_activation_date' );
265
266 if ( (int) $this->options['general']['update_delay_date'] === 0 ) {
267 if ( $activation_date + 1209600 > $current_time )
268 $this->options['general']['update_delay_date'] = $activation_date + 1209600;
269 else
270 $this->options['general']['update_delay_date'] = $current_time;
271
272 update_option( 'post_views_counter_settings_general', $this->options['general'] );
273 }
274
275 if ( ( ! empty( $this->options['general']['update_delay_date'] ) ? (int) $this->options['general']['update_delay_date'] : $current_time ) <= $current_time )
276 $this->add_notice( sprintf( __( "Hey, you've been using <strong>Post Views Counter</strong> for more than %s.", 'post-views-counter' ), human_time_diff( $activation_date, $current_time ) ) . '<br />' . __( 'Could you please do me a BIG favor and give it a 5-star rating on WordPress to help us spread the word and boost our motivation.', 'post-views-counter' ) . '<br /><br />' . __( 'Your help is much appreciated. Thank you very much', 'post-views-counter' ) . ' ~ <strong>Bartosz Arendt</strong>, ' . sprintf( __( 'founder of <a href="%s" target="_blank">dFactory</a> plugins.', 'post-views-counter' ), 'https://dfactory.eu/' ) . '<br /><br />' . sprintf( __( '<a href="%s" class="pvc-dismissible-notice" target="_blank" rel="noopener">Ok, you deserve it</a><br /><a href="javascript:void(0);" class="pvc-dismissible-notice pvc-delay-notice" rel="noopener">Nope, maybe later</a><br /><a href="javascript:void(0);" class="pvc-dismissible-notice" rel="noopener">I already did</a>', 'post-views-counter' ), 'https://wordpress.org/support/plugin/post-views-counter/reviews/?filter=5#new-post' ), 'notice notice-info is-dismissible pvc-notice' );
277 }
278 }
279
280 /**
281 * Add admin notices.
282 *
283 * @param string $html
284 * @param string $status
285 * @param bool $paragraph
286 * @return void
287 */
288 public function add_notice( $html = '', $status = 'error', $paragraph = true ) {
289 $this->notices[] = [
290 'html' => $html,
291 'status' => $status,
292 'paragraph' => $paragraph
293 ];
294
295 add_action( 'admin_notices', [ $this, 'display_notice' ] );
296 }
297
298 /**
299 * Print admin notices.
300 *
301 * @return void
302 */
303 public function display_notice() {
304 foreach( $this->notices as $notice ) {
305 echo '
306 <div class="' . $notice['status'] . '">
307 ' . ( $notice['paragraph'] ? '<p>' : '' ) . '
308 ' . $notice['html'] . '
309 ' . ( $notice['paragraph'] ? '</p>' : '' ) . '
310 </div>';
311 }
312 }
313
314 /**
315 * Print admin scripts.
316 *
317 * @return void
318 */
319 public function admin_inline_js() {
320 if ( ! current_user_can( 'install_plugins' ) )
321 return;
322 ?>
323 <script type="text/javascript">
324 ( function ( $ ) {
325 $( document ).ready( function () {
326 // save dismiss state
327 $( '.pvc-notice.is-dismissible' ).on( 'click', '.notice-dismiss, .pvc-dismissible-notice', function ( e ) {
328 var notice_action = 'hide';
329
330 if ( $( e.currentTarget ).hasClass( 'pvc-delay-notice' ) ) {
331 notice_action = 'delay'
332 }
333
334 $.post( ajaxurl, {
335 action: 'pvc_dismiss_notice',
336 notice_action: notice_action,
337 url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
338 nonce: '<?php echo wp_create_nonce( 'pvc_dismiss_notice' ); ?>'
339 } );
340
341 $( e.delegateTarget ).slideUp( 'fast' );
342 } );
343 } );
344 } )( jQuery );
345 </script>
346 <?php
347 }
348
349 /**
350 * Dismiss notice.
351 *
352 * @return void
353 */
354 public function dismiss_notice() {
355 if ( ! current_user_can( 'install_plugins' ) )
356 return;
357
358 if ( wp_verify_nonce( esc_attr( $_REQUEST['nonce'] ), 'pvc_dismiss_notice' ) ) {
359 $notice_action = empty( $_REQUEST['notice_action'] ) || $_REQUEST['notice_action'] === 'hide' ? 'hide' : esc_attr( $_REQUEST['notice_action'] );
360
361 switch ( $notice_action ) {
362 // delay notice
363 case 'delay':
364 // set delay period to 1 week from now
365 $this->options['general'] = array_merge(
366 $this->options['general'],
367 [
368 'update_delay_date' => time() + 1209600
369 ]
370 );
371 update_option( 'post_views_counter_settings_general', $this->options['general'] );
372 break;
373
374 // hide notice
375 default:
376 $this->options['general'] = array_merge(
377 $this->options['general'],
378 [
379 'update_notice' => false
380 ]
381 );
382 $this->options['general'] = array_merge(
383 $this->options['general'],
384 [
385 'update_delay_date' => 0
386 ]
387 );
388
389 update_option( 'post_views_counter_settings_general', $this->options['general'] );
390 }
391 }
392
393 exit;
394 }
395
396 /**
397 * Multisite activation.
398 *
399 * @global object $wpdb
400 * @param bool $networkwide
401 * @return void
402 */
403 public function multisite_activation( $networkwide ) {
404 if ( is_multisite() && $networkwide ) {
405 global $wpdb;
406
407 $activated_blogs = [];
408 $current_blog_id = $wpdb->blogid;
409 $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) );
410
411 foreach ( $blogs_ids as $blog_id ) {
412 switch_to_blog( $blog_id );
413 $this->activate_single();
414 $activated_blogs[] = (int) $blog_id;
415 }
416
417 switch_to_blog( $current_blog_id );
418 update_site_option( 'post_views_counter_activated_blogs', $activated_blogs, [] );
419 } else
420 $this->activate_single();
421 }
422
423 /**
424 * Single site activation.
425 *
426 * @global array $wp_roles
427 * @return void
428 */
429 public function activate_single() {
430 global $wpdb, $charset_collate;
431
432 // required for dbdelta
433 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
434
435 // create post views table
436 dbDelta( '
437 CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'post_views (
438 id bigint unsigned NOT NULL,
439 type tinyint(1) unsigned NOT NULL,
440 period varchar(8) NOT NULL,
441 count bigint unsigned NOT NULL,
442 PRIMARY KEY (type, period, id),
443 UNIQUE INDEX id_type_period_count (id, type, period, count) USING BTREE,
444 INDEX type_period_count (type, period, count) USING BTREE
445 ) ' . $charset_collate . ';'
446 );
447
448 // add default options
449 add_option( 'post_views_counter_settings_general', $this->defaults['general'], '', 'no' );
450 add_option( 'post_views_counter_settings_display', $this->defaults['display'], '', 'no' );
451 add_option( 'post_views_counter_version', $this->defaults['version'], '', 'no' );
452
453 // schedule cache flush
454 $this->schedule_cache_flush();
455 }
456
457 /**
458 * Multisite deactivation.
459 *
460 * @global array $wpdb
461 * @param bool $networkwide
462 * @return void
463 */
464 public function multisite_deactivation( $networkwide ) {
465 if ( is_multisite() && $networkwide ) {
466 global $wpdb;
467
468 $current_blog_id = $wpdb->blogid;
469 $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) );
470
471 if ( ! ( $activated_blogs = get_site_option( 'post_views_counter_activated_blogs', false, false ) ) )
472 $activated_blogs = [];
473
474 foreach ( $blogs_ids as $blog_id ) {
475 switch_to_blog( $blog_id );
476 $this->deactivate_single( true );
477
478 if ( in_array( (int) $blog_id, $activated_blogs, true ) )
479 unset( $activated_blogs[array_search( $blog_id, $activated_blogs )] );
480 }
481
482 switch_to_blog( $current_blog_id );
483 update_site_option( 'post_views_counter_activated_blogs', $activated_blogs );
484 } else
485 $this->deactivate_single();
486 }
487
488 /**
489 * Single site deactivation.
490 *
491 * @global array $wp_roles
492 * @param bool $multi
493 * @return void
494 */
495 public function deactivate_single( $multi = false ) {
496 if ( $multi ) {
497 $options = get_option( 'post_views_counter_settings_general' );
498 $check = $options['deactivation_delete'];
499 } else
500 $check = $this->options['general']['deactivation_delete'];
501
502 // delete default options
503 if ( $check ) {
504 delete_option( 'post_views_counter_settings_general' );
505 delete_option( 'post_views_counter_settings_display' );
506
507 global $wpdb;
508
509 // delete table from database
510 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post_views' );
511 }
512
513 // remove schedule
514 wp_clear_scheduled_hook( 'pvc_reset_counts' );
515 remove_action( 'pvc_reset_counts', [ Post_Views_Counter()->cron, 'reset_counts' ] );
516
517 $this->remove_cache_flush();
518 }
519
520 /**
521 * Schedule cache flushing if it's not already scheduled.
522 *
523 * @param bool $forced
524 * @return void
525 */
526 public function schedule_cache_flush( $forced = true ) {
527 if ( $forced || ! wp_next_scheduled( 'pvc_flush_cached_counts' ) )
528 wp_schedule_event( time(), 'post_views_counter_flush_interval', 'pvc_flush_cached_counts' );
529 }
530
531 /**
532 * Remove scheduled cache flush and the corresponding action.
533 *
534 * @return void
535 */
536 public function remove_cache_flush() {
537 wp_clear_scheduled_hook( 'pvc_flush_cached_counts' );
538 remove_action( 'pvc_flush_cached_counts', [ Post_Views_Counter()->cron, 'flush_cached_counts' ] );
539 }
540
541 /**
542 * Load text domain..
543 *
544 * @return void
545 */
546 public function load_textdomain() {
547 load_plugin_textdomain( 'post-views-counter', false, POST_VIEWS_COUNTER_REL_PATH . 'languages/' );
548 }
549
550 /**
551 * Load pluggable template functions..
552 *
553 * @return void
554 */
555 public function load_pluggable_functions() {
556 include_once( POST_VIEWS_COUNTER_PATH . 'includes/functions.php' );
557 }
558
559 /**
560 * Add Gutenberg blocks..
561 *
562 * @return void
563 */
564 public function gutenberg_blocks() {
565 wp_register_script( 'pvc-admin-block-views', POST_VIEWS_COUNTER_URL . '/js/admin-block.js', [ 'wp-blocks', 'wp-element', 'wp-i18n' ] );
566
567 register_block_type( 'post-views-counter/views', [ 'editor_script' => 'pvc-admin-block-views' ] );
568 }
569
570 /**
571 * Enqueue admin scripts and styles.
572 *
573 * @global string $post_type
574 * @param string $page.
575 * @return void
576 */
577 public function admin_enqueue_scripts( $page ) {
578 wp_register_style( 'pvc-admin', POST_VIEWS_COUNTER_URL . '/css/admin.css' );
579
580 wp_register_script( 'pvc-admin-settings', POST_VIEWS_COUNTER_URL . '/js/admin-settings.js', [ 'jquery' ], $this->defaults['version'] );
581 wp_register_script( 'pvc-admin-post', POST_VIEWS_COUNTER_URL . '/js/admin-post.js', [ 'jquery' ], $this->defaults['version'] );
582 wp_register_script( 'pvc-admin-quick-edit', POST_VIEWS_COUNTER_URL . '/js/admin-quick-edit.js', [ 'jquery', 'inline-edit-post' ], $this->defaults['version'] );
583
584 // load on PVC settings page
585 if ( $page === 'settings_page_post-views-counter' ) {
586 wp_enqueue_script( 'pvc-admin-settings' );
587
588 wp_localize_script(
589 'pvc-admin-settings', 'pvcArgsSettings', [
590 'resetToDefaults' => __( 'Are you sure you want to reset these settings to defaults?', 'post-views-counter' ),
591 'resetViews' => __( 'Are you sure you want to delete all existing data?', 'post-views-counter' )
592 ]
593 );
594
595 wp_enqueue_style( 'pvc-admin' );
596
597 // load on single post page
598 } elseif ( $page === 'post.php' || $page === 'post-new.php' ) {
599 $post_types = Post_Views_Counter()->options['general']['post_types_count'];
600
601 global $post_type;
602
603 if ( ! in_array( $post_type, (array) $post_types ) )
604 return;
605
606 wp_enqueue_style( 'pvc-admin' );
607 wp_enqueue_script( 'pvc-admin-post' );
608 // edit post
609 } elseif ( $page === 'edit.php' ) {
610 $post_types = Post_Views_Counter()->options['general']['post_types_count'];
611
612 global $post_type;
613
614 if ( ! in_array( $post_type, (array) $post_types ) )
615 return;
616
617 wp_enqueue_style( 'pvc-admin' );
618
619 // woocommerce
620 if ( get_post_type() !== 'product' )
621 wp_enqueue_script( 'pvc-admin-quick-edit' );
622 // widgets
623 } elseif ( $page === 'widgets.php' )
624 wp_enqueue_script( 'pvc-admin-widgets', POST_VIEWS_COUNTER_URL . '/js/admin-widgets.js', [ 'jquery' ], $this->defaults['version'] );
625 // media
626 elseif ( $page === 'upload.php' )
627 wp_enqueue_style( 'pvc-admin' );
628 }
629
630 /**
631 * Add links to plugin support forum.
632 *
633 * @param array $links
634 * @param string $file
635 * @return array
636 */
637 public function plugin_row_meta( $links, $file ) {
638 if ( ! current_user_can( 'install_plugins' ) )
639 return $links;
640
641 $plugin = plugin_basename( __FILE__ );
642
643 if ( $file == $plugin ) {
644 return array_merge(
645 $links,
646 [
647 sprintf( '<a href="http://www.dfactory.eu/support/forum/post-views-counter/" target="_blank">%s</a>', __( 'Support', 'post-views-counter' ) )
648 ]
649 );
650 }
651
652 return $links;
653 }
654
655 /**
656 * Add link to settings page.
657 *
658 * @staticvar string $plugin
659 * @param array $links
660 * @param string $file
661 * @return array
662 */
663 public function plugin_action_links( $links, $file ) {
664 if ( ! is_admin() || ! current_user_can( 'manage_options' ) )
665 return $links;
666
667 static $plugin;
668
669 $plugin = plugin_basename( __FILE__ );
670
671 if ( $file == $plugin ) {
672 $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php' ) . '?page=post-views-counter', __( 'Settings', 'post-views-counter' ) );
673
674 array_unshift( $links, $settings_link );
675 }
676
677 return $links;
678 }
679 }
680
681 endif; // end if class_exists check
682
683 /**
684 * Initialise Post Views Counter.
685 *
686 * @return object
687 */
688 function Post_Views_Counter() {
689 static $instance;
690
691 // first call to instance() initializes the plugin
692 if ( $instance === null || ! ( $instance instanceof Post_Views_Counter ) )
693 $instance = Post_Views_Counter::instance();
694
695 return $instance;
696 }
697
698 Post_Views_Counter();
699