| 1 |
<?php |
| 2 |
|
| 3 |
namespace PXLBSAdminify\Inc\Modules\MenuEditor; |
| 4 |
|
| 5 |
use PXLBSAdminify\Inc\Utils; |
| 6 |
use PXLBSAdminify\Inc\Admin\AdminSettings; |
| 7 |
use PXLBSAdminify\Inc\Admin\AdminSettingsModel; |
| 8 |
|
| 9 |
// no direct access allowed |
| 10 |
if (!defined('ABSPATH')) { |
| 11 |
exit; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* WP Adminify |
| 16 |
* |
| 17 |
* @package WP Adminify: Menu Editor |
| 18 |
* |
| 19 |
* @author WP Adminify <support@wpadminify.com> |
| 20 |
*/ |
| 21 |
|
| 22 |
class MenuEditorAssets extends AdminSettingsModel |
| 23 |
{ |
| 24 |
|
| 25 |
public $max_upload_size; |
| 26 |
public function __construct() |
| 27 |
{ |
| 28 |
$this->max_upload_size = \wp_max_upload_size(); |
| 29 |
$this->options = (array) AdminSettings::get_instance()->get(); |
| 30 |
add_action('admin_enqueue_scripts', [$this, 'menu_editor_enqueue_scripts'], 100); |
| 31 |
} |
| 32 |
|
| 33 |
public function menu_editor_enqueue_scripts() |
| 34 |
{ |
| 35 |
global $pagenow; |
| 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)) { |
| 40 |
return; |
| 41 |
} |
| 42 |
|
| 43 |
// 2. Handle customize.php |
| 44 |
if ($pagenow === 'customize.php') { |
| 45 |
return; |
| 46 |
} |
| 47 |
|
| 48 |
$screen = get_current_screen(); |
| 49 |
|
| 50 |
if ($screen && $screen->id === 'toplevel_page_wp-adminify-settings') { |
| 51 |
$this->import_css(); |
| 52 |
|
| 53 |
// Enqueue Styles |
| 54 |
wp_enqueue_style('adminify-icon-picker'); |
| 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); |
| 58 |
|
| 59 |
// Enqueue Scripts |
| 60 |
wp_enqueue_script('adminify-select2', PXLBSADMINIFY_ASSETS . 'vendors/select2/select2.min.js', array('jquery'), PXLBSADMINIFY_VER, true); |
| 61 |
$this->add_select2_inline_script(); |
| 62 |
wp_enqueue_script('adminify-icon-picker'); |
| 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); |
| 64 |
|
| 65 |
wp_localize_script( |
| 66 |
'adminify-icon-picker', |
| 67 |
'PXLBSADMINIFY_ICON_PICKER', |
| 68 |
[ |
| 69 |
'is_elementor_active' => Utils::is_plugin_active('elementor/elementor.php'), |
| 70 |
] |
| 71 |
); |
| 72 |
} |
| 73 |
|
| 74 |
wp_enqueue_style('dashicons'); |
| 75 |
|
| 76 |
// Plugins Packaged Icons Library |
| 77 |
$plugins_icons = []; |
| 78 |
// if (Utils::is_plugin_active('elementor/elementor.php')) { |
| 79 |
// $plugins_icons[] = 'elementor-icons'; |
| 80 |
// } |
| 81 |
|
| 82 |
// De-register and Dequeue Scripts/Styles |
| 83 |
// if (!empty($this->options['adminify_assets'])) { |
| 84 |
// foreach ($this->options['adminify_assets'] as $value) { |
| 85 |
// wp_dequeue_style($value); |
| 86 |
// wp_deregister_style($value); |
| 87 |
// } |
| 88 |
// } |
| 89 |
|
| 90 |
// Localize Scripts |
| 91 |
$localize_menu_data = [ |
| 92 |
'resturl' => get_rest_url() . 'wpadminify/v2/', |
| 93 |
'ajax_url' => admin_url('admin-ajax.php'), |
| 94 |
'assets_manager' => !empty($this->options['adminify_assets']) ? $this->options['adminify_assets'] : '', |
| 95 |
'plugins_icons' => $plugins_icons, |
| 96 |
'icon_picker_logo' => PXLBSADMINIFY_ASSETS_IMAGE . 'logos/menu-icon.svg', |
| 97 |
'security' => wp_create_nonce('pxlbsadminify-menu-editor-security-nonce'), |
| 98 |
'max_upload_size' => size_format(wp_max_upload_size()), |
| 99 |
'can_use_premium' => jltwp_adminify()->can_use_premium_code__premium_only(), |
| 100 |
'baseurl' => wp_upload_dir()['baseurl'], |
| 101 |
]; |
| 102 |
wp_localize_script('adminify-menu-editor', 'PXLBSADMINIFY_MENU_EDITOR', $localize_menu_data); |
| 103 |
} |
| 104 |
|
| 105 |
/**Import Menu CSS */ |
| 106 |
public function import_css() |
| 107 |
{ |
| 108 |
$menu_editor_custom_css = ''; |
| 109 |
$menu_editor_custom_css .= '.wp-adminify #wpbody-content .page-title-action{ top: -3px !important; ) |
| 110 |
.dropdown-content{ position: relative; } |
| 111 |
#adminify_import_menu{cursor: pointer;overflow: hidden;font-size: 500px;position: absolute;top: 38px;z-index: 1;width: 100%;height: 30px;left: 0;-webkit-appearance: none;opacity: 0;cursor: pointer;} |
| 112 |
.icon-picker-container { |
| 113 |
position : absolute; |
| 114 |
width : 550px; |
| 115 |
height : 290px; |
| 116 |
font-size : 14px; |
| 117 |
background-color : #fff; |
| 118 |
-webkit-box-shadow: 0 1px 5px rgba(0, 0, 0, 0.1); |
| 119 |
box-shadow : 0 1px 2px rgba(0, 0, 0, 0.1); |
| 120 |
overflow : hidden; |
| 121 |
padding : 5px; |
| 122 |
box-sizing : border-box; |
| 123 |
z-index : 9999; |
| 124 |
} |
| 125 |
.icon-picker-container { |
| 126 |
margin-left: -220px; |
| 127 |
margin-top : 50px; |
| 128 |
width : 30%; |
| 129 |
z-index : 999999 !important; |
| 130 |
} |
| 131 |
li.jltma-icommon { |
| 132 |
margin: 3px 3px !important; |
| 133 |
} |
| 134 |
li.jltma-icommon a { |
| 135 |
border : none !important; |
| 136 |
padding: 1px 2px !important; |
| 137 |
} |
| 138 |
.icon-picker-container ul li.jltma-icommon a:hover{ |
| 139 |
background: none !important; |
| 140 |
} |
| 141 |
|
| 142 |
.icon-picker-container ul { |
| 143 |
margin : 0; |
| 144 |
padding : 0; |
| 145 |
margin-top : 8px; |
| 146 |
margin-bottom: 10px; |
| 147 |
} |
| 148 |
.icon-picker-container ul li a span { |
| 149 |
width : 20px; |
| 150 |
height : 20px; |
| 151 |
font-size : 20px; |
| 152 |
display : block; |
| 153 |
text-align: left; |
| 154 |
} |
| 155 |
.icon-picker-container ul li { |
| 156 |
display: inline-block; |
| 157 |
margin : 5px; |
| 158 |
float : left; |
| 159 |
} |
| 160 |
.icon-picker-container ul li a { |
| 161 |
display : block; |
| 162 |
text-decoration: none; |
| 163 |
color : #373737; |
| 164 |
padding : 6px 10px; |
| 165 |
border : 1px solid #eee; |
| 166 |
} |
| 167 |
.icon-picker-container ul li a:hover { |
| 168 |
border-color: #999; |
| 169 |
background : #efefef; |
| 170 |
} |
| 171 |
.icon-picker-control { |
| 172 |
height: 32px; |
| 173 |
height: 64px; |
| 174 |
} |
| 175 |
.icon-picker-control a { |
| 176 |
padding : 5px; |
| 177 |
text-decoration: none; |
| 178 |
line-height : 32px; |
| 179 |
width : 25px; |
| 180 |
} |
| 181 |
.icon-picker-control a span { |
| 182 |
display : inline; |
| 183 |
vertical-align: middle; |
| 184 |
} |
| 185 |
.icon-picker-control input { |
| 186 |
width: 200px; |
| 187 |
} |
| 188 |
.icon-picker-control p { |
| 189 |
text-align: left; |
| 190 |
margin : 0; |
| 191 |
padding : 3px 10px; |
| 192 |
} |
| 193 |
.icon-picker-control select { |
| 194 |
margin : 0 auto; |
| 195 |
display: inline-block; |
| 196 |
width : auto; |
| 197 |
} |
| 198 |
/* DIV Button with Preview */ |
| 199 |
div.button.icon-picker { |
| 200 |
font-size : 24px; |
| 201 |
height : 30px; |
| 202 |
width : 30px; |
| 203 |
margin : 0; |
| 204 |
padding : 0; |
| 205 |
line-height: 30px; |
| 206 |
text-align : center; |
| 207 |
} |
| 208 |
.button.icon-picker:before{ |
| 209 |
content : "\f504"; |
| 210 |
font-family: dashicons; |
| 211 |
font-size : 30px; |
| 212 |
} |
| 213 |
.icon-picker-close{ |
| 214 |
float : right; |
| 215 |
display : inline-block; |
| 216 |
padding : 2px; |
| 217 |
background : #ccc; |
| 218 |
cursor : pointer; |
| 219 |
font-weight: 600; |
| 220 |
} |
| 221 |
.jltma-pro-badge{ |
| 222 |
position : absolute; |
| 223 |
z-index : 333; |
| 224 |
text-align : center; |
| 225 |
padding-left: 23%; |
| 226 |
font-size : 70px !important; |
| 227 |
padding-top : 10%; |
| 228 |
} |
| 229 |
.top-badge{ |
| 230 |
padding-left: 20%; |
| 231 |
padding-top : 0; |
| 232 |
} |
| 233 |
.jltma-disabled{ |
| 234 |
pointer-events: none; |
| 235 |
opacity : 0.4; |
| 236 |
} |
| 237 |
.select2-option-disabled{ |
| 238 |
opacity: 0.5; |
| 239 |
cursor: not-allowed; |
| 240 |
} |
| 241 |
.select2-container--default .select2-results__option[aria-disabled=true]{ |
| 242 |
background: none !important; |
| 243 |
color: inherit; |
| 244 |
opacity: 0.5!important; |
| 245 |
} |
| 246 |
.select2-search-hint{ |
| 247 |
color: #999; |
| 248 |
font-style: italic; |
| 249 |
} |
| 250 |
select[name="hidden_for"].select2-hidden-accessible{ |
| 251 |
position: absolute !important; |
| 252 |
width: 1px !important; |
| 253 |
height: 1px !important; |
| 254 |
padding: 0 !important; |
| 255 |
margin: -1px !important; |
| 256 |
overflow: hidden !important; |
| 257 |
clip: rect(0,0,0,0) !important; |
| 258 |
border: 0 !important; |
| 259 |
} |
| 260 |
.adminify_sub_menu_item .select2-container, |
| 261 |
.adminify_menu_item .select2-container{ |
| 262 |
width: 100% !important; |
| 263 |
}'; |
| 264 |
|
| 265 |
// Combine the values from above and minifiy them. |
| 266 |
$menu_editor_custom_css = preg_replace('#/\*.*?\*/#s', '', $menu_editor_custom_css); |
| 267 |
$menu_editor_custom_css = preg_replace('/\s*([{}|:;,])\s+/', '$1', $menu_editor_custom_css); |
| 268 |
$menu_editor_custom_css = preg_replace('/\s\s+(.*)/', '$1', $menu_editor_custom_css); |
| 269 |
|
| 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); |
| 351 |
} |
| 352 |
} |
| 353 |
|