PluginProbe ʕ •ᴥ•ʔ
Post Views Counter / 1.3.5
Post Views Counter v1.3.5
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
641 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.5
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.5
35 */
36 final class Post_Views_Counter {
37
38 private static $instance;
39 public $options;
40 public $defaults = array(
41 'general' => array(
42 'post_types_count' => array( 'post' ),
43 'counter_mode' => 'php',
44 'post_views_column' => true,
45 'time_between_counts' => array(
46 'number' => 24,
47 'type' => 'hours'
48 ),
49 'reset_counts' => array(
50 'number' => 30,
51 'type' => 'days'
52 ),
53 'flush_interval' => array(
54 'number' => 0,
55 'type' => 'minutes'
56 ),
57 'exclude' => array(
58 'groups' => array(),
59 'roles' => array()
60 ),
61 'exclude_ips' => array(),
62 'strict_counts' => false,
63 'restrict_edit_views' => 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' => array(
72 'label' => 'Post Views:',
73 'post_types_display' => array( 'post' ),
74 'page_types_display' => array( 'singular' ),
75 'restrict_display' => array(
76 'groups' => array(),
77 'roles' => array()
78 ),
79 'position' => 'after',
80 'display_style' => array(
81 'icon' => true,
82 'text' => true
83 ),
84 'link_to_post' => true,
85 'icon_class' => 'dashicons-chart-bar',
86 'toolbar_statistics' => true
87 ),
88 'version' => '1.3.5'
89 );
90
91 /**
92 * Disable object cloning.
93 */
94 public function __clone() {}
95
96 /**
97 * Disable unserializing of the class.
98 */
99 public function __wakeup() {}
100
101 /**
102 * Main plugin instance,
103 * Insures that only one instance of the plugin exists in memory at one time.
104 *
105 * @return object
106 */
107 public static function instance() {
108 if ( ! isset( self::$instance ) && ! ( self::$instance instanceof Post_Views_Counter ) ) {
109 self::$instance = new Post_Views_Counter;
110 self::$instance->define_constants();
111
112 // minimal setup for Fast AJAX
113 if ( defined( 'SHORTINIT' ) && SHORTINIT ) {
114 include_once( POST_VIEWS_COUNTER_PATH . 'includes/counter.php' );
115 include_once( POST_VIEWS_COUNTER_PATH . 'includes/crawler-detect.php' );
116 include_once( POST_VIEWS_COUNTER_PATH . 'includes/functions.php' );
117
118 self::$instance->counter = new Post_Views_Counter_Counter();
119 self::$instance->crawler_detect = new Post_Views_Counter_Crawler_Detect();
120 // regular setup
121 } else {
122 add_action( 'plugins_loaded', array( self::$instance, 'load_textdomain' ) );
123
124 self::$instance->includes();
125 self::$instance->update = new Post_Views_Counter_Update();
126 self::$instance->settings = new Post_Views_Counter_Settings();
127 self::$instance->query = new Post_Views_Counter_Query();
128 self::$instance->cron = new Post_Views_Counter_Cron();
129 self::$instance->counter = new Post_Views_Counter_Counter();
130 self::$instance->columns = new Post_Views_Counter_Columns();
131 self::$instance->crawler_detect = new Post_Views_Counter_Crawler_Detect();
132 self::$instance->frontend = new Post_Views_Counter_Frontend();
133 self::$instance->dashboard = new Post_Views_Counter_Dashboard();
134 self::$instance->widgets = new Post_Views_Counter_Widgets();
135 }
136 }
137
138 return self::$instance;
139 }
140
141 /**
142 * Setup plugin constants.
143 *
144 * @return void
145 */
146 private function define_constants() {
147 // fix plugin_basename empty $wp_plugin_paths var
148 if ( ! ( defined( 'SHORTINIT' ) && SHORTINIT ) ) {
149 define( 'POST_VIEWS_COUNTER_URL', plugins_url( '', __FILE__ ) );
150 define( 'POST_VIEWS_COUNTER_REL_PATH', dirname( plugin_basename( __FILE__ ) ) . '/' );
151 }
152
153 define( 'POST_VIEWS_COUNTER_PATH', plugin_dir_path( __FILE__ ) );
154 }
155
156 /**
157 * Include required files.
158 *
159 * @return void
160 */
161 private function includes() {
162 include_once( POST_VIEWS_COUNTER_PATH . 'includes/update.php' );
163 include_once( POST_VIEWS_COUNTER_PATH . 'includes/settings.php' );
164 include_once( POST_VIEWS_COUNTER_PATH . 'includes/columns.php' );
165 include_once( POST_VIEWS_COUNTER_PATH . 'includes/query.php' );
166 include_once( POST_VIEWS_COUNTER_PATH . 'includes/cron.php' );
167 include_once( POST_VIEWS_COUNTER_PATH . 'includes/counter.php' );
168 include_once( POST_VIEWS_COUNTER_PATH . 'includes/crawler-detect.php' );
169 include_once( POST_VIEWS_COUNTER_PATH . 'includes/frontend.php' );
170 include_once( POST_VIEWS_COUNTER_PATH . 'includes/dashboard.php' );
171 include_once( POST_VIEWS_COUNTER_PATH . 'includes/widgets.php' );
172 }
173
174 /**
175 * Class constructor.
176 *
177 * @return void
178 */
179 public function __construct() {
180 if ( defined( 'SHORTINIT' ) && SHORTINIT ) {
181 $this->options = array(
182 'general' => array_merge( $this->defaults['general'], get_option( 'post_views_counter_settings_general', $this->defaults['general'] ) ),
183 'display' => array_merge( $this->defaults['display'], get_option( 'post_views_counter_settings_display', $this->defaults['display'] ) )
184 );
185 } else {
186 register_activation_hook( __FILE__, array( $this, 'multisite_activation' ) );
187 register_deactivation_hook( __FILE__, array( $this, 'multisite_deactivation' ) );
188
189 // settings
190 $this->options = array(
191 'general' => array_merge( $this->defaults['general'], get_option( 'post_views_counter_settings_general', $this->defaults['general'] ) ),
192 'display' => array_merge( $this->defaults['display'], get_option( 'post_views_counter_settings_display', $this->defaults['display'] ) )
193 );
194
195 // actions
196 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
197 add_action( 'wp_loaded', array( $this, 'load_pluggable_functions' ), 10 );
198 // add_action( 'init', array( $this, 'gutenberg_blocks' ) );
199 add_action( 'admin_init', array( $this, 'update_notice' ) );
200 add_action( 'wp_ajax_pvc_dismiss_notice', array( $this, 'dismiss_notice' ) );
201
202 // filters
203 add_filter( 'plugin_row_meta', array( $this, 'plugin_row_meta' ), 10, 2 );
204 add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
205 }
206 }
207
208 /**
209 * Update notice.
210 *
211 * @return void
212 */
213 public function update_notice() {
214 if ( ! current_user_can( 'install_plugins' ) )
215 return;
216
217 $current_update = 2;
218
219 // get current time
220 $current_time = time();
221
222 if ( $this->options['general']['update_version'] < $current_update ) {
223 // check version, if update version is lower than plugin version, set update notice to true
224 $this->options['general'] = array_merge( $this->options['general'], array( 'update_version' => $current_update, 'update_notice' => true ) );
225
226 update_option( 'post_views_counter_settings_general', $this->options['general'] );
227
228 // set activation date
229 $activation_date = get_option( 'post_views_counter_activation_date' );
230
231 if ( $activation_date === false )
232 update_option( 'post_views_counter_activation_date', $current_time );
233 }
234
235 // display current version notice
236 if ( $this->options['general']['update_notice'] === true ) {
237 // include notice js, only if needed
238 add_action( 'admin_print_scripts', array( $this, 'admin_inline_js' ), 999 );
239
240 // get activation date
241 $activation_date = get_option( 'post_views_counter_activation_date' );
242
243 if ( (int) $this->options['general']['update_delay_date'] === 0 ) {
244 if ( $activation_date + 1209600 > $current_time )
245 $this->options['general']['update_delay_date'] = $activation_date + 1209600;
246 else
247 $this->options['general']['update_delay_date'] = $current_time;
248
249 update_option( 'post_views_counter_settings_general', $this->options['general'] );
250 }
251
252 if ( ( ! empty( $this->options['general']['update_delay_date'] ) ? (int) $this->options['general']['update_delay_date'] : $current_time ) <= $current_time )
253 $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' );
254 }
255 }
256
257 /**
258 * Add admin notices.
259 *
260 * @param string $html
261 * @param string $status
262 * @param bool $paragraph
263 */
264 public function add_notice( $html = '', $status = 'error', $paragraph = true ) {
265 $this->notices[] = array(
266 'html' => $html,
267 'status' => $status,
268 'paragraph' => $paragraph
269 );
270
271 add_action( 'admin_notices', array( $this, 'display_notice' ) );
272 }
273
274 /**
275 * Print admin notices.
276 *
277 * @return mixed
278 */
279 public function display_notice() {
280 foreach( $this->notices as $notice ) {
281 echo '
282 <div class="' . $notice['status'] . '">
283 ' . ( $notice['paragraph'] ? '<p>' : '' ) . '
284 ' . $notice['html'] . '
285 ' . ( $notice['paragraph'] ? '</p>' : '' ) . '
286 </div>';
287 }
288 }
289
290 /**
291 * Print admin scripts.
292 *
293 * @return mixed
294 */
295 public function admin_inline_js() {
296 if ( ! current_user_can( 'install_plugins' ) )
297 return;
298 ?>
299 <script type="text/javascript">
300 ( function ( $ ) {
301 $( document ).ready( function () {
302 // save dismiss state
303 $( '.pvc-notice.is-dismissible' ).on( 'click', '.notice-dismiss, .pvc-dismissible-notice', function ( e ) {
304 var notice_action = 'hide';
305
306 if ( $( e.currentTarget ).hasClass( 'pvc-delay-notice' ) ) {
307 notice_action = 'delay'
308 }
309
310 $.post( ajaxurl, {
311 action: 'pvc_dismiss_notice',
312 notice_action: notice_action,
313 url: '<?php echo admin_url( 'admin-ajax.php' ); ?>',
314 nonce: '<?php echo wp_create_nonce( 'pvc_dismiss_notice' ); ?>'
315 } );
316
317 $( e.delegateTarget ).slideUp( 'fast' );
318 } );
319 } );
320 } )( jQuery );
321 </script>
322 <?php
323 }
324
325 /**
326 * Dismiss notice.
327 */
328 public function dismiss_notice() {
329 if ( ! current_user_can( 'install_plugins' ) )
330 return;
331
332 if ( wp_verify_nonce( esc_attr( $_REQUEST['nonce'] ), 'pvc_dismiss_notice' ) ) {
333 $notice_action = empty( $_REQUEST['notice_action'] ) || $_REQUEST['notice_action'] === 'hide' ? 'hide' : esc_attr( $_REQUEST['notice_action'] );
334
335 switch ( $notice_action ) {
336 // delay notice
337 case 'delay':
338 // set delay period to 1 week from now
339 $this->options['general'] = array_merge( $this->options['general'], array( 'update_delay_date' => time() + 1209600 ) );
340 update_option( 'post_views_counter_settings_general', $this->options['general'] );
341 break;
342
343 // hide notice
344 default:
345 $this->options['general'] = array_merge( $this->options['general'], array( 'update_notice' => false ) );
346 $this->options['general'] = array_merge( $this->options['general'], array( 'update_delay_date' => 0 ) );
347
348 update_option( 'post_views_counter_settings_general', $this->options['general'] );
349 }
350 }
351
352 exit;
353 }
354
355 /**
356 * Multisite activation.
357 *
358 * @global object $wpdb
359 * @param bool $networkwide
360 */
361 public function multisite_activation( $networkwide ) {
362 if ( is_multisite() && $networkwide ) {
363 global $wpdb;
364
365 $activated_blogs = array();
366 $current_blog_id = $wpdb->blogid;
367 $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) );
368
369 foreach ( $blogs_ids as $blog_id ) {
370 switch_to_blog( $blog_id );
371 $this->activate_single();
372 $activated_blogs[] = (int) $blog_id;
373 }
374
375 switch_to_blog( $current_blog_id );
376 update_site_option( 'post_views_counter_activated_blogs', $activated_blogs, array() );
377 } else
378 $this->activate_single();
379 }
380
381 /**
382 * Single site activation.
383 *
384 * @global array $wp_roles
385 */
386 public function activate_single() {
387 global $wpdb, $charset_collate;
388
389 // required for dbdelta
390 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
391
392 // create post views table
393 dbDelta( '
394 CREATE TABLE IF NOT EXISTS ' . $wpdb->prefix . 'post_views (
395 id bigint unsigned NOT NULL,
396 type tinyint(1) unsigned NOT NULL,
397 period varchar(8) NOT NULL,
398 count bigint unsigned NOT NULL,
399 PRIMARY KEY (type, period, id),
400 UNIQUE INDEX id_type_period_count (id, type, period, count) USING BTREE,
401 INDEX type_period_count (type, period, count) USING BTREE
402 ) ' . $charset_collate . ';'
403 );
404
405 // add default options
406 add_option( 'post_views_counter_settings_general', $this->defaults['general'], '', 'no' );
407 add_option( 'post_views_counter_settings_display', $this->defaults['display'], '', 'no' );
408 add_option( 'post_views_counter_version', $this->defaults['version'], '', 'no' );
409
410 // schedule cache flush
411 $this->schedule_cache_flush();
412 }
413
414 /**
415 * Multisite deactivation.
416 *
417 * @global array $wpdb
418 * @param bool $networkwide
419 */
420 public function multisite_deactivation( $networkwide ) {
421 if ( is_multisite() && $networkwide ) {
422 global $wpdb;
423
424 $current_blog_id = $wpdb->blogid;
425 $blogs_ids = $wpdb->get_col( $wpdb->prepare( 'SELECT blog_id FROM ' . $wpdb->blogs, '' ) );
426
427 if ( ! ( $activated_blogs = get_site_option( 'post_views_counter_activated_blogs', false, false ) ) )
428 $activated_blogs = array();
429
430 foreach ( $blogs_ids as $blog_id ) {
431 switch_to_blog( $blog_id );
432 $this->deactivate_single( true );
433
434 if ( in_array( (int) $blog_id, $activated_blogs, true ) )
435 unset( $activated_blogs[array_search( $blog_id, $activated_blogs )] );
436 }
437
438 switch_to_blog( $current_blog_id );
439 update_site_option( 'post_views_counter_activated_blogs', $activated_blogs );
440 } else
441 $this->deactivate_single();
442 }
443
444 /**
445 * Single site deactivation.
446 *
447 * @global array $wp_roles
448 * @param bool $multi
449 */
450 public function deactivate_single( $multi = false ) {
451 if ( $multi ) {
452 $options = get_option( 'post_views_counter_settings_general' );
453 $check = $options['deactivation_delete'];
454 } else
455 $check = $this->options['general']['deactivation_delete'];
456
457 // delete default options
458 if ( $check ) {
459 delete_option( 'post_views_counter_settings_general' );
460 delete_option( 'post_views_counter_settings_display' );
461
462 global $wpdb;
463
464 // delete table from database
465 $wpdb->query( 'DROP TABLE IF EXISTS ' . $wpdb->prefix . 'post_views' );
466 }
467
468 // remove schedule
469 wp_clear_scheduled_hook( 'pvc_reset_counts' );
470 remove_action( 'pvc_reset_counts', array( Post_Views_Counter()->cron, 'reset_counts' ) );
471
472 $this->remove_cache_flush();
473 }
474
475 /**
476 * Schedule cache flushing if it's not already scheduled.
477 *
478 * @param bool $forced
479 */
480 public function schedule_cache_flush( $forced = true ) {
481 if ( $forced || ! wp_next_scheduled( 'pvc_flush_cached_counts' ) )
482 wp_schedule_event( time(), 'post_views_counter_flush_interval', 'pvc_flush_cached_counts' );
483 }
484
485 /**
486 * Remove scheduled cache flush and the corresponding action.
487 */
488 public function remove_cache_flush() {
489 wp_clear_scheduled_hook( 'pvc_flush_cached_counts' );
490 remove_action( 'pvc_flush_cached_counts', array( Post_Views_Counter()->cron, 'flush_cached_counts' ) );
491 }
492
493 /**
494 * Load text domain.
495 */
496 public function load_textdomain() {
497 load_plugin_textdomain( 'post-views-counter', false, POST_VIEWS_COUNTER_REL_PATH . 'languages/' );
498 }
499
500 /**
501 * Load pluggable template functions.
502 */
503 public function load_pluggable_functions() {
504 include_once( POST_VIEWS_COUNTER_PATH . 'includes/functions.php' );
505 }
506
507 /**
508 * Add Gutenberg blocks.
509 */
510 public function gutenberg_blocks() {
511 wp_register_script( 'pvc-admin-block-views', POST_VIEWS_COUNTER_URL . '/js/admin-block.js', array( 'wp-blocks', 'wp-element', 'wp-i18n' ) );
512
513 register_block_type( 'post-views-counter/views', array( 'editor_script' => 'pvc-admin-block-views' ) );
514 }
515
516 /**
517 * Enqueue admin scripts and styles.
518 *
519 * @global string $post_type
520 * @param string $page
521 */
522 public function admin_enqueue_scripts( $page ) {
523 wp_register_style( 'pvc-admin', POST_VIEWS_COUNTER_URL . '/css/admin.css' );
524
525 wp_register_script( 'pvc-admin-settings', POST_VIEWS_COUNTER_URL . '/js/admin-settings.js', array( 'jquery' ), $this->defaults['version'] );
526 wp_register_script( 'pvc-admin-post', POST_VIEWS_COUNTER_URL . '/js/admin-post.js', array( 'jquery' ), $this->defaults['version'] );
527 wp_register_script( 'pvc-admin-quick-edit', POST_VIEWS_COUNTER_URL . '/js/admin-quick-edit.js', array( 'jquery', 'inline-edit-post' ), $this->defaults['version'] );
528
529 // load on PVC settings page
530 if ( $page === 'settings_page_post-views-counter' ) {
531 wp_enqueue_script( 'pvc-admin-settings' );
532
533 wp_localize_script(
534 'pvc-admin-settings', 'pvcArgsSettings', array(
535 'resetToDefaults' => __( 'Are you sure you want to reset these settings to defaults?', 'post-views-counter' ),
536 'resetViews' => __( 'Are you sure you want to delete all existing data?', 'post-views-counter' )
537 )
538 );
539
540 wp_enqueue_style( 'pvc-admin' );
541
542 // load on single post page
543 } elseif ( $page === 'post.php' || $page === 'post-new.php' ) {
544 $post_types = Post_Views_Counter()->options['general']['post_types_count'];
545
546 global $post_type;
547
548 if ( ! in_array( $post_type, (array) $post_types ) )
549 return;
550
551 wp_enqueue_style( 'pvc-admin' );
552 wp_enqueue_script( 'pvc-admin-post' );
553 // edit post
554 } elseif ( $page === 'edit.php' ) {
555 $post_types = Post_Views_Counter()->options['general']['post_types_count'];
556
557 global $post_type;
558
559 if ( ! in_array( $post_type, (array) $post_types ) )
560 return;
561
562 wp_enqueue_style( 'pvc-admin' );
563
564 // woocommerce
565 if ( get_post_type() !== 'product' )
566 wp_enqueue_script( 'pvc-admin-quick-edit' );
567 // widgets
568 } elseif ( $page === 'widgets.php' )
569 wp_enqueue_script( 'pvc-admin-widgets', POST_VIEWS_COUNTER_URL . '/js/admin-widgets.js', array( 'jquery' ), $this->defaults['version'] );
570 // media
571 elseif ( $page === 'upload.php' )
572 wp_enqueue_style( 'pvc-admin' );
573 }
574
575 /**
576 * Add links to plugin support forum.
577 *
578 * @param array $links
579 * @param string $file
580 * @return array
581 */
582 public function plugin_row_meta( $links, $file ) {
583 if ( ! current_user_can( 'install_plugins' ) )
584 return $links;
585
586 $plugin = plugin_basename( __FILE__ );
587
588 if ( $file == $plugin ) {
589 return array_merge(
590 $links, array( sprintf( '<a href="http://www.dfactory.eu/support/forum/post-views-counter/" target="_blank">%s</a>', __( 'Support', 'post-views-counter' ) ) )
591 );
592 }
593
594 return $links;
595 }
596
597 /**
598 * Add link to settings page.
599 *
600 * @staticvar string $plugin
601 * @param array $links
602 * @param string $file
603 * @return array
604 */
605 public function plugin_action_links( $links, $file ) {
606 if ( ! is_admin() || ! current_user_can( 'manage_options' ) )
607 return $links;
608
609 static $plugin;
610
611 $plugin = plugin_basename( __FILE__ );
612
613 if ( $file == $plugin ) {
614 $settings_link = sprintf( '<a href="%s">%s</a>', admin_url( 'options-general.php' ) . '?page=post-views-counter', __( 'Settings', 'post-views-counter' ) );
615
616 array_unshift( $links, $settings_link );
617 }
618
619 return $links;
620 }
621 }
622
623 endif; // end if class_exists check
624
625 /**
626 * Initialise Post Views Counter.
627 *
628 * @return object
629 */
630 function Post_Views_Counter() {
631 static $instance;
632
633 // first call to instance() initializes the plugin
634 if ( $instance === null || ! ( $instance instanceof Post_Views_Counter ) )
635 $instance = Post_Views_Counter::instance();
636
637 return $instance;
638 }
639
640 Post_Views_Counter();
641