PluginProbe
WebberZone Top 10 — Popular Posts / 4.5.2
WebberZone Top 10 — Popular Posts v4.5.2
4.5.2 4.5.1 4.5.0 4.4.3 4.4.2 4.4.1 4.4.0 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 trunk 1.0 1.0.1 1.1 1.2 1.3 1.4 1.4.1 1.5 1.5.1 1.5.2 1.5.3 1.6 All 118 releases
← All changes | top-10.php +248 -412 1.5.3 → 4.5.2 View file →
@@ -1,412 +1,248 @@
1 -<?php
2 -/*
3 -Plugin Name: Top 10
4 -Version: 1.5.3
5 -Plugin URI: http://ajaydsouza.com/wordpress/plugins/top-10/
6 -Description: Count daily and total visits per post and display the most popular posts based on the number of views. Based on the plugin by <a href="http://weblogtoolscollection.com">Mark Ghosh</a>
7 -Author: Ajay D'Souza
8 -Author URI: http://ajaydsouza.com/
9 -*/
10 -
11 -if (!defined('ABSPATH')) die("Aren't you supposed to come here via WP-Admin?");
12 -define('ALD_TPTN_DIR', dirname(__FILE__));
13 -define('TPTN_LOCAL_NAME', 'tptn');
14 -
15 -// Pre-2.6 compatibility
16 -if ( ! defined( 'WP_CONTENT_URL' ) )
17 - define( 'WP_CONTENT_URL', get_option( 'siteurl' ) . '/wp-content' );
18 -if ( ! defined( 'WP_CONTENT_DIR' ) )
19 - define( 'WP_CONTENT_DIR', ABSPATH . 'wp-content' );
20 -if ( ! defined( 'WP_PLUGIN_URL' ) )
21 - define( 'WP_PLUGIN_URL', WP_CONTENT_URL. '/plugins' );
22 -if ( ! defined( 'WP_PLUGIN_DIR' ) )
23 - define( 'WP_PLUGIN_DIR', WP_CONTENT_DIR . '/plugins' );
24 -
25 -// Guess the location
26 -$tptn_path = WP_PLUGIN_DIR.'/'.plugin_basename(dirname(__FILE__));
27 -$tptn_url = WP_PLUGIN_URL.'/'.plugin_basename(dirname(__FILE__));
28 -
29 -
30 -
31 -if (!function_exists('add_action')) {
32 - $wp_root = '../../..';
33 - if (file_exists($wp_root.'/wp-load.php')) {
34 - require_once($wp_root.'/wp-load.php');
35 - } else {
36 - require_once($wp_root.'/wp-config.php');
37 - }
38 -}
39 -
40 -global $tptn_db_version;
41 -$tptn_db_version = "2.8";
42 -
43 -function ald_tptn_init() {
44 - //* Begin Localization Code */
45 - $tc_localizationName = TPTN_LOCAL_NAME;
46 - $tc_comments_locale = get_locale();
47 - $tc_comments_mofile = ALD_TPTN_DIR . "/languages/" . $tc_localizationName . "-". $tc_comments_locale.".mo";
48 - load_textdomain($tc_localizationName, $tc_comments_mofile);
49 - //* End Localization Code */
50 -}
51 -add_action('init', 'ald_tptn_init');
52 -
53 -/*********************************************************************
54 -* Main Function (Do not edit) *
55 -********************************************************************/
56 -// Update post views
57 -add_filter('the_content','tptn_add_viewed_count');
58 -function tptn_add_viewed_count($content) {
59 - global $post, $wpdb, $single,$tptn_url,$tptn_path;
60 - $table_name = $wpdb->prefix . "top_ten";
61 - $tptn_settings = tptn_read_options();
62 -
63 - $current_user = wp_get_current_user();
64 - $post_author = ( $current_user->ID == $post->post_author ? true : false );
65 -
66 - if((is_single() || is_page())) {
67 - if (!(($post_author)&&(!$tptn_settings['track_authors']))) {
68 - $id = intval($post->ID);
69 - $output = '<script type="text/javascript" src="'.$tptn_url.'/top-10-addcount.js.php?top_ten_id='.$id.'"></script>';
70 - return $content.$output;
71 - }
72 - else {
73 - return $content;
74 - }
75 - }
76 - else {
77 - return $content;
78 - }
79 -}
80 -
81 -
82 -// Function to add count to content
83 -function tptn_pc_content($content) {
84 - global $single, $post,$tptn_url,$tptn_path;
85 - $tptn_settings = tptn_read_options();
86 - $id = intval($post->ID);
87 -
88 - if((is_single())&&($tptn_settings['add_to_content'])) {
89 - $output = '<script type="text/javascript" src="'.$tptn_url.'/top-10-counter.js.php?top_ten_id='.$id.'"></script>';
90 - return $content.$output;
91 - } elseif((is_page())&&($tptn_settings['count_on_pages'])) {
92 - $output = '<script type="text/javascript" src="'.$tptn_url.'/top-10-counter.js.php?top_ten_id='.$id.'"></script>';
93 - return $content.$output;
94 - } else {
95 - return $content;
96 - }
97 -}
98 -add_filter('the_content', 'tptn_pc_content');
99 -
100 -// Function to manually display count
101 -function echo_tptn_post_count() {
102 - global $post,$tptn_url,$tptn_path;
103 - $id = intval($post->ID);
104 -
105 - $output = '<script type="text/javascript" src="'.$tptn_url.'/top-10-counter.js.php?top_ten_id='.$id.'"></script>';
106 - echo $output;
107 -}
108 -
109 -// Function to return popular posts
110 -function tptn_pop_posts( $daily = false , $widget = false ) {
111 - global $wpdb, $siteurl, $tableposts, $id;
112 - if ($daily) $table_name = $wpdb->prefix . "top_ten_daily";
113 - else $table_name = $wpdb->prefix . "top_ten";
114 - $tptn_settings = tptn_read_options();
115 - $limit = $tptn_settings['limit'];
116 -
117 - if (!$daily) {
118 - $sql = "SELECT postnumber, cntaccess as sumCount, ID, post_type, post_status ";
119 - $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
120 - if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
121 - $sql .= "AND post_status = 'publish' ";
122 - $sql .= "ORDER BY sumCount DESC LIMIT $limit";
123 - } else {
124 - $daily_range = $tptn_settings[daily_range]. ' DAY';
125 - $current_date = $wpdb->get_var("SELECT DATE_ADD(DATE_SUB(CURDATE(), INTERVAL ".$daily_range."), INTERVAL 1 DAY) ");
126 -
127 - $sql = "SELECT postnumber, SUM(cntaccess) as sumCount, dp_date, ID, post_type, post_status ";
128 - $sql .= "FROM $table_name INNER JOIN ". $wpdb->posts ." ON postnumber=ID " ;
129 - if ($tptn_settings['exclude_pages']) $sql .= "AND post_type = 'post' ";
130 - $sql .= "AND post_status = 'publish' AND dp_date >= '$current_date' ";
131 - $sql .= "GROUP BY postnumber ";
132 - $sql .= "ORDER BY sumCount DESC LIMIT $limit";
133 - }
134 - $results = $wpdb->get_results($sql);
135 - $output = '';
136 -
137 - if (!$widget) {
138 - if (!$daily) {
139 - $output .= '<div id="tptn_related">'.$tptn_settings['title'];
140 - } else {
141 - $output .= '<div id="tptn_related_daily">'.$tptn_settings['title_daily'];
142 - }
143 - }
144 -
145 - if ($results) {
146 - $output .= $tptn_settings['before_list'];
147 - foreach ($results as $result) {
148 - $title = trim(stripslashes(get_the_title($result->postnumber)));
149 - $output .= $tptn_settings['before_list_item'];
150 -
151 - if (($tptn_settings['post_thumb_op']=='inline')||($tptn_settings['post_thumb_op']=='thumbs_only')) {
152 - $output .= '<a href="'.get_permalink($result->postnumber).'" rel="bookmark">';
153 - if ((function_exists('has_post_thumbnail')) && (has_post_thumbnail($result->postnumber))) {
154 - $output .= get_the_post_thumbnail( $result->postnumber, array($tptn_settings[thumb_width],$tptn_settings[thumb_height]), array('title' => $title,'alt' => $title));
155 - } else {
156 - $postimage = get_post_meta($result->postnumber, $tptn_settings[thumb_meta], true);
157 - if ($postimage) {
158 - $output .= '<img src="'.$postimage.'" alt="'.$title.'" title="'.$title.'" width="'.$tptn_settings[thumb_width].'" height="'.$tptn_settings[thumb_height].'" />';
159 - } else {
160 - $output .= '<img src="'.$tptn_settings[thumb_default].'" alt="'.$title.'" title="'.$title.'" width="'.$tptn_settings[thumb_width].'" height="'.$tptn_settings[thumb_height].'" />';
161 - }
162 - }
163 - $output .= '</a> ';
164 - }
165 - if (($tptn_settings['post_thumb_op']=='inline')||($tptn_settings['post_thumb_op']=='text_only')) {
166 - $output .= '<a href="'.get_permalink($result->postnumber).'" rel="bookmark">'.$title.'</a>';
167 - }
168 - if ($tptn_settings['disp_list_count']) $output .= ' ('.$result->sumCount.')';
169 - $output .= $tptn_settings['after_list_item'];
170 - }
171 - if ($tptn_settings['show_credit']) $output .= '<li>Popular posts by <a href="http://ajaydsouza.com/wordpress/plugins/top-10/">Top 10 plugin</a></li>';
172 - $output .= $tptn_settings['after_list'];
173 - }
174 - if (!$widget) $output .= '</div>';
175 -
176 - return $output;
177 -}
178 -
179 -// Function to show popular posts
180 -function tptn_show_pop_posts() {
181 - echo tptn_pop_posts(false,false);
182 -}
183 -
184 -// Function to show daily popular posts
185 -function tptn_show_daily_pop_posts() {
186 - global $tptn_url;
187 - $tptn_settings = tptn_read_options();
188 - if ($tptn_settings['d_use_js']) {
189 - echo '<script type="text/javascript" src="'.$tptn_url.'/top-10-daily.js.php?widget=1"></script>';
190 - } else {
191 - echo tptn_pop_posts(true,false);
192 - }
193 -}
194 -
195 -// Create a WordPress Widget for Daily Popular Posts
196 -function widget_tptn_pop_daily($args) {
197 - global $wpdb, $siteurl, $tableposts, $id,$tptn_url;
198 -
199 - extract($args); // extracts before_widget,before_title,after_title,after_widget
200 -
201 - $tptn_settings = tptn_read_options();
202 - $title = (($tptn_settings['title_daily']) ? strip_tags($tptn_settings['title_daily']) : __('Daily Popular',TPTN_LOCAL_NAME));
203 -
204 - echo $before_widget;
205 - echo $before_title.$title.$after_title;
206 -
207 - if ($tptn_settings['d_use_js']) {
208 - echo '<script type="text/javascript" src="'.$tptn_url.'/top-10-daily.js.php?widget=1"></script>';
209 - } else {
210 - echo tptn_pop_posts(true,true);
211 - }
212 -
213 - echo $after_widget;
214 -}
215 -
216 -// Create a WordPress Widget for Popular Posts
217 -function widget_tptn_pop($args) {
218 - global $wpdb, $siteurl, $tableposts, $id;
219 -
220 - extract($args); // extracts before_widget,before_title,after_title,after_widget
221 -
222 - $tptn_settings = tptn_read_options();
223 - $title = (($tptn_settings['title']) ? strip_tags($tptn_settings['title']) : __('Popular Posts',TPTN_LOCAL_NAME));
224 -
225 - echo $before_widget;
226 - echo $before_title.$title.$after_title;
227 - echo tptn_pop_posts(false,true);
228 - echo $after_widget;
229 -}
230 -
231 -// Default Options
232 -function tptn_default_options() {
233 - global $tptn_url;
234 - $title = __('<h3>Popular Posts</h3>',TPTN_LOCAL_NAME);
235 - $title_daily = __('<h3>Daily Popular</h3>',TPTN_LOCAL_NAME);
236 - $thumb_default = $tptn_url.'/default.png';
237 -
238 - $tptn_settings = Array (
239 - show_credit => true, // Add link to plugin page of my blog in top posts list
240 - add_to_content => true, // Add post count to content (only on single posts)
241 - exclude_pages => true, // Exclude Pages
242 - count_on_pages => true, // Display on pages
243 - track_authors => false, // Track Authors visits
244 - pv_in_admin => true, // Add an extra column on edit posts/pages to display page views?
245 - disp_list_count => true, // Display count in popular lists?
246 - d_use_js => false, // Use JavaScript for displaying daily posts
247 - count_disp_form => '(Visited %totalcount% times, %dailycount% visits today)', // Format to display the count
248 - title => $title, // Title of Popular Posts
249 - title_daily => $title_daily, // Title of Daily Popular
250 - limit => '10', // How many posts to display?
251 - daily_range => '1', // Daily Popular will contain posts of how many days?
252 - before_list => '<ul>', // Before the entire list
253 - after_list => '</ul>', // After the entire list
254 - before_list_item => '<li>', // Before each list item
255 - after_list_item => '</li>', // After each list item
256 - post_thumb_op => 'text_only', // Display only text in posts
257 - thumb_height => '100', // Height of thumbnails
258 - thumb_width => '100', // Width of thumbnails
259 - thumb_meta => 'post-image', // Meta field that is used to store the location of default thumbnail image
260 - thumb_default => $thumb_default, // Default thumbnail image
261 - );
262 - return $tptn_settings;
263 -}
264 -
265 -// Function to read options from the database
266 -function tptn_read_options() {
267 -
268 - // Upgrade table code
269 - global $tptn_db_version;
270 - $installed_ver = get_option( "tptn_db_version" );
271 -
272 - if( $installed_ver != $tptn_db_version ) tptn_install();
273 -
274 - $tptn_settings_changed = false;
275 -
276 - $defaults = tptn_default_options();
277 -
278 - $tptn_settings = array_map('stripslashes',(array)get_option('ald_tptn_settings'));
279 - unset($tptn_settings[0]); // produced by the (array) casting when there's nothing in the DB
280 -
281 - foreach ($defaults as $k=>$v) {
282 - if (!isset($tptn_settings[$k])) {
283 - $tptn_settings[$k] = $v;
284 - $tptn_settings_changed = true;
285 - }
286 - }
287 - if ($tptn_settings_changed == true)
288 - update_option('ald_tptn_settings', $tptn_settings);
289 -
290 - return $tptn_settings;
291 -
292 -}
293 -
294 -// Create tables to store pageviews
295 -function tptn_install() {
296 - global $wpdb;
297 - global $tptn_db_version;
298 -
299 - $table_name = $wpdb->prefix . "top_ten";
300 - $table_name_daily = $wpdb->prefix . "top_ten_daily";
301 -
302 - if($wpdb->get_var("show tables like '$table_name'") != $table_name) {
303 -
304 - $sql = "CREATE TABLE " . $table_name . " (
305 - accessedid int NOT NULL AUTO_INCREMENT,
306 - postnumber int NOT NULL,
307 - cntaccess int NOT NULL,
308 - PRIMARY KEY (accessedid)
309 - );";
310 -
311 - require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
312 - dbDelta($sql);
313 -
314 - add_option("tptn_db_version", $tptn_db_version);
315 - }
316 -
317 - if($wpdb->get_var("show tables like '$table_name_daily'") != $table_name_daily) {
318 -
319 - $sql = "CREATE TABLE " . $table_name_daily . " (
320 - accessedid int NOT NULL AUTO_INCREMENT,
321 - postnumber int NOT NULL,
322 - cntaccess int NOT NULL,
323 - dp_date date NOT NULL,
324 - PRIMARY KEY (accessedid)
325 - );";
326 -
327 - require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
328 - dbDelta($sql);
329 -
330 - add_option("tptn_db_version", $tptn_db_version);
331 - }
332 -
333 - // Upgrade table code
334 - $installed_ver = get_option( "tptn_db_version" );
335 -
336 - if( $installed_ver != $tptn_db_version ) {
337 -
338 - $sql = "CREATE TABLE " . $table_name . " (
339 - accessedid int NOT NULL AUTO_INCREMENT,
340 - postnumber int NOT NULL,
341 - cntaccess int NOT NULL,
342 - PRIMARY KEY (accessedid)
343 - );";
344 -
345 - require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
346 - dbDelta($sql);
347 -
348 - $sql = "DROP TABLE $table_name_daily";
349 - $wpdb->query($sql);
350 -
351 - $sql = "CREATE TABLE " . $table_name_daily . " (
352 - accessedid int NOT NULL AUTO_INCREMENT,
353 - postnumber int NOT NULL,
354 - cntaccess int NOT NULL,
355 - dp_date date NOT NULL,
356 - PRIMARY KEY (accessedid)
357 - );";
358 -
359 - require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
360 - dbDelta($sql);
361 -
362 - update_option( "tptn_db_version", $tptn_db_version );
363 - }
364 -
365 -}
366 -if (function_exists('register_activation_hook')) {
367 - register_activation_hook(__FILE__,'tptn_install');
368 -}
369 -
370 -
371 -// Function to delete all rows in the posts table
372 -function tptn_trunc_count($daily = false) {
373 - global $wpdb;
374 - $table_name = $wpdb->prefix . "top_ten";
375 - if ($daily) $table_name .= "_daily";
376 -
377 - $sql = "TRUNCATE TABLE $table_name";
378 - $wpdb->query($sql);
379 -}
380 -
381 -
382 -function init_tptn(){
383 - register_sidebar_widget(__('Popular Posts',TPTN_LOCAL_NAME), 'widget_tptn_pop');
384 - register_sidebar_widget(__('Daily Popular',TPTN_LOCAL_NAME), 'widget_tptn_pop_daily');
385 -}
386 -add_action("plugins_loaded", "init_tptn");
387 -
388 -// This function adds an Options page in WP Admin
389 -if (is_admin() || strstr($_SERVER['PHP_SELF'], 'wp-admin/')) {
390 - require_once(ALD_TPTN_DIR . "/admin.inc.php");
391 -
392 -// Add meta links
393 -function tptn_plugin_actions( $links, $file ) {
394 - $plugin = plugin_basename(__FILE__);
395 -
396 - // create link
397 - if ($file == $plugin) {
398 - $links[] = '<a href="' . admin_url( 'options-general.php?page=tptn_options' ) . '">' . __('Settings', tptn_LOCAL_NAME ) . '</a>';
399 - $links[] = '<a href="http://ajaydsouza.org">' . __('Support', tptn_LOCAL_NAME ) . '</a>';
400 - $links[] = '<a href="http://ajaydsouza.com/donate/">' . __('Donate', tptn_LOCAL_NAME ) . '</a>';
401 - }
402 - return $links;
403 -}
404 -global $wp_version;
405 -if ( version_compare( $wp_version, '2.8alpha', '>' ) )
406 - add_filter( 'plugin_row_meta', 'tptn_plugin_actions', 10, 2 ); // only 2.8 and higher
407 -else add_filter( 'plugin_action_links', 'tptn_plugin_actions', 10, 2 );
408 -
409 -}
410 -
411 -
412 -?>
1 +<?php
2 +/**
3 + * Top 10.
4 + *
5 + * Count daily and total visits per post and display the most popular posts based on the number of views.
6 + *
7 + * @package Top_Ten
8 + * @author Ajay D'Souza
9 + * @license GPL-2.0+
10 + * @link https://webberzone.com
11 + * @copyright 2008-2026 Ajay D'Souza
12 + *
13 + * @wordpress-plugin
14 + * Plugin Name: WebberZone Top 10
15 + * Plugin URI: https://webberzone.com/plugins/top-10/
16 + * Description: Count daily and total visits per post and display the most popular posts based on the number of views
17 + * Version: 4.5.2
18 + * Author: WebberZone
19 + * Author URI: https://webberzone.com
20 + * License: GPL-2.0+
21 + * License URI: http://www.gnu.org/licenses/gpl-2.0.txt
22 + * Text Domain: top-10
23 + * Domain Path: /languages
24 + * GitHub Plugin URI: https://github.com/WebberZone/top-10/
25 + */
26 +
27 +namespace WebberZone\Top_Ten;
28 +
29 +if ( ! defined( 'WPINC' ) ) {
30 + die;
31 +}
32 +
33 +/**
34 + * Holds the version of Top 10.
35 + *
36 + * @since 3.1.0
37 + */
38 +if ( ! defined( 'TOP_TEN_VERSION' ) ) {
39 + define( 'TOP_TEN_VERSION', '4.5.2' );
40 +}
41 +
42 +/**
43 + * Holds the filesystem directory path (with trailing slash) for Top 10
44 +*
45 + * @since 2.3.0
46 + */
47 +if ( ! defined( 'TOP_TEN_PLUGIN_FILE' ) ) {
48 + define( 'TOP_TEN_PLUGIN_FILE', __FILE__ );
49 +}
50 +
51 +/**
52 + * Holds the filesystem directory path (with trailing slash) for Top 10
53 + *
54 + * @since 2.3.0
55 + */
56 +if ( ! defined( 'TOP_TEN_PLUGIN_DIR' ) ) {
57 + define( 'TOP_TEN_PLUGIN_DIR', plugin_dir_path( TOP_TEN_PLUGIN_FILE ) );
58 +}
59 +
60 +/**
61 + * Holds the filesystem directory path (with trailing slash) for Top 10
62 + *
63 + * @since 2.3.0
64 + */
65 +if ( ! defined( 'TOP_TEN_PLUGIN_URL' ) ) {
66 + define( 'TOP_TEN_PLUGIN_URL', plugin_dir_url( TOP_TEN_PLUGIN_FILE ) );
67 +}
68 +
69 +/**
70 + * Holds the default thumbnail URL for Top 10.
71 + *
72 + * @since 4.2.0
73 + */
74 +if ( ! defined( 'TOP_TEN_DEFAULT_THUMBNAIL_URL' ) ) {
75 + define( 'TOP_TEN_DEFAULT_THUMBNAIL_URL', TOP_TEN_PLUGIN_URL . 'default.png' );
76 +}
77 +
78 +/**
79 + * Number of days of data to be saved in the daily tables.
80 + *
81 + * @since 3.0.0
82 + */
83 +if ( ! defined( 'TOP_TEN_STORE_DATA' ) ) {
84 + define( 'TOP_TEN_STORE_DATA', 180 );
85 +}
86 +
87 +/**
88 + * Number of days of raw visit rows to retain in the visits log table.
89 + *
90 + * @since 4.3.0
91 + */
92 +if ( ! defined( 'TOP_TEN_LOG_STORE_DATA' ) ) {
93 + define( 'TOP_TEN_LOG_STORE_DATA', 30 );
94 +}
95 +
96 +if ( ! function_exists( __NAMESPACE__ . '\\tptn_deactivate_other_instances' ) ) {
97 + /**
98 + * Deactivate other instances of Top 10 when this plugin is activated.
99 + *
100 + * @param string $plugin The plugin being activated.
101 + * @param bool $network_wide Whether the plugin is being activated network-wide.
102 + */
103 + function tptn_deactivate_other_instances( $plugin, $network_wide = false ) {
104 + $free_plugin = 'top-10/top-10.php';
105 + $pro_plugin = 'top-10-pro/top-10.php';
106 +
107 + // Only proceed if one of our plugins is being activated.
108 + if ( ! in_array( $plugin, array( $free_plugin, $pro_plugin ), true ) ) {
109 + return;
110 + }
111 +
112 + $plugins_to_deactivate = array();
113 + $deactivated_plugin = '';
114 +
115 + // If pro is being activated, deactivate free.
116 + if ( $pro_plugin === $plugin ) {
117 + if ( is_plugin_active( $free_plugin ) || ( $network_wide && is_plugin_active_for_network( $free_plugin ) ) ) {
118 + $plugins_to_deactivate[] = $free_plugin;
119 + $deactivated_plugin = 'Top 10';
120 + }
121 + }
122 +
123 + // If free is being activated, deactivate pro.
124 + if ( $free_plugin === $plugin ) {
125 + if ( is_plugin_active( $pro_plugin ) || ( $network_wide && is_plugin_active_for_network( $pro_plugin ) ) ) {
126 + $plugins_to_deactivate[] = $pro_plugin;
127 + $deactivated_plugin = 'Top 10 Pro';
128 + }
129 + }
130 +
131 + if ( ! empty( $plugins_to_deactivate ) ) {
132 + deactivate_plugins( $plugins_to_deactivate, false, $network_wide );
133 + set_transient( 'tptn_deactivated_notice', $deactivated_plugin, 1 * HOUR_IN_SECONDS );
134 + }
135 + }
136 + add_action( 'activated_plugin', __NAMESPACE__ . '\\tptn_deactivate_other_instances', 10, 2 );
137 +}
138 +
139 +// Show admin notice about automatic deactivation.
140 +if ( ! has_action( 'admin_notices', __NAMESPACE__ . '\\tptn_show_deactivation_notice' ) ) {
141 + add_action(
142 + 'admin_notices',
143 + function () {
144 + $deactivated_plugin = get_transient( 'tptn_deactivated_notice' );
145 + if ( $deactivated_plugin ) {
146 + /* translators: %s: Name of the deactivated plugin */
147 + $message = sprintf( __( "Top 10 and Top 10 PRO should not be active at the same time. We've automatically deactivated %s.", 'top-10' ), $deactivated_plugin );
148 + ?>
149 + <div class="updated" style="border-left: 4px solid #ffba00;">
150 + <p><?php echo esc_html( $message ); ?></p>
151 + </div>
152 + <?php
153 + delete_transient( 'tptn_deactivated_notice' );
154 + }
155 + }
156 + );
157 +}
158 +
159 +/**
160 + * Global variable holding the current database version of Top 10
161 + *
162 + * @since 1.0
163 + *
164 + * @var string
165 + */
166 +global $tptn_db_version;
167 +$tptn_db_version = '7.3';
168 +
169 +// Load the Composer autoloader (includes the Freemius SDK).
170 +$composer_autoload = plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';
171 +if ( file_exists( $composer_autoload ) ) {
172 + require_once $composer_autoload;
173 +}
174 +
175 +if ( ! function_exists( __NAMESPACE__ . '\\tptn_freemius' ) ) {
176 + // Load Freemius.
177 + require_once plugin_dir_path( __FILE__ ) . 'load-freemius.php';
178 +}
179 +
180 +// Load the autoloader.
181 +if ( ! function_exists( __NAMESPACE__ . '\\autoload' ) ) {
182 + require_once plugin_dir_path( __FILE__ ) . 'includes/autoloader.php';
183 +}
184 +
185 +// Load the CrawlerDetect library (bundled directly; not via the Composer autoloader).
186 +$tptn_crawler_detect_src = plugin_dir_path( __FILE__ ) . 'vendor/jaybizzle/crawler-detect/src/';
187 +if ( ! class_exists( '\Jaybizzle\CrawlerDetect\CrawlerDetect' ) && is_dir( $tptn_crawler_detect_src ) ) {
188 + require_once $tptn_crawler_detect_src . 'Fixtures/AbstractProvider.php';
189 + require_once $tptn_crawler_detect_src . 'Fixtures/Crawlers.php';
190 + require_once $tptn_crawler_detect_src . 'Fixtures/Exclusions.php';
191 + require_once $tptn_crawler_detect_src . 'Fixtures/Headers.php';
192 + require_once $tptn_crawler_detect_src . 'CrawlerDetect.php';
193 +}
194 +unset( $tptn_crawler_detect_src );
195 +
196 +
197 +if ( ! function_exists( __NAMESPACE__ . '\wz_top_ten' ) ) {
198 + /**
199 + * Returns the main instance of Top 10 to prevent the need to use globals.
200 + *
201 + * @since 4.0.6
202 + *
203 + * @return Main Main instance of the plugin.
204 + */
205 + function wz_top_ten(): Main {
206 + return Main::get_instance();
207 + }
208 +}
209 +
210 +if ( ! function_exists( __NAMESPACE__ . '\load_tptn' ) ) {
211 + /**
212 + * The main function responsible for returning the one true Top 10 instance to functions everywhere.
213 + *
214 + * @since 3.3.0
215 + */
216 + function load_tptn(): void {
217 + wz_top_ten();
218 + }
219 + add_action( 'plugins_loaded', __NAMESPACE__ . '\load_tptn' );
220 +}
221 +
222 +// Register the activation hook.
223 +register_activation_hook( __FILE__, __NAMESPACE__ . '\Admin\Activator::activation_hook' );
224 +
225 +// Register the deactivation hook.
226 +register_deactivation_hook( __FILE__, __NAMESPACE__ . '\Admin\Activator::deactivation_hook' );
227 +
228 +/*
229 + *----------------------------------------------------------------------------
230 + * Include files
231 + *----------------------------------------------------------------------------
232 + */
233 +if ( ! function_exists( 'tptn_get_settings' ) ) {
234 + require_once plugin_dir_path( __FILE__ ) . 'includes/options-api.php';
235 + require_once plugin_dir_path( __FILE__ ) . 'includes/wz-pluggables.php';
236 + require_once plugin_dir_path( __FILE__ ) . 'includes/class-top-ten-query.php';
237 + require_once plugin_dir_path( __FILE__ ) . 'includes/functions.php';
238 +}
239 +
240 +/**
241 + * Global variable holding the current settings for Top 10
242 + *
243 + * @since 1.9.3
244 + *
245 + * @var array
246 + */
247 +global $tptn_settings;
248 +$tptn_settings = tptn_get_settings();