| 1 |
<?php |
| 2 |
/** |
| 3 |
* Admin class. |
| 4 |
* |
| 5 |
* @package WebberZone\Top_Ten\Admin |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace WebberZone\Top_Ten\Admin; |
| 9 |
|
| 10 |
use WebberZone\Top_Ten\Util\Cache; |
| 11 |
use WebberZone\Top_Ten\Admin\Settings_Wizard; |
| 12 |
use WebberZone\Top_Ten\Admin\Admin_Notices_API; |
| 13 |
use WebberZone\Top_Ten\Util\Hook_Registry; |
| 14 |
|
| 15 |
// If this file is called directly, abort. |
| 16 |
if ( ! defined( 'WPINC' ) ) { |
| 17 |
die; |
| 18 |
} |
| 19 |
|
| 20 |
/** |
| 21 |
* Bootstraps the Top 10 admin area and its sub-classes. |
| 22 |
* |
| 23 |
* @since 3.3.0 |
| 24 |
*/ |
| 25 |
class Admin { |
| 26 |
|
| 27 |
/** |
| 28 |
* Admin Dashboard. |
| 29 |
* |
| 30 |
* @since 3.3.0 |
| 31 |
* |
| 32 |
* @var object Admin Dashboard. |
| 33 |
*/ |
| 34 |
public $admin_dashboard; |
| 35 |
|
| 36 |
/** |
| 37 |
* Settings API. |
| 38 |
* |
| 39 |
* @since 3.3.0 |
| 40 |
* |
| 41 |
* @var object Settings API. |
| 42 |
*/ |
| 43 |
public $settings; |
| 44 |
|
| 45 |
/** |
| 46 |
* Settings Wizard. |
| 47 |
* |
| 48 |
* @since 4.2.0 |
| 49 |
* |
| 50 |
* @var Settings_Wizard Settings Wizard instance. |
| 51 |
*/ |
| 52 |
public $settings_wizard; |
| 53 |
|
| 54 |
/** |
| 55 |
* Statistics table. |
| 56 |
* |
| 57 |
* @since 3.3.0 |
| 58 |
* |
| 59 |
* @var object Statistics table. |
| 60 |
*/ |
| 61 |
public $statistics; |
| 62 |
|
| 63 |
/** |
| 64 |
* Activator class. |
| 65 |
* |
| 66 |
* @since 3.3.0 |
| 67 |
* |
| 68 |
* @var object Activator class. |
| 69 |
*/ |
| 70 |
public $activator; |
| 71 |
|
| 72 |
/** |
| 73 |
* Admin Columns. |
| 74 |
* |
| 75 |
* @since 3.3.0 |
| 76 |
* |
| 77 |
* @var object Admin Columns. |
| 78 |
*/ |
| 79 |
public $admin_columns; |
| 80 |
|
| 81 |
/** |
| 82 |
* Metabox functions. |
| 83 |
* |
| 84 |
* @since 3.3.0 |
| 85 |
* |
| 86 |
* @var object Metabox functions. |
| 87 |
*/ |
| 88 |
public $metabox; |
| 89 |
|
| 90 |
/** |
| 91 |
* Import Export functions. |
| 92 |
* |
| 93 |
* @since 3.3.0 |
| 94 |
* |
| 95 |
* @var object Import Export functions. |
| 96 |
*/ |
| 97 |
public $import_export; |
| 98 |
|
| 99 |
/** |
| 100 |
* Tools page. |
| 101 |
* |
| 102 |
* @since 3.3.0 |
| 103 |
* |
| 104 |
* @var object Tools page. |
| 105 |
*/ |
| 106 |
public $tools_page; |
| 107 |
|
| 108 |
/** |
| 109 |
* Dashboard widgets. |
| 110 |
* |
| 111 |
* @since 3.3.0 |
| 112 |
* |
| 113 |
* @var object Dashboard widgets. |
| 114 |
*/ |
| 115 |
public $dashboard_widgets; |
| 116 |
|
| 117 |
/** |
| 118 |
* Cache. |
| 119 |
* |
| 120 |
* @since 3.3.0 |
| 121 |
* |
| 122 |
* @var object Cache. |
| 123 |
*/ |
| 124 |
public $cache; |
| 125 |
|
| 126 |
/** |
| 127 |
* Admin notices. |
| 128 |
* |
| 129 |
* @since 4.1.0 |
| 130 |
* |
| 131 |
* @var object Admin notices. |
| 132 |
*/ |
| 133 |
public $admin_notices; |
| 134 |
|
| 135 |
/** |
| 136 |
* Admin notices API. |
| 137 |
* |
| 138 |
* @since 4.2.0 |
| 139 |
* |
| 140 |
* @var Admin_Notices_API |
| 141 |
*/ |
| 142 |
public $admin_notices_api; |
| 143 |
|
| 144 |
/** |
| 145 |
* Admin banner helper instance. |
| 146 |
* |
| 147 |
* @since 4.2.0 |
| 148 |
* |
| 149 |
* @var Admin_Banner |
| 150 |
*/ |
| 151 |
public Admin_Banner $admin_banner; |
| 152 |
|
| 153 |
/** |
| 154 |
* Prefix which is used for creating the unique filters and actions. |
| 155 |
* |
| 156 |
* @since 3.3.0 |
| 157 |
* |
| 158 |
* @var string Prefix. |
| 159 |
*/ |
| 160 |
public static $prefix; |
| 161 |
|
| 162 |
/** |
| 163 |
* Settings Key. |
| 164 |
* |
| 165 |
* @since 3.3.0 |
| 166 |
* |
| 167 |
* @var string Settings Key. |
| 168 |
*/ |
| 169 |
public $settings_key; |
| 170 |
|
| 171 |
/** |
| 172 |
* The slug name to refer to this menu by (should be unique for this menu). |
| 173 |
* |
| 174 |
* @since 3.3.0 |
| 175 |
* |
| 176 |
* @var string Menu slug. |
| 177 |
*/ |
| 178 |
public $menu_slug; |
| 179 |
|
| 180 |
/** |
| 181 |
* Main constructor class. |
| 182 |
* |
| 183 |
* @since 3.3.0 |
| 184 |
*/ |
| 185 |
public function __construct() { |
| 186 |
$this->hooks(); |
| 187 |
|
| 188 |
// Initialise admin classes. |
| 189 |
$this->admin_dashboard = new Dashboard(); |
| 190 |
$this->settings = new Settings(); |
| 191 |
$this->settings_wizard = new Settings_Wizard(); |
| 192 |
$this->statistics = new Statistics(); |
| 193 |
$this->activator = new Activator(); |
| 194 |
$this->admin_columns = new Columns(); |
| 195 |
$this->metabox = new Metabox(); |
| 196 |
$this->import_export = new Import_Export(); |
| 197 |
$this->tools_page = new Tools_Page(); |
| 198 |
$this->dashboard_widgets = new Dashboard_Widgets(); |
| 199 |
$this->cache = new Cache(); |
| 200 |
$this->admin_notices_api = new Admin_Notices_API(); |
| 201 |
$this->admin_notices = new Admin_Notices(); |
| 202 |
$this->admin_banner = new Admin_Banner( $this->get_admin_banner_config() ); |
| 203 |
} |
| 204 |
|
| 205 |
/** |
| 206 |
* Run the hooks. |
| 207 |
* |
| 208 |
* @since 3.3.0 |
| 209 |
*/ |
| 210 |
public function hooks() { |
| 211 |
Hook_Registry::add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); |
| 212 |
} |
| 213 |
|
| 214 |
/** |
| 215 |
* Enqueue scripts in admin area. |
| 216 |
* |
| 217 |
* @since 3.0.0 |
| 218 |
*/ |
| 219 |
public function admin_enqueue_scripts() { |
| 220 |
|
| 221 |
$minimize = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min'; |
| 222 |
|
| 223 |
wp_register_script( |
| 224 |
'top-ten-chart-js', |
| 225 |
TOP_TEN_PLUGIN_URL . 'includes/admin/js/chart.min.js', |
| 226 |
array(), |
| 227 |
'4.4.8', |
| 228 |
true |
| 229 |
); |
| 230 |
wp_register_script( |
| 231 |
'top-ten-chart-datalabels-js', |
| 232 |
TOP_TEN_PLUGIN_URL . 'includes/admin/js/chartjs-plugin-datalabels.min.js', |
| 233 |
array( 'top-ten-chart-js' ), |
| 234 |
'2.2.0', |
| 235 |
true |
| 236 |
); |
| 237 |
wp_register_script( |
| 238 |
'top-ten-luxon', |
| 239 |
TOP_TEN_PLUGIN_URL . 'includes/admin/js/luxon.min.js', |
| 240 |
array(), |
| 241 |
'3.5.0', |
| 242 |
true |
| 243 |
); |
| 244 |
wp_register_script( |
| 245 |
'top-ten-chartjs-adapter-luxon-js', |
| 246 |
TOP_TEN_PLUGIN_URL . 'includes/admin/js/chartjs-adapter-luxon.min.js', |
| 247 |
array( 'top-ten-luxon', 'top-ten-chart-js' ), |
| 248 |
'1.3.1', |
| 249 |
true |
| 250 |
); |
| 251 |
wp_register_script( |
| 252 |
'top-ten-chart-data-js', |
| 253 |
TOP_TEN_PLUGIN_URL . "includes/admin/js/chart-data{$minimize}.js", |
| 254 |
array( 'jquery', 'top-ten-chart-js', 'top-ten-chart-datalabels-js', 'top-ten-luxon', 'top-ten-chartjs-adapter-luxon-js' ), |
| 255 |
TOP_TEN_VERSION, |
| 256 |
true |
| 257 |
); |
| 258 |
wp_register_script( |
| 259 |
'top-ten-admin-js', |
| 260 |
TOP_TEN_PLUGIN_URL . "includes/admin/js/admin-scripts{$minimize}.js", |
| 261 |
array( 'jquery', 'jquery-ui-tabs', 'jquery-ui-datepicker' ), |
| 262 |
TOP_TEN_VERSION, |
| 263 |
true |
| 264 |
); |
| 265 |
wp_localize_script( |
| 266 |
'top-ten-admin-js', |
| 267 |
'top_ten_admin', |
| 268 |
array( |
| 269 |
'nonce' => wp_create_nonce( 'top_ten_admin_nonce' ), |
| 270 |
) |
| 271 |
); |
| 272 |
wp_register_style( |
| 273 |
'top-ten-admin-css', |
| 274 |
TOP_TEN_PLUGIN_URL . "includes/admin/css/admin-styles{$minimize}.css", |
| 275 |
array(), |
| 276 |
TOP_TEN_VERSION |
| 277 |
); |
| 278 |
wp_register_script( |
| 279 |
'top-ten-wpp-importer-js', |
| 280 |
TOP_TEN_PLUGIN_URL . "includes/admin/js/wpp-importer{$minimize}.js", |
| 281 |
array( 'jquery' ), |
| 282 |
TOP_TEN_VERSION, |
| 283 |
true |
| 284 |
); |
| 285 |
} |
| 286 |
|
| 287 |
/** |
| 288 |
* Display admin sidebar. |
| 289 |
* |
| 290 |
* @since 3.3.0 |
| 291 |
*/ |
| 292 |
public static function display_admin_sidebar() { |
| 293 |
require_once TOP_TEN_PLUGIN_DIR . 'includes/admin/sidebar.php'; |
| 294 |
} |
| 295 |
|
| 296 |
/** |
| 297 |
* Retrieve the configuration array for the admin banner. |
| 298 |
* |
| 299 |
* @since 4.2.0 |
| 300 |
* |
| 301 |
* @return array<string, mixed> |
| 302 |
*/ |
| 303 |
private function get_admin_banner_config(): array { |
| 304 |
return array( |
| 305 |
'capability' => 'manage_options', |
| 306 |
'prefix' => 'tptn', |
| 307 |
'style' => array( |
| 308 |
'version' => TOP_TEN_VERSION, |
| 309 |
), |
| 310 |
'screen_ids' => array( |
| 311 |
'toplevel_page_tptn_dashboard', |
| 312 |
'top-10_page_tptn_options_page', |
| 313 |
'top-10_page_tptn_tools_page', |
| 314 |
'top-10_page_tptn_popular_posts', |
| 315 |
), |
| 316 |
'page_slugs' => array( |
| 317 |
'tptn_dashboard', |
| 318 |
'tptn_options_page', |
| 319 |
'tptn_tools_page', |
| 320 |
'tptn_popular_posts', |
| 321 |
), |
| 322 |
'strings' => array( |
| 323 |
'region_label' => esc_html__( 'Top 10 quick links', 'top-10' ), |
| 324 |
'nav_label' => esc_html__( 'Top 10 admin shortcuts', 'top-10' ), |
| 325 |
'eyebrow' => esc_html__( 'WebberZone Top 10', 'top-10' ), |
| 326 |
'title' => esc_html__( 'Track and display popular posts on your site.', 'top-10' ), |
| 327 |
'text' => esc_html__( 'Jump to your most-used Top 10 tools, manage content faster, and explore more WebberZone plugins.', 'top-10' ), |
| 328 |
), |
| 329 |
'sections' => array( |
| 330 |
'dashboard' => array( |
| 331 |
'label' => esc_html__( 'Dashboard', 'top-10' ), |
| 332 |
'url' => admin_url( 'admin.php?page=tptn_dashboard' ), |
| 333 |
'screen_ids' => array( 'toplevel_page_tptn_dashboard' ), |
| 334 |
'page_slugs' => array( 'tptn_dashboard' ), |
| 335 |
), |
| 336 |
'popular' => array( |
| 337 |
'label' => esc_html__( 'Popular Posts', 'top-10' ), |
| 338 |
'url' => admin_url( 'admin.php?page=tptn_popular_posts' ), |
| 339 |
'screen_ids' => array( 'top-10_page_tptn_popular_posts' ), |
| 340 |
'page_slugs' => array( 'tptn_popular_posts' ), |
| 341 |
), |
| 342 |
'settings' => array( |
| 343 |
'label' => esc_html__( 'Settings', 'top-10' ), |
| 344 |
'url' => admin_url( 'admin.php?page=tptn_options_page' ), |
| 345 |
'screen_ids' => array( 'top-10_page_tptn_options_page' ), |
| 346 |
'page_slugs' => array( 'tptn_options_page' ), |
| 347 |
), |
| 348 |
'tools' => array( |
| 349 |
'label' => esc_html__( 'Tools', 'top-10' ), |
| 350 |
'url' => admin_url( 'admin.php?page=tptn_tools_page' ), |
| 351 |
'screen_ids' => array( 'top-10_page_tptn_tools_page' ), |
| 352 |
'page_slugs' => array( 'tptn_tools_page' ), |
| 353 |
), |
| 354 |
'plugins' => array( |
| 355 |
'label' => esc_html__( 'WebberZone Plugins', 'top-10' ), |
| 356 |
'url' => 'https://webberzone.com/plugins/', |
| 357 |
'type' => 'secondary', |
| 358 |
'target' => '_blank', |
| 359 |
'rel' => 'noopener noreferrer', |
| 360 |
), |
| 361 |
), |
| 362 |
); |
| 363 |
} |
| 364 |
} |
| 365 |
|