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