balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-redux-args.php (12742B)


      1 <?php
      2 /**
      3  * Redux Framework Args Class
      4  *
      5  * @package     Redux_Framework/Classes
      6  */
      7 
      8 // Exit if accessed directly.
      9 defined( 'ABSPATH' ) || exit;
     10 
     11 if ( ! class_exists( 'Redux_Args', false ) ) {
     12 
     13 	/**
     14 	 * Class Redux_Args
     15 	 */
     16 	class Redux_Args {
     17 
     18 		/**
     19 		 * Returns entire arguments array.
     20 		 *
     21 		 * @var array|mixed
     22 		 */
     23 		public $get = array();
     24 
     25 		/**
     26 		 * ReduxFramework object.
     27 		 *
     28 		 * @var null
     29 		 */
     30 		private $parent;
     31 
     32 		/**
     33 		 * Switch to omit social icons if dev_mode is set to true and Redux defaults are used.
     34 		 *
     35 		 * @var bool
     36 		 */
     37 		public $omit_icons = false;
     38 
     39 		/**
     40 		 * Switch to omit support menu items if dev_mode is set to true and redux defaults are used.
     41 		 *
     42 		 * @var bool
     43 		 */
     44 		public $omit_items = false;
     45 
     46 		/**
     47 		 * Flag to force dev_mod to true if in localhost or WP_DEBUG is set to true.
     48 		 *
     49 		 * @var bool
     50 		 */
     51 		public $dev_mode_forced = false;
     52 
     53 		/**
     54 		 * Redux_Args constructor.
     55 		 *
     56 		 * @param     object $parent ReduxFramework object.
     57 		 * @param     array  $args Global arguments array.
     58 		 */
     59 		public function __construct( $parent, array $args ) {
     60 			$this->parent = $parent;
     61 
     62 			$default = array(
     63 				'opt_name'                         => '',
     64 				'last_tab'                         => '',
     65 				'menu_icon'                        => '',
     66 				'menu_title'                       => '',
     67 				'page_title'                       => '',
     68 				'page_slug'                        => '',
     69 				'page_permissions'                 => 'manage_options',
     70 				'menu_type'                        => 'menu',
     71 				'page_parent'                      => 'themes.php',
     72 				'page_priority'                    => null,
     73 				'allow_sub_menu'                   => true,
     74 				'save_defaults'                    => true,
     75 				'footer_credit'                    => '',
     76 				'async_typography'                 => false,
     77 				'disable_google_fonts_link'        => false,
     78 				'class'                            => '',
     79 				'admin_bar'                        => true,
     80 				'admin_bar_priority'               => 999,
     81 				'admin_bar_icon'                   => '',
     82 				'help_tabs'                        => array(),
     83 				'help_sidebar'                     => '',
     84 				'database'                         => '',
     85 				'customizer'                       => false,
     86 				'global_variable'                  => '',
     87 				'output'                           => true,
     88 				'output_variables_prefix'          => '--',
     89 				'compiler_output_variables_prefix' => '$',
     90 				'compiler'                         => true,
     91 				'output_tag'                       => true,
     92 				'output_location'                  => array( 'frontend' ),
     93 				'transient_time'                   => '',
     94 				'default_show'                     => false,
     95 				'default_mark'                     => '',
     96 				'disable_save_warn'                => false,
     97 				'open_expanded'                    => false,
     98 				'hide_expand'                      => false,
     99 				'network_admin'                    => false,
    100 				'network_sites'                    => true,
    101 				'hide_reset'                       => false,
    102 				'hide_save'                        => false,
    103 				'hints'                            => array(
    104 					'icon'          => 'el el-question-sign',
    105 					'icon_position' => 'right',
    106 					'icon_color'    => 'lightgray',
    107 					'icon_size'     => 'normal',
    108 					'tip_style'     => array(
    109 						'color'   => 'light',
    110 						'shadow'  => true,
    111 						'rounded' => false,
    112 						'style'   => '',
    113 					),
    114 					'tip_position'  => array(
    115 						'my' => 'top_left',
    116 						'at' => 'bottom_right',
    117 					),
    118 					'tip_effect'    => array(
    119 						'show' => array(
    120 							'effect'   => 'slide',
    121 							'duration' => '500',
    122 							'event'    => 'mouseover',
    123 						),
    124 						'hide' => array(
    125 							'effect'   => 'fade',
    126 							'duration' => '500',
    127 							'event'    => 'click mouseleave',
    128 						),
    129 					),
    130 				),
    131 				'font_weights'                     => array(
    132 					array(
    133 						'id'   => '400',
    134 						'name' => __( 'Regular 400', 'redux-framework' ),
    135 					),
    136 					array(
    137 						'id'   => '400italic',
    138 						'name' => __( 'Regular 400 Italic', 'redux-framework' ),
    139 					),
    140 					array(
    141 						'id'   => '700',
    142 						'name' => __( 'Bold 700', 'redux-framework' ),
    143 					),
    144 					array(
    145 						'id'   => '700italic',
    146 						'name' => __( 'Bold 700 Italic', 'redux-framework' ),
    147 					),
    148 				),
    149 				'show_import_export'               => true,
    150 				'show_options_object'              => true,
    151 				'dev_mode'                         => true,
    152 				'templates_path'                   => '',
    153 				'ajax_save'                        => true,
    154 				'use_cdn'                          => true,
    155 				'cdn_check_time'                   => 1440,
    156 				'options_api'                      => true,
    157 				'allow_tracking'                   => true,
    158 				'admin_theme'                      => 'wp',
    159 				'elusive_frontend'                 => false,
    160 				'pro'                              => array(),
    161 				'font_display'                     => 'swap', // block|swap|fallback|optional.
    162 				'load_on_cron'                     => false,
    163 			);
    164 
    165 			// phpcs:ignore WordPress.NamingConventions.ValidHookName
    166 			$default = apply_filters( 'redux/pro/args/defaults', $default );
    167 
    168 			$args = Redux_Functions::parse_args( $args, $default );
    169 
    170 			$args = $this->args( $args );
    171 
    172 			$args = $this->default_cleanup( $args );
    173 
    174 			if ( ! in_array( $args['font_display'], array( 'block', 'swap', 'fallback', 'optional' ), true ) ) {
    175 				$args['font_display'] = 'swap';
    176 			}
    177 
    178 			if ( isset( $args['async_typography'] ) && $args['async_typography'] ) {
    179 				$args['async_typography'] = false;
    180 			}
    181 
    182 			$this->get = $args;
    183 
    184 			$this->parent->args = $args;
    185 
    186 			if ( 'redux_extensions_demo' !== $args['opt_name'] && 'redux_demo' !== $args['opt_name'] ) {
    187 				$this->change_demo_defaults( $args );
    188 			}
    189 		}
    190 
    191 		/**
    192 		 * Builds and sanitizes global args array.
    193 		 *
    194 		 * @param     array $args Global args.
    195 		 *
    196 		 * @return array
    197 		 */
    198 		private function args( array $args ): array {
    199 			$args = $this->no_errors_please( $args );
    200 
    201 			$this->parent->old_opt_name = $args['opt_name'];
    202 
    203 			$args = $this->filters( $args );
    204 
    205 			if ( ! function_exists( 'wp_rand' ) ) {
    206 				require_once ABSPATH . '/wp-includes/pluggable.php';
    207 			}
    208 
    209 			$this->parent->core_instance = chr( 64 + wp_rand( 1, 26 ) ) . time() . '_' . wp_rand( 0, 1000000 );
    210 			$this->parent->core_thread   = chr( 64 + wp_rand( 1, 26 ) ) . time() . '_' . wp_rand( 0, 1000000 );
    211 
    212 			if ( $args['opt_name'] === $this->parent->old_opt_name ) {
    213 				$this->parent->old_opt_name = null;
    214 				unset( $this->parent->old_opt_name );
    215 			}
    216 
    217 			// Do not save the defaults if we're on a live preview!
    218 			if ( 'customize' === $GLOBALS['pagenow'] && isset( $_GET['customize_theme'] ) && ! empty( $_GET['customize_theme'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification
    219 				$args['save_defaults'] = false;
    220 			}
    221 
    222 			return $this->shim( $args );
    223 		}
    224 
    225 		/**
    226 		 * Apply filters to arg data.
    227 		 *
    228 		 * @param     array $args Global args.
    229 		 *
    230 		 * @return mixed|void
    231 		 */
    232 		private function filters( array $args ) {
    233 			/**
    234 			 * Filter 'redux/args/{opt_name}'
    235 			 *
    236 			 * @param     array     $args ReduxFramework configuration
    237 			 */
    238 
    239 			// phpcs:ignore WordPress.NamingConventions.ValidHookName
    240 			$args = apply_filters( "redux/args/{$args['opt_name']}", $args );
    241 
    242 			/**
    243 			 * Filter 'redux/options/{opt_name}/args'
    244 			 *
    245 			 * @param     array     $args ReduxFramework configuration
    246 			 */
    247 
    248 			// phpcs:ignore WordPress.NamingConventions.ValidHookName
    249 			return apply_filters( "redux/options/{$args['opt_name']}/args", $args );
    250 		}
    251 
    252 		/**
    253 		 * Sanitize args that should not be empty.
    254 		 *
    255 		 * @param     array $args Global args.
    256 		 *
    257 		 * @return array
    258 		 */
    259 		private function no_errors_please( array $args ): array {
    260 			if ( empty( $args['transient_time'] ) ) {
    261 				$args['transient_time'] = 60 * MINUTE_IN_SECONDS;
    262 			}
    263 
    264 			if ( empty( $args['footer_credit'] ) ) {
    265 
    266 				$footer_text = sprintf(
    267 				/* translators: 1: Redux, 2: Link to plugin review */
    268 					__( 'Enjoyed %1$s? Please leave us a %2$s rating. We really appreciate your support!', 'redux-framework' ),
    269 					'<strong>' . __( 'Redux', 'redux-framework' ) . '</strong>',
    270 					'<a href="https://wordpress.org/support/plugin/redux-framework/reviews/?filter=5/#new-post" target="_blank">&#9733;&#9733;&#9733;&#9733;&#9733;</a>'
    271 				);
    272 				$args['footer_credit'] = '<span id="footer-thankyou">' . $footer_text . '</span>';
    273 			}
    274 
    275 			if ( empty( $args['menu_title'] ) ) {
    276 				$args['menu_title'] = esc_html__( 'Options', 'redux-framework' );
    277 			}
    278 
    279 			if ( empty( $args['page_title'] ) ) {
    280 				$args['page_title'] = esc_html__( 'Options', 'redux-framework' );
    281 			}
    282 
    283 			// Auto create the page_slug appropriately.
    284 			if ( empty( $args['page_slug'] ) ) {
    285 				if ( ! empty( $args['display_name'] ) ) {
    286 					$args['page_slug'] = sanitize_html_class( $args['display_name'] );
    287 				} elseif ( ! empty( $args['page_title'] ) ) {
    288 					$args['page_slug'] = sanitize_html_class( $args['page_title'] );
    289 				} elseif ( ! empty( $args['menu_title'] ) ) {
    290 					$args['page_slug'] = sanitize_html_class( $args['menu_title'] );
    291 				} else {
    292 					$args['page_slug'] = str_replace( '-', '_', $args['opt_name'] );
    293 				}
    294 			}
    295 
    296 			return $args;
    297 		}
    298 
    299 		/**
    300 		 * Shims for much older v3 configs.
    301 		 *
    302 		 * @param     array $args Global args.
    303 		 *
    304 		 * @return array
    305 		 */
    306 		private function shim( array $args ): array {
    307 			/**
    308 			 * SHIM SECTION
    309 			 * Old variables and ways of doing things that need correcting.  ;)
    310 			 * */
    311 			// Variable name change.
    312 			if ( ! empty( $args['page_cap'] ) ) {
    313 				$args['page_permissions'] = $args['page_cap'];
    314 				unset( $args['page_cap'] );
    315 			}
    316 
    317 			if ( ! empty( $args['page_position'] ) ) {
    318 				$args['page_priority'] = $args['page_position'];
    319 				unset( $args['page_position'] );
    320 			}
    321 
    322 			if ( ! empty( $args['page_type'] ) ) {
    323 				$args['menu_type'] = $args['page_type'];
    324 				unset( $args['page_type'] );
    325 			}
    326 
    327 			return $args;
    328 		}
    329 
    330 		/**
    331 		 * Verify to see if dev has bothered to change admin bar links and share icons from demo data to their own.
    332 		 *
    333 		 * @param array $args Global args.
    334 		 */
    335 		private function change_demo_defaults( array $args ) {
    336 			if ( $args['dev_mode'] || true === Redux_Helpers::is_local_host() ) {
    337 				if ( ! empty( $args['admin_bar_links'] ) ) {
    338 					foreach ( $args['admin_bar_links'] as $idx => $arr ) {
    339 						if ( is_array( $arr ) && ! empty( $arr ) ) {
    340 							foreach ( $arr as $x => $y ) {
    341 								if ( strpos( Redux_Core::strtolower( $y ), 'redux' ) !== false ) {
    342 									$msg = '<strong>' . esc_html__( 'Redux Framework Notice', 'redux-framework' ) . ' </strong>' .
    343 										esc_html__( 'There are references to the Redux Framework support site in your config\'s ', 'redux-framework' ) .
    344 										'<code>admin_bar_links</code> ' . esc_html__( 'argument.  This is sample data.  Please change or remove this data before shipping your product.', 'redux-framework' );
    345 
    346 									$this->omit_items = true;
    347 									break;
    348 								}
    349 							}
    350 						}
    351 					}
    352 				}
    353 
    354 				if ( ! empty( $args['share_icons'] ) ) {
    355 					foreach ( $args['share_icons'] as $idx => $arr ) {
    356 						if ( is_array( $arr ) && ! empty( $arr ) ) {
    357 							foreach ( $arr as $x => $y ) {
    358 								if ( strpos( Redux_Core::strtolower( $y ), 'redux' ) !== false ) {
    359 									$msg = '<strong>' . esc_html__( 'Redux Framework Notice:', 'redux-framework' ) . '</strong>' .
    360 										esc_html__( 'There are references to the Redux Framework support site in your config\'s', 'redux-framework' ) .
    361 										' <code>share_icons</code> ' . esc_html__( 'argument.  This is sample data.  Please change or remove this data before shipping your product.', 'redux-framework' );
    362 
    363 									$this->omit_icons = true;
    364 								}
    365 							}
    366 						}
    367 					}
    368 				}
    369 			}
    370 		}
    371 
    372 		/**
    373 		 * Fix other arg criteria that sometimes gets hosed up.
    374 		 *
    375 		 * @param array $args Global args.
    376 		 *
    377 		 * @return array
    378 		 */
    379 		private function default_cleanup( array $args ): array {
    380 
    381 			// Fix the global variable name.
    382 			if ( '' === $args['global_variable'] && false !== $args['global_variable'] ) {
    383 				$args['global_variable'] = str_replace( '-', '_', $args['opt_name'] );
    384 			}
    385 
    386 			if ( isset( $args['customizer_only'] ) && $args['customizer_only'] ) {
    387 				$args['menu_type']      = 'hidden';
    388 				$args['customizer']     = true;
    389 				$args['admin_bar']      = false;
    390 				$args['allow_sub_menu'] = false;
    391 			}
    392 
    393 			// Check if the Airplane Mode plugin is installed.
    394 			if ( class_exists( 'Airplane_Mode_Core' ) ) {
    395 				$airplane = Airplane_Mode_Core::getInstance();
    396 				if ( method_exists( $airplane, 'enabled' ) ) {
    397 					if ( $airplane->enabled() ) {
    398 						$args['use_cdn'] = false;
    399 					}
    400 				} elseif ( 'on' === $airplane->check_status() ) {
    401 					$args['use_cdn'] = false;
    402 				}
    403 			}
    404 
    405 			return $args;
    406 		}
    407 	}
    408 }