PluginProbe
WebberZone Top 10 — Popular Posts / 4.3.2
WebberZone Top 10 — Popular Posts v4.3.2
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 1.6.1 1.6.2 All 116 releases
top-10 / top-10.php

top-10.php in WebberZone Top 10 — Popular Posts 4.3.2, at top-10.php

232 lines 6.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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.3.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.3.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.0';
168
169 if ( ! function_exists( __NAMESPACE__ . '\\tptn_freemius' ) ) {
170 // Load Freemius.
171 require_once plugin_dir_path( __FILE__ ) . 'load-freemius.php';
172 }
173
174 // Load the autoloader.
175 if ( ! function_exists( __NAMESPACE__ . '\\autoload' ) ) {
176 require_once plugin_dir_path( __FILE__ ) . 'includes/autoloader.php';
177 }
178
179
180 if ( ! function_exists( __NAMESPACE__ . '\wz_top_ten' ) ) {
181 /**
182 * Returns the main instance of Top 10 to prevent the need to use globals.
183 *
184 * @since 4.0.6
185 *
186 * @return Main Main instance of the plugin.
187 */
188 function wz_top_ten(): Main {
189 return Main::get_instance();
190 }
191 }
192
193 if ( ! function_exists( __NAMESPACE__ . '\load_tptn' ) ) {
194 /**
195 * The main function responsible for returning the one true Top 10 instance to functions everywhere.
196 *
197 * @since 3.3.0
198 */
199 function load_tptn(): void {
200 wz_top_ten();
201 }
202 add_action( 'plugins_loaded', __NAMESPACE__ . '\load_tptn' );
203 }
204
205 // Register the activation hook.
206 register_activation_hook( __FILE__, __NAMESPACE__ . '\Admin\Activator::activation_hook' );
207
208 // Register the deactivation hook.
209 register_deactivation_hook( __FILE__, __NAMESPACE__ . '\Admin\Activator::deactivation_hook' );
210
211 /*
212 *----------------------------------------------------------------------------
213 * Include files
214 *----------------------------------------------------------------------------
215 */
216 if ( ! function_exists( 'tptn_get_settings' ) ) {
217 require_once plugin_dir_path( __FILE__ ) . 'includes/options-api.php';
218 require_once plugin_dir_path( __FILE__ ) . 'includes/wz-pluggables.php';
219 require_once plugin_dir_path( __FILE__ ) . 'includes/class-top-ten-query.php';
220 require_once plugin_dir_path( __FILE__ ) . 'includes/functions.php';
221 }
222
223 /**
224 * Global variable holding the current settings for Top 10
225 *
226 * @since 1.9.3
227 *
228 * @var array
229 */
230 global $tptn_settings;
231 $tptn_settings = tptn_get_settings();
232