class-wordpress-popular-posts-activator.php
8 years ago
class-wordpress-popular-posts-deactivator.php
8 years ago
class-wordpress-popular-posts-helper.php
8 years ago
class-wordpress-popular-posts-i18n.php
8 years ago
class-wordpress-popular-posts-image.php
8 years ago
class-wordpress-popular-posts-loader.php
8 years ago
class-wordpress-popular-posts-output.php
8 years ago
class-wordpress-popular-posts-query.php
8 years ago
class-wordpress-popular-posts-rest-controller.php
8 years ago
class-wordpress-popular-posts-settings.php
8 years ago
class-wordpress-popular-posts-template.php
8 years ago
class-wordpress-popular-posts-translate.php
8 years ago
class-wordpress-popular-posts-widget.php
8 years ago
class-wordpress-popular-posts.php
8 years ago
widget-form.php
8 years ago
class-wordpress-popular-posts.php
242 lines
| 1 | <?php |
| 2 | |
| 3 | class WordPressPopularPosts { |
| 4 | |
| 5 | /** |
| 6 | * The unique identifier of this plugin. |
| 7 | * |
| 8 | * @since 4.0.0 |
| 9 | * @access protected |
| 10 | * @var string $plugin_name |
| 11 | */ |
| 12 | protected $plugin_name; |
| 13 | |
| 14 | /** |
| 15 | * The current version of this plugin. |
| 16 | * |
| 17 | * @since 4.0.0 |
| 18 | * @access protected |
| 19 | * @var string $version |
| 20 | */ |
| 21 | protected $version; |
| 22 | |
| 23 | /** |
| 24 | * Constructor. |
| 25 | * |
| 26 | * @since 4.0.0 |
| 27 | */ |
| 28 | public function __construct(){ |
| 29 | |
| 30 | $this->plugin_name = 'wordpress-popular-posts'; |
| 31 | $this->version = WPP_VER; |
| 32 | |
| 33 | $this->load_dependencies(); |
| 34 | $this->set_locale(); |
| 35 | $this->define_admin_hooks(); |
| 36 | $this->define_public_hooks(); |
| 37 | |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Loads the required dependencies for this plugin. |
| 42 | * |
| 43 | * @since 4.0.0 |
| 44 | * @access private |
| 45 | */ |
| 46 | private function load_dependencies(){ |
| 47 | |
| 48 | /** |
| 49 | * The class responsible for defining internationalization functionality of the plugin. |
| 50 | */ |
| 51 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordpress-popular-posts-i18n.php'; |
| 52 | |
| 53 | /** |
| 54 | * The class responsible for translating objects. |
| 55 | */ |
| 56 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordpress-popular-posts-translate.php'; |
| 57 | |
| 58 | /** |
| 59 | * Settings class. |
| 60 | */ |
| 61 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordpress-popular-posts-settings.php'; |
| 62 | |
| 63 | /** |
| 64 | * Helper class. |
| 65 | */ |
| 66 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordpress-popular-posts-helper.php'; |
| 67 | |
| 68 | /** |
| 69 | * Template functions. |
| 70 | */ |
| 71 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordpress-popular-posts-template.php'; |
| 72 | |
| 73 | /** |
| 74 | * The class responsible for handling the actions and filters of the plugin. |
| 75 | */ |
| 76 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordpress-popular-posts-loader.php'; |
| 77 | |
| 78 | /** |
| 79 | * The class responsible for querying the database. |
| 80 | */ |
| 81 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordpress-popular-posts-query.php'; |
| 82 | |
| 83 | /** |
| 84 | * The class responsible for creating images. |
| 85 | */ |
| 86 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordpress-popular-posts-image.php'; |
| 87 | |
| 88 | /** |
| 89 | * The class responsible for building the HTML output. |
| 90 | */ |
| 91 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordpress-popular-posts-output.php'; |
| 92 | |
| 93 | /** |
| 94 | * The widget class. |
| 95 | */ |
| 96 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordpress-popular-posts-widget.php'; |
| 97 | |
| 98 | /** |
| 99 | * The class responsible for defining all actions that occur on the admin-facing side of the site. |
| 100 | */ |
| 101 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'admin/class-wordpress-popular-posts-admin.php'; |
| 102 | |
| 103 | /** |
| 104 | * The class responsible for defining all actions that occur on the public-facing side of the site. |
| 105 | */ |
| 106 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'public/class-wordpress-popular-posts-public.php'; |
| 107 | |
| 108 | /** |
| 109 | * The REST API controller class for the popular posts endpoing. |
| 110 | */ |
| 111 | if ( class_exists('WP_REST_Controller', false) ) { |
| 112 | require_once plugin_dir_path( dirname( __FILE__ ) ) . 'includes/class-wordpress-popular-posts-rest-controller.php'; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Get loader. |
| 117 | */ |
| 118 | $this->loader = new WPP_Loader(); |
| 119 | |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Register all of the hooks related to the admin area functionality of the plugin. |
| 124 | * |
| 125 | * @since 4.0.0 |
| 126 | * @access private |
| 127 | */ |
| 128 | public function define_admin_hooks() { |
| 129 | |
| 130 | $plugin_admin = new WPP_Admin( $this->get_plugin_name(), $this->get_version() ); |
| 131 | |
| 132 | // Check admin notices |
| 133 | $this->loader->add_action( 'admin_notices', $plugin_admin, 'check_admin_notices' ); |
| 134 | // Upgrade check |
| 135 | $this->loader->add_action( 'init', $plugin_admin, 'upgrade_check' ); |
| 136 | // Hook fired when a new blog is activated on WP Multisite |
| 137 | $this->loader->add_action( 'wpmu_new_blog', $plugin_admin, 'activate_new_site' ); |
| 138 | // Hook fired when a blog is deleted on WP Multisite |
| 139 | $this->loader->add_filter( 'wpmu_drop_tables', $plugin_admin, 'delete_site_data', 10, 2 ); |
| 140 | // At-A-Glance |
| 141 | $this->loader->add_filter( 'dashboard_glance_items', $plugin_admin, 'at_a_glance_stats' ); |
| 142 | $this->loader->add_action( 'admin_head', $plugin_admin, 'at_a_glance_stats_css' ); |
| 143 | // Load WPP's admin styles and scripts |
| 144 | $this->loader->add_action( 'admin_print_styles', $plugin_admin, 'enqueue_styles' ); |
| 145 | $this->loader->add_action( 'admin_enqueue_scripts', $plugin_admin, 'enqueue_scripts' ); |
| 146 | // Add admin screen |
| 147 | $this->loader->add_action( 'admin_menu', $plugin_admin, 'add_plugin_admin_menu' ); |
| 148 | // Contextual help |
| 149 | $this->loader->add_action( 'admin_head', $plugin_admin, 'add_contextual_help' ); |
| 150 | // Add plugin settings link |
| 151 | $this->loader->add_filter( 'plugin_action_links', $plugin_admin, 'add_plugin_settings_link', 10, 2 ); |
| 152 | // Update chart |
| 153 | $this->loader->add_action( 'wp_ajax_wpp_update_chart', $plugin_admin, 'update_chart' ); |
| 154 | // Get lists |
| 155 | $this->loader->add_action( 'wp_ajax_wpp_get_most_viewed', $plugin_admin, 'get_most_viewed' ); |
| 156 | $this->loader->add_action( 'wp_ajax_wpp_get_most_commented', $plugin_admin, 'get_most_commented' ); |
| 157 | // Delete plugin data |
| 158 | $this->loader->add_action( 'wp_ajax_wpp_clear_data', $plugin_admin, 'clear_data' ); |
| 159 | // Empty plugin's images cache |
| 160 | $this->loader->add_action( 'wp_ajax_wpp_clear_thumbnail', $plugin_admin, 'clear_thumbnails' ); |
| 161 | // Flush cached thumbnail on featured image change |
| 162 | $this->loader->add_action( 'update_postmeta', $plugin_admin, 'flush_post_thumbnail', 10, 4 ); |
| 163 | // Purge post data on post/page deletion |
| 164 | $this->loader->add_action( 'admin_init', $plugin_admin, 'purge_post_data' ); |
| 165 | // Purge old data on demand |
| 166 | $this->loader->add_action( 'wpp_cache_event', $plugin_admin, 'purge_data' ); |
| 167 | // Initialize widget |
| 168 | $this->loader->add_action( 'widgets_init', $plugin_admin, 'register_widget' ); |
| 169 | |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * Register all of the hooks related to the public area functionality of the plugin. |
| 174 | * |
| 175 | * @since 4.0.0 |
| 176 | * @access private |
| 177 | */ |
| 178 | public function define_public_hooks() { |
| 179 | |
| 180 | $plugin_public = new WPP_Public( $this->get_plugin_name(), $this->get_version() ); |
| 181 | |
| 182 | // Register logging AJAX hook |
| 183 | $this->loader->add_action( 'wp_ajax_update_views_ajax', $plugin_public, 'update_views' ); |
| 184 | $this->loader->add_action( 'wp_ajax_nopriv_update_views_ajax', $plugin_public, 'update_views' ); |
| 185 | // Add WPP's stylesheet and scripts |
| 186 | $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_styles' ); |
| 187 | $this->loader->add_action( 'wp_enqueue_scripts', $plugin_public, 'enqueue_scripts' ); |
| 188 | // Add [wpp] shortcode |
| 189 | $this->loader->add_shortcode( 'wpp', $plugin_public, 'wpp_shortcode' ); |
| 190 | // Register the REST route |
| 191 | $this->loader->add_action( 'rest_api_init', $plugin_public, 'init_rest_route' ); |
| 192 | |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * Define the locale for this plugin for internationalization. |
| 197 | * |
| 198 | * Uses the Plugin_Name_i18n class in order to set the domain and to register the hook |
| 199 | * with WordPress. |
| 200 | * |
| 201 | * @since 4.0.0 |
| 202 | * @access private |
| 203 | */ |
| 204 | private function set_locale() { |
| 205 | |
| 206 | $plugin_i18n = new WPP_i18n(); |
| 207 | $this->loader->add_action( 'plugins_loaded', $plugin_i18n, 'load_plugin_textdomain' ); |
| 208 | |
| 209 | } |
| 210 | |
| 211 | /** |
| 212 | * The name of the plugin used to uniquely identify it within the context of |
| 213 | * WordPress and to define internationalization functionality. |
| 214 | * |
| 215 | * @since 4.0.0 |
| 216 | * @return string The name of the plugin. |
| 217 | */ |
| 218 | public function get_plugin_name() { |
| 219 | return $this->plugin_name; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * Retrieve the version number of the plugin. |
| 224 | * |
| 225 | * @since 4.0.0 |
| 226 | * @return string The version number of the plugin. |
| 227 | */ |
| 228 | public function get_version() { |
| 229 | return $this->version; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * Run the loader to execute all of the hooks with WordPress. |
| 234 | * |
| 235 | * @since 4.0.0 |
| 236 | */ |
| 237 | public function run() { |
| 238 | $this->loader->run(); |
| 239 | } |
| 240 | |
| 241 | } // End WordPressPopularPosts class |
| 242 |