PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.3.11
Post Views Counter v1.3.11
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
697 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.11
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-2022, 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.11
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.11'
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, insures that only one instance of the plugin exists in memory at one time.
106 *
107 * @return object
108 */
109 public static function instance() {
110 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Post_Views_Counter ) ) {
111 self::$instance = new Post_Views_Counter;
112 self::$instance->define_constants();
113
114 // short init?
115 if ( defined( 'SHORTINIT' ) && SHORTINIT ) {
116 include_once( POST_VIEWS_COUNTER_PATH . 'includes/class-counter.php' );
117 include_once( POST_VIEWS_COUNTER_PATH . 'includes/class-crawler-detect.php' );
118 include_once( POST_VIEWS_COUNTER_PATH . 'includes/functions.php' );
119
120 self::$instance->counter = new Post_Views_Counter_Counter();
121 self::$instance->crawler_detect = new Post_Views_Counter_Crawler_Detect();
122 // regular setup
123 } else {
124 add_action( 'plugins_loaded', [ self::$instance, 'load_textdomain' ] );
125
126 self::$instance->includes();
127
128 // create settings API
129 self::$instance->settings_api = new Post_Views_Counter_Settings_API(
130 [
131 'object' => self::$instance,
132 'prefix' => 'post_views_counter',
133 'slug' => 'post-views-counter',
134 'domain' => 'post-views-counter',
135 'plugin' => 'Post Views Counter',
136 'plugin_url' => 'POST_VIEWS_COUNTER_URL'
137 ]
138 );
139
140 self::$instance->functions = new Post_Views_Counter_Functions();
141 self::$instance->update = new Post_Views_Counter_Update();
142 self::$instance->settings = new Post_Views_Counter_Settings();
143 self::$instance->admin = new Post_Views_Counter_Admin();
144 self::$instance->query = new Post_Views_Counter_Query();
145 self::$instance->cron = new Post_Views_Counter_Cron();
146 self::$instance->counter = new Post_Views_Counter_Counter();
147 self::$instance->columns = new Post_Views_Counter_Columns();
148 self::$instance->crawler_detect = new Post_Views_Counter_Crawler_Detect();
149 self::$instance->frontend = new Post_Views_Counter_Frontend();
150 self::$instance->dashboard = new Post_Views_Counter_Dashboard();
151 self::$instance->widgets = new Post_Views_Counter_Widgets();
152 }
153 }
154
155 return self::$instance;
156 }
157
158 /**
159 * Setup plugin constants.
160 *
161 * @return void
162 */
163 private function define_constants() {
164 // fix plugin_basename empty $wp_plugin_paths var
165 if ( ! ( defined( 'SHORTINIT' ) && SHORTINIT ) ) {
166 define( 'POST_VIEWS_COUNTER_URL', plugins_url( '', __FILE__ ) );
167 define( 'POST_VIEWS_COUNTER_REL_PATH', dirname( plugin_basename( __FILE__ ) ) . '/' );
168 }
169
170 define( 'POST_VIEWS_COUNTER_PATH', plugin_dir_path( __FILE__ ) );
171 }
172
173 /**
174 * Include required files.
175 *
176 * @return void
177 */
178 private function includes() {
179 include_once( POST_VIEWS_COUNTER_PATH . 'includes/class-functions.php' );
180 include_once( POST_VIEWS_COUNTER_PATH . 'includes/class-update.php' );
181 include_once( POST_VIEWS_COUNTER_PATH . 'includes/class-settings-api.php' );
182 include_once( POST_VIEWS_COUNTER_PATH . 'includes/class-settings.php' );
183 include_once( POST_VIEWS_COUNTER_PATH . 'includes/class-admin.php' );
184 include_once( POST_VIEWS_COUNTER_PATH . 'includes/class-columns.php' );
185 include_once( POST_VIEWS_COUNTER_PATH . 'includes/class-query.php' );
186 include_once( POST_VIEWS_COUNTER_PATH . 'includes/class-cron.php' );
187 include_once( POST_VIEWS_COUNTER_PATH . 'includes/class-counter.php' );
188 include_once( POST_VIEWS_COUNTER_PATH . 'includes/class-crawler-detect.php' );
189 include_once( POST_VIEWS_COUNTER_PATH . 'includes/class-frontend.php' );
190 include_once( POST_VIEWS_COUNTER_PATH . 'includes/class-dashboard.php' );
191 include_once( POST_VIEWS_COUNTER_PATH . 'includes/class-widgets.php' );
192 }
193
194 /**
195 * Class constructor.
196 *
197 * @return void
198 */
199 public function __construct() {
200 // short init?
201 if ( defined( 'SHORTINIT' ) && SHORTINIT ) {
202 $this->options = [
203 'general' => array_merge( $this->defaults['general'], get_option( 'post_views_counter_settings_general', $this->defaults['general'] ) ),
204 'display' => array_merge( $this->defaults['display'], get_option( 'post_views_counter_settings_display', $this->defaults['display'] ) )
205 ];
206
207 return;
208 }
209
210 register_activation_hook( __FILE__, [ $this, 'multisite_activation' ] );
211 register_deactivation_hook( __FILE__, [ $this, 'multisite_deactivation' ] );
212
213 // settings
214 $this->options = [
215 'general' => array_merge( $this->defaults['general'], get_option( 'post_views_counter_settings_general', $this->defaults['general'] ) ),
216 'display' => array_merge( $this->defaults['display'], get_option( 'post_views_counter_settings_display', $this->defaults['display'] ) )
217 ];
218
219 // actions
220 add_action( 'admin_enqueue_scripts', [ $this, 'admin_enqueue_scripts' ] );
221 add_action( 'wp_loaded', [ $this, 'load_pluggable_functions' ], 10 );
222 add_action( 'admin_init', [ $this, 'update_notice' ] );
223 add_action( 'wp_ajax_pvc_dismiss_notice', [ $this, 'dismiss_notice' ] );
224
225 // filters
226 add_filter( 'plugin_row_meta', [ $this, 'plugin_row_meta' ], 10, 2 );
227 add_filter( 'plugin_action_links', [ $this, 'plugin_action_links' ], 10, 2 );
228 }
229
230 /**
231 * Update notice.
232 *
233 * @return void
234 */
235 public function update_notice() {
236 if ( ! current_user_can( 'install_plugins' ) )
237 return;
238
239 $current_update = 2;
240
241 // get current time
242 $current_time = time();
243
244 if ( $this->options['general']['update_version'] < $current_update ) {
245 // check version, if update version is lower than plugin version, set update notice to true
246 $this->options['general'] = array_merge(
247 $this->options['general'],
248 [
249 'update_version' => $current_update,
250 'update_notice' => true
251 ]
252 );
253
254 update_option( 'post_views_counter_settings_general', $this->options['general'] );
255
256 // set activation date
257 $activation_date = get_option( 'post_views_counter_activation_date' );
258
259 if ( $activation_date === false )
260 update_option( 'post_views_counter_activation_date', $current_time );
261 }
262
263 // display current version notice
264 if ( $this->options['general']['update_notice'] === true ) {
265 // include notice js, only if needed
266 add_action( 'admin_print_scripts', [ $this, 'admin_inline_js' ], 999 );
267
268 // get activation date
269 $activation_date = get_option( 'post_views_counter_activation_date' );
270
271 if ( (int) $this->options['general']['update_delay_date'] === 0 ) {
272 if ( $activation_date + 1209600 > $current_time )
273 $this->options['general']['update_delay_date'] = $activation_date + 1209600;
274 else
275 $this->options['general']['update_delay_date'] = $current_time;
276
277 update_option( 'post_views_counter_settings_general', $this->options['general'] );
278 }
279
280 if ( ( ! empty( $this->options['general']['update_delay_date'] ) ? (int) $this->options['general']['update_delay_date'] : $current_time ) <= $current_time )
281 $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' );
282 }
283 }
284
285 /**
286 * Add admin notices.
287 *
288 * @param string $html
289 * @param string $status
290 * @param bool $paragraph
291 * @return void
292 */
293 public function add_notice( $html = '', $status = 'error', $paragraph = true ) {
294 $this->notices[] = [
295 'html' => $html,
296 'status' => $status,
297 'paragraph' => $paragraph
298 ];
299
300 add_action( 'admin_notices', [ $this, 'display_notice' ] );
301 }
302
303 /**
304 * Print admin notices.
305 *
306 * @return void
307 */
308 public function display_notice() {
309 foreach( $this->notices as $notice ) {
310 echo '
311 <div class="' . $notice['status'] . '">
312 ' . ( $notice['paragraph'] ? '<p>' : '' ) . '
313 ' . $notice['html'] . '
314 ' . ( $notice['paragraph'] ? '</p>' : '' ) . '
315 </div>';
316 }
317 }
318
319 /**
320 * Print admin scripts.
321 *
322 * @return void
323 */
324 public function admin_inline_js() {
325 if ( ! current_user_can( 'install_plugins' ) )
326 return;
327 ?>
328 <script type="text/javascript">
329 ( function ( $ ) {
330 $( document ).ready( function () {
331 // save dismiss state
332 $( '.pvc-notice.is-dismissible' ).on( 'click', '.notice-dismiss, .pvc-dismissible-notice', function ( e ) {
333 var notice_action = 'hide';
334
335 if ( $( e.currentTarget ).hasClass( 'pvc-delay-notice' ) ) {
336 notice_action = 'delay'
337 }
338
339 $.post( ajaxurl, {
340 action: 'pvc_dismiss_notice',
341 notice_action: notice_action,
342 url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
343 nonce: '<?php echo wp_create_nonce( 'pvc_dismiss_notice' ); ?>'
344 } );
345
346 $( e.delegateTarget ).slideUp( 'fast' );
347 } );
348 } );
349 } )( jQuery );
350 </script>
351 <?php
352 }
353
354 /**
355 * Dismiss notice.
356 *
357 * @return void
358 */
359 public function dismiss_notice() {
360 if ( ! current_user_can( 'install_plugins' ) )
361 return;
362
363 if ( wp_verify_nonce( esc_attr( $_REQUEST['nonce'] ), 'pvc_dismiss_notice' ) ) {
364 $notice_action = empty( $_REQUEST['notice_action'] ) || $_REQUEST['notice_action'] === 'hide' ? 'hide' : sanitize_text_field( $_REQUEST['notice_action'] );
365
366 switch ( $notice_action ) {
367 // delay notice
368 case 'delay':
369 // set delay period to 1 week from now
370 $this->options['general'] = array_merge(
371 $this->options['general'],
372 [
373 'update_delay_date' => time() + 1209600
374 ]
375 );
376 update_option( 'post_views_counter_settings_general', $this->options['general'] );
377 break;
378
379 // hide notice
380 default:
381 $this->options['general'] = array_merge(
382 $this->options['general'],
383 [
384 'update_notice' => false
385 ]
386 );
387 $this->options['general'] = array_merge(
388 $this->options['general'],
389 [
390 'update_delay_date' => 0
391 ]
392 );
393
394 update_option( 'post_views_counter_settings_general', $this->options['general'] );
395 }
396 }
397
398 exit;
399 }
400
401 /**
402 * Multisite activation.
403 *
404 * @global object $wpdb
405 *
406 * @param bool $networkwide
407 * @return void
408 */
409 public function multisite_activation( $networkwide ) {
410 if ( is_multisite() && $networkwide ) {
411 global $wpdb;
412
413 $activated_blogs = [];
414 $current_blog_id = $wpdb->blogid;
415 $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) );
416
417 foreach ( $blogs_ids as $blog_id ) {
418 switch_to_blog( $blog_id );
419 $this->activate_single();
420 $activated_blogs[] = (int) $blog_id;
421 }
422
423 switch_to_blog( $current_blog_id );
424 update_site_option( 'post_views_counter_activated_blogs', $activated_blogs, [] );
425 } else
426 $this->activate_single();
427 }
428
429 /**
430 * Single site activation.
431 *
432 * @global object $wpdb
433 * @global string $charset_collate
434 *
435 * @return void
436 */
437 public function activate_single() {
438 global $wpdb, $charset_collate;
439
440 // required for dbdelta
441 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
442
443 // create post views table
444 dbDelta( '
445 CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'post_views (
446 `id` bigint unsigned NOT NULL,
447 `type` tinyint(1) unsigned NOT NULL,
448 `period` varchar(8) NOT NULL,
449 `count` bigint unsigned NOT NULL,
450 PRIMARY KEY (type, period, id),
451 UNIQUE INDEX id_type_period_count (id, type, period, count) USING BTREE,
452 INDEX type_period_count (type, period, count) USING BTREE
453 ) ' . $charset_collate . ';'
454 );
455
456 // add default options
457 add_option( 'post_views_counter_settings_general', $this->defaults['general'], '', 'no' );
458 add_option( 'post_views_counter_settings_display', $this->defaults['display'], '', 'no' );
459 add_option( 'post_views_counter_version', $this->defaults['version'], '', 'no' );
460
461 // schedule cache flush
462 $this->schedule_cache_flush();
463 }
464
465 /**
466 * Multisite deactivation.
467 *
468 * @global $wpdb
469 *
470 * @param bool $networkwide
471 * @return void
472 */
473 public function multisite_deactivation( $networkwide ) {
474 if ( is_multisite() && $networkwide ) {
475 global $wpdb;
476
477 $current_blog_id = $wpdb->blogid;
478 $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) );
479
480 if ( ! ( $activated_blogs = get_site_option( 'post_views_counter_activated_blogs', false, false ) ) )
481 $activated_blogs = [];
482
483 foreach ( $blogs_ids as $blog_id ) {
484 switch_to_blog( $blog_id );
485 $this->deactivate_single( true );
486
487 if ( in_array( (int) $blog_id, $activated_blogs, true ) )
488 unset( $activated_blogs[array_search( $blog_id, $activated_blogs )] );
489 }
490
491 switch_to_blog( $current_blog_id );
492 update_site_option( 'post_views_counter_activated_blogs', $activated_blogs );
493 } else
494 $this->deactivate_single();
495 }
496
497 /**
498 * Single site deactivation.
499 *
500 * @global $wpdb
501 *
502 * @param bool $multi
503 * @return void
504 */
505 public function deactivate_single( $multi = false ) {
506 if ( $multi ) {
507 $options = get_option( 'post_views_counter_settings_general' );
508 $check = $options['deactivation_delete'];
509 } else
510 $check = $this->options['general']['deactivation_delete'];
511
512 // delete default options
513 if ( $check ) {
514 delete_option( 'post_views_counter_settings_general' );
515 delete_option( 'post_views_counter_settings_display' );
516
517 global $wpdb;
518
519 // delete table from database
520 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post_views' );
521 }
522
523 // remove schedule
524 wp_clear_scheduled_hook( 'pvc_reset_counts' );
525 remove_action( 'pvc_reset_counts', [ Post_Views_Counter()->cron, 'reset_counts' ] );
526
527 $this->remove_cache_flush();
528 }
529
530 /**
531 * Schedule cache flushing if it's not already scheduled.
532 *
533 * @param bool $forced
534 * @return void
535 */
536 public function schedule_cache_flush( $forced = true ) {
537 if ( $forced || ! wp_next_scheduled( 'pvc_flush_cached_counts' ) )
538 wp_schedule_event( time(), 'post_views_counter_flush_interval', 'pvc_flush_cached_counts' );
539 }
540
541 /**
542 * Remove scheduled cache flush and the corresponding action.
543 *
544 * @return void
545 */
546 public function remove_cache_flush() {
547 wp_clear_scheduled_hook( 'pvc_flush_cached_counts' );
548 remove_action( 'pvc_flush_cached_counts', [ Post_Views_Counter()->cron, 'flush_cached_counts' ] );
549 }
550
551 /**
552 * Load text domain.
553 *
554 * @return void
555 */
556 public function load_textdomain() {
557 load_plugin_textdomain( 'post-views-counter', false, POST_VIEWS_COUNTER_REL_PATH . 'languages/' );
558 }
559
560 /**
561 * Load pluggable template functions.
562 *
563 * @return void
564 */
565 public function load_pluggable_functions() {
566 include_once( POST_VIEWS_COUNTER_PATH . 'includes/functions.php' );
567 }
568
569 /**
570 * Enqueue admin scripts and styles.
571 *
572 * @global string $post_type
573 *
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
682 /**
683 * Initialise Post Views Counter.
684 *
685 * @return object
686 */
687 function Post_Views_Counter() {
688 static $instance;
689
690 // first call to instance() initializes the plugin
691 if ( $instance === null || ! ( $instance instanceof Post_Views_Counter ) )
692 $instance = Post_Views_Counter::instance();
693
694 return $instance;
695 }
696
697 Post_Views_Counter();