| @@ -32,25 +32,36 @@ | ||
| 32 | 32 | |
| 33 | 33 | public function menu_editor_enqueue_scripts() |
| 34 | 34 | { |
| 35 | 35 | global $pagenow; |
| 36 | - $screen = get_current_screen(); | |
| 37 | - if ($pagenow == 'wp-login.php' || $pagenow == 'wp-register.php' || $pagenow == 'customize.php') { | |
| 36 | + | |
| 37 | + // 1. Handle pages where get_current_screen() doesn't exist | |
| 38 | + $auth_pages = ['wp-login.php', 'wp-signup.php', 'wp-activate.php']; | |
| 39 | + if (in_array($pagenow, $auth_pages)) { | |
| 38 | 40 | return; |
| 39 | 41 | } |
| 42 | + | |
| 43 | + // 2. Handle customize.php | |
| 44 | + if ($pagenow === 'customize.php') { | |
| 45 | + return; | |
| 46 | + } | |
| 40 | 47 | |
| 41 | - if ($screen->id === 'toplevel_page_wp-adminify-settings') { | |
| 48 | + $screen = get_current_screen(); | |
| 49 | + | |
| 50 | + if ($screen && $screen->id === 'toplevel_page_wp-adminify-settings') { | |
| 42 | 51 | $this->import_css(); |
| 43 | 52 | |
| 44 | 53 | // Enqueue Styles |
| 45 | 54 | wp_enqueue_style('adminify-icon-picker'); |
| 46 | - wp_enqueue_style('adminify-select2'); | |
| 47 | - wp_enqueue_style('adminify-menu-editor'); | |
| 55 | + wp_enqueue_style('adminify-select2', PXLBSADMINIFY_ASSETS . 'vendors/select2/select2' . Utils::assets_ext('.css'), false, PXLBSADMINIFY_VER); | |
| 56 | + $this->add_select2_inline_style(); | |
| 57 | + wp_enqueue_style('adminify-menu-editor', PXLBSADMINIFY_ASSETS . 'css/adminify-menu-editor' . Utils::assets_ext('.css'), false, PXLBSADMINIFY_VER); | |
| 48 | 58 | |
| 49 | 59 | // Enqueue Scripts |
| 50 | - wp_enqueue_script('adminify-select2'); | |
| 60 | + wp_enqueue_script('adminify-select2', PXLBSADMINIFY_ASSETS . 'vendors/select2/select2.min.js', array('jquery'), PXLBSADMINIFY_VER, true); | |
| 61 | + $this->add_select2_inline_script(); | |
| 51 | 62 | wp_enqueue_script('adminify-icon-picker'); |
| 52 | - wp_enqueue_script('adminify-menu-editor'); | |
| 63 | + wp_enqueue_script('adminify-menu-editor', PXLBSADMINIFY_ASSETS . 'admin/js/wp-adminify-menu-editor' . Utils::assets_ext('.js'), array('jquery', 'jquery-ui-sortable', 'adminify-icon-picker'), PXLBSADMINIFY_VER, true); | |
| 53 | 64 | |
| 54 | 65 | wp_localize_script( |
| 55 | 66 | 'adminify-icon-picker', |
| 56 | 67 | 'PXLBSADMINIFY_ICON_PICKER', |
| @@ -256,6 +267,86 @@ | ||
| 256 | 267 | $menu_editor_custom_css = preg_replace('/\s*([{}|:;,])\s+/', '$1', $menu_editor_custom_css); |
| 257 | 268 | $menu_editor_custom_css = preg_replace('/\s\s+(.*)/', '$1', $menu_editor_custom_css); |
| 258 | 269 | |
| 259 | 270 | wp_add_inline_style('adminify-menu-editor', wp_strip_all_tags($menu_editor_custom_css)); |
| 271 | + } | |
| 272 | + | |
| 273 | + /** | |
| 274 | + * Select 2 Supported script | |
| 275 | + */ | |
| 276 | + private function add_select2_inline_script() { | |
| 277 | + ob_start(); | |
| 278 | + ?> | |
| 279 | + | |
| 280 | + jQuery(function($) { | |
| 281 | + $('.select-field').select2({width: '100%'}); | |
| 282 | + | |
| 283 | + $('.copy_to').on('change', function() { | |
| 284 | + if ( $(this).val() == 'copy_to_all' ) { | |
| 285 | + $(this).closest('.wp-clone-sites-options').find('.copy_exclude-field-wrapper').show(); | |
| 286 | + } else { | |
| 287 | + $(this).closest('.wp-clone-sites-options').find('.copy_exclude-field-wrapper').hide(); | |
| 288 | + } | |
| 289 | + }); | |
| 290 | + | |
| 291 | + $('#option_modules_toggle').on('click', function(e) { | |
| 292 | + e.preventDefault(); | |
| 293 | + $checkboxes = $(this).closest('.line-single--content').find('input[type="checkbox"]'); | |
| 294 | + $checked = $checkboxes.filter(':checked'); | |
| 295 | + $status = true; | |
| 296 | + if ( $checked.length == $checkboxes.length ) $status = false; | |
| 297 | + $checkboxes.each(function(){ $(this).prop('checked', $status) }); | |
| 298 | + }); | |
| 299 | + }); | |
| 300 | + <?php | |
| 301 | + | |
| 302 | + $script = ob_get_clean(); | |
| 303 | + | |
| 304 | + wp_add_inline_script('adminify-select2', $script); | |
| 305 | + } | |
| 306 | + | |
| 307 | + /** | |
| 308 | + * Select2 supported style | |
| 309 | + */ | |
| 310 | + private function add_select2_inline_style() { | |
| 311 | + $output_css = '.wp-adminify-settings .dashicons,.wp-adminify-settings .dashicons-before:before{vertical-align:middle}.adminify-status{background:#fff;padding:12px 10px;margin:30px 0;-webkit-border-radius:4px;border-radius:4px;-webkit-box-shadow:0 0 8px rgba(139,148,169,.15);box-shadow:0 0 8px rgba(139,148,169,.15)}.adminify-status.adminify-status--success{border-left:4px solid #48cf5b}.adminify-status.adminify-status--error{border-left:4px solid #f16b6b}.adminify-status p{margin:0}.adminify-status p:not(:last-child){margin-bottom:10px}.wp-clone-sites-options h1{margin:10px 0 30px}.wp-clone-sites-options{max-width:800px; margin: 50px auto;}.container.wp-clone-sites-options form{padding:30px;background:#fff;margin:20px 0;-webkit-border-radius:4px;border-radius:4px;-webkit-box-shadow:0 0 24px rgba(108,111,120,.15);box-shadow:0 0 24px rgba(108,111,120,.15)}.wp-clone-sites-options .select-field{width:100%}.line-single--wrapper{display:-webkit-box;display:-webkit-flex;display:-ms-flexbox;display:flex;-webkit-box-align:center;-webkit-align-items:center;-ms-flex-align:center;align-items:center;margin-bottom:24px;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap;background:#eff0f3;padding:24px 20px;-webkit-border-radius:4px;border-radius:4px}.line-single--title{width:100%;margin-bottom:10px;font-weight:700}.line-single--content{width:100%;display:-webkit-inline-box;display:-webkit-inline-flex;display:-ms-inline-flexbox;display:inline-flex;-webkit-flex-wrap:wrap;-ms-flex-wrap:wrap;flex-wrap:wrap}.line-single--content>div{width:33.333333%;margin-bottom:8px}button#option_modules_toggle{padding:8px 10px;line-height:1;margin-top:5px;border:none;background:#fff;-webkit-border-radius:4px;border-radius:4px;cursor:pointer;-webkit-box-shadow:0 0 4px #ddd;box-shadow:0 0 4px #ddd}'; | |
| 312 | + | |
| 313 | + // Use wp_add_inline_style instead of printf to prevent "headers already sent" errors | |
| 314 | + wp_add_inline_style('adminify-select2', 'body.toplevel_page_wp-adminify-settings.network-admin{' . wp_strip_all_tags($output_css) . '}'); | |
| 315 | + | |
| 316 | + $select2_css = '.wp-adminify .select2-container .select2-selection--single .select2-selection__rendered { | |
| 317 | + color: #000; | |
| 318 | + line-height: 34px; | |
| 319 | + } | |
| 320 | + | |
| 321 | + .select2-container--default .select2-selection--single, .select2-dropdown, .select2-container--default .select2-search--dropdown .select2-search__field { | |
| 322 | + border: 1px solid #d1d1d1; | |
| 323 | + } | |
| 324 | + | |
| 325 | + .select2-container--default .select2-selection--single .select2-selection__arrow { | |
| 326 | + height: 34px; | |
| 327 | + } | |
| 328 | + | |
| 329 | + .select2-container--default .select2-selection--multiple .select2-selection__choice__remove { | |
| 330 | + line-height: 1.6; | |
| 331 | + } | |
| 332 | + | |
| 333 | + .select2-container .select2-selection--multiple .select2-selection__rendered { | |
| 334 | + vertical-align: sub; | |
| 335 | + } | |
| 336 | + | |
| 337 | + span.select2-search.select2-search--inline { | |
| 338 | + vertical-align: super; | |
| 339 | + } | |
| 340 | + | |
| 341 | + .select2-container--default .select2-search--inline .select2-search__field { | |
| 342 | + background: none !important; | |
| 343 | + padding: 0 !important; | |
| 344 | + }'; | |
| 345 | + | |
| 346 | + // Combine the values from above and minifiy them. | |
| 347 | + $select2_css = preg_replace('#/\*.*?\*/#s', '', $select2_css); | |
| 348 | + $select2_css = preg_replace('/\s*([{}|:;,])\s+/', '$1', $select2_css); | |
| 349 | + $select2_css = preg_replace('/\s\s+(.*)/', '$1', $select2_css); | |
| 350 | + wp_add_inline_style('adminify-select2', $select2_css); | |
| 260 | 351 | } |
| 261 | 352 | } |