← All changes
|
admin/views/sp-framework/classes/setup.class.php
+58
-183
4.0.8
→
2.2.10
View file →
| @@ -1,75 +1,25 @@ | ||
| 1 | -<?php | |
| 1 | +<?php if ( ! defined( 'ABSPATH' ) ) { | |
| 2 | + die; } // Cannot a cess directly. | |
| 3 | + | |
| 2 | 4 | /** |
| 3 | - * The setup class of the plugin. | |
| 4 | 5 | * |
| 5 | - * @package Smart_Post_Show | |
| 6 | - * @subpackage Smart_Post_Show/views/sp-framework/classes | |
| 6 | + * Setup Class | |
| 7 | + * | |
| 8 | + * @since 1.0.0 | |
| 9 | + * @version 1.0.0 | |
| 7 | 10 | */ |
| 8 | - | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | - exit; // Exit if accessed directly. | |
| 11 | -} | |
| 12 | - | |
| 13 | 11 | if ( ! class_exists( 'SP_PC' ) ) { |
| 14 | - | |
| 15 | - /** | |
| 16 | - * | |
| 17 | - * Setup Class | |
| 18 | - * | |
| 19 | - * @since 1.0.0 | |
| 20 | - * @version 1.0.0 | |
| 21 | - */ | |
| 22 | 12 | class SP_PC { |
| 23 | 13 | |
| 24 | - /** | |
| 25 | - * Constants. | |
| 26 | - * | |
| 27 | - * @var string | |
| 28 | - */ | |
| 14 | + // constants. | |
| 29 | 15 | public static $version = '2.0.6'; |
| 30 | - | |
| 31 | - /** | |
| 32 | - * Premium or not. | |
| 33 | - * | |
| 34 | - * @var boolean | |
| 35 | - */ | |
| 36 | 16 | public static $premium = true; |
| 37 | - | |
| 38 | - /** | |
| 39 | - * Directory. | |
| 40 | - * | |
| 41 | - * @var string | |
| 42 | - */ | |
| 43 | - public static $dir = null; | |
| 44 | - | |
| 45 | - /** | |
| 46 | - * URL | |
| 47 | - * | |
| 48 | - * @var string | |
| 49 | - */ | |
| 50 | - public static $url = null; | |
| 51 | - | |
| 52 | - /** | |
| 53 | - * Initiated. | |
| 54 | - * | |
| 55 | - * @var array | |
| 56 | - */ | |
| 57 | - public static $inited = array(); | |
| 58 | - | |
| 59 | - /** | |
| 60 | - * The fields array. | |
| 61 | - * | |
| 62 | - * @var array | |
| 63 | - */ | |
| 64 | - public static $fields = array(); | |
| 65 | - | |
| 66 | - /** | |
| 67 | - * The arguments. | |
| 68 | - * | |
| 69 | - * @var array | |
| 70 | - */ | |
| 71 | - public static $args = array( | |
| 17 | + public static $dir = null; | |
| 18 | + public static $url = null; | |
| 19 | + public static $inited = array(); | |
| 20 | + public static $fields = array(); | |
| 21 | + public static $args = array( | |
| 72 | 22 | 'options' => array(), |
| 73 | 23 | 'customize_options' => array(), |
| 74 | 24 | 'metaboxes' => array(), |
| 75 | 25 | 'shortcoders' => array(), |
| @@ -76,20 +26,12 @@ | ||
| 76 | 26 | 'taxonomy_options' => array(), |
| 77 | 27 | 'widgets' => array(), |
| 78 | 28 | ); |
| 79 | 29 | |
| 80 | - /** | |
| 81 | - * Shortcode instances. | |
| 82 | - * | |
| 83 | - * @var array | |
| 84 | - */ | |
| 30 | + // shortcode instances. | |
| 85 | 31 | public static $shortcode_instances = array(); |
| 86 | 32 | |
| 87 | - /** | |
| 88 | - * Init. | |
| 89 | - * | |
| 90 | - * @return void | |
| 91 | - */ | |
| 33 | + // init. | |
| 92 | 34 | public static function init() { |
| 93 | 35 | |
| 94 | 36 | // init action. |
| 95 | 37 | do_action( 'spf_init' ); |
| @@ -103,15 +45,12 @@ | ||
| 103 | 45 | add_action( 'after_setup_theme', array( 'SP_PC', 'setup' ) ); |
| 104 | 46 | add_action( 'init', array( 'SP_PC', 'setup' ) ); |
| 105 | 47 | add_action( 'switch_theme', array( 'SP_PC', 'setup' ) ); |
| 106 | 48 | add_action( 'admin_enqueue_scripts', array( 'SP_PC', 'add_admin_enqueue_scripts' ), 20 ); |
| 49 | + | |
| 107 | 50 | } |
| 108 | 51 | |
| 109 | - /** | |
| 110 | - * Setup. | |
| 111 | - * | |
| 112 | - * @return void | |
| 113 | - */ | |
| 52 | + // setup. | |
| 114 | 53 | public static function setup() { |
| 115 | 54 | |
| 116 | 55 | // setup options. |
| 117 | 56 | $params = array(); |
| @@ -147,9 +86,9 @@ | ||
| 147 | 86 | } |
| 148 | 87 | } |
| 149 | 88 | } |
| 150 | 89 | |
| 151 | - // create widgets. | |
| 90 | + // create widgets | |
| 152 | 91 | if ( ! empty( self::$args['widgets'] ) && class_exists( 'WP_Widget_Factory' ) ) { |
| 153 | 92 | |
| 154 | 93 | $wp_widget_factory = new WP_Widget_Factory(); |
| 155 | 94 | |
| @@ -161,65 +100,38 @@ | ||
| 161 | 100 | } |
| 162 | 101 | } |
| 163 | 102 | |
| 164 | 103 | do_action( 'spf_loaded' ); |
| 104 | + | |
| 165 | 105 | } |
| 166 | 106 | |
| 167 | - /** | |
| 168 | - * Create options. | |
| 169 | - * | |
| 170 | - * @param string $id The option ID. | |
| 171 | - * @param array $args The arguments array. | |
| 172 | - * @return void | |
| 173 | - */ | |
| 107 | + // create options. | |
| 174 | 108 | public static function createOptions( $id, $args = array() ) { |
| 175 | 109 | self::$args['options'][ $id ] = $args; |
| 176 | 110 | } |
| 177 | 111 | |
| 178 | - /** | |
| 179 | - * Create metabox options. | |
| 180 | - * | |
| 181 | - * @param string $id The option ID. | |
| 182 | - * @param array $args The arguments array. | |
| 183 | - * @return void | |
| 184 | - */ | |
| 112 | + // create metabox options. | |
| 185 | 113 | public static function createMetabox( $id, $args = array() ) { |
| 186 | 114 | self::$args['metaboxes'][ $id ] = $args; |
| 187 | 115 | } |
| 188 | 116 | |
| 189 | - /** | |
| 190 | - * Create widget. | |
| 191 | - * | |
| 192 | - * @param string $id The option ID. | |
| 193 | - * @param array $args The arguments array. | |
| 194 | - * @return void | |
| 195 | - */ | |
| 117 | + // create widget. | |
| 196 | 118 | public static function createWidget( $id, $args = array() ) { |
| 197 | 119 | self::$args['widgets'][ $id ] = $args; |
| 198 | 120 | self::set_used_fields( $args ); |
| 199 | 121 | } |
| 200 | 122 | |
| 201 | - /** | |
| 202 | - * Create sections. | |
| 203 | - * | |
| 204 | - * @param string $id The option ID. | |
| 205 | - * @param array $sections The sections array. | |
| 206 | - * @return void | |
| 207 | - */ | |
| 123 | + // create section. | |
| 208 | 124 | public static function createSection( $id, $sections ) { |
| 209 | 125 | self::$args['sections'][ $id ][] = $sections; |
| 210 | 126 | self::set_used_fields( $sections ); |
| 211 | 127 | } |
| 212 | 128 | |
| 213 | - /** | |
| 214 | - * Constants. | |
| 215 | - * | |
| 216 | - * @return void | |
| 217 | - */ | |
| 129 | + // constants. | |
| 218 | 130 | public static function constants() { |
| 219 | 131 | |
| 220 | 132 | // we need this path-finder code for set URL of framework. |
| 221 | - $dirname = wp_normalize_path( dirname( __DIR__ ) ); | |
| 133 | + $dirname = wp_normalize_path( dirname( dirname( __FILE__ ) ) ); | |
| 222 | 134 | $theme_dir = wp_normalize_path( get_parent_theme_file_path() ); |
| 223 | 135 | $plugin_dir = wp_normalize_path( WP_PLUGIN_DIR ); |
| 224 | 136 | $located_plugin = ( preg_match( '#' . self::sanitize_dirname( $plugin_dir ) . '#', self::sanitize_dirname( $dirname ) ) ) ? true : false; |
| 225 | 137 | $directory = ( $located_plugin ) ? $plugin_dir : $theme_dir; |
| @@ -229,18 +141,11 @@ | ||
| 229 | 141 | $directory_uri = set_url_scheme( $directory_uri, $protocol_uri ); |
| 230 | 142 | |
| 231 | 143 | self::$dir = $dirname; |
| 232 | 144 | self::$url = $directory_uri . $foldername; |
| 145 | + | |
| 233 | 146 | } |
| 234 | 147 | |
| 235 | - /** | |
| 236 | - * Include plugin files. | |
| 237 | - * | |
| 238 | - * @param string $file Plugin files. | |
| 239 | - * @param boolean $load Load files. | |
| 240 | - * | |
| 241 | - * @return mixed | |
| 242 | - */ | |
| 243 | 148 | public static function include_plugin_file( $file, $load = true ) { |
| 244 | 149 | |
| 245 | 150 | $path = ''; |
| 246 | 151 | $file = ltrim( $file, '/' ); |
| @@ -273,39 +178,26 @@ | ||
| 273 | 178 | |
| 274 | 179 | return self::$dir . '/' . $file; |
| 275 | 180 | |
| 276 | 181 | } |
| 182 | + | |
| 277 | 183 | } |
| 278 | 184 | |
| 279 | - /** | |
| 280 | - * Is plugin active. | |
| 281 | - * | |
| 282 | - * @param string $file The plugin file. | |
| 283 | - * @return boolean | |
| 284 | - */ | |
| 285 | 185 | public static function is_active_plugin( $file = '' ) { |
| 286 | 186 | return in_array( $file, (array) get_option( 'active_plugins', array() ) ); |
| 287 | 187 | } |
| 288 | 188 | |
| 289 | - /** | |
| 290 | - * Sanitize dirname. | |
| 291 | - * | |
| 292 | - * @param string $dirname The directory name. | |
| 293 | - * @return string | |
| 294 | - */ | |
| 189 | + // Sanitize dirname. | |
| 295 | 190 | public static function sanitize_dirname( $dirname ) { |
| 296 | 191 | return preg_replace( '/[^A-Za-z]/', '', $dirname ); |
| 297 | 192 | } |
| 298 | 193 | |
| 299 | - /** | |
| 300 | - * General includes. | |
| 301 | - * | |
| 302 | - * @return void | |
| 303 | - */ | |
| 194 | + // General includes. | |
| 304 | 195 | public static function includes() { |
| 305 | 196 | |
| 306 | 197 | // includes helpers. |
| 307 | 198 | self::include_plugin_file( 'functions/actions.php' ); |
| 199 | + self::include_plugin_file( 'functions/deprecated.php' ); | |
| 308 | 200 | self::include_plugin_file( 'functions/helpers.php' ); |
| 309 | 201 | self::include_plugin_file( 'functions/sanitize.php' ); |
| 310 | 202 | self::include_plugin_file( 'functions/validate.php' ); |
| 311 | 203 | |
| @@ -315,12 +207,14 @@ | ||
| 315 | 207 | self::include_plugin_file( 'classes/options.class.php' ); |
| 316 | 208 | |
| 317 | 209 | // includes premium version classes. |
| 318 | 210 | if ( self::$premium ) { |
| 211 | + //self::include_plugin_file( 'classes/customize-options.class.php' ); | |
| 319 | 212 | self::include_plugin_file( 'classes/metabox.class.php' ); |
| 320 | 213 | |
| 321 | 214 | self::include_plugin_file( 'classes/widgets.class.php' ); |
| 322 | 215 | } |
| 216 | + | |
| 323 | 217 | } |
| 324 | 218 | |
| 325 | 219 | /** |
| 326 | 220 | * Include field. |
| @@ -362,21 +256,17 @@ | ||
| 362 | 256 | self::$fields[ $field['type'] ] = $field; |
| 363 | 257 | } |
| 364 | 258 | } |
| 365 | 259 | } |
| 260 | + | |
| 366 | 261 | } |
| 367 | 262 | |
| 368 | - /** | |
| 369 | - * Enqueue admin and fields styles and scripts. | |
| 370 | - * | |
| 371 | - * @return void | |
| 372 | - */ | |
| 263 | + // | |
| 264 | + // Enqueue admin and fields styles and scripts. | |
| 373 | 265 | public static function add_admin_enqueue_scripts() { |
| 374 | 266 | $current_screen = get_current_screen(); |
| 375 | 267 | $the_current_post_type = $current_screen->post_type; |
| 376 | - $pcp_page_base = 'sp_post_carousel_page_pcp_settings' === $current_screen->base || 'sp_post_carousel_page_pcp_tools' === $current_screen->base || 'sp_post_carousel_page_pcp_replace_layout' === $current_screen->base || 'sp_post_carousel_page_pcp_help' === $current_screen->base; | |
| 377 | - | |
| 378 | - if ( 'sp_post_carousel' === $the_current_post_type || $pcp_page_base ) { | |
| 268 | + if ( 'sp_post_carousel' === $the_current_post_type ) { | |
| 379 | 269 | // check for developer mode. |
| 380 | 270 | $min = ( apply_filters( 'spf_dev_mode', false ) || WP_DEBUG ) ? '' : '.min'; |
| 381 | 271 | // admin utilities. |
| 382 | 272 | wp_enqueue_media(); |
| @@ -383,35 +273,33 @@ | ||
| 383 | 273 | // wp color picker. |
| 384 | 274 | wp_enqueue_style( 'wp-color-picker' ); |
| 385 | 275 | wp_enqueue_script( 'wp-color-picker' ); |
| 386 | 276 | // framework core styles. |
| 387 | - wp_enqueue_style( 'spf', SP_PC_URL . 'admin/views/sp-framework/assets/css/spf.min.css', array(), SP_PC_VERSION, 'all' ); | |
| 277 | + wp_enqueue_style( 'spf', SP_PC_URL . 'admin/views/sp-framework/assets/css/spf.css', array(), SP_PC_VERSION, 'all' ); | |
| 388 | 278 | // rtl styles. |
| 389 | 279 | if ( is_rtl() ) { |
| 390 | - wp_enqueue_style( 'spf-rtl', SP_PC_URL . 'admin/views/sp-framework/assets/css/spf-rtl.min.css', array(), SP_PC_VERSION, 'all' ); | |
| 280 | + wp_enqueue_style( 'spf-rtl', SP_PC_URL . 'admin/views/sp-framework/assets/css/spf-rtl' . $min . '.css', array(), SP_PC_VERSION, 'all' ); | |
| 391 | 281 | } |
| 392 | 282 | |
| 393 | 283 | // framework core scripts. |
| 394 | - wp_enqueue_script( 'spf-plugins', SP_PC_URL . 'admin/views/sp-framework/assets/js/spf-plugins.min.js', array(), SP_PC_VERSION, true ); | |
| 395 | - wp_enqueue_script( 'spf', SP_PC_URL . 'admin/views/sp-framework/assets/js/spf.min.js', array( 'spf-plugins' ), SP_PC_VERSION, true ); | |
| 284 | + wp_enqueue_script( 'spf-plugins', SP_PC_URL . 'admin/views/sp-framework/assets/js/spf-plugins' . $min . '.js', array(), SP_PC_VERSION, true ); | |
| 285 | + wp_enqueue_script( 'spf', SP_PC_URL . 'admin/views/sp-framework/assets/js/spf' . $min . '.js', array( 'spf-plugins' ), SP_PC_VERSION, true ); | |
| 396 | 286 | |
| 397 | 287 | wp_localize_script( |
| 398 | 288 | 'spf', |
| 399 | 289 | 'spf_vars', |
| 400 | 290 | array( |
| 401 | - 'previewJS' => esc_url( SP_PC_URL . 'public/assets/js/scripts.min.js' ), | |
| 402 | 291 | 'color_palette' => apply_filters( 'spf_color_palette', array() ), |
| 403 | 292 | 'i18n' => array( |
| 404 | 293 | // global localize. |
| 405 | - 'confirm' => esc_html__( 'Are you sure?', 'post-carousel' ), | |
| 406 | - 'reset_notification' => esc_html__( 'Restoring options.', 'post-carousel' ), | |
| 407 | - 'import_notification' => esc_html__( 'Importing options.', 'post-carousel' ), | |
| 294 | + 'confirm' => esc_html__( 'Are you sure?', 'smart-post-show' ), | |
| 295 | + 'reset_notification' => esc_html__( 'Restoring options.', 'smart-post-show' ), | |
| 296 | + 'import_notification' => esc_html__( 'Importing options.', 'smart-post-show' ), | |
| 408 | 297 | |
| 409 | 298 | // chosen localize. |
| 410 | - /* translators: %s: minimum number of characters required */ | |
| 411 | - 'typing_text' => esc_html__( 'Please enter %s or more characters', 'post-carousel' ), | |
| 412 | - 'searching_text' => esc_html__( 'Searching...', 'post-carousel' ), | |
| 413 | - 'no_results_text' => esc_html__( 'No results match', 'post-carousel' ), | |
| 299 | + 'typing_text' => esc_html__( 'Please enter %s or more characters', 'smart-post-show' ), | |
| 300 | + 'searching_text' => esc_html__( 'Searching...', 'smart-post-show' ), | |
| 301 | + 'no_results_text' => esc_html__( 'No results match', 'smart-post-show' ), | |
| 414 | 302 | ), |
| 415 | 303 | ) |
| 416 | 304 | ); |
| 417 | 305 | |
| @@ -435,20 +323,13 @@ | ||
| 435 | 323 | } |
| 436 | 324 | |
| 437 | 325 | do_action( 'spf_enqueue' ); |
| 438 | 326 | } // Check screen ID. |
| 327 | + | |
| 439 | 328 | } |
| 440 | 329 | |
| 441 | - /** | |
| 442 | - * Add a new framework field. | |
| 443 | - * | |
| 444 | - * @param array $field The fields array. | |
| 445 | - * @param string $value The field value. | |
| 446 | - * @param string $unique The unique string. | |
| 447 | - * @param string $where The position to show the fields. | |
| 448 | - * @param string $parent If the fields has parent. | |
| 449 | - * @return void | |
| 450 | - */ | |
| 330 | + // | |
| 331 | + // Add a new framework field. | |
| 451 | 332 | public static function field( $field = array(), $value = '', $unique = '', $where = '', $parent = '' ) { |
| 452 | 333 | |
| 453 | 334 | // Check for unallow fields. |
| 454 | 335 | if ( ! empty( $field['_notice'] ) ) { |
| @@ -454,11 +335,10 @@ | ||
| 454 | 335 | if ( ! empty( $field['_notice'] ) ) { |
| 455 | 336 | |
| 456 | 337 | $field_type = $field['type']; |
| 457 | 338 | |
| 458 | - $field = array(); | |
| 459 | - /* translators: 1: field type */ | |
| 460 | - $field['content'] = sprintf( esc_html__( 'Ooops! This field type (%s) can not be used here, yet.', 'post-carousel' ), '<strong>' . $field_type . '</strong>' ); | |
| 339 | + $field = array(); | |
| 340 | + $field['content'] = sprintf( esc_html__( 'Ooops! This field type (%s) can not be used here, yet.', 'smart-post-show' ), '<strong>' . $field_type . '</strong>' ); | |
| 461 | 341 | $field['type'] = 'notice'; |
| 462 | 342 | $field['style'] = 'danger'; |
| 463 | 343 | |
| 464 | 344 | } |
| @@ -499,20 +379,13 @@ | ||
| 499 | 379 | } |
| 500 | 380 | |
| 501 | 381 | if ( ! empty( $field_type ) ) { |
| 502 | 382 | |
| 503 | - echo '<div class="spf-field spf-field-' . esc_attr( $field_type ) . esc_attr( $is_pseudo ) . esc_attr( $class ) . esc_attr( $hidden ) . '"' . wp_kses_post( $depend ) . '>'; | |
| 383 | + echo '<div class="spf-field spf-field-' . $field_type . $is_pseudo . $class . $hidden . '"' . $depend . '>'; | |
| 504 | 384 | |
| 505 | - // if ( ! empty( $field['title'] ) ) { | |
| 506 | - // $subtitle = ( ! empty( $field['subtitle'] ) ) ? '<p class="spf-text-subtitle">' . $field['subtitle'] . '</p>' : ''; | |
| 507 | - // echo '<div class="spf-title"><h4>' . esc_html( $field['title'] ) . '</h4>' . wp_kses_post( $subtitle ) . '</div>'; | |
| 508 | - // } | |
| 509 | 385 | if ( ! empty( $field['title'] ) ) { |
| 510 | - $subtitle = ( ! empty( $field['subtitle'] ) ) ? '<p class="spf-text-subtitle">' . $field['subtitle'] . '</p>' : ''; | |
| 511 | - $title_info = ( ! empty( $field['title_info'] ) ) ? '<span class="spf-help title-info"><div class="spf-help-text">' . wp_kses_post( $field['title_info'] ) . '</div><span class="tooltip-icon"><img src="' . SP_PC_URL . '/admin/assets/img/info.svg"></span></span>' : ''; | |
| 512 | - | |
| 513 | - echo '<div class="spf-title"><h4>' . wp_kses_post( $field['title'] . $title_info ) . '</h4>' . wp_kses_post( $subtitle ) . '</div>'; | |
| 514 | - | |
| 386 | + $subtitle = ( ! empty( $field['subtitle'] ) ) ? '<p class="spf-text-subtitle">' . $field['subtitle'] . '</p>' : ''; | |
| 387 | + echo '<div class="spf-title"><h4>' . $field['title'] . '</h4>' . $subtitle . '</div>'; | |
| 515 | 388 | } |
| 516 | 389 | |
| 517 | 390 | echo ( ! empty( $field['title'] ) ) ? '<div class="spf-fieldset">' : ''; |
| 518 | 391 | |
| @@ -526,18 +399,20 @@ | ||
| 526 | 399 | if ( class_exists( $classname ) ) { |
| 527 | 400 | $instance = new $classname( $field, $value, $unique, $where, $parent ); |
| 528 | 401 | $instance->render(); |
| 529 | 402 | } else { |
| 530 | - echo '<p>' . esc_html__( 'This field class is not available!', 'post-carousel' ) . '</p>'; | |
| 403 | + echo '<p>' . esc_html__( 'This field class is not available!', 'smart-post-show' ) . '</p>'; | |
| 531 | 404 | } |
| 532 | 405 | } else { |
| 533 | - echo '<p>' . esc_html__( 'This type is not found!', 'post-carousel' ) . '</p>'; | |
| 406 | + echo '<p>' . esc_html__( 'This type is not found!', 'smart-post-show' ) . '</p>'; | |
| 534 | 407 | } |
| 535 | 408 | |
| 536 | 409 | echo ( ! empty( $field['title'] ) ) ? '</div>' : ''; |
| 537 | 410 | echo '<div class="clear"></div>'; |
| 538 | 411 | echo '</div>'; |
| 412 | + | |
| 539 | 413 | } |
| 414 | + | |
| 540 | 415 | } |
| 541 | 416 | |
| 542 | 417 | SP_PC::init(); |
| 543 | 418 | } |