| 1 |
<?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly. |
| 2 |
/** |
| 3 |
* |
| 4 |
* Setup Class |
| 5 |
* |
| 6 |
* @since 1.0.0 |
| 7 |
* @version 1.0.0 |
| 8 |
* |
| 9 |
*/ |
| 10 |
if ( ! class_exists( 'ADMINIFY_Setup' ) ) { |
| 11 |
class ADMINIFY_Setup { |
| 12 |
|
| 13 |
// Default constants |
| 14 |
public static $premium = true; |
| 15 |
public static $version = '2.3.1'; |
| 16 |
public static $dir = ''; |
| 17 |
public static $url = ''; |
| 18 |
public static $css = ''; |
| 19 |
public static $file = ''; |
| 20 |
public static $enqueue = false; |
| 21 |
public static $webfonts = array(); |
| 22 |
public static $subsets = array(); |
| 23 |
public static $inited = array(); |
| 24 |
public static $fields = array(); |
| 25 |
public static $args = array( |
| 26 |
'admin_options' => array(), |
| 27 |
'customize_options' => array(), |
| 28 |
'metabox_options' => array(), |
| 29 |
'nav_menu_options' => array(), |
| 30 |
'profile_options' => array(), |
| 31 |
'taxonomy_options' => array(), |
| 32 |
'widget_options' => array(), |
| 33 |
'comment_options' => array(), |
| 34 |
'shortcode_options' => array(), |
| 35 |
); |
| 36 |
|
| 37 |
// Shortcode instances |
| 38 |
public static $shortcode_instances = array(); |
| 39 |
|
| 40 |
private static $instance = null; |
| 41 |
|
| 42 |
public static function init( $file = __FILE__, $premium = true ) { |
| 43 |
|
| 44 |
// Set file constant |
| 45 |
self::$file = $file; |
| 46 |
|
| 47 |
// Set file constant |
| 48 |
self::$premium = $premium; |
| 49 |
|
| 50 |
// Set constants |
| 51 |
self::constants(); |
| 52 |
|
| 53 |
// Include files |
| 54 |
self::includes(); |
| 55 |
|
| 56 |
if ( is_null( self::$instance ) ) { |
| 57 |
self::$instance = new self(); |
| 58 |
} |
| 59 |
|
| 60 |
return self::$instance; |
| 61 |
|
| 62 |
} |
| 63 |
|
| 64 |
// Initalize |
| 65 |
public function __construct() { |
| 66 |
|
| 67 |
// Init action |
| 68 |
do_action( 'adminify_init' ); |
| 69 |
|
| 70 |
// Setup textdomain |
| 71 |
add_action( 'init', function(){ |
| 72 |
self::textdomain(); |
| 73 |
}); |
| 74 |
|
| 75 |
add_action( 'after_setup_theme', array( 'ADMINIFY', 'setup' ) ); |
| 76 |
add_action( 'init', array( 'ADMINIFY', 'setup' ) ); |
| 77 |
add_action( 'switch_theme', array( 'ADMINIFY', 'setup' ) ); |
| 78 |
add_action( 'admin_enqueue_scripts', array( 'ADMINIFY', 'add_admin_enqueue_scripts' ) ); |
| 79 |
add_action( 'wp_enqueue_scripts', array( 'ADMINIFY', 'add_typography_enqueue_styles' ), 80 ); |
| 80 |
add_action( 'wp_head', array( 'ADMINIFY', 'add_custom_css' ), 80 ); |
| 81 |
add_filter( 'admin_body_class', array( 'ADMINIFY', 'add_admin_body_class' ) ); |
| 82 |
|
| 83 |
} |
| 84 |
|
| 85 |
// Setup frameworks |
| 86 |
public static function setup() { |
| 87 |
|
| 88 |
// Welcome |
| 89 |
self::include_plugin_file( 'views/welcome.php' ); |
| 90 |
|
| 91 |
// Setup admin option framework |
| 92 |
$params = array(); |
| 93 |
if ( class_exists( 'ADMINIFY_Options' ) && ! empty( self::$args['admin_options'] ) ) { |
| 94 |
foreach ( self::$args['admin_options'] as $key => $value ) { |
| 95 |
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) { |
| 96 |
|
| 97 |
$params['args'] = $value; |
| 98 |
$params['sections'] = self::$args['sections'][$key]; |
| 99 |
self::$inited[$key] = true; |
| 100 |
|
| 101 |
ADMINIFY_Options::instance( $key, $params ); |
| 102 |
|
| 103 |
if ( ! empty( $value['show_in_customizer'] ) ) { |
| 104 |
$value['output_css'] = false; |
| 105 |
$value['enqueue_webfont'] = false; |
| 106 |
self::$args['customize_options'][$key] = $value; |
| 107 |
self::$inited[$key] = null; |
| 108 |
} |
| 109 |
|
| 110 |
} |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
// Setup customize option framework |
| 115 |
$params = array(); |
| 116 |
if ( class_exists( 'ADMINIFY_Customize_Options' ) && ! empty( self::$args['customize_options'] ) ) { |
| 117 |
foreach ( self::$args['customize_options'] as $key => $value ) { |
| 118 |
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) { |
| 119 |
|
| 120 |
$params['args'] = $value; |
| 121 |
$params['sections'] = self::$args['sections'][$key]; |
| 122 |
self::$inited[$key] = true; |
| 123 |
|
| 124 |
ADMINIFY_Customize_Options::instance( $key, $params ); |
| 125 |
|
| 126 |
} |
| 127 |
} |
| 128 |
} |
| 129 |
|
| 130 |
// Setup metabox option framework |
| 131 |
$params = array(); |
| 132 |
if ( class_exists( 'ADMINIFY_Metabox' ) && ! empty( self::$args['metabox_options'] ) ) { |
| 133 |
foreach ( self::$args['metabox_options'] as $key => $value ) { |
| 134 |
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) { |
| 135 |
|
| 136 |
$params['args'] = $value; |
| 137 |
$params['sections'] = self::$args['sections'][$key]; |
| 138 |
self::$inited[$key] = true; |
| 139 |
|
| 140 |
ADMINIFY_Metabox::instance( $key, $params ); |
| 141 |
|
| 142 |
} |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
// Setup nav menu option framework |
| 147 |
$params = array(); |
| 148 |
if ( class_exists( 'ADMINIFY_Nav_Menu_Options' ) && ! empty( self::$args['nav_menu_options'] ) ) { |
| 149 |
foreach ( self::$args['nav_menu_options'] as $key => $value ) { |
| 150 |
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) { |
| 151 |
|
| 152 |
$params['args'] = $value; |
| 153 |
$params['sections'] = self::$args['sections'][$key]; |
| 154 |
self::$inited[$key] = true; |
| 155 |
|
| 156 |
ADMINIFY_Nav_Menu_Options::instance( $key, $params ); |
| 157 |
|
| 158 |
} |
| 159 |
} |
| 160 |
} |
| 161 |
|
| 162 |
// Setup profile option framework |
| 163 |
$params = array(); |
| 164 |
if ( class_exists( 'ADMINIFY_Profile_Options' ) && ! empty( self::$args['profile_options'] ) ) { |
| 165 |
foreach ( self::$args['profile_options'] as $key => $value ) { |
| 166 |
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) { |
| 167 |
|
| 168 |
$params['args'] = $value; |
| 169 |
$params['sections'] = self::$args['sections'][$key]; |
| 170 |
self::$inited[$key] = true; |
| 171 |
|
| 172 |
ADMINIFY_Profile_Options::instance( $key, $params ); |
| 173 |
|
| 174 |
} |
| 175 |
} |
| 176 |
} |
| 177 |
|
| 178 |
// Setup taxonomy option framework |
| 179 |
$params = array(); |
| 180 |
if ( class_exists( 'ADMINIFY_Taxonomy_Options' ) && ! empty( self::$args['taxonomy_options'] ) ) { |
| 181 |
$taxonomy = ( isset( $_GET['taxonomy'] ) ) ? sanitize_text_field( wp_unslash( $_GET['taxonomy'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only check, no state change. |
| 182 |
foreach ( self::$args['taxonomy_options'] as $key => $value ) { |
| 183 |
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) { |
| 184 |
|
| 185 |
$params['args'] = $value; |
| 186 |
$params['sections'] = self::$args['sections'][$key]; |
| 187 |
self::$inited[$key] = true; |
| 188 |
|
| 189 |
ADMINIFY_Taxonomy_Options::instance( $key, $params ); |
| 190 |
|
| 191 |
} |
| 192 |
} |
| 193 |
} |
| 194 |
|
| 195 |
// Setup widget option framework |
| 196 |
if ( class_exists( 'ADMINIFY_Widget' ) && class_exists( 'WP_Widget_Factory' ) && ! empty( self::$args['widget_options'] ) ) { |
| 197 |
$wp_widget_factory = new WP_Widget_Factory(); |
| 198 |
global $wp_widget_factory; |
| 199 |
foreach ( self::$args['widget_options'] as $key => $value ) { |
| 200 |
if ( ! isset( self::$inited[$key] ) ) { |
| 201 |
|
| 202 |
self::$inited[$key] = true; |
| 203 |
$wp_widget_factory->register( ADMINIFY_Widget::instance( $key, $value ) ); |
| 204 |
|
| 205 |
} |
| 206 |
} |
| 207 |
} |
| 208 |
|
| 209 |
// Setup comment option framework |
| 210 |
$params = array(); |
| 211 |
if ( class_exists( 'ADMINIFY_Comment_Metabox' ) && ! empty( self::$args['comment_options'] ) ) { |
| 212 |
foreach ( self::$args['comment_options'] as $key => $value ) { |
| 213 |
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) { |
| 214 |
|
| 215 |
$params['args'] = $value; |
| 216 |
$params['sections'] = self::$args['sections'][$key]; |
| 217 |
self::$inited[$key] = true; |
| 218 |
|
| 219 |
ADMINIFY_Comment_Metabox::instance( $key, $params ); |
| 220 |
|
| 221 |
} |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
// Setup shortcode option framework |
| 226 |
$params = array(); |
| 227 |
if ( class_exists( 'ADMINIFY_Shortcoder' ) && ! empty( self::$args['shortcode_options'] ) ) { |
| 228 |
foreach ( self::$args['shortcode_options'] as $key => $value ) { |
| 229 |
if ( ! empty( self::$args['sections'][$key] ) && ! isset( self::$inited[$key] ) ) { |
| 230 |
|
| 231 |
$params['args'] = $value; |
| 232 |
$params['sections'] = self::$args['sections'][$key]; |
| 233 |
self::$inited[$key] = true; |
| 234 |
|
| 235 |
ADMINIFY_Shortcoder::instance( $key, $params ); |
| 236 |
|
| 237 |
} |
| 238 |
} |
| 239 |
|
| 240 |
// Once editor setup for gutenberg and media buttons |
| 241 |
if ( class_exists( 'ADMINIFY_Shortcoder' ) && ! empty( self::$shortcode_instances ) ) { |
| 242 |
foreach ( self::$shortcode_instances as $instance ) { |
| 243 |
if ( ! empty( $instance['show_in_editor'] ) ) { |
| 244 |
ADMINIFY_Shortcoder::once_editor_setup(); |
| 245 |
break; |
| 246 |
} |
| 247 |
} |
| 248 |
} |
| 249 |
|
| 250 |
} |
| 251 |
|
| 252 |
do_action( 'adminify_loaded' ); |
| 253 |
|
| 254 |
} |
| 255 |
|
| 256 |
// Create options |
| 257 |
public static function createOptions( $id, $args = array() ) { |
| 258 |
self::$args['admin_options'][$id] = $args; |
| 259 |
} |
| 260 |
|
| 261 |
// Create customize options |
| 262 |
public static function createCustomizeOptions( $id, $args = array() ) { |
| 263 |
self::$args['customize_options'][$id] = $args; |
| 264 |
} |
| 265 |
|
| 266 |
// Create metabox options |
| 267 |
public static function createMetabox( $id, $args = array() ) { |
| 268 |
self::$args['metabox_options'][$id] = $args; |
| 269 |
} |
| 270 |
|
| 271 |
// Create menu options |
| 272 |
public static function createNavMenuOptions( $id, $args = array() ) { |
| 273 |
self::$args['nav_menu_options'][$id] = $args; |
| 274 |
} |
| 275 |
|
| 276 |
// Create shortcoder options |
| 277 |
public static function createShortcoder( $id, $args = array() ) { |
| 278 |
self::$args['shortcode_options'][$id] = $args; |
| 279 |
} |
| 280 |
|
| 281 |
// Create taxonomy options |
| 282 |
public static function createTaxonomyOptions( $id, $args = array() ) { |
| 283 |
self::$args['taxonomy_options'][$id] = $args; |
| 284 |
} |
| 285 |
|
| 286 |
// Create profile options |
| 287 |
public static function createProfileOptions( $id, $args = array() ) { |
| 288 |
self::$args['profile_options'][$id] = $args; |
| 289 |
} |
| 290 |
|
| 291 |
// Create widget |
| 292 |
public static function createWidget( $id, $args = array() ) { |
| 293 |
self::$args['widget_options'][$id] = $args; |
| 294 |
self::set_used_fields( $args ); |
| 295 |
} |
| 296 |
|
| 297 |
// Create comment metabox |
| 298 |
public static function createCommentMetabox( $id, $args = array() ) { |
| 299 |
self::$args['comment_options'][$id] = $args; |
| 300 |
} |
| 301 |
|
| 302 |
// Create section |
| 303 |
public static function createSection( $id, $sections ) { |
| 304 |
self::$args['sections'][$id][] = $sections; |
| 305 |
self::set_used_fields( $sections ); |
| 306 |
} |
| 307 |
|
| 308 |
// Set directory constants |
| 309 |
public static function constants() { |
| 310 |
|
| 311 |
// We need this path-finder code for set URL of framework |
| 312 |
$dirname = str_replace( '//', '/', wp_normalize_path( dirname( dirname( self::$file ) ) ) ); |
| 313 |
$theme_dir = str_replace( '//', '/', wp_normalize_path( get_parent_theme_file_path() ) ); |
| 314 |
$plugin_dir = str_replace( '//', '/', wp_normalize_path( WP_PLUGIN_DIR ) ); |
| 315 |
$plugin_dir = str_replace( '/opt/bitnami', '/bitnami', $plugin_dir ); |
| 316 |
$located_plugin = ( preg_match( '#'. self::sanitize_dirname( $plugin_dir ) .'#', self::sanitize_dirname( $dirname ) ) ) ? true : false; |
| 317 |
$directory = ( $located_plugin ) ? $plugin_dir : $theme_dir; |
| 318 |
$directory_uri = ( $located_plugin ) ? WP_PLUGIN_URL : get_parent_theme_file_uri(); |
| 319 |
$foldername = str_replace( $directory, '', $dirname ); |
| 320 |
$protocol_uri = ( is_ssl() ) ? 'https' : 'http'; |
| 321 |
$directory_uri = set_url_scheme( $directory_uri, $protocol_uri ); |
| 322 |
|
| 323 |
self::$dir = $dirname; |
| 324 |
self::$url = $directory_uri . $foldername; |
| 325 |
|
| 326 |
} |
| 327 |
|
| 328 |
// Include file helper |
| 329 |
public static function include_plugin_file( $file, $load = true ) { |
| 330 |
|
| 331 |
$path = ''; |
| 332 |
$file = ltrim( $file, '/' ); |
| 333 |
$override = apply_filters( 'adminify_override', 'adminify-override' ); |
| 334 |
|
| 335 |
if ( file_exists( get_parent_theme_file_path( $override .'/'. $file ) ) ) { |
| 336 |
$path = get_parent_theme_file_path( $override .'/'. $file ); |
| 337 |
} elseif ( file_exists( get_theme_file_path( $override .'/'. $file ) ) ) { |
| 338 |
$path = get_theme_file_path( $override .'/'. $file ); |
| 339 |
} elseif ( file_exists( self::$dir .'/'. $override .'/'. $file ) ) { |
| 340 |
$path = self::$dir .'/'. $override .'/'. $file; |
| 341 |
} elseif ( file_exists( self::$dir .'/'. $file ) ) { |
| 342 |
$path = self::$dir .'/'. $file; |
| 343 |
} |
| 344 |
|
| 345 |
if ( ! empty( $path ) && ! empty( $file ) && $load ) { |
| 346 |
|
| 347 |
global $wp_query; |
| 348 |
|
| 349 |
if ( is_object( $wp_query ) && function_exists( 'load_template' ) ) { |
| 350 |
|
| 351 |
load_template( $path, true ); |
| 352 |
|
| 353 |
} else { |
| 354 |
|
| 355 |
require_once( $path ); |
| 356 |
|
| 357 |
} |
| 358 |
|
| 359 |
} else { |
| 360 |
|
| 361 |
return self::$dir .'/'. $file; |
| 362 |
|
| 363 |
} |
| 364 |
|
| 365 |
} |
| 366 |
|
| 367 |
// Is active plugin helper |
| 368 |
public static function is_active_plugin( $file = '' ) { |
| 369 |
return in_array( $file, (array) get_option( 'active_plugins', array() ) ); |
| 370 |
} |
| 371 |
|
| 372 |
// Sanitize dirname |
| 373 |
public static function sanitize_dirname( $dirname ) { |
| 374 |
return preg_replace( '/[^A-Za-z]/', '', $dirname ); |
| 375 |
} |
| 376 |
|
| 377 |
// Set url constant |
| 378 |
public static function include_plugin_url( $file ) { |
| 379 |
return esc_url( self::$url ) .'/'. ltrim( $file, '/' ); |
| 380 |
} |
| 381 |
|
| 382 |
// Include files |
| 383 |
public static function includes() { |
| 384 |
|
| 385 |
// Include common functions |
| 386 |
self::include_plugin_file( 'functions/actions.php' ); |
| 387 |
self::include_plugin_file( 'functions/helpers.php' ); |
| 388 |
self::include_plugin_file( 'functions/sanitize.php' ); |
| 389 |
self::include_plugin_file( 'functions/validate.php' ); |
| 390 |
|
| 391 |
// Include free version classes |
| 392 |
self::include_plugin_file( 'classes/abstract.class.php' ); |
| 393 |
self::include_plugin_file( 'classes/fields.class.php' ); |
| 394 |
self::include_plugin_file( 'classes/admin-options.class.php' ); |
| 395 |
|
| 396 |
// Include premium version classes |
| 397 |
if ( self::$premium ) { |
| 398 |
self::include_plugin_file( 'classes/customize-options.class.php' ); |
| 399 |
self::include_plugin_file( 'classes/metabox-options.class.php' ); |
| 400 |
self::include_plugin_file( 'classes/nav-menu-options.class.php' ); |
| 401 |
self::include_plugin_file( 'classes/profile-options.class.php' ); |
| 402 |
self::include_plugin_file( 'classes/shortcode-options.class.php' ); |
| 403 |
self::include_plugin_file( 'classes/taxonomy-options.class.php' ); |
| 404 |
self::include_plugin_file( 'classes/widget-options.class.php' ); |
| 405 |
self::include_plugin_file( 'classes/comment-options.class.php' ); |
| 406 |
} |
| 407 |
|
| 408 |
// Include all framework fields |
| 409 |
$fields = apply_filters( 'adminify_fields', array( |
| 410 |
'accordion', |
| 411 |
'background', |
| 412 |
'backup', |
| 413 |
'border', |
| 414 |
'button_set', |
| 415 |
'callback', |
| 416 |
'checkbox', |
| 417 |
'code_editor', |
| 418 |
'color', |
| 419 |
'color_group', |
| 420 |
'content', |
| 421 |
'date', |
| 422 |
'datetime', |
| 423 |
'dimensions', |
| 424 |
'fieldset', |
| 425 |
'gallery', |
| 426 |
'group', |
| 427 |
'heading', |
| 428 |
'icon', |
| 429 |
'image_select', |
| 430 |
'link', |
| 431 |
'link_color', |
| 432 |
'map', |
| 433 |
'media', |
| 434 |
'notice', |
| 435 |
'number', |
| 436 |
'palette', |
| 437 |
'radio', |
| 438 |
'repeater', |
| 439 |
'select', |
| 440 |
'slider', |
| 441 |
'sortable', |
| 442 |
'sorter', |
| 443 |
'spacing', |
| 444 |
'spinner', |
| 445 |
'subheading', |
| 446 |
'submessage', |
| 447 |
'switcher', |
| 448 |
'tabbed', |
| 449 |
'text', |
| 450 |
'textarea', |
| 451 |
'typography', |
| 452 |
'upload', |
| 453 |
'wp_editor', |
| 454 |
) ); |
| 455 |
|
| 456 |
if ( ! empty( $fields ) ) { |
| 457 |
foreach ( $fields as $field ) { |
| 458 |
if ( ! class_exists( 'ADMINIFY_Field_'. $field ) && class_exists( 'ADMINIFY_Fields' ) ) { |
| 459 |
self::include_plugin_file( 'fields/'. $field .'/'. $field .'.php' ); |
| 460 |
} |
| 461 |
} |
| 462 |
} |
| 463 |
|
| 464 |
} |
| 465 |
|
| 466 |
// Setup textdomain |
| 467 |
public static function textdomain() { |
| 468 |
load_textdomain( 'adminify', self::$dir .'/languages/'. get_locale() .'.mo' ); |
| 469 |
} |
| 470 |
|
| 471 |
// Set all of used fields |
| 472 |
public static function set_used_fields( $sections ) { |
| 473 |
|
| 474 |
if ( ! empty( $sections['fields'] ) ) { |
| 475 |
|
| 476 |
foreach ( $sections['fields'] as $field ) { |
| 477 |
|
| 478 |
if ( ! empty( $field['fields'] ) ) { |
| 479 |
self::set_used_fields( $field ); |
| 480 |
} |
| 481 |
|
| 482 |
if ( ! empty( $field['tabs'] ) ) { |
| 483 |
self::set_used_fields( array( 'fields' => $field['tabs'] ) ); |
| 484 |
} |
| 485 |
|
| 486 |
if ( ! empty( $field['accordions'] ) ) { |
| 487 |
self::set_used_fields( array( 'fields' => $field['accordions'] ) ); |
| 488 |
} |
| 489 |
|
| 490 |
if ( ! empty( $field['elements'] ) ) { |
| 491 |
self::set_used_fields( array( 'fields' => $field['elements'] ) ); |
| 492 |
} |
| 493 |
|
| 494 |
if ( ! empty( $field['type'] ) ) { |
| 495 |
self::$fields[$field['type']] = $field; |
| 496 |
} |
| 497 |
|
| 498 |
} |
| 499 |
|
| 500 |
} |
| 501 |
|
| 502 |
} |
| 503 |
|
| 504 |
// Enqueue admin and fields styles and scripts |
| 505 |
public static function add_admin_enqueue_scripts() { |
| 506 |
|
| 507 |
if ( ! self::$enqueue ) { |
| 508 |
|
| 509 |
// Loads scripts and styles only when needed |
| 510 |
$wpscreen = get_current_screen(); |
| 511 |
|
| 512 |
if ( ! empty( self::$args['admin_options'] ) ) { |
| 513 |
foreach ( self::$args['admin_options'] as $argument ) { |
| 514 |
if ( substr( $wpscreen->id, -strlen( $argument['menu_slug'] ) ) === $argument['menu_slug'] ) { |
| 515 |
self::$enqueue = true; |
| 516 |
} |
| 517 |
} |
| 518 |
} |
| 519 |
|
| 520 |
if ( ! empty( self::$args['metabox_options'] ) ) { |
| 521 |
foreach ( self::$args['metabox_options'] as $argument ) { |
| 522 |
if ( in_array( $wpscreen->post_type, (array) $argument['post_type'] ) ) { |
| 523 |
self::$enqueue = true; |
| 524 |
} |
| 525 |
} |
| 526 |
} |
| 527 |
|
| 528 |
if ( ! empty( self::$args['taxonomy_options'] ) ) { |
| 529 |
foreach ( self::$args['taxonomy_options'] as $argument ) { |
| 530 |
if ( in_array( $wpscreen->taxonomy, (array) $argument['taxonomy'] ) ) { |
| 531 |
self::$enqueue = true; |
| 532 |
} |
| 533 |
} |
| 534 |
} |
| 535 |
|
| 536 |
if ( ! empty( self::$shortcode_instances ) ) { |
| 537 |
foreach ( self::$shortcode_instances as $argument ) { |
| 538 |
if ( ( $argument['show_in_editor'] && $wpscreen->base === 'post' ) || $argument['show_in_custom'] ) { |
| 539 |
self::$enqueue = true; |
| 540 |
} |
| 541 |
} |
| 542 |
} |
| 543 |
|
| 544 |
if ( ! empty( self::$args['widget_options'] ) && ( $wpscreen->id === 'widgets' || $wpscreen->id === 'customize' ) ) { |
| 545 |
self::$enqueue = true; |
| 546 |
} |
| 547 |
|
| 548 |
if ( ! empty( self::$args['customize_options'] ) && $wpscreen->id === 'customize' ) { |
| 549 |
self::$enqueue = true; |
| 550 |
} |
| 551 |
|
| 552 |
if ( ! empty( self::$args['nav_menu_options'] ) && $wpscreen->id === 'nav-menus' ) { |
| 553 |
self::$enqueue = true; |
| 554 |
} |
| 555 |
|
| 556 |
if ( ! empty( self::$args['profile_options'] ) && ( $wpscreen->id === 'profile' || $wpscreen->id === 'user-edit' ) ) { |
| 557 |
self::$enqueue = true; |
| 558 |
} |
| 559 |
|
| 560 |
if ( ! empty( self::$args['comment_options'] ) && $wpscreen->id === 'comment' ) { |
| 561 |
self::$enqueue = true; |
| 562 |
} |
| 563 |
|
| 564 |
if ( $wpscreen->id === 'tools_page_adminify-welcome' ) { |
| 565 |
self::$enqueue = true; |
| 566 |
} |
| 567 |
|
| 568 |
} |
| 569 |
|
| 570 |
if ( ! apply_filters( 'adminify_enqueue_assets', self::$enqueue ) ) { |
| 571 |
return; |
| 572 |
} |
| 573 |
|
| 574 |
// Admin utilities |
| 575 |
wp_enqueue_media(); |
| 576 |
|
| 577 |
// Wp color picker |
| 578 |
wp_enqueue_style( 'wp-color-picker' ); |
| 579 |
wp_enqueue_script( 'wp-color-picker' ); |
| 580 |
|
| 581 |
// Font awesome 4 and 5 loader. The font files live in the main plugin's |
| 582 |
// assets/ directory, not inside the framework, so resolve the base URL |
| 583 |
// from there to avoid a 404 on the framework-relative path. |
| 584 |
$adminify_fa_base = defined( 'PXLBSADMINIFY_ASSETS' ) |
| 585 |
? PXLBSADMINIFY_ASSETS . 'vendors/fontawesome/' |
| 586 |
: self::include_plugin_url( 'assets/vendors/fontawesome/' ); |
| 587 |
if ( apply_filters( 'adminify_fa4', false ) ) { |
| 588 |
wp_enqueue_style( 'adminify-fa', $adminify_fa_base . 'fa4/css/font-awesome.min.css', array(), '4.7.0', 'all' ); |
| 589 |
} else { |
| 590 |
wp_enqueue_style( 'adminify-fa5', $adminify_fa_base . 'fa5/css/all.min.css', array(), '5.15.4', 'all' ); |
| 591 |
wp_enqueue_style( 'adminify-fa5-v4-shims', $adminify_fa_base . 'fa5/css/v4-shims.min.css', array(), '5.15.4', 'all' ); |
| 592 |
} |
| 593 |
|
| 594 |
// Check for developer mode |
| 595 |
$min = ( self::$premium && SCRIPT_DEBUG ) ? '' : '.min'; |
| 596 |
|
| 597 |
// Main style |
| 598 |
wp_enqueue_style( 'adminify', self::include_plugin_url( 'assets/css/style'. $min .'.css' ), array(), self::$version, 'all' ); |
| 599 |
|
| 600 |
// Main RTL styles |
| 601 |
if ( is_rtl() ) { |
| 602 |
wp_enqueue_style( 'adminify-rtl', self::include_plugin_url( 'assets/css/style-rtl'. $min .'.css' ), array(), self::$version, 'all' ); |
| 603 |
} |
| 604 |
|
| 605 |
// Main scripts |
| 606 |
wp_enqueue_script( 'adminify-plugins', self::include_plugin_url( 'assets/js/plugins'. $min .'.js' ), array(), self::$version, true ); |
| 607 |
wp_enqueue_script( 'adminify', self::include_plugin_url( 'assets/js/main'. $min .'.js' ), array( 'adminify-plugins' ), self::$version, true ); |
| 608 |
|
| 609 |
// Main variables |
| 610 |
wp_localize_script( 'adminify', 'adminify_vars', array( |
| 611 |
'color_palette' => apply_filters( 'adminify_color_palette', array() ), |
| 612 |
'i18n' => array( |
| 613 |
'confirm' => esc_html__( 'Are you sure?', 'adminify' ), |
| 614 |
/* translators: %s: minimum number of characters required to trigger a search. */ |
| 615 |
'typing_text' => esc_html__( 'Please enter %s or more characters', 'adminify' ), |
| 616 |
'searching_text' => esc_html__( 'Searching...', 'adminify' ), |
| 617 |
'no_results_text' => esc_html__( 'No results found.', 'adminify' ), |
| 618 |
), |
| 619 |
) ); |
| 620 |
|
| 621 |
// Enqueue fields scripts and styles |
| 622 |
$enqueued = array(); |
| 623 |
|
| 624 |
if ( ! empty( self::$fields ) ) { |
| 625 |
foreach ( self::$fields as $field ) { |
| 626 |
if ( ! empty( $field['type'] ) ) { |
| 627 |
$classname = 'ADMINIFY_Field_' . $field['type']; |
| 628 |
if ( class_exists( $classname ) && method_exists( $classname, 'enqueue' ) ) { |
| 629 |
$instance = new $classname( $field ); |
| 630 |
if ( method_exists( $classname, 'enqueue' ) ) { |
| 631 |
$instance->enqueue(); |
| 632 |
} |
| 633 |
unset( $instance ); |
| 634 |
} |
| 635 |
} |
| 636 |
} |
| 637 |
} |
| 638 |
|
| 639 |
do_action( 'adminify_enqueue' ); |
| 640 |
|
| 641 |
} |
| 642 |
|
| 643 |
// Add typography enqueue styles to front page |
| 644 |
public static function add_typography_enqueue_styles() { |
| 645 |
|
| 646 |
if ( ! empty( self::$webfonts ) ) { |
| 647 |
|
| 648 |
if ( ! empty( self::$webfonts['enqueue'] ) ) { |
| 649 |
|
| 650 |
$query = array(); |
| 651 |
$fonts = array(); |
| 652 |
|
| 653 |
foreach ( self::$webfonts['enqueue'] as $family => $styles ) { |
| 654 |
$fonts[] = $family . ( ( ! empty( $styles ) ) ? ':'. implode( ',', $styles ) : '' ); |
| 655 |
} |
| 656 |
|
| 657 |
if ( ! empty( $fonts ) ) { |
| 658 |
$query['family'] = implode( '%7C', $fonts ); |
| 659 |
} |
| 660 |
|
| 661 |
if ( ! empty( self::$subsets ) ) { |
| 662 |
$query['subset'] = implode( ',', self::$subsets ); |
| 663 |
} |
| 664 |
|
| 665 |
$query['display'] = 'swap'; |
| 666 |
|
| 667 |
wp_enqueue_style( 'adminify-google-web-fonts', esc_url( add_query_arg( $query, '//fonts.googleapis.com/css' ) ), array(), PXLBSADMINIFY_VER ); |
| 668 |
|
| 669 |
} |
| 670 |
|
| 671 |
if ( ! empty( self::$webfonts['async'] ) ) { |
| 672 |
|
| 673 |
$fonts = array(); |
| 674 |
|
| 675 |
foreach ( self::$webfonts['async'] as $family => $styles ) { |
| 676 |
$fonts[] = $family . ( ( ! empty( $styles ) ) ? ':'. implode( ',', $styles ) : '' ); |
| 677 |
} |
| 678 |
|
| 679 |
wp_enqueue_script( 'adminify-google-web-fonts', self::include_plugin_url( 'assets/js/webfont.js' ), array(), self::$version, false ); |
| 680 |
|
| 681 |
wp_localize_script( 'adminify-google-web-fonts', 'WebFontConfig', array( 'google' => array( 'families' => $fonts ) ) ); |
| 682 |
|
| 683 |
} |
| 684 |
|
| 685 |
} |
| 686 |
|
| 687 |
} |
| 688 |
|
| 689 |
// Add admin body class |
| 690 |
public static function add_admin_body_class( $classes ) { |
| 691 |
|
| 692 |
if ( apply_filters( 'adminify_fa4', false ) ) { |
| 693 |
$classes .= 'adminify-fa5-shims'; |
| 694 |
} |
| 695 |
|
| 696 |
return $classes; |
| 697 |
|
| 698 |
} |
| 699 |
|
| 700 |
// Add custom css to front page |
| 701 |
public static function add_custom_css() { |
| 702 |
|
| 703 |
if ( ! empty( self::$css ) ) { |
| 704 |
echo '<style type="text/css">'. wp_strip_all_tags( self::$css ) .'</style>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- wp_strip_all_tags() removes all markup; CSS-only content cannot break out of the <style> block. |
| 705 |
} |
| 706 |
|
| 707 |
} |
| 708 |
|
| 709 |
// Add a new framework field |
| 710 |
public static function field( $field = array(), $value = '', $unique = '', $where = '', $parent = '' ) { |
| 711 |
|
| 712 |
// Check for unallow fields |
| 713 |
if ( ! empty( $field['_notice'] ) ) { |
| 714 |
|
| 715 |
$field_type = $field['type']; |
| 716 |
|
| 717 |
$field = array(); |
| 718 |
$field['content'] = esc_html__( 'Oops! Not allowed.', 'adminify' ) .' <strong>('. $field_type .')</strong>'; |
| 719 |
$field['type'] = 'notice'; |
| 720 |
$field['style'] = 'danger'; |
| 721 |
|
| 722 |
} |
| 723 |
|
| 724 |
$depend = ''; |
| 725 |
$visible = ''; |
| 726 |
$unique = ( ! empty( $unique ) ) ? $unique : ''; |
| 727 |
$class = ( ! empty( $field['class'] ) ) ? ' ' . esc_attr( $field['class'] ) : ''; |
| 728 |
$is_pseudo = ( ! empty( $field['pseudo'] ) ) ? ' adminify-pseudo-field' : ''; |
| 729 |
$field_type = ( ! empty( $field['type'] ) ) ? esc_attr( $field['type'] ) : ''; |
| 730 |
|
| 731 |
if ( ! empty( $field['dependency'] ) ) { |
| 732 |
|
| 733 |
$dependency = $field['dependency']; |
| 734 |
$depend_visible = ''; |
| 735 |
$data_controller = ''; |
| 736 |
$data_condition = ''; |
| 737 |
$data_value = ''; |
| 738 |
$data_global = ''; |
| 739 |
|
| 740 |
if ( is_array( $dependency[0] ) ) { |
| 741 |
$data_controller = implode( '|', array_column( $dependency, 0 ) ); |
| 742 |
$data_condition = implode( '|', array_column( $dependency, 1 ) ); |
| 743 |
$data_value = implode( '|', array_column( $dependency, 2 ) ); |
| 744 |
$data_global = implode( '|', array_column( $dependency, 3 ) ); |
| 745 |
$depend_visible = implode( '|', array_column( $dependency, 4 ) ); |
| 746 |
} else { |
| 747 |
$data_controller = ( ! empty( $dependency[0] ) ) ? $dependency[0] : ''; |
| 748 |
$data_condition = ( ! empty( $dependency[1] ) ) ? $dependency[1] : ''; |
| 749 |
$data_value = ( ! empty( $dependency[2] ) ) ? $dependency[2] : ''; |
| 750 |
$data_global = ( ! empty( $dependency[3] ) ) ? $dependency[3] : ''; |
| 751 |
$depend_visible = ( ! empty( $dependency[4] ) ) ? $dependency[4] : ''; |
| 752 |
} |
| 753 |
|
| 754 |
$depend .= ' data-controller="'. esc_attr( $data_controller ) .'"'; |
| 755 |
$depend .= ' data-condition="'. esc_attr( $data_condition ) .'"'; |
| 756 |
$depend .= ' data-value="'. esc_attr( $data_value ) .'"'; |
| 757 |
$depend .= ( ! empty( $data_global ) ) ? ' data-depend-global="true"' : ''; |
| 758 |
|
| 759 |
$visible = ( ! empty( $depend_visible ) ) ? ' adminify-depend-visible' : ' adminify-depend-hidden'; |
| 760 |
|
| 761 |
} |
| 762 |
|
| 763 |
// These attributes has been sanitized above. |
| 764 |
ob_start(); |
| 765 |
echo '<div class="adminify-field adminify-field-'. esc_attr( $field_type . $is_pseudo . $class . $visible ) .'"'. $depend .'>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- value pre-escaped where built. |
| 766 |
|
| 767 |
if ( ! empty( $field_type ) ) { |
| 768 |
|
| 769 |
if ( ! empty( $field['title'] ) ) { |
| 770 |
echo '<div class="adminify-title">'; |
| 771 |
echo '<h4>'. wp_kses_post( $field['title'] ) .'</h4>'; |
| 772 |
echo ( ! empty( $field['subtitle'] ) ) ? '<div class="adminify-subtitle-text">'. wp_kses_post( $field['subtitle'] ) .'</div>' : ''; |
| 773 |
echo '</div>'; |
| 774 |
} |
| 775 |
|
| 776 |
echo ( ! empty( $field['title'] ) ) ? '<div class="adminify-fieldset">' : ''; |
| 777 |
|
| 778 |
$value = ( ! isset( $value ) && isset( $field['default'] ) ) ? $field['default'] : $value; |
| 779 |
$value = ( isset( $field['value'] ) ) ? $field['value'] : $value; |
| 780 |
|
| 781 |
$classname = 'ADMINIFY_Field_'. $field_type; |
| 782 |
|
| 783 |
if ( class_exists( $classname ) ) { |
| 784 |
$instance = new $classname( $field, $value, $unique, $where, $parent ); |
| 785 |
$instance->render(); |
| 786 |
} else { |
| 787 |
echo '<p>'. esc_html__( 'Field not found!', 'adminify' ) .'</p>'; |
| 788 |
} |
| 789 |
|
| 790 |
} else { |
| 791 |
echo '<p>'. esc_html__( 'Field not found!', 'adminify' ) .'</p>'; |
| 792 |
} |
| 793 |
|
| 794 |
echo ( ! empty( $field['title'] ) ) ? '</div>' : ''; |
| 795 |
echo '<div class="clear"></div>'; |
| 796 |
echo '</div>'; |
| 797 |
|
| 798 |
$html = ob_get_clean(); |
| 799 |
echo apply_filters( 'pxlbsadminify_render_field_html', $html, $field ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- value pre-escaped where built. |
| 800 |
|
| 801 |
} |
| 802 |
|
| 803 |
} |
| 804 |
|
| 805 |
} |
| 806 |
|
| 807 |
ADMINIFY_Setup::init( __FILE__, true ); |
| 808 |
|
| 809 |
/** |
| 810 |
* |
| 811 |
* Extended Setup Class for Shortland |
| 812 |
* |
| 813 |
* @since 1.0.0 |
| 814 |
* @version 1.0.0 |
| 815 |
* |
| 816 |
*/ |
| 817 |
if ( ! class_exists( 'ADMINIFY' ) ) { |
| 818 |
class ADMINIFY extends ADMINIFY_Setup{} |
| 819 |
} |
| 820 |
|