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