@@ -129,19 +129,19 @@ discard block |
||
| 129 | 129 | * @return array |
| 130 | 130 | */ |
| 131 | 131 | public function reset_defaults_section( array $defaults = array() ): array { |
| 132 | - if ( isset( $_COOKIE[ 'redux_current_tab_' . $this->parent->args['opt_name'] ] ) ) { |
|
| 133 | - $cur_tab = sanitize_title( wp_unslash( $_COOKIE[ 'redux_current_tab_' . $this->parent->args['opt_name'] ] ) ); |
|
| 134 | - $tab_num = strval( $this->parent->field_sections['social_profiles'][ $this->field_id ] ); |
|
| 132 | + if ( isset( $_COOKIE['redux_current_tab_' . $this->parent->args['opt_name']] ) ) { |
|
| 133 | + $cur_tab = sanitize_title( wp_unslash( $_COOKIE['redux_current_tab_' . $this->parent->args['opt_name']] ) ); |
|
| 134 | + $tab_num = strval( $this->parent->field_sections['social_profiles'][$this->field_id] ); |
|
| 135 | 135 | |
| 136 | 136 | if ( $cur_tab === $tab_num ) { |
| 137 | - if ( '' !== $this->field_id && isset( $this->parent->options_defaults[ $this->field_id ] ) ) { |
|
| 137 | + if ( '' !== $this->field_id && isset( $this->parent->options_defaults[$this->field_id] ) ) { |
|
| 138 | 138 | $data = Redux_Social_Profiles_Functions::get_default_data(); |
| 139 | 139 | |
| 140 | 140 | Redux_Social_Profiles_Functions::write_data_file( $data ); |
| 141 | 141 | } |
| 142 | 142 | } |
| 143 | 143 | |
| 144 | - $defaults[ $this->field_id ] = Redux_Social_Profiles_Functions::read_data_file(); |
|
| 144 | + $defaults[$this->field_id] = Redux_Social_Profiles_Functions::read_data_file(); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | return $defaults; |
@@ -155,12 +155,12 @@ discard block |
||
| 155 | 155 | * @return array |
| 156 | 156 | */ |
| 157 | 157 | public function reset_defaults( array $defaults = array() ): array { |
| 158 | - if ( '' !== $this->field_id && isset( $this->parent->options_defaults[ $this->field_id ] ) ) { |
|
| 158 | + if ( '' !== $this->field_id && isset( $this->parent->options_defaults[$this->field_id] ) ) { |
|
| 159 | 159 | $data = Redux_Social_Profiles_Functions::get_default_data(); |
| 160 | 160 | |
| 161 | 161 | Redux_Social_Profiles_Functions::write_data_file( $data ); |
| 162 | 162 | |
| 163 | - $defaults[ $this->field_id ] = $data; |
|
| 163 | + $defaults[$this->field_id] = $data; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | return $defaults; |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | |
| 186 | 186 | Redux_Social_Profiles_Functions::write_data_file( $data ); |
| 187 | 187 | |
| 188 | - $this->parent->options[ $this->field_id ] = $data; |
|
| 188 | + $this->parent->options[$this->field_id] = $data; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | return $defaults; |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | $this->field_id = $this->field['id']; |
| 206 | 206 | } |
| 207 | 207 | |
| 208 | - if ( ! isset( $saved_options[ $this->field_id ] ) || empty( $saved_options[ $this->field_id ] ) || ( is_array( $saved_options[ $this->field_id ] ) && $saved_options === $changed_values ) || ! array_key_exists( $this->field_id, $saved_options ) ) { |
|
| 208 | + if ( ! isset( $saved_options[$this->field_id] ) || empty( $saved_options[$this->field_id] ) || ( is_array( $saved_options[$this->field_id] ) && $saved_options === $changed_values ) || ! array_key_exists( $this->field_id, $saved_options ) ) { |
|
| 209 | 209 | return $saved_options; |
| 210 | 210 | } |
| 211 | 211 | |
@@ -214,10 +214,10 @@ discard block |
||
| 214 | 214 | return $saved_options; |
| 215 | 215 | } |
| 216 | 216 | |
| 217 | - $first_value = reset( $saved_options[ $this->field_id ] ); // First Element's Value. |
|
| 217 | + $first_value = reset( $saved_options[$this->field_id] ); // First Element's Value. |
|
| 218 | 218 | |
| 219 | 219 | if ( isset( $first_value['data'] ) ) { |
| 220 | - $raw_data = $saved_options[ $this->field_id ]; |
|
| 220 | + $raw_data = $saved_options[$this->field_id]; |
|
| 221 | 221 | |
| 222 | 222 | $save_data = array(); |
| 223 | 223 | |
@@ -247,11 +247,11 @@ discard block |
||
| 247 | 247 | |
| 248 | 248 | $save_file = false; |
| 249 | 249 | |
| 250 | - if ( ! isset( $old_options[ $this->field_id ] ) || ( isset( $old_options[ $this->field_id ] ) && ! empty( $old_options[ $this->field_id ] ) ) ) { |
|
| 250 | + if ( ! isset( $old_options[$this->field_id] ) || ( isset( $old_options[$this->field_id] ) && ! empty( $old_options[$this->field_id] ) ) ) { |
|
| 251 | 251 | $save_file = true; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - if ( ! empty( $old_options[ $this->field_id ] ) && $old_options[ $this->field_id ] !== $saved_options[ $this->field_id ] ) { |
|
| 254 | + if ( ! empty( $old_options[$this->field_id] ) && $old_options[$this->field_id] !== $saved_options[$this->field_id] ) { |
|
| 255 | 255 | $save_file = true; |
| 256 | 256 | } |
| 257 | 257 | |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | Redux_Social_Profiles_Functions::write_data_file( $save_data ); |
| 260 | 260 | } |
| 261 | 261 | |
| 262 | - $saved_options[ $this->field_id ] = $save_data; |
|
| 262 | + $saved_options[$this->field_id] = $save_data; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | return $saved_options; |
@@ -15,272 +15,272 @@ |
||
| 15 | 15 | if ( ! class_exists( 'Redux_Extension_Social_Profiles' ) ) { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Main ReduxFramework social profiles extension class |
|
| 20 | - * |
|
| 21 | - * @since 1.0.0 |
|
| 22 | - */ |
|
| 23 | - class Redux_Extension_Social_Profiles extends Redux_Extension_Abstract { |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Extension version. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - public static $version = '4.5.8'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Extension friendly name. |
|
| 34 | - * |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - public string $extension_name = 'Social Profiles'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Field ID. |
|
| 41 | - * |
|
| 42 | - * @var mixed|null |
|
| 43 | - */ |
|
| 44 | - private $field_id = null; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Field array. |
|
| 48 | - * |
|
| 49 | - * @var array|null |
|
| 50 | - */ |
|
| 51 | - public ?array $field = array(); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Panel opt_name. |
|
| 55 | - * |
|
| 56 | - * @var string |
|
| 57 | - */ |
|
| 58 | - public string $opt_name; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Class Constructor. Defines the args for the extensions class |
|
| 62 | - * |
|
| 63 | - * @since 1.0.0 |
|
| 64 | - * @access public |
|
| 65 | - * |
|
| 66 | - * @param ReduxFramework $redux Parent settings. |
|
| 67 | - * |
|
| 68 | - * @return void |
|
| 69 | - */ |
|
| 70 | - public function __construct( $redux ) { |
|
| 71 | - parent::__construct( $redux, __FILE__ ); |
|
| 72 | - |
|
| 73 | - $this->add_field( 'social_profiles' ); |
|
| 74 | - |
|
| 75 | - require_once __DIR__ . '/redux-social-profiles-helpers.php'; |
|
| 76 | - |
|
| 77 | - include_once 'social_profiles/inc/class-redux-social-profiles-defaults.php'; |
|
| 78 | - include_once 'social_profiles/inc/class-redux-social-profiles-functions.php'; |
|
| 79 | - |
|
| 80 | - Redux_Social_Profiles_Functions::init( $redux ); |
|
| 81 | - |
|
| 82 | - $this->field = Redux_Social_Profiles_Functions::get_field( $redux ); |
|
| 83 | - |
|
| 84 | - if ( ! is_array( $this->field ) ) { |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $this->field_id = $this->field['id']; |
|
| 89 | - $this->opt_name = $redux->args['opt_name']; |
|
| 90 | - |
|
| 91 | - $upload_dir = Redux_Social_Profiles_Functions::$upload_dir; |
|
| 92 | - |
|
| 93 | - if ( ! is_dir( $upload_dir ) ) { |
|
| 94 | - Redux_Core::$filesystem->execute( 'mkdir', $upload_dir ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - if ( ! class_exists( 'Redux_Social_Profiles_Widget' ) ) { |
|
| 98 | - $enable = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/widget/enable', true ); // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 99 | - |
|
| 100 | - if ( $enable ) { |
|
| 101 | - include_once 'social_profiles/inc/class-redux-social-profiles-widget.php'; |
|
| 102 | - new Redux_Social_Profiles_Widget( $redux, $this->field_id ); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ( ! class_exists( 'Redux_Social_Profiles_Shortcode' ) ) { |
|
| 107 | - $enable = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/shortcode/enable', true ); // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 108 | - |
|
| 109 | - if ( $enable ) { |
|
| 110 | - include_once 'social_profiles/inc/class-redux-social-profiles-shortcode.php'; |
|
| 111 | - new Redux_Social_Profiles_Shortcode( $redux, $this->field_id ); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); |
|
| 116 | - |
|
| 117 | - add_filter( "redux/options/{$this->parent->args['opt_name']}/defaults", array( $this, 'set_defaults' ) ); |
|
| 118 | - add_action( 'redux/validate/' . $this->parent->args['opt_name'] . '/before_validation', array( $this, 'save_me' ), 0, 3 ); |
|
| 119 | - add_filter( 'redux/metaboxes/save/before_validate', array( $this, 'save_me' ), 0, 3 ); |
|
| 120 | - |
|
| 121 | - // Reset hooks. |
|
| 122 | - add_action( 'redux/validate/' . $this->parent->args['opt_name'] . '/defaults', array( $this, 'reset_defaults' ), 0, 3 ); |
|
| 123 | - add_action( 'redux/validate/' . $this->parent->args['opt_name'] . '/defaults_section', array( $this, 'reset_defaults_section' ), 0, 3 ); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Reset section defaults. |
|
| 128 | - * |
|
| 129 | - * @param array $defaults Default values. |
|
| 130 | - * |
|
| 131 | - * @return array |
|
| 132 | - */ |
|
| 133 | - public function reset_defaults_section( array $defaults = array() ): array { |
|
| 134 | - if ( isset( $_COOKIE[ 'redux_current_tab_' . $this->parent->args['opt_name'] ] ) ) { |
|
| 135 | - $cur_tab = sanitize_title( wp_unslash( $_COOKIE[ 'redux_current_tab_' . $this->parent->args['opt_name'] ] ) ); |
|
| 136 | - $tab_num = strval( $this->parent->field_sections['social_profiles'][ $this->field_id ] ); |
|
| 137 | - |
|
| 138 | - if ( $cur_tab === $tab_num ) { |
|
| 139 | - if ( '' !== $this->field_id && isset( $this->parent->options_defaults[ $this->field_id ] ) ) { |
|
| 140 | - $data = Redux_Social_Profiles_Functions::get_default_data(); |
|
| 141 | - |
|
| 142 | - Redux_Social_Profiles_Functions::write_data_file( $data ); |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $defaults[ $this->field_id ] = Redux_Social_Profiles_Functions::read_data_file(); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return $defaults; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Reset defaults. |
|
| 154 | - * |
|
| 155 | - * @param array $defaults Default values. |
|
| 156 | - * |
|
| 157 | - * @return array |
|
| 158 | - */ |
|
| 159 | - public function reset_defaults( array $defaults = array() ): array { |
|
| 160 | - if ( '' !== $this->field_id && isset( $this->parent->options_defaults[ $this->field_id ] ) ) { |
|
| 161 | - $data = Redux_Social_Profiles_Functions::get_default_data(); |
|
| 162 | - |
|
| 163 | - Redux_Social_Profiles_Functions::write_data_file( $data ); |
|
| 164 | - |
|
| 165 | - $defaults[ $this->field_id ] = $data; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return $defaults; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Set default values. |
|
| 173 | - * |
|
| 174 | - * @param array $defaults Default values. |
|
| 175 | - * |
|
| 176 | - * @return array |
|
| 177 | - */ |
|
| 178 | - public function set_defaults( array $defaults = array() ): array { |
|
| 179 | - if ( empty( $this->field_id ) ) { |
|
| 180 | - return $defaults; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $comp_file = Redux_Social_Profiles_Functions::get_data_path(); |
|
| 184 | - |
|
| 185 | - if ( ! file_exists( $comp_file ) ) { |
|
| 186 | - $data = Redux_Social_Profiles_Functions::get_default_data(); |
|
| 187 | - |
|
| 188 | - Redux_Social_Profiles_Functions::write_data_file( $data ); |
|
| 189 | - |
|
| 190 | - $this->parent->options[ $this->field_id ] = $data; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - return $defaults; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Save Data. |
|
| 198 | - * |
|
| 199 | - * @param array $saved_options Saved options. |
|
| 200 | - * @param array $changed_values Changed values. |
|
| 201 | - * |
|
| 202 | - * @return array |
|
| 203 | - */ |
|
| 204 | - public function save_me( array $saved_options = array(), array $changed_values = array() ): array { |
|
| 205 | - if ( empty( $this->field ) ) { |
|
| 206 | - $this->field = Redux_Social_Profiles_Functions::get_field(); |
|
| 207 | - $this->field_id = $this->field['id']; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - if ( ! isset( $saved_options[ $this->field_id ] ) || empty( $saved_options[ $this->field_id ] ) || ( is_array( $saved_options[ $this->field_id ] ) && $saved_options === $changed_values ) || ! array_key_exists( $this->field_id, $saved_options ) ) { |
|
| 211 | - return $saved_options; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - // We'll use the reset hook instead. |
|
| 215 | - if ( ! empty( $saved_options['defaults'] ) || ! empty( $saved_options['defaults-section'] ) ) { |
|
| 216 | - return $saved_options; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - $first_value = reset( $saved_options[ $this->field_id ] ); // First Element's Value. |
|
| 220 | - |
|
| 221 | - if ( isset( $first_value['data'] ) ) { |
|
| 222 | - $raw_data = $saved_options[ $this->field_id ]; |
|
| 223 | - |
|
| 224 | - $save_data = array(); |
|
| 225 | - |
|
| 226 | - // Enum through saved data. |
|
| 227 | - foreach ( $raw_data as $val ) { |
|
| 228 | - if ( is_array( $val ) ) { |
|
| 229 | - |
|
| 230 | - if ( ! isset( $val['data'] ) ) { |
|
| 231 | - return array(); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - $data = json_decode( rawurldecode( $val['data'] ), true ); |
|
| 235 | - |
|
| 236 | - $save_data[] = array( |
|
| 237 | - 'id' => $data['id'], |
|
| 238 | - 'class' => $data['class'] ?? 'fa', |
|
| 239 | - 'icon' => $data['icon'], |
|
| 240 | - 'enabled' => $data['enabled'], |
|
| 241 | - 'url' => $data['url'], |
|
| 242 | - 'color' => $data['color'], |
|
| 243 | - 'background' => $data['background'], |
|
| 244 | - 'order' => $data['order'], |
|
| 245 | - 'name' => $data['name'], |
|
| 246 | - 'label' => $data['label'], |
|
| 247 | - ); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $save_file = false; |
|
| 252 | - |
|
| 253 | - if ( ! isset( $old_options[ $this->field_id ] ) || ( isset( $old_options[ $this->field_id ] ) && ! empty( $old_options[ $this->field_id ] ) ) ) { |
|
| 254 | - $save_file = true; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - if ( ! empty( $old_options[ $this->field_id ] ) && $old_options[ $this->field_id ] !== $saved_options[ $this->field_id ] ) { |
|
| 258 | - $save_file = true; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if ( $save_file ) { |
|
| 262 | - Redux_Social_Profiles_Functions::write_data_file( $save_data ); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - $saved_options[ $this->field_id ] = $save_data; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - return $saved_options; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Enqueue scripts/styles. |
|
| 273 | - */ |
|
| 274 | - public function enqueue_styles() { |
|
| 275 | - // Field CSS. |
|
| 276 | - wp_enqueue_style( |
|
| 277 | - 'redux-field-social-profiles-frontend', |
|
| 278 | - $this->extension_url . 'social_profiles/css/field_social_profiles_frontend.css', |
|
| 279 | - array(), |
|
| 280 | - self::$version |
|
| 281 | - ); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - class_alias( Redux_Extension_Social_Profiles::class, 'ReduxFramework_Extension_social_profiles' ); |
|
| 18 | + /** |
|
| 19 | + * Main ReduxFramework social profiles extension class |
|
| 20 | + * |
|
| 21 | + * @since 1.0.0 |
|
| 22 | + */ |
|
| 23 | + class Redux_Extension_Social_Profiles extends Redux_Extension_Abstract { |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Extension version. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + public static $version = '4.5.8'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Extension friendly name. |
|
| 34 | + * |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + public string $extension_name = 'Social Profiles'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Field ID. |
|
| 41 | + * |
|
| 42 | + * @var mixed|null |
|
| 43 | + */ |
|
| 44 | + private $field_id = null; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Field array. |
|
| 48 | + * |
|
| 49 | + * @var array|null |
|
| 50 | + */ |
|
| 51 | + public ?array $field = array(); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Panel opt_name. |
|
| 55 | + * |
|
| 56 | + * @var string |
|
| 57 | + */ |
|
| 58 | + public string $opt_name; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Class Constructor. Defines the args for the extensions class |
|
| 62 | + * |
|
| 63 | + * @since 1.0.0 |
|
| 64 | + * @access public |
|
| 65 | + * |
|
| 66 | + * @param ReduxFramework $redux Parent settings. |
|
| 67 | + * |
|
| 68 | + * @return void |
|
| 69 | + */ |
|
| 70 | + public function __construct( $redux ) { |
|
| 71 | + parent::__construct( $redux, __FILE__ ); |
|
| 72 | + |
|
| 73 | + $this->add_field( 'social_profiles' ); |
|
| 74 | + |
|
| 75 | + require_once __DIR__ . '/redux-social-profiles-helpers.php'; |
|
| 76 | + |
|
| 77 | + include_once 'social_profiles/inc/class-redux-social-profiles-defaults.php'; |
|
| 78 | + include_once 'social_profiles/inc/class-redux-social-profiles-functions.php'; |
|
| 79 | + |
|
| 80 | + Redux_Social_Profiles_Functions::init( $redux ); |
|
| 81 | + |
|
| 82 | + $this->field = Redux_Social_Profiles_Functions::get_field( $redux ); |
|
| 83 | + |
|
| 84 | + if ( ! is_array( $this->field ) ) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $this->field_id = $this->field['id']; |
|
| 89 | + $this->opt_name = $redux->args['opt_name']; |
|
| 90 | + |
|
| 91 | + $upload_dir = Redux_Social_Profiles_Functions::$upload_dir; |
|
| 92 | + |
|
| 93 | + if ( ! is_dir( $upload_dir ) ) { |
|
| 94 | + Redux_Core::$filesystem->execute( 'mkdir', $upload_dir ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + if ( ! class_exists( 'Redux_Social_Profiles_Widget' ) ) { |
|
| 98 | + $enable = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/widget/enable', true ); // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 99 | + |
|
| 100 | + if ( $enable ) { |
|
| 101 | + include_once 'social_profiles/inc/class-redux-social-profiles-widget.php'; |
|
| 102 | + new Redux_Social_Profiles_Widget( $redux, $this->field_id ); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ( ! class_exists( 'Redux_Social_Profiles_Shortcode' ) ) { |
|
| 107 | + $enable = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/shortcode/enable', true ); // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 108 | + |
|
| 109 | + if ( $enable ) { |
|
| 110 | + include_once 'social_profiles/inc/class-redux-social-profiles-shortcode.php'; |
|
| 111 | + new Redux_Social_Profiles_Shortcode( $redux, $this->field_id ); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); |
|
| 116 | + |
|
| 117 | + add_filter( "redux/options/{$this->parent->args['opt_name']}/defaults", array( $this, 'set_defaults' ) ); |
|
| 118 | + add_action( 'redux/validate/' . $this->parent->args['opt_name'] . '/before_validation', array( $this, 'save_me' ), 0, 3 ); |
|
| 119 | + add_filter( 'redux/metaboxes/save/before_validate', array( $this, 'save_me' ), 0, 3 ); |
|
| 120 | + |
|
| 121 | + // Reset hooks. |
|
| 122 | + add_action( 'redux/validate/' . $this->parent->args['opt_name'] . '/defaults', array( $this, 'reset_defaults' ), 0, 3 ); |
|
| 123 | + add_action( 'redux/validate/' . $this->parent->args['opt_name'] . '/defaults_section', array( $this, 'reset_defaults_section' ), 0, 3 ); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Reset section defaults. |
|
| 128 | + * |
|
| 129 | + * @param array $defaults Default values. |
|
| 130 | + * |
|
| 131 | + * @return array |
|
| 132 | + */ |
|
| 133 | + public function reset_defaults_section( array $defaults = array() ): array { |
|
| 134 | + if ( isset( $_COOKIE[ 'redux_current_tab_' . $this->parent->args['opt_name'] ] ) ) { |
|
| 135 | + $cur_tab = sanitize_title( wp_unslash( $_COOKIE[ 'redux_current_tab_' . $this->parent->args['opt_name'] ] ) ); |
|
| 136 | + $tab_num = strval( $this->parent->field_sections['social_profiles'][ $this->field_id ] ); |
|
| 137 | + |
|
| 138 | + if ( $cur_tab === $tab_num ) { |
|
| 139 | + if ( '' !== $this->field_id && isset( $this->parent->options_defaults[ $this->field_id ] ) ) { |
|
| 140 | + $data = Redux_Social_Profiles_Functions::get_default_data(); |
|
| 141 | + |
|
| 142 | + Redux_Social_Profiles_Functions::write_data_file( $data ); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + $defaults[ $this->field_id ] = Redux_Social_Profiles_Functions::read_data_file(); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return $defaults; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Reset defaults. |
|
| 154 | + * |
|
| 155 | + * @param array $defaults Default values. |
|
| 156 | + * |
|
| 157 | + * @return array |
|
| 158 | + */ |
|
| 159 | + public function reset_defaults( array $defaults = array() ): array { |
|
| 160 | + if ( '' !== $this->field_id && isset( $this->parent->options_defaults[ $this->field_id ] ) ) { |
|
| 161 | + $data = Redux_Social_Profiles_Functions::get_default_data(); |
|
| 162 | + |
|
| 163 | + Redux_Social_Profiles_Functions::write_data_file( $data ); |
|
| 164 | + |
|
| 165 | + $defaults[ $this->field_id ] = $data; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + return $defaults; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Set default values. |
|
| 173 | + * |
|
| 174 | + * @param array $defaults Default values. |
|
| 175 | + * |
|
| 176 | + * @return array |
|
| 177 | + */ |
|
| 178 | + public function set_defaults( array $defaults = array() ): array { |
|
| 179 | + if ( empty( $this->field_id ) ) { |
|
| 180 | + return $defaults; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $comp_file = Redux_Social_Profiles_Functions::get_data_path(); |
|
| 184 | + |
|
| 185 | + if ( ! file_exists( $comp_file ) ) { |
|
| 186 | + $data = Redux_Social_Profiles_Functions::get_default_data(); |
|
| 187 | + |
|
| 188 | + Redux_Social_Profiles_Functions::write_data_file( $data ); |
|
| 189 | + |
|
| 190 | + $this->parent->options[ $this->field_id ] = $data; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + return $defaults; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Save Data. |
|
| 198 | + * |
|
| 199 | + * @param array $saved_options Saved options. |
|
| 200 | + * @param array $changed_values Changed values. |
|
| 201 | + * |
|
| 202 | + * @return array |
|
| 203 | + */ |
|
| 204 | + public function save_me( array $saved_options = array(), array $changed_values = array() ): array { |
|
| 205 | + if ( empty( $this->field ) ) { |
|
| 206 | + $this->field = Redux_Social_Profiles_Functions::get_field(); |
|
| 207 | + $this->field_id = $this->field['id']; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + if ( ! isset( $saved_options[ $this->field_id ] ) || empty( $saved_options[ $this->field_id ] ) || ( is_array( $saved_options[ $this->field_id ] ) && $saved_options === $changed_values ) || ! array_key_exists( $this->field_id, $saved_options ) ) { |
|
| 211 | + return $saved_options; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + // We'll use the reset hook instead. |
|
| 215 | + if ( ! empty( $saved_options['defaults'] ) || ! empty( $saved_options['defaults-section'] ) ) { |
|
| 216 | + return $saved_options; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + $first_value = reset( $saved_options[ $this->field_id ] ); // First Element's Value. |
|
| 220 | + |
|
| 221 | + if ( isset( $first_value['data'] ) ) { |
|
| 222 | + $raw_data = $saved_options[ $this->field_id ]; |
|
| 223 | + |
|
| 224 | + $save_data = array(); |
|
| 225 | + |
|
| 226 | + // Enum through saved data. |
|
| 227 | + foreach ( $raw_data as $val ) { |
|
| 228 | + if ( is_array( $val ) ) { |
|
| 229 | + |
|
| 230 | + if ( ! isset( $val['data'] ) ) { |
|
| 231 | + return array(); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + $data = json_decode( rawurldecode( $val['data'] ), true ); |
|
| 235 | + |
|
| 236 | + $save_data[] = array( |
|
| 237 | + 'id' => $data['id'], |
|
| 238 | + 'class' => $data['class'] ?? 'fa', |
|
| 239 | + 'icon' => $data['icon'], |
|
| 240 | + 'enabled' => $data['enabled'], |
|
| 241 | + 'url' => $data['url'], |
|
| 242 | + 'color' => $data['color'], |
|
| 243 | + 'background' => $data['background'], |
|
| 244 | + 'order' => $data['order'], |
|
| 245 | + 'name' => $data['name'], |
|
| 246 | + 'label' => $data['label'], |
|
| 247 | + ); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $save_file = false; |
|
| 252 | + |
|
| 253 | + if ( ! isset( $old_options[ $this->field_id ] ) || ( isset( $old_options[ $this->field_id ] ) && ! empty( $old_options[ $this->field_id ] ) ) ) { |
|
| 254 | + $save_file = true; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + if ( ! empty( $old_options[ $this->field_id ] ) && $old_options[ $this->field_id ] !== $saved_options[ $this->field_id ] ) { |
|
| 258 | + $save_file = true; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if ( $save_file ) { |
|
| 262 | + Redux_Social_Profiles_Functions::write_data_file( $save_data ); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + $saved_options[ $this->field_id ] = $save_data; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + return $saved_options; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Enqueue scripts/styles. |
|
| 273 | + */ |
|
| 274 | + public function enqueue_styles() { |
|
| 275 | + // Field CSS. |
|
| 276 | + wp_enqueue_style( |
|
| 277 | + 'redux-field-social-profiles-frontend', |
|
| 278 | + $this->extension_url . 'social_profiles/css/field_social_profiles_frontend.css', |
|
| 279 | + array(), |
|
| 280 | + self::$version |
|
| 281 | + ); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + class_alias( Redux_Extension_Social_Profiles::class, 'ReduxFramework_Extension_social_profiles' ); |
|
| 286 | 286 | } |
@@ -50,7 +50,7 @@ |
||
| 50 | 50 | */ |
| 51 | 51 | public function redux_social_profiles(): string { |
| 52 | 52 | $redux_options = get_option( $this->parent->args['opt_name'] ); |
| 53 | - $social_items = $redux_options[ $this->field_id ]; |
|
| 53 | + $social_items = $redux_options[$this->field_id]; |
|
| 54 | 54 | |
| 55 | 55 | $html = '<ul class="redux-social-media-list clearfix">'; |
| 56 | 56 | |
@@ -11,73 +11,73 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Social_Profiles_Shortcode' ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Class Redux_Social_Profiles_Shortcode |
|
| 16 | - */ |
|
| 17 | - class Redux_Social_Profiles_Shortcode { |
|
| 14 | + /** |
|
| 15 | + * Class Redux_Social_Profiles_Shortcode |
|
| 16 | + */ |
|
| 17 | + class Redux_Social_Profiles_Shortcode { |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * ReduxFramework object pointer. |
|
| 21 | - * |
|
| 22 | - * @var ReduxFramework |
|
| 23 | - */ |
|
| 24 | - private ReduxFramework $parent; |
|
| 19 | + /** |
|
| 20 | + * ReduxFramework object pointer. |
|
| 21 | + * |
|
| 22 | + * @var ReduxFramework |
|
| 23 | + */ |
|
| 24 | + private ReduxFramework $parent; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Field ID. |
|
| 28 | - * |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - private string $field_id; |
|
| 26 | + /** |
|
| 27 | + * Field ID. |
|
| 28 | + * |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + private string $field_id; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Redux_Social_Profiles_Shortcode constructor. |
|
| 35 | - * |
|
| 36 | - * @param ReduxFramework $redux ReduxFramework object. |
|
| 37 | - * @param string $field_id Field ID. |
|
| 38 | - */ |
|
| 39 | - public function __construct( ReduxFramework $redux, string $field_id ) { |
|
| 40 | - $this->parent = $redux; |
|
| 41 | - $this->field_id = $field_id; |
|
| 33 | + /** |
|
| 34 | + * Redux_Social_Profiles_Shortcode constructor. |
|
| 35 | + * |
|
| 36 | + * @param ReduxFramework $redux ReduxFramework object. |
|
| 37 | + * @param string $field_id Field ID. |
|
| 38 | + */ |
|
| 39 | + public function __construct( ReduxFramework $redux, string $field_id ) { |
|
| 40 | + $this->parent = $redux; |
|
| 41 | + $this->field_id = $field_id; |
|
| 42 | 42 | |
| 43 | - add_shortcode( 'social_profiles', array( $this, 'redux_social_profiles' ) ); |
|
| 44 | - } |
|
| 43 | + add_shortcode( 'social_profiles', array( $this, 'redux_social_profiles' ) ); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Render shortcode. |
|
| 48 | - * |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function redux_social_profiles(): string { |
|
| 52 | - $redux_options = get_option( $this->parent->args['opt_name'] ); |
|
| 53 | - $social_items = $redux_options[ $this->field_id ]; |
|
| 46 | + /** |
|
| 47 | + * Render shortcode. |
|
| 48 | + * |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function redux_social_profiles(): string { |
|
| 52 | + $redux_options = get_option( $this->parent->args['opt_name'] ); |
|
| 53 | + $social_items = $redux_options[ $this->field_id ]; |
|
| 54 | 54 | |
| 55 | - $html = '<ul class="redux-social-media-list clearfix">'; |
|
| 55 | + $html = '<ul class="redux-social-media-list clearfix">'; |
|
| 56 | 56 | |
| 57 | - if ( is_array( $social_items ) ) { |
|
| 58 | - foreach ( $social_items as $social_item ) { |
|
| 59 | - if ( $social_item['enabled'] ) { |
|
| 60 | - $icon = $social_item['icon']; |
|
| 61 | - $class = $social_item['class'] ?? 'fa'; |
|
| 62 | - $color = $social_item['color']; |
|
| 63 | - $background = $social_item['background']; |
|
| 64 | - $base_url = $social_item['url']; |
|
| 65 | - $id = $social_item['id']; |
|
| 57 | + if ( is_array( $social_items ) ) { |
|
| 58 | + foreach ( $social_items as $social_item ) { |
|
| 59 | + if ( $social_item['enabled'] ) { |
|
| 60 | + $icon = $social_item['icon']; |
|
| 61 | + $class = $social_item['class'] ?? 'fa'; |
|
| 62 | + $color = $social_item['color']; |
|
| 63 | + $background = $social_item['background']; |
|
| 64 | + $base_url = $social_item['url']; |
|
| 65 | + $id = $social_item['id']; |
|
| 66 | 66 | |
| 67 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 68 | - $url = apply_filters( 'redux/extensions/social_profiles/' . $this->parent->args['opt_name'] . '/icon_url', $id, $base_url ); |
|
| 67 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 68 | + $url = apply_filters( 'redux/extensions/social_profiles/' . $this->parent->args['opt_name'] . '/icon_url', $id, $base_url ); |
|
| 69 | 69 | |
| 70 | - $html .= '<li style="list-style: none;">'; |
|
| 71 | - $html .= "<a href='" . $url . "'>"; |
|
| 72 | - $html .= Redux_Social_Profiles_Functions::render_icon( $class, $icon, $color, $background, '', false ); |
|
| 73 | - $html .= '</a>'; |
|
| 74 | - $html .= '</li>'; |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - $html .= '</ul>'; |
|
| 70 | + $html .= '<li style="list-style: none;">'; |
|
| 71 | + $html .= "<a href='" . $url . "'>"; |
|
| 72 | + $html .= Redux_Social_Profiles_Functions::render_icon( $class, $icon, $color, $background, '', false ); |
|
| 73 | + $html .= '</a>'; |
|
| 74 | + $html .= '</li>'; |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + $html .= '</ul>'; |
|
| 79 | 79 | |
| 80 | - return $html; |
|
| 81 | - } |
|
| 82 | - } |
|
| 80 | + return $html; |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -28,13 +28,13 @@ discard block |
||
| 28 | 28 | $social_profiles = $redux->extensions['social_profiles']; |
| 29 | 29 | |
| 30 | 30 | $redux_options = get_option( $social_profiles->opt_name ); |
| 31 | - $settings = $redux_options[ $social_profiles->field_id ]; |
|
| 31 | + $settings = $redux_options[$social_profiles->field_id]; |
|
| 32 | 32 | |
| 33 | 33 | foreach ( $settings as $arr ) { |
| 34 | 34 | if ( $id === $arr['id'] ) { |
| 35 | 35 | if ( $arr['enabled'] ) { |
| 36 | - if ( isset( $arr[ $value ] ) ) { |
|
| 37 | - return $arr[ $value ]; |
|
| 36 | + if ( isset( $arr[$value] ) ) { |
|
| 37 | + return $arr[$value]; |
|
| 38 | 38 | } |
| 39 | 39 | } else { |
| 40 | 40 | return ''; |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $social_profiles = $redux->extensions['social_profiles']; |
| 71 | 71 | |
| 72 | 72 | $redux_options = get_option( $social_profiles->opt_name ); |
| 73 | - $settings = $redux_options[ $social_profiles->field_id ]; |
|
| 73 | + $settings = $redux_options[$social_profiles->field_id]; |
|
| 74 | 74 | |
| 75 | 75 | foreach ( $settings as $arr ) { |
| 76 | 76 | if ( $id === $arr['id'] ) { |
@@ -8,93 +8,93 @@ |
||
| 8 | 8 | defined( 'ABSPATH' ) || exit; |
| 9 | 9 | |
| 10 | 10 | if ( ! function_exists( 'redux_social_profile_value_from_id' ) ) { |
| 11 | - /** |
|
| 12 | - * Returns social profile value from passed profile ID. |
|
| 13 | - * |
|
| 14 | - * @param string $opt_name Redux Framework opt_name. |
|
| 15 | - * @param string $id Profile ID. |
|
| 16 | - * @param string $value Social profile value to return (icon, name, class, background, color, url, or order). |
|
| 17 | - * |
|
| 18 | - * @return string Returns HTML string when $echo is set to false. Otherwise, true. |
|
| 19 | - * @since 1.0.0 |
|
| 20 | - * @access public |
|
| 21 | - */ |
|
| 22 | - function redux_social_profile_value_from_id( string $opt_name, string $id, string $value ): string { |
|
| 23 | - if ( empty( $opt_name ) || empty( $id ) || empty( $value ) ) { |
|
| 24 | - return ''; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - $redux = ReduxFrameworkInstances::get_instance( $opt_name ); |
|
| 28 | - $social_profiles = $redux->extensions['social_profiles']; |
|
| 29 | - |
|
| 30 | - $redux_options = get_option( $social_profiles->opt_name ); |
|
| 31 | - $settings = $redux_options[ $social_profiles->field_id ]; |
|
| 32 | - |
|
| 33 | - foreach ( $settings as $arr ) { |
|
| 34 | - if ( $id === $arr['id'] ) { |
|
| 35 | - if ( $arr['enabled'] ) { |
|
| 36 | - if ( isset( $arr[ $value ] ) ) { |
|
| 37 | - return $arr[ $value ]; |
|
| 38 | - } |
|
| 39 | - } else { |
|
| 40 | - return ''; |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - return ''; |
|
| 46 | - } |
|
| 11 | + /** |
|
| 12 | + * Returns social profile value from passed profile ID. |
|
| 13 | + * |
|
| 14 | + * @param string $opt_name Redux Framework opt_name. |
|
| 15 | + * @param string $id Profile ID. |
|
| 16 | + * @param string $value Social profile value to return (icon, name, class, background, color, url, or order). |
|
| 17 | + * |
|
| 18 | + * @return string Returns HTML string when $echo is set to false. Otherwise, true. |
|
| 19 | + * @since 1.0.0 |
|
| 20 | + * @access public |
|
| 21 | + */ |
|
| 22 | + function redux_social_profile_value_from_id( string $opt_name, string $id, string $value ): string { |
|
| 23 | + if ( empty( $opt_name ) || empty( $id ) || empty( $value ) ) { |
|
| 24 | + return ''; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + $redux = ReduxFrameworkInstances::get_instance( $opt_name ); |
|
| 28 | + $social_profiles = $redux->extensions['social_profiles']; |
|
| 29 | + |
|
| 30 | + $redux_options = get_option( $social_profiles->opt_name ); |
|
| 31 | + $settings = $redux_options[ $social_profiles->field_id ]; |
|
| 32 | + |
|
| 33 | + foreach ( $settings as $arr ) { |
|
| 34 | + if ( $id === $arr['id'] ) { |
|
| 35 | + if ( $arr['enabled'] ) { |
|
| 36 | + if ( isset( $arr[ $value ] ) ) { |
|
| 37 | + return $arr[ $value ]; |
|
| 38 | + } |
|
| 39 | + } else { |
|
| 40 | + return ''; |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + return ''; |
|
| 46 | + } |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | if ( ! function_exists( 'redux_render_icon_from_id' ) ) { |
| 50 | - /** |
|
| 51 | - * Renders social icon from passed profile ID. |
|
| 52 | - * |
|
| 53 | - * @param string $opt_name Redux Framework opt_name. |
|
| 54 | - * @param string $id Profile ID. |
|
| 55 | - * @param boolean $output Echos icon HTML when true. Returns icon HTML when false. |
|
| 56 | - * @param string $a_class Class name for a tag. |
|
| 57 | - * |
|
| 58 | - * @return string Returns HTML string when $echo is set to false. Otherwise, true. |
|
| 59 | - * @since 1.0.0 |
|
| 60 | - * @access public |
|
| 61 | - */ |
|
| 62 | - function redux_render_icon_from_id( string $opt_name, string $id, bool $output = true, string $a_class = '' ) { |
|
| 63 | - if ( empty( $opt_name ) || empty( $id ) ) { |
|
| 64 | - return ''; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - include_once 'social_profiles/inc/class-redux-social-profiles-functions.php'; |
|
| 68 | - |
|
| 69 | - $redux = ReduxFrameworkInstances::get_instance( $opt_name ); |
|
| 70 | - $social_profiles = $redux->extensions['social_profiles']; |
|
| 71 | - |
|
| 72 | - $redux_options = get_option( $social_profiles->opt_name ); |
|
| 73 | - $settings = $redux_options[ $social_profiles->field_id ]; |
|
| 74 | - |
|
| 75 | - foreach ( $settings as $arr ) { |
|
| 76 | - if ( $id === $arr['id'] ) { |
|
| 77 | - if ( $arr['enabled'] ) { |
|
| 78 | - $arr['class'] = $arr['class'] ?? 'fa'; |
|
| 79 | - |
|
| 80 | - if ( $output ) { |
|
| 81 | - echo '<a class="' . esc_attr( $a_class ) . '" href="' . esc_url( $arr['url'] ) . '">'; |
|
| 82 | - Redux_Social_Profiles_Functions::render_icon( $arr['class'], $arr['icon'], $arr['color'], $arr['background'], '' ); |
|
| 83 | - echo '</a>'; |
|
| 84 | - |
|
| 85 | - return true; |
|
| 86 | - } else { |
|
| 87 | - $html = '<a class="' . $a_class . '"href="' . $arr['url'] . '">'; |
|
| 88 | - |
|
| 89 | - $html .= Redux_Social_Profiles_Functions::render_icon( $arr['class'], $arr['icon'], $arr['color'], $arr['background'], '', false ); |
|
| 90 | - $html .= '</a>'; |
|
| 91 | - |
|
| 92 | - return $html; |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - return ''; |
|
| 99 | - } |
|
| 50 | + /** |
|
| 51 | + * Renders social icon from passed profile ID. |
|
| 52 | + * |
|
| 53 | + * @param string $opt_name Redux Framework opt_name. |
|
| 54 | + * @param string $id Profile ID. |
|
| 55 | + * @param boolean $output Echos icon HTML when true. Returns icon HTML when false. |
|
| 56 | + * @param string $a_class Class name for a tag. |
|
| 57 | + * |
|
| 58 | + * @return string Returns HTML string when $echo is set to false. Otherwise, true. |
|
| 59 | + * @since 1.0.0 |
|
| 60 | + * @access public |
|
| 61 | + */ |
|
| 62 | + function redux_render_icon_from_id( string $opt_name, string $id, bool $output = true, string $a_class = '' ) { |
|
| 63 | + if ( empty( $opt_name ) || empty( $id ) ) { |
|
| 64 | + return ''; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + include_once 'social_profiles/inc/class-redux-social-profiles-functions.php'; |
|
| 68 | + |
|
| 69 | + $redux = ReduxFrameworkInstances::get_instance( $opt_name ); |
|
| 70 | + $social_profiles = $redux->extensions['social_profiles']; |
|
| 71 | + |
|
| 72 | + $redux_options = get_option( $social_profiles->opt_name ); |
|
| 73 | + $settings = $redux_options[ $social_profiles->field_id ]; |
|
| 74 | + |
|
| 75 | + foreach ( $settings as $arr ) { |
|
| 76 | + if ( $id === $arr['id'] ) { |
|
| 77 | + if ( $arr['enabled'] ) { |
|
| 78 | + $arr['class'] = $arr['class'] ?? 'fa'; |
|
| 79 | + |
|
| 80 | + if ( $output ) { |
|
| 81 | + echo '<a class="' . esc_attr( $a_class ) . '" href="' . esc_url( $arr['url'] ) . '">'; |
|
| 82 | + Redux_Social_Profiles_Functions::render_icon( $arr['class'], $arr['icon'], $arr['color'], $arr['background'], '' ); |
|
| 83 | + echo '</a>'; |
|
| 84 | + |
|
| 85 | + return true; |
|
| 86 | + } else { |
|
| 87 | + $html = '<a class="' . $a_class . '"href="' . $arr['url'] . '">'; |
|
| 88 | + |
|
| 89 | + $html .= Redux_Social_Profiles_Functions::render_icon( $arr['class'], $arr['icon'], $arr['color'], $arr['background'], '', false ); |
|
| 90 | + $html .= '</a>'; |
|
| 91 | + |
|
| 92 | + return $html; |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + return ''; |
|
| 99 | + } |
|
| 100 | 100 | } |
@@ -10,20 +10,20 @@ |
||
| 10 | 10 | // Helper function to bypass WordPress hook priorities. ;). |
| 11 | 11 | if ( ! function_exists( 'create_term_redux_users' ) ) { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Create_term_redux_users. |
|
| 15 | - * |
|
| 16 | - * @param string $profile_id Profile ID. |
|
| 17 | - */ |
|
| 18 | - function create_term_redux_users( string $profile_id ) { |
|
| 19 | - $instances = Redux::all_instances(); |
|
| 13 | + /** |
|
| 14 | + * Create_term_redux_users. |
|
| 15 | + * |
|
| 16 | + * @param string $profile_id Profile ID. |
|
| 17 | + */ |
|
| 18 | + function create_term_redux_users( string $profile_id ) { |
|
| 19 | + $instances = Redux::all_instances(); |
|
| 20 | 20 | |
| 21 | - foreach ( $_POST as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 22 | - if ( is_array( $value ) && isset( $instances[ $key ] ) ) { |
|
| 23 | - $instances[ $key ]->extensions['users']->user_meta_save( $profile_id ); |
|
| 24 | - } |
|
| 25 | - } |
|
| 26 | - } |
|
| 21 | + foreach ( $_POST as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 22 | + if ( is_array( $value ) && isset( $instances[ $key ] ) ) { |
|
| 23 | + $instances[ $key ]->extensions['users']->user_meta_save( $profile_id ); |
|
| 24 | + } |
|
| 25 | + } |
|
| 26 | + } |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | add_action( 'create_term', 'create_term_redux_users', 4 ); |
@@ -19,8 +19,8 @@ |
||
| 19 | 19 | $instances = Redux::all_instances(); |
| 20 | 20 | |
| 21 | 21 | foreach ( $_POST as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 22 | - if ( is_array( $value ) && isset( $instances[ $key ] ) ) { |
|
| 23 | - $instances[ $key ]->extensions['users']->user_meta_save( $profile_id ); |
|
| 22 | + if ( is_array( $value ) && isset( $instances[$key] ) ) { |
|
| 23 | + $instances[$key]->extensions['users']->user_meta_save( $profile_id ); |
|
| 24 | 24 | } |
| 25 | 25 | } |
| 26 | 26 | } |
@@ -12,347 +12,347 @@ |
||
| 12 | 12 | // Don't duplicate me! |
| 13 | 13 | if ( ! class_exists( 'Redux_Link_Color', false ) ) { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Main Redux_link_color class |
|
| 17 | - * |
|
| 18 | - * @since 1.0.0 |
|
| 19 | - */ |
|
| 20 | - class Redux_Link_Color extends Redux_Field { |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Set field and value defaults. |
|
| 24 | - */ |
|
| 25 | - public function set_defaults() { |
|
| 26 | - $defaults = array( |
|
| 27 | - 'regular' => true, |
|
| 28 | - 'hover' => true, |
|
| 29 | - 'visited' => false, |
|
| 30 | - 'active' => true, |
|
| 31 | - 'focus' => false, |
|
| 32 | - ); |
|
| 33 | - |
|
| 34 | - $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 35 | - |
|
| 36 | - $defaults = array( |
|
| 37 | - 'regular' => '', |
|
| 38 | - 'hover' => '', |
|
| 39 | - 'visited' => '', |
|
| 40 | - 'active' => '', |
|
| 41 | - 'focus' => '', |
|
| 42 | - ); |
|
| 43 | - |
|
| 44 | - $this->value = wp_parse_args( $this->value, $defaults ); |
|
| 45 | - |
|
| 46 | - // In case user passes no default values. |
|
| 47 | - if ( isset( $this->field['default'] ) ) { |
|
| 48 | - $this->field['default'] = wp_parse_args( $this->field['default'], $defaults ); |
|
| 49 | - } else { |
|
| 50 | - $this->field['default'] = $defaults; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Field Render Function. |
|
| 56 | - * Takes the vars and outputs the HTML for the field in the settings. |
|
| 57 | - * |
|
| 58 | - * @since 1.0.0 |
|
| 59 | - * @access public |
|
| 60 | - * @return void |
|
| 61 | - */ |
|
| 62 | - public function render() { |
|
| 63 | - if ( true === $this->field['regular'] && false !== $this->field['default']['regular'] ) { |
|
| 64 | - echo '<span class="linkColor">'; |
|
| 65 | - echo '<strong>' . esc_html__( 'Regular', 'redux-framework' ) . '</strong> '; |
|
| 66 | - echo '<input '; |
|
| 67 | - echo 'id="' . esc_attr( $this->field['id'] ) . '-regular" '; |
|
| 68 | - echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[regular]"'; |
|
| 69 | - echo 'value="' . esc_attr( $this->value['regular'] ) . '"'; |
|
| 70 | - echo 'class="color-picker redux-color redux-color-regular redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 71 | - echo 'type="text"'; |
|
| 72 | - echo 'data-default-color="' . esc_attr( $this->field['default']['regular'] ) . '"'; |
|
| 73 | - |
|
| 74 | - $data = array( |
|
| 75 | - 'field' => $this->field, |
|
| 76 | - 'index' => 'regular', |
|
| 77 | - ); |
|
| 78 | - |
|
| 79 | - echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 80 | - |
|
| 81 | - echo '>'; |
|
| 82 | - echo '</span>'; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if ( true === $this->field['hover'] && false !== $this->field['default']['hover'] ) { |
|
| 86 | - echo '<span class="linkColor">'; |
|
| 87 | - echo '<strong>' . esc_html__( 'Hover', 'redux-framework' ) . '</strong> '; |
|
| 88 | - echo '<input '; |
|
| 89 | - echo 'id="' . esc_attr( $this->field['id'] ) . '-hover"'; |
|
| 90 | - echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[hover]"'; |
|
| 91 | - echo 'value="' . esc_attr( $this->value['hover'] ) . '"'; |
|
| 92 | - echo 'class="color-picker redux-color redux-color-hover redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 93 | - echo 'type="text"'; |
|
| 94 | - echo 'data-default-color="' . esc_attr( $this->field['default']['hover'] ) . '"'; |
|
| 95 | - |
|
| 96 | - $data = array( |
|
| 97 | - 'field' => $this->field, |
|
| 98 | - 'index' => 'hover', |
|
| 99 | - ); |
|
| 100 | - |
|
| 101 | - echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 102 | - |
|
| 103 | - echo '>'; |
|
| 104 | - echo '</span>'; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if ( true === $this->field['visited'] && false !== $this->field['default']['visited'] ) { |
|
| 108 | - echo '<span class="linkColor">'; |
|
| 109 | - echo '<strong>' . esc_html__( 'Visited', 'redux-framework' ) . '</strong> '; |
|
| 110 | - echo '<input '; |
|
| 111 | - echo 'id="' . esc_attr( $this->field['id'] ) . '-visited"'; |
|
| 112 | - echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[visited]"'; |
|
| 113 | - echo 'value="' . esc_attr( $this->value['visited'] ) . '"'; |
|
| 114 | - echo 'class="color-picker redux-color redux-color-visited redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 115 | - echo 'type="text"'; |
|
| 116 | - echo 'data-default-color="' . esc_attr( $this->field['default']['visited'] ) . '"'; |
|
| 117 | - |
|
| 118 | - $data = array( |
|
| 119 | - 'field' => $this->field, |
|
| 120 | - 'index' => 'visited', |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 124 | - |
|
| 125 | - echo '>'; |
|
| 126 | - echo '</span>'; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - if ( true === $this->field['active'] && false !== $this->field['default']['active'] ) { |
|
| 130 | - echo '<span class="linkColor">'; |
|
| 131 | - echo '<strong>' . esc_html__( 'Active', 'redux-framework' ) . '</strong> '; |
|
| 132 | - echo '<input '; |
|
| 133 | - echo 'id="' . esc_attr( $this->field['id'] ) . '-active"'; |
|
| 134 | - echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[active]"'; |
|
| 135 | - echo 'value="' . esc_attr( $this->value['active'] ) . '"'; |
|
| 136 | - echo 'class="color-picker redux-color redux-color-active redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 137 | - echo 'type="text"'; |
|
| 138 | - echo 'data-default-color="' . esc_attr( $this->field['default']['active'] ) . '"'; |
|
| 139 | - |
|
| 140 | - $data = array( |
|
| 141 | - 'field' => $this->field, |
|
| 142 | - 'index' => 'active', |
|
| 143 | - ); |
|
| 144 | - |
|
| 145 | - echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 146 | - |
|
| 147 | - echo '>'; |
|
| 148 | - echo '</span>'; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - if ( true === $this->field['focus'] && false !== $this->field['default']['focus'] ) { |
|
| 152 | - echo '<span class="linkColor">'; |
|
| 153 | - echo '<strong>' . esc_html__( 'Focus', 'redux-framework' ) . '</strong> '; |
|
| 154 | - echo '<input '; |
|
| 155 | - echo 'id="' . esc_attr( $this->field['id'] ) . '-focus"'; |
|
| 156 | - echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[focus]"'; |
|
| 157 | - echo 'value="' . esc_attr( $this->value['focus'] ) . '"'; |
|
| 158 | - echo 'class="color-picker redux-color redux-color-focus redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 159 | - echo 'type="text"'; |
|
| 160 | - echo 'data-default-color="' . esc_attr( $this->field['default']['focus'] ) . '"'; |
|
| 161 | - |
|
| 162 | - $data = array( |
|
| 163 | - 'field' => $this->field, |
|
| 164 | - 'index' => 'focus', |
|
| 165 | - ); |
|
| 166 | - |
|
| 167 | - echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 168 | - |
|
| 169 | - echo '>'; |
|
| 170 | - echo '</span>'; |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * Do enqueue for each field instance. |
|
| 177 | - * |
|
| 178 | - * @return void |
|
| 179 | - */ |
|
| 180 | - public function always_enqueue() { |
|
| 181 | - if ( isset( $this->field['color_alpha'] ) && $this->field['color_alpha'] ) { |
|
| 182 | - if ( ! wp_script_is( 'redux-wp-color-picker-alpha' ) ) { |
|
| 183 | - wp_enqueue_script( 'redux-wp-color-picker-alpha' ); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Enqueue Function. |
|
| 190 | - * If this field requires any scripts, or CSS define this function and register/enqueue the scripts/css |
|
| 191 | - * |
|
| 192 | - * @since 1.0.0 |
|
| 193 | - * @access public |
|
| 194 | - * @return void |
|
| 195 | - */ |
|
| 196 | - public function enqueue() { |
|
| 197 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 198 | - |
|
| 199 | - $dep_array = array( 'jquery', 'wp-color-picker', 'redux-js' ); |
|
| 200 | - |
|
| 201 | - wp_enqueue_script( |
|
| 202 | - 'redux-field-link-color', |
|
| 203 | - Redux_Core::$url . 'inc/fields/link_color/redux-link-color' . Redux_Functions::is_min() . '.js', |
|
| 204 | - $dep_array, |
|
| 205 | - $this->timestamp, |
|
| 206 | - true |
|
| 207 | - ); |
|
| 208 | - |
|
| 209 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 210 | - wp_enqueue_style( 'redux-color-picker' ); |
|
| 211 | - |
|
| 212 | - wp_enqueue_style( |
|
| 213 | - 'redux-field-link_color', |
|
| 214 | - Redux_Core::$url . 'inc/fields/link_color/redux-link-color.css', |
|
| 215 | - array(), |
|
| 216 | - $this->timestamp |
|
| 217 | - ); |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - /** |
|
| 222 | - * Compile CSS data for output. |
|
| 223 | - * |
|
| 224 | - * @param string $data CSS data. |
|
| 225 | - * |
|
| 226 | - * @return array |
|
| 227 | - */ |
|
| 228 | - public function css_style( $data ): array { |
|
| 229 | - $style = array(); |
|
| 230 | - |
|
| 231 | - if ( ! empty( $this->value['regular'] ) && true === $this->field['regular'] && false !== $this->field['default']['regular'] ) { |
|
| 232 | - $style[] = 'color:' . $this->value['regular'] . ';'; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - if ( ! empty( $this->value['visited'] ) && true === $this->field['visited'] && false !== $this->field['default']['visited'] ) { |
|
| 236 | - $style['visited'] = 'color:' . $this->value['visited'] . ';'; |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - if ( ! empty( $this->value['hover'] ) && true === $this->field['hover'] && false !== $this->field['default']['hover'] ) { |
|
| 240 | - $style['hover'] = 'color:' . $this->value['hover'] . ';'; |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - if ( ! empty( $this->value['active'] ) && true === $this->field['active'] && false !== $this->field['default']['active'] ) { |
|
| 244 | - $style['active'] = 'color:' . $this->value['active'] . ';'; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - if ( ! empty( $this->value['focus'] ) && true === $this->field['focus'] && false !== $this->field['default']['focus'] ) { |
|
| 248 | - $style['focus'] = 'color:' . $this->value['focus'] . ';'; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - return $style; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Output CSS/compiler. |
|
| 256 | - * |
|
| 257 | - * @param string|null|array $style Style to output. |
|
| 258 | - */ |
|
| 259 | - public function output( $style = '' ) { |
|
| 260 | - if ( ! empty( $style ) ) { |
|
| 261 | - if ( isset( $this->field['output'] ) && ! is_array( $this->field['output'] ) ) { |
|
| 262 | - $this->field['output'] = array( $this->field['output'] ); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) { |
|
| 266 | - $style_string = ''; |
|
| 267 | - |
|
| 268 | - if ( isset( $this->field['output']['important'] ) ) { |
|
| 269 | - if ( $this->field['output']['important'] ) { |
|
| 270 | - $style = str_replace( ';', ' !important;', $style ); |
|
| 271 | - } |
|
| 272 | - unset( $this->field['output']['important'] ); |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - foreach ( $style as $key => $value ) { |
|
| 276 | - if ( is_numeric( $key ) ) { |
|
| 277 | - $style_string .= implode( ',', $this->field['output'] ) . '{' . $value . '}'; |
|
| 278 | - } elseif ( 1 === count( $this->field['output'] ) ) { |
|
| 279 | - $elem = ''; |
|
| 280 | - |
|
| 281 | - foreach ( $this->field['output'] as $elem ) { |
|
| 282 | - break; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - if ( false !== strpos( $elem, ',' ) ) { |
|
| 286 | - $selector_arr = explode( ',', $elem ); |
|
| 287 | - $sel_list = ''; |
|
| 288 | - |
|
| 289 | - foreach ( $selector_arr as $selector ) { |
|
| 290 | - $sel_list .= $selector . ':' . $key . ','; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - $sel_list = rtrim( $sel_list, ',' ); |
|
| 294 | - $style_string .= $sel_list . '{' . $value . '}'; |
|
| 295 | - } else { |
|
| 296 | - $style_string .= $elem . ':' . $key . '{' . $value . '}'; |
|
| 297 | - } |
|
| 298 | - } else { |
|
| 299 | - $blah = ''; |
|
| 300 | - foreach ( $this->field['output'] as $sel ) { |
|
| 301 | - $blah .= $sel . ':' . $key . ','; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - $blah = substr( $blah, 0, strlen( $blah ) - 1 ); |
|
| 305 | - $style_string .= $blah . '{' . $value . '}'; |
|
| 306 | - } |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $this->parent->outputCSS .= $style_string; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - if ( isset( $this->field['compiler'] ) && ! is_array( $this->field['compiler'] ) ) { |
|
| 313 | - $this->field['compiler'] = array( $this->field['compiler'] ); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) { |
|
| 317 | - $style_string = ''; |
|
| 318 | - |
|
| 319 | - if ( isset( $this->field['compiler']['important'] ) ) { |
|
| 320 | - if ( $this->field['compiler']['important'] ) { |
|
| 321 | - $style = str_replace( ';', ' !important;', $style ); |
|
| 322 | - } |
|
| 323 | - unset( $this->field['compiler']['important'] ); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - foreach ( $style as $key => $value ) { |
|
| 327 | - if ( is_numeric( $key ) ) { |
|
| 328 | - $style_string .= implode( ',', $this->field['compiler'] ) . '{' . $value . '}'; |
|
| 329 | - } elseif ( 1 === count( $this->field['compiler'] ) ) { |
|
| 330 | - $style_string .= $this->field['compiler'][0] . ':' . $key . '{' . $value . '}'; |
|
| 331 | - } else { |
|
| 332 | - $blah = ''; |
|
| 333 | - foreach ( $this->field['compiler'] as $sel ) { |
|
| 334 | - $blah .= $sel . ':' . $key . ','; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - $blah = substr( $blah, 0, strlen( $blah ) - 1 ); |
|
| 338 | - $style_string .= $blah . '{' . $value . '}'; |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - $this->parent->compilerCSS .= $style_string; |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Enable output_variables to be generated. |
|
| 348 | - * |
|
| 349 | - * @since 4.0.3 |
|
| 350 | - * @return void |
|
| 351 | - */ |
|
| 352 | - public function output_variables() { |
|
| 353 | - // No code needed, just defining the method is enough. |
|
| 354 | - } |
|
| 355 | - } |
|
| 15 | + /** |
|
| 16 | + * Main Redux_link_color class |
|
| 17 | + * |
|
| 18 | + * @since 1.0.0 |
|
| 19 | + */ |
|
| 20 | + class Redux_Link_Color extends Redux_Field { |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Set field and value defaults. |
|
| 24 | + */ |
|
| 25 | + public function set_defaults() { |
|
| 26 | + $defaults = array( |
|
| 27 | + 'regular' => true, |
|
| 28 | + 'hover' => true, |
|
| 29 | + 'visited' => false, |
|
| 30 | + 'active' => true, |
|
| 31 | + 'focus' => false, |
|
| 32 | + ); |
|
| 33 | + |
|
| 34 | + $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 35 | + |
|
| 36 | + $defaults = array( |
|
| 37 | + 'regular' => '', |
|
| 38 | + 'hover' => '', |
|
| 39 | + 'visited' => '', |
|
| 40 | + 'active' => '', |
|
| 41 | + 'focus' => '', |
|
| 42 | + ); |
|
| 43 | + |
|
| 44 | + $this->value = wp_parse_args( $this->value, $defaults ); |
|
| 45 | + |
|
| 46 | + // In case user passes no default values. |
|
| 47 | + if ( isset( $this->field['default'] ) ) { |
|
| 48 | + $this->field['default'] = wp_parse_args( $this->field['default'], $defaults ); |
|
| 49 | + } else { |
|
| 50 | + $this->field['default'] = $defaults; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Field Render Function. |
|
| 56 | + * Takes the vars and outputs the HTML for the field in the settings. |
|
| 57 | + * |
|
| 58 | + * @since 1.0.0 |
|
| 59 | + * @access public |
|
| 60 | + * @return void |
|
| 61 | + */ |
|
| 62 | + public function render() { |
|
| 63 | + if ( true === $this->field['regular'] && false !== $this->field['default']['regular'] ) { |
|
| 64 | + echo '<span class="linkColor">'; |
|
| 65 | + echo '<strong>' . esc_html__( 'Regular', 'redux-framework' ) . '</strong> '; |
|
| 66 | + echo '<input '; |
|
| 67 | + echo 'id="' . esc_attr( $this->field['id'] ) . '-regular" '; |
|
| 68 | + echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[regular]"'; |
|
| 69 | + echo 'value="' . esc_attr( $this->value['regular'] ) . '"'; |
|
| 70 | + echo 'class="color-picker redux-color redux-color-regular redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 71 | + echo 'type="text"'; |
|
| 72 | + echo 'data-default-color="' . esc_attr( $this->field['default']['regular'] ) . '"'; |
|
| 73 | + |
|
| 74 | + $data = array( |
|
| 75 | + 'field' => $this->field, |
|
| 76 | + 'index' => 'regular', |
|
| 77 | + ); |
|
| 78 | + |
|
| 79 | + echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 80 | + |
|
| 81 | + echo '>'; |
|
| 82 | + echo '</span>'; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + if ( true === $this->field['hover'] && false !== $this->field['default']['hover'] ) { |
|
| 86 | + echo '<span class="linkColor">'; |
|
| 87 | + echo '<strong>' . esc_html__( 'Hover', 'redux-framework' ) . '</strong> '; |
|
| 88 | + echo '<input '; |
|
| 89 | + echo 'id="' . esc_attr( $this->field['id'] ) . '-hover"'; |
|
| 90 | + echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[hover]"'; |
|
| 91 | + echo 'value="' . esc_attr( $this->value['hover'] ) . '"'; |
|
| 92 | + echo 'class="color-picker redux-color redux-color-hover redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 93 | + echo 'type="text"'; |
|
| 94 | + echo 'data-default-color="' . esc_attr( $this->field['default']['hover'] ) . '"'; |
|
| 95 | + |
|
| 96 | + $data = array( |
|
| 97 | + 'field' => $this->field, |
|
| 98 | + 'index' => 'hover', |
|
| 99 | + ); |
|
| 100 | + |
|
| 101 | + echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 102 | + |
|
| 103 | + echo '>'; |
|
| 104 | + echo '</span>'; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if ( true === $this->field['visited'] && false !== $this->field['default']['visited'] ) { |
|
| 108 | + echo '<span class="linkColor">'; |
|
| 109 | + echo '<strong>' . esc_html__( 'Visited', 'redux-framework' ) . '</strong> '; |
|
| 110 | + echo '<input '; |
|
| 111 | + echo 'id="' . esc_attr( $this->field['id'] ) . '-visited"'; |
|
| 112 | + echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[visited]"'; |
|
| 113 | + echo 'value="' . esc_attr( $this->value['visited'] ) . '"'; |
|
| 114 | + echo 'class="color-picker redux-color redux-color-visited redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 115 | + echo 'type="text"'; |
|
| 116 | + echo 'data-default-color="' . esc_attr( $this->field['default']['visited'] ) . '"'; |
|
| 117 | + |
|
| 118 | + $data = array( |
|
| 119 | + 'field' => $this->field, |
|
| 120 | + 'index' => 'visited', |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 124 | + |
|
| 125 | + echo '>'; |
|
| 126 | + echo '</span>'; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + if ( true === $this->field['active'] && false !== $this->field['default']['active'] ) { |
|
| 130 | + echo '<span class="linkColor">'; |
|
| 131 | + echo '<strong>' . esc_html__( 'Active', 'redux-framework' ) . '</strong> '; |
|
| 132 | + echo '<input '; |
|
| 133 | + echo 'id="' . esc_attr( $this->field['id'] ) . '-active"'; |
|
| 134 | + echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[active]"'; |
|
| 135 | + echo 'value="' . esc_attr( $this->value['active'] ) . '"'; |
|
| 136 | + echo 'class="color-picker redux-color redux-color-active redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 137 | + echo 'type="text"'; |
|
| 138 | + echo 'data-default-color="' . esc_attr( $this->field['default']['active'] ) . '"'; |
|
| 139 | + |
|
| 140 | + $data = array( |
|
| 141 | + 'field' => $this->field, |
|
| 142 | + 'index' => 'active', |
|
| 143 | + ); |
|
| 144 | + |
|
| 145 | + echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 146 | + |
|
| 147 | + echo '>'; |
|
| 148 | + echo '</span>'; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + if ( true === $this->field['focus'] && false !== $this->field['default']['focus'] ) { |
|
| 152 | + echo '<span class="linkColor">'; |
|
| 153 | + echo '<strong>' . esc_html__( 'Focus', 'redux-framework' ) . '</strong> '; |
|
| 154 | + echo '<input '; |
|
| 155 | + echo 'id="' . esc_attr( $this->field['id'] ) . '-focus"'; |
|
| 156 | + echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[focus]"'; |
|
| 157 | + echo 'value="' . esc_attr( $this->value['focus'] ) . '"'; |
|
| 158 | + echo 'class="color-picker redux-color redux-color-focus redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 159 | + echo 'type="text"'; |
|
| 160 | + echo 'data-default-color="' . esc_attr( $this->field['default']['focus'] ) . '"'; |
|
| 161 | + |
|
| 162 | + $data = array( |
|
| 163 | + 'field' => $this->field, |
|
| 164 | + 'index' => 'focus', |
|
| 165 | + ); |
|
| 166 | + |
|
| 167 | + echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 168 | + |
|
| 169 | + echo '>'; |
|
| 170 | + echo '</span>'; |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * Do enqueue for each field instance. |
|
| 177 | + * |
|
| 178 | + * @return void |
|
| 179 | + */ |
|
| 180 | + public function always_enqueue() { |
|
| 181 | + if ( isset( $this->field['color_alpha'] ) && $this->field['color_alpha'] ) { |
|
| 182 | + if ( ! wp_script_is( 'redux-wp-color-picker-alpha' ) ) { |
|
| 183 | + wp_enqueue_script( 'redux-wp-color-picker-alpha' ); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Enqueue Function. |
|
| 190 | + * If this field requires any scripts, or CSS define this function and register/enqueue the scripts/css |
|
| 191 | + * |
|
| 192 | + * @since 1.0.0 |
|
| 193 | + * @access public |
|
| 194 | + * @return void |
|
| 195 | + */ |
|
| 196 | + public function enqueue() { |
|
| 197 | + wp_enqueue_style( 'wp-color-picker' ); |
|
| 198 | + |
|
| 199 | + $dep_array = array( 'jquery', 'wp-color-picker', 'redux-js' ); |
|
| 200 | + |
|
| 201 | + wp_enqueue_script( |
|
| 202 | + 'redux-field-link-color', |
|
| 203 | + Redux_Core::$url . 'inc/fields/link_color/redux-link-color' . Redux_Functions::is_min() . '.js', |
|
| 204 | + $dep_array, |
|
| 205 | + $this->timestamp, |
|
| 206 | + true |
|
| 207 | + ); |
|
| 208 | + |
|
| 209 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 210 | + wp_enqueue_style( 'redux-color-picker' ); |
|
| 211 | + |
|
| 212 | + wp_enqueue_style( |
|
| 213 | + 'redux-field-link_color', |
|
| 214 | + Redux_Core::$url . 'inc/fields/link_color/redux-link-color.css', |
|
| 215 | + array(), |
|
| 216 | + $this->timestamp |
|
| 217 | + ); |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + /** |
|
| 222 | + * Compile CSS data for output. |
|
| 223 | + * |
|
| 224 | + * @param string $data CSS data. |
|
| 225 | + * |
|
| 226 | + * @return array |
|
| 227 | + */ |
|
| 228 | + public function css_style( $data ): array { |
|
| 229 | + $style = array(); |
|
| 230 | + |
|
| 231 | + if ( ! empty( $this->value['regular'] ) && true === $this->field['regular'] && false !== $this->field['default']['regular'] ) { |
|
| 232 | + $style[] = 'color:' . $this->value['regular'] . ';'; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + if ( ! empty( $this->value['visited'] ) && true === $this->field['visited'] && false !== $this->field['default']['visited'] ) { |
|
| 236 | + $style['visited'] = 'color:' . $this->value['visited'] . ';'; |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + if ( ! empty( $this->value['hover'] ) && true === $this->field['hover'] && false !== $this->field['default']['hover'] ) { |
|
| 240 | + $style['hover'] = 'color:' . $this->value['hover'] . ';'; |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + if ( ! empty( $this->value['active'] ) && true === $this->field['active'] && false !== $this->field['default']['active'] ) { |
|
| 244 | + $style['active'] = 'color:' . $this->value['active'] . ';'; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + if ( ! empty( $this->value['focus'] ) && true === $this->field['focus'] && false !== $this->field['default']['focus'] ) { |
|
| 248 | + $style['focus'] = 'color:' . $this->value['focus'] . ';'; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + return $style; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Output CSS/compiler. |
|
| 256 | + * |
|
| 257 | + * @param string|null|array $style Style to output. |
|
| 258 | + */ |
|
| 259 | + public function output( $style = '' ) { |
|
| 260 | + if ( ! empty( $style ) ) { |
|
| 261 | + if ( isset( $this->field['output'] ) && ! is_array( $this->field['output'] ) ) { |
|
| 262 | + $this->field['output'] = array( $this->field['output'] ); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) { |
|
| 266 | + $style_string = ''; |
|
| 267 | + |
|
| 268 | + if ( isset( $this->field['output']['important'] ) ) { |
|
| 269 | + if ( $this->field['output']['important'] ) { |
|
| 270 | + $style = str_replace( ';', ' !important;', $style ); |
|
| 271 | + } |
|
| 272 | + unset( $this->field['output']['important'] ); |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + foreach ( $style as $key => $value ) { |
|
| 276 | + if ( is_numeric( $key ) ) { |
|
| 277 | + $style_string .= implode( ',', $this->field['output'] ) . '{' . $value . '}'; |
|
| 278 | + } elseif ( 1 === count( $this->field['output'] ) ) { |
|
| 279 | + $elem = ''; |
|
| 280 | + |
|
| 281 | + foreach ( $this->field['output'] as $elem ) { |
|
| 282 | + break; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + if ( false !== strpos( $elem, ',' ) ) { |
|
| 286 | + $selector_arr = explode( ',', $elem ); |
|
| 287 | + $sel_list = ''; |
|
| 288 | + |
|
| 289 | + foreach ( $selector_arr as $selector ) { |
|
| 290 | + $sel_list .= $selector . ':' . $key . ','; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + $sel_list = rtrim( $sel_list, ',' ); |
|
| 294 | + $style_string .= $sel_list . '{' . $value . '}'; |
|
| 295 | + } else { |
|
| 296 | + $style_string .= $elem . ':' . $key . '{' . $value . '}'; |
|
| 297 | + } |
|
| 298 | + } else { |
|
| 299 | + $blah = ''; |
|
| 300 | + foreach ( $this->field['output'] as $sel ) { |
|
| 301 | + $blah .= $sel . ':' . $key . ','; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + $blah = substr( $blah, 0, strlen( $blah ) - 1 ); |
|
| 305 | + $style_string .= $blah . '{' . $value . '}'; |
|
| 306 | + } |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + $this->parent->outputCSS .= $style_string; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + if ( isset( $this->field['compiler'] ) && ! is_array( $this->field['compiler'] ) ) { |
|
| 313 | + $this->field['compiler'] = array( $this->field['compiler'] ); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) { |
|
| 317 | + $style_string = ''; |
|
| 318 | + |
|
| 319 | + if ( isset( $this->field['compiler']['important'] ) ) { |
|
| 320 | + if ( $this->field['compiler']['important'] ) { |
|
| 321 | + $style = str_replace( ';', ' !important;', $style ); |
|
| 322 | + } |
|
| 323 | + unset( $this->field['compiler']['important'] ); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + foreach ( $style as $key => $value ) { |
|
| 327 | + if ( is_numeric( $key ) ) { |
|
| 328 | + $style_string .= implode( ',', $this->field['compiler'] ) . '{' . $value . '}'; |
|
| 329 | + } elseif ( 1 === count( $this->field['compiler'] ) ) { |
|
| 330 | + $style_string .= $this->field['compiler'][0] . ':' . $key . '{' . $value . '}'; |
|
| 331 | + } else { |
|
| 332 | + $blah = ''; |
|
| 333 | + foreach ( $this->field['compiler'] as $sel ) { |
|
| 334 | + $blah .= $sel . ':' . $key . ','; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + $blah = substr( $blah, 0, strlen( $blah ) - 1 ); |
|
| 338 | + $style_string .= $blah . '{' . $value . '}'; |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + $this->parent->compilerCSS .= $style_string; |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Enable output_variables to be generated. |
|
| 348 | + * |
|
| 349 | + * @since 4.0.3 |
|
| 350 | + * @return void |
|
| 351 | + */ |
|
| 352 | + public function output_variables() { |
|
| 353 | + // No code needed, just defining the method is enough. |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | class_alias( 'Redux_Link_Color', 'ReduxFramework_Link_Color' ); |
@@ -12,401 +12,401 @@ |
||
| 12 | 12 | // Don't duplicate me! |
| 13 | 13 | if ( ! class_exists( 'Redux_Slides', false ) ) { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Main Redux_slides class |
|
| 17 | - * |
|
| 18 | - * @since 1.0.0 |
|
| 19 | - */ |
|
| 20 | - class Redux_Slides extends Redux_Field { |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Set field and value defaults. |
|
| 24 | - */ |
|
| 25 | - public function set_defaults() { |
|
| 26 | - $defaults = array( |
|
| 27 | - 'show' => array( |
|
| 28 | - 'title' => true, |
|
| 29 | - 'description' => true, |
|
| 30 | - 'url' => true, |
|
| 31 | - ), |
|
| 32 | - 'content_title' => esc_html__( 'Slide', 'redux-framework' ), |
|
| 33 | - ); |
|
| 34 | - |
|
| 35 | - $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Field Render Function. |
|
| 40 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 41 | - * |
|
| 42 | - * @since 1.0.0 |
|
| 43 | - * @access public |
|
| 44 | - * @return void |
|
| 45 | - */ |
|
| 46 | - public function render() { |
|
| 47 | - // translators: New accordion title. |
|
| 48 | - echo '<div class="redux-slides-accordion" data-new-content-title="' . esc_attr( sprintf( __( 'New %s', 'redux-framework' ), $this->field['content_title'] ) ) . '">'; |
|
| 49 | - |
|
| 50 | - $x = 0; |
|
| 51 | - |
|
| 52 | - if ( is_array( $this->value ) && ! empty( $this->value ) ) { |
|
| 53 | - $slides = $this->value; |
|
| 54 | - |
|
| 55 | - foreach ( $slides as $slide ) { |
|
| 56 | - if ( empty( $slide ) ) { |
|
| 57 | - continue; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - $defaults = array( |
|
| 61 | - 'title' => '', |
|
| 62 | - 'description' => '', |
|
| 63 | - 'sort' => '', |
|
| 64 | - 'url' => '', |
|
| 65 | - 'image' => '', |
|
| 66 | - 'thumb' => '', |
|
| 67 | - 'attachment_id' => '', |
|
| 68 | - 'height' => '', |
|
| 69 | - 'width' => '', |
|
| 70 | - 'select' => array(), |
|
| 71 | - ); |
|
| 72 | - |
|
| 73 | - $slide = wp_parse_args( $slide, $defaults ); |
|
| 74 | - |
|
| 75 | - if ( empty( $slide['thumb'] ) && ! empty( $slide['attachment_id'] ) ) { |
|
| 76 | - $img = wp_get_attachment_image_src( $slide['attachment_id'], 'full' ); |
|
| 77 | - $slide['image'] = $img[0]; |
|
| 78 | - $slide['width'] = $img[1]; |
|
| 79 | - $slide['height'] = $img[2]; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - echo '<div class="redux-slides-accordion-group"><fieldset class="redux-field" data-id="' . esc_attr( $this->field['id'] ) . '"><h3><span class="redux-slides-header">' . esc_html( $slide['title'] ) . '</span></h3><div>'; |
|
| 83 | - |
|
| 84 | - $hide = ''; |
|
| 85 | - if ( empty( $slide['image'] ) ) { |
|
| 86 | - $hide = ' hide'; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $alt = wp_prepare_attachment_for_js( $slide['attachment_id'] ); |
|
| 90 | - $alt = $alt['alt'] ?? ''; |
|
| 91 | - |
|
| 92 | - echo '<div class="screenshot' . esc_attr( $hide ) . '">'; |
|
| 93 | - echo '<a class="of-uploaded-image" href="' . esc_url( $slide['image'] ) . '">'; |
|
| 94 | - echo '<img |
|
| 15 | + /** |
|
| 16 | + * Main Redux_slides class |
|
| 17 | + * |
|
| 18 | + * @since 1.0.0 |
|
| 19 | + */ |
|
| 20 | + class Redux_Slides extends Redux_Field { |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Set field and value defaults. |
|
| 24 | + */ |
|
| 25 | + public function set_defaults() { |
|
| 26 | + $defaults = array( |
|
| 27 | + 'show' => array( |
|
| 28 | + 'title' => true, |
|
| 29 | + 'description' => true, |
|
| 30 | + 'url' => true, |
|
| 31 | + ), |
|
| 32 | + 'content_title' => esc_html__( 'Slide', 'redux-framework' ), |
|
| 33 | + ); |
|
| 34 | + |
|
| 35 | + $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Field Render Function. |
|
| 40 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 41 | + * |
|
| 42 | + * @since 1.0.0 |
|
| 43 | + * @access public |
|
| 44 | + * @return void |
|
| 45 | + */ |
|
| 46 | + public function render() { |
|
| 47 | + // translators: New accordion title. |
|
| 48 | + echo '<div class="redux-slides-accordion" data-new-content-title="' . esc_attr( sprintf( __( 'New %s', 'redux-framework' ), $this->field['content_title'] ) ) . '">'; |
|
| 49 | + |
|
| 50 | + $x = 0; |
|
| 51 | + |
|
| 52 | + if ( is_array( $this->value ) && ! empty( $this->value ) ) { |
|
| 53 | + $slides = $this->value; |
|
| 54 | + |
|
| 55 | + foreach ( $slides as $slide ) { |
|
| 56 | + if ( empty( $slide ) ) { |
|
| 57 | + continue; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + $defaults = array( |
|
| 61 | + 'title' => '', |
|
| 62 | + 'description' => '', |
|
| 63 | + 'sort' => '', |
|
| 64 | + 'url' => '', |
|
| 65 | + 'image' => '', |
|
| 66 | + 'thumb' => '', |
|
| 67 | + 'attachment_id' => '', |
|
| 68 | + 'height' => '', |
|
| 69 | + 'width' => '', |
|
| 70 | + 'select' => array(), |
|
| 71 | + ); |
|
| 72 | + |
|
| 73 | + $slide = wp_parse_args( $slide, $defaults ); |
|
| 74 | + |
|
| 75 | + if ( empty( $slide['thumb'] ) && ! empty( $slide['attachment_id'] ) ) { |
|
| 76 | + $img = wp_get_attachment_image_src( $slide['attachment_id'], 'full' ); |
|
| 77 | + $slide['image'] = $img[0]; |
|
| 78 | + $slide['width'] = $img[1]; |
|
| 79 | + $slide['height'] = $img[2]; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + echo '<div class="redux-slides-accordion-group"><fieldset class="redux-field" data-id="' . esc_attr( $this->field['id'] ) . '"><h3><span class="redux-slides-header">' . esc_html( $slide['title'] ) . '</span></h3><div>'; |
|
| 83 | + |
|
| 84 | + $hide = ''; |
|
| 85 | + if ( empty( $slide['image'] ) ) { |
|
| 86 | + $hide = ' hide'; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $alt = wp_prepare_attachment_for_js( $slide['attachment_id'] ); |
|
| 90 | + $alt = $alt['alt'] ?? ''; |
|
| 91 | + |
|
| 92 | + echo '<div class="screenshot' . esc_attr( $hide ) . '">'; |
|
| 93 | + echo '<a class="of-uploaded-image" href="' . esc_url( $slide['image'] ) . '">'; |
|
| 94 | + echo '<img |
|
| 95 | 95 | class="redux-slides-image" |
| 96 | 96 | id="image_image_id_' . esc_attr( $x ) . '" src="' . esc_url( $slide['thumb'] ) . '" |
| 97 | 97 | alt="' . esc_attr( $alt ) . '" |
| 98 | 98 | target="_blank" rel="external" />'; |
| 99 | 99 | |
| 100 | - echo '</a>'; |
|
| 101 | - echo '</div>'; |
|
| 100 | + echo '</a>'; |
|
| 101 | + echo '</div>'; |
|
| 102 | 102 | |
| 103 | - echo '<div class="redux_slides_add_remove">'; |
|
| 103 | + echo '<div class="redux_slides_add_remove">'; |
|
| 104 | 104 | |
| 105 | - echo '<span class="button media_upload_button" id="add_' . esc_attr( $x ) . '">' . esc_html__( 'Upload', 'redux-framework' ) . '</span>'; |
|
| 105 | + echo '<span class="button media_upload_button" id="add_' . esc_attr( $x ) . '">' . esc_html__( 'Upload', 'redux-framework' ) . '</span>'; |
|
| 106 | 106 | |
| 107 | - $hide = ''; |
|
| 108 | - if ( empty( $slide['image'] ) ) { |
|
| 109 | - $hide = ' hide'; |
|
| 110 | - } |
|
| 107 | + $hide = ''; |
|
| 108 | + if ( empty( $slide['image'] ) ) { |
|
| 109 | + $hide = ' hide'; |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - echo '<span |
|
| 112 | + echo '<span |
|
| 113 | 113 | class="button remove-image' . esc_attr( $hide ) . '" |
| 114 | 114 | id="reset_' . esc_attr( $x ) . '" |
| 115 | 115 | rel="' . esc_attr( $slide['attachment_id'] ) . '">' . |
| 116 | - esc_html__( 'Remove', 'redux-framework' ) . '</span>'; |
|
| 116 | + esc_html__( 'Remove', 'redux-framework' ) . '</span>'; |
|
| 117 | 117 | |
| 118 | - echo '</div>' . "\n"; |
|
| 118 | + echo '</div>' . "\n"; |
|
| 119 | 119 | |
| 120 | - echo '<ul id="' . esc_attr( $this->field['id'] ) . '-ul" class="redux-slides-list">'; |
|
| 120 | + echo '<ul id="' . esc_attr( $this->field['id'] ) . '-ul" class="redux-slides-list">'; |
|
| 121 | 121 | |
| 122 | - if ( $this->field['show']['title'] ) { |
|
| 123 | - $title_type = 'text'; |
|
| 124 | - } else { |
|
| 125 | - $title_type = 'hidden'; |
|
| 126 | - } |
|
| 122 | + if ( $this->field['show']['title'] ) { |
|
| 123 | + $title_type = 'text'; |
|
| 124 | + } else { |
|
| 125 | + $title_type = 'hidden'; |
|
| 126 | + } |
|
| 127 | 127 | |
| 128 | - $placeholder = ( isset( $this->field['placeholder']['title'] ) ) ? esc_attr( $this->field['placeholder']['title'] ) : __( 'Title', 'redux-framework' ); |
|
| 129 | - echo '<li>'; |
|
| 130 | - echo '<input |
|
| 128 | + $placeholder = ( isset( $this->field['placeholder']['title'] ) ) ? esc_attr( $this->field['placeholder']['title'] ) : __( 'Title', 'redux-framework' ); |
|
| 129 | + echo '<li>'; |
|
| 130 | + echo '<input |
|
| 131 | 131 | type="' . esc_attr( $title_type ) . '" |
| 132 | 132 | id="' . esc_attr( $this->field['id'] ) . '-title_' . esc_attr( $x ) . '" |
| 133 | 133 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][title]' . $this->field['name_suffix'] ) . '" |
| 134 | 134 | value="' . esc_attr( $slide['title'] ) . '" |
| 135 | 135 | placeholder="' . esc_attr( $placeholder ) . '" class="full-text slide-title" />'; |
| 136 | 136 | |
| 137 | - echo '</li>'; |
|
| 137 | + echo '</li>'; |
|
| 138 | 138 | |
| 139 | - if ( $this->field['show']['description'] ) { |
|
| 140 | - $placeholder = ( isset( $this->field['placeholder']['description'] ) ) ? esc_attr( $this->field['placeholder']['description'] ) : __( 'Description', 'redux-framework' ); |
|
| 141 | - echo '<li>'; |
|
| 142 | - echo '<textarea |
|
| 139 | + if ( $this->field['show']['description'] ) { |
|
| 140 | + $placeholder = ( isset( $this->field['placeholder']['description'] ) ) ? esc_attr( $this->field['placeholder']['description'] ) : __( 'Description', 'redux-framework' ); |
|
| 141 | + echo '<li>'; |
|
| 142 | + echo '<textarea |
|
| 143 | 143 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][description]' . $this->field['name_suffix'] ) . '" |
| 144 | 144 | id="' . esc_attr( $this->field['id'] ) . '-description_' . esc_attr( $x ) . '" |
| 145 | 145 | placeholder="' . esc_attr( $placeholder ) . '" |
| 146 | 146 | class="large-text" |
| 147 | 147 | rows="6">' . esc_textarea( $slide['description'] ) . '</textarea>'; |
| 148 | 148 | |
| 149 | - echo '</li>'; |
|
| 150 | - } |
|
| 149 | + echo '</li>'; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - $placeholder = ( isset( $this->field['placeholder']['url'] ) ) ? esc_attr( $this->field['placeholder']['url'] ) : __( 'URL', 'redux-framework' ); |
|
| 153 | - if ( $this->field['show']['url'] ) { |
|
| 154 | - $url_type = 'text'; |
|
| 155 | - } else { |
|
| 156 | - $url_type = 'hidden'; |
|
| 157 | - } |
|
| 152 | + $placeholder = ( isset( $this->field['placeholder']['url'] ) ) ? esc_attr( $this->field['placeholder']['url'] ) : __( 'URL', 'redux-framework' ); |
|
| 153 | + if ( $this->field['show']['url'] ) { |
|
| 154 | + $url_type = 'text'; |
|
| 155 | + } else { |
|
| 156 | + $url_type = 'hidden'; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - echo '<li>'; |
|
| 160 | - echo '<input |
|
| 159 | + echo '<li>'; |
|
| 160 | + echo '<input |
|
| 161 | 161 | type="' . esc_attr( $url_type ) . '" |
| 162 | 162 | id="' . esc_attr( $this->field['id'] . '-url_' ) . esc_attr( $x ) . '" |
| 163 | 163 | name="' . esc_attr( $this->field['name'] . '[' . esc_attr( $x ) . '][url]' . $this->field['name_suffix'] ) . '" |
| 164 | 164 | value="' . esc_attr( $slide['url'] ) . '" |
| 165 | 165 | class="full-text" placeholder="' . esc_attr( $placeholder ) . '" />'; |
| 166 | - echo '</li>'; |
|
| 166 | + echo '</li>'; |
|
| 167 | 167 | |
| 168 | - echo '<li>'; |
|
| 169 | - echo '<input |
|
| 168 | + echo '<li>'; |
|
| 169 | + echo '<input |
|
| 170 | 170 | type="hidden" |
| 171 | 171 | class="slide-sort" |
| 172 | 172 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][sort]' . $this->field['name_suffix'] ) . '" |
| 173 | 173 | id="' . esc_attr( $this->field['id'] ) . '-sort_' . esc_attr( $x ) . '" |
| 174 | 174 | value="' . esc_attr( $slide['sort'] ) . '" />'; |
| 175 | 175 | |
| 176 | - echo '<li>'; |
|
| 177 | - echo '<input |
|
| 176 | + echo '<li>'; |
|
| 177 | + echo '<input |
|
| 178 | 178 | type="hidden" |
| 179 | 179 | class="upload-id" |
| 180 | 180 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][attachment_id]' . $this->field['name_suffix'] ) . '" |
| 181 | 181 | id="' . esc_attr( $this->field['id'] ) . '-image_id_' . esc_attr( $x ) . '" |
| 182 | 182 | value="' . esc_attr( $slide['attachment_id'] ) . '" />'; |
| 183 | 183 | |
| 184 | - echo '<input |
|
| 184 | + echo '<input |
|
| 185 | 185 | type="hidden" |
| 186 | 186 | class="upload" name="' . esc_attr( $this->field['name'] . '[' . $x . '][image]' . $this->field['name_suffix'] ) . '" |
| 187 | 187 | id="' . esc_attr( $this->field['id'] ) . '-image_url_' . esc_attr( $x ) . '" |
| 188 | 188 | value="' . esc_attr( $slide['image'] ) . '" readonly="readonly" />'; |
| 189 | 189 | |
| 190 | - echo '<input |
|
| 190 | + echo '<input |
|
| 191 | 191 | type="hidden" |
| 192 | 192 | class="upload-height" |
| 193 | 193 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][height]' . $this->field['name_suffix'] ) . '" |
| 194 | 194 | id="' . esc_attr( $this->field['id'] ) . '-image_height_' . esc_attr( $x ) . '" |
| 195 | 195 | value="' . esc_attr( $slide['height'] ) . '" />'; |
| 196 | 196 | |
| 197 | - echo '<input |
|
| 197 | + echo '<input |
|
| 198 | 198 | type="hidden" |
| 199 | 199 | class="upload-width" |
| 200 | 200 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][width]' . $this->field['name_suffix'] ) . '" |
| 201 | 201 | id="' . esc_attr( $this->field['id'] ) . '-image_width_' . esc_attr( $x ) . '" |
| 202 | 202 | value="' . esc_attr( $slide['width'] ) . '" />'; |
| 203 | 203 | |
| 204 | - echo '</li>'; |
|
| 204 | + echo '</li>'; |
|
| 205 | 205 | |
| 206 | - echo '<input |
|
| 206 | + echo '<input |
|
| 207 | 207 | type="hidden" |
| 208 | 208 | class="upload-thumbnail" |
| 209 | 209 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][thumb]' . $this->field['name_suffix'] ) . '" |
| 210 | 210 | id="' . esc_attr( $this->field['id'] ) . '-thumb_url_' . esc_attr( $x ) . '" |
| 211 | 211 | value="' . esc_attr( $slide['thumb'] ) . '" readonly="readonly" />'; |
| 212 | - echo '</li>'; |
|
| 212 | + echo '</li>'; |
|
| 213 | 213 | |
| 214 | - echo '<li>'; |
|
| 215 | - echo '<a href="javascript:void(0);" class="button deletion redux-slides-remove">' . esc_html__( 'Delete', 'redux-framework' ) . '</a>'; |
|
| 216 | - echo '</li>'; |
|
| 214 | + echo '<li>'; |
|
| 215 | + echo '<a href="javascript:void(0);" class="button deletion redux-slides-remove">' . esc_html__( 'Delete', 'redux-framework' ) . '</a>'; |
|
| 216 | + echo '</li>'; |
|
| 217 | 217 | |
| 218 | - echo '</ul>'; |
|
| 219 | - echo '</div>'; |
|
| 220 | - echo '</fieldset>'; |
|
| 221 | - echo '</div>'; |
|
| 218 | + echo '</ul>'; |
|
| 219 | + echo '</div>'; |
|
| 220 | + echo '</fieldset>'; |
|
| 221 | + echo '</div>'; |
|
| 222 | 222 | |
| 223 | - ++$x; |
|
| 224 | - } |
|
| 225 | - } |
|
| 223 | + ++$x; |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - if ( 0 === $x ) { |
|
| 228 | - echo '<div class="redux-slides-accordion-group">'; |
|
| 229 | - echo '<fieldset class="redux-field" data-id="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 230 | - echo '<h3>'; |
|
| 227 | + if ( 0 === $x ) { |
|
| 228 | + echo '<div class="redux-slides-accordion-group">'; |
|
| 229 | + echo '<fieldset class="redux-field" data-id="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 230 | + echo '<h3>'; |
|
| 231 | 231 | |
| 232 | - // translators: Content title for new accordion. |
|
| 233 | - echo '<span class="redux-slides-header">' . esc_html( sprintf( __( 'New %s', 'redux-framework' ), esc_attr( $this->field['content_title'] ) ) ) . '</span>'; |
|
| 234 | - echo '</h3>'; |
|
| 235 | - echo '<div>'; |
|
| 232 | + // translators: Content title for new accordion. |
|
| 233 | + echo '<span class="redux-slides-header">' . esc_html( sprintf( __( 'New %s', 'redux-framework' ), esc_attr( $this->field['content_title'] ) ) ) . '</span>'; |
|
| 234 | + echo '</h3>'; |
|
| 235 | + echo '<div>'; |
|
| 236 | 236 | |
| 237 | - $hide = ' hide'; |
|
| 237 | + $hide = ' hide'; |
|
| 238 | 238 | |
| 239 | - echo '<div class="screenshot' . esc_attr( $hide ) . '">'; |
|
| 240 | - echo '<a class="of-uploaded-image" href="">'; |
|
| 241 | - echo '<img class="redux-slides-image" id="image_image_id_' . esc_attr( $x ) . '" src="" alt="placeholder" target="_blank" rel="external" />'; |
|
| 242 | - echo '</a>'; |
|
| 243 | - echo '</div>'; |
|
| 239 | + echo '<div class="screenshot' . esc_attr( $hide ) . '">'; |
|
| 240 | + echo '<a class="of-uploaded-image" href="">'; |
|
| 241 | + echo '<img class="redux-slides-image" id="image_image_id_' . esc_attr( $x ) . '" src="" alt="placeholder" target="_blank" rel="external" />'; |
|
| 242 | + echo '</a>'; |
|
| 243 | + echo '</div>'; |
|
| 244 | 244 | |
| 245 | - // Upload controls DIV. |
|
| 246 | - echo '<div class="upload_button_div">'; |
|
| 245 | + // Upload controls DIV. |
|
| 246 | + echo '<div class="upload_button_div">'; |
|
| 247 | 247 | |
| 248 | - // If the user has WP3.5+ show upload/remove button. |
|
| 249 | - echo '<span class="button media_upload_button" id="add_' . esc_attr( $x ) . '">' . esc_html__( 'Upload', 'redux-framework' ) . '</span>'; |
|
| 248 | + // If the user has WP3.5+ show upload/remove button. |
|
| 249 | + echo '<span class="button media_upload_button" id="add_' . esc_attr( $x ) . '">' . esc_html__( 'Upload', 'redux-framework' ) . '</span>'; |
|
| 250 | 250 | |
| 251 | - echo '<span class="button remove-image' . esc_attr( $hide ) . '" id="reset_' . esc_attr( $x ) . '" rel="' . esc_attr( $this->parent->args['opt_name'] . '[' . $this->field['id'] ) . '][attachment_id]">' . esc_html__( 'Remove', 'redux-framework' ) . '</span>'; |
|
| 251 | + echo '<span class="button remove-image' . esc_attr( $hide ) . '" id="reset_' . esc_attr( $x ) . '" rel="' . esc_attr( $this->parent->args['opt_name'] . '[' . $this->field['id'] ) . '][attachment_id]">' . esc_html__( 'Remove', 'redux-framework' ) . '</span>'; |
|
| 252 | 252 | |
| 253 | - echo '</div>' . "\n"; |
|
| 253 | + echo '</div>' . "\n"; |
|
| 254 | 254 | |
| 255 | - echo '<ul id="' . esc_attr( $this->field['id'] ) . '-ul" class="redux-slides-list">'; |
|
| 255 | + echo '<ul id="' . esc_attr( $this->field['id'] ) . '-ul" class="redux-slides-list">'; |
|
| 256 | 256 | |
| 257 | - if ( $this->field['show']['title'] ) { |
|
| 258 | - $title_type = 'text'; |
|
| 259 | - } else { |
|
| 260 | - $title_type = 'hidden'; |
|
| 261 | - } |
|
| 257 | + if ( $this->field['show']['title'] ) { |
|
| 258 | + $title_type = 'text'; |
|
| 259 | + } else { |
|
| 260 | + $title_type = 'hidden'; |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - $placeholder = ( isset( $this->field['placeholder']['title'] ) ) ? esc_attr( $this->field['placeholder']['title'] ) : __( 'Title', 'redux-framework' ); |
|
| 263 | + $placeholder = ( isset( $this->field['placeholder']['title'] ) ) ? esc_attr( $this->field['placeholder']['title'] ) : __( 'Title', 'redux-framework' ); |
|
| 264 | 264 | |
| 265 | - echo '<li>'; |
|
| 266 | - echo '<input |
|
| 265 | + echo '<li>'; |
|
| 266 | + echo '<input |
|
| 267 | 267 | type="' . esc_attr( $title_type ) . '" |
| 268 | 268 | id="' . esc_attr( $this->field['id'] . '-title_' . $x ) . '" |
| 269 | 269 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][title]' . $this->field['name_suffix'] ) . '" |
| 270 | 270 | value="" |
| 271 | 271 | placeholder="' . esc_attr( $placeholder ) . '" |
| 272 | 272 | class="full-text slide-title" />'; |
| 273 | - echo '</li>'; |
|
| 273 | + echo '</li>'; |
|
| 274 | 274 | |
| 275 | - if ( $this->field['show']['description'] ) { |
|
| 276 | - $placeholder = ( isset( $this->field['placeholder']['description'] ) ) ? esc_attr( $this->field['placeholder']['description'] ) : __( 'Description', 'redux-framework' ); |
|
| 275 | + if ( $this->field['show']['description'] ) { |
|
| 276 | + $placeholder = ( isset( $this->field['placeholder']['description'] ) ) ? esc_attr( $this->field['placeholder']['description'] ) : __( 'Description', 'redux-framework' ); |
|
| 277 | 277 | |
| 278 | - echo '<li>'; |
|
| 279 | - echo '<textarea |
|
| 278 | + echo '<li>'; |
|
| 279 | + echo '<textarea |
|
| 280 | 280 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][description]' . $this->field['name_suffix'] ) . '" |
| 281 | 281 | id="' . esc_attr( $this->field['id'] . '-description_' . $x ) . '" |
| 282 | 282 | placeholder="' . esc_attr( $placeholder ) . '" |
| 283 | 283 | class="large-text" |
| 284 | 284 | rows="6"></textarea>'; |
| 285 | - echo '</li>'; |
|
| 286 | - } |
|
| 285 | + echo '</li>'; |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - $placeholder = ( isset( $this->field['placeholder']['url'] ) ) ? esc_attr( $this->field['placeholder']['url'] ) : __( 'URL', 'redux-framework' ); |
|
| 288 | + $placeholder = ( isset( $this->field['placeholder']['url'] ) ) ? esc_attr( $this->field['placeholder']['url'] ) : __( 'URL', 'redux-framework' ); |
|
| 289 | 289 | |
| 290 | - if ( $this->field['show']['url'] ) { |
|
| 291 | - $url_type = 'text'; |
|
| 292 | - } else { |
|
| 293 | - $url_type = 'hidden'; |
|
| 294 | - } |
|
| 290 | + if ( $this->field['show']['url'] ) { |
|
| 291 | + $url_type = 'text'; |
|
| 292 | + } else { |
|
| 293 | + $url_type = 'hidden'; |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - echo '<li>'; |
|
| 297 | - echo '<input |
|
| 296 | + echo '<li>'; |
|
| 297 | + echo '<input |
|
| 298 | 298 | type="' . esc_attr( $url_type ) . '" |
| 299 | 299 | id="' . esc_attr( $this->field['id'] . '-url_' . $x ) . '" |
| 300 | 300 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][url]' . $this->field['name_suffix'] ) . '" |
| 301 | 301 | value="" class="full-text" placeholder="' . esc_attr( $placeholder ) . '" />'; |
| 302 | - echo '</li>'; |
|
| 302 | + echo '</li>'; |
|
| 303 | 303 | |
| 304 | - echo '<li>'; |
|
| 305 | - echo '<input |
|
| 304 | + echo '<li>'; |
|
| 305 | + echo '<input |
|
| 306 | 306 | type="hidden" |
| 307 | 307 | class="slide-sort" |
| 308 | 308 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][sort]' . $this->field['name_suffix'] ) . '" |
| 309 | 309 | id="' . esc_attr( $this->field['id'] . '-sort_' . $x ) . '" |
| 310 | 310 | value="' . esc_attr( $x ) . '" />'; |
| 311 | 311 | |
| 312 | - echo '<li>'; |
|
| 313 | - echo '<input |
|
| 312 | + echo '<li>'; |
|
| 313 | + echo '<input |
|
| 314 | 314 | type="hidden" |
| 315 | 315 | class="upload-id" |
| 316 | 316 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][attachment_id]' . $this->field['name_suffix'] ) . '" |
| 317 | 317 | id="' . esc_attr( $this->field['id'] . '-image_id_' . $x ) . '" |
| 318 | 318 | value="" />'; |
| 319 | 319 | |
| 320 | - echo '<input |
|
| 320 | + echo '<input |
|
| 321 | 321 | type="hidden" |
| 322 | 322 | class="upload" |
| 323 | 323 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][image]' . $this->field['name_suffix'] ) . '" |
| 324 | 324 | id="' . esc_attr( $this->field['id'] . '-image_url_' . $x ) . '" |
| 325 | 325 | value="" readonly="readonly" />'; |
| 326 | 326 | |
| 327 | - echo '<input |
|
| 327 | + echo '<input |
|
| 328 | 328 | type="hidden" |
| 329 | 329 | class="upload-height" |
| 330 | 330 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][height]' . $this->field['name_suffix'] ) . '" |
| 331 | 331 | id="' . esc_attr( $this->field['id'] . '-image_height_' . $x ) . '" |
| 332 | 332 | value="" />'; |
| 333 | 333 | |
| 334 | - echo '<input |
|
| 334 | + echo '<input |
|
| 335 | 335 | type="hidden" |
| 336 | 336 | class="upload-width" |
| 337 | 337 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][width]' . $this->field['name_suffix'] ) . '" |
| 338 | 338 | id="' . esc_attr( $this->field['id'] . '-image_width_' . $x ) . '" |
| 339 | 339 | value="" />'; |
| 340 | - echo '</li>'; |
|
| 340 | + echo '</li>'; |
|
| 341 | 341 | |
| 342 | - echo '<input |
|
| 342 | + echo '<input |
|
| 343 | 343 | type="hidden" |
| 344 | 344 | class="upload-thumbnail" |
| 345 | 345 | name="' . esc_attr( $this->field['name'] . '[' . $x . '][thumb]' . $this->field['name_suffix'] ) . '" |
| 346 | 346 | id="' . esc_attr( $this->field['id'] . '-thumb_url_' . $x ) . '" |
| 347 | 347 | value="" />'; |
| 348 | - echo '</li>'; |
|
| 349 | - |
|
| 350 | - echo '<li>'; |
|
| 351 | - echo '<a href="javascript:void(0);" class="button deletion redux-slides-remove">' . esc_html__( 'Delete', 'redux-framework' ) . '</a>'; |
|
| 352 | - echo '</li>'; |
|
| 353 | - |
|
| 354 | - echo '</ul>'; |
|
| 355 | - echo '</div>'; |
|
| 356 | - echo '</fieldset>'; |
|
| 357 | - echo '</div>'; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - echo '</div>'; |
|
| 361 | - |
|
| 362 | - // translators: Content title for accordion. |
|
| 363 | - echo '<a href="javascript:void(0);" class="button redux-slides-add button-primary" rel-id="' . esc_attr( $this->field['id'] ) . '-ul" rel-name="' . esc_attr( $this->field['name'] . '[title][]' . $this->field['name_suffix'] ) . '">' . esc_html( sprintf( __( 'Add %s', 'redux-framework' ), esc_html( $this->field['content_title'] ) ) ) . '</a>'; |
|
| 364 | - echo '<br/>'; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - /** |
|
| 368 | - * Enqueue Function. |
|
| 369 | - * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 370 | - * |
|
| 371 | - * @since 1.0.0 |
|
| 372 | - * @access public |
|
| 373 | - * @return void |
|
| 374 | - */ |
|
| 375 | - public function enqueue() { |
|
| 376 | - if ( function_exists( 'wp_enqueue_media' ) ) { |
|
| 377 | - wp_enqueue_media(); |
|
| 378 | - } else { |
|
| 379 | - wp_enqueue_script( 'media-upload' ); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 383 | - wp_enqueue_style( 'redux-field-media' ); |
|
| 384 | - |
|
| 385 | - wp_enqueue_style( |
|
| 386 | - 'redux-field-slides', |
|
| 387 | - Redux_Core::$url . 'inc/fields/slides/redux-slides.css', |
|
| 388 | - array(), |
|
| 389 | - $this->timestamp |
|
| 390 | - ); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - wp_enqueue_script( |
|
| 394 | - 'redux-field-media', |
|
| 395 | - Redux_Core::$url . 'assets/js/media/media' . Redux_Functions::is_min() . '.js', |
|
| 396 | - array( 'jquery', 'redux-js' ), |
|
| 397 | - $this->timestamp, |
|
| 398 | - true |
|
| 399 | - ); |
|
| 400 | - |
|
| 401 | - wp_enqueue_script( |
|
| 402 | - 'redux-field-slides', |
|
| 403 | - Redux_Core::$url . 'inc/fields/slides/redux-slides' . Redux_Functions::is_min() . '.js', |
|
| 404 | - array( 'jquery', 'jquery-ui-core', 'jquery-ui-accordion', 'jquery-ui-sortable', 'redux-field-media' ), |
|
| 405 | - $this->timestamp, |
|
| 406 | - true |
|
| 407 | - ); |
|
| 408 | - } |
|
| 409 | - } |
|
| 348 | + echo '</li>'; |
|
| 349 | + |
|
| 350 | + echo '<li>'; |
|
| 351 | + echo '<a href="javascript:void(0);" class="button deletion redux-slides-remove">' . esc_html__( 'Delete', 'redux-framework' ) . '</a>'; |
|
| 352 | + echo '</li>'; |
|
| 353 | + |
|
| 354 | + echo '</ul>'; |
|
| 355 | + echo '</div>'; |
|
| 356 | + echo '</fieldset>'; |
|
| 357 | + echo '</div>'; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + echo '</div>'; |
|
| 361 | + |
|
| 362 | + // translators: Content title for accordion. |
|
| 363 | + echo '<a href="javascript:void(0);" class="button redux-slides-add button-primary" rel-id="' . esc_attr( $this->field['id'] ) . '-ul" rel-name="' . esc_attr( $this->field['name'] . '[title][]' . $this->field['name_suffix'] ) . '">' . esc_html( sprintf( __( 'Add %s', 'redux-framework' ), esc_html( $this->field['content_title'] ) ) ) . '</a>'; |
|
| 364 | + echo '<br/>'; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + /** |
|
| 368 | + * Enqueue Function. |
|
| 369 | + * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 370 | + * |
|
| 371 | + * @since 1.0.0 |
|
| 372 | + * @access public |
|
| 373 | + * @return void |
|
| 374 | + */ |
|
| 375 | + public function enqueue() { |
|
| 376 | + if ( function_exists( 'wp_enqueue_media' ) ) { |
|
| 377 | + wp_enqueue_media(); |
|
| 378 | + } else { |
|
| 379 | + wp_enqueue_script( 'media-upload' ); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 383 | + wp_enqueue_style( 'redux-field-media' ); |
|
| 384 | + |
|
| 385 | + wp_enqueue_style( |
|
| 386 | + 'redux-field-slides', |
|
| 387 | + Redux_Core::$url . 'inc/fields/slides/redux-slides.css', |
|
| 388 | + array(), |
|
| 389 | + $this->timestamp |
|
| 390 | + ); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + wp_enqueue_script( |
|
| 394 | + 'redux-field-media', |
|
| 395 | + Redux_Core::$url . 'assets/js/media/media' . Redux_Functions::is_min() . '.js', |
|
| 396 | + array( 'jquery', 'redux-js' ), |
|
| 397 | + $this->timestamp, |
|
| 398 | + true |
|
| 399 | + ); |
|
| 400 | + |
|
| 401 | + wp_enqueue_script( |
|
| 402 | + 'redux-field-slides', |
|
| 403 | + Redux_Core::$url . 'inc/fields/slides/redux-slides' . Redux_Functions::is_min() . '.js', |
|
| 404 | + array( 'jquery', 'jquery-ui-core', 'jquery-ui-accordion', 'jquery-ui-sortable', 'redux-field-media' ), |
|
| 405 | + $this->timestamp, |
|
| 406 | + true |
|
| 407 | + ); |
|
| 408 | + } |
|
| 409 | + } |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | class_alias( 'Redux_Slides', 'ReduxFramework_Slides' ); |
@@ -71,7 +71,7 @@ |
||
| 71 | 71 | data-placeholder="' . esc_attr( $placeholder ) . '" |
| 72 | 72 | name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '" |
| 73 | 73 | class="redux-select-item redux-select-images ' . esc_attr( $this->field['class'] ) . '"' . |
| 74 | - $width . ' rows="6"' . esc_attr( $select2_data ) . '>'; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 74 | + $width . ' rows="6"' . esc_attr( $select2_data ) . '>'; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 75 | 75 | |
| 76 | 76 | echo '<option></option>'; |
| 77 | 77 | |
@@ -12,169 +12,169 @@ |
||
| 12 | 12 | |
| 13 | 13 | if ( ! class_exists( 'Redux_Select_Image', false ) ) { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Class Redux_Select_Image |
|
| 17 | - */ |
|
| 18 | - class Redux_Select_Image extends Redux_Field { |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Set field defaults. |
|
| 22 | - */ |
|
| 23 | - public function set_defaults() { |
|
| 24 | - $defaults = array( |
|
| 25 | - 'options' => array(), |
|
| 26 | - 'placeholder' => esc_html__( 'Select an item', 'redux-framework' ), |
|
| 27 | - ); |
|
| 28 | - |
|
| 29 | - $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Field Render Function. |
|
| 34 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 35 | - * |
|
| 36 | - * @since ReduxFramework 1.0.0 |
|
| 37 | - */ |
|
| 38 | - public function render() { |
|
| 39 | - |
|
| 40 | - // If options is NOT empty, the process. |
|
| 41 | - if ( ! empty( $this->field['options'] ) ) { |
|
| 42 | - |
|
| 43 | - // bean counter. |
|
| 44 | - $x = 1; |
|
| 45 | - |
|
| 46 | - // Process width. |
|
| 47 | - if ( ! empty( $this->field['width'] ) ) { |
|
| 48 | - $width = ' style="width:' . esc_attr( $this->field['width'] ) . ';"'; |
|
| 49 | - } else { |
|
| 50 | - $width = ' style="width: 40%;"'; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - // Process placeholder. |
|
| 54 | - $placeholder = esc_attr( $this->field['placeholder'] ); |
|
| 55 | - |
|
| 56 | - $this->select2_config['allowClear'] = true; |
|
| 57 | - |
|
| 58 | - if ( isset( $this->field['select2'] ) ) { |
|
| 59 | - $this->field['select2'] = wp_parse_args( $this->field['select2'], $this->select2_config ); |
|
| 60 | - } else { |
|
| 61 | - $this->field['select2'] = $this->select2_config; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - $this->field['select2'] = Redux_Functions::sanitize_camel_case_array_keys( $this->field['select2'] ); |
|
| 65 | - |
|
| 66 | - $select2_data = Redux_Functions::create_data_string( $this->field['select2'] ); |
|
| 67 | - |
|
| 68 | - // Begin the <select> tag. |
|
| 69 | - echo '<select |
|
| 15 | + /** |
|
| 16 | + * Class Redux_Select_Image |
|
| 17 | + */ |
|
| 18 | + class Redux_Select_Image extends Redux_Field { |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Set field defaults. |
|
| 22 | + */ |
|
| 23 | + public function set_defaults() { |
|
| 24 | + $defaults = array( |
|
| 25 | + 'options' => array(), |
|
| 26 | + 'placeholder' => esc_html__( 'Select an item', 'redux-framework' ), |
|
| 27 | + ); |
|
| 28 | + |
|
| 29 | + $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Field Render Function. |
|
| 34 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 35 | + * |
|
| 36 | + * @since ReduxFramework 1.0.0 |
|
| 37 | + */ |
|
| 38 | + public function render() { |
|
| 39 | + |
|
| 40 | + // If options is NOT empty, the process. |
|
| 41 | + if ( ! empty( $this->field['options'] ) ) { |
|
| 42 | + |
|
| 43 | + // bean counter. |
|
| 44 | + $x = 1; |
|
| 45 | + |
|
| 46 | + // Process width. |
|
| 47 | + if ( ! empty( $this->field['width'] ) ) { |
|
| 48 | + $width = ' style="width:' . esc_attr( $this->field['width'] ) . ';"'; |
|
| 49 | + } else { |
|
| 50 | + $width = ' style="width: 40%;"'; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + // Process placeholder. |
|
| 54 | + $placeholder = esc_attr( $this->field['placeholder'] ); |
|
| 55 | + |
|
| 56 | + $this->select2_config['allowClear'] = true; |
|
| 57 | + |
|
| 58 | + if ( isset( $this->field['select2'] ) ) { |
|
| 59 | + $this->field['select2'] = wp_parse_args( $this->field['select2'], $this->select2_config ); |
|
| 60 | + } else { |
|
| 61 | + $this->field['select2'] = $this->select2_config; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + $this->field['select2'] = Redux_Functions::sanitize_camel_case_array_keys( $this->field['select2'] ); |
|
| 65 | + |
|
| 66 | + $select2_data = Redux_Functions::create_data_string( $this->field['select2'] ); |
|
| 67 | + |
|
| 68 | + // Begin the <select> tag. |
|
| 69 | + echo '<select |
|
| 70 | 70 | data-id="' . esc_attr( $this->field['id'] ) . '" |
| 71 | 71 | data-placeholder="' . esc_attr( $placeholder ) . '" |
| 72 | 72 | name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '" |
| 73 | 73 | class="redux-select-item redux-select-images ' . esc_attr( $this->field['class'] ) . '"' . |
| 74 | - $width . ' rows="6"' . esc_attr( $select2_data ) . '>'; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 75 | - |
|
| 76 | - echo '<option></option>'; |
|
| 77 | - |
|
| 78 | - // Enum through the options array. |
|
| 79 | - foreach ( $this->field['options'] as $v ) { |
|
| 80 | - |
|
| 81 | - // No array? No problem! |
|
| 82 | - if ( ! is_array( $v ) ) { |
|
| 83 | - $v = array( 'img' => $v ); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // No title set? Make it blank. |
|
| 87 | - if ( ! isset( $v['title'] ) ) { |
|
| 88 | - $v['title'] = ''; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - // No alt? Set it to title. We do this so the alt tag shows |
|
| 92 | - // something. It also makes HTML/SEO purists happy. |
|
| 93 | - if ( ! isset( $v['alt'] ) ) { |
|
| 94 | - $v['alt'] = $v['title']; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // Set the selected entry. |
|
| 98 | - $selected = selected( $this->value, $v['img'], false ); |
|
| 99 | - |
|
| 100 | - // If selected returns something other than a blank space, we |
|
| 101 | - // found our default/saved name. Save the array number in a |
|
| 102 | - // variable to use later on when we want to extract its associated |
|
| 103 | - // url. |
|
| 104 | - if ( '' !== $selected ) { |
|
| 105 | - $arr_num = $x; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - // Add the option tag, with values. |
|
| 109 | - echo '<option value="' . esc_url( $v['img'] ) . '" ' . esc_html( $selected ) . '>' . esc_attr( $v['alt'] ) . '</option>'; |
|
| 110 | - |
|
| 111 | - // Add a bean. |
|
| 112 | - ++$x; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // Close the <select> tag. |
|
| 116 | - echo '</select>'; |
|
| 117 | - |
|
| 118 | - // Some space. |
|
| 119 | - echo '<br /><br />'; |
|
| 120 | - |
|
| 121 | - // Show the preview image. |
|
| 122 | - echo '<div>'; |
|
| 123 | - |
|
| 124 | - // just in case. You never know. |
|
| 125 | - if ( ! isset( $arr_num ) ) { |
|
| 126 | - $this->value = ''; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // Set the default image. To get the url from the default name, |
|
| 130 | - // we save the array count from the for/each loop, when the default image |
|
| 131 | - // is mark as selected. Since the for/each loop starts at one, we must |
|
| 132 | - // subtract one from the saved array number. We then pull the url |
|
| 133 | - // out of the options array, and there we go. |
|
| 134 | - if ( '' === $this->value ) { |
|
| 135 | - // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage -- No image/icon to enqueue. |
|
| 136 | - echo '<img src="#" class="redux-preview-image" style="visibility:hidden;" id="image_' . esc_attr( $this->field['id'] ) . '">'; |
|
| 137 | - } else { |
|
| 138 | - // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage -- No image/icon to enqueue. |
|
| 139 | - echo '<img src=' . esc_url( $this->value ) . ' class="redux-preview-image" id="image_' . esc_attr( $this->field['id'] ) . '">'; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - // Close the <div> tag. |
|
| 143 | - echo '</div>'; |
|
| 144 | - } else { |
|
| 145 | - |
|
| 146 | - // No options specified. Really? |
|
| 147 | - echo '<strong>' . esc_html__( 'No items of this type were found.', 'redux-framework' ) . '</strong>'; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - /** |
|
| 152 | - * Enqueue Function. |
|
| 153 | - * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 154 | - * |
|
| 155 | - * @since ReduxFramework 1.0.0 |
|
| 156 | - */ |
|
| 157 | - public function enqueue() { |
|
| 158 | - wp_enqueue_style( 'select2-css' ); |
|
| 159 | - |
|
| 160 | - wp_enqueue_script( |
|
| 161 | - 'redux-field-select-image', |
|
| 162 | - Redux_Core::$url . 'inc/fields/select_image/redux-select-image' . Redux_Functions::is_min() . '.js', |
|
| 163 | - array( 'jquery', 'select2-js', 'redux-js' ), |
|
| 164 | - $this->timestamp, |
|
| 165 | - true |
|
| 166 | - ); |
|
| 167 | - |
|
| 168 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 169 | - wp_enqueue_style( |
|
| 170 | - 'redux-field-select-image', |
|
| 171 | - Redux_Core::$url . 'inc/fields/select_image/redux-select-image.css', |
|
| 172 | - array(), |
|
| 173 | - $this->timestamp |
|
| 174 | - ); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - } |
|
| 74 | + $width . ' rows="6"' . esc_attr( $select2_data ) . '>'; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 75 | + |
|
| 76 | + echo '<option></option>'; |
|
| 77 | + |
|
| 78 | + // Enum through the options array. |
|
| 79 | + foreach ( $this->field['options'] as $v ) { |
|
| 80 | + |
|
| 81 | + // No array? No problem! |
|
| 82 | + if ( ! is_array( $v ) ) { |
|
| 83 | + $v = array( 'img' => $v ); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // No title set? Make it blank. |
|
| 87 | + if ( ! isset( $v['title'] ) ) { |
|
| 88 | + $v['title'] = ''; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + // No alt? Set it to title. We do this so the alt tag shows |
|
| 92 | + // something. It also makes HTML/SEO purists happy. |
|
| 93 | + if ( ! isset( $v['alt'] ) ) { |
|
| 94 | + $v['alt'] = $v['title']; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // Set the selected entry. |
|
| 98 | + $selected = selected( $this->value, $v['img'], false ); |
|
| 99 | + |
|
| 100 | + // If selected returns something other than a blank space, we |
|
| 101 | + // found our default/saved name. Save the array number in a |
|
| 102 | + // variable to use later on when we want to extract its associated |
|
| 103 | + // url. |
|
| 104 | + if ( '' !== $selected ) { |
|
| 105 | + $arr_num = $x; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + // Add the option tag, with values. |
|
| 109 | + echo '<option value="' . esc_url( $v['img'] ) . '" ' . esc_html( $selected ) . '>' . esc_attr( $v['alt'] ) . '</option>'; |
|
| 110 | + |
|
| 111 | + // Add a bean. |
|
| 112 | + ++$x; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // Close the <select> tag. |
|
| 116 | + echo '</select>'; |
|
| 117 | + |
|
| 118 | + // Some space. |
|
| 119 | + echo '<br /><br />'; |
|
| 120 | + |
|
| 121 | + // Show the preview image. |
|
| 122 | + echo '<div>'; |
|
| 123 | + |
|
| 124 | + // just in case. You never know. |
|
| 125 | + if ( ! isset( $arr_num ) ) { |
|
| 126 | + $this->value = ''; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // Set the default image. To get the url from the default name, |
|
| 130 | + // we save the array count from the for/each loop, when the default image |
|
| 131 | + // is mark as selected. Since the for/each loop starts at one, we must |
|
| 132 | + // subtract one from the saved array number. We then pull the url |
|
| 133 | + // out of the options array, and there we go. |
|
| 134 | + if ( '' === $this->value ) { |
|
| 135 | + // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage -- No image/icon to enqueue. |
|
| 136 | + echo '<img src="#" class="redux-preview-image" style="visibility:hidden;" id="image_' . esc_attr( $this->field['id'] ) . '">'; |
|
| 137 | + } else { |
|
| 138 | + // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage -- No image/icon to enqueue. |
|
| 139 | + echo '<img src=' . esc_url( $this->value ) . ' class="redux-preview-image" id="image_' . esc_attr( $this->field['id'] ) . '">'; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + // Close the <div> tag. |
|
| 143 | + echo '</div>'; |
|
| 144 | + } else { |
|
| 145 | + |
|
| 146 | + // No options specified. Really? |
|
| 147 | + echo '<strong>' . esc_html__( 'No items of this type were found.', 'redux-framework' ) . '</strong>'; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + /** |
|
| 152 | + * Enqueue Function. |
|
| 153 | + * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 154 | + * |
|
| 155 | + * @since ReduxFramework 1.0.0 |
|
| 156 | + */ |
|
| 157 | + public function enqueue() { |
|
| 158 | + wp_enqueue_style( 'select2-css' ); |
|
| 159 | + |
|
| 160 | + wp_enqueue_script( |
|
| 161 | + 'redux-field-select-image', |
|
| 162 | + Redux_Core::$url . 'inc/fields/select_image/redux-select-image' . Redux_Functions::is_min() . '.js', |
|
| 163 | + array( 'jquery', 'select2-js', 'redux-js' ), |
|
| 164 | + $this->timestamp, |
|
| 165 | + true |
|
| 166 | + ); |
|
| 167 | + |
|
| 168 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 169 | + wp_enqueue_style( |
|
| 170 | + 'redux-field-select-image', |
|
| 171 | + Redux_Core::$url . 'inc/fields/select_image/redux-select-image.css', |
|
| 172 | + array(), |
|
| 173 | + $this->timestamp |
|
| 174 | + ); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | class_alias( 'Redux_Select_Image', 'ReduxFramework_Select_Image' ); |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | $the_value = $k; |
| 96 | 96 | |
| 97 | - if ( ! empty( $this->field['tiles'] ) && true === (bool) $this->field['tiles'] ) { |
|
| 97 | + if ( ! empty( $this->field['tiles'] ) && true === ( bool ) $this->field['tiles'] ) { |
|
| 98 | 98 | $the_value = $v['img']; |
| 99 | 99 | } |
| 100 | 100 | |
@@ -123,14 +123,14 @@ discard block |
||
| 123 | 123 | } else { |
| 124 | 124 | foreach ( $v['presets'] as $pk => $pv ) { |
| 125 | 125 | if ( isset( $v['merge'] ) && false !== $v['merge'] ) { |
| 126 | - if ( ( true === $v['merge'] || in_array( $pk, $v['merge'], true ) ) && is_array( $this->parent->options[ $pk ] ) ) { |
|
| 127 | - $pv = array_merge( $this->parent->options[ $pk ], $pv ); |
|
| 126 | + if ( ( true === $v['merge'] || in_array( $pk, $v['merge'], true ) ) && is_array( $this->parent->options[$pk] ) ) { |
|
| 127 | + $pv = array_merge( $this->parent->options[$pk], $pv ); |
|
| 128 | 128 | } |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - if ( empty( $pv ) && isset( $this->parent->options[ $pk ] ) && ! empty( $this->parent->options[ $pk ] ) ) { |
|
| 131 | + if ( empty( $pv ) && isset( $this->parent->options[$pk] ) && ! empty( $this->parent->options[$pk] ) ) { |
|
| 132 | 132 | $selected = false; |
| 133 | - } elseif ( ! empty( $pv ) && ! isset( $this->parent->options[ $pk ] ) ) { |
|
| 133 | + } elseif ( ! empty( $pv ) && ! isset( $this->parent->options[$pk] ) ) { |
|
| 134 | 134 | $selected = false; |
| 135 | 135 | } |
| 136 | 136 | |
@@ -227,10 +227,10 @@ discard block |
||
| 227 | 227 | if ( ! empty( $data ) && ! is_array( $data ) ) { |
| 228 | 228 | switch ( $mode ) { |
| 229 | 229 | case 'background-image': |
| 230 | - if ( isset( $this->field['tiles'] ) && true === (bool) $this->field['tiles'] ) { |
|
| 230 | + if ( isset( $this->field['tiles'] ) && true === ( bool ) $this->field['tiles'] ) { |
|
| 231 | 231 | $img = $data; |
| 232 | 232 | } else { |
| 233 | - $img = $this->field['options'][ $data ]['img'] ?? ''; |
|
| 233 | + $img = $this->field['options'][$data]['img'] ?? ''; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | if ( '' !== $img ) { |
@@ -12,243 +12,243 @@ |
||
| 12 | 12 | // Don't duplicate me! |
| 13 | 13 | if ( ! class_exists( 'Redux_Image_Select', false ) ) { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Main Redux_image_select class |
|
| 17 | - * |
|
| 18 | - * @since 1.0.0 |
|
| 19 | - */ |
|
| 20 | - class Redux_Image_Select extends Redux_Field { |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Set field defaults. |
|
| 24 | - */ |
|
| 25 | - public function set_defaults() { |
|
| 26 | - $defaults = array( |
|
| 27 | - 'tiles' => false, |
|
| 28 | - 'mode' => 'background-image', |
|
| 29 | - 'presets' => false, |
|
| 30 | - 'options' => array(), |
|
| 31 | - 'width' => '', |
|
| 32 | - 'height' => '', |
|
| 33 | - ); |
|
| 34 | - |
|
| 35 | - $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Field Render Function. |
|
| 40 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 41 | - * |
|
| 42 | - * @since 1.0.0 |
|
| 43 | - * @access public |
|
| 44 | - * @return void |
|
| 45 | - */ |
|
| 46 | - public function render() { |
|
| 47 | - if ( ! empty( $this->field['options'] ) ) { |
|
| 48 | - echo '<div class="redux-table-container">'; |
|
| 49 | - echo '<ul class="redux-image-select">'; |
|
| 50 | - |
|
| 51 | - $x = 1; |
|
| 52 | - |
|
| 53 | - foreach ( $this->field['options'] as $k => $v ) { |
|
| 54 | - |
|
| 55 | - if ( ! is_array( $v ) ) { |
|
| 56 | - $v = array( 'img' => $v ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - if ( ! isset( $v['title'] ) ) { |
|
| 60 | - $v['title'] = ''; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - if ( ! isset( $v['alt'] ) ) { |
|
| 64 | - $v['alt'] = $v['title']; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - if ( ! isset( $v['class'] ) ) { |
|
| 68 | - $v['class'] = ''; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $style = ''; |
|
| 72 | - |
|
| 73 | - if ( ! empty( $this->field['width'] ) ) { |
|
| 74 | - $style .= 'width: ' . $this->field['width']; |
|
| 75 | - |
|
| 76 | - if ( is_numeric( $this->field['width'] ) ) { |
|
| 77 | - $style .= 'px'; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - $style .= ';'; |
|
| 81 | - } else { |
|
| 82 | - $style .= ' width: 100%; '; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if ( ! empty( $this->field['height'] ) ) { |
|
| 86 | - $style .= 'height: ' . $this->field['height']; |
|
| 87 | - |
|
| 88 | - if ( is_numeric( $this->field['height'] ) ) { |
|
| 89 | - $style .= 'px'; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - $style .= ';'; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $the_value = $k; |
|
| 96 | - |
|
| 97 | - if ( ! empty( $this->field['tiles'] ) && true === (bool) $this->field['tiles'] ) { |
|
| 98 | - $the_value = $v['img']; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $selected = ( '' !== checked( $this->value, $the_value, false ) ) ? ' redux-image-select-selected' : ''; |
|
| 102 | - |
|
| 103 | - $presets = ''; |
|
| 104 | - $is_preset = false; |
|
| 105 | - |
|
| 106 | - $this->field['class'] = trim( str_replace( 'no-update', '', $this->field['class'] ) ); |
|
| 107 | - $this->field['class'] .= ' no-update '; |
|
| 108 | - |
|
| 109 | - if ( isset( $this->field['presets'] ) && false !== $this->field['presets'] ) { |
|
| 110 | - $this->field['class'] = trim( $this->field['class'] ); |
|
| 111 | - if ( ! isset( $v['presets'] ) ) { |
|
| 112 | - $v['presets'] = array(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - if ( ! is_array( $v['presets'] ) ) { |
|
| 116 | - $v['presets'] = json_decode( $v['presets'], true ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // Only highlight the preset if it's the same. |
|
| 120 | - if ( $selected ) { |
|
| 121 | - if ( empty( $v['presets'] ) ) { |
|
| 122 | - $selected = false; |
|
| 123 | - } else { |
|
| 124 | - foreach ( $v['presets'] as $pk => $pv ) { |
|
| 125 | - if ( isset( $v['merge'] ) && false !== $v['merge'] ) { |
|
| 126 | - if ( ( true === $v['merge'] || in_array( $pk, $v['merge'], true ) ) && is_array( $this->parent->options[ $pk ] ) ) { |
|
| 127 | - $pv = array_merge( $this->parent->options[ $pk ], $pv ); |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - if ( empty( $pv ) && isset( $this->parent->options[ $pk ] ) && ! empty( $this->parent->options[ $pk ] ) ) { |
|
| 132 | - $selected = false; |
|
| 133 | - } elseif ( ! empty( $pv ) && ! isset( $this->parent->options[ $pk ] ) ) { |
|
| 134 | - $selected = false; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - if ( ! $selected ) { // We're still not using the same preset. Let's unset that shall we? |
|
| 138 | - $this->value = ''; |
|
| 139 | - break; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $v['presets']['redux-backup'] = 1; |
|
| 146 | - |
|
| 147 | - $presets = ' data-presets="' . esc_attr( htmlspecialchars( wp_json_encode( $v['presets'] ), ENT_QUOTES ) ) . '"'; |
|
| 148 | - $is_preset = true; |
|
| 149 | - |
|
| 150 | - $this->field['class'] = trim( $this->field['class'] ) . ' redux-presets'; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - $is_preset_class = $is_preset ? '-preset-' : ' '; |
|
| 154 | - |
|
| 155 | - $merge = ''; |
|
| 156 | - if ( isset( $v['merge'] ) && false !== $v['merge'] ) { |
|
| 157 | - $merge = is_array( $v['merge'] ) ? implode( '|', $v['merge'] ) : 'true'; |
|
| 158 | - $merge = ' data-merge="' . esc_attr( htmlspecialchars( $merge, ENT_QUOTES ) ) . '"'; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - echo '<li class="redux-image-select">'; |
|
| 162 | - echo '<label class="' . esc_attr( $selected ) . ' redux-image-select' . esc_attr( $is_preset_class ) . esc_attr( $this->field['id'] . '_' . $x ) . '" for="' . esc_attr( $this->field['id'] . '_' . ( array_search( $k, array_keys( $this->field['options'] ), true ) + 1 ) ) . '">'; |
|
| 163 | - // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 164 | - echo '<input type="radio" class="' . esc_attr( $this->field['class'] ) . '" id="' . esc_attr( $this->field['id'] . '_' . ( array_search( $k, array_keys( $this->field['options'] ), true ) + 1 ) ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '" value="' . esc_attr( $the_value ) . '" ' . checked( $this->value, $the_value, false ) . $presets . $merge . '/>'; |
|
| 165 | - if ( ! empty( $this->field['tiles'] ) && true === $this->field['tiles'] ) { |
|
| 166 | - echo '<span class="tiles ' . esc_attr( $v['class'] ) . '" style="background-image: url(' . esc_url( $v['img'] ) . ');" rel="' . esc_url( $v['img'] ) . '""> </span>'; |
|
| 167 | - } else { |
|
| 168 | - // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage -- No image/icon to enqueue. |
|
| 169 | - echo '<img src="' . esc_url( $v['img'] ) . '" title="' . esc_attr( $v['alt'] ) . '" alt="' . esc_attr( $v['alt'] ) . '" class="' . esc_attr( $v['class'] ) . '" style="' . esc_attr( $style ) . '"' . esc_attr( $presets ) . esc_attr( $merge ) . ' />'; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if ( '' !== $v['title'] ) { |
|
| 173 | - echo '<br /><span>' . wp_kses_post( ( $v['title'] ) ) . '</span>'; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - echo '</label>'; |
|
| 177 | - echo '</li>'; |
|
| 178 | - |
|
| 179 | - ++$x; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - echo '</ul>'; |
|
| 183 | - echo '</div>'; |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Enqueue Function. |
|
| 189 | - * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 190 | - * |
|
| 191 | - * @since 1.0.0 |
|
| 192 | - * @access public |
|
| 193 | - * @return void |
|
| 194 | - */ |
|
| 195 | - public function enqueue() { |
|
| 196 | - |
|
| 197 | - wp_enqueue_script( |
|
| 198 | - 'redux-field-image-select', |
|
| 199 | - Redux_Core::$url . 'inc/fields/image_select/redux-image-select' . Redux_Functions::is_min() . '.js', |
|
| 200 | - array( 'jquery', 'redux-js' ), |
|
| 201 | - $this->timestamp, |
|
| 202 | - true |
|
| 203 | - ); |
|
| 204 | - |
|
| 205 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 206 | - wp_enqueue_style( |
|
| 207 | - 'redux-field-image-select', |
|
| 208 | - Redux_Core::$url . 'inc/fields/image_select/redux-image-select.css', |
|
| 209 | - array(), |
|
| 210 | - $this->timestamp |
|
| 211 | - ); |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Compile CSS data for output. |
|
| 217 | - * |
|
| 218 | - * @param string $data css string. |
|
| 219 | - * |
|
| 220 | - * @return string |
|
| 221 | - */ |
|
| 222 | - public function css_style( $data ): string { |
|
| 223 | - $css = ''; |
|
| 224 | - $output = ''; |
|
| 225 | - |
|
| 226 | - $mode = ( isset( $this->field['mode'] ) && ! empty( $this->field['mode'] ) ? $this->field['mode'] : 'background-image' ); |
|
| 227 | - |
|
| 228 | - if ( ! empty( $data ) && ! is_array( $data ) ) { |
|
| 229 | - switch ( $mode ) { |
|
| 230 | - case 'background-image': |
|
| 231 | - if ( isset( $this->field['tiles'] ) && true === (bool) $this->field['tiles'] ) { |
|
| 232 | - $img = $data; |
|
| 233 | - } else { |
|
| 234 | - $img = $this->field['options'][ $data ]['img'] ?? ''; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - if ( '' !== $img ) { |
|
| 238 | - $output = "background-image: url('" . esc_url( $img ) . "');"; |
|
| 239 | - } |
|
| 240 | - break; |
|
| 241 | - |
|
| 242 | - default: |
|
| 243 | - $output = $mode . ': ' . $data . ';'; |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - $css .= $output; |
|
| 248 | - |
|
| 249 | - return $css; |
|
| 250 | - } |
|
| 251 | - } |
|
| 15 | + /** |
|
| 16 | + * Main Redux_image_select class |
|
| 17 | + * |
|
| 18 | + * @since 1.0.0 |
|
| 19 | + */ |
|
| 20 | + class Redux_Image_Select extends Redux_Field { |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Set field defaults. |
|
| 24 | + */ |
|
| 25 | + public function set_defaults() { |
|
| 26 | + $defaults = array( |
|
| 27 | + 'tiles' => false, |
|
| 28 | + 'mode' => 'background-image', |
|
| 29 | + 'presets' => false, |
|
| 30 | + 'options' => array(), |
|
| 31 | + 'width' => '', |
|
| 32 | + 'height' => '', |
|
| 33 | + ); |
|
| 34 | + |
|
| 35 | + $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Field Render Function. |
|
| 40 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 41 | + * |
|
| 42 | + * @since 1.0.0 |
|
| 43 | + * @access public |
|
| 44 | + * @return void |
|
| 45 | + */ |
|
| 46 | + public function render() { |
|
| 47 | + if ( ! empty( $this->field['options'] ) ) { |
|
| 48 | + echo '<div class="redux-table-container">'; |
|
| 49 | + echo '<ul class="redux-image-select">'; |
|
| 50 | + |
|
| 51 | + $x = 1; |
|
| 52 | + |
|
| 53 | + foreach ( $this->field['options'] as $k => $v ) { |
|
| 54 | + |
|
| 55 | + if ( ! is_array( $v ) ) { |
|
| 56 | + $v = array( 'img' => $v ); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + if ( ! isset( $v['title'] ) ) { |
|
| 60 | + $v['title'] = ''; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + if ( ! isset( $v['alt'] ) ) { |
|
| 64 | + $v['alt'] = $v['title']; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + if ( ! isset( $v['class'] ) ) { |
|
| 68 | + $v['class'] = ''; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $style = ''; |
|
| 72 | + |
|
| 73 | + if ( ! empty( $this->field['width'] ) ) { |
|
| 74 | + $style .= 'width: ' . $this->field['width']; |
|
| 75 | + |
|
| 76 | + if ( is_numeric( $this->field['width'] ) ) { |
|
| 77 | + $style .= 'px'; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + $style .= ';'; |
|
| 81 | + } else { |
|
| 82 | + $style .= ' width: 100%; '; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + if ( ! empty( $this->field['height'] ) ) { |
|
| 86 | + $style .= 'height: ' . $this->field['height']; |
|
| 87 | + |
|
| 88 | + if ( is_numeric( $this->field['height'] ) ) { |
|
| 89 | + $style .= 'px'; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + $style .= ';'; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $the_value = $k; |
|
| 96 | + |
|
| 97 | + if ( ! empty( $this->field['tiles'] ) && true === (bool) $this->field['tiles'] ) { |
|
| 98 | + $the_value = $v['img']; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $selected = ( '' !== checked( $this->value, $the_value, false ) ) ? ' redux-image-select-selected' : ''; |
|
| 102 | + |
|
| 103 | + $presets = ''; |
|
| 104 | + $is_preset = false; |
|
| 105 | + |
|
| 106 | + $this->field['class'] = trim( str_replace( 'no-update', '', $this->field['class'] ) ); |
|
| 107 | + $this->field['class'] .= ' no-update '; |
|
| 108 | + |
|
| 109 | + if ( isset( $this->field['presets'] ) && false !== $this->field['presets'] ) { |
|
| 110 | + $this->field['class'] = trim( $this->field['class'] ); |
|
| 111 | + if ( ! isset( $v['presets'] ) ) { |
|
| 112 | + $v['presets'] = array(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + if ( ! is_array( $v['presets'] ) ) { |
|
| 116 | + $v['presets'] = json_decode( $v['presets'], true ); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // Only highlight the preset if it's the same. |
|
| 120 | + if ( $selected ) { |
|
| 121 | + if ( empty( $v['presets'] ) ) { |
|
| 122 | + $selected = false; |
|
| 123 | + } else { |
|
| 124 | + foreach ( $v['presets'] as $pk => $pv ) { |
|
| 125 | + if ( isset( $v['merge'] ) && false !== $v['merge'] ) { |
|
| 126 | + if ( ( true === $v['merge'] || in_array( $pk, $v['merge'], true ) ) && is_array( $this->parent->options[ $pk ] ) ) { |
|
| 127 | + $pv = array_merge( $this->parent->options[ $pk ], $pv ); |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + if ( empty( $pv ) && isset( $this->parent->options[ $pk ] ) && ! empty( $this->parent->options[ $pk ] ) ) { |
|
| 132 | + $selected = false; |
|
| 133 | + } elseif ( ! empty( $pv ) && ! isset( $this->parent->options[ $pk ] ) ) { |
|
| 134 | + $selected = false; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + if ( ! $selected ) { // We're still not using the same preset. Let's unset that shall we? |
|
| 138 | + $this->value = ''; |
|
| 139 | + break; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $v['presets']['redux-backup'] = 1; |
|
| 146 | + |
|
| 147 | + $presets = ' data-presets="' . esc_attr( htmlspecialchars( wp_json_encode( $v['presets'] ), ENT_QUOTES ) ) . '"'; |
|
| 148 | + $is_preset = true; |
|
| 149 | + |
|
| 150 | + $this->field['class'] = trim( $this->field['class'] ) . ' redux-presets'; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + $is_preset_class = $is_preset ? '-preset-' : ' '; |
|
| 154 | + |
|
| 155 | + $merge = ''; |
|
| 156 | + if ( isset( $v['merge'] ) && false !== $v['merge'] ) { |
|
| 157 | + $merge = is_array( $v['merge'] ) ? implode( '|', $v['merge'] ) : 'true'; |
|
| 158 | + $merge = ' data-merge="' . esc_attr( htmlspecialchars( $merge, ENT_QUOTES ) ) . '"'; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + echo '<li class="redux-image-select">'; |
|
| 162 | + echo '<label class="' . esc_attr( $selected ) . ' redux-image-select' . esc_attr( $is_preset_class ) . esc_attr( $this->field['id'] . '_' . $x ) . '" for="' . esc_attr( $this->field['id'] . '_' . ( array_search( $k, array_keys( $this->field['options'] ), true ) + 1 ) ) . '">'; |
|
| 163 | + // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped |
|
| 164 | + echo '<input type="radio" class="' . esc_attr( $this->field['class'] ) . '" id="' . esc_attr( $this->field['id'] . '_' . ( array_search( $k, array_keys( $this->field['options'] ), true ) + 1 ) ) . '" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '" value="' . esc_attr( $the_value ) . '" ' . checked( $this->value, $the_value, false ) . $presets . $merge . '/>'; |
|
| 165 | + if ( ! empty( $this->field['tiles'] ) && true === $this->field['tiles'] ) { |
|
| 166 | + echo '<span class="tiles ' . esc_attr( $v['class'] ) . '" style="background-image: url(' . esc_url( $v['img'] ) . ');" rel="' . esc_url( $v['img'] ) . '""> </span>'; |
|
| 167 | + } else { |
|
| 168 | + // phpcs:ignore PluginCheck.CodeAnalysis.ImageFunctions.NonEnqueuedImage -- No image/icon to enqueue. |
|
| 169 | + echo '<img src="' . esc_url( $v['img'] ) . '" title="' . esc_attr( $v['alt'] ) . '" alt="' . esc_attr( $v['alt'] ) . '" class="' . esc_attr( $v['class'] ) . '" style="' . esc_attr( $style ) . '"' . esc_attr( $presets ) . esc_attr( $merge ) . ' />'; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if ( '' !== $v['title'] ) { |
|
| 173 | + echo '<br /><span>' . wp_kses_post( ( $v['title'] ) ) . '</span>'; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + echo '</label>'; |
|
| 177 | + echo '</li>'; |
|
| 178 | + |
|
| 179 | + ++$x; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + echo '</ul>'; |
|
| 183 | + echo '</div>'; |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Enqueue Function. |
|
| 189 | + * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 190 | + * |
|
| 191 | + * @since 1.0.0 |
|
| 192 | + * @access public |
|
| 193 | + * @return void |
|
| 194 | + */ |
|
| 195 | + public function enqueue() { |
|
| 196 | + |
|
| 197 | + wp_enqueue_script( |
|
| 198 | + 'redux-field-image-select', |
|
| 199 | + Redux_Core::$url . 'inc/fields/image_select/redux-image-select' . Redux_Functions::is_min() . '.js', |
|
| 200 | + array( 'jquery', 'redux-js' ), |
|
| 201 | + $this->timestamp, |
|
| 202 | + true |
|
| 203 | + ); |
|
| 204 | + |
|
| 205 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 206 | + wp_enqueue_style( |
|
| 207 | + 'redux-field-image-select', |
|
| 208 | + Redux_Core::$url . 'inc/fields/image_select/redux-image-select.css', |
|
| 209 | + array(), |
|
| 210 | + $this->timestamp |
|
| 211 | + ); |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Compile CSS data for output. |
|
| 217 | + * |
|
| 218 | + * @param string $data css string. |
|
| 219 | + * |
|
| 220 | + * @return string |
|
| 221 | + */ |
|
| 222 | + public function css_style( $data ): string { |
|
| 223 | + $css = ''; |
|
| 224 | + $output = ''; |
|
| 225 | + |
|
| 226 | + $mode = ( isset( $this->field['mode'] ) && ! empty( $this->field['mode'] ) ? $this->field['mode'] : 'background-image' ); |
|
| 227 | + |
|
| 228 | + if ( ! empty( $data ) && ! is_array( $data ) ) { |
|
| 229 | + switch ( $mode ) { |
|
| 230 | + case 'background-image': |
|
| 231 | + if ( isset( $this->field['tiles'] ) && true === (bool) $this->field['tiles'] ) { |
|
| 232 | + $img = $data; |
|
| 233 | + } else { |
|
| 234 | + $img = $this->field['options'][ $data ]['img'] ?? ''; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + if ( '' !== $img ) { |
|
| 238 | + $output = "background-image: url('" . esc_url( $img ) . "');"; |
|
| 239 | + } |
|
| 240 | + break; |
|
| 241 | + |
|
| 242 | + default: |
|
| 243 | + $output = $mode . ': ' . $data . ';'; |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + $css .= $output; |
|
| 248 | + |
|
| 249 | + return $css; |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | class_alias( 'Redux_Image_Select', 'ReduxFramework_Image_Select' ); |
@@ -12,67 +12,67 @@ discard block |
||
| 12 | 12 | // Don't duplicate me! |
| 13 | 13 | if ( ! class_exists( 'Redux_Color_Rgba', false ) ) { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Main Redux_color_rgba class |
|
| 17 | - * |
|
| 18 | - * @since 1.0.0 |
|
| 19 | - */ |
|
| 20 | - class Redux_Color_Rgba extends Redux_Field { |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Set field and value defaults. |
|
| 24 | - */ |
|
| 25 | - public function set_defaults() { |
|
| 26 | - $defaults = array( |
|
| 27 | - 'color' => '', |
|
| 28 | - 'alpha' => 1, |
|
| 29 | - 'rgba' => '', |
|
| 30 | - ); |
|
| 31 | - |
|
| 32 | - $option_defaults = array( |
|
| 33 | - 'show_input' => true, |
|
| 34 | - 'show_initial' => false, |
|
| 35 | - 'show_alpha' => true, |
|
| 36 | - 'show_palette' => false, |
|
| 37 | - 'show_palette_only' => false, |
|
| 38 | - 'max_palette_size' => 10, |
|
| 39 | - 'show_selection_palette' => false, |
|
| 40 | - 'allow_empty' => true, |
|
| 41 | - 'clickout_fires_change' => false, |
|
| 42 | - 'choose_text' => esc_html__( 'Choose', 'redux-framework' ), |
|
| 43 | - 'cancel_text' => esc_html__( 'Cancel', 'redux-framework' ), |
|
| 44 | - 'show_buttons' => true, |
|
| 45 | - 'input_text' => esc_html__( 'Select Color', 'redux-framework' ), |
|
| 46 | - 'palette' => null, |
|
| 47 | - ); |
|
| 48 | - |
|
| 49 | - $this->value = wp_parse_args( $this->value, $defaults ); |
|
| 50 | - |
|
| 51 | - if ( isset( $this->field ) && ! is_array( $this->field ) ) { |
|
| 52 | - return; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - $this->field['options'] = isset( $this->field['options'] ) ? wp_parse_args( $this->field['options'], $option_defaults ) : $option_defaults; |
|
| 56 | - |
|
| 57 | - // Convert an empty array to null, if there. |
|
| 58 | - $this->field['options']['palette'] = empty( $this->field['options']['palette'] ) ? null : $this->field['options']['palette']; |
|
| 59 | - |
|
| 60 | - $this->field['output_transparent'] = $this->field['output_transparent'] ?? false; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Field Render Function. |
|
| 65 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 66 | - * |
|
| 67 | - * @since 1.0.0 |
|
| 68 | - * @access public |
|
| 69 | - * @return void |
|
| 70 | - */ |
|
| 71 | - public function render() { |
|
| 72 | - $field_id = $this->field['id']; |
|
| 73 | - |
|
| 74 | - // Color picker container. |
|
| 75 | - echo '<div |
|
| 15 | + /** |
|
| 16 | + * Main Redux_color_rgba class |
|
| 17 | + * |
|
| 18 | + * @since 1.0.0 |
|
| 19 | + */ |
|
| 20 | + class Redux_Color_Rgba extends Redux_Field { |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Set field and value defaults. |
|
| 24 | + */ |
|
| 25 | + public function set_defaults() { |
|
| 26 | + $defaults = array( |
|
| 27 | + 'color' => '', |
|
| 28 | + 'alpha' => 1, |
|
| 29 | + 'rgba' => '', |
|
| 30 | + ); |
|
| 31 | + |
|
| 32 | + $option_defaults = array( |
|
| 33 | + 'show_input' => true, |
|
| 34 | + 'show_initial' => false, |
|
| 35 | + 'show_alpha' => true, |
|
| 36 | + 'show_palette' => false, |
|
| 37 | + 'show_palette_only' => false, |
|
| 38 | + 'max_palette_size' => 10, |
|
| 39 | + 'show_selection_palette' => false, |
|
| 40 | + 'allow_empty' => true, |
|
| 41 | + 'clickout_fires_change' => false, |
|
| 42 | + 'choose_text' => esc_html__( 'Choose', 'redux-framework' ), |
|
| 43 | + 'cancel_text' => esc_html__( 'Cancel', 'redux-framework' ), |
|
| 44 | + 'show_buttons' => true, |
|
| 45 | + 'input_text' => esc_html__( 'Select Color', 'redux-framework' ), |
|
| 46 | + 'palette' => null, |
|
| 47 | + ); |
|
| 48 | + |
|
| 49 | + $this->value = wp_parse_args( $this->value, $defaults ); |
|
| 50 | + |
|
| 51 | + if ( isset( $this->field ) && ! is_array( $this->field ) ) { |
|
| 52 | + return; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + $this->field['options'] = isset( $this->field['options'] ) ? wp_parse_args( $this->field['options'], $option_defaults ) : $option_defaults; |
|
| 56 | + |
|
| 57 | + // Convert an empty array to null, if there. |
|
| 58 | + $this->field['options']['palette'] = empty( $this->field['options']['palette'] ) ? null : $this->field['options']['palette']; |
|
| 59 | + |
|
| 60 | + $this->field['output_transparent'] = $this->field['output_transparent'] ?? false; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Field Render Function. |
|
| 65 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 66 | + * |
|
| 67 | + * @since 1.0.0 |
|
| 68 | + * @access public |
|
| 69 | + * @return void |
|
| 70 | + */ |
|
| 71 | + public function render() { |
|
| 72 | + $field_id = $this->field['id']; |
|
| 73 | + |
|
| 74 | + // Color picker container. |
|
| 75 | + echo '<div |
|
| 76 | 76 | class="redux-color-rgba-container ' . esc_attr( $this->field['class'] ) . '" |
| 77 | 77 | data-id="' . esc_attr( $field_id ) . '" |
| 78 | 78 | data-show-input="' . esc_attr( $this->field['options']['show_input'] ) . '" |
@@ -91,18 +91,18 @@ discard block |
||
| 91 | 91 | data-palette="' . rawurlencode( wp_json_encode( $this->field['options']['palette'] ) ) . '" |
| 92 | 92 | >'; |
| 93 | 93 | |
| 94 | - // Colour picker layout. |
|
| 95 | - if ( '' === $this->value['color'] || 'transparent' === $this->value['color'] ) { |
|
| 96 | - $color = ''; |
|
| 97 | - } else { |
|
| 98 | - $color = Redux_Helpers::hex2rgba( $this->value['color'], $this->value['alpha'] ); |
|
| 99 | - } |
|
| 94 | + // Colour picker layout. |
|
| 95 | + if ( '' === $this->value['color'] || 'transparent' === $this->value['color'] ) { |
|
| 96 | + $color = ''; |
|
| 97 | + } else { |
|
| 98 | + $color = Redux_Helpers::hex2rgba( $this->value['color'], $this->value['alpha'] ); |
|
| 99 | + } |
|
| 100 | 100 | |
| 101 | - if ( '' === $this->value['rgba'] && '' !== $this->value['color'] ) { |
|
| 102 | - $this->value['rgba'] = Redux_Helpers::hex2rgba( $this->value['color'], $this->value['alpha'] ); |
|
| 103 | - } |
|
| 101 | + if ( '' === $this->value['rgba'] && '' !== $this->value['color'] ) { |
|
| 102 | + $this->value['rgba'] = Redux_Helpers::hex2rgba( $this->value['color'], $this->value['alpha'] ); |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - echo '<input |
|
| 105 | + echo '<input |
|
| 106 | 106 | name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[color]" |
| 107 | 107 | id="' . esc_attr( $field_id ) . '-color-display" |
| 108 | 108 | class="redux-color-rgba" |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | data-output-transparent="' . esc_attr( $this->field['output_transparent'] ) . '" |
| 116 | 116 | />'; |
| 117 | 117 | |
| 118 | - echo '<input |
|
| 118 | + echo '<input |
|
| 119 | 119 | type="hidden" |
| 120 | 120 | class="redux-hidden-color" |
| 121 | 121 | data-id="' . esc_attr( $field_id ) . '-color" |
@@ -123,8 +123,8 @@ discard block |
||
| 123 | 123 | value="' . esc_attr( $this->value['color'] ) . '" |
| 124 | 124 | />'; |
| 125 | 125 | |
| 126 | - // Hidden input for alpha channel. |
|
| 127 | - echo '<input |
|
| 126 | + // Hidden input for alpha channel. |
|
| 127 | + echo '<input |
|
| 128 | 128 | type="hidden" |
| 129 | 129 | class="redux-hidden-alpha" |
| 130 | 130 | data-id="' . esc_attr( $field_id ) . '-alpha" |
@@ -133,8 +133,8 @@ discard block |
||
| 133 | 133 | value="' . esc_attr( $this->value['alpha'] ) . '" |
| 134 | 134 | />'; |
| 135 | 135 | |
| 136 | - // Hidden input for rgba. |
|
| 137 | - echo '<input |
|
| 136 | + // Hidden input for rgba. |
|
| 137 | + echo '<input |
|
| 138 | 138 | type="hidden" |
| 139 | 139 | class="redux-hidden-rgba" |
| 140 | 140 | data-id="' . esc_attr( $field_id ) . '-rgba" |
@@ -143,142 +143,142 @@ discard block |
||
| 143 | 143 | value="' . esc_attr( $this->value['rgba'] ) . '" |
| 144 | 144 | />'; |
| 145 | 145 | |
| 146 | - echo '</div>'; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Enqueue Function. |
|
| 151 | - * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 152 | - * |
|
| 153 | - * @since 1.0.0 |
|
| 154 | - * @access public |
|
| 155 | - * @return void |
|
| 156 | - */ |
|
| 157 | - public function enqueue() { |
|
| 158 | - |
|
| 159 | - // Set up min files for dev_mode = false. |
|
| 160 | - $min = Redux_Functions::is_min(); |
|
| 161 | - |
|
| 162 | - // Field dependent JS. |
|
| 163 | - wp_enqueue_script( |
|
| 164 | - 'redux-field-color-rgba', |
|
| 165 | - Redux_Core::$url . 'inc/fields/color_rgba/redux-color-rgba' . $min . '.js', |
|
| 166 | - array( 'jquery', 'redux-spectrum-js', 'redux-js' ), |
|
| 167 | - $this->timestamp, |
|
| 168 | - true |
|
| 169 | - ); |
|
| 170 | - |
|
| 171 | - // Spectrum CSS. |
|
| 172 | - if ( ! wp_style_is( 'redux-spectrum-css' ) ) { |
|
| 173 | - wp_enqueue_style( 'redux-spectrum-css' ); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 177 | - wp_enqueue_style( |
|
| 178 | - 'redux-field-color-rgba', |
|
| 179 | - Redux_Core::$url . 'inc/fields/color_rgba/redux-color-rgba.css', |
|
| 180 | - array(), |
|
| 181 | - $this->timestamp |
|
| 182 | - ); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - /** |
|
| 187 | - * -> getColorVal. Returns formatted color val in hex or rgba. |
|
| 188 | - * If this field requires any scripts or css, define this function and register/enqueue the scripts/css |
|
| 189 | - * |
|
| 190 | - * @since 1.0.0 |
|
| 191 | - * @access private |
|
| 192 | - * @return string |
|
| 193 | - */ |
|
| 194 | - private function get_color_val(): string { |
|
| 195 | - |
|
| 196 | - // No notices. |
|
| 197 | - $color = ''; |
|
| 198 | - $alpha = 1; |
|
| 199 | - $rgba = ''; |
|
| 200 | - |
|
| 201 | - // Must be an array. |
|
| 202 | - if ( is_array( $this->value ) ) { |
|
| 203 | - |
|
| 204 | - // Enum array to parse values. |
|
| 205 | - foreach ( $this->value as $id => $val ) { |
|
| 206 | - |
|
| 207 | - // Sanitize alpha. |
|
| 208 | - if ( 'alpha' === $id ) { |
|
| 209 | - $alpha = is_numeric( $val ) ? $val : 1; |
|
| 210 | - } elseif ( 'color' === $id ) { |
|
| 211 | - $color = ! empty( $val ) ? $val : ''; |
|
| 212 | - } elseif ( 'rgba' === $id ) { |
|
| 213 | - $rgba = Redux_Helpers::hex2rgba( $color, $alpha ); |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // Only build rgba output if alpha ia less than 1. |
|
| 218 | - if ( $alpha < 1 && '' !== $alpha ) { |
|
| 219 | - $color = $rgba; |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - return $color; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * Generate CSS style. |
|
| 228 | - * |
|
| 229 | - * @param string $data Field data. |
|
| 230 | - * |
|
| 231 | - * @return string |
|
| 232 | - */ |
|
| 233 | - public function css_style( $data ): string { |
|
| 234 | - return ''; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * Output Function. |
|
| 239 | - * Used to enqueue to the front-end |
|
| 240 | - * |
|
| 241 | - * @since 1.0.0 |
|
| 242 | - * @access public |
|
| 243 | - * |
|
| 244 | - * @param string|null|array $style css data. |
|
| 245 | - * |
|
| 246 | - * @return void |
|
| 247 | - */ |
|
| 248 | - public function output( $style = '' ) { |
|
| 249 | - if ( ! empty( $this->value ) ) { |
|
| 250 | - $mode = ( isset( $this->field['mode'] ) && ! empty( $this->field['mode'] ) ? $this->field['mode'] : 'color' ); |
|
| 251 | - |
|
| 252 | - $color_val = $this->get_color_val(); |
|
| 253 | - |
|
| 254 | - $style = $mode . ':' . $color_val . ';'; |
|
| 255 | - |
|
| 256 | - if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) { |
|
| 257 | - if ( ! empty( $color_val ) ) { |
|
| 258 | - $css = Redux_Functions::parse_css( $this->field['output'], $style, $color_val ); |
|
| 259 | - $this->parent->outputCSS .= esc_attr( $css ); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) { |
|
| 264 | - if ( ! empty( $color_val ) ) { |
|
| 265 | - $css = Redux_Functions::parse_css( $this->field['compiler'], $style, $color_val ); |
|
| 266 | - $this->parent->compilerCSS .= esc_attr( $css ); |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * Enable output_variables to be generated. |
|
| 274 | - * |
|
| 275 | - * @since 4.0.3 |
|
| 276 | - * @return void |
|
| 277 | - */ |
|
| 278 | - public function output_variables() { |
|
| 279 | - // No code needed, just defining the method is enough. |
|
| 280 | - } |
|
| 281 | - } |
|
| 146 | + echo '</div>'; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Enqueue Function. |
|
| 151 | + * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 152 | + * |
|
| 153 | + * @since 1.0.0 |
|
| 154 | + * @access public |
|
| 155 | + * @return void |
|
| 156 | + */ |
|
| 157 | + public function enqueue() { |
|
| 158 | + |
|
| 159 | + // Set up min files for dev_mode = false. |
|
| 160 | + $min = Redux_Functions::is_min(); |
|
| 161 | + |
|
| 162 | + // Field dependent JS. |
|
| 163 | + wp_enqueue_script( |
|
| 164 | + 'redux-field-color-rgba', |
|
| 165 | + Redux_Core::$url . 'inc/fields/color_rgba/redux-color-rgba' . $min . '.js', |
|
| 166 | + array( 'jquery', 'redux-spectrum-js', 'redux-js' ), |
|
| 167 | + $this->timestamp, |
|
| 168 | + true |
|
| 169 | + ); |
|
| 170 | + |
|
| 171 | + // Spectrum CSS. |
|
| 172 | + if ( ! wp_style_is( 'redux-spectrum-css' ) ) { |
|
| 173 | + wp_enqueue_style( 'redux-spectrum-css' ); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 177 | + wp_enqueue_style( |
|
| 178 | + 'redux-field-color-rgba', |
|
| 179 | + Redux_Core::$url . 'inc/fields/color_rgba/redux-color-rgba.css', |
|
| 180 | + array(), |
|
| 181 | + $this->timestamp |
|
| 182 | + ); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + /** |
|
| 187 | + * -> getColorVal. Returns formatted color val in hex or rgba. |
|
| 188 | + * If this field requires any scripts or css, define this function and register/enqueue the scripts/css |
|
| 189 | + * |
|
| 190 | + * @since 1.0.0 |
|
| 191 | + * @access private |
|
| 192 | + * @return string |
|
| 193 | + */ |
|
| 194 | + private function get_color_val(): string { |
|
| 195 | + |
|
| 196 | + // No notices. |
|
| 197 | + $color = ''; |
|
| 198 | + $alpha = 1; |
|
| 199 | + $rgba = ''; |
|
| 200 | + |
|
| 201 | + // Must be an array. |
|
| 202 | + if ( is_array( $this->value ) ) { |
|
| 203 | + |
|
| 204 | + // Enum array to parse values. |
|
| 205 | + foreach ( $this->value as $id => $val ) { |
|
| 206 | + |
|
| 207 | + // Sanitize alpha. |
|
| 208 | + if ( 'alpha' === $id ) { |
|
| 209 | + $alpha = is_numeric( $val ) ? $val : 1; |
|
| 210 | + } elseif ( 'color' === $id ) { |
|
| 211 | + $color = ! empty( $val ) ? $val : ''; |
|
| 212 | + } elseif ( 'rgba' === $id ) { |
|
| 213 | + $rgba = Redux_Helpers::hex2rgba( $color, $alpha ); |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // Only build rgba output if alpha ia less than 1. |
|
| 218 | + if ( $alpha < 1 && '' !== $alpha ) { |
|
| 219 | + $color = $rgba; |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + return $color; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * Generate CSS style. |
|
| 228 | + * |
|
| 229 | + * @param string $data Field data. |
|
| 230 | + * |
|
| 231 | + * @return string |
|
| 232 | + */ |
|
| 233 | + public function css_style( $data ): string { |
|
| 234 | + return ''; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * Output Function. |
|
| 239 | + * Used to enqueue to the front-end |
|
| 240 | + * |
|
| 241 | + * @since 1.0.0 |
|
| 242 | + * @access public |
|
| 243 | + * |
|
| 244 | + * @param string|null|array $style css data. |
|
| 245 | + * |
|
| 246 | + * @return void |
|
| 247 | + */ |
|
| 248 | + public function output( $style = '' ) { |
|
| 249 | + if ( ! empty( $this->value ) ) { |
|
| 250 | + $mode = ( isset( $this->field['mode'] ) && ! empty( $this->field['mode'] ) ? $this->field['mode'] : 'color' ); |
|
| 251 | + |
|
| 252 | + $color_val = $this->get_color_val(); |
|
| 253 | + |
|
| 254 | + $style = $mode . ':' . $color_val . ';'; |
|
| 255 | + |
|
| 256 | + if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) { |
|
| 257 | + if ( ! empty( $color_val ) ) { |
|
| 258 | + $css = Redux_Functions::parse_css( $this->field['output'], $style, $color_val ); |
|
| 259 | + $this->parent->outputCSS .= esc_attr( $css ); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) { |
|
| 264 | + if ( ! empty( $color_val ) ) { |
|
| 265 | + $css = Redux_Functions::parse_css( $this->field['compiler'], $style, $color_val ); |
|
| 266 | + $this->parent->compilerCSS .= esc_attr( $css ); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * Enable output_variables to be generated. |
|
| 274 | + * |
|
| 275 | + * @since 4.0.3 |
|
| 276 | + * @return void |
|
| 277 | + */ |
|
| 278 | + public function output_variables() { |
|
| 279 | + // No code needed, just defining the method is enough. |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | class_alias( 'Redux_Color_Rgba', 'ReduxFramework_Color_Rgba' ); |