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