@@ -59,8 +59,8 @@ discard block |
||
| 59 | 59 | |
| 60 | 60 | foreach ( $this->field['options'] as $k => $v ) { |
| 61 | 61 | |
| 62 | - if ( empty( $this->value[ $k ] ) ) { |
|
| 63 | - $this->value[ $k ] = ''; |
|
| 62 | + if ( empty( $this->value[$k] ) ) { |
|
| 63 | + $this->value[$k] = ''; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | echo '<li>'; |
@@ -77,8 +77,8 @@ discard block |
||
| 77 | 77 | $id = $ident_1 . '_' . $ident_2; |
| 78 | 78 | |
| 79 | 79 | echo '<label for="' . esc_attr( $id ) . '">'; |
| 80 | - echo '<input type="hidden" class="checkbox-check" data-val="1" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] . '[' . $k . ']' ) . '" value="' . esc_attr( $this->value[ $k ] ) . '"/>'; |
|
| 81 | - echo '<input type="checkbox" class="checkbox ' . esc_attr( $this->field['class'] ) . '" id="' . esc_attr( $id ) . '" value="1" ' . checked( $this->value[ $k ], '1', false ) . '/>'; |
|
| 80 | + echo '<input type="hidden" class="checkbox-check" data-val="1" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] . '[' . $k . ']' ) . '" value="' . esc_attr( $this->value[$k] ) . '"/>'; |
|
| 81 | + echo '<input type="checkbox" class="checkbox ' . esc_attr( $this->field['class'] ) . '" id="' . esc_attr( $id ) . '" value="1" ' . checked( $this->value[$k], '1', false ) . '/>'; |
|
| 82 | 82 | echo ' ' . esc_attr( $v ) . '</label>'; |
| 83 | 83 | echo '</li>'; |
| 84 | 84 | } |
@@ -12,135 +12,135 @@ |
||
| 12 | 12 | // Don't duplicate me! |
| 13 | 13 | if ( ! class_exists( 'Redux_Checkbox', false ) ) { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Main Redux_checkbox class |
|
| 17 | - * |
|
| 18 | - * @since 1.0.0 |
|
| 19 | - */ |
|
| 20 | - class Redux_Checkbox extends Redux_Field { |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Field Render Function. |
|
| 24 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 25 | - * |
|
| 26 | - * @since 1.0.0 |
|
| 27 | - * @access public |
|
| 28 | - * @return void |
|
| 29 | - */ |
|
| 30 | - public function render() { |
|
| 31 | - if ( ! empty( $this->field['data'] ) && empty( $this->field['options'] ) ) { |
|
| 32 | - if ( empty( $this->field['args'] ) ) { |
|
| 33 | - $this->field['args'] = array(); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - $this->field['options'] = $this->parent->wordpress_data->get( $this->field['data'], $this->field['args'], $this->parent->args['opt_name'], $this->value ); |
|
| 37 | - if ( empty( $this->field['options'] ) ) { |
|
| 38 | - return; |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - $this->field['data_class'] = ( isset( $this->field['multi_layout'] ) ) ? 'data-' . $this->field['multi_layout'] : 'data-full'; |
|
| 43 | - |
|
| 44 | - if ( ! empty( $this->field['options'] ) && ( is_array( $this->field['options'] ) || is_array( $this->field['default'] ) ) ) { |
|
| 45 | - |
|
| 46 | - echo '<ul class="' . esc_attr( $this->field['data_class'] ) . '">'; |
|
| 47 | - |
|
| 48 | - if ( ! isset( $this->value ) ) { |
|
| 49 | - $this->value = array(); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - if ( ! is_array( $this->value ) ) { |
|
| 53 | - $this->value = array(); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - if ( empty( $this->field['options'] ) && isset( $this->field['default'] ) && is_array( $this->field['default'] ) ) { |
|
| 57 | - $this->field['options'] = $this->field['default']; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - foreach ( $this->field['options'] as $k => $v ) { |
|
| 61 | - |
|
| 62 | - if ( empty( $this->value[ $k ] ) ) { |
|
| 63 | - $this->value[ $k ] = ''; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - echo '<li>'; |
|
| 67 | - |
|
| 68 | - $ident_1 = strtr( |
|
| 69 | - $this->parent->args['opt_name'] . '[' . $this->field['id'] . '][' . $k . ']', |
|
| 70 | - array( |
|
| 71 | - '[' => '_', |
|
| 72 | - ']' => '', |
|
| 73 | - ) |
|
| 74 | - ); |
|
| 75 | - |
|
| 76 | - $ident_2 = array_search( $k, array_keys( $this->field['options'] ), true ); |
|
| 77 | - $id = $ident_1 . '_' . $ident_2; |
|
| 78 | - |
|
| 79 | - echo '<label for="' . esc_attr( $id ) . '">'; |
|
| 80 | - echo '<input type="hidden" class="checkbox-check" data-val="1" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] . '[' . $k . ']' ) . '" value="' . esc_attr( $this->value[ $k ] ) . '"/>'; |
|
| 81 | - echo '<input type="checkbox" class="checkbox ' . esc_attr( $this->field['class'] ) . '" id="' . esc_attr( $id ) . '" value="1" ' . checked( $this->value[ $k ], '1', false ) . '/>'; |
|
| 82 | - echo ' ' . esc_attr( $v ) . '</label>'; |
|
| 83 | - echo '</li>'; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - echo '</ul>'; |
|
| 87 | - } elseif ( empty( $this->field['data'] ) ) { |
|
| 88 | - echo '<ul class="data-full">'; |
|
| 89 | - echo '<li>'; |
|
| 90 | - |
|
| 91 | - if ( ! empty( $this->field['label'] ) ) { |
|
| 92 | - echo '<label>'; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $ident_1 = strtr( |
|
| 96 | - $this->parent->args['opt_name'] . '[' . $this->field['id'] . ']', |
|
| 97 | - array( |
|
| 98 | - '[' => '_', |
|
| 99 | - ']' => '', |
|
| 100 | - ) |
|
| 101 | - ); |
|
| 102 | - |
|
| 103 | - // Got the "Checked" status as "0" or "1" then insert it as the "value" option. |
|
| 104 | - echo '<input type="hidden" class="checkbox-check" data-val="1" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '" value="' . esc_attr( $this->value ) . '"/>'; |
|
| 105 | - echo '<input type="checkbox" id="' . esc_attr( $ident_1 ) . '" value="1" class="checkbox ' . esc_attr( $this->field['class'] ) . '" ' . checked( $this->value, '1', false ) . '/>'; |
|
| 106 | - |
|
| 107 | - if ( ! empty( $this->field['label'] ) ) { |
|
| 108 | - echo ' ' . esc_html( $this->field['label'] ); |
|
| 109 | - echo '</label>'; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - echo '</li>'; |
|
| 113 | - echo '</ul>'; |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Enqueue Function. |
|
| 119 | - * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 120 | - * |
|
| 121 | - * @since 1.0.0 |
|
| 122 | - * @access public |
|
| 123 | - * @return void |
|
| 124 | - */ |
|
| 125 | - public function enqueue() { |
|
| 126 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 127 | - wp_enqueue_style( |
|
| 128 | - 'redux-field-checkbox', |
|
| 129 | - Redux_Core::$url . 'inc/fields/checkbox/redux-checkbox.css', |
|
| 130 | - array(), |
|
| 131 | - $this->timestamp |
|
| 132 | - ); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - wp_enqueue_script( |
|
| 136 | - 'redux-field-checkbox', |
|
| 137 | - Redux_Core::$url . 'inc/fields/checkbox/redux-checkbox' . Redux_Functions::is_min() . '.js', |
|
| 138 | - array( 'jquery', 'redux-js' ), |
|
| 139 | - $this->timestamp, |
|
| 140 | - true |
|
| 141 | - ); |
|
| 142 | - } |
|
| 143 | - } |
|
| 15 | + /** |
|
| 16 | + * Main Redux_checkbox class |
|
| 17 | + * |
|
| 18 | + * @since 1.0.0 |
|
| 19 | + */ |
|
| 20 | + class Redux_Checkbox extends Redux_Field { |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Field Render Function. |
|
| 24 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 25 | + * |
|
| 26 | + * @since 1.0.0 |
|
| 27 | + * @access public |
|
| 28 | + * @return void |
|
| 29 | + */ |
|
| 30 | + public function render() { |
|
| 31 | + if ( ! empty( $this->field['data'] ) && empty( $this->field['options'] ) ) { |
|
| 32 | + if ( empty( $this->field['args'] ) ) { |
|
| 33 | + $this->field['args'] = array(); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + $this->field['options'] = $this->parent->wordpress_data->get( $this->field['data'], $this->field['args'], $this->parent->args['opt_name'], $this->value ); |
|
| 37 | + if ( empty( $this->field['options'] ) ) { |
|
| 38 | + return; |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + $this->field['data_class'] = ( isset( $this->field['multi_layout'] ) ) ? 'data-' . $this->field['multi_layout'] : 'data-full'; |
|
| 43 | + |
|
| 44 | + if ( ! empty( $this->field['options'] ) && ( is_array( $this->field['options'] ) || is_array( $this->field['default'] ) ) ) { |
|
| 45 | + |
|
| 46 | + echo '<ul class="' . esc_attr( $this->field['data_class'] ) . '">'; |
|
| 47 | + |
|
| 48 | + if ( ! isset( $this->value ) ) { |
|
| 49 | + $this->value = array(); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + if ( ! is_array( $this->value ) ) { |
|
| 53 | + $this->value = array(); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + if ( empty( $this->field['options'] ) && isset( $this->field['default'] ) && is_array( $this->field['default'] ) ) { |
|
| 57 | + $this->field['options'] = $this->field['default']; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + foreach ( $this->field['options'] as $k => $v ) { |
|
| 61 | + |
|
| 62 | + if ( empty( $this->value[ $k ] ) ) { |
|
| 63 | + $this->value[ $k ] = ''; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + echo '<li>'; |
|
| 67 | + |
|
| 68 | + $ident_1 = strtr( |
|
| 69 | + $this->parent->args['opt_name'] . '[' . $this->field['id'] . '][' . $k . ']', |
|
| 70 | + array( |
|
| 71 | + '[' => '_', |
|
| 72 | + ']' => '', |
|
| 73 | + ) |
|
| 74 | + ); |
|
| 75 | + |
|
| 76 | + $ident_2 = array_search( $k, array_keys( $this->field['options'] ), true ); |
|
| 77 | + $id = $ident_1 . '_' . $ident_2; |
|
| 78 | + |
|
| 79 | + echo '<label for="' . esc_attr( $id ) . '">'; |
|
| 80 | + echo '<input type="hidden" class="checkbox-check" data-val="1" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] . '[' . $k . ']' ) . '" value="' . esc_attr( $this->value[ $k ] ) . '"/>'; |
|
| 81 | + echo '<input type="checkbox" class="checkbox ' . esc_attr( $this->field['class'] ) . '" id="' . esc_attr( $id ) . '" value="1" ' . checked( $this->value[ $k ], '1', false ) . '/>'; |
|
| 82 | + echo ' ' . esc_attr( $v ) . '</label>'; |
|
| 83 | + echo '</li>'; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + echo '</ul>'; |
|
| 87 | + } elseif ( empty( $this->field['data'] ) ) { |
|
| 88 | + echo '<ul class="data-full">'; |
|
| 89 | + echo '<li>'; |
|
| 90 | + |
|
| 91 | + if ( ! empty( $this->field['label'] ) ) { |
|
| 92 | + echo '<label>'; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $ident_1 = strtr( |
|
| 96 | + $this->parent->args['opt_name'] . '[' . $this->field['id'] . ']', |
|
| 97 | + array( |
|
| 98 | + '[' => '_', |
|
| 99 | + ']' => '', |
|
| 100 | + ) |
|
| 101 | + ); |
|
| 102 | + |
|
| 103 | + // Got the "Checked" status as "0" or "1" then insert it as the "value" option. |
|
| 104 | + echo '<input type="hidden" class="checkbox-check" data-val="1" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '" value="' . esc_attr( $this->value ) . '"/>'; |
|
| 105 | + echo '<input type="checkbox" id="' . esc_attr( $ident_1 ) . '" value="1" class="checkbox ' . esc_attr( $this->field['class'] ) . '" ' . checked( $this->value, '1', false ) . '/>'; |
|
| 106 | + |
|
| 107 | + if ( ! empty( $this->field['label'] ) ) { |
|
| 108 | + echo ' ' . esc_html( $this->field['label'] ); |
|
| 109 | + echo '</label>'; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + echo '</li>'; |
|
| 113 | + echo '</ul>'; |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Enqueue Function. |
|
| 119 | + * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 120 | + * |
|
| 121 | + * @since 1.0.0 |
|
| 122 | + * @access public |
|
| 123 | + * @return void |
|
| 124 | + */ |
|
| 125 | + public function enqueue() { |
|
| 126 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 127 | + wp_enqueue_style( |
|
| 128 | + 'redux-field-checkbox', |
|
| 129 | + Redux_Core::$url . 'inc/fields/checkbox/redux-checkbox.css', |
|
| 130 | + array(), |
|
| 131 | + $this->timestamp |
|
| 132 | + ); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + wp_enqueue_script( |
|
| 136 | + 'redux-field-checkbox', |
|
| 137 | + Redux_Core::$url . 'inc/fields/checkbox/redux-checkbox' . Redux_Functions::is_min() . '.js', |
|
| 138 | + array( 'jquery', 'redux-js' ), |
|
| 139 | + $this->timestamp, |
|
| 140 | + true |
|
| 141 | + ); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | class_alias( 'Redux_Checkbox', 'ReduxFramework_Checkbox' ); |
@@ -33,9 +33,9 @@ discard block |
||
| 33 | 33 | $slug = Redux_Core::strtolower( $name ); |
| 34 | 34 | $slug = str_replace( ' ', '-', $slug ); |
| 35 | 35 | |
| 36 | - $new_arr[ $slug ] = $name; |
|
| 36 | + $new_arr[$slug] = $name; |
|
| 37 | 37 | } else { |
| 38 | - $new_arr[ $id ] = $name; |
|
| 38 | + $new_arr[$id] = $name; |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | } |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | if ( isset( $this->field['data'] ) ) { |
| 81 | - $this->field['options'] = $this->parent->options_defaults[ $this->field['id'] ]; |
|
| 81 | + $this->field['options'] = $this->parent->options_defaults[$this->field['id']]; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | $this->field['repeater_id'] = $this->field['repeater_id'] ?? ''; |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | if ( ! empty( $sortlists ) ) { |
| 106 | 106 | foreach ( $sortlists as $section => $arr ) { |
| 107 | 107 | $arr = $this->replace_id_with_slug( $arr ); |
| 108 | - $sortlists[ $section ] = $arr; |
|
| 109 | - $this->value[ $section ] = $arr; |
|
| 108 | + $sortlists[$section] = $arr; |
|
| 109 | + $this->value[$section] = $arr; |
|
| 110 | 110 | } |
| 111 | 111 | } |
| 112 | 112 | |
@@ -122,9 +122,9 @@ discard block |
||
| 122 | 122 | if ( ! empty( $temp2 ) ) { |
| 123 | 123 | if ( ! array_key_exists( $k, $temp2 ) ) { |
| 124 | 124 | if ( isset( $sortlists['Disabled'] ) ) { |
| 125 | - $sortlists['Disabled'][ $k ] = $v; |
|
| 125 | + $sortlists['Disabled'][$k] = $v; |
|
| 126 | 126 | } else { |
| 127 | - $sortlists['disabled'][ $k ] = $v; |
|
| 127 | + $sortlists['disabled'][$k] = $v; |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | } |
@@ -138,18 +138,18 @@ discard block |
||
| 138 | 138 | // k = id. |
| 139 | 139 | // v = name. |
| 140 | 140 | if ( ! array_key_exists( $k, $temp ) ) { |
| 141 | - unset( $sortlist[ $k ] ); |
|
| 141 | + unset( $sortlist[$k] ); |
|
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | - $sortlists[ $key ] = $sortlist; |
|
| 144 | + $sortlists[$key] = $sortlist; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // assuming all synced, now get the correct naming for each block. |
| 148 | 148 | foreach ( $sortlists as $key => $sortlist ) { |
| 149 | 149 | foreach ( $sortlist as $k => $v ) { |
| 150 | - $sortlist[ $k ] = $temp[ $k ]; |
|
| 150 | + $sortlist[$k] = $temp[$k]; |
|
| 151 | 151 | } |
| 152 | - $sortlists[ $key ] = $sortlist; |
|
| 152 | + $sortlists[$key] = $sortlist; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | if ( $sortlists ) { |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | foreach ( $sortlists as $group => $sortlist ) { |
| 159 | 159 | $filled = ''; |
| 160 | 160 | |
| 161 | - if ( isset( $this->field['limits'][ $group ] ) && count( $sortlist ) >= $this->field['limits'][ $group ] ) { |
|
| 161 | + if ( isset( $this->field['limits'][$group] ) && count( $sortlist ) >= $this->field['limits'][$group] ) { |
|
| 162 | 162 | $filled = ' filled'; |
| 163 | 163 | } |
| 164 | 164 | |
@@ -11,234 +11,234 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Sorter', false ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Class Redux_Sorter |
|
| 16 | - */ |
|
| 17 | - class Redux_Sorter extends Redux_Field { |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Replaced ID with slag. |
|
| 21 | - * |
|
| 22 | - * @param array $arr . |
|
| 23 | - * |
|
| 24 | - * @return array |
|
| 25 | - */ |
|
| 26 | - private function replace_id_with_slug( array $arr ): array { |
|
| 27 | - $new_arr = array(); |
|
| 28 | - |
|
| 29 | - if ( ! empty( $arr ) ) { |
|
| 30 | - foreach ( $arr as $id => $name ) { |
|
| 31 | - |
|
| 32 | - if ( is_numeric( $id ) ) { |
|
| 33 | - $slug = Redux_Core::strtolower( $name ); |
|
| 34 | - $slug = str_replace( ' ', '-', $slug ); |
|
| 35 | - |
|
| 36 | - $new_arr[ $slug ] = $name; |
|
| 37 | - } else { |
|
| 38 | - $new_arr[ $id ] = $name; |
|
| 39 | - } |
|
| 40 | - } |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - return $new_arr; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Check for empty value. |
|
| 48 | - * |
|
| 49 | - * @param mixed $val Value to check. |
|
| 50 | - * |
|
| 51 | - * @return bool |
|
| 52 | - */ |
|
| 53 | - private function is_value_empty( $val ): bool { |
|
| 54 | - if ( ! empty( $val ) ) { |
|
| 55 | - foreach ( $val as $arr ) { |
|
| 56 | - if ( ! empty( $arr ) ) { |
|
| 57 | - return false; |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return true; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Field Render Function. |
|
| 67 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 68 | - * |
|
| 69 | - * @since 1.0.0 |
|
| 70 | - */ |
|
| 71 | - public function render() { |
|
| 72 | - if ( ! is_array( $this->value ) && isset( $this->field['options'] ) ) { |
|
| 73 | - $this->value = $this->field['options']; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if ( ! isset( $this->field['args'] ) ) { |
|
| 77 | - $this->field['args'] = array(); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - if ( isset( $this->field['data'] ) ) { |
|
| 81 | - $this->field['options'] = $this->parent->options_defaults[ $this->field['id'] ]; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $this->field['repeater_id'] = $this->field['repeater_id'] ?? ''; |
|
| 85 | - |
|
| 86 | - // Make sure to get list of all the default blocks first. |
|
| 87 | - $all_blocks = ! empty( $this->field['options'] ) ? $this->field['options'] : array(); |
|
| 88 | - $temp = array(); // holds default blocks. |
|
| 89 | - $temp2 = array(); // holds saved blocks. |
|
| 90 | - |
|
| 91 | - foreach ( $all_blocks as $blocks ) { |
|
| 92 | - $temp = array_merge( $temp, $blocks ); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $temp = $this->replace_id_with_slug( $temp ); |
|
| 96 | - |
|
| 97 | - if ( $this->is_value_empty( $this->value ) ) { |
|
| 98 | - if ( ! empty( $this->field['options'] ) ) { |
|
| 99 | - $this->value = $this->field['options']; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - $sortlists = $this->value; |
|
| 104 | - |
|
| 105 | - if ( ! empty( $sortlists ) ) { |
|
| 106 | - foreach ( $sortlists as $section => $arr ) { |
|
| 107 | - $arr = $this->replace_id_with_slug( $arr ); |
|
| 108 | - $sortlists[ $section ] = $arr; |
|
| 109 | - $this->value[ $section ] = $arr; |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - if ( is_array( $sortlists ) ) { |
|
| 114 | - foreach ( $sortlists as $sortlist ) { |
|
| 115 | - $temp2 = array_merge( $temp2, $sortlist ); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // now let's compare if we have anything missing. |
|
| 119 | - foreach ( $temp as $k => $v ) { |
|
| 120 | - // k = id/slug. |
|
| 121 | - // v = name. |
|
| 122 | - if ( ! empty( $temp2 ) ) { |
|
| 123 | - if ( ! array_key_exists( $k, $temp2 ) ) { |
|
| 124 | - if ( isset( $sortlists['Disabled'] ) ) { |
|
| 125 | - $sortlists['Disabled'][ $k ] = $v; |
|
| 126 | - } else { |
|
| 127 | - $sortlists['disabled'][ $k ] = $v; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - // now check if saved blocks has blocks not registered under default blocks. |
|
| 134 | - foreach ( $sortlists as $key => $sortlist ) { |
|
| 135 | - // key = enabled, disabled, backup. |
|
| 136 | - // sortlist = id => name. |
|
| 137 | - foreach ( $sortlist as $k => $v ) { |
|
| 138 | - // k = id. |
|
| 139 | - // v = name. |
|
| 140 | - if ( ! array_key_exists( $k, $temp ) ) { |
|
| 141 | - unset( $sortlist[ $k ] ); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - $sortlists[ $key ] = $sortlist; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - // assuming all synced, now get the correct naming for each block. |
|
| 148 | - foreach ( $sortlists as $key => $sortlist ) { |
|
| 149 | - foreach ( $sortlist as $k => $v ) { |
|
| 150 | - $sortlist[ $k ] = $temp[ $k ]; |
|
| 151 | - } |
|
| 152 | - $sortlists[ $key ] = $sortlist; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - if ( $sortlists ) { |
|
| 156 | - echo '<fieldset id="' . esc_attr( $this->field['id'] ) . '" class="redux-sorter-container redux-sorter ' . esc_attr( $this->field['class'] ) . '">'; |
|
| 157 | - |
|
| 158 | - foreach ( $sortlists as $group => $sortlist ) { |
|
| 159 | - $filled = ''; |
|
| 160 | - |
|
| 161 | - if ( isset( $this->field['limits'][ $group ] ) && count( $sortlist ) >= $this->field['limits'][ $group ] ) { |
|
| 162 | - $filled = ' filled'; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - echo '<ul id="' . esc_attr( $this->field['id'] . '_' . $group ) . '" class="sortlist_' . esc_attr( $this->field['id'] . $filled ) . '" data-id="' . esc_attr( $this->field['id'] ) . '" data-repeater-id="' . esc_attr( $this->field['repeater_id'] ) . '" data-suffix="' . esc_attr( $this->field['name_suffix'] ) . '" data-group-id="' . esc_attr( $group ) . '">'; |
|
| 166 | - echo '<h3>' . esc_html( $group ) . '</h3>'; |
|
| 167 | - |
|
| 168 | - if ( ! isset( $sortlist['placebo'] ) ) { |
|
| 169 | - $sortlist['placebo'] = 'placebo'; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - foreach ( $sortlist as $key => $list ) { |
|
| 173 | - echo '<input |
|
| 14 | + /** |
|
| 15 | + * Class Redux_Sorter |
|
| 16 | + */ |
|
| 17 | + class Redux_Sorter extends Redux_Field { |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Replaced ID with slag. |
|
| 21 | + * |
|
| 22 | + * @param array $arr . |
|
| 23 | + * |
|
| 24 | + * @return array |
|
| 25 | + */ |
|
| 26 | + private function replace_id_with_slug( array $arr ): array { |
|
| 27 | + $new_arr = array(); |
|
| 28 | + |
|
| 29 | + if ( ! empty( $arr ) ) { |
|
| 30 | + foreach ( $arr as $id => $name ) { |
|
| 31 | + |
|
| 32 | + if ( is_numeric( $id ) ) { |
|
| 33 | + $slug = Redux_Core::strtolower( $name ); |
|
| 34 | + $slug = str_replace( ' ', '-', $slug ); |
|
| 35 | + |
|
| 36 | + $new_arr[ $slug ] = $name; |
|
| 37 | + } else { |
|
| 38 | + $new_arr[ $id ] = $name; |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + return $new_arr; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Check for empty value. |
|
| 48 | + * |
|
| 49 | + * @param mixed $val Value to check. |
|
| 50 | + * |
|
| 51 | + * @return bool |
|
| 52 | + */ |
|
| 53 | + private function is_value_empty( $val ): bool { |
|
| 54 | + if ( ! empty( $val ) ) { |
|
| 55 | + foreach ( $val as $arr ) { |
|
| 56 | + if ( ! empty( $arr ) ) { |
|
| 57 | + return false; |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return true; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Field Render Function. |
|
| 67 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 68 | + * |
|
| 69 | + * @since 1.0.0 |
|
| 70 | + */ |
|
| 71 | + public function render() { |
|
| 72 | + if ( ! is_array( $this->value ) && isset( $this->field['options'] ) ) { |
|
| 73 | + $this->value = $this->field['options']; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if ( ! isset( $this->field['args'] ) ) { |
|
| 77 | + $this->field['args'] = array(); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + if ( isset( $this->field['data'] ) ) { |
|
| 81 | + $this->field['options'] = $this->parent->options_defaults[ $this->field['id'] ]; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $this->field['repeater_id'] = $this->field['repeater_id'] ?? ''; |
|
| 85 | + |
|
| 86 | + // Make sure to get list of all the default blocks first. |
|
| 87 | + $all_blocks = ! empty( $this->field['options'] ) ? $this->field['options'] : array(); |
|
| 88 | + $temp = array(); // holds default blocks. |
|
| 89 | + $temp2 = array(); // holds saved blocks. |
|
| 90 | + |
|
| 91 | + foreach ( $all_blocks as $blocks ) { |
|
| 92 | + $temp = array_merge( $temp, $blocks ); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $temp = $this->replace_id_with_slug( $temp ); |
|
| 96 | + |
|
| 97 | + if ( $this->is_value_empty( $this->value ) ) { |
|
| 98 | + if ( ! empty( $this->field['options'] ) ) { |
|
| 99 | + $this->value = $this->field['options']; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + $sortlists = $this->value; |
|
| 104 | + |
|
| 105 | + if ( ! empty( $sortlists ) ) { |
|
| 106 | + foreach ( $sortlists as $section => $arr ) { |
|
| 107 | + $arr = $this->replace_id_with_slug( $arr ); |
|
| 108 | + $sortlists[ $section ] = $arr; |
|
| 109 | + $this->value[ $section ] = $arr; |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + if ( is_array( $sortlists ) ) { |
|
| 114 | + foreach ( $sortlists as $sortlist ) { |
|
| 115 | + $temp2 = array_merge( $temp2, $sortlist ); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // now let's compare if we have anything missing. |
|
| 119 | + foreach ( $temp as $k => $v ) { |
|
| 120 | + // k = id/slug. |
|
| 121 | + // v = name. |
|
| 122 | + if ( ! empty( $temp2 ) ) { |
|
| 123 | + if ( ! array_key_exists( $k, $temp2 ) ) { |
|
| 124 | + if ( isset( $sortlists['Disabled'] ) ) { |
|
| 125 | + $sortlists['Disabled'][ $k ] = $v; |
|
| 126 | + } else { |
|
| 127 | + $sortlists['disabled'][ $k ] = $v; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + // now check if saved blocks has blocks not registered under default blocks. |
|
| 134 | + foreach ( $sortlists as $key => $sortlist ) { |
|
| 135 | + // key = enabled, disabled, backup. |
|
| 136 | + // sortlist = id => name. |
|
| 137 | + foreach ( $sortlist as $k => $v ) { |
|
| 138 | + // k = id. |
|
| 139 | + // v = name. |
|
| 140 | + if ( ! array_key_exists( $k, $temp ) ) { |
|
| 141 | + unset( $sortlist[ $k ] ); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + $sortlists[ $key ] = $sortlist; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + // assuming all synced, now get the correct naming for each block. |
|
| 148 | + foreach ( $sortlists as $key => $sortlist ) { |
|
| 149 | + foreach ( $sortlist as $k => $v ) { |
|
| 150 | + $sortlist[ $k ] = $temp[ $k ]; |
|
| 151 | + } |
|
| 152 | + $sortlists[ $key ] = $sortlist; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + if ( $sortlists ) { |
|
| 156 | + echo '<fieldset id="' . esc_attr( $this->field['id'] ) . '" class="redux-sorter-container redux-sorter ' . esc_attr( $this->field['class'] ) . '">'; |
|
| 157 | + |
|
| 158 | + foreach ( $sortlists as $group => $sortlist ) { |
|
| 159 | + $filled = ''; |
|
| 160 | + |
|
| 161 | + if ( isset( $this->field['limits'][ $group ] ) && count( $sortlist ) >= $this->field['limits'][ $group ] ) { |
|
| 162 | + $filled = ' filled'; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + echo '<ul id="' . esc_attr( $this->field['id'] . '_' . $group ) . '" class="sortlist_' . esc_attr( $this->field['id'] . $filled ) . '" data-id="' . esc_attr( $this->field['id'] ) . '" data-repeater-id="' . esc_attr( $this->field['repeater_id'] ) . '" data-suffix="' . esc_attr( $this->field['name_suffix'] ) . '" data-group-id="' . esc_attr( $group ) . '">'; |
|
| 166 | + echo '<h3>' . esc_html( $group ) . '</h3>'; |
|
| 167 | + |
|
| 168 | + if ( ! isset( $sortlist['placebo'] ) ) { |
|
| 169 | + $sortlist['placebo'] = 'placebo'; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + foreach ( $sortlist as $key => $list ) { |
|
| 173 | + echo '<input |
|
| 174 | 174 | class="sorter-placebo" |
| 175 | 175 | type="hidden" |
| 176 | 176 | name="' . esc_attr( $this->field['name'] ) . esc_attr( $this->field['name_suffix'] ) . '[' . esc_html( $group ) . '][placebo]" |
| 177 | 177 | value="placebo">'; |
| 178 | 178 | |
| 179 | - if ( 'placebo' !== $key ) { |
|
| 180 | - echo '<li id="sortee-' . esc_attr( $key ) . '" class="sortee" data-id="' . esc_attr( $key ) . '">'; |
|
| 181 | - echo '<input class="position ' . esc_attr( $this->field['class'] ) . '" type="hidden" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] . '[' . $group . '][' . $key . ']' ) . '" value="' . esc_attr( $list ) . '">'; |
|
| 182 | - echo esc_html( $list ); |
|
| 183 | - echo '</li>'; |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - echo '</ul>'; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - echo '</fieldset>'; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Enqueue scripts and styles. |
|
| 197 | - */ |
|
| 198 | - public function enqueue() { |
|
| 199 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 200 | - wp_enqueue_style( |
|
| 201 | - 'redux-field-sorter', |
|
| 202 | - Redux_Core::$url . 'inc/fields/sorter/redux-sorter.css', |
|
| 203 | - array(), |
|
| 204 | - $this->timestamp |
|
| 205 | - ); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - wp_enqueue_script( |
|
| 209 | - 'redux-field-sorter', |
|
| 210 | - Redux_Core::$url . 'inc/fields/sorter/redux-sorter' . Redux_Functions::is_min() . '.js', |
|
| 211 | - array( 'jquery', 'redux-js', 'jquery-ui-sortable' ), |
|
| 212 | - $this->timestamp, |
|
| 213 | - true |
|
| 214 | - ); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Functions to pass data from the PHP to the JS at render time. |
|
| 219 | - * |
|
| 220 | - * @param array $field Field values. |
|
| 221 | - * @param string $value Option values. |
|
| 222 | - * |
|
| 223 | - * @return array Params to be saved as a javascript object accessible to the UI. |
|
| 224 | - * @since Redux_Framework 3.1.5 |
|
| 225 | - */ |
|
| 226 | - public function localize( array $field, string $value = '' ): array { |
|
| 227 | - $params = array(); |
|
| 228 | - |
|
| 229 | - if ( ! empty( $field['limits'] ) ) { |
|
| 230 | - $params['limits'] = $field['limits']; |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - if ( empty( $value ) ) { |
|
| 234 | - $value = $this->value; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - $params['val'] = $value; |
|
| 238 | - |
|
| 239 | - return $params; |
|
| 240 | - } |
|
| 241 | - } |
|
| 179 | + if ( 'placebo' !== $key ) { |
|
| 180 | + echo '<li id="sortee-' . esc_attr( $key ) . '" class="sortee" data-id="' . esc_attr( $key ) . '">'; |
|
| 181 | + echo '<input class="position ' . esc_attr( $this->field['class'] ) . '" type="hidden" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] . '[' . $group . '][' . $key . ']' ) . '" value="' . esc_attr( $list ) . '">'; |
|
| 182 | + echo esc_html( $list ); |
|
| 183 | + echo '</li>'; |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + echo '</ul>'; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + echo '</fieldset>'; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Enqueue scripts and styles. |
|
| 197 | + */ |
|
| 198 | + public function enqueue() { |
|
| 199 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 200 | + wp_enqueue_style( |
|
| 201 | + 'redux-field-sorter', |
|
| 202 | + Redux_Core::$url . 'inc/fields/sorter/redux-sorter.css', |
|
| 203 | + array(), |
|
| 204 | + $this->timestamp |
|
| 205 | + ); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + wp_enqueue_script( |
|
| 209 | + 'redux-field-sorter', |
|
| 210 | + Redux_Core::$url . 'inc/fields/sorter/redux-sorter' . Redux_Functions::is_min() . '.js', |
|
| 211 | + array( 'jquery', 'redux-js', 'jquery-ui-sortable' ), |
|
| 212 | + $this->timestamp, |
|
| 213 | + true |
|
| 214 | + ); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Functions to pass data from the PHP to the JS at render time. |
|
| 219 | + * |
|
| 220 | + * @param array $field Field values. |
|
| 221 | + * @param string $value Option values. |
|
| 222 | + * |
|
| 223 | + * @return array Params to be saved as a javascript object accessible to the UI. |
|
| 224 | + * @since Redux_Framework 3.1.5 |
|
| 225 | + */ |
|
| 226 | + public function localize( array $field, string $value = '' ): array { |
|
| 227 | + $params = array(); |
|
| 228 | + |
|
| 229 | + if ( ! empty( $field['limits'] ) ) { |
|
| 230 | + $params['limits'] = $field['limits']; |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + if ( empty( $value ) ) { |
|
| 234 | + $value = $this->value; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + $params['val'] = $value; |
|
| 238 | + |
|
| 239 | + return $params; |
|
| 240 | + } |
|
| 241 | + } |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | class_alias( 'Redux_Sorter', 'ReduxFramework_Sorter' ); |
@@ -108,10 +108,10 @@ discard block |
||
| 108 | 108 | echo 'data-id="' . esc_attr( $this->field['id'] ) . '"'; |
| 109 | 109 | echo 'id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $mode ) . '"'; |
| 110 | 110 | echo 'name="' . esc_attr( $this->field['name'] ) . esc_attr( $this->field['name_suffix'] ) . '[' . esc_attr( $mode ) . ']"'; |
| 111 | - echo 'value="' . esc_attr( $this->value[ $mode ] ) . '"'; |
|
| 111 | + echo 'value="' . esc_attr( $this->value[$mode] ) . '"'; |
|
| 112 | 112 | echo 'class="color-picker redux-color redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
| 113 | 113 | echo 'type="text"'; |
| 114 | - echo 'data-default-color="' . esc_attr( $this->field['default'][ $mode ] ) . '"'; |
|
| 114 | + echo 'data-default-color="' . esc_attr( $this->field['default'][$mode] ) . '"'; |
|
| 115 | 115 | |
| 116 | 116 | // Escaping done in function. |
| 117 | 117 | // phpcs:ignore WordPress.Security.EscapeOutput |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | if ( ! isset( $this->field['transparent'] ) || false !== $this->field['transparent'] ) { |
| 125 | 125 | $trans_checked = ''; |
| 126 | 126 | |
| 127 | - if ( 'transparent' === $this->value[ $mode ] ) { |
|
| 127 | + if ( 'transparent' === $this->value[$mode] ) { |
|
| 128 | 128 | $trans_checked = ' checked="checked"'; |
| 129 | 129 | } |
| 130 | 130 | |
@@ -12,218 +12,218 @@ |
||
| 12 | 12 | // Don't duplicate me! |
| 13 | 13 | if ( ! class_exists( 'Redux_Color_Gradient', false ) ) { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Main Redux_color_gradient class |
|
| 17 | - * |
|
| 18 | - * @since 1.0.0 |
|
| 19 | - */ |
|
| 20 | - class Redux_Color_Gradient extends Redux_Field { |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Filters enabled flag. |
|
| 24 | - * |
|
| 25 | - * @var bool |
|
| 26 | - */ |
|
| 27 | - private $filters_enabled = false; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Redux_Field constructor. |
|
| 31 | - * |
|
| 32 | - * @param array $field Field array. |
|
| 33 | - * @param string $value Field values. |
|
| 34 | - * @param null $redux ReduxFramework object pointer. |
|
| 35 | - * |
|
| 36 | - * @throws ReflectionException Reflection. |
|
| 37 | - */ |
|
| 38 | - public function __construct( $field = array(), $value = null, $redux = null ) { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod |
|
| 39 | - parent::__construct( $field, $value, $redux ); |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Set field and value defaults. |
|
| 44 | - */ |
|
| 45 | - public function set_defaults() { |
|
| 46 | - // No errors please. |
|
| 47 | - $defaults = array( |
|
| 48 | - 'from' => '', |
|
| 49 | - 'to' => '', |
|
| 50 | - 'gradient-type' => 'linear', |
|
| 51 | - 'gradient-angle' => 0, |
|
| 52 | - 'gradient-reach' => array( |
|
| 53 | - 'from' => 0, |
|
| 54 | - 'to' => 100, |
|
| 55 | - ), |
|
| 56 | - ); |
|
| 57 | - |
|
| 58 | - $this->value = Redux_Functions::parse_args( $this->value, $defaults ); |
|
| 59 | - |
|
| 60 | - $defaults = array( |
|
| 61 | - 'preview' => false, |
|
| 62 | - 'preview_height' => '150px', |
|
| 63 | - 'transparent' => true, |
|
| 64 | - 'gradient-type' => false, |
|
| 65 | - 'gradient-reach' => false, |
|
| 66 | - 'gradient-angle' => false, |
|
| 67 | - ); |
|
| 68 | - |
|
| 69 | - $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 70 | - |
|
| 71 | - include_once Redux_Core::$dir . 'inc/lib/gradient-filters/class-redux-gradient-filters.php'; |
|
| 72 | - |
|
| 73 | - if ( $this->field['gradient-reach'] || $this->field['gradient-angle'] || $this->field['gradient-type'] ) { |
|
| 74 | - include_once Redux_Core::$dir . 'inc/lib/gradient-filters/class-redux-gradient-filters.php'; |
|
| 75 | - $this->filters_enabled = true; |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Field Render Function. |
|
| 81 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 82 | - * |
|
| 83 | - * @since 1.0.0 |
|
| 84 | - * @access public |
|
| 85 | - * @return void |
|
| 86 | - */ |
|
| 87 | - public function render() { |
|
| 88 | - $data = array( |
|
| 89 | - 'field' => $this->field, |
|
| 90 | - 'value' => $this->value, |
|
| 91 | - ); |
|
| 92 | - |
|
| 93 | - // Escaping done in function. |
|
| 94 | - // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 95 | - echo Redux_Gradient_Filters::render_select( $data ); |
|
| 96 | - |
|
| 97 | - $mode_arr = array( |
|
| 98 | - 'from', |
|
| 99 | - 'to', |
|
| 100 | - ); |
|
| 101 | - |
|
| 102 | - foreach ( $mode_arr as $mode ) { |
|
| 103 | - $uc_mode = ucfirst( $mode ); |
|
| 104 | - |
|
| 105 | - echo '<div class="colorGradient ' . esc_html( $mode ) . 'Label">'; |
|
| 106 | - echo '<strong>' . esc_html( $uc_mode . ' ' ) . '</strong> '; |
|
| 107 | - echo '<input '; |
|
| 108 | - echo 'data-id="' . esc_attr( $this->field['id'] ) . '"'; |
|
| 109 | - echo 'id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $mode ) . '"'; |
|
| 110 | - echo 'name="' . esc_attr( $this->field['name'] ) . esc_attr( $this->field['name_suffix'] ) . '[' . esc_attr( $mode ) . ']"'; |
|
| 111 | - echo 'value="' . esc_attr( $this->value[ $mode ] ) . '"'; |
|
| 112 | - echo 'class="color-picker redux-color redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 113 | - echo 'type="text"'; |
|
| 114 | - echo 'data-default-color="' . esc_attr( $this->field['default'][ $mode ] ) . '"'; |
|
| 115 | - |
|
| 116 | - // Escaping done in function. |
|
| 117 | - // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 118 | - echo Redux_Functions_Ex::output_alpha_data( $data ); |
|
| 119 | - |
|
| 120 | - echo '>'; |
|
| 121 | - |
|
| 122 | - echo '<input type="hidden" class="redux-saved-color" id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $mode ) . '-saved-color" value="">'; |
|
| 123 | - |
|
| 124 | - if ( ! isset( $this->field['transparent'] ) || false !== $this->field['transparent'] ) { |
|
| 125 | - $trans_checked = ''; |
|
| 126 | - |
|
| 127 | - if ( 'transparent' === $this->value[ $mode ] ) { |
|
| 128 | - $trans_checked = ' checked="checked"'; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - echo '<label for="' . esc_attr( $this->field['id'] ) . '-' . esc_html( $mode ) . '-transparency" class="color-transparency-check">'; |
|
| 132 | - echo '<input type="checkbox" class="checkbox color-transparency ' . esc_attr( $this->field['class'] ) . '" id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $mode ) . '-transparency" data-id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $mode ) . '" value="1"' . esc_html( $trans_checked ) . '> ' . esc_html__( 'Transparent', 'redux-framework' ); |
|
| 133 | - echo '</label>'; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - echo '</div>'; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - // Escaping done in function. |
|
| 140 | - // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 141 | - echo Redux_Gradient_Filters::render_preview( $data ); |
|
| 142 | - |
|
| 143 | - // Escaping done in function. |
|
| 144 | - // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 145 | - echo Redux_Gradient_Filters::render_sliders( $data ); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - /** |
|
| 149 | - * Do enqueue for each field instance. |
|
| 150 | - * |
|
| 151 | - * @return void |
|
| 152 | - */ |
|
| 153 | - public function always_enqueue() { |
|
| 154 | - Redux_Gradient_Filters::enqueue( $this->field, $this->filters_enabled ); |
|
| 155 | - |
|
| 156 | - if ( isset( $this->field['color_alpha'] ) && ( $this->field['color_alpha'] || ( $this->field['color_alpha']['from'] || $this->field['color_alpha']['to'] ) ) ) { |
|
| 157 | - if ( ! wp_script_is( 'redux-wp-color-picker-alpha' ) ) { |
|
| 158 | - wp_enqueue_script( 'redux-wp-color-picker-alpha' ); |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Enqueue Function. |
|
| 165 | - * If this field requires any scripts, or CSS define this function and register/enqueue the scripts/css |
|
| 166 | - * |
|
| 167 | - * @since 1.0.0 |
|
| 168 | - * @access public |
|
| 169 | - * @return void |
|
| 170 | - */ |
|
| 171 | - public function enqueue() { |
|
| 172 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 173 | - |
|
| 174 | - $min = Redux_Functions::isMin(); |
|
| 175 | - |
|
| 176 | - wp_enqueue_script( |
|
| 177 | - 'redux-field-color-gradient', |
|
| 178 | - Redux_Core::$url . 'inc/fields/color_gradient/redux-color-gradient' . $min . '.js', |
|
| 179 | - array( 'jquery', 'wp-color-picker', 'redux-js' ), |
|
| 180 | - $this->timestamp, |
|
| 181 | - true |
|
| 182 | - ); |
|
| 183 | - |
|
| 184 | - if ( $this->filters_enabled ) { |
|
| 185 | - wp_enqueue_script( |
|
| 186 | - 'redux-field-color-gradient', |
|
| 187 | - Redux_Core::$url . 'inc/fields/color_gradient/redux-color-gradient' . $min . '.js', |
|
| 188 | - array( 'jquery', 'wp-color-picker' ), |
|
| 189 | - Redux_Core::$version, |
|
| 190 | - true |
|
| 191 | - ); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 195 | - wp_enqueue_style( 'redux-color-picker' ); |
|
| 196 | - |
|
| 197 | - wp_enqueue_style( |
|
| 198 | - 'redux-field-color_gradient', |
|
| 199 | - Redux_Core::$url . 'inc/fields/color_gradient/redux-color-gradient.css', |
|
| 200 | - array(), |
|
| 201 | - $this->timestamp |
|
| 202 | - ); |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Compile CSS styling for output. |
|
| 208 | - * |
|
| 209 | - * @param string $data CSS data. |
|
| 210 | - * |
|
| 211 | - * @return string |
|
| 212 | - */ |
|
| 213 | - public function css_style( $data ): string { |
|
| 214 | - return Redux_Gradient_Filters::get_output( $data ); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Enable output_variables to be generated. |
|
| 219 | - * |
|
| 220 | - * @since 4.0.3 |
|
| 221 | - * @return void |
|
| 222 | - */ |
|
| 223 | - public function output_variables() { |
|
| 224 | - // No code needed, just defining the method is enough. |
|
| 225 | - } |
|
| 226 | - } |
|
| 15 | + /** |
|
| 16 | + * Main Redux_color_gradient class |
|
| 17 | + * |
|
| 18 | + * @since 1.0.0 |
|
| 19 | + */ |
|
| 20 | + class Redux_Color_Gradient extends Redux_Field { |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Filters enabled flag. |
|
| 24 | + * |
|
| 25 | + * @var bool |
|
| 26 | + */ |
|
| 27 | + private $filters_enabled = false; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Redux_Field constructor. |
|
| 31 | + * |
|
| 32 | + * @param array $field Field array. |
|
| 33 | + * @param string $value Field values. |
|
| 34 | + * @param null $redux ReduxFramework object pointer. |
|
| 35 | + * |
|
| 36 | + * @throws ReflectionException Reflection. |
|
| 37 | + */ |
|
| 38 | + public function __construct( $field = array(), $value = null, $redux = null ) { // phpcs:ignore Generic.CodeAnalysis.UselessOverridingMethod |
|
| 39 | + parent::__construct( $field, $value, $redux ); |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Set field and value defaults. |
|
| 44 | + */ |
|
| 45 | + public function set_defaults() { |
|
| 46 | + // No errors please. |
|
| 47 | + $defaults = array( |
|
| 48 | + 'from' => '', |
|
| 49 | + 'to' => '', |
|
| 50 | + 'gradient-type' => 'linear', |
|
| 51 | + 'gradient-angle' => 0, |
|
| 52 | + 'gradient-reach' => array( |
|
| 53 | + 'from' => 0, |
|
| 54 | + 'to' => 100, |
|
| 55 | + ), |
|
| 56 | + ); |
|
| 57 | + |
|
| 58 | + $this->value = Redux_Functions::parse_args( $this->value, $defaults ); |
|
| 59 | + |
|
| 60 | + $defaults = array( |
|
| 61 | + 'preview' => false, |
|
| 62 | + 'preview_height' => '150px', |
|
| 63 | + 'transparent' => true, |
|
| 64 | + 'gradient-type' => false, |
|
| 65 | + 'gradient-reach' => false, |
|
| 66 | + 'gradient-angle' => false, |
|
| 67 | + ); |
|
| 68 | + |
|
| 69 | + $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 70 | + |
|
| 71 | + include_once Redux_Core::$dir . 'inc/lib/gradient-filters/class-redux-gradient-filters.php'; |
|
| 72 | + |
|
| 73 | + if ( $this->field['gradient-reach'] || $this->field['gradient-angle'] || $this->field['gradient-type'] ) { |
|
| 74 | + include_once Redux_Core::$dir . 'inc/lib/gradient-filters/class-redux-gradient-filters.php'; |
|
| 75 | + $this->filters_enabled = true; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Field Render Function. |
|
| 81 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 82 | + * |
|
| 83 | + * @since 1.0.0 |
|
| 84 | + * @access public |
|
| 85 | + * @return void |
|
| 86 | + */ |
|
| 87 | + public function render() { |
|
| 88 | + $data = array( |
|
| 89 | + 'field' => $this->field, |
|
| 90 | + 'value' => $this->value, |
|
| 91 | + ); |
|
| 92 | + |
|
| 93 | + // Escaping done in function. |
|
| 94 | + // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 95 | + echo Redux_Gradient_Filters::render_select( $data ); |
|
| 96 | + |
|
| 97 | + $mode_arr = array( |
|
| 98 | + 'from', |
|
| 99 | + 'to', |
|
| 100 | + ); |
|
| 101 | + |
|
| 102 | + foreach ( $mode_arr as $mode ) { |
|
| 103 | + $uc_mode = ucfirst( $mode ); |
|
| 104 | + |
|
| 105 | + echo '<div class="colorGradient ' . esc_html( $mode ) . 'Label">'; |
|
| 106 | + echo '<strong>' . esc_html( $uc_mode . ' ' ) . '</strong> '; |
|
| 107 | + echo '<input '; |
|
| 108 | + echo 'data-id="' . esc_attr( $this->field['id'] ) . '"'; |
|
| 109 | + echo 'id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $mode ) . '"'; |
|
| 110 | + echo 'name="' . esc_attr( $this->field['name'] ) . esc_attr( $this->field['name_suffix'] ) . '[' . esc_attr( $mode ) . ']"'; |
|
| 111 | + echo 'value="' . esc_attr( $this->value[ $mode ] ) . '"'; |
|
| 112 | + echo 'class="color-picker redux-color redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 113 | + echo 'type="text"'; |
|
| 114 | + echo 'data-default-color="' . esc_attr( $this->field['default'][ $mode ] ) . '"'; |
|
| 115 | + |
|
| 116 | + // Escaping done in function. |
|
| 117 | + // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 118 | + echo Redux_Functions_Ex::output_alpha_data( $data ); |
|
| 119 | + |
|
| 120 | + echo '>'; |
|
| 121 | + |
|
| 122 | + echo '<input type="hidden" class="redux-saved-color" id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $mode ) . '-saved-color" value="">'; |
|
| 123 | + |
|
| 124 | + if ( ! isset( $this->field['transparent'] ) || false !== $this->field['transparent'] ) { |
|
| 125 | + $trans_checked = ''; |
|
| 126 | + |
|
| 127 | + if ( 'transparent' === $this->value[ $mode ] ) { |
|
| 128 | + $trans_checked = ' checked="checked"'; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + echo '<label for="' . esc_attr( $this->field['id'] ) . '-' . esc_html( $mode ) . '-transparency" class="color-transparency-check">'; |
|
| 132 | + echo '<input type="checkbox" class="checkbox color-transparency ' . esc_attr( $this->field['class'] ) . '" id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $mode ) . '-transparency" data-id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $mode ) . '" value="1"' . esc_html( $trans_checked ) . '> ' . esc_html__( 'Transparent', 'redux-framework' ); |
|
| 133 | + echo '</label>'; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + echo '</div>'; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + // Escaping done in function. |
|
| 140 | + // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 141 | + echo Redux_Gradient_Filters::render_preview( $data ); |
|
| 142 | + |
|
| 143 | + // Escaping done in function. |
|
| 144 | + // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 145 | + echo Redux_Gradient_Filters::render_sliders( $data ); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + /** |
|
| 149 | + * Do enqueue for each field instance. |
|
| 150 | + * |
|
| 151 | + * @return void |
|
| 152 | + */ |
|
| 153 | + public function always_enqueue() { |
|
| 154 | + Redux_Gradient_Filters::enqueue( $this->field, $this->filters_enabled ); |
|
| 155 | + |
|
| 156 | + if ( isset( $this->field['color_alpha'] ) && ( $this->field['color_alpha'] || ( $this->field['color_alpha']['from'] || $this->field['color_alpha']['to'] ) ) ) { |
|
| 157 | + if ( ! wp_script_is( 'redux-wp-color-picker-alpha' ) ) { |
|
| 158 | + wp_enqueue_script( 'redux-wp-color-picker-alpha' ); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Enqueue Function. |
|
| 165 | + * If this field requires any scripts, or CSS define this function and register/enqueue the scripts/css |
|
| 166 | + * |
|
| 167 | + * @since 1.0.0 |
|
| 168 | + * @access public |
|
| 169 | + * @return void |
|
| 170 | + */ |
|
| 171 | + public function enqueue() { |
|
| 172 | + wp_enqueue_style( 'wp-color-picker' ); |
|
| 173 | + |
|
| 174 | + $min = Redux_Functions::isMin(); |
|
| 175 | + |
|
| 176 | + wp_enqueue_script( |
|
| 177 | + 'redux-field-color-gradient', |
|
| 178 | + Redux_Core::$url . 'inc/fields/color_gradient/redux-color-gradient' . $min . '.js', |
|
| 179 | + array( 'jquery', 'wp-color-picker', 'redux-js' ), |
|
| 180 | + $this->timestamp, |
|
| 181 | + true |
|
| 182 | + ); |
|
| 183 | + |
|
| 184 | + if ( $this->filters_enabled ) { |
|
| 185 | + wp_enqueue_script( |
|
| 186 | + 'redux-field-color-gradient', |
|
| 187 | + Redux_Core::$url . 'inc/fields/color_gradient/redux-color-gradient' . $min . '.js', |
|
| 188 | + array( 'jquery', 'wp-color-picker' ), |
|
| 189 | + Redux_Core::$version, |
|
| 190 | + true |
|
| 191 | + ); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 195 | + wp_enqueue_style( 'redux-color-picker' ); |
|
| 196 | + |
|
| 197 | + wp_enqueue_style( |
|
| 198 | + 'redux-field-color_gradient', |
|
| 199 | + Redux_Core::$url . 'inc/fields/color_gradient/redux-color-gradient.css', |
|
| 200 | + array(), |
|
| 201 | + $this->timestamp |
|
| 202 | + ); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Compile CSS styling for output. |
|
| 208 | + * |
|
| 209 | + * @param string $data CSS data. |
|
| 210 | + * |
|
| 211 | + * @return string |
|
| 212 | + */ |
|
| 213 | + public function css_style( $data ): string { |
|
| 214 | + return Redux_Gradient_Filters::get_output( $data ); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Enable output_variables to be generated. |
|
| 219 | + * |
|
| 220 | + * @since 4.0.3 |
|
| 221 | + * @return void |
|
| 222 | + */ |
|
| 223 | + public function output_variables() { |
|
| 224 | + // No code needed, just defining the method is enough. |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | class_alias( 'Redux_Color_Gradient', 'ReduxFramework_Color_Gradient' ); |
@@ -58,7 +58,7 @@ |
||
| 58 | 58 | 'index' => '', |
| 59 | 59 | ); |
| 60 | 60 | |
| 61 | - echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 61 | + echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 62 | 62 | |
| 63 | 63 | echo '>'; |
| 64 | 64 | |
@@ -12,157 +12,157 @@ |
||
| 12 | 12 | // Don't duplicate me! |
| 13 | 13 | if ( ! class_exists( 'Redux_Color', false ) ) { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Main Redux_color class |
|
| 17 | - * |
|
| 18 | - * @since 1.0.0 |
|
| 19 | - */ |
|
| 20 | - class Redux_Color extends Redux_Field { |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Set field defaults. |
|
| 24 | - */ |
|
| 25 | - public function set_defaults() { |
|
| 26 | - $defaults = array( |
|
| 27 | - 'transparent' => true, |
|
| 28 | - 'color_alpha' => false, |
|
| 29 | - ); |
|
| 30 | - |
|
| 31 | - $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Field Render Function. |
|
| 36 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 37 | - * |
|
| 38 | - * @since 1.0.0 |
|
| 39 | - * @access public |
|
| 40 | - * @return void |
|
| 41 | - */ |
|
| 42 | - public function render() { |
|
| 43 | - if ( isset( $this->field['color_alpha'] ) && $this->field['color_alpha'] ) { |
|
| 44 | - $this->field['class'] = 'alpha-enabled'; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - echo '<input '; |
|
| 48 | - echo 'data-id="' . esc_attr( $this->field['id'] ) . '"'; |
|
| 49 | - echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '"'; |
|
| 50 | - echo 'id="' . esc_attr( $this->field['id'] ) . '-color"'; |
|
| 51 | - echo 'class="color-picker redux-color redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 52 | - echo 'type="text" value="' . esc_attr( $this->value ) . '"'; |
|
| 53 | - echo 'data-oldcolor=""'; |
|
| 54 | - echo 'data-default-color="' . ( isset( $this->field['default'] ) ? esc_attr( $this->field['default'] ) : '' ) . '"'; |
|
| 55 | - |
|
| 56 | - $data = array( |
|
| 57 | - 'field' => $this->field, |
|
| 58 | - 'index' => '', |
|
| 59 | - ); |
|
| 60 | - |
|
| 61 | - echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 62 | - |
|
| 63 | - echo '>'; |
|
| 64 | - |
|
| 65 | - echo '<input type="hidden" class="redux-saved-color" id="' . esc_attr( $this->field['id'] ) . '-saved-color" value="">'; |
|
| 66 | - |
|
| 67 | - if ( ! isset( $this->field['transparent'] ) || false !== $this->field['transparent'] ) { |
|
| 68 | - $trans_checked = ''; |
|
| 69 | - |
|
| 70 | - if ( 'transparent' === $this->value ) { |
|
| 71 | - $trans_checked = ' checked="checked"'; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - echo '<label for="' . esc_attr( $this->field['id'] ) . '-transparency" class="color-transparency-check">'; |
|
| 75 | - echo '<input type="checkbox" class="checkbox color-transparency ' . esc_attr( $this->field['class'] ) . '" id="' . esc_attr( $this->field['id'] ) . '-transparency" data-id="' . esc_attr( $this->field['id'] ) . '-color" value="1"' . esc_html( $trans_checked ) . '>'; |
|
| 76 | - echo esc_html__( 'Transparent', 'redux-framework' ); |
|
| 77 | - echo '</label>'; |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Do enqueue for each field instance. |
|
| 83 | - * |
|
| 84 | - * @return void |
|
| 85 | - */ |
|
| 86 | - public function always_enqueue() { |
|
| 87 | - if ( isset( $this->field['color_alpha'] ) && $this->field['color_alpha'] ) { |
|
| 88 | - if ( ! wp_script_is( 'redux-wp-color-picker-alpha' ) ) { |
|
| 89 | - wp_enqueue_script( 'redux-wp-color-picker-alpha' ); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Enqueue Function. |
|
| 96 | - * If this field requires any scripts, or CSS define this function and register/enqueue the scripts/css |
|
| 97 | - * |
|
| 98 | - * @since 1.0.0 |
|
| 99 | - * @access public |
|
| 100 | - * @return void |
|
| 101 | - */ |
|
| 102 | - public function enqueue() { |
|
| 103 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 104 | - wp_enqueue_style( 'redux-color-picker' ); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if ( ! wp_style_is( 'wp-color-picker' ) ) { |
|
| 108 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $dep_array = array( 'jquery', 'wp-color-picker', 'redux-js' ); |
|
| 112 | - |
|
| 113 | - wp_enqueue_script( |
|
| 114 | - 'redux-field-color', |
|
| 115 | - Redux_Core::$url . 'inc/fields/color/redux-color' . Redux_Functions::is_min() . '.js', |
|
| 116 | - $dep_array, |
|
| 117 | - $this->timestamp, |
|
| 118 | - true |
|
| 119 | - ); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Generate CSS style (unused, but needed). |
|
| 124 | - * |
|
| 125 | - * @param string $data Field data. |
|
| 126 | - * |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 129 | - public function css_style( $data ): string { |
|
| 130 | - return ''; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Output CSS styling. |
|
| 135 | - * |
|
| 136 | - * @param string|null|array $style CSS style. |
|
| 137 | - */ |
|
| 138 | - public function output( $style = '' ) { |
|
| 139 | - if ( ! empty( $this->value ) ) { |
|
| 140 | - $mode = ( isset( $this->field['mode'] ) && ! empty( $this->field['mode'] ) ? $this->field['mode'] : 'color' ); |
|
| 141 | - |
|
| 142 | - $style = $mode . ':' . $this->value . ';'; |
|
| 143 | - |
|
| 144 | - if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) { |
|
| 145 | - $css = Redux_Functions::parse_css( $this->field['output'], $style, $this->value ); |
|
| 146 | - $this->parent->outputCSS .= $css; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) { |
|
| 150 | - $css = Redux_Functions::parse_css( $this->field['compiler'], $style, $this->value ); |
|
| 151 | - $this->parent->compilerCSS .= $css; |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Enable output_variables to be generated. |
|
| 158 | - * |
|
| 159 | - * @since 4.0.3 |
|
| 160 | - * @return void |
|
| 161 | - */ |
|
| 162 | - public function output_variables() { |
|
| 163 | - // No code needed, just defining the method is enough. |
|
| 164 | - } |
|
| 165 | - } |
|
| 15 | + /** |
|
| 16 | + * Main Redux_color class |
|
| 17 | + * |
|
| 18 | + * @since 1.0.0 |
|
| 19 | + */ |
|
| 20 | + class Redux_Color extends Redux_Field { |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Set field defaults. |
|
| 24 | + */ |
|
| 25 | + public function set_defaults() { |
|
| 26 | + $defaults = array( |
|
| 27 | + 'transparent' => true, |
|
| 28 | + 'color_alpha' => false, |
|
| 29 | + ); |
|
| 30 | + |
|
| 31 | + $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Field Render Function. |
|
| 36 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 37 | + * |
|
| 38 | + * @since 1.0.0 |
|
| 39 | + * @access public |
|
| 40 | + * @return void |
|
| 41 | + */ |
|
| 42 | + public function render() { |
|
| 43 | + if ( isset( $this->field['color_alpha'] ) && $this->field['color_alpha'] ) { |
|
| 44 | + $this->field['class'] = 'alpha-enabled'; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + echo '<input '; |
|
| 48 | + echo 'data-id="' . esc_attr( $this->field['id'] ) . '"'; |
|
| 49 | + echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '"'; |
|
| 50 | + echo 'id="' . esc_attr( $this->field['id'] ) . '-color"'; |
|
| 51 | + echo 'class="color-picker redux-color redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 52 | + echo 'type="text" value="' . esc_attr( $this->value ) . '"'; |
|
| 53 | + echo 'data-oldcolor=""'; |
|
| 54 | + echo 'data-default-color="' . ( isset( $this->field['default'] ) ? esc_attr( $this->field['default'] ) : '' ) . '"'; |
|
| 55 | + |
|
| 56 | + $data = array( |
|
| 57 | + 'field' => $this->field, |
|
| 58 | + 'index' => '', |
|
| 59 | + ); |
|
| 60 | + |
|
| 61 | + echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 62 | + |
|
| 63 | + echo '>'; |
|
| 64 | + |
|
| 65 | + echo '<input type="hidden" class="redux-saved-color" id="' . esc_attr( $this->field['id'] ) . '-saved-color" value="">'; |
|
| 66 | + |
|
| 67 | + if ( ! isset( $this->field['transparent'] ) || false !== $this->field['transparent'] ) { |
|
| 68 | + $trans_checked = ''; |
|
| 69 | + |
|
| 70 | + if ( 'transparent' === $this->value ) { |
|
| 71 | + $trans_checked = ' checked="checked"'; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + echo '<label for="' . esc_attr( $this->field['id'] ) . '-transparency" class="color-transparency-check">'; |
|
| 75 | + echo '<input type="checkbox" class="checkbox color-transparency ' . esc_attr( $this->field['class'] ) . '" id="' . esc_attr( $this->field['id'] ) . '-transparency" data-id="' . esc_attr( $this->field['id'] ) . '-color" value="1"' . esc_html( $trans_checked ) . '>'; |
|
| 76 | + echo esc_html__( 'Transparent', 'redux-framework' ); |
|
| 77 | + echo '</label>'; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Do enqueue for each field instance. |
|
| 83 | + * |
|
| 84 | + * @return void |
|
| 85 | + */ |
|
| 86 | + public function always_enqueue() { |
|
| 87 | + if ( isset( $this->field['color_alpha'] ) && $this->field['color_alpha'] ) { |
|
| 88 | + if ( ! wp_script_is( 'redux-wp-color-picker-alpha' ) ) { |
|
| 89 | + wp_enqueue_script( 'redux-wp-color-picker-alpha' ); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Enqueue Function. |
|
| 96 | + * If this field requires any scripts, or CSS define this function and register/enqueue the scripts/css |
|
| 97 | + * |
|
| 98 | + * @since 1.0.0 |
|
| 99 | + * @access public |
|
| 100 | + * @return void |
|
| 101 | + */ |
|
| 102 | + public function enqueue() { |
|
| 103 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 104 | + wp_enqueue_style( 'redux-color-picker' ); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if ( ! wp_style_is( 'wp-color-picker' ) ) { |
|
| 108 | + wp_enqueue_style( 'wp-color-picker' ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $dep_array = array( 'jquery', 'wp-color-picker', 'redux-js' ); |
|
| 112 | + |
|
| 113 | + wp_enqueue_script( |
|
| 114 | + 'redux-field-color', |
|
| 115 | + Redux_Core::$url . 'inc/fields/color/redux-color' . Redux_Functions::is_min() . '.js', |
|
| 116 | + $dep_array, |
|
| 117 | + $this->timestamp, |
|
| 118 | + true |
|
| 119 | + ); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Generate CSS style (unused, but needed). |
|
| 124 | + * |
|
| 125 | + * @param string $data Field data. |
|
| 126 | + * |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | + public function css_style( $data ): string { |
|
| 130 | + return ''; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Output CSS styling. |
|
| 135 | + * |
|
| 136 | + * @param string|null|array $style CSS style. |
|
| 137 | + */ |
|
| 138 | + public function output( $style = '' ) { |
|
| 139 | + if ( ! empty( $this->value ) ) { |
|
| 140 | + $mode = ( isset( $this->field['mode'] ) && ! empty( $this->field['mode'] ) ? $this->field['mode'] : 'color' ); |
|
| 141 | + |
|
| 142 | + $style = $mode . ':' . $this->value . ';'; |
|
| 143 | + |
|
| 144 | + if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) { |
|
| 145 | + $css = Redux_Functions::parse_css( $this->field['output'], $style, $this->value ); |
|
| 146 | + $this->parent->outputCSS .= $css; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) { |
|
| 150 | + $css = Redux_Functions::parse_css( $this->field['compiler'], $style, $this->value ); |
|
| 151 | + $this->parent->compilerCSS .= $css; |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Enable output_variables to be generated. |
|
| 158 | + * |
|
| 159 | + * @since 4.0.3 |
|
| 160 | + * @return void |
|
| 161 | + */ |
|
| 162 | + public function output_variables() { |
|
| 163 | + // No code needed, just defining the method is enough. |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | class_alias( 'Redux_Color', 'ReduxFramework_Color' ); |
@@ -86,10 +86,10 @@ discard block |
||
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | $value = array( |
| 89 | - 'top' => isset( $this->value[ $this->field['mode'] . '-top' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-top' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['top'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 90 | - 'right' => isset( $this->value[ $this->field['mode'] . '-right' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-right' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['right'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 91 | - 'bottom' => isset( $this->value[ $this->field['mode'] . '-bottom' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-bottom' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['bottom'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 92 | - 'left' => isset( $this->value[ $this->field['mode'] . '-left' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-left' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['left'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 89 | + 'top' => isset( $this->value[$this->field['mode'] . '-top'] ) ? filter_var( $this->value[$this->field['mode'] . '-top'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['top'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 90 | + 'right' => isset( $this->value[$this->field['mode'] . '-right'] ) ? filter_var( $this->value[$this->field['mode'] . '-right'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['right'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 91 | + 'bottom' => isset( $this->value[$this->field['mode'] . '-bottom'] ) ? filter_var( $this->value[$this->field['mode'] . '-bottom'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['bottom'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 92 | + 'left' => isset( $this->value[$this->field['mode'] . '-left'] ) ? filter_var( $this->value[$this->field['mode'] . '-left'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['left'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 93 | 93 | ); |
| 94 | 94 | |
| 95 | 95 | // if field units has a value and is NOT an array, then evaluate as needed. |
@@ -343,7 +343,7 @@ discard block |
||
| 343 | 343 | public function css_style( $data ) { |
| 344 | 344 | $style = ''; |
| 345 | 345 | |
| 346 | - $data = (array) $data; |
|
| 346 | + $data = ( array ) $data; |
|
| 347 | 347 | |
| 348 | 348 | if ( ! isset( $this->field ) ) { |
| 349 | 349 | return; |
@@ -11,152 +11,152 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Spacing', false ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Class Redux_Spacing |
|
| 16 | - */ |
|
| 17 | - class Redux_Spacing extends Redux_Field { |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Set field a value defaults. |
|
| 21 | - */ |
|
| 22 | - public function set_defaults() { |
|
| 23 | - $defaults = array( |
|
| 24 | - 'units' => 'px', |
|
| 25 | - 'mode' => 'padding', |
|
| 26 | - 'top' => true, |
|
| 27 | - 'bottom' => true, |
|
| 28 | - 'all' => false, |
|
| 29 | - 'left' => true, |
|
| 30 | - 'right' => true, |
|
| 31 | - 'units_extended' => false, |
|
| 32 | - 'display_units' => true, |
|
| 33 | - ); |
|
| 34 | - |
|
| 35 | - $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 36 | - |
|
| 37 | - // Set default values. |
|
| 38 | - $defaults = array( |
|
| 39 | - 'top' => '', |
|
| 40 | - 'right' => '', |
|
| 41 | - 'bottom' => '', |
|
| 42 | - 'left' => '', |
|
| 43 | - 'units' => 'px', |
|
| 44 | - ); |
|
| 45 | - |
|
| 46 | - $this->value = wp_parse_args( $this->value, $defaults ); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Field Render Function. |
|
| 51 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 52 | - * |
|
| 53 | - * @since ReduxFramework 1.0.0 |
|
| 54 | - */ |
|
| 55 | - public function render() { |
|
| 56 | - /* |
|
| 14 | + /** |
|
| 15 | + * Class Redux_Spacing |
|
| 16 | + */ |
|
| 17 | + class Redux_Spacing extends Redux_Field { |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Set field a value defaults. |
|
| 21 | + */ |
|
| 22 | + public function set_defaults() { |
|
| 23 | + $defaults = array( |
|
| 24 | + 'units' => 'px', |
|
| 25 | + 'mode' => 'padding', |
|
| 26 | + 'top' => true, |
|
| 27 | + 'bottom' => true, |
|
| 28 | + 'all' => false, |
|
| 29 | + 'left' => true, |
|
| 30 | + 'right' => true, |
|
| 31 | + 'units_extended' => false, |
|
| 32 | + 'display_units' => true, |
|
| 33 | + ); |
|
| 34 | + |
|
| 35 | + $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 36 | + |
|
| 37 | + // Set default values. |
|
| 38 | + $defaults = array( |
|
| 39 | + 'top' => '', |
|
| 40 | + 'right' => '', |
|
| 41 | + 'bottom' => '', |
|
| 42 | + 'left' => '', |
|
| 43 | + 'units' => 'px', |
|
| 44 | + ); |
|
| 45 | + |
|
| 46 | + $this->value = wp_parse_args( $this->value, $defaults ); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Field Render Function. |
|
| 51 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 52 | + * |
|
| 53 | + * @since ReduxFramework 1.0.0 |
|
| 54 | + */ |
|
| 55 | + public function render() { |
|
| 56 | + /* |
|
| 57 | 57 | * Acceptable values checks. If the passed variable doesn't pass muster, we unset them |
| 58 | 58 | * and reset them with default values to avoid errors. |
| 59 | 59 | */ |
| 60 | 60 | |
| 61 | - $unit_arr = Redux_Helpers::$array_units; |
|
| 62 | - |
|
| 63 | - $unit_check = $unit_arr; |
|
| 64 | - $unit_check[] = false; |
|
| 65 | - |
|
| 66 | - // If units field has a value but is not an acceptable value, unset the variable. |
|
| 67 | - if ( ! Redux_Helpers::array_in_array( $this->field['units'], $unit_check ) ) { |
|
| 68 | - $this->field['units'] = 'px'; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // If there is a default unit value but is not an accepted value, unset the variable. |
|
| 72 | - if ( ! Redux_Helpers::array_in_array( $this->value['units'], $unit_check ) ) { |
|
| 73 | - $this->value['units'] = 'px'; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if ( false === $this->field['units'] ) { |
|
| 77 | - $this->value['units'] = ''; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - if ( ! in_array( $this->field['mode'], array( 'margin', 'padding' ), true ) ) { |
|
| 81 | - if ( 'absolute' === $this->field['mode'] ) { |
|
| 82 | - $this->field['mode'] = ''; |
|
| 83 | - } else { |
|
| 84 | - $this->field['mode'] = 'padding'; |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $value = array( |
|
| 89 | - 'top' => isset( $this->value[ $this->field['mode'] . '-top' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-top' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['top'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 90 | - 'right' => isset( $this->value[ $this->field['mode'] . '-right' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-right' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['right'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 91 | - 'bottom' => isset( $this->value[ $this->field['mode'] . '-bottom' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-bottom' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['bottom'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 92 | - 'left' => isset( $this->value[ $this->field['mode'] . '-left' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-left' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['left'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - // if field units has a value and is NOT an array, then evaluate as needed. |
|
| 96 | - if ( ! is_array( $this->field['units'] ) ) { |
|
| 97 | - |
|
| 98 | - // If units fields has a value and is not empty but units value does not then make units value the field value. |
|
| 99 | - if ( '' === $this->value['units'] && ( '' !== $this->field['units'] || false === $this->field['units'] ) ) { |
|
| 100 | - $this->value['units'] = $this->field['units']; |
|
| 101 | - |
|
| 102 | - // If units field does NOT have a value and units value does NOT have a value, set both to blank (default?). |
|
| 103 | - } elseif ( '' === $this->field['units'] && '' === $this->value['units'] ) { |
|
| 104 | - $this->field['units'] = 'px'; |
|
| 105 | - $this->value['units'] = 'px'; |
|
| 106 | - |
|
| 107 | - // If units field has NO value but units value does, then set unit field to value field. |
|
| 108 | - } elseif ( '' === $this->field['units'] && '' !== $this->value['units'] ) { |
|
| 109 | - $this->field['units'] = $this->value['units']; |
|
| 110 | - |
|
| 111 | - // if unit value is set and unit value doesn't equal unit field (coz who knows why) |
|
| 112 | - // then set unit value to unit field. |
|
| 113 | - } elseif ( '' !== $this->value['units'] && $this->field['units'] !== $this->value['units'] ) { |
|
| 114 | - $this->value['units'] = $this->field['units']; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // do stuff based on unit field NOT set as an array. |
|
| 118 | - // phpcs:ignore Generic.CodeAnalysis.EmptyStatement |
|
| 119 | - } elseif ( ! empty( $this->field['units'] ) && is_array( $this->field['units'] ) ) { |
|
| 120 | - // nothing to do here, but I'm leaving the construct just in case I have to debug this again. |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - if ( '' !== $this->field['units'] ) { |
|
| 124 | - $value['units'] = $this->value['units']; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - $this->value = $value; |
|
| 128 | - |
|
| 129 | - if ( '' !== $this->field['mode'] ) { |
|
| 130 | - $this->field['mode'] = $this->field['mode'] . '-'; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - if ( isset( $this->field['select2'] ) ) { |
|
| 134 | - $this->field['select2'] = wp_parse_args( $this->field['select2'], $this->select2_config ); |
|
| 135 | - } else { |
|
| 136 | - $this->field['select2'] = $this->select2_config; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - $this->field['select2'] = Redux_Functions::sanitize_camel_case_array_keys( $this->field['select2'] ); |
|
| 140 | - |
|
| 141 | - $select2_data = Redux_Functions::create_data_string( $this->field['select2'] ); |
|
| 142 | - |
|
| 143 | - echo '<input |
|
| 61 | + $unit_arr = Redux_Helpers::$array_units; |
|
| 62 | + |
|
| 63 | + $unit_check = $unit_arr; |
|
| 64 | + $unit_check[] = false; |
|
| 65 | + |
|
| 66 | + // If units field has a value but is not an acceptable value, unset the variable. |
|
| 67 | + if ( ! Redux_Helpers::array_in_array( $this->field['units'], $unit_check ) ) { |
|
| 68 | + $this->field['units'] = 'px'; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // If there is a default unit value but is not an accepted value, unset the variable. |
|
| 72 | + if ( ! Redux_Helpers::array_in_array( $this->value['units'], $unit_check ) ) { |
|
| 73 | + $this->value['units'] = 'px'; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if ( false === $this->field['units'] ) { |
|
| 77 | + $this->value['units'] = ''; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + if ( ! in_array( $this->field['mode'], array( 'margin', 'padding' ), true ) ) { |
|
| 81 | + if ( 'absolute' === $this->field['mode'] ) { |
|
| 82 | + $this->field['mode'] = ''; |
|
| 83 | + } else { |
|
| 84 | + $this->field['mode'] = 'padding'; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $value = array( |
|
| 89 | + 'top' => isset( $this->value[ $this->field['mode'] . '-top' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-top' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['top'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 90 | + 'right' => isset( $this->value[ $this->field['mode'] . '-right' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-right' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['right'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 91 | + 'bottom' => isset( $this->value[ $this->field['mode'] . '-bottom' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-bottom' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['bottom'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 92 | + 'left' => isset( $this->value[ $this->field['mode'] . '-left' ] ) ? filter_var( $this->value[ $this->field['mode'] . '-left' ], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['left'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + // if field units has a value and is NOT an array, then evaluate as needed. |
|
| 96 | + if ( ! is_array( $this->field['units'] ) ) { |
|
| 97 | + |
|
| 98 | + // If units fields has a value and is not empty but units value does not then make units value the field value. |
|
| 99 | + if ( '' === $this->value['units'] && ( '' !== $this->field['units'] || false === $this->field['units'] ) ) { |
|
| 100 | + $this->value['units'] = $this->field['units']; |
|
| 101 | + |
|
| 102 | + // If units field does NOT have a value and units value does NOT have a value, set both to blank (default?). |
|
| 103 | + } elseif ( '' === $this->field['units'] && '' === $this->value['units'] ) { |
|
| 104 | + $this->field['units'] = 'px'; |
|
| 105 | + $this->value['units'] = 'px'; |
|
| 106 | + |
|
| 107 | + // If units field has NO value but units value does, then set unit field to value field. |
|
| 108 | + } elseif ( '' === $this->field['units'] && '' !== $this->value['units'] ) { |
|
| 109 | + $this->field['units'] = $this->value['units']; |
|
| 110 | + |
|
| 111 | + // if unit value is set and unit value doesn't equal unit field (coz who knows why) |
|
| 112 | + // then set unit value to unit field. |
|
| 113 | + } elseif ( '' !== $this->value['units'] && $this->field['units'] !== $this->value['units'] ) { |
|
| 114 | + $this->value['units'] = $this->field['units']; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // do stuff based on unit field NOT set as an array. |
|
| 118 | + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement |
|
| 119 | + } elseif ( ! empty( $this->field['units'] ) && is_array( $this->field['units'] ) ) { |
|
| 120 | + // nothing to do here, but I'm leaving the construct just in case I have to debug this again. |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + if ( '' !== $this->field['units'] ) { |
|
| 124 | + $value['units'] = $this->value['units']; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + $this->value = $value; |
|
| 128 | + |
|
| 129 | + if ( '' !== $this->field['mode'] ) { |
|
| 130 | + $this->field['mode'] = $this->field['mode'] . '-'; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + if ( isset( $this->field['select2'] ) ) { |
|
| 134 | + $this->field['select2'] = wp_parse_args( $this->field['select2'], $this->select2_config ); |
|
| 135 | + } else { |
|
| 136 | + $this->field['select2'] = $this->select2_config; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + $this->field['select2'] = Redux_Functions::sanitize_camel_case_array_keys( $this->field['select2'] ); |
|
| 140 | + |
|
| 141 | + $select2_data = Redux_Functions::create_data_string( $this->field['select2'] ); |
|
| 142 | + |
|
| 143 | + echo '<input |
|
| 144 | 144 | type="hidden" |
| 145 | 145 | id="' . esc_attr( $this->field['id'] ) . '-units" |
| 146 | 146 | name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[units]" |
| 147 | 147 | class="field-units" value="' . esc_attr( $this->value['units'] ) . '">'; |
| 148 | 148 | |
| 149 | - if ( true === $this->field['all'] ) { |
|
| 150 | - $this->field['top'] = true; |
|
| 151 | - $this->field['right'] = true; |
|
| 152 | - $this->field['bottom'] = true; |
|
| 153 | - $this->field['left'] = true; |
|
| 149 | + if ( true === $this->field['all'] ) { |
|
| 150 | + $this->field['top'] = true; |
|
| 151 | + $this->field['right'] = true; |
|
| 152 | + $this->field['bottom'] = true; |
|
| 153 | + $this->field['left'] = true; |
|
| 154 | 154 | |
| 155 | - $this->value['bottom'] = $this->value['top']; |
|
| 156 | - $this->value['left'] = $this->value['top']; |
|
| 157 | - $this->value['right'] = $this->value['top']; |
|
| 155 | + $this->value['bottom'] = $this->value['top']; |
|
| 156 | + $this->value['left'] = $this->value['top']; |
|
| 157 | + $this->value['right'] = $this->value['top']; |
|
| 158 | 158 | |
| 159 | - echo '<div class="field-spacing-input input-prepend"> |
|
| 159 | + echo '<div class="field-spacing-input input-prepend"> |
|
| 160 | 160 | <span class="add-on"> |
| 161 | 161 | <i class="el el-fullscreen icon-large"></i> |
| 162 | 162 | </span> |
@@ -169,54 +169,54 @@ discard block |
||
| 169 | 169 | value="' . esc_attr( $this->value['top'] ) . '" |
| 170 | 170 | > |
| 171 | 171 | </div>'; |
| 172 | - } |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - if ( true === $this->field['top'] ) { |
|
| 175 | - echo '<input |
|
| 174 | + if ( true === $this->field['top'] ) { |
|
| 175 | + echo '<input |
|
| 176 | 176 | type="hidden" |
| 177 | 177 | class="redux-spacing-value" |
| 178 | 178 | id="' . esc_attr( $this->field['id'] ) . '-top-hidden" |
| 179 | 179 | name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] . '[' . $this->field['mode'] ) . 'top]" |
| 180 | 180 | value="' . esc_attr( $this->value['top'] ) . ( ! empty( $this->value['top'] ) ? esc_attr( $this->value['units'] ) : '' ) . '" |
| 181 | 181 | >'; |
| 182 | - } |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - if ( true === $this->field['right'] ) { |
|
| 185 | - echo '<input |
|
| 184 | + if ( true === $this->field['right'] ) { |
|
| 185 | + echo '<input |
|
| 186 | 186 | type="hidden" |
| 187 | 187 | class="redux-spacing-value" |
| 188 | 188 | id="' . esc_attr( $this->field['id'] ) . '-right-hidden" |
| 189 | 189 | name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] . '[' . $this->field['mode'] ) . 'right]" |
| 190 | 190 | value="' . esc_attr( $this->value['right'] ) . ( ! empty( $this->value['right'] ) ? esc_attr( $this->value['units'] ) : '' ) . '" |
| 191 | 191 | >'; |
| 192 | - } |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - if ( true === $this->field['bottom'] ) { |
|
| 195 | - echo '<input |
|
| 194 | + if ( true === $this->field['bottom'] ) { |
|
| 195 | + echo '<input |
|
| 196 | 196 | type="hidden" |
| 197 | 197 | class="redux-spacing-value" |
| 198 | 198 | id="' . esc_attr( $this->field['id'] ) . '-bottom-hidden" |
| 199 | 199 | name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] . '[' . $this->field['mode'] ) . 'bottom]" |
| 200 | 200 | value="' . esc_attr( $this->value['bottom'] ) . ( ! empty( $this->value['bottom'] ) ? esc_attr( $this->value['units'] ) : '' ) . '" |
| 201 | 201 | >'; |
| 202 | - } |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - if ( true === $this->field['left'] ) { |
|
| 205 | - echo '<input |
|
| 204 | + if ( true === $this->field['left'] ) { |
|
| 205 | + echo '<input |
|
| 206 | 206 | type="hidden" |
| 207 | 207 | class="redux-spacing-value" |
| 208 | 208 | id="' . esc_attr( $this->field['id'] ) . '-left-hidden" |
| 209 | 209 | name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] . '[' . $this->field['mode'] ) . 'left]" |
| 210 | 210 | value="' . esc_attr( $this->value['left'] ) . ( ! empty( $this->value['left'] ) ? esc_attr( $this->value['units'] ) : '' ) . '" |
| 211 | 211 | >'; |
| 212 | - } |
|
| 213 | - |
|
| 214 | - if ( false === $this->field['all'] ) { |
|
| 215 | - /** |
|
| 216 | - * Top |
|
| 217 | - * */ |
|
| 218 | - if ( true === $this->field['top'] ) { |
|
| 219 | - echo '<div class="field-spacing-input input-prepend"> |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + if ( false === $this->field['all'] ) { |
|
| 215 | + /** |
|
| 216 | + * Top |
|
| 217 | + * */ |
|
| 218 | + if ( true === $this->field['top'] ) { |
|
| 219 | + echo '<div class="field-spacing-input input-prepend"> |
|
| 220 | 220 | <span class="add-on"> |
| 221 | 221 | <i class="el el-arrow-up icon-large"></i> |
| 222 | 222 | </span> |
@@ -227,13 +227,13 @@ discard block |
||
| 227 | 227 | rel="' . esc_attr( $this->field['id'] ) . '-top-hidden" |
| 228 | 228 | value="' . esc_attr( $this->value['top'] ) . '"/> |
| 229 | 229 | </div>'; |
| 230 | - } |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * Right |
|
| 234 | - * */ |
|
| 235 | - if ( true === $this->field['right'] ) { |
|
| 236 | - echo '<div class="field-spacing-input input-prepend"> |
|
| 232 | + /** |
|
| 233 | + * Right |
|
| 234 | + * */ |
|
| 235 | + if ( true === $this->field['right'] ) { |
|
| 236 | + echo '<div class="field-spacing-input input-prepend"> |
|
| 237 | 237 | <span class="add-on"> |
| 238 | 238 | <i class="el el-arrow-right icon-large"></i> |
| 239 | 239 | </span> |
@@ -244,13 +244,13 @@ discard block |
||
| 244 | 244 | rel="' . esc_attr( $this->field['id'] ) . '-right-hidden" |
| 245 | 245 | value="' . esc_attr( $this->value['right'] ) . '"/> |
| 246 | 246 | </div>'; |
| 247 | - } |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - /** |
|
| 250 | - * Bottom |
|
| 251 | - * */ |
|
| 252 | - if ( true === $this->field['bottom'] ) { |
|
| 253 | - echo '<div class="field-spacing-input input-prepend"> |
|
| 249 | + /** |
|
| 250 | + * Bottom |
|
| 251 | + * */ |
|
| 252 | + if ( true === $this->field['bottom'] ) { |
|
| 253 | + echo '<div class="field-spacing-input input-prepend"> |
|
| 254 | 254 | <span class="add-on"> |
| 255 | 255 | <i class="el el-arrow-down icon-large"></i> |
| 256 | 256 | </span> |
@@ -261,13 +261,13 @@ discard block |
||
| 261 | 261 | rel="' . esc_attr( $this->field['id'] ) . '-bottom-hidden" |
| 262 | 262 | value="' . esc_attr( $this->value['bottom'] ) . '"> |
| 263 | 263 | </div>'; |
| 264 | - } |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | - /** |
|
| 267 | - * Left |
|
| 268 | - * */ |
|
| 269 | - if ( true === $this->field['left'] ) { |
|
| 270 | - echo '<div class="field-spacing-input input-prepend"> |
|
| 266 | + /** |
|
| 267 | + * Left |
|
| 268 | + * */ |
|
| 269 | + if ( true === $this->field['left'] ) { |
|
| 270 | + echo '<div class="field-spacing-input input-prepend"> |
|
| 271 | 271 | <span class="add-on"> |
| 272 | 272 | <i class="el el-arrow-left icon-large"></i> |
| 273 | 273 | </span> |
@@ -278,120 +278,120 @@ discard block |
||
| 278 | 278 | rel="' . esc_attr( $this->field['id'] ) . '-left-hidden" |
| 279 | 279 | value="' . esc_attr( $this->value['left'] ) . '"/> |
| 280 | 280 | </div>'; |
| 281 | - } |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * Units |
|
| 286 | - * */ |
|
| 287 | - if ( false !== $this->field['units'] && true === $this->field['display_units'] ) { |
|
| 288 | - echo '<div class="select_wrapper spacing-units" original-title="' . esc_html__( 'Units', 'redux-framework' ) . '">'; |
|
| 289 | - echo '<select data-placeholder="' . esc_html__( 'Units', 'redux-framework' ) . '" class="redux-spacing redux-spacing-units select ' . esc_attr( $this->field['class'] ) . '" original-title="' . esc_html__( 'Units', 'redux-framework' ) . '" id="' . esc_attr( $this->field['id'] ) . '_units"' . esc_attr( $select2_data ) . '>'; |
|
| 290 | - |
|
| 291 | - if ( $this->field['units_extended'] ) { |
|
| 292 | - $test_units = $unit_arr; |
|
| 293 | - } else { |
|
| 294 | - $test_units = array( 'px', 'em', 'pt', 'rem', '%' ); |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - if ( '' !== $this->field['units'] || is_array( $this->field['units'] ) ) { |
|
| 298 | - $test_units = $this->field['units']; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - echo '<option></option>'; |
|
| 302 | - |
|
| 303 | - if ( ! is_array( $this->field['units'] ) ) { |
|
| 304 | - echo '<option value="' . esc_attr( $this->field['units'] ) . '" selected="selected">' . esc_attr( $this->field['units'] ) . '</option>'; |
|
| 305 | - } else { |
|
| 306 | - foreach ( $test_units as $a_unit ) { |
|
| 307 | - echo '<option value="' . esc_attr( $a_unit ) . '" ' . selected( $this->value['units'], $a_unit, false ) . '>' . esc_html( $a_unit ) . '</option>'; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - echo '</select></div>'; |
|
| 312 | - } |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Enqueue Function. |
|
| 317 | - * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 318 | - * |
|
| 319 | - * @since ReduxFramework 1.0.0 |
|
| 320 | - */ |
|
| 321 | - public function enqueue() { |
|
| 322 | - wp_enqueue_style( 'select2-css' ); |
|
| 323 | - |
|
| 324 | - wp_enqueue_script( |
|
| 325 | - 'redux-field-spacing', |
|
| 326 | - Redux_Core::$url . 'inc/fields/spacing/redux-spacing' . Redux_Functions::is_min() . '.js', |
|
| 327 | - array( 'jquery', 'select2-js', 'redux-js' ), |
|
| 328 | - $this->timestamp, |
|
| 329 | - true |
|
| 330 | - ); |
|
| 331 | - |
|
| 332 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 333 | - wp_enqueue_style( |
|
| 334 | - 'redux-field-spacing', |
|
| 335 | - Redux_Core::$url . 'inc/fields/spacing/redux-spacing.css', |
|
| 336 | - array(), |
|
| 337 | - $this->timestamp |
|
| 338 | - ); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Compile CSS data for output. |
|
| 344 | - * |
|
| 345 | - * @param string $data CSS data. |
|
| 346 | - * |
|
| 347 | - * @return string|void |
|
| 348 | - */ |
|
| 349 | - public function css_style( $data ) { |
|
| 350 | - $style = ''; |
|
| 351 | - |
|
| 352 | - $data = (array) $data; |
|
| 353 | - |
|
| 354 | - if ( ! isset( $this->field ) ) { |
|
| 355 | - return; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - if ( ! in_array( $this->field['mode'], array( 'padding', 'absolute', 'margin' ), true ) ) { |
|
| 359 | - $this->field['mode'] = 'padding'; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - $units = $data['units'] ?? ''; |
|
| 363 | - |
|
| 364 | - foreach ( $data as $key => $value ) { |
|
| 365 | - if ( 'units' === $key ) { |
|
| 366 | - continue; |
|
| 367 | - } |
|
| 368 | - $the_units = $units; |
|
| 369 | - |
|
| 370 | - // Strip off any alpha for is_numeric test - kp. |
|
| 371 | - $num_no_alpha = preg_replace( '/[^\d.-]/', '', $value ); |
|
| 372 | - if ( empty( $the_units ) ) { |
|
| 373 | - $the_units = str_replace( $num_no_alpha, '', $value ); |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - // Output if it's a numeric entry. |
|
| 377 | - if ( isset( $value ) && is_numeric( $num_no_alpha ) ) { |
|
| 378 | - $style .= $key . ':' . $num_no_alpha . $the_units . ';'; |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - return $style; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Enable output_variables to be generated. |
|
| 387 | - * |
|
| 388 | - * @since 4.0.3 |
|
| 389 | - * @return void |
|
| 390 | - */ |
|
| 391 | - public function output_variables() { |
|
| 392 | - // No code needed, just defining the method is enough. |
|
| 393 | - } |
|
| 394 | - } |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Units |
|
| 286 | + * */ |
|
| 287 | + if ( false !== $this->field['units'] && true === $this->field['display_units'] ) { |
|
| 288 | + echo '<div class="select_wrapper spacing-units" original-title="' . esc_html__( 'Units', 'redux-framework' ) . '">'; |
|
| 289 | + echo '<select data-placeholder="' . esc_html__( 'Units', 'redux-framework' ) . '" class="redux-spacing redux-spacing-units select ' . esc_attr( $this->field['class'] ) . '" original-title="' . esc_html__( 'Units', 'redux-framework' ) . '" id="' . esc_attr( $this->field['id'] ) . '_units"' . esc_attr( $select2_data ) . '>'; |
|
| 290 | + |
|
| 291 | + if ( $this->field['units_extended'] ) { |
|
| 292 | + $test_units = $unit_arr; |
|
| 293 | + } else { |
|
| 294 | + $test_units = array( 'px', 'em', 'pt', 'rem', '%' ); |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + if ( '' !== $this->field['units'] || is_array( $this->field['units'] ) ) { |
|
| 298 | + $test_units = $this->field['units']; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + echo '<option></option>'; |
|
| 302 | + |
|
| 303 | + if ( ! is_array( $this->field['units'] ) ) { |
|
| 304 | + echo '<option value="' . esc_attr( $this->field['units'] ) . '" selected="selected">' . esc_attr( $this->field['units'] ) . '</option>'; |
|
| 305 | + } else { |
|
| 306 | + foreach ( $test_units as $a_unit ) { |
|
| 307 | + echo '<option value="' . esc_attr( $a_unit ) . '" ' . selected( $this->value['units'], $a_unit, false ) . '>' . esc_html( $a_unit ) . '</option>'; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + echo '</select></div>'; |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Enqueue Function. |
|
| 317 | + * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 318 | + * |
|
| 319 | + * @since ReduxFramework 1.0.0 |
|
| 320 | + */ |
|
| 321 | + public function enqueue() { |
|
| 322 | + wp_enqueue_style( 'select2-css' ); |
|
| 323 | + |
|
| 324 | + wp_enqueue_script( |
|
| 325 | + 'redux-field-spacing', |
|
| 326 | + Redux_Core::$url . 'inc/fields/spacing/redux-spacing' . Redux_Functions::is_min() . '.js', |
|
| 327 | + array( 'jquery', 'select2-js', 'redux-js' ), |
|
| 328 | + $this->timestamp, |
|
| 329 | + true |
|
| 330 | + ); |
|
| 331 | + |
|
| 332 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 333 | + wp_enqueue_style( |
|
| 334 | + 'redux-field-spacing', |
|
| 335 | + Redux_Core::$url . 'inc/fields/spacing/redux-spacing.css', |
|
| 336 | + array(), |
|
| 337 | + $this->timestamp |
|
| 338 | + ); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Compile CSS data for output. |
|
| 344 | + * |
|
| 345 | + * @param string $data CSS data. |
|
| 346 | + * |
|
| 347 | + * @return string|void |
|
| 348 | + */ |
|
| 349 | + public function css_style( $data ) { |
|
| 350 | + $style = ''; |
|
| 351 | + |
|
| 352 | + $data = (array) $data; |
|
| 353 | + |
|
| 354 | + if ( ! isset( $this->field ) ) { |
|
| 355 | + return; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + if ( ! in_array( $this->field['mode'], array( 'padding', 'absolute', 'margin' ), true ) ) { |
|
| 359 | + $this->field['mode'] = 'padding'; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + $units = $data['units'] ?? ''; |
|
| 363 | + |
|
| 364 | + foreach ( $data as $key => $value ) { |
|
| 365 | + if ( 'units' === $key ) { |
|
| 366 | + continue; |
|
| 367 | + } |
|
| 368 | + $the_units = $units; |
|
| 369 | + |
|
| 370 | + // Strip off any alpha for is_numeric test - kp. |
|
| 371 | + $num_no_alpha = preg_replace( '/[^\d.-]/', '', $value ); |
|
| 372 | + if ( empty( $the_units ) ) { |
|
| 373 | + $the_units = str_replace( $num_no_alpha, '', $value ); |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + // Output if it's a numeric entry. |
|
| 377 | + if ( isset( $value ) && is_numeric( $num_no_alpha ) ) { |
|
| 378 | + $style .= $key . ':' . $num_no_alpha . $the_units . ';'; |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + return $style; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Enable output_variables to be generated. |
|
| 387 | + * |
|
| 388 | + * @since 4.0.3 |
|
| 389 | + * @return void |
|
| 390 | + */ |
|
| 391 | + public function output_variables() { |
|
| 392 | + // No code needed, just defining the method is enough. |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | class_alias( 'Redux_Spacing', 'ReduxFramework_Spacing' ); |
@@ -144,11 +144,11 @@ discard block |
||
| 144 | 144 | |
| 145 | 145 | foreach ( $ex_arr as $ext ) { |
| 146 | 146 | if ( in_array( $ext, $lib_array, true ) ) { |
| 147 | - $json_arr[ $ext ] = $type; |
|
| 147 | + $json_arr[$ext] = $type; |
|
| 148 | 148 | } |
| 149 | 149 | } |
| 150 | 150 | } elseif ( in_array( $ext, $lib_array, true ) ) { |
| 151 | - $json_arr[ $ext ] = $type; |
|
| 151 | + $json_arr[$ext] = $type; |
|
| 152 | 152 | } |
| 153 | 153 | } |
| 154 | 154 | |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * @return string|null |
| 302 | 302 | */ |
| 303 | 303 | public function css_style( $data ): string { |
| 304 | - $data = (array) $data; |
|
| 304 | + $data = ( array ) $data; |
|
| 305 | 305 | |
| 306 | 306 | if ( isset( $data['filter'] ) ) { |
| 307 | 307 | return $this->get_filter_css( $data['filter'] ); |
@@ -12,339 +12,339 @@ |
||
| 12 | 12 | // Don't duplicate me! |
| 13 | 13 | if ( ! class_exists( 'Redux_Media', false ) ) { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Main Redux_media class |
|
| 17 | - * |
|
| 18 | - * @since 1.0.0 |
|
| 19 | - */ |
|
| 20 | - class Redux_Media extends Redux_Field { |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Flag to filter file types. |
|
| 24 | - * |
|
| 25 | - * @var bool $filters_enabled . |
|
| 26 | - */ |
|
| 27 | - private $filters_enabled = false; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Set field and value defaults. |
|
| 31 | - */ |
|
| 32 | - public function set_defaults() { |
|
| 33 | - // No errors please. |
|
| 34 | - $defaults = array( |
|
| 35 | - 'id' => '', |
|
| 36 | - 'url' => '', |
|
| 37 | - 'width' => '', |
|
| 38 | - 'height' => '', |
|
| 39 | - 'thumbnail' => '', |
|
| 40 | - 'filter' => array( |
|
| 41 | - 'grayscale' => array( |
|
| 42 | - 'checked' => false, |
|
| 43 | - 'value' => 0, |
|
| 44 | - ), |
|
| 45 | - 'blur' => array( |
|
| 46 | - 'checked' => false, |
|
| 47 | - 'value' => 0, |
|
| 48 | - ), |
|
| 49 | - 'sepia' => array( |
|
| 50 | - 'checked' => false, |
|
| 51 | - 'value' => 0, |
|
| 52 | - ), |
|
| 53 | - 'saturate' => array( |
|
| 54 | - 'checked' => false, |
|
| 55 | - 'value' => 1, |
|
| 56 | - ), |
|
| 57 | - 'opacity' => array( |
|
| 58 | - 'checked' => false, |
|
| 59 | - 'value' => 1, |
|
| 60 | - ), |
|
| 61 | - 'brightness' => array( |
|
| 62 | - 'checked' => false, |
|
| 63 | - 'value' => 100, |
|
| 64 | - ), |
|
| 65 | - 'contrast' => array( |
|
| 66 | - 'checked' => false, |
|
| 67 | - 'value' => 100, |
|
| 68 | - ), |
|
| 69 | - 'hue-rotate' => array( |
|
| 70 | - 'checked' => false, |
|
| 71 | - 'value' => 0, |
|
| 72 | - ), |
|
| 73 | - 'invert' => array( |
|
| 74 | - 'checked' => false, |
|
| 75 | - 'value' => 0, |
|
| 76 | - ), |
|
| 77 | - ), |
|
| 78 | - ); |
|
| 79 | - |
|
| 80 | - // Since value sub-arrays do not get parsed in wp_parse_args! |
|
| 81 | - $this->value = Redux_Functions::parse_args( $this->value, $defaults ); |
|
| 82 | - |
|
| 83 | - $defaults = array( |
|
| 84 | - 'mode' => 'image', |
|
| 85 | - 'preview' => true, |
|
| 86 | - 'preview_size' => 'thumbnail', |
|
| 87 | - 'url' => true, |
|
| 88 | - 'alt' => '', |
|
| 89 | - 'placeholder' => esc_html__( 'No media selected', 'redux-framework' ), |
|
| 90 | - 'readonly' => true, |
|
| 91 | - 'class' => '', |
|
| 92 | - 'filter' => array( |
|
| 93 | - 'grayscale' => false, |
|
| 94 | - 'blur' => false, |
|
| 95 | - 'sepia' => false, |
|
| 96 | - 'saturate' => false, |
|
| 97 | - 'opacity' => false, |
|
| 98 | - 'brightness' => false, |
|
| 99 | - 'contrast' => false, |
|
| 100 | - 'hue-rotate' => false, |
|
| 101 | - 'invert' => false, |
|
| 102 | - ), |
|
| 103 | - ); |
|
| 104 | - |
|
| 105 | - $this->field = Redux_Functions::parse_args( $this->field, $defaults ); |
|
| 106 | - |
|
| 107 | - if ( false === $this->field['mode'] ) { |
|
| 108 | - $this->field['mode'] = 0; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - include_once Redux_Core::$dir . 'inc/lib/image-filters/class-redux-image-filters.php'; |
|
| 112 | - if ( in_array( true, $this->field['filter'], true ) ) { |
|
| 113 | - $this->filters_enabled = true; |
|
| 114 | - include_once Redux_Core::$dir . 'inc/lib/image-filters/class-redux-image-filters.php'; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Field Render Function. |
|
| 120 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 121 | - * |
|
| 122 | - * @since 1.0.0 |
|
| 123 | - * @access public |
|
| 124 | - * @return void |
|
| 125 | - */ |
|
| 126 | - public function render() { |
|
| 127 | - if ( ! isset( $this->field['library_filter'] ) ) { |
|
| 128 | - $lib_filter = ''; |
|
| 129 | - } else { |
|
| 130 | - if ( ! is_array( $this->field['library_filter'] ) ) { |
|
| 131 | - $this->field['library_filter'] = array( $this->field['library_filter'] ); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - $mime_types = get_allowed_mime_types(); |
|
| 135 | - |
|
| 136 | - $lib_array = $this->field['library_filter']; |
|
| 137 | - |
|
| 138 | - $json_arr = array(); |
|
| 139 | - |
|
| 140 | - // Enum mime types. |
|
| 141 | - foreach ( $mime_types as $ext => $type ) { |
|
| 142 | - if ( strpos( $ext, '|' ) ) { |
|
| 143 | - $ex_arr = explode( '|', $ext ); |
|
| 144 | - |
|
| 145 | - foreach ( $ex_arr as $ext ) { |
|
| 146 | - if ( in_array( $ext, $lib_array, true ) ) { |
|
| 147 | - $json_arr[ $ext ] = $type; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - } elseif ( in_array( $ext, $lib_array, true ) ) { |
|
| 151 | - $json_arr[ $ext ] = $type; |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - $lib_filter = rawurlencode( wp_json_encode( $json_arr ) ); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - if ( empty( $this->value ) && ! empty( $this->field['default'] ) ) { // If there are standard values and value is empty. |
|
| 159 | - if ( is_array( $this->field['default'] ) ) { |
|
| 160 | - if ( ! empty( $this->field['default']['id'] ) ) { |
|
| 161 | - $this->value['id'] = $this->field['default']['id']; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - if ( ! empty( $this->field['default']['url'] ) ) { |
|
| 165 | - $this->value['url'] = $this->field['default']['url']; |
|
| 166 | - } |
|
| 167 | - } elseif ( is_numeric( $this->field['default'] ) ) { |
|
| 168 | - // Check if it's an attachment ID. |
|
| 169 | - $this->value['id'] = $this->field['default']; |
|
| 170 | - } else { // Must be a URL. |
|
| 171 | - $this->value['url'] = $this->field['default']; |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - if ( empty( $this->value['url'] ) && ! empty( $this->value['id'] ) ) { |
|
| 176 | - $img = wp_get_attachment_image_src( $this->value['id'], 'full' ); |
|
| 177 | - $this->value['url'] = $img[0]; |
|
| 178 | - $this->value['width'] = $img[1]; |
|
| 179 | - $this->value['height'] = $img[2]; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - $hide = 'hide '; |
|
| 183 | - |
|
| 184 | - if ( false === $this->field['preview'] ) { |
|
| 185 | - $this->field['class'] .= ' noPreview'; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - if ( ( ! empty( $this->field['url'] ) && true === $this->field['url'] ) || false === $this->field['preview'] ) { |
|
| 189 | - $hide = ''; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - $read_only = ''; |
|
| 193 | - if ( $this->field['readonly'] ) { |
|
| 194 | - $read_only = ' readonly="readonly"'; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - echo '<input placeholder="' . esc_attr( $this->field['placeholder'] ) . '" type="text" class="' . esc_attr( $hide ) . 'upload large-text ' . esc_attr( $this->field['class'] ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[url]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][url]" value="' . esc_attr( $this->value['url'] ) . '"' . esc_html( $read_only ) . '/>'; |
|
| 198 | - echo '<input type="hidden" class="data" data-preview-size="' . esc_attr( $this->field['preview_size'] ) . '" data-mode="' . esc_attr( $this->field['mode'] ) . '" />'; |
|
| 199 | - echo '<input type="hidden" class="library-filter" data-lib-filter="' . $lib_filter . '" />'; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 200 | - echo '<input type="hidden" class="upload-id ' . esc_attr( $this->field['class'] ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[id]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][id]" value="' . esc_attr( $this->value['id'] ) . '" />'; |
|
| 201 | - echo '<input type="hidden" class="upload-height" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[height]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][height]" value="' . esc_attr( $this->value['height'] ) . '" />'; |
|
| 202 | - echo '<input type="hidden" class="upload-width" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[width]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][width]" value="' . esc_attr( $this->value['width'] ) . '" />'; |
|
| 203 | - echo '<input type="hidden" class="upload-thumbnail" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[thumbnail]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][thumbnail]" value="' . esc_attr( $this->value['thumbnail'] ) . '" />'; |
|
| 204 | - |
|
| 205 | - // Preview. |
|
| 206 | - $hide = ''; |
|
| 207 | - |
|
| 208 | - if ( ( false === $this->field['preview'] ) || empty( $this->value['url'] ) ) { |
|
| 209 | - $hide .= 'display:none;'; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - if ( empty( $this->value['thumbnail'] ) && ! empty( $this->value['url'] ) ) { // Just in case. |
|
| 213 | - if ( ! empty( $this->value['id'] ) ) { |
|
| 214 | - $image = wp_get_attachment_image_src( $this->value['id'], array( 150, 150 ) ); |
|
| 215 | - |
|
| 216 | - if ( empty( $image[0] ) ) { |
|
| 217 | - $this->value['thumbnail'] = $this->value['url']; |
|
| 218 | - } else { |
|
| 219 | - $this->value['thumbnail'] = $image[0]; |
|
| 220 | - } |
|
| 221 | - } else { |
|
| 222 | - $this->value['thumbnail'] = $this->value['url']; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - $css = $this->get_filter_css( $this->value['filter'] ); |
|
| 227 | - |
|
| 228 | - $alt = wp_prepare_attachment_for_js( $this->value['id'] ); |
|
| 229 | - $alt = $alt['alt'] ?? ''; |
|
| 230 | - |
|
| 231 | - echo '<div class="screenshot" style="' . esc_attr( $hide ) . '">'; |
|
| 232 | - echo '<a class="of-uploaded-image" href="' . esc_url( $this->value['url'] ) . '" target="_blank">'; |
|
| 233 | - echo '<img class="redux-option-image" id="image_' . esc_attr( $this->field['id'] ) . '" src="' . esc_url( $this->value['thumbnail'] ) . '" alt="' . esc_attr( $alt ) . '" target="_blank" rel="external" style="' . $css . '" />'; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 234 | - echo '</a>'; |
|
| 235 | - echo '</div>'; |
|
| 236 | - |
|
| 237 | - // Upload controls DIV. |
|
| 238 | - echo '<div class="upload_button_div">'; |
|
| 239 | - |
|
| 240 | - // If the user has WP3.5+ show upload/remove button. |
|
| 241 | - echo '<span class="button media_upload_button" id="' . esc_attr( $this->field['id'] ) . '-media">' . esc_html__( 'Upload', 'redux-framework' ) . '</span>'; |
|
| 242 | - |
|
| 243 | - $hide = ''; |
|
| 244 | - if ( empty( $this->value['url'] ) || '' === $this->value['url'] ) { |
|
| 245 | - $hide = ' hide'; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - echo '<span class="button remove-image' . esc_attr( $hide ) . '" id="reset_' . esc_attr( $this->field['id'] ) . '" rel="' . esc_attr( $this->field['id'] ) . '">' . esc_html__( 'Remove', 'redux-framework' ) . '</span>'; |
|
| 249 | - echo '</div>'; |
|
| 250 | - |
|
| 251 | - if ( $this->filters_enabled ) { |
|
| 252 | - $data = array( |
|
| 253 | - 'parent' => $this->parent, |
|
| 254 | - 'field' => $this->field, |
|
| 255 | - 'value' => $this->value, |
|
| 256 | - 'mode' => 'media', |
|
| 257 | - ); |
|
| 258 | - |
|
| 259 | - echo Redux_Image_Filters::render( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Do enqueue for each field instance. |
|
| 265 | - * |
|
| 266 | - * @return void |
|
| 267 | - */ |
|
| 268 | - public function always_enqueue() { |
|
| 269 | - Redux_Image_Filters::enqueue( $this->filters_enabled ); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Enqueue Function. |
|
| 274 | - * If this field requires any scripts, or CSS define this function and register/enqueue the scripts/css |
|
| 275 | - * |
|
| 276 | - * @since 1.0.0 |
|
| 277 | - * @access public |
|
| 278 | - * @return void |
|
| 279 | - */ |
|
| 280 | - public function enqueue() { |
|
| 281 | - if ( function_exists( 'wp_enqueue_media' ) ) { |
|
| 282 | - wp_enqueue_media(); |
|
| 283 | - } else { |
|
| 284 | - wp_enqueue_script( 'media-upload' ); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - wp_enqueue_script( |
|
| 288 | - 'redux-field-media', |
|
| 289 | - Redux_Core::$url . 'assets/js/media/media' . Redux_Functions::is_min() . '.js', |
|
| 290 | - array( 'jquery', 'redux-js' ), |
|
| 291 | - $this->timestamp, |
|
| 292 | - true |
|
| 293 | - ); |
|
| 294 | - |
|
| 295 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 296 | - wp_enqueue_style( 'redux-field-media' ); |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Compile CSS styles for output. |
|
| 302 | - * |
|
| 303 | - * @param string $data CSS data. |
|
| 304 | - * |
|
| 305 | - * @return string|null |
|
| 306 | - */ |
|
| 307 | - public function css_style( $data ): string { |
|
| 308 | - $data = (array) $data; |
|
| 309 | - |
|
| 310 | - if ( isset( $data['filter'] ) ) { |
|
| 311 | - return $this->get_filter_css( $data['filter'] ); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - return ''; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * Get filter CSS. |
|
| 319 | - * |
|
| 320 | - * @param array $data Data. |
|
| 321 | - * |
|
| 322 | - * @return string |
|
| 323 | - */ |
|
| 324 | - private function get_filter_css( array $data ): string { |
|
| 325 | - $css = ''; |
|
| 326 | - |
|
| 327 | - foreach ( $data as $filter => $values ) { |
|
| 328 | - $checked = filter_var( $values['checked'], FILTER_VALIDATE_BOOLEAN ); |
|
| 329 | - |
|
| 330 | - if ( true === $checked ) { |
|
| 331 | - $unit = Redux_Image_Filters::get_filter_unit( $filter ); |
|
| 332 | - |
|
| 333 | - if ( '°' === $unit ) { |
|
| 334 | - $unit = 'deg'; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - $css .= ' ' . $filter . '(' . $values['value'] . $unit . ')'; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - if ( '' !== $css ) { |
|
| 342 | - return 'filter:' . $css . ';-webkit-filter:' . $css . ';'; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - return ''; |
|
| 346 | - } |
|
| 347 | - } |
|
| 15 | + /** |
|
| 16 | + * Main Redux_media class |
|
| 17 | + * |
|
| 18 | + * @since 1.0.0 |
|
| 19 | + */ |
|
| 20 | + class Redux_Media extends Redux_Field { |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Flag to filter file types. |
|
| 24 | + * |
|
| 25 | + * @var bool $filters_enabled . |
|
| 26 | + */ |
|
| 27 | + private $filters_enabled = false; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Set field and value defaults. |
|
| 31 | + */ |
|
| 32 | + public function set_defaults() { |
|
| 33 | + // No errors please. |
|
| 34 | + $defaults = array( |
|
| 35 | + 'id' => '', |
|
| 36 | + 'url' => '', |
|
| 37 | + 'width' => '', |
|
| 38 | + 'height' => '', |
|
| 39 | + 'thumbnail' => '', |
|
| 40 | + 'filter' => array( |
|
| 41 | + 'grayscale' => array( |
|
| 42 | + 'checked' => false, |
|
| 43 | + 'value' => 0, |
|
| 44 | + ), |
|
| 45 | + 'blur' => array( |
|
| 46 | + 'checked' => false, |
|
| 47 | + 'value' => 0, |
|
| 48 | + ), |
|
| 49 | + 'sepia' => array( |
|
| 50 | + 'checked' => false, |
|
| 51 | + 'value' => 0, |
|
| 52 | + ), |
|
| 53 | + 'saturate' => array( |
|
| 54 | + 'checked' => false, |
|
| 55 | + 'value' => 1, |
|
| 56 | + ), |
|
| 57 | + 'opacity' => array( |
|
| 58 | + 'checked' => false, |
|
| 59 | + 'value' => 1, |
|
| 60 | + ), |
|
| 61 | + 'brightness' => array( |
|
| 62 | + 'checked' => false, |
|
| 63 | + 'value' => 100, |
|
| 64 | + ), |
|
| 65 | + 'contrast' => array( |
|
| 66 | + 'checked' => false, |
|
| 67 | + 'value' => 100, |
|
| 68 | + ), |
|
| 69 | + 'hue-rotate' => array( |
|
| 70 | + 'checked' => false, |
|
| 71 | + 'value' => 0, |
|
| 72 | + ), |
|
| 73 | + 'invert' => array( |
|
| 74 | + 'checked' => false, |
|
| 75 | + 'value' => 0, |
|
| 76 | + ), |
|
| 77 | + ), |
|
| 78 | + ); |
|
| 79 | + |
|
| 80 | + // Since value sub-arrays do not get parsed in wp_parse_args! |
|
| 81 | + $this->value = Redux_Functions::parse_args( $this->value, $defaults ); |
|
| 82 | + |
|
| 83 | + $defaults = array( |
|
| 84 | + 'mode' => 'image', |
|
| 85 | + 'preview' => true, |
|
| 86 | + 'preview_size' => 'thumbnail', |
|
| 87 | + 'url' => true, |
|
| 88 | + 'alt' => '', |
|
| 89 | + 'placeholder' => esc_html__( 'No media selected', 'redux-framework' ), |
|
| 90 | + 'readonly' => true, |
|
| 91 | + 'class' => '', |
|
| 92 | + 'filter' => array( |
|
| 93 | + 'grayscale' => false, |
|
| 94 | + 'blur' => false, |
|
| 95 | + 'sepia' => false, |
|
| 96 | + 'saturate' => false, |
|
| 97 | + 'opacity' => false, |
|
| 98 | + 'brightness' => false, |
|
| 99 | + 'contrast' => false, |
|
| 100 | + 'hue-rotate' => false, |
|
| 101 | + 'invert' => false, |
|
| 102 | + ), |
|
| 103 | + ); |
|
| 104 | + |
|
| 105 | + $this->field = Redux_Functions::parse_args( $this->field, $defaults ); |
|
| 106 | + |
|
| 107 | + if ( false === $this->field['mode'] ) { |
|
| 108 | + $this->field['mode'] = 0; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + include_once Redux_Core::$dir . 'inc/lib/image-filters/class-redux-image-filters.php'; |
|
| 112 | + if ( in_array( true, $this->field['filter'], true ) ) { |
|
| 113 | + $this->filters_enabled = true; |
|
| 114 | + include_once Redux_Core::$dir . 'inc/lib/image-filters/class-redux-image-filters.php'; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Field Render Function. |
|
| 120 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 121 | + * |
|
| 122 | + * @since 1.0.0 |
|
| 123 | + * @access public |
|
| 124 | + * @return void |
|
| 125 | + */ |
|
| 126 | + public function render() { |
|
| 127 | + if ( ! isset( $this->field['library_filter'] ) ) { |
|
| 128 | + $lib_filter = ''; |
|
| 129 | + } else { |
|
| 130 | + if ( ! is_array( $this->field['library_filter'] ) ) { |
|
| 131 | + $this->field['library_filter'] = array( $this->field['library_filter'] ); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + $mime_types = get_allowed_mime_types(); |
|
| 135 | + |
|
| 136 | + $lib_array = $this->field['library_filter']; |
|
| 137 | + |
|
| 138 | + $json_arr = array(); |
|
| 139 | + |
|
| 140 | + // Enum mime types. |
|
| 141 | + foreach ( $mime_types as $ext => $type ) { |
|
| 142 | + if ( strpos( $ext, '|' ) ) { |
|
| 143 | + $ex_arr = explode( '|', $ext ); |
|
| 144 | + |
|
| 145 | + foreach ( $ex_arr as $ext ) { |
|
| 146 | + if ( in_array( $ext, $lib_array, true ) ) { |
|
| 147 | + $json_arr[ $ext ] = $type; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + } elseif ( in_array( $ext, $lib_array, true ) ) { |
|
| 151 | + $json_arr[ $ext ] = $type; |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + $lib_filter = rawurlencode( wp_json_encode( $json_arr ) ); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + if ( empty( $this->value ) && ! empty( $this->field['default'] ) ) { // If there are standard values and value is empty. |
|
| 159 | + if ( is_array( $this->field['default'] ) ) { |
|
| 160 | + if ( ! empty( $this->field['default']['id'] ) ) { |
|
| 161 | + $this->value['id'] = $this->field['default']['id']; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + if ( ! empty( $this->field['default']['url'] ) ) { |
|
| 165 | + $this->value['url'] = $this->field['default']['url']; |
|
| 166 | + } |
|
| 167 | + } elseif ( is_numeric( $this->field['default'] ) ) { |
|
| 168 | + // Check if it's an attachment ID. |
|
| 169 | + $this->value['id'] = $this->field['default']; |
|
| 170 | + } else { // Must be a URL. |
|
| 171 | + $this->value['url'] = $this->field['default']; |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + if ( empty( $this->value['url'] ) && ! empty( $this->value['id'] ) ) { |
|
| 176 | + $img = wp_get_attachment_image_src( $this->value['id'], 'full' ); |
|
| 177 | + $this->value['url'] = $img[0]; |
|
| 178 | + $this->value['width'] = $img[1]; |
|
| 179 | + $this->value['height'] = $img[2]; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + $hide = 'hide '; |
|
| 183 | + |
|
| 184 | + if ( false === $this->field['preview'] ) { |
|
| 185 | + $this->field['class'] .= ' noPreview'; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + if ( ( ! empty( $this->field['url'] ) && true === $this->field['url'] ) || false === $this->field['preview'] ) { |
|
| 189 | + $hide = ''; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + $read_only = ''; |
|
| 193 | + if ( $this->field['readonly'] ) { |
|
| 194 | + $read_only = ' readonly="readonly"'; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + echo '<input placeholder="' . esc_attr( $this->field['placeholder'] ) . '" type="text" class="' . esc_attr( $hide ) . 'upload large-text ' . esc_attr( $this->field['class'] ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[url]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][url]" value="' . esc_attr( $this->value['url'] ) . '"' . esc_html( $read_only ) . '/>'; |
|
| 198 | + echo '<input type="hidden" class="data" data-preview-size="' . esc_attr( $this->field['preview_size'] ) . '" data-mode="' . esc_attr( $this->field['mode'] ) . '" />'; |
|
| 199 | + echo '<input type="hidden" class="library-filter" data-lib-filter="' . $lib_filter . '" />'; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 200 | + echo '<input type="hidden" class="upload-id ' . esc_attr( $this->field['class'] ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[id]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][id]" value="' . esc_attr( $this->value['id'] ) . '" />'; |
|
| 201 | + echo '<input type="hidden" class="upload-height" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[height]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][height]" value="' . esc_attr( $this->value['height'] ) . '" />'; |
|
| 202 | + echo '<input type="hidden" class="upload-width" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[width]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][width]" value="' . esc_attr( $this->value['width'] ) . '" />'; |
|
| 203 | + echo '<input type="hidden" class="upload-thumbnail" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[thumbnail]" id="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][thumbnail]" value="' . esc_attr( $this->value['thumbnail'] ) . '" />'; |
|
| 204 | + |
|
| 205 | + // Preview. |
|
| 206 | + $hide = ''; |
|
| 207 | + |
|
| 208 | + if ( ( false === $this->field['preview'] ) || empty( $this->value['url'] ) ) { |
|
| 209 | + $hide .= 'display:none;'; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + if ( empty( $this->value['thumbnail'] ) && ! empty( $this->value['url'] ) ) { // Just in case. |
|
| 213 | + if ( ! empty( $this->value['id'] ) ) { |
|
| 214 | + $image = wp_get_attachment_image_src( $this->value['id'], array( 150, 150 ) ); |
|
| 215 | + |
|
| 216 | + if ( empty( $image[0] ) ) { |
|
| 217 | + $this->value['thumbnail'] = $this->value['url']; |
|
| 218 | + } else { |
|
| 219 | + $this->value['thumbnail'] = $image[0]; |
|
| 220 | + } |
|
| 221 | + } else { |
|
| 222 | + $this->value['thumbnail'] = $this->value['url']; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + $css = $this->get_filter_css( $this->value['filter'] ); |
|
| 227 | + |
|
| 228 | + $alt = wp_prepare_attachment_for_js( $this->value['id'] ); |
|
| 229 | + $alt = $alt['alt'] ?? ''; |
|
| 230 | + |
|
| 231 | + echo '<div class="screenshot" style="' . esc_attr( $hide ) . '">'; |
|
| 232 | + echo '<a class="of-uploaded-image" href="' . esc_url( $this->value['url'] ) . '" target="_blank">'; |
|
| 233 | + echo '<img class="redux-option-image" id="image_' . esc_attr( $this->field['id'] ) . '" src="' . esc_url( $this->value['thumbnail'] ) . '" alt="' . esc_attr( $alt ) . '" target="_blank" rel="external" style="' . $css . '" />'; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 234 | + echo '</a>'; |
|
| 235 | + echo '</div>'; |
|
| 236 | + |
|
| 237 | + // Upload controls DIV. |
|
| 238 | + echo '<div class="upload_button_div">'; |
|
| 239 | + |
|
| 240 | + // If the user has WP3.5+ show upload/remove button. |
|
| 241 | + echo '<span class="button media_upload_button" id="' . esc_attr( $this->field['id'] ) . '-media">' . esc_html__( 'Upload', 'redux-framework' ) . '</span>'; |
|
| 242 | + |
|
| 243 | + $hide = ''; |
|
| 244 | + if ( empty( $this->value['url'] ) || '' === $this->value['url'] ) { |
|
| 245 | + $hide = ' hide'; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + echo '<span class="button remove-image' . esc_attr( $hide ) . '" id="reset_' . esc_attr( $this->field['id'] ) . '" rel="' . esc_attr( $this->field['id'] ) . '">' . esc_html__( 'Remove', 'redux-framework' ) . '</span>'; |
|
| 249 | + echo '</div>'; |
|
| 250 | + |
|
| 251 | + if ( $this->filters_enabled ) { |
|
| 252 | + $data = array( |
|
| 253 | + 'parent' => $this->parent, |
|
| 254 | + 'field' => $this->field, |
|
| 255 | + 'value' => $this->value, |
|
| 256 | + 'mode' => 'media', |
|
| 257 | + ); |
|
| 258 | + |
|
| 259 | + echo Redux_Image_Filters::render( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Do enqueue for each field instance. |
|
| 265 | + * |
|
| 266 | + * @return void |
|
| 267 | + */ |
|
| 268 | + public function always_enqueue() { |
|
| 269 | + Redux_Image_Filters::enqueue( $this->filters_enabled ); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Enqueue Function. |
|
| 274 | + * If this field requires any scripts, or CSS define this function and register/enqueue the scripts/css |
|
| 275 | + * |
|
| 276 | + * @since 1.0.0 |
|
| 277 | + * @access public |
|
| 278 | + * @return void |
|
| 279 | + */ |
|
| 280 | + public function enqueue() { |
|
| 281 | + if ( function_exists( 'wp_enqueue_media' ) ) { |
|
| 282 | + wp_enqueue_media(); |
|
| 283 | + } else { |
|
| 284 | + wp_enqueue_script( 'media-upload' ); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + wp_enqueue_script( |
|
| 288 | + 'redux-field-media', |
|
| 289 | + Redux_Core::$url . 'assets/js/media/media' . Redux_Functions::is_min() . '.js', |
|
| 290 | + array( 'jquery', 'redux-js' ), |
|
| 291 | + $this->timestamp, |
|
| 292 | + true |
|
| 293 | + ); |
|
| 294 | + |
|
| 295 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 296 | + wp_enqueue_style( 'redux-field-media' ); |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Compile CSS styles for output. |
|
| 302 | + * |
|
| 303 | + * @param string $data CSS data. |
|
| 304 | + * |
|
| 305 | + * @return string|null |
|
| 306 | + */ |
|
| 307 | + public function css_style( $data ): string { |
|
| 308 | + $data = (array) $data; |
|
| 309 | + |
|
| 310 | + if ( isset( $data['filter'] ) ) { |
|
| 311 | + return $this->get_filter_css( $data['filter'] ); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + return ''; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * Get filter CSS. |
|
| 319 | + * |
|
| 320 | + * @param array $data Data. |
|
| 321 | + * |
|
| 322 | + * @return string |
|
| 323 | + */ |
|
| 324 | + private function get_filter_css( array $data ): string { |
|
| 325 | + $css = ''; |
|
| 326 | + |
|
| 327 | + foreach ( $data as $filter => $values ) { |
|
| 328 | + $checked = filter_var( $values['checked'], FILTER_VALIDATE_BOOLEAN ); |
|
| 329 | + |
|
| 330 | + if ( true === $checked ) { |
|
| 331 | + $unit = Redux_Image_Filters::get_filter_unit( $filter ); |
|
| 332 | + |
|
| 333 | + if ( '°' === $unit ) { |
|
| 334 | + $unit = 'deg'; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + $css .= ' ' . $filter . '(' . $values['value'] . $unit . ')'; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + if ( '' !== $css ) { |
|
| 342 | + return 'filter:' . $css . ';-webkit-filter:' . $css . ';'; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + return ''; |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | class_alias( 'Redux_Media', 'ReduxFramework_Media' ); |
@@ -40,8 +40,8 @@ |
||
| 40 | 40 | 'hour-max' => 23, |
| 41 | 41 | 'minute-min' => 0, |
| 42 | 42 | 'minute-max' => 59, |
| 43 | - 'date-min' => - 1, |
|
| 44 | - 'date-max' => - 1, |
|
| 43 | + 'date-min' => -1, |
|
| 44 | + 'date-max' => -1, |
|
| 45 | 45 | ); |
| 46 | 46 | |
| 47 | 47 | $this->field = wp_parse_args( $this->field, $defaults ); |
@@ -12,147 +12,147 @@ discard block |
||
| 12 | 12 | // Don't duplicate me! |
| 13 | 13 | if ( ! class_exists( 'Redux_Datetime', false ) ) { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Class Redux_Datetime |
|
| 17 | - */ |
|
| 18 | - class Redux_Datetime extends Redux_Field { |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Set field defaults. |
|
| 22 | - */ |
|
| 23 | - public function set_defaults() { |
|
| 24 | - $defaults = array( |
|
| 25 | - 'date-format' => 'mm-dd-yy', |
|
| 26 | - 'time-format' => 'hh:mm TT z', |
|
| 27 | - 'split' => false, |
|
| 28 | - 'separator' => ' ', |
|
| 29 | - 'date-picker' => true, |
|
| 30 | - 'time-picker' => true, |
|
| 31 | - 'control-type' => 'slider', |
|
| 32 | - 'num-of-months' => 1, |
|
| 33 | - |
|
| 34 | - // DO NOT CHANGE THESE!!!! |
|
| 35 | - // It will make this file's JavaScript sister |
|
| 36 | - // cry like a deflowered virgin on prom night. |
|
| 37 | - 'timezone-list' => null, |
|
| 38 | - 'timezone' => '0', |
|
| 39 | - 'hour-min' => 0, |
|
| 40 | - 'hour-max' => 23, |
|
| 41 | - 'minute-min' => 0, |
|
| 42 | - 'minute-max' => 59, |
|
| 43 | - 'date-min' => - 1, |
|
| 44 | - 'date-max' => - 1, |
|
| 45 | - ); |
|
| 46 | - |
|
| 47 | - $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Field Render Function. |
|
| 52 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 53 | - * |
|
| 54 | - * @since 1.0.0 |
|
| 55 | - * @access public |
|
| 56 | - * @return void |
|
| 57 | - */ |
|
| 58 | - public function render() { |
|
| 59 | - $num_of_months = $this->field['num-of-months']; |
|
| 60 | - if ( 0 === $num_of_months ) { |
|
| 61 | - $num_of_months = 1; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // Validate min/max values. |
|
| 65 | - $hour_min = $this->field['hour-min']; |
|
| 66 | - $hour_max = $this->field['hour-max']; |
|
| 67 | - $min_min = $this->field['minute-min']; |
|
| 68 | - $min_max = $this->field['minute-max']; |
|
| 69 | - |
|
| 70 | - if ( $hour_min < 0 || $hour_min > 23 ) { |
|
| 71 | - $hour_min = 0; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - if ( $hour_max < 0 || $hour_max > 23 ) { |
|
| 75 | - $hour_max = 23; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - if ( $min_min < 0 || $min_min > 59 ) { |
|
| 79 | - $min_min = 0; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if ( $min_max < 0 || $min_max > 59 ) { |
|
| 83 | - $min_max = 59; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // Validate min date month. |
|
| 87 | - if ( is_array( $this->field['date-min'] ) ) { |
|
| 88 | - if ( isset( $this->field['date-min']['month'] ) ) { |
|
| 89 | - if ( $this->field['date-min']['month'] < 1 || $this->field['date-min']['month'] > 12 ) { |
|
| 90 | - $this->field['date-min']['month'] = 1; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - if ( isset( $this->field['date-min']['day'] ) ) { |
|
| 95 | - if ( $this->field['date-min']['day'] < 1 || $this->field['date-min']['day'] > 31 ) { |
|
| 96 | - $this->field['date-min']['day'] = 1; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // Validate max date month. |
|
| 102 | - if ( is_array( $this->field['date-max'] ) ) { |
|
| 103 | - if ( isset( $this->field['date-max']['month'] ) ) { |
|
| 104 | - if ( $this->field['date-max']['month'] < 1 || $this->field['date-max']['month'] > 12 ) { |
|
| 105 | - $this->field['date-max']['month'] = 1; |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // Validate max date day (imperfect, so we'll just use 31). |
|
| 110 | - if ( isset( $this->field['date-max']['day'] ) ) { |
|
| 111 | - if ( $this->field['date-max']['day'] < 1 || $this->field['date-max']['day'] > 31 ) { |
|
| 112 | - $this->field['date-max']['day'] = 1; |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // Assignment, make it easier to read. |
|
| 118 | - $field_id = $this->field['id']; |
|
| 119 | - $field_name = $this->field['name']; |
|
| 120 | - $split = $this->field['split']; |
|
| 121 | - $control_type = $this->field['control-type']; |
|
| 122 | - |
|
| 123 | - // Sanitize width |
|
| 124 | - // Sanitize default value. |
|
| 125 | - if ( true === $split ) { |
|
| 126 | - if ( ! is_array( $this->value ) ) { |
|
| 127 | - $this->value = array(); |
|
| 128 | - $this->value['time'] = ''; |
|
| 129 | - $this->value['date'] = ''; |
|
| 130 | - } |
|
| 131 | - } elseif ( is_array( $this->value ) ) { |
|
| 132 | - $this->value = ''; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // Dummy check, in case something other than select or slider |
|
| 136 | - // is entered. |
|
| 137 | - switch ( $control_type ) { |
|
| 138 | - case 'select': |
|
| 139 | - case 'slider': |
|
| 140 | - break; |
|
| 141 | - default: |
|
| 142 | - $control_type = 'slider'; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - // Set placeholder based on mode. |
|
| 146 | - if ( true === $split ) { |
|
| 147 | - $date_placeholder = $this->field['placeholder']['date'] ?? esc_html__( 'Date', 'redux-framework' ); |
|
| 148 | - $time_placeholder = $this->field['placeholder']['time'] ?? esc_html__( 'Time', 'redux-framework' ); |
|
| 149 | - } else { |
|
| 150 | - $date_placeholder = $this->field['placeholder'] ?? esc_html__( 'Date / Time', 'redux-framework' ); |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // Output defaults to div, so JS can read it. |
|
| 154 | - // Broken up for readability; coz I'm the one who has to debug it! |
|
| 155 | - echo '<div id="' . esc_attr( $field_id ) . '" class="redux-datetime-container" |
|
| 15 | + /** |
|
| 16 | + * Class Redux_Datetime |
|
| 17 | + */ |
|
| 18 | + class Redux_Datetime extends Redux_Field { |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Set field defaults. |
|
| 22 | + */ |
|
| 23 | + public function set_defaults() { |
|
| 24 | + $defaults = array( |
|
| 25 | + 'date-format' => 'mm-dd-yy', |
|
| 26 | + 'time-format' => 'hh:mm TT z', |
|
| 27 | + 'split' => false, |
|
| 28 | + 'separator' => ' ', |
|
| 29 | + 'date-picker' => true, |
|
| 30 | + 'time-picker' => true, |
|
| 31 | + 'control-type' => 'slider', |
|
| 32 | + 'num-of-months' => 1, |
|
| 33 | + |
|
| 34 | + // DO NOT CHANGE THESE!!!! |
|
| 35 | + // It will make this file's JavaScript sister |
|
| 36 | + // cry like a deflowered virgin on prom night. |
|
| 37 | + 'timezone-list' => null, |
|
| 38 | + 'timezone' => '0', |
|
| 39 | + 'hour-min' => 0, |
|
| 40 | + 'hour-max' => 23, |
|
| 41 | + 'minute-min' => 0, |
|
| 42 | + 'minute-max' => 59, |
|
| 43 | + 'date-min' => - 1, |
|
| 44 | + 'date-max' => - 1, |
|
| 45 | + ); |
|
| 46 | + |
|
| 47 | + $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Field Render Function. |
|
| 52 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 53 | + * |
|
| 54 | + * @since 1.0.0 |
|
| 55 | + * @access public |
|
| 56 | + * @return void |
|
| 57 | + */ |
|
| 58 | + public function render() { |
|
| 59 | + $num_of_months = $this->field['num-of-months']; |
|
| 60 | + if ( 0 === $num_of_months ) { |
|
| 61 | + $num_of_months = 1; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // Validate min/max values. |
|
| 65 | + $hour_min = $this->field['hour-min']; |
|
| 66 | + $hour_max = $this->field['hour-max']; |
|
| 67 | + $min_min = $this->field['minute-min']; |
|
| 68 | + $min_max = $this->field['minute-max']; |
|
| 69 | + |
|
| 70 | + if ( $hour_min < 0 || $hour_min > 23 ) { |
|
| 71 | + $hour_min = 0; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + if ( $hour_max < 0 || $hour_max > 23 ) { |
|
| 75 | + $hour_max = 23; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + if ( $min_min < 0 || $min_min > 59 ) { |
|
| 79 | + $min_min = 0; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if ( $min_max < 0 || $min_max > 59 ) { |
|
| 83 | + $min_max = 59; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // Validate min date month. |
|
| 87 | + if ( is_array( $this->field['date-min'] ) ) { |
|
| 88 | + if ( isset( $this->field['date-min']['month'] ) ) { |
|
| 89 | + if ( $this->field['date-min']['month'] < 1 || $this->field['date-min']['month'] > 12 ) { |
|
| 90 | + $this->field['date-min']['month'] = 1; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + if ( isset( $this->field['date-min']['day'] ) ) { |
|
| 95 | + if ( $this->field['date-min']['day'] < 1 || $this->field['date-min']['day'] > 31 ) { |
|
| 96 | + $this->field['date-min']['day'] = 1; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // Validate max date month. |
|
| 102 | + if ( is_array( $this->field['date-max'] ) ) { |
|
| 103 | + if ( isset( $this->field['date-max']['month'] ) ) { |
|
| 104 | + if ( $this->field['date-max']['month'] < 1 || $this->field['date-max']['month'] > 12 ) { |
|
| 105 | + $this->field['date-max']['month'] = 1; |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // Validate max date day (imperfect, so we'll just use 31). |
|
| 110 | + if ( isset( $this->field['date-max']['day'] ) ) { |
|
| 111 | + if ( $this->field['date-max']['day'] < 1 || $this->field['date-max']['day'] > 31 ) { |
|
| 112 | + $this->field['date-max']['day'] = 1; |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // Assignment, make it easier to read. |
|
| 118 | + $field_id = $this->field['id']; |
|
| 119 | + $field_name = $this->field['name']; |
|
| 120 | + $split = $this->field['split']; |
|
| 121 | + $control_type = $this->field['control-type']; |
|
| 122 | + |
|
| 123 | + // Sanitize width |
|
| 124 | + // Sanitize default value. |
|
| 125 | + if ( true === $split ) { |
|
| 126 | + if ( ! is_array( $this->value ) ) { |
|
| 127 | + $this->value = array(); |
|
| 128 | + $this->value['time'] = ''; |
|
| 129 | + $this->value['date'] = ''; |
|
| 130 | + } |
|
| 131 | + } elseif ( is_array( $this->value ) ) { |
|
| 132 | + $this->value = ''; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // Dummy check, in case something other than select or slider |
|
| 136 | + // is entered. |
|
| 137 | + switch ( $control_type ) { |
|
| 138 | + case 'select': |
|
| 139 | + case 'slider': |
|
| 140 | + break; |
|
| 141 | + default: |
|
| 142 | + $control_type = 'slider'; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // Set placeholder based on mode. |
|
| 146 | + if ( true === $split ) { |
|
| 147 | + $date_placeholder = $this->field['placeholder']['date'] ?? esc_html__( 'Date', 'redux-framework' ); |
|
| 148 | + $time_placeholder = $this->field['placeholder']['time'] ?? esc_html__( 'Time', 'redux-framework' ); |
|
| 149 | + } else { |
|
| 150 | + $date_placeholder = $this->field['placeholder'] ?? esc_html__( 'Date / Time', 'redux-framework' ); |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // Output defaults to div, so JS can read it. |
|
| 154 | + // Broken up for readability; coz I'm the one who has to debug it! |
|
| 155 | + echo '<div id="' . esc_attr( $field_id ) . '" class="redux-datetime-container" |
|
| 156 | 156 | data-dev-mode="' . esc_attr( $this->parent->args['dev_mode'] ) . '" |
| 157 | 157 | data-version="' . esc_attr( Redux_Extension_Datetime::$version ) . '" |
| 158 | 158 | data-id="' . esc_attr( $field_id ) . '" |
@@ -174,11 +174,11 @@ discard block |
||
| 174 | 174 | data-time-format="' . esc_attr( $this->field['time-format'] ) . '" |
| 175 | 175 | data-date-format="' . esc_attr( $this->field['date-format'] ) . '">'; |
| 176 | 176 | |
| 177 | - // If split mode is on, output two text boxes. |
|
| 178 | - if ( true === $split ) { |
|
| 179 | - echo '<div class="redux-date-input input_wrapper">'; |
|
| 180 | - echo '<label for="' . esc_attr( $field_id ) . '-date" class="redux-date-input-label">' . esc_html( $date_placeholder ) . '</label>'; |
|
| 181 | - echo ' <input |
|
| 177 | + // If split mode is on, output two text boxes. |
|
| 178 | + if ( true === $split ) { |
|
| 179 | + echo '<div class="redux-date-input input_wrapper">'; |
|
| 180 | + echo '<label for="' . esc_attr( $field_id ) . '-date" class="redux-date-input-label">' . esc_html( $date_placeholder ) . '</label>'; |
|
| 181 | + echo ' <input |
|
| 182 | 182 | data-id="' . esc_attr( $field_id ) . '" |
| 183 | 183 | type="text" |
| 184 | 184 | id="' . esc_attr( $field_id ) . '-date" |
@@ -187,11 +187,11 @@ discard block |
||
| 187 | 187 | value="' . esc_attr( $this->value['date'] ) . '" |
| 188 | 188 | class="redux-date-picker ' . esc_attr( $this->field['class'] ) . '" /> '; |
| 189 | 189 | |
| 190 | - echo '</div>'; |
|
| 190 | + echo '</div>'; |
|
| 191 | 191 | |
| 192 | - echo '<div class="redux-time-input input_wrapper">'; |
|
| 193 | - echo '<label for="' . esc_attr( $field_id ) . '-time" class="redux-time-input-label">' . esc_html( $time_placeholder ) . '</label>'; |
|
| 194 | - echo ' <input |
|
| 192 | + echo '<div class="redux-time-input input_wrapper">'; |
|
| 193 | + echo '<label for="' . esc_attr( $field_id ) . '-time" class="redux-time-input-label">' . esc_html( $time_placeholder ) . '</label>'; |
|
| 194 | + echo ' <input |
|
| 195 | 195 | data-id="' . esc_attr( $field_id ) . '" |
| 196 | 196 | type="text" |
| 197 | 197 | id="' . esc_attr( $field_id ) . '-time" |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | value="' . esc_attr( $this->value['time'] ) . '" |
| 201 | 201 | class="redux-time-picker ' . esc_attr( $this->field['class'] ) . '" />'; |
| 202 | 202 | |
| 203 | - // Otherwise, just one. |
|
| 204 | - } else { |
|
| 205 | - echo '<div class="redux-datetime-input single_wrapper">'; |
|
| 206 | - echo '<label for="' . esc_attr( $field_id ) . '-date" class="redux-datetime-input-label">' . esc_attr( $date_placeholder ) . '</label>'; |
|
| 207 | - echo ' <input |
|
| 203 | + // Otherwise, just one. |
|
| 204 | + } else { |
|
| 205 | + echo '<div class="redux-datetime-input single_wrapper">'; |
|
| 206 | + echo '<label for="' . esc_attr( $field_id ) . '-date" class="redux-datetime-input-label">' . esc_attr( $date_placeholder ) . '</label>'; |
|
| 207 | + echo ' <input |
|
| 208 | 208 | data-id="' . esc_attr( $field_id ) . '" |
| 209 | 209 | type="text" |
| 210 | 210 | id="' . esc_attr( $field_id ) . '-date" |
@@ -213,63 +213,63 @@ discard block |
||
| 213 | 213 | value="' . esc_attr( $this->value ) . '" |
| 214 | 214 | class="redux-date-picker ' . esc_attr( $this->field['class'] ) . '" />'; |
| 215 | 215 | |
| 216 | - } |
|
| 217 | - |
|
| 218 | - echo '</div>'; |
|
| 219 | - |
|
| 220 | - // Close da div, main! |
|
| 221 | - echo '</div>'; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Enqueue Function. |
|
| 226 | - * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 227 | - * |
|
| 228 | - * @since 1.0.0 |
|
| 229 | - * @access public |
|
| 230 | - * @return void |
|
| 231 | - */ |
|
| 232 | - public function enqueue() { |
|
| 233 | - $min = Redux_Functions::is_min(); |
|
| 234 | - |
|
| 235 | - wp_enqueue_script( |
|
| 236 | - 'redux-datetime-slider', |
|
| 237 | - $this->url . 'vendor/jquery-ui-sliderAccess' . $min . '.js', |
|
| 238 | - array( 'jquery' ), |
|
| 239 | - '0.3', |
|
| 240 | - true |
|
| 241 | - ); |
|
| 242 | - |
|
| 243 | - wp_enqueue_script( |
|
| 244 | - 'redux-datetime', |
|
| 245 | - $this->url . 'vendor/jquery-ui-timepicker-addon' . $min . '.js', |
|
| 246 | - array( |
|
| 247 | - 'jquery', |
|
| 248 | - 'jquery-ui-datepicker', |
|
| 249 | - 'jquery-ui-widget', |
|
| 250 | - 'jquery-ui-slider', |
|
| 251 | - 'redux-datetime-slider', |
|
| 252 | - ), |
|
| 253 | - '1.6.3', |
|
| 254 | - true |
|
| 255 | - ); |
|
| 256 | - |
|
| 257 | - wp_enqueue_script( |
|
| 258 | - 'redux-field-datetime', |
|
| 259 | - $this->url . 'redux-datetime' . $min . '.js', |
|
| 260 | - array( 'jquery', 'redux-datetime', 'redux-js' ), |
|
| 261 | - Redux_Extension_Datetime::$version, |
|
| 262 | - true |
|
| 263 | - ); |
|
| 264 | - |
|
| 265 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 266 | - wp_enqueue_style( |
|
| 267 | - 'redux-field-datetime', |
|
| 268 | - $this->url . 'redux-datetime.css', |
|
| 269 | - array(), |
|
| 270 | - Redux_Extension_Datetime::$version, |
|
| 271 | - ); |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - } |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + echo '</div>'; |
|
| 219 | + |
|
| 220 | + // Close da div, main! |
|
| 221 | + echo '</div>'; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Enqueue Function. |
|
| 226 | + * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 227 | + * |
|
| 228 | + * @since 1.0.0 |
|
| 229 | + * @access public |
|
| 230 | + * @return void |
|
| 231 | + */ |
|
| 232 | + public function enqueue() { |
|
| 233 | + $min = Redux_Functions::is_min(); |
|
| 234 | + |
|
| 235 | + wp_enqueue_script( |
|
| 236 | + 'redux-datetime-slider', |
|
| 237 | + $this->url . 'vendor/jquery-ui-sliderAccess' . $min . '.js', |
|
| 238 | + array( 'jquery' ), |
|
| 239 | + '0.3', |
|
| 240 | + true |
|
| 241 | + ); |
|
| 242 | + |
|
| 243 | + wp_enqueue_script( |
|
| 244 | + 'redux-datetime', |
|
| 245 | + $this->url . 'vendor/jquery-ui-timepicker-addon' . $min . '.js', |
|
| 246 | + array( |
|
| 247 | + 'jquery', |
|
| 248 | + 'jquery-ui-datepicker', |
|
| 249 | + 'jquery-ui-widget', |
|
| 250 | + 'jquery-ui-slider', |
|
| 251 | + 'redux-datetime-slider', |
|
| 252 | + ), |
|
| 253 | + '1.6.3', |
|
| 254 | + true |
|
| 255 | + ); |
|
| 256 | + |
|
| 257 | + wp_enqueue_script( |
|
| 258 | + 'redux-field-datetime', |
|
| 259 | + $this->url . 'redux-datetime' . $min . '.js', |
|
| 260 | + array( 'jquery', 'redux-datetime', 'redux-js' ), |
|
| 261 | + Redux_Extension_Datetime::$version, |
|
| 262 | + true |
|
| 263 | + ); |
|
| 264 | + |
|
| 265 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 266 | + wp_enqueue_style( |
|
| 267 | + 'redux-field-datetime', |
|
| 268 | + $this->url . 'redux-datetime.css', |
|
| 269 | + array(), |
|
| 270 | + Redux_Extension_Datetime::$version, |
|
| 271 | + ); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | 275 | } |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @param null $param Who knows. |
| 73 | 73 | */ |
| 74 | 74 | public function register( $widget, $param = null ) { |
| 75 | - $this->widgets[ $widget ] = new $widget( $param ); |
|
| 75 | + $this->widgets[$widget] = new $widget( $param ); |
|
| 76 | 76 | } |
| 77 | 77 | } |
| 78 | 78 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | $title = $instance['title']; |
| 126 | 126 | $redux_options = get_option( $this->parent->args['opt_name'] ); |
| 127 | 127 | |
| 128 | - $social_items = $redux_options[ $this->field_id ]; |
|
| 128 | + $social_items = $redux_options[$this->field_id]; |
|
| 129 | 129 | |
| 130 | 130 | echo $before_widget; // phpcs:ignore WordPress.Security.EscapeOutput |
| 131 | 131 | |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | 'title' => esc_html__( 'Social', 'redux-framework' ), |
| 191 | 191 | ); |
| 192 | 192 | |
| 193 | - $instance = wp_parse_args( (array) $instance, $defaults ); |
|
| 193 | + $instance = wp_parse_args( ( array ) $instance, $defaults ); |
|
| 194 | 194 | ?> |
| 195 | 195 | <p> |
| 196 | 196 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"> |
@@ -13,187 +13,187 @@ discard block |
||
| 13 | 13 | |
| 14 | 14 | if ( ! class_exists( 'Redux_Social_Profiles_Widget' ) ) { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Class Redux_Social_Profiles_Widget |
|
| 18 | - */ |
|
| 19 | - class Redux_Social_Profiles_Widget { |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Field ID. |
|
| 23 | - * |
|
| 24 | - * @var string|null |
|
| 25 | - */ |
|
| 26 | - public ?string $field_id = ''; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * ReduxFramework object pointer. |
|
| 30 | - * |
|
| 31 | - * @var ReduxFramework|null |
|
| 32 | - */ |
|
| 33 | - public ?ReduxFramework $parent = null; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Redux_Social_Profiles_Widget constructor. |
|
| 37 | - * |
|
| 38 | - * @param ReduxFramework $redux ReduxFramework object. |
|
| 39 | - * @param string $field_id Field ID. |
|
| 40 | - */ |
|
| 41 | - public function __construct( ReduxFramework $redux, string $field_id ) { |
|
| 42 | - return; |
|
| 43 | - |
|
| 44 | - $this->parent = $redux; |
|
| 45 | - $this->field_id = $field_id; |
|
| 46 | - |
|
| 47 | - |
|
| 48 | - $this->params = array( |
|
| 49 | - 'parent' => $this->parent, |
|
| 50 | - 'field_id' => $this->field_id, |
|
| 51 | - ); |
|
| 52 | - |
|
| 53 | - add_action( 'widgets_init', array( $this, 'load_widget' ), 0 ); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Load widget |
|
| 58 | - */ |
|
| 59 | - public function load_widget() { |
|
| 60 | - $x = new Extend_WP_Widget_Factory(); |
|
| 61 | - $x->register( 'Redux_Social_Widget_Display', $this->params ); |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Class Extend_WP_Widget_Factory |
|
| 67 | - */ |
|
| 68 | - // phpcs:ignore Generic.Files.OneClassPerFile |
|
| 69 | - class Extend_WP_Widget_Factory extends WP_Widget_Factory { |
|
| 70 | - /** |
|
| 71 | - * Register widget. |
|
| 72 | - * |
|
| 73 | - * @param string|WP_Widget $widget Widget class. |
|
| 74 | - * @param null $param Who knows. |
|
| 75 | - */ |
|
| 76 | - public function register( $widget, $param = null ) { |
|
| 77 | - $this->widgets[ $widget ] = new $widget( $param ); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Class Redux_Social_Widget_Display |
|
| 83 | - */ |
|
| 84 | - class Redux_Social_Widget_Display extends WP_Widget { |
|
| 85 | - |
|
| 86 | - public $show_instance_in_rest = true; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Redux_Social_Widget_Display constructor. |
|
| 90 | - * |
|
| 91 | - * @param array $params Params. |
|
| 92 | - */ |
|
| 93 | - public function __construct( $params ) { |
|
| 94 | - |
|
| 95 | - extract( $params ); // phpcs:ignore WordPress.PHP.DontExtract |
|
| 96 | - |
|
| 97 | - $this->parent = $parent; |
|
| 98 | - $this->field_id = $field_id; |
|
| 99 | - |
|
| 100 | - $widget_ops = array( |
|
| 101 | - 'classname' => 'redux-social-icons-display', |
|
| 102 | - 'description' => __( 'Display social media links', 'redux-framework' ), |
|
| 103 | - 'show_instance_in_rest' => true |
|
| 104 | - ); |
|
| 105 | - |
|
| 106 | - $control_ops = array( |
|
| 107 | - 'width' => 250, |
|
| 108 | - 'height' => 200, |
|
| 109 | - 'id_base' => 'redux-social-icons-display', |
|
| 110 | - 'show_instance_in_rest' => true, |
|
| 111 | - ); |
|
| 112 | - |
|
| 113 | - parent::__construct( 'redux-social-icons-display', 'Redux Social Widget', $widget_ops, $control_ops ); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Widget render. |
|
| 118 | - * |
|
| 119 | - * @param array $args Args. |
|
| 120 | - * @param array $instance Instance. |
|
| 121 | - */ |
|
| 122 | - public function widget( $args, $instance ) { |
|
| 123 | - include_once 'class-redux-social-profiles-functions.php'; |
|
| 124 | - |
|
| 125 | - extract( $args, EXTR_SKIP ); // phpcs:ignore WordPress.PHP.DontExtract |
|
| 126 | - |
|
| 127 | - $title = $instance['title']; |
|
| 128 | - $redux_options = get_option( $this->parent->args['opt_name'] ); |
|
| 129 | - |
|
| 130 | - $social_items = $redux_options[ $this->field_id ]; |
|
| 131 | - |
|
| 132 | - echo $before_widget; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 133 | - |
|
| 134 | - if ( $title ) { |
|
| 135 | - echo $before_title . esc_html( $title ) . $after_title; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - ?> |
|
| 16 | + /** |
|
| 17 | + * Class Redux_Social_Profiles_Widget |
|
| 18 | + */ |
|
| 19 | + class Redux_Social_Profiles_Widget { |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Field ID. |
|
| 23 | + * |
|
| 24 | + * @var string|null |
|
| 25 | + */ |
|
| 26 | + public ?string $field_id = ''; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * ReduxFramework object pointer. |
|
| 30 | + * |
|
| 31 | + * @var ReduxFramework|null |
|
| 32 | + */ |
|
| 33 | + public ?ReduxFramework $parent = null; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Redux_Social_Profiles_Widget constructor. |
|
| 37 | + * |
|
| 38 | + * @param ReduxFramework $redux ReduxFramework object. |
|
| 39 | + * @param string $field_id Field ID. |
|
| 40 | + */ |
|
| 41 | + public function __construct( ReduxFramework $redux, string $field_id ) { |
|
| 42 | + return; |
|
| 43 | + |
|
| 44 | + $this->parent = $redux; |
|
| 45 | + $this->field_id = $field_id; |
|
| 46 | + |
|
| 47 | + |
|
| 48 | + $this->params = array( |
|
| 49 | + 'parent' => $this->parent, |
|
| 50 | + 'field_id' => $this->field_id, |
|
| 51 | + ); |
|
| 52 | + |
|
| 53 | + add_action( 'widgets_init', array( $this, 'load_widget' ), 0 ); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Load widget |
|
| 58 | + */ |
|
| 59 | + public function load_widget() { |
|
| 60 | + $x = new Extend_WP_Widget_Factory(); |
|
| 61 | + $x->register( 'Redux_Social_Widget_Display', $this->params ); |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Class Extend_WP_Widget_Factory |
|
| 67 | + */ |
|
| 68 | + // phpcs:ignore Generic.Files.OneClassPerFile |
|
| 69 | + class Extend_WP_Widget_Factory extends WP_Widget_Factory { |
|
| 70 | + /** |
|
| 71 | + * Register widget. |
|
| 72 | + * |
|
| 73 | + * @param string|WP_Widget $widget Widget class. |
|
| 74 | + * @param null $param Who knows. |
|
| 75 | + */ |
|
| 76 | + public function register( $widget, $param = null ) { |
|
| 77 | + $this->widgets[ $widget ] = new $widget( $param ); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Class Redux_Social_Widget_Display |
|
| 83 | + */ |
|
| 84 | + class Redux_Social_Widget_Display extends WP_Widget { |
|
| 85 | + |
|
| 86 | + public $show_instance_in_rest = true; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Redux_Social_Widget_Display constructor. |
|
| 90 | + * |
|
| 91 | + * @param array $params Params. |
|
| 92 | + */ |
|
| 93 | + public function __construct( $params ) { |
|
| 94 | + |
|
| 95 | + extract( $params ); // phpcs:ignore WordPress.PHP.DontExtract |
|
| 96 | + |
|
| 97 | + $this->parent = $parent; |
|
| 98 | + $this->field_id = $field_id; |
|
| 99 | + |
|
| 100 | + $widget_ops = array( |
|
| 101 | + 'classname' => 'redux-social-icons-display', |
|
| 102 | + 'description' => __( 'Display social media links', 'redux-framework' ), |
|
| 103 | + 'show_instance_in_rest' => true |
|
| 104 | + ); |
|
| 105 | + |
|
| 106 | + $control_ops = array( |
|
| 107 | + 'width' => 250, |
|
| 108 | + 'height' => 200, |
|
| 109 | + 'id_base' => 'redux-social-icons-display', |
|
| 110 | + 'show_instance_in_rest' => true, |
|
| 111 | + ); |
|
| 112 | + |
|
| 113 | + parent::__construct( 'redux-social-icons-display', 'Redux Social Widget', $widget_ops, $control_ops ); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Widget render. |
|
| 118 | + * |
|
| 119 | + * @param array $args Args. |
|
| 120 | + * @param array $instance Instance. |
|
| 121 | + */ |
|
| 122 | + public function widget( $args, $instance ) { |
|
| 123 | + include_once 'class-redux-social-profiles-functions.php'; |
|
| 124 | + |
|
| 125 | + extract( $args, EXTR_SKIP ); // phpcs:ignore WordPress.PHP.DontExtract |
|
| 126 | + |
|
| 127 | + $title = $instance['title']; |
|
| 128 | + $redux_options = get_option( $this->parent->args['opt_name'] ); |
|
| 129 | + |
|
| 130 | + $social_items = $redux_options[ $this->field_id ]; |
|
| 131 | + |
|
| 132 | + echo $before_widget; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 133 | + |
|
| 134 | + if ( $title ) { |
|
| 135 | + echo $before_title . esc_html( $title ) . $after_title; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + ?> |
|
| 139 | 139 | <ul class="redux-social-media-list clearfix"> |
| 140 | 140 | <?php |
| 141 | - if ( is_array( $social_items ) ) { |
|
| 142 | - foreach ( $social_items as $social_item ) { |
|
| 143 | - if ( $social_item['enabled'] ) { |
|
| 144 | - $icon = $social_item['icon']; |
|
| 145 | - $color = $social_item['color']; |
|
| 146 | - $background = $social_item['background']; |
|
| 147 | - $base_url = $social_item['url']; |
|
| 148 | - $id = $social_item['id']; |
|
| 149 | - |
|
| 150 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 151 | - $url = apply_filters( 'redux/extensions/social_profiles/' . $this->parent->args['opt_name'] . '/icon_url', $id, $base_url ); |
|
| 152 | - |
|
| 153 | - echo '<li>'; |
|
| 154 | - echo '<a href="' . esc_url( $url ) . '">'; |
|
| 155 | - Redux_Social_Profiles_Functions::render_icon( $icon, $color, $background, '' ); |
|
| 156 | - echo '</a>'; |
|
| 157 | - echo '</li>'; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - ?> |
|
| 141 | + if ( is_array( $social_items ) ) { |
|
| 142 | + foreach ( $social_items as $social_item ) { |
|
| 143 | + if ( $social_item['enabled'] ) { |
|
| 144 | + $icon = $social_item['icon']; |
|
| 145 | + $color = $social_item['color']; |
|
| 146 | + $background = $social_item['background']; |
|
| 147 | + $base_url = $social_item['url']; |
|
| 148 | + $id = $social_item['id']; |
|
| 149 | + |
|
| 150 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 151 | + $url = apply_filters( 'redux/extensions/social_profiles/' . $this->parent->args['opt_name'] . '/icon_url', $id, $base_url ); |
|
| 152 | + |
|
| 153 | + echo '<li>'; |
|
| 154 | + echo '<a href="' . esc_url( $url ) . '">'; |
|
| 155 | + Redux_Social_Profiles_Functions::render_icon( $icon, $color, $background, '' ); |
|
| 156 | + echo '</a>'; |
|
| 157 | + echo '</li>'; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + ?> |
|
| 162 | 162 | </ul> |
| 163 | 163 | <?php |
| 164 | 164 | |
| 165 | - echo $after_widget; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Update Widget. |
|
| 170 | - * |
|
| 171 | - * @param array $new_instance New instance. |
|
| 172 | - * @param array $old_instance Old instance. |
|
| 173 | - * |
|
| 174 | - * @return array |
|
| 175 | - */ |
|
| 176 | - public function update( $new_instance, $old_instance ): array { |
|
| 177 | - $instance = $old_instance; |
|
| 178 | - $instance['title'] = wp_strip_all_tags( $new_instance['title'] ?? '' ); |
|
| 179 | - |
|
| 180 | - return $instance; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Render widget form. |
|
| 185 | - * |
|
| 186 | - * @param array $instance Instance. |
|
| 187 | - * |
|
| 188 | - * @return void |
|
| 189 | - */ |
|
| 190 | - public function form( $instance ) { |
|
| 191 | - $defaults = array( |
|
| 192 | - 'title' => esc_html__( 'Social', 'redux-framework' ), |
|
| 193 | - ); |
|
| 194 | - |
|
| 195 | - $instance = wp_parse_args( (array) $instance, $defaults ); |
|
| 196 | - ?> |
|
| 165 | + echo $after_widget; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Update Widget. |
|
| 170 | + * |
|
| 171 | + * @param array $new_instance New instance. |
|
| 172 | + * @param array $old_instance Old instance. |
|
| 173 | + * |
|
| 174 | + * @return array |
|
| 175 | + */ |
|
| 176 | + public function update( $new_instance, $old_instance ): array { |
|
| 177 | + $instance = $old_instance; |
|
| 178 | + $instance['title'] = wp_strip_all_tags( $new_instance['title'] ?? '' ); |
|
| 179 | + |
|
| 180 | + return $instance; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Render widget form. |
|
| 185 | + * |
|
| 186 | + * @param array $instance Instance. |
|
| 187 | + * |
|
| 188 | + * @return void |
|
| 189 | + */ |
|
| 190 | + public function form( $instance ) { |
|
| 191 | + $defaults = array( |
|
| 192 | + 'title' => esc_html__( 'Social', 'redux-framework' ), |
|
| 193 | + ); |
|
| 194 | + |
|
| 195 | + $instance = wp_parse_args( (array) $instance, $defaults ); |
|
| 196 | + ?> |
|
| 197 | 197 | <p> |
| 198 | 198 | <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"> |
| 199 | 199 | <?php esc_html_e( 'Title', 'redux-framework' ); ?> |
@@ -206,15 +206,15 @@ discard block |
||
| 206 | 206 | </label> |
| 207 | 207 | <label for="redux-social-icons-info"> |
| 208 | 208 | <?php |
| 209 | - $tab = Redux_Helpers::tab_from_field( $this->parent, 'social_profiles' ); |
|
| 210 | - $slug = $this->parent->args['page_slug']; |
|
| 209 | + $tab = Redux_Helpers::tab_from_field( $this->parent, 'social_profiles' ); |
|
| 210 | + $slug = $this->parent->args['page_slug']; |
|
| 211 | 211 | |
| 212 | - // translators: %1$s: Settings page URL. %2$s: Closing a tag. |
|
| 213 | - printf( esc_html__( 'Control which icons are displayed and their urls on the %1$sssettings page%2$s', 'redux-framework' ), '<a href="' . esc_url( admin_url( 'admin.php?page=' . esc_attr( $slug ) . '&tab=' . esc_attr( $tab ) ) ) . '">', '</a>' ); |
|
| 214 | - ?> |
|
| 212 | + // translators: %1$s: Settings page URL. %2$s: Closing a tag. |
|
| 213 | + printf( esc_html__( 'Control which icons are displayed and their urls on the %1$sssettings page%2$s', 'redux-framework' ), '<a href="' . esc_url( admin_url( 'admin.php?page=' . esc_attr( $slug ) . '&tab=' . esc_attr( $tab ) ) ) . '">', '</a>' ); |
|
| 214 | + ?> |
|
| 215 | 215 | </label> |
| 216 | 216 | </p> |
| 217 | 217 | <?php |
| 218 | - } |
|
| 219 | - } |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | 220 | } |
@@ -18,50 +18,50 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | class Template_Overrides { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * ReduxTemplates Template_Overrides. |
|
| 23 | - * |
|
| 24 | - * @since 4.0.0 |
|
| 25 | - */ |
|
| 26 | - public function __construct() { |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Detects if the current page has blocks or not. |
|
| 31 | - * |
|
| 32 | - * @return bool |
|
| 33 | - * @since 4.0.0 |
|
| 34 | - */ |
|
| 35 | - public static function is_gutenberg(): bool { |
|
| 36 | - global $post; |
|
| 37 | - if ( function_exists( 'has_blocks' ) && has_blocks( $post->ID ) ) { |
|
| 38 | - return true; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - return false; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Detects the current theme and provides overrides. |
|
| 46 | - * |
|
| 47 | - * @return string |
|
| 48 | - * @since 4.0.0 |
|
| 49 | - */ |
|
| 50 | - public static function get_overrides(): string { |
|
| 51 | - |
|
| 52 | - if ( ! self::is_gutenberg() ) { |
|
| 53 | - return ''; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $template = mb_strtolower( get_template() ); |
|
| 57 | - |
|
| 58 | - $css = ''; |
|
| 59 | - if ( method_exists( __CLASS__, $template ) ) { |
|
| 60 | - $css = call_user_func( array( __CLASS__, $template ) ); |
|
| 61 | - $css = preg_replace( '/\s+/S', ' ', $css ); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - $css .= <<<'EOD' |
|
| 21 | + /** |
|
| 22 | + * ReduxTemplates Template_Overrides. |
|
| 23 | + * |
|
| 24 | + * @since 4.0.0 |
|
| 25 | + */ |
|
| 26 | + public function __construct() { |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Detects if the current page has blocks or not. |
|
| 31 | + * |
|
| 32 | + * @return bool |
|
| 33 | + * @since 4.0.0 |
|
| 34 | + */ |
|
| 35 | + public static function is_gutenberg(): bool { |
|
| 36 | + global $post; |
|
| 37 | + if ( function_exists( 'has_blocks' ) && has_blocks( $post->ID ) ) { |
|
| 38 | + return true; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + return false; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Detects the current theme and provides overrides. |
|
| 46 | + * |
|
| 47 | + * @return string |
|
| 48 | + * @since 4.0.0 |
|
| 49 | + */ |
|
| 50 | + public static function get_overrides(): string { |
|
| 51 | + |
|
| 52 | + if ( ! self::is_gutenberg() ) { |
|
| 53 | + return ''; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $template = mb_strtolower( get_template() ); |
|
| 57 | + |
|
| 58 | + $css = ''; |
|
| 59 | + if ( method_exists( __CLASS__, $template ) ) { |
|
| 60 | + $css = call_user_func( array( __CLASS__, $template ) ); |
|
| 61 | + $css = preg_replace( '/\s+/S', ' ', $css ); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + $css .= <<<'EOD' |
|
| 65 | 65 | #main { |
| 66 | 66 | padding: unset !important; |
| 67 | 67 | } |
@@ -78,68 +78,68 @@ discard block |
||
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | 80 | EOD; |
| 81 | - // Remove comments. |
|
| 82 | - $css = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css ); |
|
| 83 | - // Remove space after colons. |
|
| 84 | - $css = str_replace( ': ', ':', $css ); |
|
| 85 | - // Remove space after commas. |
|
| 86 | - $css = str_replace( ', ', ',', $css ); |
|
| 87 | - // Remove space after opening bracket. |
|
| 88 | - $css = str_replace( ' {', '{', $css ); |
|
| 89 | - // Remove whitespace. |
|
| 90 | - return str_replace( array( "\r\n", "\r", "\n", "\t", ' ', ' ', ' ' ), '', $css ); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * Consulting theme overrides. |
|
| 95 | - * |
|
| 96 | - * @return string |
|
| 97 | - * @since 4.0.0 |
|
| 98 | - */ |
|
| 99 | - public static function consulting(): string { |
|
| 100 | - return <<<'EOD' |
|
| 81 | + // Remove comments. |
|
| 82 | + $css = preg_replace( '!/\*[^*]*\*+([^/][^*]*\*+)*/!', '', $css ); |
|
| 83 | + // Remove space after colons. |
|
| 84 | + $css = str_replace( ': ', ':', $css ); |
|
| 85 | + // Remove space after commas. |
|
| 86 | + $css = str_replace( ', ', ',', $css ); |
|
| 87 | + // Remove space after opening bracket. |
|
| 88 | + $css = str_replace( ' {', '{', $css ); |
|
| 89 | + // Remove whitespace. |
|
| 90 | + return str_replace( array( "\r\n", "\r", "\n", "\t", ' ', ' ', ' ' ), '', $css ); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * Consulting theme overrides. |
|
| 95 | + * |
|
| 96 | + * @return string |
|
| 97 | + * @since 4.0.0 |
|
| 98 | + */ |
|
| 99 | + public static function consulting(): string { |
|
| 100 | + return <<<'EOD' |
|
| 101 | 101 | #content-core { |
| 102 | 102 | max-width: 100%; |
| 103 | 103 | } |
| 104 | 104 | EOD; |
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Avada theme overrides. |
|
| 109 | - * |
|
| 110 | - * @return string |
|
| 111 | - * @since 4.0.0 |
|
| 112 | - */ |
|
| 113 | - public static function avada(): string { |
|
| 114 | - return <<<'EOD' |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Avada theme overrides. |
|
| 109 | + * |
|
| 110 | + * @return string |
|
| 111 | + * @since 4.0.0 |
|
| 112 | + */ |
|
| 113 | + public static function avada(): string { |
|
| 114 | + return <<<'EOD' |
|
| 115 | 115 | #main .fusion-row { |
| 116 | 116 | max-width: unset; |
| 117 | 117 | } |
| 118 | 118 | EOD; |
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * GeneratePress theme overrides. |
|
| 123 | - * |
|
| 124 | - * @return string |
|
| 125 | - * @since 4.1.24 |
|
| 126 | - */ |
|
| 127 | - public static function generatepress(): string { |
|
| 128 | - return <<<'EOD' |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * GeneratePress theme overrides. |
|
| 123 | + * |
|
| 124 | + * @return string |
|
| 125 | + * @since 4.1.24 |
|
| 126 | + */ |
|
| 127 | + public static function generatepress(): string { |
|
| 128 | + return <<<'EOD' |
|
| 129 | 129 | .site-content { |
| 130 | 130 | display: block!important; |
| 131 | 131 | } |
| 132 | 132 | EOD; |
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * TwentyTwenty theme overrides. |
|
| 137 | - * |
|
| 138 | - * @return string |
|
| 139 | - * @since 4.0.0 |
|
| 140 | - */ |
|
| 141 | - public static function twentytwenty(): string { |
|
| 142 | - return <<<'EOD' |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * TwentyTwenty theme overrides. |
|
| 137 | + * |
|
| 138 | + * @return string |
|
| 139 | + * @since 4.0.0 |
|
| 140 | + */ |
|
| 141 | + public static function twentytwenty(): string { |
|
| 142 | + return <<<'EOD' |
|
| 143 | 143 | [class*="__inner-container"] > *:not(.alignwide):not(.alignfull):not(.alignleft):not(.alignright):not(.is-style-wide) { |
| 144 | 144 | max-width: unset !important; |
| 145 | 145 | } |
@@ -148,6 +148,6 @@ discard block |
||
| 148 | 148 | margin-bottom: unset; |
| 149 | 149 | } |
| 150 | 150 | EOD; |
| 151 | - } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | 153 | } |