PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.3.9
Post Views Counter v1.3.9
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
691 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.9
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.9
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.9'
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' : esc_attr( $_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 * @param bool $networkwide
406 * @return void
407 */
408 public function multisite_activation( $networkwide ) {
409 if ( is_multisite() && $networkwide ) {
410 global $wpdb;
411
412 $activated_blogs = [];
413 $current_blog_id = $wpdb->blogid;
414 $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) );
415
416 foreach ( $blogs_ids as $blog_id ) {
417 switch_to_blog( $blog_id );
418 $this->activate_single();
419 $activated_blogs[] = (int) $blog_id;
420 }
421
422 switch_to_blog( $current_blog_id );
423 update_site_option( 'post_views_counter_activated_blogs', $activated_blogs, [] );
424 } else
425 $this->activate_single();
426 }
427
428 /**
429 * Single site activation.
430 *
431 * @global array $wp_roles
432 * @return void
433 */
434 public function activate_single() {
435 global $wpdb, $charset_collate;
436
437 // required for dbdelta
438 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
439
440 // create post views table
441 dbDelta( '
442 CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'post_views (
443 `id` bigint unsigned NOT NULL,
444 `type` tinyint(1) unsigned NOT NULL,
445 `period` varchar(8) NOT NULL,
446 `count` bigint unsigned NOT NULL,
447 PRIMARY KEY (type, period, id),
448 UNIQUE INDEX id_type_period_count (id, type, period, count) USING BTREE,
449 INDEX type_period_count (type, period, count) USING BTREE
450 ) ' . $charset_collate . ';'
451 );
452
453 // add default options
454 add_option( 'post_views_counter_settings_general', $this->defaults['general'], '', 'no' );
455 add_option( 'post_views_counter_settings_display', $this->defaults['display'], '', 'no' );
456 add_option( 'post_views_counter_version', $this->defaults['version'], '', 'no' );
457
458 // schedule cache flush
459 $this->schedule_cache_flush();
460 }
461
462 /**
463 * Multisite deactivation.
464 *
465 * @global $wpdb
466 * @param bool $networkwide
467 * @return void
468 */
469 public function multisite_deactivation( $networkwide ) {
470 if ( is_multisite() && $networkwide ) {
471 global $wpdb;
472
473 $current_blog_id = $wpdb->blogid;
474 $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) );
475
476 if ( ! ( $activated_blogs = get_site_option( 'post_views_counter_activated_blogs', false, false ) ) )
477 $activated_blogs = [];
478
479 foreach ( $blogs_ids as $blog_id ) {
480 switch_to_blog( $blog_id );
481 $this->deactivate_single( true );
482
483 if ( in_array( (int) $blog_id, $activated_blogs, true ) )
484 unset( $activated_blogs[array_search( $blog_id, $activated_blogs )] );
485 }
486
487 switch_to_blog( $current_blog_id );
488 update_site_option( 'post_views_counter_activated_blogs', $activated_blogs );
489 } else
490 $this->deactivate_single();
491 }
492
493 /**
494 * Single site deactivation.
495 *
496 * @global $wpdb
497 * @param bool $multi
498 * @return void
499 */
500 public function deactivate_single( $multi = false ) {
501 if ( $multi ) {
502 $options = get_option( 'post_views_counter_settings_general' );
503 $check = $options['deactivation_delete'];
504 } else
505 $check = $this->options['general']['deactivation_delete'];
506
507 // delete default options
508 if ( $check ) {
509 delete_option( 'post_views_counter_settings_general' );
510 delete_option( 'post_views_counter_settings_display' );
511
512 global $wpdb;
513
514 // delete table from database
515 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post_views' );
516 }
517
518 // remove schedule
519 wp_clear_scheduled_hook( 'pvc_reset_counts' );
520 remove_action( 'pvc_reset_counts', [ Post_Views_Counter()->cron, 'reset_counts' ] );
521
522 $this->remove_cache_flush();
523 }
524
525 /**
526 * Schedule cache flushing if it's not already scheduled.
527 *
528 * @param bool $forced
529 * @return void
530 */
531 public function schedule_cache_flush( $forced = true ) {
532 if ( $forced || ! wp_next_scheduled( 'pvc_flush_cached_counts' ) )
533 wp_schedule_event( time(), 'post_views_counter_flush_interval', 'pvc_flush_cached_counts' );
534 }
535
536 /**
537 * Remove scheduled cache flush and the corresponding action.
538 *
539 * @return void
540 */
541 public function remove_cache_flush() {
542 wp_clear_scheduled_hook( 'pvc_flush_cached_counts' );
543 remove_action( 'pvc_flush_cached_counts', [ Post_Views_Counter()->cron, 'flush_cached_counts' ] );
544 }
545
546 /**
547 * Load text domain.
548 *
549 * @return void
550 */
551 public function load_textdomain() {
552 load_plugin_textdomain( 'post-views-counter', false, POST_VIEWS_COUNTER_REL_PATH . 'languages/' );
553 }
554
555 /**
556 * Load pluggable template functions.
557 *
558 * @return void
559 */
560 public function load_pluggable_functions() {
561 include_once( POST_VIEWS_COUNTER_PATH . 'includes/functions.php' );
562 }
563
564 /**
565 * Enqueue admin scripts and styles.
566 *
567 * @global string $post_type
568 * @param string $page.
569 * @return void
570 */
571 public function admin_enqueue_scripts( $page ) {
572 wp_register_style( 'pvc-admin', POST_VIEWS_COUNTER_URL . '/css/admin.css' );
573
574 wp_register_script( 'pvc-admin-settings', POST_VIEWS_COUNTER_URL . '/js/admin-settings.js', [ 'jquery' ], $this->defaults['version'] );
575 wp_register_script( 'pvc-admin-post', POST_VIEWS_COUNTER_URL . '/js/admin-post.js', [ 'jquery' ], $this->defaults['version'] );
576 wp_register_script( 'pvc-admin-quick-edit', POST_VIEWS_COUNTER_URL . '/js/admin-quick-edit.js', [ 'jquery', 'inline-edit-post' ], $this->defaults['version'] );
577
578 // load on PVC settings page
579 if ( $page === 'settings_page_post-views-counter' ) {
580 wp_enqueue_script( 'pvc-admin-settings' );
581
582 wp_localize_script(
583 'pvc-admin-settings', 'pvcArgsSettings', [
584 'resetToDefaults' => __( 'Are you sure you want to reset these settings to defaults?', 'post-views-counter' ),
585 'resetViews' => __( 'Are you sure you want to delete all existing data?', 'post-views-counter' )
586 ]
587 );
588
589 wp_enqueue_style( 'pvc-admin' );
590
591 // load on single post page
592 } elseif ( $page === 'post.php' || $page === 'post-new.php' ) {
593 $post_types = Post_Views_Counter()->options['general']['post_types_count'];
594
595 global $post_type;
596
597 if ( ! in_array( $post_type, (array) $post_types ) )
598 return;
599
600 wp_enqueue_style( 'pvc-admin' );
601 wp_enqueue_script( 'pvc-admin-post' );
602 // edit post
603 } elseif ( $page === 'edit.php' ) {
604 $post_types = Post_Views_Counter()->options['general']['post_types_count'];
605
606 global $post_type;
607
608 if ( ! in_array( $post_type, (array) $post_types ) )
609 return;
610
611 wp_enqueue_style( 'pvc-admin' );
612
613 // woocommerce
614 if ( get_post_type() !== 'product' )
615 wp_enqueue_script( 'pvc-admin-quick-edit' );
616 // widgets
617 } elseif ( $page === 'widgets.php' )
618 wp_enqueue_script( 'pvc-admin-widgets', POST_VIEWS_COUNTER_URL . '/js/admin-widgets.js', [ 'jquery' ], $this->defaults['version'] );
619 // media
620 elseif ( $page === 'upload.php' )
621 wp_enqueue_style( 'pvc-admin' );
622 }
623
624 /**
625 * Add links to plugin support forum.
626 *
627 * @param array $links
628 * @param string $file
629 * @return array
630 */
631 public function plugin_row_meta( $links, $file ) {
632 if ( ! current_user_can( 'install_plugins' ) )
633 return $links;
634
635 $plugin = plugin_basename( __FILE__ );
636
637 if ( $file == $plugin ) {
638 return array_merge(
639 $links,
640 [
641 sprintf( '<a href="http://www.dfactory.eu/support/forum/post-views-counter/" target="_blank">%s</a>', __( 'Support', 'post-views-counter' ) )
642 ]
643 );
644 }
645
646 return $links;
647 }
648
649 /**
650 * Add link to settings page.
651 *
652 * @staticvar string $plugin
653 * @param array $links
654 * @param string $file
655 * @return array
656 */
657 public function plugin_action_links( $links, $file ) {
658 if ( ! is_admin() || ! current_user_can( 'manage_options' ) )
659 return $links;
660
661 static $plugin;
662
663 $plugin = plugin_basename( __FILE__ );
664
665 if ( $file == $plugin ) {
666 $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php' ) . '?page=post-views-counter', __( 'Settings', 'post-views-counter' ) );
667
668 array_unshift( $links, $settings_link );
669 }
670
671 return $links;
672 }
673 }
674 }
675
676 /**
677 * Initialise Post Views Counter.
678 *
679 * @return object
680 */
681 function Post_Views_Counter() {
682 static $instance;
683
684 // first call to instance() initializes the plugin
685 if ( $instance === null || ! ( $instance instanceof Post_Views_Counter ) )
686 $instance = Post_Views_Counter::instance();
687
688 return $instance;
689 }
690
691 Post_Views_Counter();