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