| 1 |
<?php |
| 2 |
|
| 3 |
namespace PXLBSAdminify\Inc\Classes; |
| 4 |
|
| 5 |
use PXLBSAdminify\Inc\Utils; |
| 6 |
use PXLBSAdminify\Inc\Admin\AdminSettings; |
| 7 |
use PXLBSAdminify\Inc\Admin\AdminSettingsModel; |
| 8 |
use PXLBSAdminify\Inc\Classes\Addons_Plugins; |
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
// no direct access allowed |
| 13 |
if (!defined('ABSPATH')) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
class Assets extends AdminSettingsModel |
| 18 |
{ |
| 19 |
|
| 20 |
public $classic_editor = true; |
| 21 |
public $block_editor = true; |
| 22 |
public $dark_mode = true; |
| 23 |
|
| 24 |
public function __construct() |
| 25 |
{ |
| 26 |
$this->options = (array) AdminSettings::get_instance()->get(); |
| 27 |
$global_dark_mode = !empty($this->options['light_dark_mode']['admin_ui_mode']) ? $this->options['light_dark_mode']['admin_ui_mode'] : 'light'; |
| 28 |
$this->dark_mode = empty(get_user_meta(get_current_user_id(), 'color_mode', true)) ? $global_dark_mode : get_user_meta(get_current_user_id(), 'color_mode', true); |
| 29 |
add_action('admin_enqueue_scripts', array($this, 'pxlbsadminify_admin_scripts'), 100); |
| 30 |
add_action('wp_ajax_pxlbsadminify_addons_install_active', array( $this, 'pxlbsadminify_addons_install_active' ) ); |
| 31 |
add_action('wp_ajax_pxlbsadminify_ssl_check', array( $this, 'pxlbsadminify_ssl_check' ) ); |
| 32 |
|
| 33 |
// Always hooked: header_scripts() prints the dark-mode loader, which the |
| 34 |
// topbar toggle needs even on pages that booted in light mode. |
| 35 |
add_action('admin_head', array($this, 'header_scripts')); |
| 36 |
} |
| 37 |
|
| 38 |
|
| 39 |
/** |
| 40 |
* Resolved light/dark mode for the current user, normalised to |
| 41 |
* 'light' | 'dark' | 'system'. The settings UI has used 'auto' as a |
| 42 |
* synonym for 'system', so fold that in here. |
| 43 |
* |
| 44 |
* @return string |
| 45 |
*/ |
| 46 |
public function color_mode() |
| 47 |
{ |
| 48 |
$mode = !empty($this->dark_mode) ? $this->dark_mode : 'light'; |
| 49 |
|
| 50 |
return ('auto' === $mode) ? 'system' : $mode; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
/** |
| 55 |
* URL of the dark mode (Darkreader) bundle. |
| 56 |
* |
| 57 |
* @return string |
| 58 |
*/ |
| 59 |
private function dark_mode_url() |
| 60 |
{ |
| 61 |
return PXLBSADMINIFY_ASSETS . 'admin/js/wp-adminify-dark-mode' . Utils::assets_ext('.js'); |
| 62 |
} |
| 63 |
|
| 64 |
|
| 65 |
/** |
| 66 |
* Function: Ajax Call for Install and Activate WP Adminify Plugin |
| 67 |
*/ |
| 68 |
function pxlbsadminify_addons_install_active() |
| 69 |
{ |
| 70 |
|
| 71 |
// Include necessary WordPress files |
| 72 |
require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; |
| 73 |
require_once ABSPATH . 'wp-admin/includes/class-wp-upgrader.php'; |
| 74 |
require_once ABSPATH . 'wp-admin/includes/class-wp-ajax-upgrader-skin.php'; |
| 75 |
require_once ABSPATH . 'wp-admin/includes/class-plugin-upgrader.php'; |
| 76 |
|
| 77 |
if (isset($_POST['plugin'])) { |
| 78 |
|
| 79 |
$nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : ''; |
| 80 |
|
| 81 |
if (!wp_verify_nonce($nonce, 'pxlbsadminify_addons_nonce')) { |
| 82 |
wp_send_json_error(array('mess' => esc_html__('Nonce is invalid', 'adminify'))); |
| 83 |
} |
| 84 |
|
| 85 |
if ((is_multisite() && is_network_admin()) || !current_user_can('install_plugins')) { |
| 86 |
wp_send_json_error(array('mess' => esc_html__('Invalid Access', 'adminify'))); |
| 87 |
} |
| 88 |
|
| 89 |
$plugin = sanitize_text_field(wp_unslash($_POST['plugin'])); |
| 90 |
|
| 91 |
if (empty($plugin)) { |
| 92 |
wp_send_json_error(array('mess' => esc_html__('Invalid plugin', 'adminify'))); |
| 93 |
} |
| 94 |
|
| 95 |
// Validate the requested plugin against the trusted addons list |
| 96 |
// and replace the user-supplied value with the canonical |
| 97 |
// download URL from that list before passing it to the upgrader. |
| 98 |
$addons = new Addons_Plugins(); |
| 99 |
$plugins_list = (array) $addons->get_adminify_plugins_lists(); |
| 100 |
$requested_slug = ''; |
| 101 |
$trusted_source = ''; |
| 102 |
foreach ( $plugins_list as $slug => $entry ) { |
| 103 |
if ( ! empty( $entry['download_link'] ) && $entry['download_link'] === $plugin ) { |
| 104 |
$requested_slug = $slug; |
| 105 |
$trusted_source = $entry['download_link']; |
| 106 |
break; |
| 107 |
} |
| 108 |
if ( $slug === $plugin ) { |
| 109 |
$requested_slug = $slug; |
| 110 |
$trusted_source = ! empty( $entry['download_link'] ) ? $entry['download_link'] : ''; |
| 111 |
break; |
| 112 |
} |
| 113 |
} |
| 114 |
if ( empty( $requested_slug ) || empty( $trusted_source ) ) { |
| 115 |
wp_send_json_error( array( 'mess' => esc_html__( 'Invalid plugin', 'adminify' ) ) ); |
| 116 |
} |
| 117 |
|
| 118 |
$type = isset($_POST['type']) ? sanitize_text_field(wp_unslash($_POST['type'])) : 'install'; |
| 119 |
$skin = new \WP_Ajax_Upgrader_Skin(); |
| 120 |
$upgrader = new \Plugin_Upgrader($skin); |
| 121 |
|
| 122 |
if ('install' === $type) { |
| 123 |
$result = $upgrader->install( $trusted_source ); |
| 124 |
if (is_wp_error($result)) { |
| 125 |
wp_send_json_error( |
| 126 |
array( |
| 127 |
'mess' => $result->get_error_message(), |
| 128 |
) |
| 129 |
); |
| 130 |
} |
| 131 |
$args = array( |
| 132 |
'slug' => $upgrader->result['destination_name'], |
| 133 |
'fields' => array( |
| 134 |
'short_description' => true, |
| 135 |
'icons' => true, |
| 136 |
'banners' => false, |
| 137 |
'added' => false, |
| 138 |
'reviews' => false, |
| 139 |
'sections' => false, |
| 140 |
'requires' => false, |
| 141 |
'rating' => false, |
| 142 |
'ratings' => false, |
| 143 |
'downloaded' => false, |
| 144 |
'last_updated' => false, |
| 145 |
'added' => false, |
| 146 |
'tags' => false, |
| 147 |
'compatibility' => false, |
| 148 |
'homepage' => false, |
| 149 |
'donate_link' => false, |
| 150 |
), |
| 151 |
); |
| 152 |
$plugin_data = plugins_api('plugin_information', $args); |
| 153 |
|
| 154 |
if ($plugin_data && !is_wp_error($plugin_data)) { |
| 155 |
$install_status = \install_plugin_install_status($plugin_data); |
| 156 |
activate_plugin($install_status['file']); |
| 157 |
} |
| 158 |
wp_die(); // die(); |
| 159 |
} |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
|
| 164 |
/* |
| 165 |
* Function is_dark_mode() |
| 166 |
* |
| 167 |
*/ |
| 168 |
public function is_dark_mode() |
| 169 |
{ |
| 170 |
|
| 171 |
if (!empty($this->dark_mode) && $this->dark_mode == 'dark') { |
| 172 |
$adminify_dark_mode = true; |
| 173 |
} else { |
| 174 |
$adminify_dark_mode = false; |
| 175 |
} |
| 176 |
return $adminify_dark_mode; |
| 177 |
} |
| 178 |
|
| 179 |
/** |
| 180 |
* Print the dark-mode loader and boot it for the resolved mode. |
| 181 |
* |
| 182 |
* The Darkreader bundle is ~110 KB, so it is no longer enqueued on every admin |
| 183 |
* page. What ships on every page instead is `window.PXLBSADMINIFYDarkMode`, a few hundred |
| 184 |
* bytes that know how to pull the bundle into a window on demand: |
| 185 |
* |
| 186 |
* - 'dark' the bundle is already enqueued in the head by |
| 187 |
* pxlbsadminify_admin_scripts(), so this only calls enable(). |
| 188 |
* - 'system' nothing is enqueued; the browser decides. When the OS prefers dark |
| 189 |
* the loader fetches the bundle, with a pre-paint guard so the page |
| 190 |
* does not flash white while it streams in. |
| 191 |
* - 'light' nothing is fetched at all. |
| 192 |
* |
| 193 |
* The topbar toggle (classic admin bar and the React frame alike) calls |
| 194 |
* PXLBSADMINIFYDarkMode.load() so switching to dark works without a page reload. |
| 195 |
*/ |
| 196 |
public function header_scripts() |
| 197 |
{ |
| 198 |
// Skip on excluded pages |
| 199 |
if ( $this->should_skip_adminify_scripts() ) { |
| 200 |
return; |
| 201 |
} |
| 202 |
|
| 203 |
$mode = $this->color_mode(); |
| 204 |
?> |
| 205 |
<script id="adminify-dark-mode-loader"> |
| 206 |
window.PXLBSADMINIFYDarkMode = window.PXLBSADMINIFYDarkMode || (function () { |
| 207 |
var url = <?php echo wp_json_encode( $this->dark_mode_url() ); ?>; |
| 208 |
|
| 209 |
// Pulls the bundle into `win` (defaults to this window) and hands |
| 210 |
// AdminifyDarkMode to `cb`. Repeat calls while a fetch is in flight |
| 211 |
// queue up behind it instead of requesting the file again. |
| 212 |
function load(win, cb) { |
| 213 |
win = win || window; |
| 214 |
cb = cb || function () {}; |
| 215 |
|
| 216 |
var doc; |
| 217 |
try { |
| 218 |
doc = win.document; |
| 219 |
} catch (e) { |
| 220 |
return; |
| 221 |
} |
| 222 |
if (!doc) { |
| 223 |
return; |
| 224 |
} |
| 225 |
|
| 226 |
if (win.AdminifyDarkMode) { |
| 227 |
cb(win.AdminifyDarkMode); |
| 228 |
return; |
| 229 |
} |
| 230 |
|
| 231 |
if (win.__pxlbsadminifyDarkModeQueue) { |
| 232 |
win.__pxlbsadminifyDarkModeQueue.push(cb); |
| 233 |
return; |
| 234 |
} |
| 235 |
win.__pxlbsadminifyDarkModeQueue = [cb]; |
| 236 |
|
| 237 |
var script = doc.createElement('script'); |
| 238 |
script.src = url; |
| 239 |
script.async = false; |
| 240 |
script.onload = function () { |
| 241 |
var queue = win.__pxlbsadminifyDarkModeQueue || []; |
| 242 |
win.__pxlbsadminifyDarkModeQueue = null; |
| 243 |
for (var i = 0; i < queue.length; i++) { |
| 244 |
try { |
| 245 |
queue[i](win.AdminifyDarkMode); |
| 246 |
} catch (e) {} |
| 247 |
} |
| 248 |
}; |
| 249 |
script.onerror = function () { |
| 250 |
win.__pxlbsadminifyDarkModeQueue = null; |
| 251 |
}; |
| 252 |
(doc.head || doc.documentElement).appendChild(script); |
| 253 |
} |
| 254 |
|
| 255 |
function enable(win) { |
| 256 |
load(win, function (dm) { |
| 257 |
if (dm) { |
| 258 |
dm.enable({ brightness: 120 }); |
| 259 |
} |
| 260 |
}); |
| 261 |
} |
| 262 |
|
| 263 |
function disable(win) { |
| 264 |
win = win || window; |
| 265 |
// Nothing to undo when the bundle was never fetched. |
| 266 |
if (win.AdminifyDarkMode) { |
| 267 |
win.AdminifyDarkMode.disable(); |
| 268 |
} |
| 269 |
} |
| 270 |
|
| 271 |
return { url: url, load: load, enable: enable, disable: disable }; |
| 272 |
}()); |
| 273 |
</script> |
| 274 |
<?php if ( 'dark' === $mode ) { ?> |
| 275 |
<script> |
| 276 |
window.PXLBSADMINIFYDarkMode.enable(); |
| 277 |
addEventListener("load", function () { |
| 278 |
window.PXLBSADMINIFYDarkMode.enable(); |
| 279 |
}); |
| 280 |
</script> |
| 281 |
<?php } elseif ( 'system' === $mode ) { ?> |
| 282 |
<script> |
| 283 |
(function () { |
| 284 |
if (!(window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches)) { |
| 285 |
return; |
| 286 |
} |
| 287 |
|
| 288 |
// The bundle is fetched rather than blocking in the head, so paint |
| 289 |
// the page dark up front and drop the guard once Darkreader owns it. |
| 290 |
var guard = document.createElement('style'); |
| 291 |
guard.textContent = 'html,body{background-color:#181a1b!important;color:#e8e6e3!important}'; |
| 292 |
(document.head || document.documentElement).appendChild(guard); |
| 293 |
|
| 294 |
var dropGuard = function () { |
| 295 |
if (guard && guard.parentNode) { |
| 296 |
guard.parentNode.removeChild(guard); |
| 297 |
} |
| 298 |
}; |
| 299 |
|
| 300 |
window.PXLBSADMINIFYDarkMode.load(window, function (dm) { |
| 301 |
if (dm) { |
| 302 |
dm.enable({ brightness: 120 }); |
| 303 |
} |
| 304 |
dropGuard(); |
| 305 |
}); |
| 306 |
|
| 307 |
// Failsafe: never leave the guard behind if the fetch never lands. |
| 308 |
setTimeout(dropGuard, 5000); |
| 309 |
|
| 310 |
addEventListener("load", function () { |
| 311 |
window.PXLBSADMINIFYDarkMode.enable(); |
| 312 |
}); |
| 313 |
}()); |
| 314 |
</script> |
| 315 |
<?php } |
| 316 |
|
| 317 |
} |
| 318 |
|
| 319 |
|
| 320 |
|
| 321 |
/** |
| 322 |
* Check if current page should skip Adminify scripts |
| 323 |
* Handles root, subdirectory, subdomain, and multisite installations |
| 324 |
* |
| 325 |
* @return bool True if scripts should be skipped |
| 326 |
*/ |
| 327 |
private function should_skip_adminify_scripts() { |
| 328 |
global $pagenow; |
| 329 |
|
| 330 |
// Pages where Adminify scripts should not load |
| 331 |
$excluded_pages = [ |
| 332 |
'customize.php', |
| 333 |
'wp-login.php', |
| 334 |
'wp-register.php', |
| 335 |
]; |
| 336 |
|
| 337 |
// Check global $pagenow |
| 338 |
if ( in_array( $pagenow, $excluded_pages, true ) ) { |
| 339 |
return true; |
| 340 |
} |
| 341 |
|
| 342 |
// Fallback: Check PHP_SELF for subdirectory WordPress installs |
| 343 |
// Normalize path by extracting just the filename |
| 344 |
$php_self = isset( $_SERVER['PHP_SELF'] ) ? sanitize_text_field( wp_unslash( $_SERVER['PHP_SELF'] ) ) : ''; |
| 345 |
$current_file = basename( $php_self ); |
| 346 |
|
| 347 |
if ( in_array( $current_file, $excluded_pages, true ) ) { |
| 348 |
return true; |
| 349 |
} |
| 350 |
|
| 351 |
// Additional check using REQUEST_URI for edge cases |
| 352 |
$request_uri = isset( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : ''; |
| 353 |
foreach ( $excluded_pages as $page ) { |
| 354 |
if ( strpos( $request_uri, '/' . $page ) !== false ) { |
| 355 |
return true; |
| 356 |
} |
| 357 |
} |
| 358 |
|
| 359 |
return false; |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
/** |
| 364 |
* Matches a Font Awesome class in any of the shapes Adminify stores: |
| 365 |
* "fa fa-gear", "fas fa-rocket", and the URL-encoded "fas%20fa-rocket" that |
| 366 |
* WordPress produces when an icon class is handed to add_menu_page(). |
| 367 |
*/ |
| 368 |
const FONTAWESOME_CLASS_PATTERN = '/(?:^|[^a-z0-9-])fa[bsrl]?(?:\s|%20|-)fa-/i'; |
| 369 |
|
| 370 |
|
| 371 |
/** |
| 372 |
* Whether Font Awesome has anything to paint on the current screen. |
| 373 |
* |
| 374 |
* The stylesheet plus its webfonts weigh well over a megabyte, so it is only |
| 375 |
* worth loading where Adminify actually renders an icon with it: |
| 376 |
* |
| 377 |
* - Adminify's own screens, whose section headers and field UI use hardcoded |
| 378 |
* `fas fa-*` classes. |
| 379 |
* - The dashboard, but only when a widget is actually configured with a Font |
| 380 |
* Awesome class. |
| 381 |
* - Any screen at all when an admin menu item carries a Font Awesome icon, |
| 382 |
* because the sidebar renders on every screen. |
| 383 |
* |
| 384 |
* Framework option, metabox, taxonomy, widget, customizer, nav-menu, profile |
| 385 |
* and comment screens are deliberately not listed: the framework scopes and |
| 386 |
* enqueues Font Awesome itself in ADMINIFY::add_admin_enqueue_scripts(). |
| 387 |
* |
| 388 |
* @param \WP_Screen|null $screen Current screen. |
| 389 |
* @return bool |
| 390 |
*/ |
| 391 |
private function needs_fontawesome( $screen ) { |
| 392 |
|
| 393 |
if ( isset( $screen->id ) && false !== strpos( $screen->id, 'wp-adminify' ) ) { |
| 394 |
return true; |
| 395 |
} |
| 396 |
|
| 397 |
if ( isset( $screen->id ) && 'dashboard' === $screen->id && $this->has_fontawesome_dashboard_widget() ) { |
| 398 |
return true; |
| 399 |
} |
| 400 |
|
| 401 |
// Falls through on the dashboard too: the admin menu renders there as well. |
| 402 |
return $this->has_fontawesome_menu_icon(); |
| 403 |
} |
| 404 |
|
| 405 |
|
| 406 |
/** |
| 407 |
* Whether any dashboard widget is configured with a Font Awesome class. |
| 408 |
* |
| 409 |
* Widget icons come from the framework icon field, whose list is still Font |
| 410 |
* Awesome (Libs/adminify-framework/functions/actions.php), and the editor and |
| 411 |
* script widget types can hold arbitrary markup — so scan the whole saved |
| 412 |
* option rather than just the icon keys, or a widget whose body contains |
| 413 |
* `<i class="fas fa-star">` would render a blank square. |
| 414 |
* |
| 415 |
* The option is the one read by DashboardWidgetModel::$prefix, which the |
| 416 |
* Dashboard Widget module already loads on every admin page, so this is an |
| 417 |
* options-cache hit rather than a query. Only ever called on the dashboard. |
| 418 |
* |
| 419 |
* @return bool |
| 420 |
*/ |
| 421 |
private function has_fontawesome_dashboard_widget() { |
| 422 |
|
| 423 |
$settings = get_option( 'pxlbsadminify_dasboard_widgets' ); |
| 424 |
|
| 425 |
if ( empty( $settings ) ) { |
| 426 |
return false; |
| 427 |
} |
| 428 |
|
| 429 |
// Arrays and objects come back as a serialized string; scalars pass through. |
| 430 |
$settings = maybe_serialize( $settings ); |
| 431 |
|
| 432 |
if ( ! is_string( $settings ) || '' === $settings ) { |
| 433 |
return false; |
| 434 |
} |
| 435 |
|
| 436 |
return (bool) preg_match( self::FONTAWESOME_CLASS_PATTERN, $settings ); |
| 437 |
} |
| 438 |
|
| 439 |
|
| 440 |
/** |
| 441 |
* Look for a Font Awesome class stored as an admin menu icon. |
| 442 |
* |
| 443 |
* Pro admin pages pass the picked icon class straight to add_menu_page() |
| 444 |
* (Pro/Modules/AdminPages/AdminPages_Output.php), where WordPress treats it as |
| 445 |
* an image URL and prints `http://fas%20fa-rocket`; wp-adminify.js turns that |
| 446 |
* back into a class. Either shape counts as a hit. |
| 447 |
* |
| 448 |
* $menu is built during admin_menu, which runs before admin_enqueue_scripts, |
| 449 |
* so it is fully populated by the time this is called. |
| 450 |
* |
| 451 |
* @return bool |
| 452 |
*/ |
| 453 |
private function has_fontawesome_menu_icon() { |
| 454 |
global $menu; |
| 455 |
|
| 456 |
if ( empty( $menu ) || ! is_array( $menu ) ) { |
| 457 |
return false; |
| 458 |
} |
| 459 |
|
| 460 |
foreach ( $menu as $item ) { |
| 461 |
|
| 462 |
if ( empty( $item[6] ) || ! is_string( $item[6] ) ) { |
| 463 |
continue; |
| 464 |
} |
| 465 |
|
| 466 |
if ( preg_match( self::FONTAWESOME_CLASS_PATTERN, $item[6] ) ) { |
| 467 |
return true; |
| 468 |
} |
| 469 |
} |
| 470 |
|
| 471 |
return false; |
| 472 |
} |
| 473 |
|
| 474 |
|
| 475 |
public function pxlbsadminify_admin_scripts() |
| 476 |
{ |
| 477 |
// Skip loading scripts on excluded pages (customize.php, login, etc.) |
| 478 |
if ( $this->should_skip_adminify_scripts() ) { |
| 479 |
return; |
| 480 |
} |
| 481 |
|
| 482 |
$screen = get_current_screen(); |
| 483 |
|
| 484 |
|
| 485 |
// Register Styles |
| 486 |
wp_register_style('adminify-admin', PXLBSADMINIFY_ASSETS . 'css/wp-adminify' . Utils::assets_ext('.css'), false, PXLBSADMINIFY_VER); |
| 487 |
wp_register_style('adminify-default-ui', PXLBSADMINIFY_ASSETS . 'css/wp-adminify-default-ui' . Utils::assets_ext('.css'), false, PXLBSADMINIFY_VER); |
| 488 |
|
| 489 |
|
| 490 |
// Register Scripts |
| 491 |
wp_register_script('adminify-admin', PXLBSADMINIFY_ASSETS . 'admin/js/wp-adminify' . Utils::assets_ext('.js'), array('jquery'), PXLBSADMINIFY_VER, true); |
| 492 |
|
| 493 |
// Adminify Icon Picker |
| 494 |
wp_register_style('adminify-simple-line-icons', PXLBSADMINIFY_ASSETS . 'vendors/font-icons/simple-line-icons/css/simple-line-icons' . Utils::assets_ext('.css'), false, PXLBSADMINIFY_VER); |
| 495 |
wp_register_style('adminify-icon-picker', PXLBSADMINIFY_ASSETS . 'vendors/adminify-icon-picker/css/style' . Utils::assets_ext('.css'), false, PXLBSADMINIFY_VER); |
| 496 |
wp_register_script('adminify-icon-picker', PXLBSADMINIFY_ASSETS . 'vendors/adminify-icon-picker/js/adminify-icon-picker' . Utils::assets_ext('.js'), array('jquery'), PXLBSADMINIFY_VER, true); |
| 497 |
|
| 498 |
// Dark Mode |
| 499 |
wp_register_script('adminify--dark-mode', $this->dark_mode_url(), array(), PXLBSADMINIFY_VER, false); |
| 500 |
|
| 501 |
// Styles Enqueue |
| 502 |
if (!empty($this->options['admin_ui'])) { |
| 503 |
// wp_enqueue_style('wp-adminify-animate'); |
| 504 |
wp_enqueue_style('adminify-admin'); |
| 505 |
// Commented on: 9-6-24 |
| 506 |
// wp_enqueue_style('wp-adminify-admin-bar'); |
| 507 |
} else { |
| 508 |
wp_enqueue_style('adminify-default-ui'); |
| 509 |
} |
| 510 |
|
| 511 |
|
| 512 |
// RTL CSS |
| 513 |
if ( is_rtl() ) { |
| 514 |
wp_enqueue_style( 'adminify-rtl', PXLBSADMINIFY_URL . 'Libs/adminify-framework/assets/css/style-rtl'. Utils::assets_ext('.css'), array(), PXLBSADMINIFY_VER, 'all' ); |
| 515 |
} |
| 516 |
|
| 517 |
|
| 518 |
// Dark Mode Style |
| 519 |
// wp_enqueue_style('adminify-dark-mode'); |
| 520 |
|
| 521 |
// Only a user who is actually in dark mode gets the ~110 KB bundle up front. |
| 522 |
// 'system' is resolved in the browser and 'light' never needs it at all; both |
| 523 |
// go through the loader printed by header_scripts(). |
| 524 |
if ('dark' === $this->color_mode()) { |
| 525 |
wp_enqueue_script('adminify--dark-mode'); |
| 526 |
} |
| 527 |
|
| 528 |
|
| 529 |
// Get local fonts data for frontend - download if not exists |
| 530 |
$local_fonts = GoogleFontsLocal::get_instance(); |
| 531 |
$local_fonts_urls = []; |
| 532 |
|
| 533 |
// Process light mode logo font |
| 534 |
if (!empty($this->options['light_dark_mode']['admin_ui_light_mode']['admin_ui_light_logo_text_typo']['font-family'])) { |
| 535 |
$font_family = $this->options['light_dark_mode']['admin_ui_light_mode']['admin_ui_light_logo_text_typo']['font-family']; |
| 536 |
$font_weight = !empty($this->options['light_dark_mode']['admin_ui_light_mode']['admin_ui_light_logo_text_typo']['font-weight']) ? $this->options['light_dark_mode']['admin_ui_light_mode']['admin_ui_light_logo_text_typo']['font-weight'] : '400'; |
| 537 |
|
| 538 |
if (!$local_fonts->is_font_local($font_family)) { |
| 539 |
$local_fonts->download_font($font_family, $font_weight); |
| 540 |
} |
| 541 |
|
| 542 |
$local_url = $local_fonts->get_local_font_url($font_family); |
| 543 |
if ($local_url) { |
| 544 |
$local_fonts_urls['light_logo'] = $local_url; |
| 545 |
} |
| 546 |
} |
| 547 |
|
| 548 |
// Process dark mode logo font |
| 549 |
if (!empty($this->options['light_dark_mode']['admin_ui_dark_mode']['admin_ui_dark_logo_text_typo']['font-family'])) { |
| 550 |
$font_family = $this->options['light_dark_mode']['admin_ui_dark_mode']['admin_ui_dark_logo_text_typo']['font-family']; |
| 551 |
$font_weight = !empty($this->options['light_dark_mode']['admin_ui_dark_mode']['admin_ui_dark_logo_text_typo']['font-weight']) ? $this->options['light_dark_mode']['admin_ui_dark_mode']['admin_ui_dark_logo_text_typo']['font-weight'] : '400'; |
| 552 |
|
| 553 |
if (!$local_fonts->is_font_local($font_family)) { |
| 554 |
$local_fonts->download_font($font_family, $font_weight); |
| 555 |
} |
| 556 |
|
| 557 |
$local_url = $local_fonts->get_local_font_url($font_family); |
| 558 |
if ($local_url) { |
| 559 |
$local_fonts_urls['dark_logo'] = $local_url; |
| 560 |
} |
| 561 |
} |
| 562 |
|
| 563 |
$local_fonts_data = [ |
| 564 |
'base_url' => $local_fonts->get_folder_url(), |
| 565 |
'urls' => $local_fonts_urls, |
| 566 |
]; |
| 567 |
|
| 568 |
$localize_array_data = [ |
| 569 |
'admin_ajax' => admin_url('admin-ajax.php'), |
| 570 |
'settings' => [ |
| 571 |
'adminify_ui' => !empty($this->options['admin_ui']) ? true : false, |
| 572 |
], |
| 573 |
'admin_nonce' => wp_create_nonce('pxlbsadminify_frame_nonce'), |
| 574 |
'is_pro' => (class_exists('\\PXLBSAdminify\\Pro\\Adminify_Pro') && !empty(\PXLBSAdminify\Pro\Adminify_Pro::is_premium())) ? true : false, |
| 575 |
'local_fonts' => $local_fonts_data |
| 576 |
]; |
| 577 |
|
| 578 |
// Pro-only settings flags (e.g. menu_search) attach via this |
| 579 |
// filter from Pro/Classes/Assets_Pro.php. Free leaves the |
| 580 |
// localize array untouched. |
| 581 |
$localize_array_data = (array) apply_filters( 'pxlbsadminify_admin_localize_data', $localize_array_data, $this->options ); |
| 582 |
|
| 583 |
// Scripts Enqueue |
| 584 |
wp_enqueue_script('adminify-admin'); |
| 585 |
wp_localize_script( 'adminify-admin', 'PXLBSADMINIFY_ADMIN', $localize_array_data ); |
| 586 |
|
| 587 |
// Font Awesome, only on screens that actually paint an icon with it. The |
| 588 |
// old guard called wp_script_is() on what are styles, so it always passed |
| 589 |
// and every admin page paid for the font. wp_enqueue_style() is a no-op on |
| 590 |
// an already-enqueued handle, so no guard is needed against the framework |
| 591 |
// having enqueued these first. |
| 592 |
if ($this->needs_fontawesome($screen)) { |
| 593 |
if (apply_filters('adminify_fa4', false)) { |
| 594 |
wp_enqueue_style('adminify-fa', PXLBSADMINIFY_ASSETS . 'vendors/fontawesome/fa4/css/font-awesome.min.css', array(), '4.7.0', 'all'); |
| 595 |
} else { |
| 596 |
wp_enqueue_style('adminify-fa5', PXLBSADMINIFY_ASSETS . 'vendors/fontawesome/fa5/css/all.min.css', array(), '5.15.4', 'all'); |
| 597 |
wp_enqueue_style('adminify-fa5-v4-shims', PXLBSADMINIFY_ASSETS . 'vendors/fontawesome/fa5/css/v4-shims.min.css', array(), '5.15.4', 'all'); |
| 598 |
} |
| 599 |
} |
| 600 |
wp_enqueue_style('adminify-simple-line-icons'); |
| 601 |
|
| 602 |
// Adminify UI HTTPS gate — only on the main settings screen where the switcher lives. |
| 603 |
if (isset($screen->id) && false !== strpos($screen->id, 'wp-adminify-settings')) { |
| 604 |
wp_enqueue_script('adminify-ui-ssl-check', PXLBSADMINIFY_ASSETS . 'admin/js/adminify-ui-ssl-check.js', array('jquery'), PXLBSADMINIFY_VER, true); |
| 605 |
wp_localize_script( |
| 606 |
'adminify-ui-ssl-check', |
| 607 |
'PXLBSADMINIFY_SSL', |
| 608 |
array( |
| 609 |
'ajax_url' => admin_url('admin-ajax.php'), |
| 610 |
'nonce' => wp_create_nonce('pxlbsadminify_frame_nonce'), |
| 611 |
'field_id' => 'admin_ui', |
| 612 |
'i18n' => array( |
| 613 |
'label' => esc_html__('Adminify UI needs HTTPS:', 'adminify'), |
| 614 |
'generic_error' => esc_html__('Could not verify HTTPS right now. Please try again.', 'adminify'), |
| 615 |
), |
| 616 |
) |
| 617 |
); |
| 618 |
|
| 619 |
// Adminify UI live theme preset changer |
| 620 |
wp_enqueue_script('adminify-theme-presetter', PXLBSADMINIFY_ASSETS . 'admin/js/wp-adminify-theme-presetter' . Utils::assets_ext('.js'), ['jquery'], PXLBSADMINIFY_VER, true); |
| 621 |
wp_localize_script('adminify-theme-presetter', 'PXLBSADMINIFY_PRESET_THEMES', Utils::get_theme_presets()); |
| 622 |
} |
| 623 |
|
| 624 |
if ($screen->id === 'adminify_page_wp-adminify-addons-plugins' || $screen->id === 'adminify-pro_page_wp-adminify-addons-plugins') { |
| 625 |
// JS Files . |
| 626 |
wp_enqueue_script('adminify-addons', PXLBSADMINIFY_ASSETS . 'admin/js/wp-adminify-addons' . Utils::assets_ext('.js'), array('jquery'), PXLBSADMINIFY_VER, true); |
| 627 |
wp_localize_script( |
| 628 |
'adminify-addons', |
| 629 |
'PXLBSADMINIFY_CORE', |
| 630 |
array( |
| 631 |
'admin_ajax' => admin_url('admin-ajax.php'), |
| 632 |
'addons_nonce' => wp_create_nonce('pxlbsadminify_addons_nonce'), |
| 633 |
'plugin_key' => 'pxlbsadminify' |
| 634 |
) |
| 635 |
); |
| 636 |
} |
| 637 |
} |
| 638 |
|
| 639 |
/** |
| 640 |
* AJAX: verify the site is HTTPS-ready before enabling the Adminify UI. |
| 641 |
* |
| 642 |
* Called from assets/admin/js/adminify-ui-ssl-check.js when the user flips |
| 643 |
* the "Adminify UI" switcher on. Returns success only when the dashboard |
| 644 |
* frame would actually load (see Utils::adminify_ui_https_status()). |
| 645 |
*/ |
| 646 |
public function pxlbsadminify_ssl_check() |
| 647 |
{ |
| 648 |
$nonce = isset($_POST['nonce']) ? sanitize_text_field(wp_unslash($_POST['nonce'])) : ''; |
| 649 |
|
| 650 |
if (!wp_verify_nonce($nonce, 'pxlbsadminify_frame_nonce')) { |
| 651 |
wp_send_json_error(array( |
| 652 |
'https_ready' => false, |
| 653 |
'message' => esc_html__('Security check failed. Please reload the page and try again.', 'adminify'), |
| 654 |
)); |
| 655 |
} |
| 656 |
|
| 657 |
if (!current_user_can('manage_options')) { |
| 658 |
wp_send_json_error(array( |
| 659 |
'https_ready' => false, |
| 660 |
'message' => esc_html__('You do not have permission to change this setting.', 'adminify'), |
| 661 |
)); |
| 662 |
} |
| 663 |
|
| 664 |
$status = Utils::adminify_ui_https_status(); |
| 665 |
|
| 666 |
if (!empty($status['ready'])) { |
| 667 |
wp_send_json_success(array('https_ready' => true)); |
| 668 |
} |
| 669 |
|
| 670 |
wp_send_json_error(array( |
| 671 |
'https_ready' => false, |
| 672 |
'message' => $status['message'], |
| 673 |
)); |
| 674 |
} |
| 675 |
|
| 676 |
// WP Adminify Options Page Style |
| 677 |
public function pxlbsadminify_admin_script() |
| 678 |
{ |
| 679 |
echo '<style>.wp-adminify-two-columns{ display: flex; flex-wrap: wrap; padding: 15px; } .wp-adminify .adminify-hightlight-field{ border: 2px solid #0347FF !important; font-weight: 600 !important;} .wp-adminify-two-columns .adminify-full-width-field{ width: 100% !important; flex-basis: 100% !important; } .wp-adminify-two-columns > .adminify-field{ width: 49%; flex-basis: 49%; margin-right: 1%; margin-top: -1px; border: 1px solid #eee; box-sizing: border-box; } .wp-adminify-two-columns.aminify-title-width-40 .adminify-title, .aminify-title-width-40 .adminify-title{ width: 40% !important;} .wp-adminify-two-columns.aminify-title-width-40 .adminify-fieldset, .aminify-title-width-40 .adminify-fieldset{ width: calc(60% - 20px) !important;} .wp-adminify-two-columns.aminify-title-width-65 .adminify-title{ width: 65%;} .wp-adminify-two-columns.aminify-title-width-65 .adminify-fieldset{ width: calc(35% - 20px);} .wp-adminify-two-columns .adminify-field-subheading{height:25px;box-sizing: content-box; width: 100%; flex-basis: 100%;} .wp-adminify-white-label-notice-content { background-color: #fff; box-shadow: 0px 0px 50px rgb(0 0 0 / 13%); position: absolute; top: 150px; left: 400px; width: 530px; padding: 32px; padding-bottom: 50px; -webkit-border-radius: 20px; border-radius: 20px; text-align: center; z-index: 2; } .wp-adminify-white-label-notice-logo img { height: 100px; width: 250px; padding: 10px; padding-top: 10px; } .wp-adminify-white-label-notice-content h2 span{ color: #6814cd; text-transform: uppercase; } .wp-adminify-white-label-notice-content em{ font-size: 13px; color: red; } .wp-adminify-white-label-notice .wp-adminify-get-pro{ background-image: -moz-linear-gradient( 0deg, rgb(223,29,198) 0%, rgb(106,20,209) 100%); background-image: -webkit-linear-gradient( 0deg , rgb(223,29,198) 0%, rgb(106,20,209) 100%); background-image: -ms-linear-gradient( 0deg, rgb(223,29,198) 0%, rgb(106,20,209) 100%); border: none; box-shadow: none; color: #fff; cursor: pointer; font-weight: 700; line-height: 35px; padding: 0 15px; text-transform: uppercase; text-decoration: none; display: inline-block; width: 180px; padding: 5px 15px !important; border-radius: 10px; font-size: 15px; font-weight: 800; -webkit-transition: all 0.2s ease-in-out; transition: all 0.2s ease-in-out; } .wp-adminify-white-label-notice{ position: absolute !important; top: 0; left: 0; width: 100% !important; height: 100%; background: rgba(200, 200, 200, 0.5); -js-display: flex; display: -webkit-box; display: -webkit-flex; display: -moz-box; display: -ms-flexbox; display: flex; -webkit-box-pack: center; -webkit-justify-content: center; -moz-box-pack: center; -ms-flex-pack: center; justify-content: center;z-index: 1; } .wp-adminify-white-label-notice .wp-adminify-get-pro:hover { color:#fff; background-image: -moz-linear-gradient(0deg, rgb(106, 20, 209) 0%, rgb(223, 29, 198) 100%); background-image: -webkit-linear-gradient( 0deg, rgb(106, 20, 209) 0%, rgb(223, 29, 198) 100%); background-image: -ms-linear-gradient(0deg, rgb(106, 20, 209) 0%, rgb(223, 29, 198) 100%);} .adminify-field-callback a.wp-adminify-rollback-button{font-family:inherit !important;} .wp-adminify-rollback-button.dashicons, .wp-adminify-rollback-button.dashicons-before:before{ width: inherit !important;}</style>'; |
| 680 |
} |
| 681 |
|
| 682 |
} |
| 683 |
|