@@ -11,390 +11,390 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Args', false ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Class Redux_Args |
|
| 16 | - */ |
|
| 17 | - class Redux_Args { |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Returns entire arguments array. |
|
| 21 | - * |
|
| 22 | - * @var array|mixed |
|
| 23 | - */ |
|
| 24 | - public $get = array(); |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * ReduxFramework object. |
|
| 28 | - * |
|
| 29 | - * @var ReduxFramework|null |
|
| 30 | - */ |
|
| 31 | - private ?ReduxFramework $parent; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Switch to omit social icons if dev_mode is set to true and Redux defaults are used. |
|
| 35 | - * |
|
| 36 | - * @var bool |
|
| 37 | - */ |
|
| 38 | - public bool $omit_icons = false; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Switch to omit support menu items if dev_mode is set to true and redux defaults are used. |
|
| 42 | - * |
|
| 43 | - * @var bool |
|
| 44 | - */ |
|
| 45 | - public bool $omit_items = false; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Flag to force dev_mod to true if in localhost or WP_DEBUG is set to true. |
|
| 49 | - * |
|
| 50 | - * @var bool |
|
| 51 | - */ |
|
| 52 | - public bool $dev_mode_forced = false; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Redux_Args constructor. |
|
| 56 | - * |
|
| 57 | - * @param ReduxFramework $redux ReduxFramework object. |
|
| 58 | - * @param array $args Global arguments array. |
|
| 59 | - */ |
|
| 60 | - public function __construct( ReduxFramework $redux, array $args ) { |
|
| 61 | - $this->parent = $redux; |
|
| 62 | - |
|
| 63 | - $default = array( |
|
| 64 | - 'opt_name' => '', |
|
| 65 | - 'last_tab' => '', |
|
| 66 | - 'menu_icon' => '', |
|
| 67 | - 'menu_title' => '', |
|
| 68 | - 'page_title' => '', |
|
| 69 | - 'page_slug' => '', |
|
| 70 | - 'page_permissions' => 'manage_options', |
|
| 71 | - 'menu_type' => 'menu', |
|
| 72 | - 'page_parent' => 'themes.php', |
|
| 73 | - 'page_priority' => null, |
|
| 74 | - 'allow_sub_menu' => true, |
|
| 75 | - 'save_defaults' => true, |
|
| 76 | - 'footer_credit' => '', |
|
| 77 | - 'async_typography' => false, |
|
| 78 | - 'disable_google_fonts_link' => false, |
|
| 79 | - 'class' => '', |
|
| 80 | - 'admin_bar' => true, |
|
| 81 | - 'admin_bar_priority' => 999, |
|
| 82 | - 'admin_bar_icon' => '', |
|
| 83 | - 'help_tabs' => array(), |
|
| 84 | - 'help_sidebar' => '', |
|
| 85 | - 'database' => '', |
|
| 86 | - 'customizer' => false, |
|
| 87 | - 'global_variable' => '', |
|
| 88 | - 'output' => true, |
|
| 89 | - 'output_variables_prefix' => '--', |
|
| 90 | - 'compiler_output_variables_prefix' => '$', |
|
| 91 | - 'compiler' => true, |
|
| 92 | - 'output_tag' => true, |
|
| 93 | - 'output_location' => array( 'frontend' ), |
|
| 94 | - 'transient_time' => '', |
|
| 95 | - 'default_show' => false, |
|
| 96 | - 'default_mark' => '', |
|
| 97 | - 'disable_save_warn' => false, |
|
| 98 | - 'open_expanded' => false, |
|
| 99 | - 'hide_expand' => false, |
|
| 100 | - 'network_admin' => false, |
|
| 101 | - 'network_sites' => true, |
|
| 102 | - 'hide_reset' => false, |
|
| 103 | - 'hide_save' => false, |
|
| 104 | - 'hints' => array( |
|
| 105 | - 'icon' => 'el el-question-sign', |
|
| 106 | - 'icon_position' => 'right', |
|
| 107 | - 'icon_color' => 'lightgray', |
|
| 108 | - 'icon_size' => 'normal', |
|
| 109 | - 'tip_style' => array( |
|
| 110 | - 'color' => 'light', |
|
| 111 | - 'shadow' => true, |
|
| 112 | - 'rounded' => false, |
|
| 113 | - 'style' => '', |
|
| 114 | - ), |
|
| 115 | - 'tip_position' => array( |
|
| 116 | - 'my' => 'top_left', |
|
| 117 | - 'at' => 'bottom_right', |
|
| 118 | - ), |
|
| 119 | - 'tip_effect' => array( |
|
| 120 | - 'show' => array( |
|
| 121 | - 'effect' => 'slide', |
|
| 122 | - 'duration' => '500', |
|
| 123 | - 'event' => 'mouseover', |
|
| 124 | - ), |
|
| 125 | - 'hide' => array( |
|
| 126 | - 'effect' => 'fade', |
|
| 127 | - 'duration' => '500', |
|
| 128 | - 'event' => 'click mouseleave', |
|
| 129 | - ), |
|
| 130 | - ), |
|
| 131 | - ), |
|
| 132 | - 'font_weights' => array( |
|
| 133 | - array( |
|
| 134 | - 'id' => '400', |
|
| 135 | - 'name' => __( 'Regular 400', 'redux-framework' ), |
|
| 136 | - ), |
|
| 137 | - array( |
|
| 138 | - 'id' => '400italic', |
|
| 139 | - 'name' => __( 'Regular 400 Italic', 'redux-framework' ), |
|
| 140 | - ), |
|
| 141 | - array( |
|
| 142 | - 'id' => '700', |
|
| 143 | - 'name' => __( 'Bold 700', 'redux-framework' ), |
|
| 144 | - ), |
|
| 145 | - array( |
|
| 146 | - 'id' => '700italic', |
|
| 147 | - 'name' => __( 'Bold 700 Italic', 'redux-framework' ), |
|
| 148 | - ), |
|
| 149 | - ), |
|
| 150 | - 'show_import_export' => true, |
|
| 151 | - 'show_options_object' => true, |
|
| 152 | - 'dev_mode' => true, |
|
| 153 | - 'templates_path' => '', |
|
| 154 | - 'ajax_save' => true, |
|
| 155 | - 'use_cdn' => true, |
|
| 156 | - 'cdn_check_time' => 1440, |
|
| 157 | - 'options_api' => true, |
|
| 158 | - 'allow_tracking' => true, |
|
| 159 | - 'admin_theme' => 'wp', |
|
| 160 | - 'elusive_frontend' => false, |
|
| 161 | - 'fontawesome_frontend' => false, |
|
| 162 | - 'flyout_submenus' => true, |
|
| 163 | - 'font_display' => 'swap', // block|swap|fallback|optional. |
|
| 164 | - 'load_on_cron' => false, |
|
| 165 | - 'search' => false, |
|
| 166 | - 'widget_area' => false, |
|
| 167 | - 'custom_fonts' => true, |
|
| 168 | - ); |
|
| 169 | - |
|
| 170 | - $args = Redux_Functions::parse_args( $args, $default ); |
|
| 171 | - |
|
| 172 | - $args = $this->args( $args ); |
|
| 173 | - |
|
| 174 | - $args = $this->default_cleanup( $args ); |
|
| 175 | - |
|
| 176 | - if ( ! in_array( $args['font_display'], array( 'block', 'swap', 'fallback', 'optional' ), true ) ) { |
|
| 177 | - $args['font_display'] = 'swap'; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - if ( isset( $args['async_typography'] ) && $args['async_typography'] ) { |
|
| 181 | - $args['async_typography'] = false; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - $this->get = $args; |
|
| 185 | - |
|
| 186 | - $this->parent->args = $args; |
|
| 187 | - |
|
| 188 | - if ( 'redux_extensions_demo' !== $args['opt_name'] && 'redux_demo' !== $args['opt_name'] ) { |
|
| 189 | - $this->change_demo_defaults( $args ); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * Builds and sanitizes a global args array. |
|
| 195 | - * |
|
| 196 | - * @param array $args Global args. |
|
| 197 | - * |
|
| 198 | - * @return array |
|
| 199 | - */ |
|
| 200 | - private function args( array $args ): array { |
|
| 201 | - $args = $this->no_errors_please( $args ); |
|
| 202 | - |
|
| 203 | - $this->parent->old_opt_name = $args['opt_name']; |
|
| 204 | - |
|
| 205 | - $args = $this->filters( $args ); |
|
| 206 | - |
|
| 207 | - if ( ! function_exists( 'wp_rand' ) ) { |
|
| 208 | - require_once ABSPATH . '/wp-includes/pluggable.php'; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - if ( $args['opt_name'] === $this->parent->old_opt_name ) { |
|
| 212 | - $this->parent->old_opt_name = null; |
|
| 213 | - unset( $this->parent->old_opt_name ); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // Do not save the defaults if we're on a live preview! |
|
| 217 | - if ( 'customize' === $GLOBALS['pagenow'] && isset( $_GET['customize_theme'] ) && ! empty( $_GET['customize_theme'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 218 | - $args['save_defaults'] = false; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - return $this->shim( $args ); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Apply filters to arg data. |
|
| 226 | - * |
|
| 227 | - * @param array $args Global args. |
|
| 228 | - * |
|
| 229 | - * @return mixed|void |
|
| 230 | - */ |
|
| 231 | - private function filters( array $args ) { |
|
| 232 | - /** |
|
| 233 | - * Filter 'redux/args/{opt_name}' |
|
| 234 | - * |
|
| 235 | - * @param array $args ReduxFramework configuration |
|
| 236 | - */ |
|
| 237 | - |
|
| 238 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 239 | - $args = apply_filters( "redux/args/{$args['opt_name']}", $args ); |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Filter 'redux/options/{opt_name}/args' |
|
| 243 | - * |
|
| 244 | - * @param array $args ReduxFramework configuration |
|
| 245 | - */ |
|
| 246 | - |
|
| 247 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 248 | - return apply_filters( "redux/options/{$args['opt_name']}/args", $args ); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Sanitize args that should not be empty. |
|
| 253 | - * |
|
| 254 | - * @param array $args Global args. |
|
| 255 | - * |
|
| 256 | - * @return array |
|
| 257 | - */ |
|
| 258 | - private function no_errors_please( array $args ): array { |
|
| 259 | - if ( empty( $args['transient_time'] ) ) { |
|
| 260 | - $args['transient_time'] = 60 * MINUTE_IN_SECONDS; |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - if ( empty( $args['footer_credit'] ) ) { |
|
| 264 | - |
|
| 265 | - $footer_text = sprintf( |
|
| 266 | - /* translators: 1: Redux, 2: Link to plugin review */ |
|
| 267 | - __( 'Enjoyed %1$s? Please leave us a %2$s rating. We really appreciate your support!', 'redux-framework' ), |
|
| 268 | - '<strong>' . __( 'Redux', 'redux-framework' ) . '</strong>', |
|
| 269 | - '<a href="https://wordpress.org/support/plugin/redux-framework/reviews/?filter=5/#new-post" target="_blank">★★★★★</a>' |
|
| 270 | - ); |
|
| 271 | - $args['footer_credit'] = '<span id="footer-thankyou">' . $footer_text . '</span>'; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - if ( empty( $args['menu_title'] ) ) { |
|
| 275 | - $args['menu_title'] = esc_html__( 'Options', 'redux-framework' ); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - if ( empty( $args['page_title'] ) ) { |
|
| 279 | - $args['page_title'] = esc_html__( 'Options', 'redux-framework' ); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // Auto creates the page_slug appropriately. |
|
| 283 | - if ( empty( $args['page_slug'] ) ) { |
|
| 284 | - if ( ! empty( $args['display_name'] ) ) { |
|
| 285 | - $args['page_slug'] = sanitize_html_class( $args['display_name'] ); |
|
| 286 | - } elseif ( ! empty( $args['page_title'] ) ) { |
|
| 287 | - $args['page_slug'] = sanitize_html_class( $args['page_title'] ); |
|
| 288 | - } elseif ( ! empty( $args['menu_title'] ) ) { |
|
| 289 | - $args['page_slug'] = sanitize_html_class( $args['menu_title'] ); |
|
| 290 | - } else { |
|
| 291 | - $args['page_slug'] = str_replace( '-', '_', $args['opt_name'] ); |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - return $args; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - /** |
|
| 299 | - * Shims for much older v3 configs. |
|
| 300 | - * |
|
| 301 | - * @param array $args Global args. |
|
| 302 | - * |
|
| 303 | - * @return array |
|
| 304 | - */ |
|
| 305 | - private function shim( array $args ): array { |
|
| 306 | - /** |
|
| 307 | - * SHIM SECTION |
|
| 308 | - * Old variables and ways of doing things that need correcting. ;) |
|
| 309 | - * */ |
|
| 310 | - // Variable name change. |
|
| 311 | - if ( ! empty( $args['page_cap'] ) ) { |
|
| 312 | - $args['page_permissions'] = $args['page_cap']; |
|
| 313 | - unset( $args['page_cap'] ); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - if ( ! empty( $args['page_position'] ) ) { |
|
| 317 | - $args['page_priority'] = $args['page_position']; |
|
| 318 | - unset( $args['page_position'] ); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - if ( ! empty( $args['page_type'] ) ) { |
|
| 322 | - $args['menu_type'] = $args['page_type']; |
|
| 323 | - unset( $args['page_type'] ); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - return $args; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - /** |
|
| 330 | - * Verify to see if dev has bothered to change admin bar links and share icons from demo data to their own. |
|
| 331 | - * |
|
| 332 | - * @param array $args Global args. |
|
| 333 | - */ |
|
| 334 | - private function change_demo_defaults( array $args ) { |
|
| 335 | - if ( $args['dev_mode'] || true === Redux_Helpers::is_local_host() ) { |
|
| 336 | - if ( ! empty( $args['admin_bar_links'] ) ) { |
|
| 337 | - foreach ( $args['admin_bar_links'] as $arr ) { |
|
| 338 | - if ( is_array( $arr ) && ! empty( $arr ) ) { |
|
| 339 | - foreach ( $arr as $y ) { |
|
| 340 | - if ( strpos( Redux_Core::strtolower( $y ), 'redux' ) !== false ) { |
|
| 341 | - $this->omit_items = true; |
|
| 342 | - break; |
|
| 343 | - } |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - if ( ! empty( $args['share_icons'] ) ) { |
|
| 350 | - foreach ( $args['share_icons'] as $arr ) { |
|
| 351 | - if ( is_array( $arr ) && ! empty( $arr ) ) { |
|
| 352 | - foreach ( $arr as $y ) { |
|
| 353 | - if ( strpos( Redux_Core::strtolower( $y ), 'redux' ) !== false ) { |
|
| 354 | - $this->omit_icons = true; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - } |
|
| 358 | - } |
|
| 359 | - } |
|
| 360 | - } |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Fix other arg criteria that sometimes gets hosed up. |
|
| 365 | - * |
|
| 366 | - * @param array $args Global args. |
|
| 367 | - * |
|
| 368 | - * @return array |
|
| 369 | - * @noinspection PhpStrictComparisonWithOperandsOfDifferentTypesInspection |
|
| 370 | - */ |
|
| 371 | - private function default_cleanup( array $args ): array { |
|
| 372 | - |
|
| 373 | - // Fix the global variable name. |
|
| 374 | - if ( '' === $args['global_variable'] && false !== $args['global_variable'] ) { |
|
| 375 | - $args['global_variable'] = str_replace( '-', '_', $args['opt_name'] ); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - if ( isset( $args['customizer_only'] ) && $args['customizer_only'] ) { |
|
| 379 | - $args['menu_type'] = 'hidden'; |
|
| 380 | - $args['customizer'] = true; |
|
| 381 | - $args['admin_bar'] = false; |
|
| 382 | - $args['allow_sub_menu'] = false; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - // Check if the Airplane Mode plugin is installed. |
|
| 386 | - if ( class_exists( 'Airplane_Mode_Core' ) ) { |
|
| 387 | - $airplane = Airplane_Mode_Core::getInstance(); |
|
| 388 | - if ( method_exists( $airplane, 'enabled' ) ) { |
|
| 389 | - if ( $airplane->enabled() ) { |
|
| 390 | - $args['use_cdn'] = false; |
|
| 391 | - } |
|
| 392 | - } elseif ( 'on' === $airplane->check_status() ) { |
|
| 393 | - $args['use_cdn'] = false; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - return $args; |
|
| 398 | - } |
|
| 399 | - } |
|
| 14 | + /** |
|
| 15 | + * Class Redux_Args |
|
| 16 | + */ |
|
| 17 | + class Redux_Args { |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Returns entire arguments array. |
|
| 21 | + * |
|
| 22 | + * @var array|mixed |
|
| 23 | + */ |
|
| 24 | + public $get = array(); |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * ReduxFramework object. |
|
| 28 | + * |
|
| 29 | + * @var ReduxFramework|null |
|
| 30 | + */ |
|
| 31 | + private ?ReduxFramework $parent; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Switch to omit social icons if dev_mode is set to true and Redux defaults are used. |
|
| 35 | + * |
|
| 36 | + * @var bool |
|
| 37 | + */ |
|
| 38 | + public bool $omit_icons = false; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Switch to omit support menu items if dev_mode is set to true and redux defaults are used. |
|
| 42 | + * |
|
| 43 | + * @var bool |
|
| 44 | + */ |
|
| 45 | + public bool $omit_items = false; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Flag to force dev_mod to true if in localhost or WP_DEBUG is set to true. |
|
| 49 | + * |
|
| 50 | + * @var bool |
|
| 51 | + */ |
|
| 52 | + public bool $dev_mode_forced = false; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Redux_Args constructor. |
|
| 56 | + * |
|
| 57 | + * @param ReduxFramework $redux ReduxFramework object. |
|
| 58 | + * @param array $args Global arguments array. |
|
| 59 | + */ |
|
| 60 | + public function __construct( ReduxFramework $redux, array $args ) { |
|
| 61 | + $this->parent = $redux; |
|
| 62 | + |
|
| 63 | + $default = array( |
|
| 64 | + 'opt_name' => '', |
|
| 65 | + 'last_tab' => '', |
|
| 66 | + 'menu_icon' => '', |
|
| 67 | + 'menu_title' => '', |
|
| 68 | + 'page_title' => '', |
|
| 69 | + 'page_slug' => '', |
|
| 70 | + 'page_permissions' => 'manage_options', |
|
| 71 | + 'menu_type' => 'menu', |
|
| 72 | + 'page_parent' => 'themes.php', |
|
| 73 | + 'page_priority' => null, |
|
| 74 | + 'allow_sub_menu' => true, |
|
| 75 | + 'save_defaults' => true, |
|
| 76 | + 'footer_credit' => '', |
|
| 77 | + 'async_typography' => false, |
|
| 78 | + 'disable_google_fonts_link' => false, |
|
| 79 | + 'class' => '', |
|
| 80 | + 'admin_bar' => true, |
|
| 81 | + 'admin_bar_priority' => 999, |
|
| 82 | + 'admin_bar_icon' => '', |
|
| 83 | + 'help_tabs' => array(), |
|
| 84 | + 'help_sidebar' => '', |
|
| 85 | + 'database' => '', |
|
| 86 | + 'customizer' => false, |
|
| 87 | + 'global_variable' => '', |
|
| 88 | + 'output' => true, |
|
| 89 | + 'output_variables_prefix' => '--', |
|
| 90 | + 'compiler_output_variables_prefix' => '$', |
|
| 91 | + 'compiler' => true, |
|
| 92 | + 'output_tag' => true, |
|
| 93 | + 'output_location' => array( 'frontend' ), |
|
| 94 | + 'transient_time' => '', |
|
| 95 | + 'default_show' => false, |
|
| 96 | + 'default_mark' => '', |
|
| 97 | + 'disable_save_warn' => false, |
|
| 98 | + 'open_expanded' => false, |
|
| 99 | + 'hide_expand' => false, |
|
| 100 | + 'network_admin' => false, |
|
| 101 | + 'network_sites' => true, |
|
| 102 | + 'hide_reset' => false, |
|
| 103 | + 'hide_save' => false, |
|
| 104 | + 'hints' => array( |
|
| 105 | + 'icon' => 'el el-question-sign', |
|
| 106 | + 'icon_position' => 'right', |
|
| 107 | + 'icon_color' => 'lightgray', |
|
| 108 | + 'icon_size' => 'normal', |
|
| 109 | + 'tip_style' => array( |
|
| 110 | + 'color' => 'light', |
|
| 111 | + 'shadow' => true, |
|
| 112 | + 'rounded' => false, |
|
| 113 | + 'style' => '', |
|
| 114 | + ), |
|
| 115 | + 'tip_position' => array( |
|
| 116 | + 'my' => 'top_left', |
|
| 117 | + 'at' => 'bottom_right', |
|
| 118 | + ), |
|
| 119 | + 'tip_effect' => array( |
|
| 120 | + 'show' => array( |
|
| 121 | + 'effect' => 'slide', |
|
| 122 | + 'duration' => '500', |
|
| 123 | + 'event' => 'mouseover', |
|
| 124 | + ), |
|
| 125 | + 'hide' => array( |
|
| 126 | + 'effect' => 'fade', |
|
| 127 | + 'duration' => '500', |
|
| 128 | + 'event' => 'click mouseleave', |
|
| 129 | + ), |
|
| 130 | + ), |
|
| 131 | + ), |
|
| 132 | + 'font_weights' => array( |
|
| 133 | + array( |
|
| 134 | + 'id' => '400', |
|
| 135 | + 'name' => __( 'Regular 400', 'redux-framework' ), |
|
| 136 | + ), |
|
| 137 | + array( |
|
| 138 | + 'id' => '400italic', |
|
| 139 | + 'name' => __( 'Regular 400 Italic', 'redux-framework' ), |
|
| 140 | + ), |
|
| 141 | + array( |
|
| 142 | + 'id' => '700', |
|
| 143 | + 'name' => __( 'Bold 700', 'redux-framework' ), |
|
| 144 | + ), |
|
| 145 | + array( |
|
| 146 | + 'id' => '700italic', |
|
| 147 | + 'name' => __( 'Bold 700 Italic', 'redux-framework' ), |
|
| 148 | + ), |
|
| 149 | + ), |
|
| 150 | + 'show_import_export' => true, |
|
| 151 | + 'show_options_object' => true, |
|
| 152 | + 'dev_mode' => true, |
|
| 153 | + 'templates_path' => '', |
|
| 154 | + 'ajax_save' => true, |
|
| 155 | + 'use_cdn' => true, |
|
| 156 | + 'cdn_check_time' => 1440, |
|
| 157 | + 'options_api' => true, |
|
| 158 | + 'allow_tracking' => true, |
|
| 159 | + 'admin_theme' => 'wp', |
|
| 160 | + 'elusive_frontend' => false, |
|
| 161 | + 'fontawesome_frontend' => false, |
|
| 162 | + 'flyout_submenus' => true, |
|
| 163 | + 'font_display' => 'swap', // block|swap|fallback|optional. |
|
| 164 | + 'load_on_cron' => false, |
|
| 165 | + 'search' => false, |
|
| 166 | + 'widget_area' => false, |
|
| 167 | + 'custom_fonts' => true, |
|
| 168 | + ); |
|
| 169 | + |
|
| 170 | + $args = Redux_Functions::parse_args( $args, $default ); |
|
| 171 | + |
|
| 172 | + $args = $this->args( $args ); |
|
| 173 | + |
|
| 174 | + $args = $this->default_cleanup( $args ); |
|
| 175 | + |
|
| 176 | + if ( ! in_array( $args['font_display'], array( 'block', 'swap', 'fallback', 'optional' ), true ) ) { |
|
| 177 | + $args['font_display'] = 'swap'; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + if ( isset( $args['async_typography'] ) && $args['async_typography'] ) { |
|
| 181 | + $args['async_typography'] = false; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + $this->get = $args; |
|
| 185 | + |
|
| 186 | + $this->parent->args = $args; |
|
| 187 | + |
|
| 188 | + if ( 'redux_extensions_demo' !== $args['opt_name'] && 'redux_demo' !== $args['opt_name'] ) { |
|
| 189 | + $this->change_demo_defaults( $args ); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * Builds and sanitizes a global args array. |
|
| 195 | + * |
|
| 196 | + * @param array $args Global args. |
|
| 197 | + * |
|
| 198 | + * @return array |
|
| 199 | + */ |
|
| 200 | + private function args( array $args ): array { |
|
| 201 | + $args = $this->no_errors_please( $args ); |
|
| 202 | + |
|
| 203 | + $this->parent->old_opt_name = $args['opt_name']; |
|
| 204 | + |
|
| 205 | + $args = $this->filters( $args ); |
|
| 206 | + |
|
| 207 | + if ( ! function_exists( 'wp_rand' ) ) { |
|
| 208 | + require_once ABSPATH . '/wp-includes/pluggable.php'; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + if ( $args['opt_name'] === $this->parent->old_opt_name ) { |
|
| 212 | + $this->parent->old_opt_name = null; |
|
| 213 | + unset( $this->parent->old_opt_name ); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // Do not save the defaults if we're on a live preview! |
|
| 217 | + if ( 'customize' === $GLOBALS['pagenow'] && isset( $_GET['customize_theme'] ) && ! empty( $_GET['customize_theme'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 218 | + $args['save_defaults'] = false; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + return $this->shim( $args ); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Apply filters to arg data. |
|
| 226 | + * |
|
| 227 | + * @param array $args Global args. |
|
| 228 | + * |
|
| 229 | + * @return mixed|void |
|
| 230 | + */ |
|
| 231 | + private function filters( array $args ) { |
|
| 232 | + /** |
|
| 233 | + * Filter 'redux/args/{opt_name}' |
|
| 234 | + * |
|
| 235 | + * @param array $args ReduxFramework configuration |
|
| 236 | + */ |
|
| 237 | + |
|
| 238 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 239 | + $args = apply_filters( "redux/args/{$args['opt_name']}", $args ); |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Filter 'redux/options/{opt_name}/args' |
|
| 243 | + * |
|
| 244 | + * @param array $args ReduxFramework configuration |
|
| 245 | + */ |
|
| 246 | + |
|
| 247 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 248 | + return apply_filters( "redux/options/{$args['opt_name']}/args", $args ); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Sanitize args that should not be empty. |
|
| 253 | + * |
|
| 254 | + * @param array $args Global args. |
|
| 255 | + * |
|
| 256 | + * @return array |
|
| 257 | + */ |
|
| 258 | + private function no_errors_please( array $args ): array { |
|
| 259 | + if ( empty( $args['transient_time'] ) ) { |
|
| 260 | + $args['transient_time'] = 60 * MINUTE_IN_SECONDS; |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + if ( empty( $args['footer_credit'] ) ) { |
|
| 264 | + |
|
| 265 | + $footer_text = sprintf( |
|
| 266 | + /* translators: 1: Redux, 2: Link to plugin review */ |
|
| 267 | + __( 'Enjoyed %1$s? Please leave us a %2$s rating. We really appreciate your support!', 'redux-framework' ), |
|
| 268 | + '<strong>' . __( 'Redux', 'redux-framework' ) . '</strong>', |
|
| 269 | + '<a href="https://wordpress.org/support/plugin/redux-framework/reviews/?filter=5/#new-post" target="_blank">★★★★★</a>' |
|
| 270 | + ); |
|
| 271 | + $args['footer_credit'] = '<span id="footer-thankyou">' . $footer_text . '</span>'; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + if ( empty( $args['menu_title'] ) ) { |
|
| 275 | + $args['menu_title'] = esc_html__( 'Options', 'redux-framework' ); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + if ( empty( $args['page_title'] ) ) { |
|
| 279 | + $args['page_title'] = esc_html__( 'Options', 'redux-framework' ); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // Auto creates the page_slug appropriately. |
|
| 283 | + if ( empty( $args['page_slug'] ) ) { |
|
| 284 | + if ( ! empty( $args['display_name'] ) ) { |
|
| 285 | + $args['page_slug'] = sanitize_html_class( $args['display_name'] ); |
|
| 286 | + } elseif ( ! empty( $args['page_title'] ) ) { |
|
| 287 | + $args['page_slug'] = sanitize_html_class( $args['page_title'] ); |
|
| 288 | + } elseif ( ! empty( $args['menu_title'] ) ) { |
|
| 289 | + $args['page_slug'] = sanitize_html_class( $args['menu_title'] ); |
|
| 290 | + } else { |
|
| 291 | + $args['page_slug'] = str_replace( '-', '_', $args['opt_name'] ); |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + return $args; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + /** |
|
| 299 | + * Shims for much older v3 configs. |
|
| 300 | + * |
|
| 301 | + * @param array $args Global args. |
|
| 302 | + * |
|
| 303 | + * @return array |
|
| 304 | + */ |
|
| 305 | + private function shim( array $args ): array { |
|
| 306 | + /** |
|
| 307 | + * SHIM SECTION |
|
| 308 | + * Old variables and ways of doing things that need correcting. ;) |
|
| 309 | + * */ |
|
| 310 | + // Variable name change. |
|
| 311 | + if ( ! empty( $args['page_cap'] ) ) { |
|
| 312 | + $args['page_permissions'] = $args['page_cap']; |
|
| 313 | + unset( $args['page_cap'] ); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + if ( ! empty( $args['page_position'] ) ) { |
|
| 317 | + $args['page_priority'] = $args['page_position']; |
|
| 318 | + unset( $args['page_position'] ); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + if ( ! empty( $args['page_type'] ) ) { |
|
| 322 | + $args['menu_type'] = $args['page_type']; |
|
| 323 | + unset( $args['page_type'] ); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + return $args; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + /** |
|
| 330 | + * Verify to see if dev has bothered to change admin bar links and share icons from demo data to their own. |
|
| 331 | + * |
|
| 332 | + * @param array $args Global args. |
|
| 333 | + */ |
|
| 334 | + private function change_demo_defaults( array $args ) { |
|
| 335 | + if ( $args['dev_mode'] || true === Redux_Helpers::is_local_host() ) { |
|
| 336 | + if ( ! empty( $args['admin_bar_links'] ) ) { |
|
| 337 | + foreach ( $args['admin_bar_links'] as $arr ) { |
|
| 338 | + if ( is_array( $arr ) && ! empty( $arr ) ) { |
|
| 339 | + foreach ( $arr as $y ) { |
|
| 340 | + if ( strpos( Redux_Core::strtolower( $y ), 'redux' ) !== false ) { |
|
| 341 | + $this->omit_items = true; |
|
| 342 | + break; |
|
| 343 | + } |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + if ( ! empty( $args['share_icons'] ) ) { |
|
| 350 | + foreach ( $args['share_icons'] as $arr ) { |
|
| 351 | + if ( is_array( $arr ) && ! empty( $arr ) ) { |
|
| 352 | + foreach ( $arr as $y ) { |
|
| 353 | + if ( strpos( Redux_Core::strtolower( $y ), 'redux' ) !== false ) { |
|
| 354 | + $this->omit_icons = true; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | + } |
|
| 359 | + } |
|
| 360 | + } |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Fix other arg criteria that sometimes gets hosed up. |
|
| 365 | + * |
|
| 366 | + * @param array $args Global args. |
|
| 367 | + * |
|
| 368 | + * @return array |
|
| 369 | + * @noinspection PhpStrictComparisonWithOperandsOfDifferentTypesInspection |
|
| 370 | + */ |
|
| 371 | + private function default_cleanup( array $args ): array { |
|
| 372 | + |
|
| 373 | + // Fix the global variable name. |
|
| 374 | + if ( '' === $args['global_variable'] && false !== $args['global_variable'] ) { |
|
| 375 | + $args['global_variable'] = str_replace( '-', '_', $args['opt_name'] ); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + if ( isset( $args['customizer_only'] ) && $args['customizer_only'] ) { |
|
| 379 | + $args['menu_type'] = 'hidden'; |
|
| 380 | + $args['customizer'] = true; |
|
| 381 | + $args['admin_bar'] = false; |
|
| 382 | + $args['allow_sub_menu'] = false; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + // Check if the Airplane Mode plugin is installed. |
|
| 386 | + if ( class_exists( 'Airplane_Mode_Core' ) ) { |
|
| 387 | + $airplane = Airplane_Mode_Core::getInstance(); |
|
| 388 | + if ( method_exists( $airplane, 'enabled' ) ) { |
|
| 389 | + if ( $airplane->enabled() ) { |
|
| 390 | + $args['use_cdn'] = false; |
|
| 391 | + } |
|
| 392 | + } elseif ( 'on' === $airplane->check_status() ) { |
|
| 393 | + $args['use_cdn'] = false; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + return $args; |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | 400 | } |
@@ -11,299 +11,299 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Shortcodes' ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Redux Framework shortcode extension class. Takes the common WordPress functions `wp_get_theme()` and `bloginfo()` and a few other functions and makes them accessible via shortcodes. Below you will find a table for the possible shortcodes and their values. |
|
| 16 | - * | shortcode | Function | Description | |
|
| 17 | - * |-----------|----------|-------------| |
|
| 18 | - * | blog-name | bloginfo("name") | Displays the "Site Title" set in Settings > General. This data is retrieved from the "blogname" record in the wp_options table. | |
|
| 19 | - * | blog-description | bloginfo("description") | Displays the "Tagline" set in Settings > General. This data is retrieved from the "blogdescription" record in the wp_options table.| |
|
| 20 | - * | blog-wpurl | bloginfo("wpurl") | Displays the "WordPress address (URL)" set in Settings > General. This data is retrieved from the "siteurl" record in the wp_options table. Consider using **blog-root_url** instead, especially for multi-site configurations using paths instead of subdomains (it will return the root site not the current sub-site). | |
|
| 21 | - * | blog-root_url | site_url() | Return the root site, not the current sub-site. | |
|
| 22 | - * | blog-url | home_url() | Displays the "Site address (URL)" set in Settings > General. This data is retrieved from the "home" record in the wp_options table. | |
|
| 23 | - * | blog-admin_email | bloginfo("admin_email") | Displays the "E-mail address" set in Settings > General. This data is retrieved from the "admin_email" record in the wp_options table.| |
|
| 24 | - * | blog-charset | bloginfo("charset") | Displays the "Encoding for pages and feeds" set in Settings > Reading. This data is retrieved from the "blog_charset" record in the wp_options table. Note: In Version 3.5.0 and later, character encoding is no longer configurable from the Administration Panel. Therefore, this parameter always echoes "UTF-8", which is the default encoding of WordPress.| |
|
| 25 | - * | blog-version | bloginfo("version") | Displays the WordPress Version you use. This data is retrieved from the $wp_version variable set in wp-includes/version.php.| |
|
| 26 | - * | blog-html_type | bloginfo("html_type") | Displays the Content-Type of WordPress HTML pages (default: "text/html"). This data is retrieved from the "html_type" record in the wp_options table. Themes and plugins can override the default value using the pre_option_html_type filter.| |
|
| 27 | - * | blog-text_direction | bloginfo("text_direction") | Displays the Text Direction of WordPress HTML pages. Consider using **blog-text_direction_boolean** instead if you want a true/false response. | |
|
| 28 | - * | blog-text_direction_boolean | is_rtl() | Displays true/false check if the Text Direction of WordPress HTML pages is left instead of right | |
|
| 29 | - * | blog-language | bloginfo("language") | Displays the language of WordPress.| |
|
| 30 | - * | blog-stylesheet_url | get_stylesheet_uri() | Displays the primary CSS (usually style.css) file URL of the active theme. | |
|
| 31 | - * | blog-stylesheet_directory | bloginfo("stylesheet_directory") | Displays the stylesheet directory URL of the active theme. (Was a local path in earlier WordPress versions.) Consider echoing get_stylesheet_directory_uri() instead.| |
|
| 32 | - * | blog-template_url | get_template_directory_uri() | Parent template uri. Consider using **blog-child_template_url** for the child template URI. | |
|
| 33 | - * | blog-child_template_url | get_stylesheet_directory_uri() | Child template URI. | |
|
| 34 | - * | blog-pingback_url | bloginfo("pingback_url") | Displays the Pingback XML-RPC file URL (xmlrpc.php).| |
|
| 35 | - * | blog-atom_url | bloginfo("atom_url") | Displays the Atom feed URL (/feed/atom).| |
|
| 36 | - * | blog-rdf_url | bloginfo("rdf_url") | Displays the RDF/RSS 1.0 feed URL (/feed/rfd).| |
|
| 37 | - * | blog-rss_url | bloginfo("rss_url") | Displays the RSS 0.92 feed URL (/feed/rss).| |
|
| 38 | - * | blog-rss2_url | bloginfo("rss2_url") | Displays the RSS 2.0 feed URL (/feed).| |
|
| 39 | - * | blog-comments_atom_url | bloginfo("comments_atom_url") | Displays the comments Atom feed URL (/comments/feed).| |
|
| 40 | - * | blog-comments_rss2_url | bloginfo("comments_rss2_url") | Displays the comments RSS 2.0 feed URL (/comments/feed).| |
|
| 41 | - * | login-url | wp_login_url() | Returns the WordPress login URL. | |
|
| 42 | - * | login-url | wp_logout_url() | Returns the WordPress logout URL. | |
|
| 43 | - * | current_year | date("Y") | Returns the current year. | |
|
| 44 | - * | theme-name | $theme_info->get("Name") | Theme name as given in theme's style.css | |
|
| 45 | - * | theme-uri | $theme_info->get("ThemeURI") | The path to the theme's directory | |
|
| 46 | - * | theme-description | $theme_info->get("Description") | The description of the theme | |
|
| 47 | - * | theme-author | $theme_info->get("Author") | The theme's author | |
|
| 48 | - * | theme-author_uri | $theme_info->get("AuthorURI") | The website of the theme author | |
|
| 49 | - * | theme-version | $theme_info->get("Version") | The version of the theme | |
|
| 50 | - * | theme-template | $theme_info->get("Template") | The folder name of the current theme | |
|
| 51 | - * | theme-status | $theme_info->get("Status") | If the theme is published | |
|
| 52 | - * | theme-tags | $theme_info->get("Tags") | Tags used to describe the theme | |
|
| 53 | - * | theme-text_domain | $theme_info->get("TextDomain") | The text domain used in the theme for translation purposes | |
|
| 54 | - * | theme-domain_path | $theme_info->get("DomainPath") | Path to the theme translation files | |
|
| 55 | - * |
|
| 56 | - * @version 1.0.0 |
|
| 57 | - */ |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Class Redux_Shortcodes |
|
| 61 | - */ |
|
| 62 | - class Redux_Shortcodes { |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Redux_Shortcodes constructor. |
|
| 66 | - */ |
|
| 67 | - public function __construct() { |
|
| 68 | - if ( ! shortcode_exists( 'bloginfo' ) ) { |
|
| 69 | - add_shortcode( 'bloginfo', array( $this, 'blog_info' ) ); |
|
| 70 | - } else { |
|
| 71 | - add_shortcode( 'redux_bloginfo', array( $this, 'blog_info' ) ); |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - if ( ! shortcode_exists( 'themeinfo' ) ) { |
|
| 75 | - add_shortcode( 'themeinfo', array( $this, 'theme_info' ) ); |
|
| 76 | - } else { |
|
| 77 | - add_shortcode( 'redux_themeinfo', array( $this, 'theme_info' ) ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - if ( ! shortcode_exists( 'date' ) ) { |
|
| 81 | - add_shortcode( 'date', array( $this, 'date' ) ); |
|
| 82 | - } else { |
|
| 83 | - add_shortcode( 'redux_date', array( $this, 'date' ) ); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Return site/blog info by a validated selector. |
|
| 89 | - * Assumes the return value is printed into HTML (text node). |
|
| 90 | - * If you need raw values for other contexts, remove the esc_* here |
|
| 91 | - * and escape at the final render point instead. |
|
| 92 | - * |
|
| 93 | - * @param array|string $atts Attributes. |
|
| 94 | - * @param string|null $content Content. |
|
| 95 | - * |
|
| 96 | - * @return string Escaped for HTML text (URLs are escaped with esc_url()). |
|
| 97 | - */ |
|
| 98 | - public function blog_info( $atts = array(), ?string $content = null ): string { |
|
| 99 | - |
|
| 100 | - // Normalize and merge defaults. |
|
| 101 | - $atts = is_array( $atts ) ? wp_unslash( $atts ) : array(); |
|
| 102 | - $atts = shortcode_atts( |
|
| 103 | - array( |
|
| 104 | - 'data' => '', |
|
| 105 | - ), |
|
| 106 | - $atts |
|
| 107 | - ); |
|
| 108 | - |
|
| 109 | - // Allow content as fallback for the selector. |
|
| 110 | - if ( null !== $content && '' === $atts['data'] ) { |
|
| 111 | - $atts['data'] = $content; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - // Validate selector as a key and clamp length. |
|
| 115 | - $key = substr( sanitize_key( $atts['data'] ), 0, 64 ); |
|
| 116 | - |
|
| 117 | - // Map aliases -> handlers. |
|
| 118 | - // Keep your original intent (filesystem paths vs URIs) but make it safe and explicit. |
|
| 119 | - switch ( $key ) { |
|
| 120 | - // Filesystem paths (escape as text). |
|
| 121 | - case 'stylesheet_directory': |
|
| 122 | - case 'child_template_directory': |
|
| 123 | - return esc_html( get_stylesheet_directory() ); |
|
| 124 | - |
|
| 125 | - case 'template_directory': |
|
| 126 | - return esc_html( get_template_directory() ); |
|
| 127 | - |
|
| 128 | - // Theme URIs. |
|
| 129 | - case 'parent_template_url': |
|
| 130 | - return esc_url( get_template_directory_uri() ); |
|
| 131 | - |
|
| 132 | - case 'child_template_url': |
|
| 133 | - case 'template_url': |
|
| 134 | - return esc_url( get_stylesheet_directory_uri() ); |
|
| 135 | - |
|
| 136 | - // URLs. |
|
| 137 | - case 'url': |
|
| 138 | - return esc_url( home_url() ); |
|
| 139 | - |
|
| 140 | - case 'root_url': |
|
| 141 | - return esc_url( site_url() ); |
|
| 142 | - |
|
| 143 | - case 'stylesheet_url': |
|
| 144 | - return esc_url( get_stylesheet_uri() ); |
|
| 145 | - |
|
| 146 | - case 'logout_url': |
|
| 147 | - return esc_url( wp_logout_url() ); |
|
| 148 | - |
|
| 149 | - case 'login_url': |
|
| 150 | - return esc_url( wp_login_url() ); |
|
| 151 | - |
|
| 152 | - case 'register_url': |
|
| 153 | - return esc_url( wp_registration_url() ); |
|
| 154 | - |
|
| 155 | - case 'lostpassword_url': |
|
| 156 | - case 'lost_password_url': |
|
| 157 | - return esc_url( wp_lostpassword_url() ); |
|
| 158 | - |
|
| 159 | - // Booleans. |
|
| 160 | - case 'text_direction_bool': |
|
| 161 | - case 'text_direction_boolean': |
|
| 162 | - return esc_html( is_rtl() ? '1' : '0' ); |
|
| 163 | - |
|
| 164 | - case 'is_multisite': |
|
| 165 | - return esc_html( is_multisite() ? '1' : '0' ); |
|
| 166 | - |
|
| 167 | - // Text direction as string. |
|
| 168 | - case 'text_direction': |
|
| 169 | - return esc_html( is_rtl() ? 'rtl' : 'ltr' ); |
|
| 170 | - |
|
| 171 | - default: |
|
| 172 | - // Safe fallback: pull raw blog info, then escape as text. |
|
| 173 | - // (Avoid over-sanitizing: this is trusted core data). |
|
| 174 | - $value = get_bloginfo( $key ); |
|
| 175 | - return esc_html( (string) $value ); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Get theme info. |
|
| 181 | - * |
|
| 182 | - * @param array|string $atts Attributes. |
|
| 183 | - * @param string|null $content Content. |
|
| 184 | - * |
|
| 185 | - * @return string |
|
| 186 | - */ |
|
| 187 | - public function theme_info( array $atts = array(), ?string $content = null ): string { |
|
| 188 | - // Normalize input and merge defaults. |
|
| 189 | - $atts = wp_unslash( $atts ); |
|
| 190 | - $atts = shortcode_atts( |
|
| 191 | - array( |
|
| 192 | - 'data' => '', |
|
| 193 | - ), |
|
| 194 | - $atts |
|
| 195 | - ); |
|
| 196 | - |
|
| 197 | - // Allow content as a fallback selector. |
|
| 198 | - if ( null !== $content && '' === $atts['data'] ) { |
|
| 199 | - $atts['data'] = $content; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - // Validate selector as a key. |
|
| 203 | - $key = sanitize_key( $atts['data'] ); |
|
| 204 | - |
|
| 205 | - // Map aliases -> canonical WP_Theme header keys or special handlers. |
|
| 206 | - $map = array( |
|
| 207 | - 'name' => 'Name', |
|
| 208 | - 'themeuri' => 'ThemeURI', |
|
| 209 | - 'theme_uri' => 'ThemeURI', |
|
| 210 | - 'description' => 'Description', |
|
| 211 | - 'author' => 'Author', |
|
| 212 | - 'authoruri' => 'AuthorURI', |
|
| 213 | - 'author_uri' => 'AuthorURI', |
|
| 214 | - 'version' => 'Version', |
|
| 215 | - 'template' => 'Template', |
|
| 216 | - 'status' => 'Status', |
|
| 217 | - 'tags' => 'Tags', |
|
| 218 | - 'textdomain' => 'TextDomain', |
|
| 219 | - 'text_domain' => 'TextDomain', |
|
| 220 | - 'domainpath' => 'DomainPath', |
|
| 221 | - 'domain_path' => 'DomainPath', |
|
| 222 | - 'is_child' => 'is_child', // special case. |
|
| 223 | - ); |
|
| 224 | - |
|
| 225 | - // Default to "name" when empty or unknown. |
|
| 226 | - if ( '' === $key || ! isset( $map[ $key ] ) ) { |
|
| 227 | - $key = 'name'; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - // Cache theme object. |
|
| 231 | - if ( empty( $this->theme_info ) ) { |
|
| 232 | - $this->theme_info = wp_get_theme(); |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - $canonical = $map[ $key ]; |
|
| 236 | - |
|
| 237 | - // Special case: is_child — return "1" or "0" as string. |
|
| 238 | - if ( 'is_child' === $canonical ) { |
|
| 239 | - $bool = Redux_Helpers::is_child_theme( get_template_directory() ); |
|
| 240 | - return esc_html( $bool ? '1' : '0' ); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - $value = $this->theme_info->get( $canonical ); |
|
| 244 | - |
|
| 245 | - // WP_Theme::get('Tags') may be array; normalize to string. |
|
| 246 | - if ( is_array( $value ) ) { |
|
| 247 | - $value = implode( ', ', array_filter( array_map( 'trim', $value ) ) ); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $value = (string) $value; |
|
| 251 | - |
|
| 252 | - // Escape by context. |
|
| 253 | - switch ( $canonical ) { |
|
| 254 | - case 'ThemeURI': |
|
| 255 | - case 'AuthorURI': |
|
| 256 | - // If you ultimately print this inside an href, escape at that final context instead. |
|
| 257 | - // Here we assume the plain text output of the URL. |
|
| 258 | - return esc_url( $value ); |
|
| 259 | - |
|
| 260 | - default: |
|
| 261 | - return esc_html( $value ); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Get date info. |
|
| 267 | - * |
|
| 268 | - * @param array|string $atts Attributes. |
|
| 269 | - * @param string|null $content Content. |
|
| 270 | - * |
|
| 271 | - * @return string |
|
| 272 | - */ |
|
| 273 | - public function date( $atts = array(), ?string $content = null ): string { |
|
| 274 | - |
|
| 275 | - // 1) Normalize + unslash |
|
| 276 | - $atts = is_array( $atts ) ? wp_unslash( $atts ) : array(); |
|
| 277 | - |
|
| 278 | - // 2) Default/merge (if this is a shortcode handler, pass the tag as the 3rd arg) |
|
| 279 | - $atts = shortcode_atts( |
|
| 280 | - array( |
|
| 281 | - 'data' => '', |
|
| 282 | - ), |
|
| 283 | - $atts |
|
| 284 | - ); |
|
| 285 | - |
|
| 286 | - // 3) Allow content as a fallback for the format |
|
| 287 | - if ( null !== $content && '' === $atts['data'] ) { |
|
| 288 | - // Keep content simple text; strip tags and control chars. |
|
| 289 | - $atts['data'] = sanitize_text_field( wp_unslash( $content ) ); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - // 4) Validate and constrain the format string |
|
| 293 | - $format = (string) $atts['data']; |
|
| 294 | - $format = substr( $format, 0, 64 ); // avoid absurdly long inputs. |
|
| 295 | - |
|
| 296 | - // Allow common date format tokens + typical literal punctuation and backslash for escaping. |
|
| 297 | - // If invalid chars are present, fall back to a safe default. |
|
| 298 | - if ( '' === $format || ! preg_match( '/^[A-Za-z0-9\s:\-.,\/\\\\T]+$/', $format ) ) { |
|
| 299 | - $format = 'Y'; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - // 5) Use wp_date() to respect WP timezone and locale (date_i18n is deprecated). |
|
| 303 | - $output = wp_date( $format ); |
|
| 304 | - |
|
| 305 | - // 6) Escape for HTML context before returning (safe default for shortcode/rendered output). |
|
| 306 | - return esc_html( $output ); |
|
| 307 | - } |
|
| 308 | - } |
|
| 14 | + /** |
|
| 15 | + * Redux Framework shortcode extension class. Takes the common WordPress functions `wp_get_theme()` and `bloginfo()` and a few other functions and makes them accessible via shortcodes. Below you will find a table for the possible shortcodes and their values. |
|
| 16 | + * | shortcode | Function | Description | |
|
| 17 | + * |-----------|----------|-------------| |
|
| 18 | + * | blog-name | bloginfo("name") | Displays the "Site Title" set in Settings > General. This data is retrieved from the "blogname" record in the wp_options table. | |
|
| 19 | + * | blog-description | bloginfo("description") | Displays the "Tagline" set in Settings > General. This data is retrieved from the "blogdescription" record in the wp_options table.| |
|
| 20 | + * | blog-wpurl | bloginfo("wpurl") | Displays the "WordPress address (URL)" set in Settings > General. This data is retrieved from the "siteurl" record in the wp_options table. Consider using **blog-root_url** instead, especially for multi-site configurations using paths instead of subdomains (it will return the root site not the current sub-site). | |
|
| 21 | + * | blog-root_url | site_url() | Return the root site, not the current sub-site. | |
|
| 22 | + * | blog-url | home_url() | Displays the "Site address (URL)" set in Settings > General. This data is retrieved from the "home" record in the wp_options table. | |
|
| 23 | + * | blog-admin_email | bloginfo("admin_email") | Displays the "E-mail address" set in Settings > General. This data is retrieved from the "admin_email" record in the wp_options table.| |
|
| 24 | + * | blog-charset | bloginfo("charset") | Displays the "Encoding for pages and feeds" set in Settings > Reading. This data is retrieved from the "blog_charset" record in the wp_options table. Note: In Version 3.5.0 and later, character encoding is no longer configurable from the Administration Panel. Therefore, this parameter always echoes "UTF-8", which is the default encoding of WordPress.| |
|
| 25 | + * | blog-version | bloginfo("version") | Displays the WordPress Version you use. This data is retrieved from the $wp_version variable set in wp-includes/version.php.| |
|
| 26 | + * | blog-html_type | bloginfo("html_type") | Displays the Content-Type of WordPress HTML pages (default: "text/html"). This data is retrieved from the "html_type" record in the wp_options table. Themes and plugins can override the default value using the pre_option_html_type filter.| |
|
| 27 | + * | blog-text_direction | bloginfo("text_direction") | Displays the Text Direction of WordPress HTML pages. Consider using **blog-text_direction_boolean** instead if you want a true/false response. | |
|
| 28 | + * | blog-text_direction_boolean | is_rtl() | Displays true/false check if the Text Direction of WordPress HTML pages is left instead of right | |
|
| 29 | + * | blog-language | bloginfo("language") | Displays the language of WordPress.| |
|
| 30 | + * | blog-stylesheet_url | get_stylesheet_uri() | Displays the primary CSS (usually style.css) file URL of the active theme. | |
|
| 31 | + * | blog-stylesheet_directory | bloginfo("stylesheet_directory") | Displays the stylesheet directory URL of the active theme. (Was a local path in earlier WordPress versions.) Consider echoing get_stylesheet_directory_uri() instead.| |
|
| 32 | + * | blog-template_url | get_template_directory_uri() | Parent template uri. Consider using **blog-child_template_url** for the child template URI. | |
|
| 33 | + * | blog-child_template_url | get_stylesheet_directory_uri() | Child template URI. | |
|
| 34 | + * | blog-pingback_url | bloginfo("pingback_url") | Displays the Pingback XML-RPC file URL (xmlrpc.php).| |
|
| 35 | + * | blog-atom_url | bloginfo("atom_url") | Displays the Atom feed URL (/feed/atom).| |
|
| 36 | + * | blog-rdf_url | bloginfo("rdf_url") | Displays the RDF/RSS 1.0 feed URL (/feed/rfd).| |
|
| 37 | + * | blog-rss_url | bloginfo("rss_url") | Displays the RSS 0.92 feed URL (/feed/rss).| |
|
| 38 | + * | blog-rss2_url | bloginfo("rss2_url") | Displays the RSS 2.0 feed URL (/feed).| |
|
| 39 | + * | blog-comments_atom_url | bloginfo("comments_atom_url") | Displays the comments Atom feed URL (/comments/feed).| |
|
| 40 | + * | blog-comments_rss2_url | bloginfo("comments_rss2_url") | Displays the comments RSS 2.0 feed URL (/comments/feed).| |
|
| 41 | + * | login-url | wp_login_url() | Returns the WordPress login URL. | |
|
| 42 | + * | login-url | wp_logout_url() | Returns the WordPress logout URL. | |
|
| 43 | + * | current_year | date("Y") | Returns the current year. | |
|
| 44 | + * | theme-name | $theme_info->get("Name") | Theme name as given in theme's style.css | |
|
| 45 | + * | theme-uri | $theme_info->get("ThemeURI") | The path to the theme's directory | |
|
| 46 | + * | theme-description | $theme_info->get("Description") | The description of the theme | |
|
| 47 | + * | theme-author | $theme_info->get("Author") | The theme's author | |
|
| 48 | + * | theme-author_uri | $theme_info->get("AuthorURI") | The website of the theme author | |
|
| 49 | + * | theme-version | $theme_info->get("Version") | The version of the theme | |
|
| 50 | + * | theme-template | $theme_info->get("Template") | The folder name of the current theme | |
|
| 51 | + * | theme-status | $theme_info->get("Status") | If the theme is published | |
|
| 52 | + * | theme-tags | $theme_info->get("Tags") | Tags used to describe the theme | |
|
| 53 | + * | theme-text_domain | $theme_info->get("TextDomain") | The text domain used in the theme for translation purposes | |
|
| 54 | + * | theme-domain_path | $theme_info->get("DomainPath") | Path to the theme translation files | |
|
| 55 | + * |
|
| 56 | + * @version 1.0.0 |
|
| 57 | + */ |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Class Redux_Shortcodes |
|
| 61 | + */ |
|
| 62 | + class Redux_Shortcodes { |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Redux_Shortcodes constructor. |
|
| 66 | + */ |
|
| 67 | + public function __construct() { |
|
| 68 | + if ( ! shortcode_exists( 'bloginfo' ) ) { |
|
| 69 | + add_shortcode( 'bloginfo', array( $this, 'blog_info' ) ); |
|
| 70 | + } else { |
|
| 71 | + add_shortcode( 'redux_bloginfo', array( $this, 'blog_info' ) ); |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + if ( ! shortcode_exists( 'themeinfo' ) ) { |
|
| 75 | + add_shortcode( 'themeinfo', array( $this, 'theme_info' ) ); |
|
| 76 | + } else { |
|
| 77 | + add_shortcode( 'redux_themeinfo', array( $this, 'theme_info' ) ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + if ( ! shortcode_exists( 'date' ) ) { |
|
| 81 | + add_shortcode( 'date', array( $this, 'date' ) ); |
|
| 82 | + } else { |
|
| 83 | + add_shortcode( 'redux_date', array( $this, 'date' ) ); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Return site/blog info by a validated selector. |
|
| 89 | + * Assumes the return value is printed into HTML (text node). |
|
| 90 | + * If you need raw values for other contexts, remove the esc_* here |
|
| 91 | + * and escape at the final render point instead. |
|
| 92 | + * |
|
| 93 | + * @param array|string $atts Attributes. |
|
| 94 | + * @param string|null $content Content. |
|
| 95 | + * |
|
| 96 | + * @return string Escaped for HTML text (URLs are escaped with esc_url()). |
|
| 97 | + */ |
|
| 98 | + public function blog_info( $atts = array(), ?string $content = null ): string { |
|
| 99 | + |
|
| 100 | + // Normalize and merge defaults. |
|
| 101 | + $atts = is_array( $atts ) ? wp_unslash( $atts ) : array(); |
|
| 102 | + $atts = shortcode_atts( |
|
| 103 | + array( |
|
| 104 | + 'data' => '', |
|
| 105 | + ), |
|
| 106 | + $atts |
|
| 107 | + ); |
|
| 108 | + |
|
| 109 | + // Allow content as fallback for the selector. |
|
| 110 | + if ( null !== $content && '' === $atts['data'] ) { |
|
| 111 | + $atts['data'] = $content; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + // Validate selector as a key and clamp length. |
|
| 115 | + $key = substr( sanitize_key( $atts['data'] ), 0, 64 ); |
|
| 116 | + |
|
| 117 | + // Map aliases -> handlers. |
|
| 118 | + // Keep your original intent (filesystem paths vs URIs) but make it safe and explicit. |
|
| 119 | + switch ( $key ) { |
|
| 120 | + // Filesystem paths (escape as text). |
|
| 121 | + case 'stylesheet_directory': |
|
| 122 | + case 'child_template_directory': |
|
| 123 | + return esc_html( get_stylesheet_directory() ); |
|
| 124 | + |
|
| 125 | + case 'template_directory': |
|
| 126 | + return esc_html( get_template_directory() ); |
|
| 127 | + |
|
| 128 | + // Theme URIs. |
|
| 129 | + case 'parent_template_url': |
|
| 130 | + return esc_url( get_template_directory_uri() ); |
|
| 131 | + |
|
| 132 | + case 'child_template_url': |
|
| 133 | + case 'template_url': |
|
| 134 | + return esc_url( get_stylesheet_directory_uri() ); |
|
| 135 | + |
|
| 136 | + // URLs. |
|
| 137 | + case 'url': |
|
| 138 | + return esc_url( home_url() ); |
|
| 139 | + |
|
| 140 | + case 'root_url': |
|
| 141 | + return esc_url( site_url() ); |
|
| 142 | + |
|
| 143 | + case 'stylesheet_url': |
|
| 144 | + return esc_url( get_stylesheet_uri() ); |
|
| 145 | + |
|
| 146 | + case 'logout_url': |
|
| 147 | + return esc_url( wp_logout_url() ); |
|
| 148 | + |
|
| 149 | + case 'login_url': |
|
| 150 | + return esc_url( wp_login_url() ); |
|
| 151 | + |
|
| 152 | + case 'register_url': |
|
| 153 | + return esc_url( wp_registration_url() ); |
|
| 154 | + |
|
| 155 | + case 'lostpassword_url': |
|
| 156 | + case 'lost_password_url': |
|
| 157 | + return esc_url( wp_lostpassword_url() ); |
|
| 158 | + |
|
| 159 | + // Booleans. |
|
| 160 | + case 'text_direction_bool': |
|
| 161 | + case 'text_direction_boolean': |
|
| 162 | + return esc_html( is_rtl() ? '1' : '0' ); |
|
| 163 | + |
|
| 164 | + case 'is_multisite': |
|
| 165 | + return esc_html( is_multisite() ? '1' : '0' ); |
|
| 166 | + |
|
| 167 | + // Text direction as string. |
|
| 168 | + case 'text_direction': |
|
| 169 | + return esc_html( is_rtl() ? 'rtl' : 'ltr' ); |
|
| 170 | + |
|
| 171 | + default: |
|
| 172 | + // Safe fallback: pull raw blog info, then escape as text. |
|
| 173 | + // (Avoid over-sanitizing: this is trusted core data). |
|
| 174 | + $value = get_bloginfo( $key ); |
|
| 175 | + return esc_html( (string) $value ); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Get theme info. |
|
| 181 | + * |
|
| 182 | + * @param array|string $atts Attributes. |
|
| 183 | + * @param string|null $content Content. |
|
| 184 | + * |
|
| 185 | + * @return string |
|
| 186 | + */ |
|
| 187 | + public function theme_info( array $atts = array(), ?string $content = null ): string { |
|
| 188 | + // Normalize input and merge defaults. |
|
| 189 | + $atts = wp_unslash( $atts ); |
|
| 190 | + $atts = shortcode_atts( |
|
| 191 | + array( |
|
| 192 | + 'data' => '', |
|
| 193 | + ), |
|
| 194 | + $atts |
|
| 195 | + ); |
|
| 196 | + |
|
| 197 | + // Allow content as a fallback selector. |
|
| 198 | + if ( null !== $content && '' === $atts['data'] ) { |
|
| 199 | + $atts['data'] = $content; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + // Validate selector as a key. |
|
| 203 | + $key = sanitize_key( $atts['data'] ); |
|
| 204 | + |
|
| 205 | + // Map aliases -> canonical WP_Theme header keys or special handlers. |
|
| 206 | + $map = array( |
|
| 207 | + 'name' => 'Name', |
|
| 208 | + 'themeuri' => 'ThemeURI', |
|
| 209 | + 'theme_uri' => 'ThemeURI', |
|
| 210 | + 'description' => 'Description', |
|
| 211 | + 'author' => 'Author', |
|
| 212 | + 'authoruri' => 'AuthorURI', |
|
| 213 | + 'author_uri' => 'AuthorURI', |
|
| 214 | + 'version' => 'Version', |
|
| 215 | + 'template' => 'Template', |
|
| 216 | + 'status' => 'Status', |
|
| 217 | + 'tags' => 'Tags', |
|
| 218 | + 'textdomain' => 'TextDomain', |
|
| 219 | + 'text_domain' => 'TextDomain', |
|
| 220 | + 'domainpath' => 'DomainPath', |
|
| 221 | + 'domain_path' => 'DomainPath', |
|
| 222 | + 'is_child' => 'is_child', // special case. |
|
| 223 | + ); |
|
| 224 | + |
|
| 225 | + // Default to "name" when empty or unknown. |
|
| 226 | + if ( '' === $key || ! isset( $map[ $key ] ) ) { |
|
| 227 | + $key = 'name'; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + // Cache theme object. |
|
| 231 | + if ( empty( $this->theme_info ) ) { |
|
| 232 | + $this->theme_info = wp_get_theme(); |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + $canonical = $map[ $key ]; |
|
| 236 | + |
|
| 237 | + // Special case: is_child — return "1" or "0" as string. |
|
| 238 | + if ( 'is_child' === $canonical ) { |
|
| 239 | + $bool = Redux_Helpers::is_child_theme( get_template_directory() ); |
|
| 240 | + return esc_html( $bool ? '1' : '0' ); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + $value = $this->theme_info->get( $canonical ); |
|
| 244 | + |
|
| 245 | + // WP_Theme::get('Tags') may be array; normalize to string. |
|
| 246 | + if ( is_array( $value ) ) { |
|
| 247 | + $value = implode( ', ', array_filter( array_map( 'trim', $value ) ) ); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $value = (string) $value; |
|
| 251 | + |
|
| 252 | + // Escape by context. |
|
| 253 | + switch ( $canonical ) { |
|
| 254 | + case 'ThemeURI': |
|
| 255 | + case 'AuthorURI': |
|
| 256 | + // If you ultimately print this inside an href, escape at that final context instead. |
|
| 257 | + // Here we assume the plain text output of the URL. |
|
| 258 | + return esc_url( $value ); |
|
| 259 | + |
|
| 260 | + default: |
|
| 261 | + return esc_html( $value ); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Get date info. |
|
| 267 | + * |
|
| 268 | + * @param array|string $atts Attributes. |
|
| 269 | + * @param string|null $content Content. |
|
| 270 | + * |
|
| 271 | + * @return string |
|
| 272 | + */ |
|
| 273 | + public function date( $atts = array(), ?string $content = null ): string { |
|
| 274 | + |
|
| 275 | + // 1) Normalize + unslash |
|
| 276 | + $atts = is_array( $atts ) ? wp_unslash( $atts ) : array(); |
|
| 277 | + |
|
| 278 | + // 2) Default/merge (if this is a shortcode handler, pass the tag as the 3rd arg) |
|
| 279 | + $atts = shortcode_atts( |
|
| 280 | + array( |
|
| 281 | + 'data' => '', |
|
| 282 | + ), |
|
| 283 | + $atts |
|
| 284 | + ); |
|
| 285 | + |
|
| 286 | + // 3) Allow content as a fallback for the format |
|
| 287 | + if ( null !== $content && '' === $atts['data'] ) { |
|
| 288 | + // Keep content simple text; strip tags and control chars. |
|
| 289 | + $atts['data'] = sanitize_text_field( wp_unslash( $content ) ); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + // 4) Validate and constrain the format string |
|
| 293 | + $format = (string) $atts['data']; |
|
| 294 | + $format = substr( $format, 0, 64 ); // avoid absurdly long inputs. |
|
| 295 | + |
|
| 296 | + // Allow common date format tokens + typical literal punctuation and backslash for escaping. |
|
| 297 | + // If invalid chars are present, fall back to a safe default. |
|
| 298 | + if ( '' === $format || ! preg_match( '/^[A-Za-z0-9\s:\-.,\/\\\\T]+$/', $format ) ) { |
|
| 299 | + $format = 'Y'; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + // 5) Use wp_date() to respect WP timezone and locale (date_i18n is deprecated). |
|
| 303 | + $output = wp_date( $format ); |
|
| 304 | + |
|
| 305 | + // 6) Escape for HTML context before returning (safe default for shortcode/rendered output). |
|
| 306 | + return esc_html( $output ); |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | 309 | } |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | // Safe fallback: pull raw blog info, then escape as text. |
| 173 | 173 | // (Avoid over-sanitizing: this is trusted core data). |
| 174 | 174 | $value = get_bloginfo( $key ); |
| 175 | - return esc_html( (string) $value ); |
|
| 175 | + return esc_html( ( string ) $value ); |
|
| 176 | 176 | } |
| 177 | 177 | } |
| 178 | 178 | |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | ); |
| 224 | 224 | |
| 225 | 225 | // Default to "name" when empty or unknown. |
| 226 | - if ( '' === $key || ! isset( $map[ $key ] ) ) { |
|
| 226 | + if ( '' === $key || ! isset( $map[$key] ) ) { |
|
| 227 | 227 | $key = 'name'; |
| 228 | 228 | } |
| 229 | 229 | |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | $this->theme_info = wp_get_theme(); |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - $canonical = $map[ $key ]; |
|
| 235 | + $canonical = $map[$key]; |
|
| 236 | 236 | |
| 237 | 237 | // Special case: is_child — return "1" or "0" as string. |
| 238 | 238 | if ( 'is_child' === $canonical ) { |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | $value = implode( ', ', array_filter( array_map( 'trim', $value ) ) ); |
| 248 | 248 | } |
| 249 | 249 | |
| 250 | - $value = (string) $value; |
|
| 250 | + $value = ( string ) $value; |
|
| 251 | 251 | |
| 252 | 252 | // Escape by context. |
| 253 | 253 | switch ( $canonical ) { |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | // 4) Validate and constrain the format string |
| 293 | - $format = (string) $atts['data']; |
|
| 293 | + $format = ( string ) $atts['data']; |
|
| 294 | 294 | $format = substr( $format, 0, 64 ); // avoid absurdly long inputs. |
| 295 | 295 | |
| 296 | 296 | // Allow common date format tokens + typical literal punctuation and backslash for escaping. |
@@ -12,440 +12,440 @@ |
||
| 12 | 12 | // Don't duplicate me! |
| 13 | 13 | if ( ! class_exists( 'Redux_Repeater' ) ) { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Class Redux_Repeater |
|
| 17 | - */ |
|
| 18 | - class Redux_Repeater extends Redux_Field { |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Repeater values. |
|
| 22 | - * |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - private string $repeater_values; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * Set defaults. |
|
| 29 | - */ |
|
| 30 | - public function set_defaults() { |
|
| 31 | - $this->repeater_values = ''; |
|
| 32 | - |
|
| 33 | - if ( ! isset( $this->field['bind_title'] ) && ! empty( $this->field['fields'] ) ) { |
|
| 34 | - $this->field['bind_title'] = $this->field['fields'][0]['id']; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - $default = array( |
|
| 38 | - 'group_values' => false, |
|
| 39 | - 'item_name' => '', |
|
| 40 | - 'bind_title' => true, |
|
| 41 | - 'sortable' => true, |
|
| 42 | - 'limit' => 10, |
|
| 43 | - 'init_empty' => false, |
|
| 44 | - 'panels_closed' => false, |
|
| 45 | - ); |
|
| 46 | - |
|
| 47 | - $this->field = wp_parse_args( $this->field, $default ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Field Render Function. |
|
| 52 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 53 | - * |
|
| 54 | - * @since 1.0.0 |
|
| 55 | - * @access public |
|
| 56 | - * @return void |
|
| 57 | - */ |
|
| 58 | - public function render() { |
|
| 59 | - $unallowed = array( 'tabbed', 'social_profiles', 'color_scheme', 'repeater' ); |
|
| 60 | - |
|
| 61 | - if ( isset( $this->field['group_values'] ) && $this->field['group_values'] ) { |
|
| 62 | - $this->repeater_values = '[' . $this->field['id'] . ']'; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - if ( false === $this->field['init_empty'] ) { |
|
| 66 | - $title = ''; |
|
| 67 | - |
|
| 68 | - if ( empty( $this->value ) || ! is_array( $this->value ) ) { |
|
| 69 | - $this->value = array( |
|
| 70 | - 'redux_repeater_data' => array( |
|
| 71 | - array( |
|
| 72 | - 'title' => $title, |
|
| 73 | - ), |
|
| 74 | - ), |
|
| 75 | - ); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - if ( isset( $this->field['subfields'] ) && empty( $this->field['fields'] ) ) { |
|
| 80 | - $this->field['fields'] = $this->field['subfields']; |
|
| 81 | - unset( $this->field['subfields'] ); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - echo '<div class="redux-repeater-accordion" data-id="' . esc_attr( $this->field['id'] ) . '" data-panels-closed="' . esc_attr( $this->field['panels_closed'] ) . '">'; |
|
| 85 | - |
|
| 86 | - $x = 0; |
|
| 87 | - |
|
| 88 | - if ( isset( $this->value['redux_repeater_data'] ) && is_array( $this->value['redux_repeater_data'] ) && ! empty( $this->value['redux_repeater_data'] ) ) { |
|
| 89 | - $repeaters = $this->value['redux_repeater_data']; |
|
| 90 | - |
|
| 91 | - if ( '' === $this->field['bind_title'] ) { |
|
| 92 | - $keys = array_keys( min( $repeaters ) ); |
|
| 93 | - $this->field['bind_title'] = $keys[0]; |
|
| 94 | - } |
|
| 95 | - foreach ( $repeaters as $repeater ) { |
|
| 96 | - if ( empty( $repeater ) ) { |
|
| 97 | - continue; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - echo '<div class="redux-repeater-accordion-repeater" data-sortid="' . esc_attr( $x ) . '">'; |
|
| 101 | - echo '<table style="margin-top: 0;" class="redux-repeater-accordion redux-repeater form-table no-border">'; |
|
| 102 | - echo '<fieldset class="redux-field " data-id="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 103 | - |
|
| 104 | - echo '<input type="hidden" name="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][redux_repeater_data][' . esc_attr( $x ) . '][title]" value="' . esc_attr( $repeater['title'] ) . '" class="regular-text slide-title" data-key="' . esc_attr( $x ) . '" />'; |
|
| 105 | - |
|
| 106 | - if ( isset( $this->field['bind_title'] ) ) { |
|
| 107 | - foreach ( $this->field['fields'] as $field ) { |
|
| 108 | - if ( $field['id'] === $this->field['bind_title'] ) { |
|
| 109 | - if ( isset( $field['options'] ) ) { |
|
| 110 | - |
|
| 111 | - // Sorter data filter. |
|
| 112 | - if ( 'sorter' === $field['type'] && ! empty( $field['data'] ) && is_array( $field['data'] ) ) { |
|
| 113 | - if ( ! isset( $field['args'] ) ) { |
|
| 114 | - $field['args'] = array(); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - foreach ( $field['data'] as $key => $data ) { |
|
| 118 | - if ( ! isset( $field['args'][ $key ] ) ) { |
|
| 119 | - $field['args'][ $key ] = array(); |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - $field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] ); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - $default = $field['default'] ?? ''; |
|
| 128 | - |
|
| 129 | - if ( ! empty( $this->repeater_values ) ) { |
|
| 130 | - $repeater['title'] = ! isset( $this->parent->options[ $this->field['id'] ][ $field['id'] ][ $x ] ) ? $default : $this->parent->options[ $this->field['id'] ][ $field['id'] ][ $x ]; |
|
| 131 | - } else { |
|
| 132 | - $repeater['title'] = ! isset( $this->parent->options[ $field['id'] ][ $x ] ) ? $default : $this->parent->options[ $field['id'] ][ $x ]; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - if ( isset( $field['options'] ) && is_array( $field['options'] ) ) { |
|
| 136 | - if ( isset( $field['options'][ $repeater['title'] ] ) ) { |
|
| 137 | - $repeater['title'] = $field['options'][ $repeater['title'] ]; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - if ( is_array( $repeater['title'] ) ) { |
|
| 145 | - $repeater['title'] = esc_html__( 'Title', 'redux-framework' ); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - echo '<h3><span class="redux-repeater-header">' . esc_html( $repeater['title'] ) . ' </span></h3>'; |
|
| 149 | - |
|
| 150 | - echo '<div>'; |
|
| 151 | - |
|
| 152 | - foreach ( $this->field['fields'] as $field ) { |
|
| 153 | - if ( ! isset( $field['class'] ) ) { |
|
| 154 | - $field['class'] = ''; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if ( isset( $this->field['bind_title'] ) && $field['id'] === $this->field['bind_title'] ) { |
|
| 158 | - $field['class'] .= ' bind_title'; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if ( in_array( $field['type'], $unallowed, true ) ) { |
|
| 162 | - echo esc_html__( 'The', 'redux-framework' ) . ' <code>' . esc_html( $field['type'] ) . '</code> ' . esc_html__( 'field is not supported within the Repeater field.', 'redux-framework' ); |
|
| 163 | - } else { |
|
| 164 | - $this->output_field( $field, $x ); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - if ( ! isset( $this->field['static'] ) && empty( $this->field['static'] ) ) { |
|
| 169 | - echo '<a href="javascript:void(0);" class="button deletion redux-warning-primary redux-repeaters-remove">' . esc_html__( 'Delete', 'redux-framework' ) . ' ' . esc_html( $this->field['item_name'] ) . '</a>'; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - echo '</div>'; |
|
| 173 | - echo '</fieldset>'; |
|
| 174 | - echo '</table>'; |
|
| 175 | - echo '</div>'; |
|
| 176 | - |
|
| 177 | - ++$x; |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - if ( 0 === $x || ( isset( $this->field['static'] ) && ( $x - 1 ) < $this->field['static'] ) ) { |
|
| 182 | - if ( isset( $this->field['static'] ) && $x < $this->field['static'] ) { |
|
| 183 | - $loop = $this->field['static'] - $x; |
|
| 184 | - } else { |
|
| 185 | - $loop = 1; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - $class = ''; |
|
| 189 | - |
|
| 190 | - if ( 0 === $x && true === $this->field['init_empty'] ) { |
|
| 191 | - $class = 'close-me'; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - while ( $loop > 0 ) { |
|
| 195 | - echo '<div class="redux-repeater-accordion-repeater ' . esc_attr( $class ) . '">'; |
|
| 196 | - echo '<table style="margin-top: 0;" class="redux-repeater-accordion redux-repeater form-table no-border">'; |
|
| 197 | - echo '<fieldset class="redux-field" data-id="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 198 | - |
|
| 199 | - if ( ! isset( $this->value['redux_repeater_data'][ $x ]['title'] ) && is_array( $this->value ) && isset( $this->value['redux_repeater_data'] ) && is_array( $this->value['redux_repeater_data'] ) ) { |
|
| 200 | - $this->value['redux_repeater_data'][ $x ]['title'] = null; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - echo '<input type="hidden" name="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][redux_repeater_data][' . intval( $x ) . '][title]" value="" class="regular-text slide-title" />'; |
|
| 204 | - |
|
| 205 | - echo '<h3><span class="redux-repeater-header"> </span></h3>'; |
|
| 206 | - echo '<div>'; |
|
| 207 | - |
|
| 208 | - foreach ( $this->field['fields'] as $field ) { |
|
| 209 | - if ( isset( $this->field['bind_title'] ) && $field['id'] === $this->field['bind_title'] ) { |
|
| 210 | - if ( ! isset( $field['class'] ) || ( isset( $field['title'] ) && empty( $field['title'] ) ) ) { |
|
| 211 | - $field['class'] = 'bind_title'; |
|
| 212 | - } else { |
|
| 213 | - $field['class'] .= ' bind_title'; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $this->output_field( $field, $x ); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - if ( ! isset( $this->field['static'] ) && empty( $this->field['static'] ) ) { |
|
| 221 | - echo '<a href="javascript:void(0);" class="button deletion redux-repeaters-remove">' . esc_html__( 'Delete', 'redux-framework' ) . ' ' . esc_html( $this->field['item_name'] ) . '</a>'; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - echo '</div>'; |
|
| 225 | - echo '</fieldset>'; |
|
| 226 | - echo '</table>'; |
|
| 227 | - echo '</div>'; |
|
| 228 | - |
|
| 229 | - ++$x; |
|
| 230 | - --$loop; |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - echo '</div>'; |
|
| 235 | - if ( ! isset( $this->field['static'] ) && empty( $this->field['static'] ) ) { |
|
| 236 | - $disabled = ''; |
|
| 237 | - |
|
| 238 | - if ( isset( $this->field['limit'] ) && is_integer( $this->field['limit'] ) ) { |
|
| 239 | - if ( $x >= $this->field['limit'] ) { |
|
| 240 | - $disabled = ' button-disabled'; |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - echo '<a href="javascript:void(0);" class="button redux-repeaters-add button-primary' . esc_attr( $disabled ) . '" data-name="' . esc_attr( $this->parent->args['opt_name'] . $this->repeater_values ) . '[title][]">' . esc_html__( 'Add', 'redux-framework' ) . ' ' . esc_html( $this->field['item_name'] ) . '</a><br/>'; |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Enqueue Function. |
|
| 250 | - * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 251 | - * |
|
| 252 | - * @since 1.0.0 |
|
| 253 | - * @access public |
|
| 254 | - * @return void |
|
| 255 | - */ |
|
| 256 | - public function enqueue() { |
|
| 257 | - wp_print_styles( 'editor-buttons' ); |
|
| 258 | - |
|
| 259 | - // Set up min files for dev_mode = false. |
|
| 260 | - $min = Redux_Functions::is_min(); |
|
| 261 | - |
|
| 262 | - wp_enqueue_script( |
|
| 263 | - 'redux-field-repeater', |
|
| 264 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 265 | - $this->url . 'redux-repeater' . $min . '.js', |
|
| 266 | - array( 'jquery', 'jquery-ui-core', 'jquery-ui-accordion', 'jquery-ui-sortable', 'wp-color-picker', 'redux-js' ), |
|
| 267 | - Redux_Extension_Repeater::$version, |
|
| 268 | - true |
|
| 269 | - ); |
|
| 270 | - |
|
| 271 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 272 | - wp_enqueue_style( |
|
| 273 | - 'redux-field-repeater', |
|
| 274 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 275 | - $this->url . 'redux-repeater.css', |
|
| 276 | - array(), |
|
| 277 | - Redux_Extension_Repeater::$version |
|
| 278 | - ); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - /** |
|
| 283 | - * Output field. |
|
| 284 | - * |
|
| 285 | - * @param array $field Field array. |
|
| 286 | - * @param int $x Index. |
|
| 287 | - */ |
|
| 288 | - public function output_field( array $field, int $x ) { |
|
| 289 | - $this->enqueue_dependencies( $field ); |
|
| 290 | - |
|
| 291 | - if ( ! isset( $field['class'] ) ) { |
|
| 292 | - $field['class'] = ''; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - $field['class'] .= ' repeater'; |
|
| 296 | - |
|
| 297 | - if ( ! empty( $field['title'] ) ) { |
|
| 298 | - echo '<h4>' . wp_kses_post( $field['title'] ) . '</h4>'; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - if ( ! empty( $field['subtitle'] ) ) { |
|
| 302 | - echo '<span class="description">' . wp_kses_post( $field['subtitle'] ) . '</span>'; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - $orig_field_id = $field['id']; |
|
| 306 | - |
|
| 307 | - $field['id'] = $field['id'] . '-' . $x; |
|
| 308 | - $field['name'] = $this->parent->args['opt_name'] . $this->repeater_values . '[' . $orig_field_id . ']'; |
|
| 309 | - $field['name_suffix'] = '[' . $x . ']'; |
|
| 310 | - $field['class'] .= ' in-repeater'; |
|
| 311 | - $field['repeater_id'] = $orig_field_id; |
|
| 312 | - |
|
| 313 | - if ( isset( $field['options'] ) ) { |
|
| 314 | - |
|
| 315 | - // Sorter data filter. |
|
| 316 | - if ( 'sorter' === $field['type'] && ! empty( $field['data'] ) && is_array( $field['data'] ) ) { |
|
| 317 | - if ( ! isset( $field['args'] ) ) { |
|
| 318 | - $field['args'] = array(); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - foreach ( $field['data'] as $key => $data ) { |
|
| 322 | - if ( ! isset( $field['args'][ $key ] ) ) { |
|
| 323 | - $field['args'][ $key ] = array(); |
|
| 324 | - } |
|
| 325 | - $field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] ); |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - $default = $field['default'] ?? ''; |
|
| 331 | - |
|
| 332 | - if ( ! empty( $this->repeater_values ) ) { |
|
| 333 | - $value = empty( $this->parent->options[ $this->field['id'] ][ $orig_field_id ][ $x ] ) ? $default : $this->parent->options[ $this->field['id'] ][ $orig_field_id ][ $x ]; |
|
| 334 | - } else { |
|
| 335 | - $value = empty( $this->parent->options[ $orig_field_id ][ $x ] ) ? $default : $this->parent->options[ $orig_field_id ][ $x ]; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - ob_start(); |
|
| 339 | - |
|
| 340 | - $this->parent->render_class->field_input( $field, $value ); |
|
| 341 | - |
|
| 342 | - $content = ob_get_contents(); |
|
| 343 | - |
|
| 344 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 345 | - $_field = apply_filters( 'redux-support-repeater', $content, $field, 0 ); |
|
| 346 | - |
|
| 347 | - ob_end_clean(); |
|
| 348 | - |
|
| 349 | - echo $_field; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Localize. |
|
| 355 | - * |
|
| 356 | - * @param array $field Field array. |
|
| 357 | - * @param string $value Value. |
|
| 358 | - * |
|
| 359 | - * @return array|string |
|
| 360 | - */ |
|
| 361 | - public function localize( array $field, string $value = '' ) { |
|
| 362 | - if ( isset( $field['subfields'] ) && empty( $field['fields'] ) ) { |
|
| 363 | - $field['fields'] = $field['subfields']; |
|
| 364 | - unset( $field['subfields'] ); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - if ( isset( $field['group_values'] ) && $field['group_values'] ) { |
|
| 368 | - $this->repeater_values = '[' . $field['id'] . ']'; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - $var = ''; |
|
| 372 | - |
|
| 373 | - if ( '' === $value ) { |
|
| 374 | - $value = array(); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - if ( ! empty( $field['fields'] ) ) { |
|
| 378 | - ob_start(); |
|
| 379 | - |
|
| 380 | - foreach ( $field['fields'] as $f ) { |
|
| 381 | - if ( isset( $this->field['bind_title'] ) && $f['id'] === $this->field['bind_title'] ) { |
|
| 382 | - if ( ! isset( $f['class'] ) || ( isset( $f['title'] ) && empty( $f['title'] ) ) ) { |
|
| 383 | - $f['class'] = 'bind_title'; |
|
| 384 | - } else { |
|
| 385 | - $f['class'] .= ' bind_title'; |
|
| 386 | - } |
|
| 387 | - } |
|
| 15 | + /** |
|
| 16 | + * Class Redux_Repeater |
|
| 17 | + */ |
|
| 18 | + class Redux_Repeater extends Redux_Field { |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Repeater values. |
|
| 22 | + * |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + private string $repeater_values; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * Set defaults. |
|
| 29 | + */ |
|
| 30 | + public function set_defaults() { |
|
| 31 | + $this->repeater_values = ''; |
|
| 32 | + |
|
| 33 | + if ( ! isset( $this->field['bind_title'] ) && ! empty( $this->field['fields'] ) ) { |
|
| 34 | + $this->field['bind_title'] = $this->field['fields'][0]['id']; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + $default = array( |
|
| 38 | + 'group_values' => false, |
|
| 39 | + 'item_name' => '', |
|
| 40 | + 'bind_title' => true, |
|
| 41 | + 'sortable' => true, |
|
| 42 | + 'limit' => 10, |
|
| 43 | + 'init_empty' => false, |
|
| 44 | + 'panels_closed' => false, |
|
| 45 | + ); |
|
| 46 | + |
|
| 47 | + $this->field = wp_parse_args( $this->field, $default ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Field Render Function. |
|
| 52 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 53 | + * |
|
| 54 | + * @since 1.0.0 |
|
| 55 | + * @access public |
|
| 56 | + * @return void |
|
| 57 | + */ |
|
| 58 | + public function render() { |
|
| 59 | + $unallowed = array( 'tabbed', 'social_profiles', 'color_scheme', 'repeater' ); |
|
| 60 | + |
|
| 61 | + if ( isset( $this->field['group_values'] ) && $this->field['group_values'] ) { |
|
| 62 | + $this->repeater_values = '[' . $this->field['id'] . ']'; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + if ( false === $this->field['init_empty'] ) { |
|
| 66 | + $title = ''; |
|
| 67 | + |
|
| 68 | + if ( empty( $this->value ) || ! is_array( $this->value ) ) { |
|
| 69 | + $this->value = array( |
|
| 70 | + 'redux_repeater_data' => array( |
|
| 71 | + array( |
|
| 72 | + 'title' => $title, |
|
| 73 | + ), |
|
| 74 | + ), |
|
| 75 | + ); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + if ( isset( $this->field['subfields'] ) && empty( $this->field['fields'] ) ) { |
|
| 80 | + $this->field['fields'] = $this->field['subfields']; |
|
| 81 | + unset( $this->field['subfields'] ); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + echo '<div class="redux-repeater-accordion" data-id="' . esc_attr( $this->field['id'] ) . '" data-panels-closed="' . esc_attr( $this->field['panels_closed'] ) . '">'; |
|
| 85 | + |
|
| 86 | + $x = 0; |
|
| 87 | + |
|
| 88 | + if ( isset( $this->value['redux_repeater_data'] ) && is_array( $this->value['redux_repeater_data'] ) && ! empty( $this->value['redux_repeater_data'] ) ) { |
|
| 89 | + $repeaters = $this->value['redux_repeater_data']; |
|
| 90 | + |
|
| 91 | + if ( '' === $this->field['bind_title'] ) { |
|
| 92 | + $keys = array_keys( min( $repeaters ) ); |
|
| 93 | + $this->field['bind_title'] = $keys[0]; |
|
| 94 | + } |
|
| 95 | + foreach ( $repeaters as $repeater ) { |
|
| 96 | + if ( empty( $repeater ) ) { |
|
| 97 | + continue; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + echo '<div class="redux-repeater-accordion-repeater" data-sortid="' . esc_attr( $x ) . '">'; |
|
| 101 | + echo '<table style="margin-top: 0;" class="redux-repeater-accordion redux-repeater form-table no-border">'; |
|
| 102 | + echo '<fieldset class="redux-field " data-id="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 103 | + |
|
| 104 | + echo '<input type="hidden" name="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][redux_repeater_data][' . esc_attr( $x ) . '][title]" value="' . esc_attr( $repeater['title'] ) . '" class="regular-text slide-title" data-key="' . esc_attr( $x ) . '" />'; |
|
| 105 | + |
|
| 106 | + if ( isset( $this->field['bind_title'] ) ) { |
|
| 107 | + foreach ( $this->field['fields'] as $field ) { |
|
| 108 | + if ( $field['id'] === $this->field['bind_title'] ) { |
|
| 109 | + if ( isset( $field['options'] ) ) { |
|
| 110 | + |
|
| 111 | + // Sorter data filter. |
|
| 112 | + if ( 'sorter' === $field['type'] && ! empty( $field['data'] ) && is_array( $field['data'] ) ) { |
|
| 113 | + if ( ! isset( $field['args'] ) ) { |
|
| 114 | + $field['args'] = array(); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + foreach ( $field['data'] as $key => $data ) { |
|
| 118 | + if ( ! isset( $field['args'][ $key ] ) ) { |
|
| 119 | + $field['args'][ $key ] = array(); |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + $field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] ); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + $default = $field['default'] ?? ''; |
|
| 128 | + |
|
| 129 | + if ( ! empty( $this->repeater_values ) ) { |
|
| 130 | + $repeater['title'] = ! isset( $this->parent->options[ $this->field['id'] ][ $field['id'] ][ $x ] ) ? $default : $this->parent->options[ $this->field['id'] ][ $field['id'] ][ $x ]; |
|
| 131 | + } else { |
|
| 132 | + $repeater['title'] = ! isset( $this->parent->options[ $field['id'] ][ $x ] ) ? $default : $this->parent->options[ $field['id'] ][ $x ]; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + if ( isset( $field['options'] ) && is_array( $field['options'] ) ) { |
|
| 136 | + if ( isset( $field['options'][ $repeater['title'] ] ) ) { |
|
| 137 | + $repeater['title'] = $field['options'][ $repeater['title'] ]; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + if ( is_array( $repeater['title'] ) ) { |
|
| 145 | + $repeater['title'] = esc_html__( 'Title', 'redux-framework' ); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + echo '<h3><span class="redux-repeater-header">' . esc_html( $repeater['title'] ) . ' </span></h3>'; |
|
| 149 | + |
|
| 150 | + echo '<div>'; |
|
| 151 | + |
|
| 152 | + foreach ( $this->field['fields'] as $field ) { |
|
| 153 | + if ( ! isset( $field['class'] ) ) { |
|
| 154 | + $field['class'] = ''; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if ( isset( $this->field['bind_title'] ) && $field['id'] === $this->field['bind_title'] ) { |
|
| 158 | + $field['class'] .= ' bind_title'; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if ( in_array( $field['type'], $unallowed, true ) ) { |
|
| 162 | + echo esc_html__( 'The', 'redux-framework' ) . ' <code>' . esc_html( $field['type'] ) . '</code> ' . esc_html__( 'field is not supported within the Repeater field.', 'redux-framework' ); |
|
| 163 | + } else { |
|
| 164 | + $this->output_field( $field, $x ); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + if ( ! isset( $this->field['static'] ) && empty( $this->field['static'] ) ) { |
|
| 169 | + echo '<a href="javascript:void(0);" class="button deletion redux-warning-primary redux-repeaters-remove">' . esc_html__( 'Delete', 'redux-framework' ) . ' ' . esc_html( $this->field['item_name'] ) . '</a>'; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + echo '</div>'; |
|
| 173 | + echo '</fieldset>'; |
|
| 174 | + echo '</table>'; |
|
| 175 | + echo '</div>'; |
|
| 176 | + |
|
| 177 | + ++$x; |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + if ( 0 === $x || ( isset( $this->field['static'] ) && ( $x - 1 ) < $this->field['static'] ) ) { |
|
| 182 | + if ( isset( $this->field['static'] ) && $x < $this->field['static'] ) { |
|
| 183 | + $loop = $this->field['static'] - $x; |
|
| 184 | + } else { |
|
| 185 | + $loop = 1; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + $class = ''; |
|
| 189 | + |
|
| 190 | + if ( 0 === $x && true === $this->field['init_empty'] ) { |
|
| 191 | + $class = 'close-me'; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + while ( $loop > 0 ) { |
|
| 195 | + echo '<div class="redux-repeater-accordion-repeater ' . esc_attr( $class ) . '">'; |
|
| 196 | + echo '<table style="margin-top: 0;" class="redux-repeater-accordion redux-repeater form-table no-border">'; |
|
| 197 | + echo '<fieldset class="redux-field" data-id="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 198 | + |
|
| 199 | + if ( ! isset( $this->value['redux_repeater_data'][ $x ]['title'] ) && is_array( $this->value ) && isset( $this->value['redux_repeater_data'] ) && is_array( $this->value['redux_repeater_data'] ) ) { |
|
| 200 | + $this->value['redux_repeater_data'][ $x ]['title'] = null; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + echo '<input type="hidden" name="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][redux_repeater_data][' . intval( $x ) . '][title]" value="" class="regular-text slide-title" />'; |
|
| 204 | + |
|
| 205 | + echo '<h3><span class="redux-repeater-header"> </span></h3>'; |
|
| 206 | + echo '<div>'; |
|
| 207 | + |
|
| 208 | + foreach ( $this->field['fields'] as $field ) { |
|
| 209 | + if ( isset( $this->field['bind_title'] ) && $field['id'] === $this->field['bind_title'] ) { |
|
| 210 | + if ( ! isset( $field['class'] ) || ( isset( $field['title'] ) && empty( $field['title'] ) ) ) { |
|
| 211 | + $field['class'] = 'bind_title'; |
|
| 212 | + } else { |
|
| 213 | + $field['class'] .= ' bind_title'; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $this->output_field( $field, $x ); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + if ( ! isset( $this->field['static'] ) && empty( $this->field['static'] ) ) { |
|
| 221 | + echo '<a href="javascript:void(0);" class="button deletion redux-repeaters-remove">' . esc_html__( 'Delete', 'redux-framework' ) . ' ' . esc_html( $this->field['item_name'] ) . '</a>'; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + echo '</div>'; |
|
| 225 | + echo '</fieldset>'; |
|
| 226 | + echo '</table>'; |
|
| 227 | + echo '</div>'; |
|
| 228 | + |
|
| 229 | + ++$x; |
|
| 230 | + --$loop; |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + echo '</div>'; |
|
| 235 | + if ( ! isset( $this->field['static'] ) && empty( $this->field['static'] ) ) { |
|
| 236 | + $disabled = ''; |
|
| 237 | + |
|
| 238 | + if ( isset( $this->field['limit'] ) && is_integer( $this->field['limit'] ) ) { |
|
| 239 | + if ( $x >= $this->field['limit'] ) { |
|
| 240 | + $disabled = ' button-disabled'; |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + echo '<a href="javascript:void(0);" class="button redux-repeaters-add button-primary' . esc_attr( $disabled ) . '" data-name="' . esc_attr( $this->parent->args['opt_name'] . $this->repeater_values ) . '[title][]">' . esc_html__( 'Add', 'redux-framework' ) . ' ' . esc_html( $this->field['item_name'] ) . '</a><br/>'; |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Enqueue Function. |
|
| 250 | + * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 251 | + * |
|
| 252 | + * @since 1.0.0 |
|
| 253 | + * @access public |
|
| 254 | + * @return void |
|
| 255 | + */ |
|
| 256 | + public function enqueue() { |
|
| 257 | + wp_print_styles( 'editor-buttons' ); |
|
| 258 | + |
|
| 259 | + // Set up min files for dev_mode = false. |
|
| 260 | + $min = Redux_Functions::is_min(); |
|
| 261 | + |
|
| 262 | + wp_enqueue_script( |
|
| 263 | + 'redux-field-repeater', |
|
| 264 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 265 | + $this->url . 'redux-repeater' . $min . '.js', |
|
| 266 | + array( 'jquery', 'jquery-ui-core', 'jquery-ui-accordion', 'jquery-ui-sortable', 'wp-color-picker', 'redux-js' ), |
|
| 267 | + Redux_Extension_Repeater::$version, |
|
| 268 | + true |
|
| 269 | + ); |
|
| 270 | + |
|
| 271 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 272 | + wp_enqueue_style( |
|
| 273 | + 'redux-field-repeater', |
|
| 274 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 275 | + $this->url . 'redux-repeater.css', |
|
| 276 | + array(), |
|
| 277 | + Redux_Extension_Repeater::$version |
|
| 278 | + ); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + /** |
|
| 283 | + * Output field. |
|
| 284 | + * |
|
| 285 | + * @param array $field Field array. |
|
| 286 | + * @param int $x Index. |
|
| 287 | + */ |
|
| 288 | + public function output_field( array $field, int $x ) { |
|
| 289 | + $this->enqueue_dependencies( $field ); |
|
| 290 | + |
|
| 291 | + if ( ! isset( $field['class'] ) ) { |
|
| 292 | + $field['class'] = ''; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + $field['class'] .= ' repeater'; |
|
| 296 | + |
|
| 297 | + if ( ! empty( $field['title'] ) ) { |
|
| 298 | + echo '<h4>' . wp_kses_post( $field['title'] ) . '</h4>'; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + if ( ! empty( $field['subtitle'] ) ) { |
|
| 302 | + echo '<span class="description">' . wp_kses_post( $field['subtitle'] ) . '</span>'; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + $orig_field_id = $field['id']; |
|
| 306 | + |
|
| 307 | + $field['id'] = $field['id'] . '-' . $x; |
|
| 308 | + $field['name'] = $this->parent->args['opt_name'] . $this->repeater_values . '[' . $orig_field_id . ']'; |
|
| 309 | + $field['name_suffix'] = '[' . $x . ']'; |
|
| 310 | + $field['class'] .= ' in-repeater'; |
|
| 311 | + $field['repeater_id'] = $orig_field_id; |
|
| 312 | + |
|
| 313 | + if ( isset( $field['options'] ) ) { |
|
| 314 | + |
|
| 315 | + // Sorter data filter. |
|
| 316 | + if ( 'sorter' === $field['type'] && ! empty( $field['data'] ) && is_array( $field['data'] ) ) { |
|
| 317 | + if ( ! isset( $field['args'] ) ) { |
|
| 318 | + $field['args'] = array(); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + foreach ( $field['data'] as $key => $data ) { |
|
| 322 | + if ( ! isset( $field['args'][ $key ] ) ) { |
|
| 323 | + $field['args'][ $key ] = array(); |
|
| 324 | + } |
|
| 325 | + $field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] ); |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + $default = $field['default'] ?? ''; |
|
| 331 | + |
|
| 332 | + if ( ! empty( $this->repeater_values ) ) { |
|
| 333 | + $value = empty( $this->parent->options[ $this->field['id'] ][ $orig_field_id ][ $x ] ) ? $default : $this->parent->options[ $this->field['id'] ][ $orig_field_id ][ $x ]; |
|
| 334 | + } else { |
|
| 335 | + $value = empty( $this->parent->options[ $orig_field_id ][ $x ] ) ? $default : $this->parent->options[ $orig_field_id ][ $x ]; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + ob_start(); |
|
| 339 | + |
|
| 340 | + $this->parent->render_class->field_input( $field, $value ); |
|
| 341 | + |
|
| 342 | + $content = ob_get_contents(); |
|
| 343 | + |
|
| 344 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 345 | + $_field = apply_filters( 'redux-support-repeater', $content, $field, 0 ); |
|
| 346 | + |
|
| 347 | + ob_end_clean(); |
|
| 348 | + |
|
| 349 | + echo $_field; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Localize. |
|
| 355 | + * |
|
| 356 | + * @param array $field Field array. |
|
| 357 | + * @param string $value Value. |
|
| 358 | + * |
|
| 359 | + * @return array|string |
|
| 360 | + */ |
|
| 361 | + public function localize( array $field, string $value = '' ) { |
|
| 362 | + if ( isset( $field['subfields'] ) && empty( $field['fields'] ) ) { |
|
| 363 | + $field['fields'] = $field['subfields']; |
|
| 364 | + unset( $field['subfields'] ); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + if ( isset( $field['group_values'] ) && $field['group_values'] ) { |
|
| 368 | + $this->repeater_values = '[' . $field['id'] . ']'; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + $var = ''; |
|
| 372 | + |
|
| 373 | + if ( '' === $value ) { |
|
| 374 | + $value = array(); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + if ( ! empty( $field['fields'] ) ) { |
|
| 378 | + ob_start(); |
|
| 379 | + |
|
| 380 | + foreach ( $field['fields'] as $f ) { |
|
| 381 | + if ( isset( $this->field['bind_title'] ) && $f['id'] === $this->field['bind_title'] ) { |
|
| 382 | + if ( ! isset( $f['class'] ) || ( isset( $f['title'] ) && empty( $f['title'] ) ) ) { |
|
| 383 | + $f['class'] = 'bind_title'; |
|
| 384 | + } else { |
|
| 385 | + $f['class'] .= ' bind_title'; |
|
| 386 | + } |
|
| 387 | + } |
|
| 388 | 388 | |
| 389 | - $this->output_field( $f, 99999 ); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - $var = ob_get_contents(); |
|
| 389 | + $this->output_field( $f, 99999 ); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + $var = ob_get_contents(); |
|
| 393 | 393 | |
| 394 | - $var = array( |
|
| 395 | - 'html' => $var . '<a href="javascript:void(0);" class="button deletion redux-repeaters-remove">' . esc_html__( 'Delete', 'redux-framework' ) . '</a>', |
|
| 396 | - 'count' => count( $value ), |
|
| 397 | - 'sortable' => true, |
|
| 398 | - 'limit' => '', |
|
| 399 | - 'name' => $this->parent->args['opt_name'] . '[' . $field['id'] . '][0]', |
|
| 400 | - ); |
|
| 401 | - |
|
| 402 | - if ( isset( $field['sortable'] ) && is_bool( $this->field['sortable'] ) ) { |
|
| 403 | - $var['sortable'] = $field['sortable']; |
|
| 404 | - } |
|
| 405 | - if ( isset( $field['limit'] ) && is_integer( $field['limit'] ) ) { |
|
| 406 | - $var['limit'] = $field['limit']; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - ob_end_clean(); |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - return $var; |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * Enqueue Deps. |
|
| 417 | - * |
|
| 418 | - * @param array $field Field. |
|
| 419 | - */ |
|
| 420 | - private function enqueue_dependencies( array $field ) { |
|
| 421 | - $field_type = $field['type']; |
|
| 422 | - |
|
| 423 | - $field_class = 'Redux_' . $field_type; |
|
| 394 | + $var = array( |
|
| 395 | + 'html' => $var . '<a href="javascript:void(0);" class="button deletion redux-repeaters-remove">' . esc_html__( 'Delete', 'redux-framework' ) . '</a>', |
|
| 396 | + 'count' => count( $value ), |
|
| 397 | + 'sortable' => true, |
|
| 398 | + 'limit' => '', |
|
| 399 | + 'name' => $this->parent->args['opt_name'] . '[' . $field['id'] . '][0]', |
|
| 400 | + ); |
|
| 401 | + |
|
| 402 | + if ( isset( $field['sortable'] ) && is_bool( $this->field['sortable'] ) ) { |
|
| 403 | + $var['sortable'] = $field['sortable']; |
|
| 404 | + } |
|
| 405 | + if ( isset( $field['limit'] ) && is_integer( $field['limit'] ) ) { |
|
| 406 | + $var['limit'] = $field['limit']; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + ob_end_clean(); |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + return $var; |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * Enqueue Deps. |
|
| 417 | + * |
|
| 418 | + * @param array $field Field. |
|
| 419 | + */ |
|
| 420 | + private function enqueue_dependencies( array $field ) { |
|
| 421 | + $field_type = $field['type']; |
|
| 422 | + |
|
| 423 | + $field_class = 'Redux_' . $field_type; |
|
| 424 | 424 | |
| 425 | - if ( ! class_exists( $field_class ) ) { |
|
| 426 | - $field_type = str_replace( '_', '-', $field_type ); |
|
| 425 | + if ( ! class_exists( $field_class ) ) { |
|
| 426 | + $field_type = str_replace( '_', '-', $field_type ); |
|
| 427 | 427 | |
| 428 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 429 | - $class_file = apply_filters( 'redux-typeclass-load', ReduxFramework::$_dir . 'inc/fields/' . $field_type . '/class-redux-' . $field_type . '.php', $field_class ); |
|
| 428 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 429 | + $class_file = apply_filters( 'redux-typeclass-load', ReduxFramework::$_dir . 'inc/fields/' . $field_type . '/class-redux-' . $field_type . '.php', $field_class ); |
|
| 430 | 430 | |
| 431 | - if ( file_exists( $class_file ) ) { |
|
| 432 | - require_once $class_file; |
|
| 433 | - } |
|
| 434 | - } |
|
| 431 | + if ( file_exists( $class_file ) ) { |
|
| 432 | + require_once $class_file; |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | 435 | |
| 436 | - if ( class_exists( $field_class ) && method_exists( $field_class, 'enqueue' ) ) { |
|
| 437 | - $enqueue = new $field_class( '', '', $this->parent ); |
|
| 438 | - $enqueue->enqueue(); |
|
| 439 | - } |
|
| 436 | + if ( class_exists( $field_class ) && method_exists( $field_class, 'enqueue' ) ) { |
|
| 437 | + $enqueue = new $field_class( '', '', $this->parent ); |
|
| 438 | + $enqueue->enqueue(); |
|
| 439 | + } |
|
| 440 | 440 | |
| 441 | - if ( class_exists( $field_class ) && method_exists( $field_class, 'localize' ) ) { |
|
| 442 | - |
|
| 443 | - $enqueue = new $field_class( '', '', $this->parent ); |
|
| 444 | - |
|
| 445 | - $data = $enqueue->localize( $field ); |
|
| 446 | - |
|
| 447 | - $this->parent->enqueue_class->localize_data[ $field['type'] ][ $field['id'] ] = $data; |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - } |
|
| 441 | + if ( class_exists( $field_class ) && method_exists( $field_class, 'localize' ) ) { |
|
| 442 | + |
|
| 443 | + $enqueue = new $field_class( '', '', $this->parent ); |
|
| 444 | + |
|
| 445 | + $data = $enqueue->localize( $field ); |
|
| 446 | + |
|
| 447 | + $this->parent->enqueue_class->localize_data[ $field['type'] ][ $field['id'] ] = $data; |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | 451 | } |
@@ -115,11 +115,11 @@ discard block |
||
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | foreach ( $field['data'] as $key => $data ) { |
| 118 | - if ( ! isset( $field['args'][ $key ] ) ) { |
|
| 119 | - $field['args'][ $key ] = array(); |
|
| 118 | + if ( ! isset( $field['args'][$key] ) ) { |
|
| 119 | + $field['args'][$key] = array(); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | - $field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] ); |
|
| 122 | + $field['options'][$key] = $this->parent->wordpress_data->get( $data, $field['args'][$key], $this->parent->args['opt_name'] ); |
|
| 123 | 123 | } |
| 124 | 124 | } |
| 125 | 125 | } |
@@ -127,14 +127,14 @@ discard block |
||
| 127 | 127 | $default = $field['default'] ?? ''; |
| 128 | 128 | |
| 129 | 129 | if ( ! empty( $this->repeater_values ) ) { |
| 130 | - $repeater['title'] = ! isset( $this->parent->options[ $this->field['id'] ][ $field['id'] ][ $x ] ) ? $default : $this->parent->options[ $this->field['id'] ][ $field['id'] ][ $x ]; |
|
| 130 | + $repeater['title'] = ! isset( $this->parent->options[$this->field['id']][$field['id']][$x] ) ? $default : $this->parent->options[$this->field['id']][$field['id']][$x]; |
|
| 131 | 131 | } else { |
| 132 | - $repeater['title'] = ! isset( $this->parent->options[ $field['id'] ][ $x ] ) ? $default : $this->parent->options[ $field['id'] ][ $x ]; |
|
| 132 | + $repeater['title'] = ! isset( $this->parent->options[$field['id']][$x] ) ? $default : $this->parent->options[$field['id']][$x]; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | if ( isset( $field['options'] ) && is_array( $field['options'] ) ) { |
| 136 | - if ( isset( $field['options'][ $repeater['title'] ] ) ) { |
|
| 137 | - $repeater['title'] = $field['options'][ $repeater['title'] ]; |
|
| 136 | + if ( isset( $field['options'][$repeater['title']] ) ) { |
|
| 137 | + $repeater['title'] = $field['options'][$repeater['title']]; |
|
| 138 | 138 | } |
| 139 | 139 | } |
| 140 | 140 | } |
@@ -196,8 +196,8 @@ discard block |
||
| 196 | 196 | echo '<table style="margin-top: 0;" class="redux-repeater-accordion redux-repeater form-table no-border">'; |
| 197 | 197 | echo '<fieldset class="redux-field" data-id="' . esc_attr( $this->field['id'] ) . '">'; |
| 198 | 198 | |
| 199 | - if ( ! isset( $this->value['redux_repeater_data'][ $x ]['title'] ) && is_array( $this->value ) && isset( $this->value['redux_repeater_data'] ) && is_array( $this->value['redux_repeater_data'] ) ) { |
|
| 200 | - $this->value['redux_repeater_data'][ $x ]['title'] = null; |
|
| 199 | + if ( ! isset( $this->value['redux_repeater_data'][$x]['title'] ) && is_array( $this->value ) && isset( $this->value['redux_repeater_data'] ) && is_array( $this->value['redux_repeater_data'] ) ) { |
|
| 200 | + $this->value['redux_repeater_data'][$x]['title'] = null; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | echo '<input type="hidden" name="' . esc_attr( $this->parent->args['opt_name'] ) . '[' . esc_attr( $this->field['id'] ) . '][redux_repeater_data][' . intval( $x ) . '][title]" value="" class="regular-text slide-title" />'; |
@@ -319,10 +319,10 @@ discard block |
||
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | foreach ( $field['data'] as $key => $data ) { |
| 322 | - if ( ! isset( $field['args'][ $key ] ) ) { |
|
| 323 | - $field['args'][ $key ] = array(); |
|
| 322 | + if ( ! isset( $field['args'][$key] ) ) { |
|
| 323 | + $field['args'][$key] = array(); |
|
| 324 | 324 | } |
| 325 | - $field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] ); |
|
| 325 | + $field['options'][$key] = $this->parent->wordpress_data->get( $data, $field['args'][$key], $this->parent->args['opt_name'] ); |
|
| 326 | 326 | } |
| 327 | 327 | } |
| 328 | 328 | } |
@@ -330,9 +330,9 @@ discard block |
||
| 330 | 330 | $default = $field['default'] ?? ''; |
| 331 | 331 | |
| 332 | 332 | if ( ! empty( $this->repeater_values ) ) { |
| 333 | - $value = empty( $this->parent->options[ $this->field['id'] ][ $orig_field_id ][ $x ] ) ? $default : $this->parent->options[ $this->field['id'] ][ $orig_field_id ][ $x ]; |
|
| 333 | + $value = empty( $this->parent->options[$this->field['id']][$orig_field_id][$x] ) ? $default : $this->parent->options[$this->field['id']][$orig_field_id][$x]; |
|
| 334 | 334 | } else { |
| 335 | - $value = empty( $this->parent->options[ $orig_field_id ][ $x ] ) ? $default : $this->parent->options[ $orig_field_id ][ $x ]; |
|
| 335 | + $value = empty( $this->parent->options[$orig_field_id][$x] ) ? $default : $this->parent->options[$orig_field_id][$x]; |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | ob_start(); |
@@ -444,7 +444,7 @@ discard block |
||
| 444 | 444 | |
| 445 | 445 | $data = $enqueue->localize( $field ); |
| 446 | 446 | |
| 447 | - $this->parent->enqueue_class->localize_data[ $field['type'] ][ $field['id'] ] = $data; |
|
| 447 | + $this->parent->enqueue_class->localize_data[$field['type']][$field['id']] = $data; |
|
| 448 | 448 | } |
| 449 | 449 | } |
| 450 | 450 | } |
@@ -11,211 +11,211 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Tabbed', false ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Class Redux_Tabbed |
|
| 16 | - */ |
|
| 17 | - class Redux_Tabbed extends Redux_Field { |
|
| 14 | + /** |
|
| 15 | + * Class Redux_Tabbed |
|
| 16 | + */ |
|
| 17 | + class Redux_Tabbed extends Redux_Field { |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Set field defaults. |
|
| 21 | - */ |
|
| 22 | - public function set_defaults() { |
|
| 23 | - $defaults = array( |
|
| 24 | - 'icon' => '', |
|
| 25 | - ); |
|
| 19 | + /** |
|
| 20 | + * Set field defaults. |
|
| 21 | + */ |
|
| 22 | + public function set_defaults() { |
|
| 23 | + $defaults = array( |
|
| 24 | + 'icon' => '', |
|
| 25 | + ); |
|
| 26 | 26 | |
| 27 | - $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 28 | - } |
|
| 27 | + $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Field Render Function. |
|
| 32 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 33 | - * |
|
| 34 | - * @since ReduxFramework 0.0.4 |
|
| 35 | - */ |
|
| 36 | - public function render() { |
|
| 37 | - $unallowed = array( 'tabbed', 'social_profiles', 'color_schemes', 'repeater' ); |
|
| 30 | + /** |
|
| 31 | + * Field Render Function. |
|
| 32 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 33 | + * |
|
| 34 | + * @since ReduxFramework 0.0.4 |
|
| 35 | + */ |
|
| 36 | + public function render() { |
|
| 37 | + $unallowed = array( 'tabbed', 'social_profiles', 'color_schemes', 'repeater' ); |
|
| 38 | 38 | |
| 39 | - echo '<div id="' . esc_attr( $this->field['id'] ) . '-tabbed" class="redux-tabbed" rel="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 40 | - echo '<div class="redux-tabbed-nav" data-id="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 41 | - foreach ( $this->field['tabs'] as $key => $tab ) { |
|
| 39 | + echo '<div id="' . esc_attr( $this->field['id'] ) . '-tabbed" class="redux-tabbed" rel="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 40 | + echo '<div class="redux-tabbed-nav" data-id="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 41 | + foreach ( $this->field['tabs'] as $key => $tab ) { |
|
| 42 | 42 | |
| 43 | - $tabbed_icon = ( ! empty( $tab['icon'] ) ) ? '<i class="redux-tab-icon ' . esc_attr( $tab['icon'] ) . '"></i>' : ''; |
|
| 44 | - $tabbed_active = ( empty( $key ) ) ? 'redux-tabbed-active' : ''; |
|
| 45 | - |
|
| 46 | - // Output HTML escaped above. |
|
| 47 | - // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 48 | - echo '<a href="#" class="' . esc_attr( $tabbed_active ) . '"">' . $tabbed_icon . esc_attr( $tab['title'] ) . '</a>'; |
|
| 49 | - |
|
| 50 | - } |
|
| 51 | - echo '</div>'; |
|
| 52 | - |
|
| 53 | - echo '<div class="redux-tabbed-contents">'; |
|
| 54 | - foreach ( $this->field['tabs'] as $key => $tab ) { |
|
| 55 | - |
|
| 56 | - $tabbed_hidden = ( ! empty( $key ) ) ? ' hidden' : ''; |
|
| 57 | - |
|
| 58 | - echo '<div class="redux-tabbed-content' . esc_attr( $tabbed_hidden ) . '">'; |
|
| 59 | - |
|
| 60 | - foreach ( $tab['fields'] as $field ) { |
|
| 61 | - |
|
| 62 | - if ( in_array( $field['type'], $unallowed, true ) ) { |
|
| 63 | - echo esc_html__( 'The', 'redux-framework' ) . ' <code>' . esc_html( $field['type'] ) . '</code> ' . esc_html__( 'field is not supported within the Tabbed field.', 'redux-framework' ); |
|
| 64 | - } else { |
|
| 65 | - $this->output_field( $field ); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - echo '</div>'; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - echo '</div>'; |
|
| 73 | - echo '</div>'; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * Output field. |
|
| 78 | - * |
|
| 79 | - * @param array $field Field array. |
|
| 80 | - */ |
|
| 81 | - public function output_field( array $field ) { |
|
| 82 | - $this->enqueue_dependencies( $field ); |
|
| 83 | - |
|
| 84 | - if ( ! isset( $field['class'] ) ) { |
|
| 85 | - $field['class'] = ''; |
|
| 86 | - } |
|
| 43 | + $tabbed_icon = ( ! empty( $tab['icon'] ) ) ? '<i class="redux-tab-icon ' . esc_attr( $tab['icon'] ) . '"></i>' : ''; |
|
| 44 | + $tabbed_active = ( empty( $key ) ) ? 'redux-tabbed-active' : ''; |
|
| 45 | + |
|
| 46 | + // Output HTML escaped above. |
|
| 47 | + // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 48 | + echo '<a href="#" class="' . esc_attr( $tabbed_active ) . '"">' . $tabbed_icon . esc_attr( $tab['title'] ) . '</a>'; |
|
| 49 | + |
|
| 50 | + } |
|
| 51 | + echo '</div>'; |
|
| 52 | + |
|
| 53 | + echo '<div class="redux-tabbed-contents">'; |
|
| 54 | + foreach ( $this->field['tabs'] as $key => $tab ) { |
|
| 55 | + |
|
| 56 | + $tabbed_hidden = ( ! empty( $key ) ) ? ' hidden' : ''; |
|
| 57 | + |
|
| 58 | + echo '<div class="redux-tabbed-content' . esc_attr( $tabbed_hidden ) . '">'; |
|
| 59 | + |
|
| 60 | + foreach ( $tab['fields'] as $field ) { |
|
| 61 | + |
|
| 62 | + if ( in_array( $field['type'], $unallowed, true ) ) { |
|
| 63 | + echo esc_html__( 'The', 'redux-framework' ) . ' <code>' . esc_html( $field['type'] ) . '</code> ' . esc_html__( 'field is not supported within the Tabbed field.', 'redux-framework' ); |
|
| 64 | + } else { |
|
| 65 | + $this->output_field( $field ); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + echo '</div>'; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + echo '</div>'; |
|
| 73 | + echo '</div>'; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * Output field. |
|
| 78 | + * |
|
| 79 | + * @param array $field Field array. |
|
| 80 | + */ |
|
| 81 | + public function output_field( array $field ) { |
|
| 82 | + $this->enqueue_dependencies( $field ); |
|
| 83 | + |
|
| 84 | + if ( ! isset( $field['class'] ) ) { |
|
| 85 | + $field['class'] = ''; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - $field['class'] .= ' tabbed'; |
|
| 88 | + $field['class'] .= ' tabbed'; |
|
| 89 | 89 | |
| 90 | - echo '<div class="redux-tab-field">'; |
|
| 90 | + echo '<div class="redux-tab-field">'; |
|
| 91 | 91 | |
| 92 | - if ( ! empty( $field['title'] ) ) { |
|
| 93 | - echo '<div class="redux-field-title">'; |
|
| 94 | - echo '<h4>' . wp_kses_post( $field['title'] ) . '</h4>'; |
|
| 92 | + if ( ! empty( $field['title'] ) ) { |
|
| 93 | + echo '<div class="redux-field-title">'; |
|
| 94 | + echo '<h4>' . wp_kses_post( $field['title'] ) . '</h4>'; |
|
| 95 | 95 | |
| 96 | - if ( ! empty( $field['subtitle'] ) ) { |
|
| 97 | - echo '<div class="redux-field-subtitle">' . wp_kses_post( $field['subtitle'] ) . '</div>'; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - echo '</div>'; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - $orig_field_id = $field['id']; |
|
| 104 | - |
|
| 105 | - $field['name'] = $this->parent->args['opt_name'] . '[' . $orig_field_id . ']'; |
|
| 106 | - $field['class'] .= ' in-tabbed'; |
|
| 107 | - |
|
| 108 | - if ( isset( $field['options'] ) ) { |
|
| 109 | - |
|
| 110 | - // Sorter data filter. |
|
| 111 | - if ( 'sorter' === $field['type'] && ! empty( $field['data'] ) && is_array( $field['data'] ) ) { |
|
| 112 | - if ( ! isset( $field['args'] ) ) { |
|
| 113 | - $field['args'] = array(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - foreach ( $field['data'] as $key => $data ) { |
|
| 117 | - if ( ! isset( $field['args'][ $key ] ) ) { |
|
| 118 | - $field['args'][ $key ] = array(); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - $field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] ); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $default = $field['default'] ?? null; |
|
| 127 | - |
|
| 128 | - // phpcs:ignore Squiz.PHP.CommentedOutCode.Found |
|
| 129 | - // $value = isset( $this->parent->options[ $orig_field_id ] ) && 0 !== (int) $this->parent->options[ $orig_field_id ] ? $this->parent->options[ $orig_field_id ] : $default; |
|
| 130 | - $value = $this->parent->options[ $orig_field_id ] ?? $default; |
|
| 131 | - |
|
| 132 | - $this->parent->render_class->field_input( $field, $value ); |
|
| 133 | - |
|
| 134 | - echo '<div class="clear"></div>'; |
|
| 135 | - echo '</div>'; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * Localize. |
|
| 140 | - * |
|
| 141 | - * @param array $field Field. |
|
| 142 | - * @param string $value Value. |
|
| 143 | - * |
|
| 144 | - * @return void |
|
| 145 | - */ |
|
| 146 | - public function localize( array $field, string $value = '' ) { |
|
| 147 | - ob_start(); |
|
| 148 | - |
|
| 149 | - foreach ( $field['tabs'] as $f ) { |
|
| 150 | - foreach ( $f['fields'] as $field ) { |
|
| 151 | - $this->output_field( $field ); |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - ob_end_clean(); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Enqueue Deps. |
|
| 160 | - * |
|
| 161 | - * @param array $field Field. |
|
| 162 | - */ |
|
| 163 | - private function enqueue_dependencies( array $field ) { |
|
| 164 | - $field_type = $field['type']; |
|
| 165 | - |
|
| 166 | - $field_class = 'Redux_' . $field_type; |
|
| 167 | - |
|
| 168 | - if ( ! class_exists( $field_class ) ) { |
|
| 169 | - $field_type = str_replace( '_', '-', $field_type ); |
|
| 170 | - |
|
| 171 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 172 | - $class_file = apply_filters( 'redux-typeclass-load', ReduxFramework::$_dir . 'inc/fields/' . $field_type . '/class-redux-' . $field_type . '.php', $field_class ); |
|
| 173 | - |
|
| 174 | - if ( file_exists( $class_file ) ) { |
|
| 175 | - require_once $class_file; |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - if ( class_exists( $field_class ) && method_exists( $field_class, 'enqueue' ) ) { |
|
| 180 | - $enqueue = new $field_class( '', '', $this->parent ); |
|
| 181 | - $enqueue->enqueue(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - if ( class_exists( $field_class ) && method_exists( $field_class, 'localize' ) ) { |
|
| 185 | - |
|
| 186 | - $enqueue = new $field_class( '', '', $this->parent ); |
|
| 187 | - |
|
| 188 | - $data = $enqueue->localize( $field ); |
|
| 189 | - |
|
| 190 | - $this->parent->enqueue_class->localize_data[ $field['type'] ][ $field['id'] ] = $data; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Enqueue Function. |
|
| 196 | - * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 197 | - * |
|
| 198 | - * @since ReduxFramework 0.0.4 |
|
| 199 | - */ |
|
| 200 | - public function enqueue() { |
|
| 201 | - wp_print_styles( 'editor-buttons' ); |
|
| 202 | - |
|
| 203 | - wp_enqueue_script( |
|
| 204 | - 'redux-field-tabbed', |
|
| 205 | - Redux_Core::$url . 'inc/extensions/tabbed/tabbed/redux-tabbed' . Redux_Functions::is_min() . '.js', |
|
| 206 | - array( 'jquery', 'redux-js' ), |
|
| 207 | - Redux_Extension_Tabbed::$version, |
|
| 208 | - true |
|
| 209 | - ); |
|
| 210 | - |
|
| 211 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 212 | - wp_enqueue_style( |
|
| 213 | - 'redux-field-tabbed', |
|
| 214 | - Redux_Core::$url . 'inc/extensions/tabbed/tabbed/redux-tabbed.css', |
|
| 215 | - array(), |
|
| 216 | - Redux_Extension_Tabbed::$version |
|
| 217 | - ); |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - } |
|
| 96 | + if ( ! empty( $field['subtitle'] ) ) { |
|
| 97 | + echo '<div class="redux-field-subtitle">' . wp_kses_post( $field['subtitle'] ) . '</div>'; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + echo '</div>'; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + $orig_field_id = $field['id']; |
|
| 104 | + |
|
| 105 | + $field['name'] = $this->parent->args['opt_name'] . '[' . $orig_field_id . ']'; |
|
| 106 | + $field['class'] .= ' in-tabbed'; |
|
| 107 | + |
|
| 108 | + if ( isset( $field['options'] ) ) { |
|
| 109 | + |
|
| 110 | + // Sorter data filter. |
|
| 111 | + if ( 'sorter' === $field['type'] && ! empty( $field['data'] ) && is_array( $field['data'] ) ) { |
|
| 112 | + if ( ! isset( $field['args'] ) ) { |
|
| 113 | + $field['args'] = array(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + foreach ( $field['data'] as $key => $data ) { |
|
| 117 | + if ( ! isset( $field['args'][ $key ] ) ) { |
|
| 118 | + $field['args'][ $key ] = array(); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + $field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] ); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $default = $field['default'] ?? null; |
|
| 127 | + |
|
| 128 | + // phpcs:ignore Squiz.PHP.CommentedOutCode.Found |
|
| 129 | + // $value = isset( $this->parent->options[ $orig_field_id ] ) && 0 !== (int) $this->parent->options[ $orig_field_id ] ? $this->parent->options[ $orig_field_id ] : $default; |
|
| 130 | + $value = $this->parent->options[ $orig_field_id ] ?? $default; |
|
| 131 | + |
|
| 132 | + $this->parent->render_class->field_input( $field, $value ); |
|
| 133 | + |
|
| 134 | + echo '<div class="clear"></div>'; |
|
| 135 | + echo '</div>'; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * Localize. |
|
| 140 | + * |
|
| 141 | + * @param array $field Field. |
|
| 142 | + * @param string $value Value. |
|
| 143 | + * |
|
| 144 | + * @return void |
|
| 145 | + */ |
|
| 146 | + public function localize( array $field, string $value = '' ) { |
|
| 147 | + ob_start(); |
|
| 148 | + |
|
| 149 | + foreach ( $field['tabs'] as $f ) { |
|
| 150 | + foreach ( $f['fields'] as $field ) { |
|
| 151 | + $this->output_field( $field ); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + ob_end_clean(); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Enqueue Deps. |
|
| 160 | + * |
|
| 161 | + * @param array $field Field. |
|
| 162 | + */ |
|
| 163 | + private function enqueue_dependencies( array $field ) { |
|
| 164 | + $field_type = $field['type']; |
|
| 165 | + |
|
| 166 | + $field_class = 'Redux_' . $field_type; |
|
| 167 | + |
|
| 168 | + if ( ! class_exists( $field_class ) ) { |
|
| 169 | + $field_type = str_replace( '_', '-', $field_type ); |
|
| 170 | + |
|
| 171 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 172 | + $class_file = apply_filters( 'redux-typeclass-load', ReduxFramework::$_dir . 'inc/fields/' . $field_type . '/class-redux-' . $field_type . '.php', $field_class ); |
|
| 173 | + |
|
| 174 | + if ( file_exists( $class_file ) ) { |
|
| 175 | + require_once $class_file; |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + if ( class_exists( $field_class ) && method_exists( $field_class, 'enqueue' ) ) { |
|
| 180 | + $enqueue = new $field_class( '', '', $this->parent ); |
|
| 181 | + $enqueue->enqueue(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + if ( class_exists( $field_class ) && method_exists( $field_class, 'localize' ) ) { |
|
| 185 | + |
|
| 186 | + $enqueue = new $field_class( '', '', $this->parent ); |
|
| 187 | + |
|
| 188 | + $data = $enqueue->localize( $field ); |
|
| 189 | + |
|
| 190 | + $this->parent->enqueue_class->localize_data[ $field['type'] ][ $field['id'] ] = $data; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Enqueue Function. |
|
| 196 | + * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 197 | + * |
|
| 198 | + * @since ReduxFramework 0.0.4 |
|
| 199 | + */ |
|
| 200 | + public function enqueue() { |
|
| 201 | + wp_print_styles( 'editor-buttons' ); |
|
| 202 | + |
|
| 203 | + wp_enqueue_script( |
|
| 204 | + 'redux-field-tabbed', |
|
| 205 | + Redux_Core::$url . 'inc/extensions/tabbed/tabbed/redux-tabbed' . Redux_Functions::is_min() . '.js', |
|
| 206 | + array( 'jquery', 'redux-js' ), |
|
| 207 | + Redux_Extension_Tabbed::$version, |
|
| 208 | + true |
|
| 209 | + ); |
|
| 210 | + |
|
| 211 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 212 | + wp_enqueue_style( |
|
| 213 | + 'redux-field-tabbed', |
|
| 214 | + Redux_Core::$url . 'inc/extensions/tabbed/tabbed/redux-tabbed.css', |
|
| 215 | + array(), |
|
| 216 | + Redux_Extension_Tabbed::$version |
|
| 217 | + ); |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | 221 | } |
@@ -114,11 +114,11 @@ discard block |
||
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | foreach ( $field['data'] as $key => $data ) { |
| 117 | - if ( ! isset( $field['args'][ $key ] ) ) { |
|
| 118 | - $field['args'][ $key ] = array(); |
|
| 117 | + if ( ! isset( $field['args'][$key] ) ) { |
|
| 118 | + $field['args'][$key] = array(); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | - $field['options'][ $key ] = $this->parent->wordpress_data->get( $data, $field['args'][ $key ], $this->parent->args['opt_name'] ); |
|
| 121 | + $field['options'][$key] = $this->parent->wordpress_data->get( $data, $field['args'][$key], $this->parent->args['opt_name'] ); |
|
| 122 | 122 | } |
| 123 | 123 | } |
| 124 | 124 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | // phpcs:ignore Squiz.PHP.CommentedOutCode.Found |
| 129 | 129 | // $value = isset( $this->parent->options[ $orig_field_id ] ) && 0 !== (int) $this->parent->options[ $orig_field_id ] ? $this->parent->options[ $orig_field_id ] : $default; |
| 130 | - $value = $this->parent->options[ $orig_field_id ] ?? $default; |
|
| 130 | + $value = $this->parent->options[$orig_field_id] ?? $default; |
|
| 131 | 131 | |
| 132 | 132 | $this->parent->render_class->field_input( $field, $value ); |
| 133 | 133 | |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | |
| 188 | 188 | $data = $enqueue->localize( $field ); |
| 189 | 189 | |
| 190 | - $this->parent->enqueue_class->localize_data[ $field['type'] ][ $field['id'] ] = $data; |
|
| 190 | + $this->parent->enqueue_class->localize_data[$field['type']][$field['id']] = $data; |
|
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | 193 | |