PluginProbe
WP-PostViews / 2.0.0
WP-PostViews v2.0.0
2.0.1 2.0.0 1.01 1.02 1.10 1.11 1.20 1.30 1.31 1.40 1.50 1.66 1.67 1.68 1.69 1.70 1.71 1.72 1.73 1.74 1.75 1.76 1.76.1 1.77 1.78 All 29 releases
wp-postviews / wp-postviews.php

wp-postviews.php in WP-PostViews 2.0.0, at wp-postviews.php

146 lines 4.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: WP-PostViews
4 * Plugin URI: https://lesterchan.net/portfolio/programming/php/
5 * Description: Enables you to display how many times a post/page had been viewed.
6 * Version: 2.0.0
7 * Requires at least: 6.8
8 * Requires PHP: 8.2
9 * Author: Lester 'GaMerZ' Chan
10 * Author URI: https://lesterchan.net
11 * License: GPLv2 or later
12 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
13 * Text Domain: wp-postviews
14 * Domain Path: /languages
15 *
16 * @package WP-PostViews
17 */
18
19 /*
20 Copyright 2026 Lester Chan (email : lesterchan@gmail.com)
21
22 This program is free software; you can redistribute it and/or modify
23 it under the terms of the GNU General Public License as published by
24 the Free Software Foundation; either version 2 of the License, or
25 (at your option) any later version.
26
27 This program is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU General Public License for more details.
31
32 You should have received a copy of the GNU General Public License
33 along with this program; if not, write to the Free Software
34 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
35 */
36
37 // Exit if accessed directly.
38 if ( ! defined( 'ABSPATH' ) ) {
39 exit;
40 }
41
42 /**
43 * WP-PostViews version. Compared against the 'plugin' marker in wp_postviews_version.
44 */
45 define( 'WP_POSTVIEWS_VERSION', '2.0.0' );
46
47 /**
48 * Schema counter. Compared against the 'db' marker in wp_postviews_version.
49 *
50 * Starts at 1: the plugin owns no table, and the row it did keep before 2.0.0
51 * held a plugin version string rather than a counter, so there is no earlier
52 * number an install could be told it had gone backwards from.
53 */
54 define( 'WP_POSTVIEWS_DB_VERSION', '1' );
55
56 /**
57 * Plugin slug, text domain and menu slug.
58 */
59 define( 'WP_POSTVIEWS_SLUG', 'wp-postviews' );
60
61 /**
62 * WP-PostViews main file.
63 */
64 define( 'WP_POSTVIEWS_MAIN_FILE', __FILE__ );
65
66 /**
67 * Filesystem path of the plugin directory, with a trailing slash.
68 */
69 define( 'WP_POSTVIEWS_DIR', plugin_dir_path( __FILE__ ) );
70
71 /**
72 * URL of the plugin directory, with a trailing slash.
73 */
74 define( 'WP_POSTVIEWS_URL', plugin_dir_url( __FILE__ ) );
75
76 // Classes. Required at file load because the activation hook and the option
77 // accessor are both reached before any action fires.
78 require_once WP_POSTVIEWS_DIR . 'includes/class-wp-postviews-options.php';
79 require_once WP_POSTVIEWS_DIR . 'includes/class-wp-postviews-display.php';
80 require_once WP_POSTVIEWS_DIR . 'includes/class-wp-postviews-query.php';
81 require_once WP_POSTVIEWS_DIR . 'includes/class-wp-postviews-counter.php';
82 require_once WP_POSTVIEWS_DIR . 'includes/class-wp-postviews-blocks.php';
83 require_once WP_POSTVIEWS_DIR . 'includes/class-wp-postviews-core.php';
84 require_once WP_POSTVIEWS_DIR . 'includes/class-wp-postviews-api.php';
85 require_once WP_POSTVIEWS_DIR . 'includes/class-wp-postviews-widget.php';
86 require_once WP_POSTVIEWS_DIR . 'includes/class-wp-postviews-admin.php';
87 require_once WP_POSTVIEWS_DIR . 'includes/class-wp-postviews-settings.php';
88 require_once WP_POSTVIEWS_DIR . 'includes/class-wp-postviews-wpstats.php';
89 require_once WP_POSTVIEWS_DIR . 'includes/template-tags.php';
90
91 WP_PostViews_Options::init();
92 WP_PostViews_Display::init();
93 WP_PostViews_Counter::init();
94 WP_PostViews_Blocks::init();
95 WP_PostViews_Core::init();
96 new WP_PostViews_API();
97 WP_PostViews_Core::register_command();
98 WP_PostViews_Admin::init();
99 WP_PostViews_Settings::init();
100
101 // Loaded and initialised unconditionally. WP-Stats may not be installed, in
102 // which case nothing fires wp_stats_sections and this is inert - there is no
103 // class_exists() probing between the two plugins.
104 WP_PostViews_WPStats::init();
105
106 add_action(
107 'widgets_init',
108 function () {
109 register_widget( 'WP_PostViews_Widget' );
110 }
111 );
112
113 // register_activation_hook() has to be called while the plugin file is being
114 // loaded, which is why this is here rather than inside a class initialiser.
115 register_activation_hook( __FILE__, 'wp_postviews_activate' );
116
117 /**
118 * Seed the options row, on this site or across the network.
119 *
120 * @param bool $network_wide Whether the plugin is being activated network wide.
121 * @return void
122 */
123 function wp_postviews_activate( $network_wide ) {
124 if ( is_multisite() && $network_wide ) {
125 // get_sites(), not the wp_get_sites() this used to call: that one has
126 // been deprecated since WP 4.6 and returns only the first 100 sites.
127 // 'number' => 0 lifts WP_Site_Query's own default cap of 100 too.
128 $site_ids = get_sites(
129 array(
130 'fields' => 'ids',
131 'number' => 0,
132 )
133 );
134
135 foreach ( $site_ids as $site_id ) {
136 switch_to_blog( (int) $site_id );
137 WP_PostViews_Options::install();
138 restore_current_blog();
139 }
140
141 return;
142 }
143
144 WP_PostViews_Options::install();
145 }
146