diff --git a/redux-core/framework.php b/redux-core/framework.php index 878ed1307..2b4cf47b1 100644 --- a/redux-core/framework.php +++ b/redux-core/framework.php @@ -49,10 +49,10 @@ class ReduxFramework { /** * ReduxFramework instance storage. * - * @var ReduxFramework|null + * @var null * @access public */ - public static ?ReduxFramework $instance; + public static $instance = null; /** * Redux current version. @@ -62,7 +62,7 @@ class ReduxFramework { * * @deprecated 4.0.0 */ - public static string $_version = ''; // phpcs:ignore PSR2.Classes.PropertyDeclaration + public static $_version = ''; // phpcs:ignore PSR2.Classes.PropertyDeclaration /** * Absolute directory of the Redux instance. @@ -72,7 +72,7 @@ class ReduxFramework { * * @deprecated 4.0.0 */ - public static string $_dir = ''; // phpcs:ignore PSR2.Classes.PropertyDeclaration + public static $_dir = ''; // phpcs:ignore PSR2.Classes.PropertyDeclaration /** * Full URL of the Redux instance. @@ -82,7 +82,7 @@ class ReduxFramework { * * @deprecated 4.0.0 */ - public static string $_url = ''; // phpcs:ignore PSR2.Classes.PropertyDeclaration + public static $_url = ''; // phpcs:ignore PSR2.Classes.PropertyDeclaration /** * Current WordPress upload directory. @@ -92,7 +92,7 @@ class ReduxFramework { * * @deprecated 4.0.0 */ - public static string $_upload_dir = ''; // phpcs:ignore PSR2.Classes.PropertyDeclaration + public static $_upload_dir = ''; // phpcs:ignore PSR2.Classes.PropertyDeclaration /** * Current WordPress upload URL @@ -102,7 +102,7 @@ class ReduxFramework { * * @deprecated 4.0.0 */ - public static string $_upload_url; // phpcs:ignore PSR2.Classes.PropertyDeclaration + public static $_upload_url; // phpcs:ignore PSR2.Classes.PropertyDeclaration /** * Init @@ -126,28 +126,28 @@ public static function init() { * * @var array */ - public array $fields = array(); + public $fields = array(); /** * Array of field types. * * @var array */ - public array $field_types = array(); + public $field_types = array(); /** * Array of field heads. * * @var array */ - public array $field_head = array(); + public $field_head = array(); /** * Array of extensions by type used in the panel. * * @var array */ - public array $extensions = array(); + public $extensions = array(); /** * Array of sections and fields arrays. @@ -161,271 +161,271 @@ public static function init() { * * @var array */ - public array $errors = array(); + public $errors = array(); /** * Array of generated warnings from the panel for localization. * * @var array */ - public array $warnings = array(); + public $warnings = array(); /** * Array of generated sanitize notices from the panel for localization. * * @var array */ - public array $sanitize = array(); + public $sanitize = array(); /** * Validation ran flag. * * @var bool */ - public bool $validation_ran; + public $validation_ran; /** * No output flag. * * @var bool */ - public bool $no_output; + public $no_output; /** * Array of current option values. * * @var array */ - public array $options = array(); + public $options = array(); /** * Array of option defaults. * - * @var array|null + * @var null */ - public ?array $options_defaults = array(); + public $options_defaults = null; /** * Array of fields set to trigger the compiler hook. * * @var array */ - public array $compiler_fields = array(); + public $compiler_fields = array(); /** * Field folding information for localization. * * @var array */ - public array $required = array(); + public $required = array(); /** * Field child-folding information for localization. * * @var array */ - public array $required_child = array(); + public $required_child = array(); /** * Array of fonts used by the panel for localization. * * @var array */ - public array $fonts = array(); + public $fonts = array(); /** * Array of Google fonts used by the panel for localization. * * @var array */ - public array $google_array = array(); + public $google_array = array(); /** * Array of fields to be folded. * * @var array */ - public array $folds = array(); + public $folds = array(); /** * Array of fields with CSS output selectors. * * @var array */ - public array $output = array(); + public $output = array(); /** * Autogenerated CSS appended to the header (snake case maintained for backward compatibility). * * @var string */ - public string $outputCSS = ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName + public $outputCSS = ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName /** * Autogenerated variables appended to dynamic output. * * @var array */ - public array $output_variables = array(); + public $output_variables = array(); /** * CSS sent to the compiler hook (snake case maintained for backward compatibility). * * @var string */ - public string $compilerCSS = ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName + public $compilerCSS = ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName /** * Array of fields that didn't pass the fold dependency test and are hidden. * * @var array */ - public array $fields_hidden = array(); + public $fields_hidden = array(); /** * Array of fields to use as pointers in extensions. * * @var array */ - public array $field_sections = array(); + public $field_sections = array(); /** * Values to generate google font CSS. * - * @var null|array + * @var string */ - public ?array $typography = array(); + public $typography = array(); /** * Array of global arguments. * - * @var array|null + * @var array|mixed */ - public ?array $args = array(); + public $args = array(); /** * Used in customizer hooks. * - * @var null|string + * @var string */ - public ?string $old_opt_name = ''; + public $old_opt_name = ''; /** * File system object used for I/O file operations. DOnr the WordPress way. * - * @var null|Redux_Filesystem + * @var null|object */ - public ?Redux_Filesystem $filesystem; + public $filesystem = null; /** * Array of various font groups used within the typography field. * * @var array */ - public array $font_groups = array(); + public $font_groups = array(); /** * Pointer to the Redux_Options_Default class. * * @var null|Redux_Options_Defaults */ - public ?Redux_Options_Defaults $options_defaults_class; + public $options_defaults_class = null; /** * Pointer to the Redux_Options class. * * @var null|Redux_Options_Constructor */ - public ?Redux_Options_Constructor $options_class; + public $options_class = null; /** * Pointer to the Redux_Required class * * @var null|Redux_Required */ - public ?Redux_Required $required_class; + public $required_class = null; /** * Pointer to the Redux_Output class. * * @var null|Redux_Output */ - public ?Redux_Output $output_class; + public $output_class = null; /** * Pointer to the Redux_Page_Render class. * * @var null|Redux_Page_Render */ - public ?Redux_Page_Render $render_class; + public $render_class = null; /** * Pointer to the Redux_Enqueue class. * * @var null|Redux_Enqueue */ - public ?Redux_Enqueue $enqueue_class; + public $enqueue_class = null; /** * Pointer to the Redux_Transients class. * * @var null|Redux_Transients */ - public ?Redux_Transients $transient_class; + public $transient_class = null; /** * Pointer to the Redux_wordPress_Data class. * * @var null|Redux_WordPress_Data */ - public ?Redux_WordPress_Data $wordpress_data; + public $wordpress_data = null; /** * Pointer to the Redux_Validation class. * * @var null|Redux_Validation */ - public ?Redux_Validation $validate_class; + public $validate_class = null; /** * Pointer to the Redux_Sanitize class. * - * @var null|Redux_Sanitize + * @var null|Redux_Validation */ - public ?Redux_Sanitize $sanitize_class = null; + public $sanitize_class = null; /** * Pointer to the Redux_Args class. * * @var null|Redux_Args */ - public ?Redux_Args $args_class; + public $args_class = null; /** * Array of active transients used by Redux. * - * @var mixed|null + * @var array */ public $transients = array(); /** * Array of localized repeater data. * - * @var null|array + * @var array */ - public ?array $repeater_data = array(); + public $repeater_data = array(); /** * Array of localized data. * - * @var array|null + * @var array */ - public ?array $localize_data = array(); + public $localize_data = array(); /** * Array of checked transients used by Redux. * - * @var mixed|null + * @var array */ public $transients_check = array(); @@ -434,7 +434,7 @@ public static function init() { * * @var bool */ - public bool $never_save_to_db; + public $never_save_to_db; /** * Deprecated shim for v3 templates. @@ -443,7 +443,7 @@ public static function init() { * * @deprecated 4.0.0 */ - public array $hidden_perm_sections = array(); + public $hidden_perm_sections = array(); /** * Deprecated shim for v3 as plugin check. @@ -452,7 +452,7 @@ public static function init() { * * @deprecated 4.0.0 */ - public static bool $_as_plugin = false; // phpcs:ignore PSR2.Classes.PropertyDeclaration + public static $_as_plugin = false; // phpcs:ignore PSR2.Classes.PropertyDeclaration /** * Deprecated shim for v3 as plugin check. @@ -461,7 +461,7 @@ public static function init() { * * @deprecated 4.0.0 */ - public static bool $_is_plugin = false; // phpcs:ignore PSR2.Classes.PropertyDeclaration + public static $_is_plugin = false; // phpcs:ignore PSR2.Classes.PropertyDeclaration /** * Cloning is forbidden. diff --git a/redux-core/inc/fields/slider/class-redux-slider.php b/redux-core/inc/fields/slider/class-redux-slider.php index 2a811bc9b..1a95e939e 100644 --- a/redux-core/inc/fields/slider/class-redux-slider.php +++ b/redux-core/inc/fields/slider/class-redux-slider.php @@ -23,35 +23,35 @@ class Redux_Slider extends Redux_Field { * * @var int */ - private $display_none = 0; + private int $display_none = 0; /** * Label value readout. * * @var int */ - private $display_label = 1; + private int $display_label = 1; /** * Text value readout. * * @var int */ - private $display_text = 2; + private int $display_text = 2; /** * Select box value readout. * * @var int */ - private $display_select = 3; + private int $display_select = 3; /** * Select2 options. * * @var string */ - private $select2_data = ''; + private string $select2_data = ''; /** * Set field and value defaults. @@ -203,14 +203,18 @@ private function clean() { if ( 2 === $this->field['handles'] ) { if ( ! is_array( $this->value ) ) { + $this->value = array(); + $this->value[1] = 0; $this->value[2] = 1; } + $this->value = $this->clean_default_array( $this->value ); } else { if ( is_array( $this->value ) ) { $this->value = 0; } + $this->value = $this->clean_default( $this->value ); } @@ -424,6 +428,75 @@ class="redux-slider-value-two-' . esc_attr( $field_id ) . ' ' . esc_attr( $this- } } + /** + * CSS/compiler output. + * + * @param string|null|array $style CSS styles. + */ + public function output( $style = '' ) { + if ( ! empty( $this->value ) ) { + if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) { + $css = $this->parse_css( $this->value, $this->field['output'] ); + $this->parent->outputCSS .= esc_attr( $css ); + } + + if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) { + $css = $this->parse_css( $this->value, $this->field['compiler'] ); + $this->parent->compilerCSS .= esc_attr( $css ); + } + } + } + + /** + * Compile CSS data for output. + * + * @param mixed $value Value. + * @param mixed $output . + * + * @return string + */ + private function parse_css( $value, $output ): string { + // No notices. + $css = ''; + + $unit = $this->field['output_unit'] ?? 'px'; + + // Must be an array. + if ( is_array( $output ) ) { + if ( is_array( $value ) ) { + foreach ( $output as $idx => $arr ) { + + if ( is_array( $arr ) ) { + foreach ( $arr as $selector => $mode ) { + if ( '' !== $mode && '' !== $selector ) { + $css .= $selector . '{' . $mode . ':' . $value[ $idx ] . $unit . ';}'; + } + } + } + } + } else { + foreach ( $output as $selector => $mode ) { + if ( '' !== $mode && '' !== $selector ) { + $css .= $selector . '{' . $mode . ':' . $value . $unit . ';}'; + } + } + } + } + + return $css; + } + + /** + * Generate CSS style (unused, but needed). + * + * @param string $data Field data. + * + * @return string + */ + public function css_style( $data ): string { + return ''; + } + /** * Enable output_variables to be generated. * diff --git a/sample/sections/slider-spinner/slider.php b/sample/sections/slider-spinner/slider.php index bc7276328..c3523d39d 100644 --- a/sample/sections/slider-spinner/slider.php +++ b/sample/sections/slider-spinner/slider.php @@ -32,12 +32,13 @@ 'type' => 'slider', 'title' => esc_html__( 'Slider Example 2 with Steps (5)', 'your-textdomain-here' ), 'subtitle' => esc_html__( 'This example displays the value in a text box', 'your-textdomain-here' ), - 'desc' => esc_html__( 'Slider description. Min: 0, max: 300, step: 5, default value: 75', 'your-textdomain-here' ), - 'default' => 75, + 'desc' => esc_html__( 'Slider description. Min: 0, max: 800, step: 5, default value: 75', 'your-textdomain-here' ), + 'default' => 750, 'min' => 0, 'step' => 5, - 'max' => 300, + 'max' => 800, 'display_value' => 'text', + 'output' => array( '.site-content' => 'max-width' ), ), array( 'id' => 'opt-slider-select', @@ -54,6 +55,10 @@ 'max' => '500', 'display_value' => 'select', 'handles' => 2, + 'output' => array( + 1 => array( '.site-footer' => 'max-width' ), + 2 => array( '.site-footer' => 'min-width' ), + ), ), array( 'id' => 'opt-slider-float',