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