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