@@ -11,46 +11,46 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_AJAX_Typography', false ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Class Redux_AJAX_Typography |
|
| 16 | - */ |
|
| 17 | - class Redux_AJAX_Typography extends Redux_Class { |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Redux_AJAX_Typography constructor. |
|
| 21 | - * |
|
| 22 | - * @param object $redux ReduxFramework object. |
|
| 23 | - */ |
|
| 24 | - public function __construct( $redux ) { |
|
| 25 | - parent::__construct( $redux ); |
|
| 26 | - add_action( 'wp_ajax_redux_update_google_fonts', array( $this, 'google_fonts_update' ) ); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Google font AJAX callback |
|
| 31 | - * |
|
| 32 | - * @return void |
|
| 33 | - */ |
|
| 34 | - public function google_fonts_update() { |
|
| 35 | - $field_class = 'Redux_typography'; |
|
| 36 | - |
|
| 37 | - if ( ! class_exists( $field_class ) ) { |
|
| 38 | - $dir = str_replace( '/classes', '', Redux_Functions_Ex::wp_normalize_path( __DIR__ ) ); |
|
| 39 | - |
|
| 40 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 41 | - $class_file = apply_filters( 'redux-typeclass-load', $dir . '/fields/typography/class-redux-typography.php', $field_class ); |
|
| 42 | - if ( $class_file ) { |
|
| 43 | - require_once $class_file; |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - if ( class_exists( $field_class ) && method_exists( $field_class, 'google_fonts_update_ajax' ) ) { |
|
| 48 | - $f = new $field_class( array(), '', $this->parent ); |
|
| 49 | - |
|
| 50 | - $f->google_fonts_update_ajax(); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - die(); |
|
| 54 | - } |
|
| 55 | - } |
|
| 14 | + /** |
|
| 15 | + * Class Redux_AJAX_Typography |
|
| 16 | + */ |
|
| 17 | + class Redux_AJAX_Typography extends Redux_Class { |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Redux_AJAX_Typography constructor. |
|
| 21 | + * |
|
| 22 | + * @param object $redux ReduxFramework object. |
|
| 23 | + */ |
|
| 24 | + public function __construct( $redux ) { |
|
| 25 | + parent::__construct( $redux ); |
|
| 26 | + add_action( 'wp_ajax_redux_update_google_fonts', array( $this, 'google_fonts_update' ) ); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Google font AJAX callback |
|
| 31 | + * |
|
| 32 | + * @return void |
|
| 33 | + */ |
|
| 34 | + public function google_fonts_update() { |
|
| 35 | + $field_class = 'Redux_typography'; |
|
| 36 | + |
|
| 37 | + if ( ! class_exists( $field_class ) ) { |
|
| 38 | + $dir = str_replace( '/classes', '', Redux_Functions_Ex::wp_normalize_path( __DIR__ ) ); |
|
| 39 | + |
|
| 40 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 41 | + $class_file = apply_filters( 'redux-typeclass-load', $dir . '/fields/typography/class-redux-typography.php', $field_class ); |
|
| 42 | + if ( $class_file ) { |
|
| 43 | + require_once $class_file; |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + if ( class_exists( $field_class ) && method_exists( $field_class, 'google_fonts_update_ajax' ) ) { |
|
| 48 | + $f = new $field_class( array(), '', $this->parent ); |
|
| 49 | + |
|
| 50 | + $f->google_fonts_update_ajax(); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + die(); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | 56 | } |
@@ -168,8 +168,8 @@ |
||
| 168 | 168 | // phpcs:ignore WordPress.NamingConventions.ValidHookName |
| 169 | 169 | add_filter( |
| 170 | 170 | 'redux/fields', |
| 171 | - function ( $classes ) use ( $field_name, $class ) { |
|
| 172 | - $classes[ $field_name ] = $class; |
|
| 171 | + function( $classes ) use ( $field_name, $class ) { |
|
| 172 | + $classes[$field_name] = $class; |
|
| 173 | 173 | |
| 174 | 174 | return $classes; |
| 175 | 175 | } |
@@ -17,229 +17,229 @@ |
||
| 17 | 17 | * @see the samples directory to find a usage example |
| 18 | 18 | */ |
| 19 | 19 | abstract class Redux_Extension_Abstract { |
| 20 | - /** |
|
| 21 | - * The version of the extension (This is a default value you may want to override it) |
|
| 22 | - * |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - public static $version = '1.0.0'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * The extension URL. |
|
| 29 | - * |
|
| 30 | - * @var string |
|
| 31 | - */ |
|
| 32 | - protected string $extension_url; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * The extension dir. |
|
| 36 | - * |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - protected string $extension_dir; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * The instance of the extension |
|
| 43 | - * |
|
| 44 | - * @var null|object |
|
| 45 | - */ |
|
| 46 | - protected static ?object $instance; |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * The extension's file |
|
| 50 | - * |
|
| 51 | - * @var string |
|
| 52 | - */ |
|
| 53 | - protected $file; |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * The redux framework instance that spawned the extension. |
|
| 57 | - * |
|
| 58 | - * @var ReduxFramework|null |
|
| 59 | - */ |
|
| 60 | - public ?ReduxFramework $parent; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * The ReflectionClass of the extension |
|
| 64 | - * |
|
| 65 | - * @var ReflectionClass |
|
| 66 | - */ |
|
| 67 | - protected ReflectionClass $reflection_class; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Redux_Extension_Abstract constructor. |
|
| 71 | - * |
|
| 72 | - * @param ReduxFramework $redux ReduxFramework pointer. |
|
| 73 | - * @param string $file Extension file. |
|
| 74 | - */ |
|
| 75 | - public function __construct( ReduxFramework $redux, string $file = '' ) { |
|
| 76 | - $this->parent = $redux; |
|
| 77 | - |
|
| 78 | - // If the file is not given, make sure we have one. |
|
| 79 | - if ( empty( $file ) ) { |
|
| 80 | - $file = $this->get_reflection()->getFileName(); |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - $this->file = $file; |
|
| 84 | - |
|
| 85 | - $this->extension_dir = trailingslashit( str_replace( '\\', '/', dirname( $file ) ) ); |
|
| 86 | - |
|
| 87 | - $plugin_info = Redux_Functions_Ex::is_inside_plugin( $this->file ); |
|
| 88 | - |
|
| 89 | - if ( false !== $plugin_info ) { |
|
| 90 | - $this->extension_url = trailingslashit( dirname( $plugin_info['url'] ) ); |
|
| 91 | - } else { |
|
| 92 | - $theme_info = Redux_Functions_Ex::is_inside_theme( $this->file ); |
|
| 93 | - if ( false !== $theme_info ) { |
|
| 94 | - $this->extension_url = trailingslashit( dirname( $theme_info['url'] ) ); |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - static::$instance = $this; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Get the reflection class of the extension. |
|
| 103 | - * |
|
| 104 | - * @return ReflectionClass |
|
| 105 | - */ |
|
| 106 | - protected function get_reflection(): ReflectionClass { |
|
| 107 | - if ( ! isset( $this->reflection_class ) ) { |
|
| 108 | - $this->reflection_class = new ReflectionClass( $this ); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $this->reflection_class; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * Return extension version. |
|
| 116 | - * |
|
| 117 | - * @return string |
|
| 118 | - */ |
|
| 119 | - public static function get_version(): string { |
|
| 120 | - return static::$version; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Returns extension instance. |
|
| 125 | - * |
|
| 126 | - * @return object |
|
| 127 | - */ |
|
| 128 | - public static function get_instance(): object { |
|
| 129 | - return static::$instance; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Return extension dir. |
|
| 134 | - * |
|
| 135 | - * @return string |
|
| 136 | - */ |
|
| 137 | - public function get_dir(): string { |
|
| 138 | - return $this->extension_dir; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Returns extension URL |
|
| 143 | - * |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - public function get_url(): string { |
|
| 147 | - return $this->extension_url; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Adds the local field. (The use of add_field is recommended). |
|
| 152 | - * |
|
| 153 | - * @param string $field_name Name of field. |
|
| 154 | - */ |
|
| 155 | - protected function add_overload_field_filter( string $field_name ) { |
|
| 156 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 157 | - add_filter( 'redux/' . $this->parent->args['opt_name'] . '/field/class/' . $field_name, array( &$this, 'overload_field_path' ), 10, 2 ); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Adds the local field to the extension and register it in the builder. |
|
| 162 | - * |
|
| 163 | - * @param string $field_name Name of field. |
|
| 164 | - */ |
|
| 165 | - protected function add_field( string $field_name ) { |
|
| 166 | - $class = $this->get_reflection()->getName(); |
|
| 167 | - |
|
| 168 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 169 | - add_filter( |
|
| 170 | - 'redux/fields', |
|
| 171 | - function ( $classes ) use ( $field_name, $class ) { |
|
| 172 | - $classes[ $field_name ] = $class; |
|
| 173 | - |
|
| 174 | - return $classes; |
|
| 175 | - } |
|
| 176 | - ); |
|
| 177 | - |
|
| 178 | - $this->add_overload_field_filter( $field_name ); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Overload a field path. |
|
| 183 | - * |
|
| 184 | - * @param string $file Extension file. |
|
| 185 | - * @param array $field Field array. |
|
| 186 | - * |
|
| 187 | - * @return string |
|
| 188 | - */ |
|
| 189 | - public function overload_field_path( string $file, array $field ): string { |
|
| 190 | - $filename_fix = str_replace( '_', '-', $field['type'] ); |
|
| 191 | - |
|
| 192 | - $files = array( |
|
| 193 | - trailingslashit( dirname( $this->file ) ) . $field['type'] . DIRECTORY_SEPARATOR . 'field_' . $field['type'] . '.php', |
|
| 194 | - trailingslashit( dirname( $this->file ) ) . $field['type'] . DIRECTORY_SEPARATOR . 'class-redux-' . $filename_fix . '.php', |
|
| 195 | - ); |
|
| 196 | - |
|
| 197 | - return Redux_Functions::file_exists_ex( $files ); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Sets the minimum version of Redux to use. Displays a notice if requirements are not met. |
|
| 202 | - * |
|
| 203 | - * @param string $min_version Minimum version to evaluate. |
|
| 204 | - * @param string $extension_version Extension version number. |
|
| 205 | - * @param string $friendly_name Friend extension name for notice display. |
|
| 206 | - * |
|
| 207 | - * @return bool |
|
| 208 | - */ |
|
| 209 | - public function is_minimum_version( string $min_version = '', string $extension_version = '', string $friendly_name = '' ): bool { |
|
| 210 | - $redux_ver = Redux_Core::$version; |
|
| 211 | - |
|
| 212 | - if ( '' !== $min_version ) { |
|
| 213 | - if ( version_compare( $redux_ver, $min_version ) < 0 ) { |
|
| 214 | - // translators: %1$s Extension friendly name. %2$s: minimum Redux version. |
|
| 215 | - $msg = '<strong>' . sprintf( esc_html__( 'The %1$s extension requires Redux Framework version %2$s or higher.', 'redux-framework' ), $friendly_name, $min_version ) . '</strong> ' . esc_html__( 'You are currently running Redux Framework version ', 'redux-framework' ) . ' ' . $redux_ver . '.<br/><br/>' . esc_html__( 'This field will not render in your option panel, and features of this extension will not be available until the latest version of Redux Framework has been installed.', 'redux-framework' ); |
|
| 216 | - |
|
| 217 | - $data = array( |
|
| 218 | - 'parent' => $this->parent, |
|
| 219 | - 'type' => 'error', |
|
| 220 | - 'msg' => $msg, |
|
| 221 | - 'id' => $this->extension_name . '_notice_' . $extension_version, |
|
| 222 | - 'dismiss' => false, |
|
| 223 | - ); |
|
| 224 | - |
|
| 225 | - if ( method_exists( 'Redux_Admin_Notices', 'set_notice' ) ) { |
|
| 226 | - Redux_Admin_Notices::set_notice( $data ); |
|
| 227 | - } else { |
|
| 228 | - echo '<div class="error">'; |
|
| 229 | - echo '<p>'; |
|
| 230 | - echo $msg; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 231 | - echo '</p>'; |
|
| 232 | - echo '</div>'; |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return false; |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return true; |
|
| 240 | - } |
|
| 20 | + /** |
|
| 21 | + * The version of the extension (This is a default value you may want to override it) |
|
| 22 | + * |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + public static $version = '1.0.0'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * The extension URL. |
|
| 29 | + * |
|
| 30 | + * @var string |
|
| 31 | + */ |
|
| 32 | + protected string $extension_url; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * The extension dir. |
|
| 36 | + * |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + protected string $extension_dir; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * The instance of the extension |
|
| 43 | + * |
|
| 44 | + * @var null|object |
|
| 45 | + */ |
|
| 46 | + protected static ?object $instance; |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * The extension's file |
|
| 50 | + * |
|
| 51 | + * @var string |
|
| 52 | + */ |
|
| 53 | + protected $file; |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * The redux framework instance that spawned the extension. |
|
| 57 | + * |
|
| 58 | + * @var ReduxFramework|null |
|
| 59 | + */ |
|
| 60 | + public ?ReduxFramework $parent; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * The ReflectionClass of the extension |
|
| 64 | + * |
|
| 65 | + * @var ReflectionClass |
|
| 66 | + */ |
|
| 67 | + protected ReflectionClass $reflection_class; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Redux_Extension_Abstract constructor. |
|
| 71 | + * |
|
| 72 | + * @param ReduxFramework $redux ReduxFramework pointer. |
|
| 73 | + * @param string $file Extension file. |
|
| 74 | + */ |
|
| 75 | + public function __construct( ReduxFramework $redux, string $file = '' ) { |
|
| 76 | + $this->parent = $redux; |
|
| 77 | + |
|
| 78 | + // If the file is not given, make sure we have one. |
|
| 79 | + if ( empty( $file ) ) { |
|
| 80 | + $file = $this->get_reflection()->getFileName(); |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + $this->file = $file; |
|
| 84 | + |
|
| 85 | + $this->extension_dir = trailingslashit( str_replace( '\\', '/', dirname( $file ) ) ); |
|
| 86 | + |
|
| 87 | + $plugin_info = Redux_Functions_Ex::is_inside_plugin( $this->file ); |
|
| 88 | + |
|
| 89 | + if ( false !== $plugin_info ) { |
|
| 90 | + $this->extension_url = trailingslashit( dirname( $plugin_info['url'] ) ); |
|
| 91 | + } else { |
|
| 92 | + $theme_info = Redux_Functions_Ex::is_inside_theme( $this->file ); |
|
| 93 | + if ( false !== $theme_info ) { |
|
| 94 | + $this->extension_url = trailingslashit( dirname( $theme_info['url'] ) ); |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + static::$instance = $this; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Get the reflection class of the extension. |
|
| 103 | + * |
|
| 104 | + * @return ReflectionClass |
|
| 105 | + */ |
|
| 106 | + protected function get_reflection(): ReflectionClass { |
|
| 107 | + if ( ! isset( $this->reflection_class ) ) { |
|
| 108 | + $this->reflection_class = new ReflectionClass( $this ); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $this->reflection_class; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * Return extension version. |
|
| 116 | + * |
|
| 117 | + * @return string |
|
| 118 | + */ |
|
| 119 | + public static function get_version(): string { |
|
| 120 | + return static::$version; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Returns extension instance. |
|
| 125 | + * |
|
| 126 | + * @return object |
|
| 127 | + */ |
|
| 128 | + public static function get_instance(): object { |
|
| 129 | + return static::$instance; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Return extension dir. |
|
| 134 | + * |
|
| 135 | + * @return string |
|
| 136 | + */ |
|
| 137 | + public function get_dir(): string { |
|
| 138 | + return $this->extension_dir; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Returns extension URL |
|
| 143 | + * |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + public function get_url(): string { |
|
| 147 | + return $this->extension_url; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Adds the local field. (The use of add_field is recommended). |
|
| 152 | + * |
|
| 153 | + * @param string $field_name Name of field. |
|
| 154 | + */ |
|
| 155 | + protected function add_overload_field_filter( string $field_name ) { |
|
| 156 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 157 | + add_filter( 'redux/' . $this->parent->args['opt_name'] . '/field/class/' . $field_name, array( &$this, 'overload_field_path' ), 10, 2 ); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Adds the local field to the extension and register it in the builder. |
|
| 162 | + * |
|
| 163 | + * @param string $field_name Name of field. |
|
| 164 | + */ |
|
| 165 | + protected function add_field( string $field_name ) { |
|
| 166 | + $class = $this->get_reflection()->getName(); |
|
| 167 | + |
|
| 168 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 169 | + add_filter( |
|
| 170 | + 'redux/fields', |
|
| 171 | + function ( $classes ) use ( $field_name, $class ) { |
|
| 172 | + $classes[ $field_name ] = $class; |
|
| 173 | + |
|
| 174 | + return $classes; |
|
| 175 | + } |
|
| 176 | + ); |
|
| 177 | + |
|
| 178 | + $this->add_overload_field_filter( $field_name ); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Overload a field path. |
|
| 183 | + * |
|
| 184 | + * @param string $file Extension file. |
|
| 185 | + * @param array $field Field array. |
|
| 186 | + * |
|
| 187 | + * @return string |
|
| 188 | + */ |
|
| 189 | + public function overload_field_path( string $file, array $field ): string { |
|
| 190 | + $filename_fix = str_replace( '_', '-', $field['type'] ); |
|
| 191 | + |
|
| 192 | + $files = array( |
|
| 193 | + trailingslashit( dirname( $this->file ) ) . $field['type'] . DIRECTORY_SEPARATOR . 'field_' . $field['type'] . '.php', |
|
| 194 | + trailingslashit( dirname( $this->file ) ) . $field['type'] . DIRECTORY_SEPARATOR . 'class-redux-' . $filename_fix . '.php', |
|
| 195 | + ); |
|
| 196 | + |
|
| 197 | + return Redux_Functions::file_exists_ex( $files ); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Sets the minimum version of Redux to use. Displays a notice if requirements are not met. |
|
| 202 | + * |
|
| 203 | + * @param string $min_version Minimum version to evaluate. |
|
| 204 | + * @param string $extension_version Extension version number. |
|
| 205 | + * @param string $friendly_name Friend extension name for notice display. |
|
| 206 | + * |
|
| 207 | + * @return bool |
|
| 208 | + */ |
|
| 209 | + public function is_minimum_version( string $min_version = '', string $extension_version = '', string $friendly_name = '' ): bool { |
|
| 210 | + $redux_ver = Redux_Core::$version; |
|
| 211 | + |
|
| 212 | + if ( '' !== $min_version ) { |
|
| 213 | + if ( version_compare( $redux_ver, $min_version ) < 0 ) { |
|
| 214 | + // translators: %1$s Extension friendly name. %2$s: minimum Redux version. |
|
| 215 | + $msg = '<strong>' . sprintf( esc_html__( 'The %1$s extension requires Redux Framework version %2$s or higher.', 'redux-framework' ), $friendly_name, $min_version ) . '</strong> ' . esc_html__( 'You are currently running Redux Framework version ', 'redux-framework' ) . ' ' . $redux_ver . '.<br/><br/>' . esc_html__( 'This field will not render in your option panel, and features of this extension will not be available until the latest version of Redux Framework has been installed.', 'redux-framework' ); |
|
| 216 | + |
|
| 217 | + $data = array( |
|
| 218 | + 'parent' => $this->parent, |
|
| 219 | + 'type' => 'error', |
|
| 220 | + 'msg' => $msg, |
|
| 221 | + 'id' => $this->extension_name . '_notice_' . $extension_version, |
|
| 222 | + 'dismiss' => false, |
|
| 223 | + ); |
|
| 224 | + |
|
| 225 | + if ( method_exists( 'Redux_Admin_Notices', 'set_notice' ) ) { |
|
| 226 | + Redux_Admin_Notices::set_notice( $data ); |
|
| 227 | + } else { |
|
| 228 | + echo '<div class="error">'; |
|
| 229 | + echo '<p>'; |
|
| 230 | + echo $msg; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 231 | + echo '</p>'; |
|
| 232 | + echo '</div>'; |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return false; |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return true; |
|
| 240 | + } |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | if ( ! class_exists( 'Redux_Abstract_Extension' ) ) { |
| 244 | - class_alias( 'Redux_Extension_Abstract', 'Redux_Abstract_Extension' ); |
|
| 244 | + class_alias( 'Redux_Extension_Abstract', 'Redux_Abstract_Extension' ); |
|
| 245 | 245 | } |
@@ -11,220 +11,220 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Field', false ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Class Redux_Field |
|
| 16 | - */ |
|
| 17 | - abstract class Redux_Field { |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * CSS styling per field output/compiler. |
|
| 21 | - * |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - public $style = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Class dir. |
|
| 28 | - * |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - public $dir = null; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Class URL. |
|
| 35 | - * |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 38 | - public $url = null; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Timestamp for ver append in dev_mode |
|
| 42 | - * |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 45 | - public $timestamp = null; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * ReduxFramework object pointer. |
|
| 49 | - * |
|
| 50 | - * @var ReduxFramework |
|
| 51 | - */ |
|
| 52 | - public $parent; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Field values. |
|
| 56 | - * |
|
| 57 | - * @var string|array |
|
| 58 | - */ |
|
| 59 | - public $field; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Value values. |
|
| 63 | - * |
|
| 64 | - * @var string|array |
|
| 65 | - */ |
|
| 66 | - public $value; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Select2 options. |
|
| 70 | - * |
|
| 71 | - * @var array |
|
| 72 | - */ |
|
| 73 | - public $select2_config = array(); |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Redux_Field constructor. |
|
| 77 | - * |
|
| 78 | - * @param array|string|null $field Field array. |
|
| 79 | - * @param string|array|null $value Field values. |
|
| 80 | - * @param null $redux ReduxFramework object pointer. |
|
| 81 | - * |
|
| 82 | - * @throws ReflectionException Comment. |
|
| 83 | - */ |
|
| 84 | - public function __construct( $field = array(), $value = null, $redux = null ) { |
|
| 85 | - $this->parent = $redux; |
|
| 86 | - $this->field = $field; |
|
| 87 | - $this->value = $value; |
|
| 88 | - |
|
| 89 | - $this->select2_config = array( |
|
| 90 | - 'width' => 'resolve', |
|
| 91 | - 'allowClear' => false, |
|
| 92 | - 'theme' => 'default', |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - $this->set_defaults(); |
|
| 96 | - |
|
| 97 | - $class_name = get_class( $this ); |
|
| 98 | - $reflector = new ReflectionClass( $class_name ); |
|
| 99 | - $path = $reflector->getFilename(); |
|
| 100 | - $path_info = Redux_Helpers::path_info( $path ); |
|
| 101 | - $this->dir = trailingslashit( dirname( $path_info['real_path'] ) ); |
|
| 102 | - $this->url = trailingslashit( dirname( $path_info['url'] ) ); |
|
| 103 | - |
|
| 104 | - $this->timestamp = Redux_Core::$version; |
|
| 105 | - if ( $redux->args['dev_mode'] ) { |
|
| 106 | - $this->timestamp .= '.' . time(); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Media query compiler for Redux Pro, |
|
| 112 | - * |
|
| 113 | - * @param string $style_data CSS string. |
|
| 114 | - */ |
|
| 115 | - public function media_query( string $style_data = '' ) { |
|
| 116 | - $query_arr = $this->field['media_query']; |
|
| 117 | - $css = ''; |
|
| 118 | - |
|
| 119 | - if ( isset( $query_arr['queries'] ) ) { |
|
| 120 | - foreach ( $query_arr['queries'] as $query ) { |
|
| 121 | - $rule = $query['rule'] ?? ''; |
|
| 122 | - $selectors = $query['selectors'] ?? array(); |
|
| 123 | - |
|
| 124 | - if ( ! is_array( $selectors ) && '' !== $selectors ) { |
|
| 125 | - $selectors = array( $selectors ); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - if ( '' !== $rule && ! empty( $selectors ) ) { |
|
| 129 | - $selectors = implode( ',', $selectors ); |
|
| 130 | - |
|
| 131 | - $css .= '@media ' . $rule . '{'; |
|
| 132 | - $css .= $selectors . '{' . $style_data . '}'; |
|
| 133 | - $css .= '}'; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } else { |
|
| 137 | - return; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - if ( isset( $query_arr['output'] ) && $query_arr['output'] ) { |
|
| 141 | - $this->parent->outputCSS .= $css; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - if ( isset( $query_arr['compiler'] ) && $query_arr['compiler'] ) { |
|
| 145 | - $this->parent->compilerCSS .= $css; |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * CSS for field output, if set (Remove the noinpection line and fix this function when we drop support for PHP 7.1). |
|
| 151 | - * |
|
| 152 | - * @param string $style CSS string. |
|
| 153 | - * |
|
| 154 | - * @noinspection PhpMissingParamTypeInspection |
|
| 155 | - */ |
|
| 156 | - public function output( $style = '' ) { |
|
| 157 | - if ( '' !== $style ) { |
|
| 158 | - |
|
| 159 | - // Force output value into an array. |
|
| 160 | - if ( isset( $this->field['output'] ) && ! is_array( $this->field['output'] ) ) { |
|
| 161 | - $this->field['output'] = array( $this->field['output'] ); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) { |
|
| 165 | - if ( isset( $this->field['output']['important'] ) ) { |
|
| 166 | - if ( $this->field['output']['important'] ) { |
|
| 167 | - $style = str_replace( ';', ' !important;', $style ); |
|
| 168 | - } |
|
| 169 | - unset( $this->field['output']['important'] ); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - $keys = implode( ',', $this->field['output'] ); |
|
| 173 | - $this->parent->outputCSS .= $keys . '{' . $style . '}'; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // Force compiler value into an array. |
|
| 177 | - if ( isset( $this->field['compiler'] ) && ! is_array( $this->field['compiler'] ) ) { |
|
| 178 | - $this->field['compiler'] = array( $this->field['compiler'] ); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - if ( isset( $this->field['compiler']['important'] ) ) { |
|
| 182 | - if ( $this->field['compiler']['important'] ) { |
|
| 183 | - $style = str_replace( ';', ' !important;', $style ); |
|
| 184 | - } |
|
| 185 | - unset( $this->field['compiler']['important'] ); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) { |
|
| 189 | - $keys = implode( ',', $this->field['compiler'] ); |
|
| 190 | - $this->parent->compilerCSS .= $keys . '{' . $style . '}'; |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Unused for now. |
|
| 197 | - * |
|
| 198 | - * @param mixed $data CSS data. |
|
| 199 | - */ |
|
| 200 | - public function css_style( $data ) {} |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * Unused for now. |
|
| 204 | - */ |
|
| 205 | - public function set_defaults() {} |
|
| 206 | - |
|
| 207 | - /** |
|
| 208 | - * Unused for now. |
|
| 209 | - */ |
|
| 210 | - public function render() {} |
|
| 211 | - |
|
| 212 | - /** |
|
| 213 | - * Unused for now. |
|
| 214 | - */ |
|
| 215 | - public function enqueue() {} |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Unused for now. |
|
| 219 | - */ |
|
| 220 | - public function always_enqueue() {} |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Unused for now. |
|
| 224 | - * |
|
| 225 | - * @param array $field Field array. |
|
| 226 | - * @param string $value Value array. |
|
| 227 | - */ |
|
| 228 | - public function localize( array $field, string $value = '' ) {} |
|
| 229 | - } |
|
| 14 | + /** |
|
| 15 | + * Class Redux_Field |
|
| 16 | + */ |
|
| 17 | + abstract class Redux_Field { |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * CSS styling per field output/compiler. |
|
| 21 | + * |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + public $style = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Class dir. |
|
| 28 | + * |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + public $dir = null; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Class URL. |
|
| 35 | + * |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | + public $url = null; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Timestamp for ver append in dev_mode |
|
| 42 | + * |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | + public $timestamp = null; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * ReduxFramework object pointer. |
|
| 49 | + * |
|
| 50 | + * @var ReduxFramework |
|
| 51 | + */ |
|
| 52 | + public $parent; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Field values. |
|
| 56 | + * |
|
| 57 | + * @var string|array |
|
| 58 | + */ |
|
| 59 | + public $field; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Value values. |
|
| 63 | + * |
|
| 64 | + * @var string|array |
|
| 65 | + */ |
|
| 66 | + public $value; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Select2 options. |
|
| 70 | + * |
|
| 71 | + * @var array |
|
| 72 | + */ |
|
| 73 | + public $select2_config = array(); |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Redux_Field constructor. |
|
| 77 | + * |
|
| 78 | + * @param array|string|null $field Field array. |
|
| 79 | + * @param string|array|null $value Field values. |
|
| 80 | + * @param null $redux ReduxFramework object pointer. |
|
| 81 | + * |
|
| 82 | + * @throws ReflectionException Comment. |
|
| 83 | + */ |
|
| 84 | + public function __construct( $field = array(), $value = null, $redux = null ) { |
|
| 85 | + $this->parent = $redux; |
|
| 86 | + $this->field = $field; |
|
| 87 | + $this->value = $value; |
|
| 88 | + |
|
| 89 | + $this->select2_config = array( |
|
| 90 | + 'width' => 'resolve', |
|
| 91 | + 'allowClear' => false, |
|
| 92 | + 'theme' => 'default', |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + $this->set_defaults(); |
|
| 96 | + |
|
| 97 | + $class_name = get_class( $this ); |
|
| 98 | + $reflector = new ReflectionClass( $class_name ); |
|
| 99 | + $path = $reflector->getFilename(); |
|
| 100 | + $path_info = Redux_Helpers::path_info( $path ); |
|
| 101 | + $this->dir = trailingslashit( dirname( $path_info['real_path'] ) ); |
|
| 102 | + $this->url = trailingslashit( dirname( $path_info['url'] ) ); |
|
| 103 | + |
|
| 104 | + $this->timestamp = Redux_Core::$version; |
|
| 105 | + if ( $redux->args['dev_mode'] ) { |
|
| 106 | + $this->timestamp .= '.' . time(); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Media query compiler for Redux Pro, |
|
| 112 | + * |
|
| 113 | + * @param string $style_data CSS string. |
|
| 114 | + */ |
|
| 115 | + public function media_query( string $style_data = '' ) { |
|
| 116 | + $query_arr = $this->field['media_query']; |
|
| 117 | + $css = ''; |
|
| 118 | + |
|
| 119 | + if ( isset( $query_arr['queries'] ) ) { |
|
| 120 | + foreach ( $query_arr['queries'] as $query ) { |
|
| 121 | + $rule = $query['rule'] ?? ''; |
|
| 122 | + $selectors = $query['selectors'] ?? array(); |
|
| 123 | + |
|
| 124 | + if ( ! is_array( $selectors ) && '' !== $selectors ) { |
|
| 125 | + $selectors = array( $selectors ); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + if ( '' !== $rule && ! empty( $selectors ) ) { |
|
| 129 | + $selectors = implode( ',', $selectors ); |
|
| 130 | + |
|
| 131 | + $css .= '@media ' . $rule . '{'; |
|
| 132 | + $css .= $selectors . '{' . $style_data . '}'; |
|
| 133 | + $css .= '}'; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } else { |
|
| 137 | + return; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + if ( isset( $query_arr['output'] ) && $query_arr['output'] ) { |
|
| 141 | + $this->parent->outputCSS .= $css; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + if ( isset( $query_arr['compiler'] ) && $query_arr['compiler'] ) { |
|
| 145 | + $this->parent->compilerCSS .= $css; |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * CSS for field output, if set (Remove the noinpection line and fix this function when we drop support for PHP 7.1). |
|
| 151 | + * |
|
| 152 | + * @param string $style CSS string. |
|
| 153 | + * |
|
| 154 | + * @noinspection PhpMissingParamTypeInspection |
|
| 155 | + */ |
|
| 156 | + public function output( $style = '' ) { |
|
| 157 | + if ( '' !== $style ) { |
|
| 158 | + |
|
| 159 | + // Force output value into an array. |
|
| 160 | + if ( isset( $this->field['output'] ) && ! is_array( $this->field['output'] ) ) { |
|
| 161 | + $this->field['output'] = array( $this->field['output'] ); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) { |
|
| 165 | + if ( isset( $this->field['output']['important'] ) ) { |
|
| 166 | + if ( $this->field['output']['important'] ) { |
|
| 167 | + $style = str_replace( ';', ' !important;', $style ); |
|
| 168 | + } |
|
| 169 | + unset( $this->field['output']['important'] ); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + $keys = implode( ',', $this->field['output'] ); |
|
| 173 | + $this->parent->outputCSS .= $keys . '{' . $style . '}'; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // Force compiler value into an array. |
|
| 177 | + if ( isset( $this->field['compiler'] ) && ! is_array( $this->field['compiler'] ) ) { |
|
| 178 | + $this->field['compiler'] = array( $this->field['compiler'] ); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + if ( isset( $this->field['compiler']['important'] ) ) { |
|
| 182 | + if ( $this->field['compiler']['important'] ) { |
|
| 183 | + $style = str_replace( ';', ' !important;', $style ); |
|
| 184 | + } |
|
| 185 | + unset( $this->field['compiler']['important'] ); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) { |
|
| 189 | + $keys = implode( ',', $this->field['compiler'] ); |
|
| 190 | + $this->parent->compilerCSS .= $keys . '{' . $style . '}'; |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Unused for now. |
|
| 197 | + * |
|
| 198 | + * @param mixed $data CSS data. |
|
| 199 | + */ |
|
| 200 | + public function css_style( $data ) {} |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * Unused for now. |
|
| 204 | + */ |
|
| 205 | + public function set_defaults() {} |
|
| 206 | + |
|
| 207 | + /** |
|
| 208 | + * Unused for now. |
|
| 209 | + */ |
|
| 210 | + public function render() {} |
|
| 211 | + |
|
| 212 | + /** |
|
| 213 | + * Unused for now. |
|
| 214 | + */ |
|
| 215 | + public function enqueue() {} |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Unused for now. |
|
| 219 | + */ |
|
| 220 | + public function always_enqueue() {} |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Unused for now. |
|
| 224 | + * |
|
| 225 | + * @param array $field Field array. |
|
| 226 | + * @param string $value Value array. |
|
| 227 | + */ |
|
| 228 | + public function localize( array $field, string $value = '' ) {} |
|
| 229 | + } |
|
| 230 | 230 | } |
@@ -243,9 +243,9 @@ discard block |
||
| 243 | 243 | 'localhost.localdomain', |
| 244 | 244 | '127.0.0.1', |
| 245 | 245 | '::1', |
| 246 | - 'local.wordpress.test', // VVV pattern. |
|
| 247 | - 'local.wordpress-trunk.test', // VVV pattern. |
|
| 248 | - 'src.wordpress-develop.test', // VVV pattern. |
|
| 246 | + 'local.wordpress.test', // VVV pattern. |
|
| 247 | + 'local.wordpress-trunk.test', // VVV pattern. |
|
| 248 | + 'src.wordpress-develop.test', // VVV pattern. |
|
| 249 | 249 | 'build.wordpress-develop.test', // VVV pattern. |
| 250 | 250 | ); |
| 251 | 251 | |
@@ -512,29 +512,29 @@ discard block |
||
| 512 | 512 | $theme_info = self::is_inside_theme( $caller ); |
| 513 | 513 | |
| 514 | 514 | if ( $theme_info ) { |
| 515 | - if ( ! isset( $data['theme'][ $theme_info['slug'] ] ) ) { |
|
| 516 | - $data['theme'][ $theme_info['slug'] ] = array(); |
|
| 515 | + if ( ! isset( $data['theme'][$theme_info['slug']] ) ) { |
|
| 516 | + $data['theme'][$theme_info['slug']] = array(); |
|
| 517 | 517 | } |
| 518 | - if ( ! isset( $data['theme'][ $theme_info['slug'] ][ $opt_name ] ) ) { |
|
| 519 | - $data['theme'][ $theme_info['slug'] ][ $opt_name ] = array(); |
|
| 518 | + if ( ! isset( $data['theme'][$theme_info['slug']][$opt_name] ) ) { |
|
| 519 | + $data['theme'][$theme_info['slug']][$opt_name] = array(); |
|
| 520 | 520 | } |
| 521 | 521 | if ( $simple ) { |
| 522 | - $data['theme'][ $theme_info['slug'] ][ $opt_name ][] = $theme_info['basename']; |
|
| 522 | + $data['theme'][$theme_info['slug']][$opt_name][] = $theme_info['basename']; |
|
| 523 | 523 | } else { |
| 524 | - $data['theme'][ $theme_info['slug'] ][ $opt_name ][] = $theme_info; |
|
| 524 | + $data['theme'][$theme_info['slug']][$opt_name][] = $theme_info; |
|
| 525 | 525 | } |
| 526 | 526 | } elseif ( $plugin_info ) { |
| 527 | - if ( ! isset( $data['plugin'][ $plugin_info['slug'] ] ) ) { |
|
| 528 | - $data['plugin'][ $plugin_info['slug'] ] = array(); |
|
| 527 | + if ( ! isset( $data['plugin'][$plugin_info['slug']] ) ) { |
|
| 528 | + $data['plugin'][$plugin_info['slug']] = array(); |
|
| 529 | 529 | } |
| 530 | - if ( ! in_array( $opt_name, $data['plugin'][ $plugin_info['slug'] ], true ) ) { |
|
| 531 | - if ( ! isset( $data['plugin'][ $plugin_info['slug'] ][ $opt_name ] ) ) { |
|
| 532 | - $data['plugin'][ $plugin_info['slug'] ][ $opt_name ] = array(); |
|
| 530 | + if ( ! in_array( $opt_name, $data['plugin'][$plugin_info['slug']], true ) ) { |
|
| 531 | + if ( ! isset( $data['plugin'][$plugin_info['slug']][$opt_name] ) ) { |
|
| 532 | + $data['plugin'][$plugin_info['slug']][$opt_name] = array(); |
|
| 533 | 533 | } |
| 534 | 534 | if ( $simple ) { |
| 535 | - $data['plugin'][ $plugin_info['slug'] ][ $opt_name ][] = $plugin_info['basename']; |
|
| 535 | + $data['plugin'][$plugin_info['slug']][$opt_name][] = $plugin_info['basename']; |
|
| 536 | 536 | } else { |
| 537 | - $data['plugin'][ $plugin_info['slug'] ][ $opt_name ][] = $plugin_info; |
|
| 537 | + $data['plugin'][$plugin_info['slug']][$opt_name][] = $plugin_info; |
|
| 538 | 538 | } |
| 539 | 539 | } |
| 540 | 540 | } |
@@ -682,12 +682,12 @@ discard block |
||
| 682 | 682 | return join( |
| 683 | 683 | ' ', |
| 684 | 684 | array_map( |
| 685 | - function ( $key ) use ( $attributes ) { |
|
| 686 | - if ( is_bool( $attributes[ $key ] ) ) { |
|
| 687 | - return $attributes[ $key ] ? $key : ''; |
|
| 685 | + function( $key ) use ( $attributes ) { |
|
| 686 | + if ( is_bool( $attributes[$key] ) ) { |
|
| 687 | + return $attributes[$key] ? $key : ''; |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | - return $key . '="' . $attributes[ $key ] . '"'; |
|
| 690 | + return $key . '="' . $attributes[$key] . '"'; |
|
| 691 | 691 | }, |
| 692 | 692 | array_keys( $attributes ) |
| 693 | 693 | ) |
@@ -860,7 +860,7 @@ discard block |
||
| 860 | 860 | $args[] = $object_id; |
| 861 | 861 | } |
| 862 | 862 | |
| 863 | - $expression_result = call_user_func_array( 'user_can', $args ) === (bool) $value; |
|
| 863 | + $expression_result = call_user_func_array( 'user_can', $args ) === ( bool ) $value; |
|
| 864 | 864 | } elseif ( is_array( $value ) ) { |
| 865 | 865 | ++$depth; |
| 866 | 866 | |
@@ -1121,7 +1121,7 @@ discard block |
||
| 1121 | 1121 | $new_arr = array(); |
| 1122 | 1122 | |
| 1123 | 1123 | foreach ( $arr as $key => $value ) { |
| 1124 | - $new_arr[ $key ] = ( is_array( $value ) ? self::array_map_r( $func, $value ) : ( is_array( $func ) ? call_user_func_array( $func, $value ) : $func( $value ) ) ); |
|
| 1124 | + $new_arr[$key] = ( is_array( $value ) ? self::array_map_r( $func, $value ) : ( is_array( $func ) ? call_user_func_array( $func, $value ) : $func( $value ) ) ); |
|
| 1125 | 1125 | } |
| 1126 | 1126 | |
| 1127 | 1127 | return $new_arr; |
@@ -1196,8 +1196,8 @@ discard block |
||
| 1196 | 1196 | |
| 1197 | 1197 | $position_colors = array(); |
| 1198 | 1198 | foreach ( $colors as $color_family ) { |
| 1199 | - if ( isset( $color_family[ $key ] ) ) { |
|
| 1200 | - $position_colors[] = $color_family[ $key ]; |
|
| 1199 | + if ( isset( $color_family[$key] ) ) { |
|
| 1200 | + $position_colors[] = $color_family[$key]; |
|
| 1201 | 1201 | } |
| 1202 | 1202 | } |
| 1203 | 1203 | |
@@ -1216,8 +1216,8 @@ discard block |
||
| 1216 | 1216 | } elseif ( 'primary' === $context ) { |
| 1217 | 1217 | return $colors['primary']; |
| 1218 | 1218 | } else { |
| 1219 | - if ( isset( $colors[ $context ] ) ) { |
|
| 1220 | - return $colors[ $context ]; |
|
| 1219 | + if ( isset( $colors[$context] ) ) { |
|
| 1220 | + return $colors[$context]; |
|
| 1221 | 1221 | } |
| 1222 | 1222 | |
| 1223 | 1223 | return $colors['primary']; |
@@ -15,1215 +15,1215 @@ |
||
| 15 | 15 | // Don't duplicate me! |
| 16 | 16 | if ( ! class_exists( 'Redux_Helpers', false ) ) { |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Redux Helpers Class |
|
| 20 | - * A Class of useful functions that can/should be shared among all Redux files. |
|
| 21 | - * |
|
| 22 | - * @since 3.0.0 |
|
| 23 | - */ |
|
| 24 | - class Redux_Helpers { |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Reusable supported unit array. |
|
| 28 | - * |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - public static $array_units = array( '', '%', 'in', 'cm', 'mm', 'em', 'rem', 'ex', 'pt', 'pc', 'px', 'vh', 'vw', 'vmin', 'vmax', 'ch' ); |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Is customizer loaded. |
|
| 35 | - * |
|
| 36 | - * @return bool |
|
| 37 | - */ |
|
| 38 | - public static function is_customizer_loaded(): bool { |
|
| 39 | - global $wp_customize; |
|
| 40 | - |
|
| 41 | - if ( isset( $wp_customize ) ) { |
|
| 42 | - return true; |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - return false; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * Retrieve the section array from field ID. |
|
| 50 | - * |
|
| 51 | - * @param string $opt_name Panel opt_name. |
|
| 52 | - * @param string $field_id Field ID. |
|
| 53 | - */ |
|
| 54 | - public static function section_from_field_id( string $opt_name = '', string $field_id = '' ) { |
|
| 55 | - if ( '' !== $opt_name ) { |
|
| 56 | - $redux = Redux::instance( $opt_name ); |
|
| 57 | - |
|
| 58 | - if ( is_object( $redux ) ) { |
|
| 59 | - $sections = $redux->sections; |
|
| 60 | - |
|
| 61 | - if ( is_array( $sections ) && ! empty( $sections ) ) { |
|
| 62 | - foreach ( $sections as $section ) { |
|
| 63 | - if ( ! empty( $section['fields'] ) ) { |
|
| 64 | - foreach ( $section['fields'] as $field ) { |
|
| 65 | - if ( is_array( $field ) && ! empty( $field ) ) { |
|
| 66 | - if ( isset( $field['id'] ) && $field['id'] === $field_id ) { |
|
| 67 | - return $section; |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - return null; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Verify integer value. |
|
| 82 | - * |
|
| 83 | - * @param mixed $val Value to test. |
|
| 84 | - * |
|
| 85 | - * @return bool|false|int |
|
| 86 | - */ |
|
| 87 | - public static function is_integer( $val ) { |
|
| 88 | - if ( ! is_scalar( $val ) || is_bool( $val ) ) { |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - return is_float( $val ) ? false : preg_match( '~^([+\-]?[0-9]+)$~', $val ); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Deprecated. Gets panel tab number from the specified field. |
|
| 97 | - * |
|
| 98 | - * @param object $redux ReduxFramework object. |
|
| 99 | - * @param array|string $field Field array. |
|
| 100 | - * |
|
| 101 | - * @return int|string |
|
| 102 | - * @deprecated No longer using camelCase naming convention. |
|
| 103 | - */ |
|
| 104 | - public static function tabFromField( $redux, $field ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 105 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0', 'Redux_Helpers::tab_from_field( $parent, $field )' ); |
|
| 106 | - |
|
| 107 | - return self::tab_from_field( $redux, $field ); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * Gets panel tab number from the specified field. |
|
| 112 | - * |
|
| 113 | - * @param object $redux ReduxFramework object. |
|
| 114 | - * @param array|string $field Field array. |
|
| 115 | - * |
|
| 116 | - * @return int|string |
|
| 117 | - */ |
|
| 118 | - public static function tab_from_field( $redux, $field ) { |
|
| 119 | - foreach ( $redux->sections as $k => $section ) { |
|
| 120 | - if ( ! isset( $section['title'] ) ) { |
|
| 121 | - continue; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - if ( ! empty( $section['fields'] ) ) { |
|
| 125 | - if ( self::recursive_array_search( $field, $section['fields'] ) ) { |
|
| 126 | - return $k; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return null; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Deprecated. Verifies if a specified field type is in use. |
|
| 136 | - * |
|
| 137 | - * @param array $fields Field arrays. |
|
| 138 | - * @param array $field Field array. |
|
| 139 | - * |
|
| 140 | - * @return bool |
|
| 141 | - * @deprecated No longer using camelCase naming convention. |
|
| 142 | - */ |
|
| 143 | - public static function isFieldInUseByType( array $fields, array $field = array() ): bool { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 144 | - // phpcs:ignore Squiz.PHP.CommentedOutCode |
|
| 145 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0', 'Redux_Helpers::is_field_in_use_by_type( $parent, $field )' ); |
|
| 146 | - return self::is_field_in_use_by_type( $fields, $field ); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Verifies if a specified field type is in use. |
|
| 151 | - * |
|
| 152 | - * @param array $fields Field arrays. |
|
| 153 | - * @param array $field Field arrays to check. |
|
| 154 | - * |
|
| 155 | - * @return bool |
|
| 156 | - */ |
|
| 157 | - public static function is_field_in_use_by_type( array $fields, array $field = array() ): bool { |
|
| 158 | - foreach ( $field as $name ) { |
|
| 159 | - if ( array_key_exists( $name, $fields ) ) { |
|
| 160 | - return true; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - return false; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Deprecated Verifies if field is in use. |
|
| 169 | - * |
|
| 170 | - * @param object $redux ReduxFramework object. |
|
| 171 | - * @param string $field Field type. |
|
| 172 | - * |
|
| 173 | - * @return bool |
|
| 174 | - * @deprecated No longer using camelCase function names. |
|
| 175 | - */ |
|
| 176 | - public static function isFieldInUse( $redux, string $field ): bool { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 177 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0', 'Redux_Helpers::is_field_in_use( $parent, $field )' ); |
|
| 178 | - |
|
| 179 | - return self::is_field_in_use( $redux, $field ); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Verifies if field is in use. |
|
| 184 | - * |
|
| 185 | - * @param object $redux ReduxFramework object. |
|
| 186 | - * @param string $field Field type. |
|
| 187 | - * |
|
| 188 | - * @return bool |
|
| 189 | - */ |
|
| 190 | - public static function is_field_in_use( $redux, string $field ): bool { |
|
| 191 | - if ( empty( $redux->sections ) ) { |
|
| 192 | - return false; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - foreach ( $redux->sections as $section ) { |
|
| 196 | - if ( ! isset( $section['title'] ) ) { |
|
| 197 | - continue; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ( ! empty( $section['fields'] ) ) { |
|
| 201 | - if ( self::recursive_array_search( $field, $section['fields'] ) ) { |
|
| 202 | - return true; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - return false; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Returns major version from version number. |
|
| 212 | - * |
|
| 213 | - * @param string $v Version number. |
|
| 214 | - * |
|
| 215 | - * @return string |
|
| 216 | - */ |
|
| 217 | - public static function major_version( string $v ): string { |
|
| 218 | - $version = explode( '.', $v ); |
|
| 219 | - if ( count( $version ) > 1 ) { |
|
| 220 | - return $version[0] . '.' . $version[1]; |
|
| 221 | - } else { |
|
| 222 | - return $v; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Deprecated. Checks for localhost environment. |
|
| 229 | - * |
|
| 230 | - * @return bool |
|
| 231 | - * @deprecated No longer using camelCase naming convention. |
|
| 232 | - * @since 4.0 |
|
| 233 | - */ |
|
| 234 | - public static function isLocalHost(): bool { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 235 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0', 'Redux_Helpers::is_local_host()' ); |
|
| 236 | - |
|
| 237 | - return self::is_local_host(); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * Checks for localhost environment. |
|
| 242 | - * |
|
| 243 | - * @return bool |
|
| 244 | - */ |
|
| 245 | - public static function is_local_host(): bool { |
|
| 246 | - $is_local = false; |
|
| 247 | - |
|
| 248 | - $domains_to_check = array_unique( |
|
| 249 | - array( |
|
| 250 | - 'siteurl' => wp_parse_url( get_site_url(), PHP_URL_HOST ), |
|
| 251 | - 'homeurl' => wp_parse_url( get_home_url(), PHP_URL_HOST ), |
|
| 252 | - ) |
|
| 253 | - ); |
|
| 254 | - |
|
| 255 | - $forbidden_domains = array( |
|
| 256 | - 'wordpress.com', |
|
| 257 | - 'localhost', |
|
| 258 | - 'localhost.localdomain', |
|
| 259 | - '127.0.0.1', |
|
| 260 | - '::1', |
|
| 261 | - 'local.wordpress.test', // VVV pattern. |
|
| 262 | - 'local.wordpress-trunk.test', // VVV pattern. |
|
| 263 | - 'src.wordpress-develop.test', // VVV pattern. |
|
| 264 | - 'build.wordpress-develop.test', // VVV pattern. |
|
| 265 | - ); |
|
| 266 | - |
|
| 267 | - foreach ( $domains_to_check as $domain ) { |
|
| 268 | - // If it's empty, just fail out. |
|
| 269 | - if ( ! $domain ) { |
|
| 270 | - $is_local = true; |
|
| 271 | - break; |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // None of the explicit localhosts. |
|
| 275 | - if ( in_array( $domain, $forbidden_domains, true ) ) { |
|
| 276 | - $is_local = true; |
|
| 277 | - break; |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - // No .test or .local domains. |
|
| 281 | - if ( preg_match( '#\.(test|local)$#i', $domain ) ) { |
|
| 282 | - $is_local = true; |
|
| 283 | - break; |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - return $is_local; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Deprecated. Checks if WP_DEBUG is enabled. |
|
| 292 | - * |
|
| 293 | - * @return bool::is_wp_debug() |
|
| 294 | - * @deprecated No longer using camelCase naming convention. |
|
| 295 | - * @since 4.0 |
|
| 296 | - */ |
|
| 297 | - public static function isWpDebug(): bool { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 298 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0', 'Redux_Functions_Ex::is_wp_debug()' ); |
|
| 299 | - |
|
| 300 | - return self::is_wp_debug(); |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Checks if WP_DEBUG is enabled. |
|
| 305 | - * |
|
| 306 | - * @return bool |
|
| 307 | - */ |
|
| 308 | - public static function is_wp_debug(): bool { |
|
| 309 | - return ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - /** |
|
| 313 | - * Deprecated. Determines if theme is parent. |
|
| 314 | - * |
|
| 315 | - * @param string $file Path to file. |
|
| 316 | - * |
|
| 317 | - * @return bool |
|
| 318 | - * @deprecated No longer using camelCase naming convention. |
|
| 319 | - */ |
|
| 320 | - public static function isParentTheme( string $file ): bool { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 321 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0.0', 'Redux_Instances::is_parent_theme( $file )' ); |
|
| 322 | - |
|
| 323 | - return self::is_parent_theme( $file ); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Determines if theme is parent. |
|
| 328 | - * |
|
| 329 | - * @param string $file Path to theme dir. |
|
| 330 | - * |
|
| 331 | - * @return bool |
|
| 332 | - */ |
|
| 333 | - public static function is_parent_theme( string $file ): bool { |
|
| 334 | - $file = Redux_Functions_Ex::wp_normalize_path( $file ); |
|
| 335 | - $dir = Redux_Functions_Ex::wp_normalize_path( get_template_directory() ); |
|
| 336 | - |
|
| 337 | - $file = str_replace( '//', '/', $file ); |
|
| 338 | - $dir = str_replace( '//', '/', $dir ); |
|
| 339 | - |
|
| 340 | - if ( strpos( $file, $dir ) !== false ) { |
|
| 341 | - return true; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - return false; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - /** |
|
| 348 | - * Deprecated. Moved to another class. |
|
| 349 | - * |
|
| 350 | - * @param string $file Path to file. |
|
| 351 | - * |
|
| 352 | - * @return string |
|
| 353 | - * @deprecated Moved to another class. |
|
| 354 | - */ |
|
| 355 | - public static function wp_normalize_path( string $file ): string { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 356 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0.0', 'Redux_Functions_Ex::wp_normalize_path( $file )' ); |
|
| 357 | - |
|
| 358 | - return Redux_Functions_Ex::wp_normalize_path( $file ); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * Deprecated. Determines if the theme is child. |
|
| 363 | - * |
|
| 364 | - * @param string $file Path to file. |
|
| 365 | - * |
|
| 366 | - * @return bool |
|
| 367 | - * @deprecated No longer using camelCase naming convention. |
|
| 368 | - */ |
|
| 369 | - public static function isChildTheme( string $file ): bool { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 370 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0.0', 'Redux_Instances::is_child_theme( $file )' ); |
|
| 371 | - |
|
| 372 | - return self::is_child_theme( $file ); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Determines if the theme is child. |
|
| 377 | - * |
|
| 378 | - * @param string $file Path to theme dir. |
|
| 379 | - * |
|
| 380 | - * @return bool |
|
| 381 | - */ |
|
| 382 | - public static function is_child_theme( string $file ): bool { |
|
| 383 | - $file = Redux_Functions_Ex::wp_normalize_path( $file ); |
|
| 384 | - $dir = Redux_Functions_Ex::wp_normalize_path( get_stylesheet_directory() ); |
|
| 385 | - |
|
| 386 | - $file = str_replace( '//', '/', $file ); |
|
| 387 | - $dir = str_replace( '//', '/', $dir ); |
|
| 388 | - |
|
| 389 | - if ( strpos( $file, $dir ) !== false ) { |
|
| 390 | - return true; |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - return false; |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - /** |
|
| 397 | - * Deprecated. Determines if file is a theme. |
|
| 398 | - * |
|
| 399 | - * @param string $file Path to file. |
|
| 400 | - * |
|
| 401 | - * @return bool |
|
| 402 | - * @deprecated No longer using camelCase naming convention. |
|
| 403 | - */ |
|
| 404 | - public static function isTheme( string $file ): bool { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 405 | - // phpcs:ignore Squiz.PHP.CommentedOutCode |
|
| 406 | - // _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0.0', 'Redux_Instances::is_theme( $file )' ); |
|
| 407 | - |
|
| 408 | - return self::is_theme( $file ); |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Determines if file is a theme. |
|
| 413 | - * |
|
| 414 | - * @param string $file Path to fle to test. |
|
| 415 | - * |
|
| 416 | - * @return bool |
|
| 417 | - */ |
|
| 418 | - public static function is_theme( string $file ): bool { |
|
| 419 | - if ( true === self::is_child_theme( $file ) || true === self::is_parent_theme( $file ) ) { |
|
| 420 | - return true; |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - return false; |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - /** |
|
| 427 | - * Determines deep array status. |
|
| 428 | - * |
|
| 429 | - * @param array|string $needle array to test. |
|
| 430 | - * @param array $haystack Array to search. |
|
| 431 | - * |
|
| 432 | - * @return bool |
|
| 433 | - */ |
|
| 434 | - public static function array_in_array( $needle, array $haystack ): bool { |
|
| 435 | - // Make sure $needle is an array for foreach. |
|
| 436 | - if ( ! is_array( $needle ) ) { |
|
| 437 | - $needle = array( $needle ); |
|
| 438 | - } |
|
| 439 | - // For each value in $needle, return TRUE if in $haystack. |
|
| 440 | - foreach ( $needle as $pin ) { |
|
| 441 | - if ( in_array( $pin, $haystack, true ) ) { |
|
| 442 | - return true; |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - // Return FALSE if none of the values from $needle are found in $haystack. |
|
| 447 | - return false; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * Enum through an entire deep array. |
|
| 452 | - * |
|
| 453 | - * @param string|array $needle String to search for. |
|
| 454 | - * @param array $haystack Array in which to search. |
|
| 455 | - * |
|
| 456 | - * @return bool |
|
| 457 | - */ |
|
| 458 | - public static function recursive_array_search( $needle, array $haystack ): bool { |
|
| 459 | - foreach ( $haystack as $value ) { |
|
| 460 | - if ( $needle === $value || ( is_array( $value ) && self::recursive_array_search( $needle, $value ) !== false ) ) { |
|
| 461 | - return true; |
|
| 462 | - } |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - return false; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - /** |
|
| 469 | - * Take a path and return it clean. |
|
| 470 | - * |
|
| 471 | - * @param string $path Path to clean. |
|
| 472 | - * |
|
| 473 | - * @return string |
|
| 474 | - * @deprecated Replaced with wp_normalize_path. |
|
| 475 | - * @since 3.1.7 |
|
| 476 | - */ |
|
| 477 | - public static function cleanFilePath( string $path ): string { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 478 | - // phpcs:ignore Squiz.PHP.CommentedOutCode |
|
| 479 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0', 'Redux_Functions_Ex::wp_normalize_path( $path )' ); |
|
| 480 | - return Redux_Functions_Ex::wp_normalize_path( $path ); |
|
| 481 | - } |
|
| 482 | - |
|
| 483 | - /** |
|
| 484 | - * Get info for specified file. |
|
| 485 | - * |
|
| 486 | - * @param string $file File to check. |
|
| 487 | - * |
|
| 488 | - * @return array|bool |
|
| 489 | - */ |
|
| 490 | - public static function path_info( string $file ) { |
|
| 491 | - $theme_info = Redux_Functions_Ex::is_inside_theme( $file ); |
|
| 492 | - $plugin_info = Redux_Functions_Ex::is_inside_plugin( $file ); |
|
| 493 | - |
|
| 494 | - if ( false !== $theme_info ) { |
|
| 495 | - return $theme_info; |
|
| 496 | - } elseif ( false !== $plugin_info ) { |
|
| 497 | - return $plugin_info; |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - return array(); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * Compiles caller data for Redux. |
|
| 505 | - * |
|
| 506 | - * @param bool $simple Mode. |
|
| 507 | - * |
|
| 508 | - * @return array |
|
| 509 | - */ |
|
| 510 | - public static function process_redux_callers( bool $simple = false ): array { |
|
| 511 | - $data = array(); |
|
| 512 | - |
|
| 513 | - foreach ( Redux_Core::$callers as $opt_name => $callers ) { |
|
| 514 | - foreach ( $callers as $caller ) { |
|
| 515 | - $plugin_info = self::is_inside_plugin( $caller ); |
|
| 516 | - $theme_info = self::is_inside_theme( $caller ); |
|
| 517 | - |
|
| 518 | - if ( $theme_info ) { |
|
| 519 | - if ( ! isset( $data['theme'][ $theme_info['slug'] ] ) ) { |
|
| 520 | - $data['theme'][ $theme_info['slug'] ] = array(); |
|
| 521 | - } |
|
| 522 | - if ( ! isset( $data['theme'][ $theme_info['slug'] ][ $opt_name ] ) ) { |
|
| 523 | - $data['theme'][ $theme_info['slug'] ][ $opt_name ] = array(); |
|
| 524 | - } |
|
| 525 | - if ( $simple ) { |
|
| 526 | - $data['theme'][ $theme_info['slug'] ][ $opt_name ][] = $theme_info['basename']; |
|
| 527 | - } else { |
|
| 528 | - $data['theme'][ $theme_info['slug'] ][ $opt_name ][] = $theme_info; |
|
| 529 | - } |
|
| 530 | - } elseif ( $plugin_info ) { |
|
| 531 | - if ( ! isset( $data['plugin'][ $plugin_info['slug'] ] ) ) { |
|
| 532 | - $data['plugin'][ $plugin_info['slug'] ] = array(); |
|
| 533 | - } |
|
| 534 | - if ( ! in_array( $opt_name, $data['plugin'][ $plugin_info['slug'] ], true ) ) { |
|
| 535 | - if ( ! isset( $data['plugin'][ $plugin_info['slug'] ][ $opt_name ] ) ) { |
|
| 536 | - $data['plugin'][ $plugin_info['slug'] ][ $opt_name ] = array(); |
|
| 537 | - } |
|
| 538 | - if ( $simple ) { |
|
| 539 | - $data['plugin'][ $plugin_info['slug'] ][ $opt_name ][] = $plugin_info['basename']; |
|
| 540 | - } else { |
|
| 541 | - $data['plugin'][ $plugin_info['slug'] ][ $opt_name ][] = $plugin_info; |
|
| 542 | - } |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - return $data; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - /** |
|
| 552 | - * Field Render Function. |
|
| 553 | - * Takes the color hex value and converts to a rgba. |
|
| 554 | - * |
|
| 555 | - * @param string $hex Color value. |
|
| 556 | - * @param string $alpha Alpha value. |
|
| 557 | - * |
|
| 558 | - * @since ReduxFramework 3.0.4 |
|
| 559 | - */ |
|
| 560 | - public static function hex2rgba( string $hex, string $alpha = '' ): string { |
|
| 561 | - $hex = ltrim( $hex, '#' ); |
|
| 562 | - $hex = sanitize_hex_color_no_hash( $hex ); |
|
| 563 | - |
|
| 564 | - if ( '' === $hex ) { |
|
| 565 | - return ''; |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - if ( 3 === strlen( $hex ) ) { |
|
| 569 | - $r = hexdec( substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) ); |
|
| 570 | - $g = hexdec( substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) ); |
|
| 571 | - $b = hexdec( substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ) ); |
|
| 572 | - } else { |
|
| 573 | - $r = hexdec( substr( $hex, 0, 2 ) ); |
|
| 574 | - $g = hexdec( substr( $hex, 2, 2 ) ); |
|
| 575 | - $b = hexdec( substr( $hex, 4, 2 ) ); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - $rgb = $r . ',' . $g . ',' . $b; |
|
| 579 | - |
|
| 580 | - if ( '' === $alpha ) { |
|
| 581 | - return $rgb; |
|
| 582 | - } else { |
|
| 583 | - $alpha = floatval( $alpha ); |
|
| 584 | - |
|
| 585 | - return 'rgba(' . $rgb . ',' . $alpha . ')'; |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - /** |
|
| 590 | - * Deprecated. Returns string boolean value. |
|
| 591 | - * |
|
| 592 | - * @param mixed $variable String to convert to true boolean. |
|
| 593 | - * |
|
| 594 | - * @return mixed|array |
|
| 595 | - * |
|
| 596 | - * @deprecated No longer using camelCase naming convention. |
|
| 597 | - */ |
|
| 598 | - public static function makeBoolStr( $variable ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 599 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0.0', 'Redux_Instances::make_bool_str( $var )' ); |
|
| 600 | - |
|
| 601 | - return self::make_bool_str( $variable ); |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - /** |
|
| 605 | - * Returns string boolean value. |
|
| 606 | - * |
|
| 607 | - * @param mixed $variable true|false to convert. |
|
| 608 | - * |
|
| 609 | - * @return mixed|array |
|
| 610 | - */ |
|
| 611 | - public static function make_bool_str( $variable ) { |
|
| 612 | - if ( 'false' === $variable || empty( $variable ) ) { |
|
| 613 | - return 'false'; |
|
| 614 | - } elseif ( true === $variable || 'true' === $variable || 1 === $variable || '1' === $variable ) { |
|
| 615 | - return 'true'; |
|
| 616 | - } else { |
|
| 617 | - return $variable; |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - /** |
|
| 622 | - * Compile a localized array. |
|
| 623 | - * |
|
| 624 | - * @param array $localize Array of localized strings. |
|
| 625 | - * |
|
| 626 | - * @return array |
|
| 627 | - */ |
|
| 628 | - public static function localize( array $localize ): array { |
|
| 629 | - |
|
| 630 | - return $localize; |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * Check mokama. |
|
| 635 | - * |
|
| 636 | - * @access public |
|
| 637 | - * @since 4.0.0 |
|
| 638 | - * @return bool |
|
| 639 | - */ |
|
| 640 | - public static function mokama(): bool { |
|
| 641 | - if ( defined( 'RDX_MOKAMA' ) ) { |
|
| 642 | - return Redux_Functions_Ex::s(); |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - return false; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - /** |
|
| 649 | - * Retrieves template version. |
|
| 650 | - * |
|
| 651 | - * @param string $file Path to template file. |
|
| 652 | - * |
|
| 653 | - * @return string |
|
| 654 | - */ |
|
| 655 | - public static function get_template_version( string $file ): string { |
|
| 656 | - $filesystem = Redux_Filesystem::get_instance(); |
|
| 657 | - // Avoid notices if file does not exist. |
|
| 658 | - if ( ! file_exists( $file ) ) { |
|
| 659 | - return ''; |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - $data = get_file_data( $file, array( 'version' ), 'plugin' ); |
|
| 663 | - |
|
| 664 | - if ( ! empty( $data[0] ) ) { |
|
| 665 | - return $data[0]; |
|
| 666 | - } else { |
|
| 667 | - $file_data = $filesystem->get_contents( $file ); |
|
| 668 | - |
|
| 669 | - $file_data = str_replace( "\r", "\n", $file_data ); |
|
| 670 | - $version = '1.0.0'; |
|
| 671 | - |
|
| 672 | - if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] ) { |
|
| 673 | - $version = _cleanup_header_comment( $match[1] ); |
|
| 674 | - } |
|
| 675 | - |
|
| 676 | - return $version; |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - |
|
| 680 | - /** |
|
| 681 | - * Create HTML attribute string. |
|
| 682 | - * |
|
| 683 | - * @param array $attributes Array of attributes. |
|
| 684 | - */ |
|
| 685 | - public static function html_attributes( array $attributes = array() ): string { |
|
| 686 | - return join( |
|
| 687 | - ' ', |
|
| 688 | - array_map( |
|
| 689 | - function ( $key ) use ( $attributes ) { |
|
| 690 | - if ( is_bool( $attributes[ $key ] ) ) { |
|
| 691 | - return $attributes[ $key ] ? $key : ''; |
|
| 692 | - } |
|
| 693 | - |
|
| 694 | - return $key . '="' . $attributes[ $key ] . '"'; |
|
| 695 | - }, |
|
| 696 | - array_keys( $attributes ) |
|
| 697 | - ) |
|
| 698 | - ) . ' '; |
|
| 699 | - } |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * Normalize extensions dir. |
|
| 703 | - * |
|
| 704 | - * @param string $dir Path to extensions. |
|
| 705 | - * |
|
| 706 | - * @return string |
|
| 707 | - */ |
|
| 708 | - public static function get_extension_dir( string $dir ): string { |
|
| 709 | - return trailingslashit( Redux_Functions_Ex::wp_normalize_path( dirname( $dir ) ) ); |
|
| 710 | - } |
|
| 711 | - |
|
| 712 | - /** |
|
| 713 | - * Normalize extensions URL. |
|
| 714 | - * |
|
| 715 | - * @param string $dir Path to extensions. |
|
| 716 | - * |
|
| 717 | - * @return array|string|string[] |
|
| 718 | - */ |
|
| 719 | - public static function get_extension_url( string $dir ) { |
|
| 720 | - $ext_dir = self::get_extension_dir( $dir ); |
|
| 721 | - |
|
| 722 | - return str_replace( Redux_Functions_Ex::wp_normalize_path( WP_CONTENT_DIR ), WP_CONTENT_URL, $ext_dir ); |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - /** |
|
| 726 | - * Checks a nested capabilities array or string to determine if the current user meets the requirements. |
|
| 727 | - * |
|
| 728 | - * @param string|array $caps Permission string or array to check. See self::user_can() for details. |
|
| 729 | - * |
|
| 730 | - * @return bool Whether the user meets the requirements. False on invalid user. |
|
| 731 | - * @since 3.6.3.4 |
|
| 732 | - */ |
|
| 733 | - public static function current_user_can( $caps ): bool { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found |
|
| 734 | - $current_user = wp_get_current_user(); |
|
| 735 | - |
|
| 736 | - if ( empty( $current_user ) ) { |
|
| 737 | - return false; |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - $name_arr = func_get_args(); |
|
| 741 | - $args = array_merge( array( $current_user ), $name_arr ); |
|
| 742 | - |
|
| 743 | - return call_user_func_array( array( __CLASS__, 'user_can' ), $args ); |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * Checks a nested capabilities array or string to determine if the user meets the requirements. |
|
| 748 | - * You can pass in a simple string like 'edit_posts' or an array of conditions. |
|
| 749 | - * The capability 'relation' is reserved for controlling the relation mode (AND/OR), which defaults to AND. |
|
| 750 | - * Max depth of 30 levels. False is returned for any conditions exceeding max depth. |
|
| 751 | - * If you want to check meta caps, you must also pass the object ID on which to check against. |
|
| 752 | - * If you get the error: PHP Notice: Undefined offset: 0 in /wp-includes/capabilities.php, you didn't |
|
| 753 | - * pass the required $object_id. |
|
| 754 | - * |
|
| 755 | - * @param int|WP_User $user User ID or WP_User object to check. Defaults to the current user. |
|
| 756 | - * @param string|array $capabilities Capability string or array to check. The array lets you use multiple |
|
| 757 | - * conditions to determine if a user has permission. |
|
| 758 | - * Invalid conditions are skipped (conditions which aren't a string/array/bool/number(cast to bool)). |
|
| 759 | - * Example array where the user needs to have either the 'edit_posts' capability OR doesn't have the |
|
| 760 | - * 'delete_pages' cap OR has the 'update_plugins' AND 'add_users' capabilities. |
|
| 761 | - * array( |
|
| 762 | - * 'relation' => 'OR', // Optional, defaults to AND. |
|
| 763 | - * 'edit_posts', // Equivalent to 'edit_posts' => true, |
|
| 764 | - * 'delete_pages' => false, // Tests that the user DOESN'T have this capability |
|
| 765 | - * array( // Nested conditions array (up to 30 nestings) |
|
| 766 | - * 'update_plugins', |
|
| 767 | - * 'add_users', |
|
| 768 | - * ), |
|
| 769 | - * ). |
|
| 770 | - * @param int|null $object_id (Optional) ID of the specific object to check against if capability is a "meta" cap. |
|
| 771 | - * e.g. 'edit_post', 'edit_user', 'edit_page', etc. |
|
| 772 | - * |
|
| 773 | - * @return bool Whether the user meets the requirements. |
|
| 774 | - * Will always return false for: |
|
| 775 | - * - Invalid/missing user |
|
| 776 | - * - If the $capabilities is not a string or array |
|
| 777 | - * - Max nesting depth exceeded (for that level) |
|
| 778 | - * @since 3.6.3.4 |
|
| 779 | - * @example |
|
| 780 | - * user_can( 42, 'edit_pages' ); // Checks if user ID 42 has the 'edit_pages' cap. |
|
| 781 | - * user_can( 42, 'edit_page', 17433 ); // Checks if user ID 42 has the 'edit_page' cap for post-ID 17433. |
|
| 782 | - * user_can( 42, array( 'edit_pages', 'edit_posts' ) ); // Checks if user ID 42 has both the 'edit_pages' and 'edit_posts' caps. |
|
| 783 | - */ |
|
| 784 | - public static function user_can( $user, $capabilities, ?int $object_id = null ): bool { |
|
| 785 | - static $depth = 0; |
|
| 786 | - |
|
| 787 | - if ( $depth >= 30 ) { |
|
| 788 | - return false; |
|
| 789 | - } |
|
| 790 | - |
|
| 791 | - if ( empty( $user ) ) { |
|
| 792 | - return false; |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - if ( ! is_object( $user ) ) { |
|
| 796 | - $user = get_userdata( $user ); |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - if ( is_string( $capabilities ) ) { |
|
| 800 | - // Simple string capability check. |
|
| 801 | - $args = array( $user, $capabilities ); |
|
| 802 | - |
|
| 803 | - if ( null !== $object_id ) { |
|
| 804 | - $args[] = $object_id; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - return call_user_func_array( 'user_can', $args ); |
|
| 808 | - } elseif ( ! is_array( $capabilities ) ) { |
|
| 809 | - // Only strings and arrays are allowed as valid capabilities. |
|
| 810 | - return false; |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - // Capability array check. |
|
| 814 | - $or = false; |
|
| 815 | - |
|
| 816 | - foreach ( $capabilities as $key => $value ) { |
|
| 817 | - if ( 'relation' === $key ) { |
|
| 818 | - if ( 'OR' === $value ) { |
|
| 819 | - $or = true; |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - continue; |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - /** |
|
| 826 | - * Rules can be in 4 different formats: |
|
| 827 | - * [ |
|
| 828 | - * [0] => 'foobar', |
|
| 829 | - * [1] => array(...), |
|
| 830 | - * 'foobar' => false, |
|
| 831 | - * 'foobar' => array(...), |
|
| 832 | - * ] |
|
| 833 | - */ |
|
| 834 | - if ( is_numeric( $key ) ) { |
|
| 835 | - // Numeric key. |
|
| 836 | - if ( is_string( $value ) ) { |
|
| 837 | - // Numeric key with a string value is the capability string to check |
|
| 838 | - // [0] => 'foobar'. |
|
| 839 | - $args = array( $user, $value ); |
|
| 840 | - |
|
| 841 | - if ( null !== $object_id ) { |
|
| 842 | - $args[] = $object_id; |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - $expression_result = call_user_func_array( 'user_can', $args ) === true; |
|
| 846 | - } elseif ( is_array( $value ) ) { |
|
| 847 | - ++$depth; |
|
| 848 | - |
|
| 849 | - $expression_result = self::user_can( $user, $value, $object_id ); |
|
| 850 | - |
|
| 851 | - --$depth; |
|
| 852 | - } else { |
|
| 853 | - // Invalid types are skipped. |
|
| 854 | - continue; |
|
| 855 | - } |
|
| 856 | - } else { |
|
| 857 | - // Non-numeric key. |
|
| 858 | - if ( is_scalar( $value ) ) { |
|
| 859 | - $args = array( $user, $key ); |
|
| 860 | - |
|
| 861 | - if ( null !== $object_id ) { |
|
| 862 | - $args[] = $object_id; |
|
| 863 | - } |
|
| 864 | - |
|
| 865 | - $expression_result = call_user_func_array( 'user_can', $args ) === (bool) $value; |
|
| 866 | - } elseif ( is_array( $value ) ) { |
|
| 867 | - ++$depth; |
|
| 868 | - |
|
| 869 | - $expression_result = self::user_can( $user, $value, $object_id ); |
|
| 870 | - |
|
| 871 | - --$depth; |
|
| 872 | - } else { |
|
| 873 | - // Invalid types are skipped. |
|
| 874 | - continue; |
|
| 875 | - } |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - // Check after every evaluation if we know enough to return a definitive answer. |
|
| 879 | - if ( $or ) { |
|
| 880 | - if ( $expression_result ) { |
|
| 881 | - // If the relation is OR, return on the first true expression. |
|
| 882 | - return true; |
|
| 883 | - } |
|
| 884 | - } elseif ( ! $expression_result ) { |
|
| 885 | - // If the relation is AND, return on the first false expression. |
|
| 886 | - return false; |
|
| 887 | - } |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - // If we get this far on an OR, then it failed. |
|
| 891 | - // If we get this far on an AND, then it succeeded. |
|
| 892 | - return ! $or; |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - /** |
|
| 896 | - * Check if Google font update is needed. |
|
| 897 | - * |
|
| 898 | - * @return bool |
|
| 899 | - */ |
|
| 900 | - public static function google_fonts_update_needed(): bool { |
|
| 901 | - $path = trailingslashit( Redux_Core::$upload_dir ) . 'google_fonts.json'; |
|
| 902 | - $now = time(); |
|
| 903 | - $secs = 60 * 60 * 24 * 7; |
|
| 904 | - |
|
| 905 | - if ( file_exists( $path ) ) { |
|
| 906 | - if ( ( $now - filemtime( $path ) ) < $secs ) { |
|
| 907 | - return false; |
|
| 908 | - } |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - return true; |
|
| 912 | - } |
|
| 913 | - |
|
| 914 | - /** |
|
| 915 | - * Retrieve an updated Google font array. |
|
| 916 | - * |
|
| 917 | - * @param bool $download Flag to download to file. |
|
| 918 | - * |
|
| 919 | - * @return array|WP_Error |
|
| 920 | - */ |
|
| 921 | - public static function google_fonts_array( bool $download = false ) { |
|
| 922 | - if ( ! empty( Redux_Core::$updated_google_fonts ) && ! self::google_fonts_update_needed() ) { |
|
| 923 | - return Redux_Core::$updated_google_fonts; |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - $filesystem = Redux_Filesystem::get_instance(); |
|
| 927 | - |
|
| 928 | - $path = trailingslashit( Redux_Core::$upload_dir ) . 'google_fonts.json'; |
|
| 929 | - |
|
| 930 | - if ( ! file_exists( $path ) || ( file_exists( $path ) && $download && self::google_fonts_update_needed() ) ) { |
|
| 931 | - if ( $download ) { |
|
| 932 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 933 | - $url = apply_filters( 'redux/typography/google_fonts/url', 'https://raw.githubusercontent.com/reduxframework/google-fonts/master/google_fonts.json' ); |
|
| 934 | - |
|
| 935 | - $request = wp_remote_get( |
|
| 936 | - $url, |
|
| 937 | - array( |
|
| 938 | - 'timeout' => 20, |
|
| 939 | - ) |
|
| 940 | - ); |
|
| 941 | - |
|
| 942 | - if ( ! is_wp_error( $request ) ) { |
|
| 943 | - $body = wp_remote_retrieve_body( $request ); |
|
| 944 | - if ( ! empty( $body ) ) { |
|
| 945 | - $filesystem->put_contents( $path, $body ); |
|
| 946 | - Redux_Core::$updated_google_fonts = json_decode( $body, true ); |
|
| 947 | - } |
|
| 948 | - } else { |
|
| 949 | - return $request; |
|
| 950 | - } |
|
| 951 | - } |
|
| 952 | - } elseif ( file_exists( $path ) ) { |
|
| 953 | - Redux_Core::$updated_google_fonts = json_decode( $filesystem->get_contents( $path ), true ); |
|
| 954 | - if ( empty( Redux_Core::$updated_google_fonts ) ) { |
|
| 955 | - $filesystem->unlink( $path ); |
|
| 956 | - } |
|
| 957 | - } |
|
| 958 | - |
|
| 959 | - return Redux_Core::$updated_google_fonts; |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - /** |
|
| 963 | - * Deprecated. Gets all Redux instances |
|
| 964 | - * |
|
| 965 | - * @return array |
|
| 966 | - * @deprecated No longer using camelCase naming convention and moved to a different class. |
|
| 967 | - */ |
|
| 968 | - public static function getReduxInstances(): array { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 969 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0.0', 'Redux_Instances::get_all_instances()' ); |
|
| 970 | - |
|
| 971 | - return Redux_Instances::get_all_instances(); |
|
| 972 | - } |
|
| 973 | - |
|
| 974 | - /** |
|
| 975 | - * Is Inside Plugin |
|
| 976 | - * |
|
| 977 | - * @param string $file File name. |
|
| 978 | - * |
|
| 979 | - * @return array|bool |
|
| 980 | - */ |
|
| 981 | - public static function is_inside_plugin( string $file ) { |
|
| 982 | - |
|
| 983 | - // phpcs:ignore Squiz.PHP.CommentedOutCode |
|
| 984 | - // if ( substr( strtoupper( $file ), 0, 2 ) === 'C:' ) { |
|
| 985 | - // $file = ltrim( $file, 'C:' ); |
|
| 986 | - // $file = ltrim( $file, 'c:' ); |
|
| 987 | - // } . |
|
| 988 | - // |
|
| 989 | - $plugin_basename = plugin_basename( $file ); |
|
| 990 | - |
|
| 991 | - if ( Redux_Functions_Ex::wp_normalize_path( $file ) !== '/' . $plugin_basename ) { |
|
| 992 | - $slug = explode( '/', $plugin_basename ); |
|
| 993 | - $slug = $slug[0]; |
|
| 994 | - |
|
| 995 | - return array( |
|
| 996 | - 'slug' => $slug, |
|
| 997 | - 'basename' => $plugin_basename, |
|
| 998 | - 'path' => Redux_Functions_Ex::wp_normalize_path( $file ), |
|
| 999 | - 'url' => plugins_url( $plugin_basename ), |
|
| 1000 | - 'real_path' => Redux_Functions_Ex::wp_normalize_path( dirname( realpath( $file ) ) ), |
|
| 1001 | - ); |
|
| 1002 | - } |
|
| 1003 | - |
|
| 1004 | - return false; |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - /** |
|
| 1008 | - * Is inside theme. |
|
| 1009 | - * |
|
| 1010 | - * @param string $file File name. |
|
| 1011 | - * |
|
| 1012 | - * @return array|bool |
|
| 1013 | - */ |
|
| 1014 | - public static function is_inside_theme( string $file = '' ) { |
|
| 1015 | - $theme_paths = array( |
|
| 1016 | - Redux_Functions_Ex::wp_normalize_path( get_template_directory() ) => get_template_directory_uri(), |
|
| 1017 | - Redux_Functions_Ex::wp_normalize_path( get_stylesheet_directory() ) => get_stylesheet_directory_uri(), |
|
| 1018 | - ); |
|
| 1019 | - |
|
| 1020 | - $theme_paths = array_unique( $theme_paths ); |
|
| 1021 | - |
|
| 1022 | - $file_path = Redux_Functions_Ex::wp_normalize_path( $file ); |
|
| 1023 | - $filename = explode( '/', $file_path ); |
|
| 1024 | - $filename = end( $filename ); |
|
| 1025 | - foreach ( $theme_paths as $theme_path => $url ) { |
|
| 1026 | - |
|
| 1027 | - $real_path = Redux_Functions_Ex::wp_normalize_path( realpath( $theme_path ) ); |
|
| 1028 | - |
|
| 1029 | - if ( strpos( $file_path, trailingslashit( $real_path ) ) !== false ) { |
|
| 1030 | - $slug = explode( '/', Redux_Functions_Ex::wp_normalize_path( $theme_path ) ); |
|
| 1031 | - if ( empty( $slug ) ) { |
|
| 1032 | - continue; |
|
| 1033 | - } |
|
| 1034 | - $slug = end( $slug ); |
|
| 1035 | - $relative_path = explode( $slug, dirname( $file_path ) ); |
|
| 1036 | - |
|
| 1037 | - if ( 1 === count( $relative_path ) ) { |
|
| 1038 | - $relative_path = $file_path; |
|
| 1039 | - } else { |
|
| 1040 | - $relative_path = $relative_path[1]; |
|
| 1041 | - } |
|
| 1042 | - $relative_path = ltrim( $relative_path, '/' ); |
|
| 1043 | - |
|
| 1044 | - $data = array( |
|
| 1045 | - 'slug' => $slug, |
|
| 1046 | - 'path' => trailingslashit( trailingslashit( $theme_path ) . $relative_path ) . $filename, |
|
| 1047 | - 'real_path' => trailingslashit( trailingslashit( $real_path ) . $relative_path ) . $filename, |
|
| 1048 | - 'url' => trailingslashit( trailingslashit( $url ) . $relative_path ) . $filename, |
|
| 1049 | - ); |
|
| 1050 | - |
|
| 1051 | - $basename = explode( $data['slug'], $data['path'] ); |
|
| 1052 | - $basename = end( $basename ); |
|
| 1053 | - $basename = ltrim( $basename, '/' ); |
|
| 1054 | - $data['basename'] = trailingslashit( $data['slug'] ) . $basename; |
|
| 1055 | - |
|
| 1056 | - if ( is_child_theme() ) { |
|
| 1057 | - $parent = get_template_directory(); |
|
| 1058 | - $data['parent_slug'] = explode( '/', $parent ); |
|
| 1059 | - $data['parent_slug'] = end( $data['parent_slug'] ); |
|
| 1060 | - if ( $data['slug'] === $data['parent_slug'] ) { |
|
| 1061 | - unset( $data['parent_slug'] ); |
|
| 1062 | - } |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - return $data; |
|
| 1066 | - } |
|
| 1067 | - } |
|
| 1068 | - |
|
| 1069 | - return false; |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - |
|
| 1073 | - /** |
|
| 1074 | - * Get plugin options. |
|
| 1075 | - * |
|
| 1076 | - * @return array|mixed|void |
|
| 1077 | - */ |
|
| 1078 | - public static function get_plugin_options() { |
|
| 1079 | - $defaults = array( |
|
| 1080 | - 'demo' => false, |
|
| 1081 | - ); |
|
| 1082 | - $options = array(); |
|
| 1083 | - |
|
| 1084 | - // If multisite is enabled. |
|
| 1085 | - if ( is_multisite() ) { |
|
| 1086 | - |
|
| 1087 | - // Get network activated plugins. |
|
| 1088 | - $plugins = get_site_option( 'active_sitewide_plugins' ); |
|
| 1089 | - |
|
| 1090 | - foreach ( $plugins as $file => $plugin ) { |
|
| 1091 | - if ( strpos( $file, 'redux-framework.php' ) !== false ) { |
|
| 1092 | - $options = get_site_option( 'ReduxFrameworkPlugin', $defaults ); |
|
| 1093 | - } |
|
| 1094 | - } |
|
| 1095 | - } |
|
| 1096 | - |
|
| 1097 | - // If options aren't set, grab them now! |
|
| 1098 | - if ( empty( $options ) ) { |
|
| 1099 | - $options = get_option( 'ReduxFrameworkPlugin', $defaults ); |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - return $options; |
|
| 1103 | - } |
|
| 1104 | - |
|
| 1105 | - /** |
|
| 1106 | - * Sanitize array keys and values. |
|
| 1107 | - * |
|
| 1108 | - * @param array $arr Array to sanitize. |
|
| 1109 | - */ |
|
| 1110 | - public static function sanitize_array( array $arr ): array { |
|
| 1111 | - return self::array_map_r( 'wp_kses_post', $arr ); |
|
| 1112 | - } |
|
| 1113 | - |
|
| 1114 | - /** |
|
| 1115 | - * Recursive array map. |
|
| 1116 | - * |
|
| 1117 | - * @param string $func function to run. |
|
| 1118 | - * @param array $arr Array to clean. |
|
| 1119 | - * |
|
| 1120 | - * @return array |
|
| 1121 | - */ |
|
| 1122 | - private static function array_map_r( string $func, array $arr ): array { |
|
| 1123 | - $new_arr = array(); |
|
| 1124 | - |
|
| 1125 | - foreach ( $arr as $key => $value ) { |
|
| 1126 | - $new_arr[ $key ] = ( is_array( $value ) ? self::array_map_r( $func, $value ) : ( is_array( $func ) ? call_user_func_array( $func, $value ) : $func( $value ) ) ); |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - return $new_arr; |
|
| 1130 | - } |
|
| 1131 | - |
|
| 1132 | - /** |
|
| 1133 | - * Material design colors. |
|
| 1134 | - * |
|
| 1135 | - * @param string $context Mode to use. |
|
| 1136 | - * |
|
| 1137 | - * @return array |
|
| 1138 | - */ |
|
| 1139 | - public static function get_material_design_colors( string $context = 'primary' ): array { |
|
| 1140 | - $colors = array( |
|
| 1141 | - 'primary' => array( '#FFFFFF', '#000000', '#F44336', '#E91E63', '#9C27B0', '#673AB7', '#3F51B5', '#2196F3', '#03A9F4', '#00BCD4', '#009688', '#4CAF50', '#8BC34A', '#CDDC39', '#FFEB3B', '#FFC107', '#FF9800', '#FF5722', '#795548', '#9E9E9E', '#607D8B' ), |
|
| 1142 | - 'red' => array( '#FFEBEE', '#FFCDD2', '#EF9A9A', '#E57373', '#EF5350', '#F44336', '#E53935', '#D32F2F', '#C62828', '#B71C1C', '#FF8A80', '#FF5252', '#FF1744', '#D50000' ), |
|
| 1143 | - 'pink' => array( '#FCE4EC', '#F8BBD0', '#F48FB1', '#F06292', '#EC407A', '#E91E63', '#D81B60', '#C2185B', '#AD1457', '#880E4F', '#FF80AB', '#FF4081', '#F50057', '#C51162' ), |
|
| 1144 | - 'purple' => array( '#F3E5F5', '#E1BEE7', '#CE93D8', '#BA68C8', '#AB47BC', '#9C27B0', '#8E24AA', '#7B1FA2', '#6A1B9A', '#4A148C', '#EA80FC', '#E040FB', '#D500F9', '#AA00FF' ), |
|
| 1145 | - 'deep-purple' => array( '#EDE7F6', '#D1C4E9', '#B39DDB', '#9575CD', '#7E57C2', '#673AB7', '#5E35B1', '#512DA8', '#4527A0', '#311B92', '#B388FF', '#7C4DFF', '#651FFF', '#6200EA' ), |
|
| 1146 | - 'indigo' => array( '#E8EAF6', '#C5CAE9', '#9FA8DA', '#7986CB', '#5C6BC0', '#3F51B5', '#3949AB', '#303F9F', '#283593', '#1A237E', '#8C9EFF', '#536DFE', '#3D5AFE', '#304FFE' ), |
|
| 1147 | - 'blue' => array( '#E3F2FD', '#BBDEFB', '#90CAF9', '#64B5F6', '#42A5F5', '#2196F3', '#1E88E5', '#1976D2', '#1565C0', '#0D47A1', '#82B1FF', '#448AFF', '#2979FF', '#2962FF' ), |
|
| 1148 | - 'light-blue' => array( '#E1F5FE', '#B3E5FC', '#81D4fA', '#4fC3F7', '#29B6FC', '#03A9F4', '#039BE5', '#0288D1', '#0277BD', '#01579B', '#80D8FF', '#40C4FF', '#00B0FF', '#0091EA' ), |
|
| 1149 | - 'cyan' => array( '#E0F7FA', '#B2EBF2', '#80DEEA', '#4DD0E1', '#26C6DA', '#00BCD4', '#00ACC1', '#0097A7', '#00838F', '#006064', '#84FFFF', '#18FFFF', '#00E5FF', '#00B8D4' ), |
|
| 1150 | - 'teal' => array( '#E0F2F1', '#B2DFDB', '#80CBC4', '#4DB6AC', '#26A69A', '#009688', '#00897B', '#00796B', '#00695C', '#004D40', '#A7FFEB', '#64FFDA', '#1DE9B6', '#00BFA5' ), |
|
| 1151 | - 'green' => array( '#E8F5E9', '#C8E6C9', '#A5D6A7', '#81C784', '#66BB6A', '#4CAF50', '#43A047', '#388E3C', '#2E7D32', '#1B5E20', '#B9F6CA', '#69F0AE', '#00E676', '#00C853' ), |
|
| 1152 | - 'light-green' => array( '#F1F8E9', '#DCEDC8', '#C5E1A5', '#AED581', '#9CCC65', '#8BC34A', '#7CB342', '#689F38', '#558B2F', '#33691E', '#CCFF90', '#B2FF59', '#76FF03', '#64DD17' ), |
|
| 1153 | - 'lime' => array( '#F9FBE7', '#F0F4C3', '#E6EE9C', '#DCE775', '#D4E157', '#CDDC39', '#C0CA33', '#A4B42B', '#9E9D24', '#827717', '#F4FF81', '#EEFF41', '#C6FF00', '#AEEA00' ), |
|
| 1154 | - 'yellow' => array( '#FFFDE7', '#FFF9C4', '#FFF590', '#FFF176', '#FFEE58', '#FFEB3B', '#FDD835', '#FBC02D', '#F9A825', '#F57F17', '#FFFF82', '#FFFF00', '#FFEA00', '#FFD600' ), |
|
| 1155 | - 'amber' => array( '#FFF8E1', '#FFECB3', '#FFE082', '#FFD54F', '#FFCA28', '#FFC107', '#FFB300', '#FFA000', '#FF8F00', '#FF6F00', '#FFE57F', '#FFD740', '#FFC400', '#FFAB00' ), |
|
| 1156 | - 'orange' => array( '#FFF3E0', '#FFE0B2', '#FFCC80', '#FFB74D', '#FFA726', '#FF9800', '#FB8C00', '#F57C00', '#EF6C00', '#E65100', '#FFD180', '#FFAB40', '#FF9100', '#FF6D00' ), |
|
| 1157 | - 'deep-orange' => array( '#FBE9A7', '#FFCCBC', '#FFAB91', '#FF8A65', '#FF7043', '#FF5722', '#F4511E', '#E64A19', '#D84315', '#BF360C', '#FF9E80', '#FF6E40', '#FF3D00', '#DD2600' ), |
|
| 1158 | - 'brown' => array( '#EFEBE9', '#D7CCC8', '#BCAAA4', '#A1887F', '#8D6E63', '#795548', '#6D4C41', '#5D4037', '#4E342E', '#3E2723' ), |
|
| 1159 | - 'gray' => array( '#FAFAFA', '#F5F5F5', '#EEEEEE', '#E0E0E0', '#BDBDBD', '#9E9E9E', '#757575', '#616161', '#424242', '#212121', '#000000', '#ffffff' ), |
|
| 1160 | - 'blue-gray' => array( '#ECEFF1', '#CFD8DC', '#B0BBC5', '#90A4AE', '#78909C', '#607D8B', '#546E7A', '#455A64', '#37474F', '#263238' ), |
|
| 1161 | - ); |
|
| 1162 | - |
|
| 1163 | - $mui_arr = array( |
|
| 1164 | - '50', |
|
| 1165 | - '100', |
|
| 1166 | - '200', |
|
| 1167 | - '300', |
|
| 1168 | - '400', |
|
| 1169 | - '500', |
|
| 1170 | - '600', |
|
| 1171 | - '700', |
|
| 1172 | - '800', |
|
| 1173 | - '900', |
|
| 1174 | - 'A100', |
|
| 1175 | - 'A200', |
|
| 1176 | - 'A400', |
|
| 1177 | - 'A700', |
|
| 1178 | - ); |
|
| 1179 | - |
|
| 1180 | - if ( in_array( $context, $mui_arr, true ) ) { |
|
| 1181 | - $key = absint( $context ) / 100; |
|
| 1182 | - |
|
| 1183 | - if ( 'A100' === $context ) { |
|
| 1184 | - $key = 10; |
|
| 1185 | - unset( $colors['grey'] ); |
|
| 1186 | - } elseif ( 'A200' === $context ) { |
|
| 1187 | - $key = 11; |
|
| 1188 | - unset( $colors['grey'] ); |
|
| 1189 | - } elseif ( 'A400' === $context ) { |
|
| 1190 | - $key = 12; |
|
| 1191 | - unset( $colors['grey'] ); |
|
| 1192 | - } elseif ( 'A700' === $context ) { |
|
| 1193 | - $key = 13; |
|
| 1194 | - unset( $colors['grey'] ); |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - unset( $colors['primary'] ); |
|
| 1198 | - |
|
| 1199 | - $position_colors = array(); |
|
| 1200 | - foreach ( $colors as $color_family ) { |
|
| 1201 | - if ( isset( $color_family[ $key ] ) ) { |
|
| 1202 | - $position_colors[] = $color_family[ $key ]; |
|
| 1203 | - } |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - return $position_colors; |
|
| 1207 | - } elseif ( 'all' === $context ) { |
|
| 1208 | - unset( $colors['primary'] ); |
|
| 1209 | - |
|
| 1210 | - $all_colors = array(); |
|
| 1211 | - foreach ( $colors as $color_family ) { |
|
| 1212 | - foreach ( $color_family as $color ) { |
|
| 1213 | - $all_colors[] = $color; |
|
| 1214 | - } |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - return $all_colors; |
|
| 1218 | - } elseif ( 'primary' === $context ) { |
|
| 1219 | - return $colors['primary']; |
|
| 1220 | - } else { |
|
| 1221 | - if ( isset( $colors[ $context ] ) ) { |
|
| 1222 | - return $colors[ $context ]; |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - return $colors['primary']; |
|
| 1226 | - } |
|
| 1227 | - } |
|
| 1228 | - } |
|
| 18 | + /** |
|
| 19 | + * Redux Helpers Class |
|
| 20 | + * A Class of useful functions that can/should be shared among all Redux files. |
|
| 21 | + * |
|
| 22 | + * @since 3.0.0 |
|
| 23 | + */ |
|
| 24 | + class Redux_Helpers { |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Reusable supported unit array. |
|
| 28 | + * |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + public static $array_units = array( '', '%', 'in', 'cm', 'mm', 'em', 'rem', 'ex', 'pt', 'pc', 'px', 'vh', 'vw', 'vmin', 'vmax', 'ch' ); |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Is customizer loaded. |
|
| 35 | + * |
|
| 36 | + * @return bool |
|
| 37 | + */ |
|
| 38 | + public static function is_customizer_loaded(): bool { |
|
| 39 | + global $wp_customize; |
|
| 40 | + |
|
| 41 | + if ( isset( $wp_customize ) ) { |
|
| 42 | + return true; |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + return false; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * Retrieve the section array from field ID. |
|
| 50 | + * |
|
| 51 | + * @param string $opt_name Panel opt_name. |
|
| 52 | + * @param string $field_id Field ID. |
|
| 53 | + */ |
|
| 54 | + public static function section_from_field_id( string $opt_name = '', string $field_id = '' ) { |
|
| 55 | + if ( '' !== $opt_name ) { |
|
| 56 | + $redux = Redux::instance( $opt_name ); |
|
| 57 | + |
|
| 58 | + if ( is_object( $redux ) ) { |
|
| 59 | + $sections = $redux->sections; |
|
| 60 | + |
|
| 61 | + if ( is_array( $sections ) && ! empty( $sections ) ) { |
|
| 62 | + foreach ( $sections as $section ) { |
|
| 63 | + if ( ! empty( $section['fields'] ) ) { |
|
| 64 | + foreach ( $section['fields'] as $field ) { |
|
| 65 | + if ( is_array( $field ) && ! empty( $field ) ) { |
|
| 66 | + if ( isset( $field['id'] ) && $field['id'] === $field_id ) { |
|
| 67 | + return $section; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + return null; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Verify integer value. |
|
| 82 | + * |
|
| 83 | + * @param mixed $val Value to test. |
|
| 84 | + * |
|
| 85 | + * @return bool|false|int |
|
| 86 | + */ |
|
| 87 | + public static function is_integer( $val ) { |
|
| 88 | + if ( ! is_scalar( $val ) || is_bool( $val ) ) { |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + return is_float( $val ) ? false : preg_match( '~^([+\-]?[0-9]+)$~', $val ); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Deprecated. Gets panel tab number from the specified field. |
|
| 97 | + * |
|
| 98 | + * @param object $redux ReduxFramework object. |
|
| 99 | + * @param array|string $field Field array. |
|
| 100 | + * |
|
| 101 | + * @return int|string |
|
| 102 | + * @deprecated No longer using camelCase naming convention. |
|
| 103 | + */ |
|
| 104 | + public static function tabFromField( $redux, $field ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 105 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0', 'Redux_Helpers::tab_from_field( $parent, $field )' ); |
|
| 106 | + |
|
| 107 | + return self::tab_from_field( $redux, $field ); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * Gets panel tab number from the specified field. |
|
| 112 | + * |
|
| 113 | + * @param object $redux ReduxFramework object. |
|
| 114 | + * @param array|string $field Field array. |
|
| 115 | + * |
|
| 116 | + * @return int|string |
|
| 117 | + */ |
|
| 118 | + public static function tab_from_field( $redux, $field ) { |
|
| 119 | + foreach ( $redux->sections as $k => $section ) { |
|
| 120 | + if ( ! isset( $section['title'] ) ) { |
|
| 121 | + continue; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + if ( ! empty( $section['fields'] ) ) { |
|
| 125 | + if ( self::recursive_array_search( $field, $section['fields'] ) ) { |
|
| 126 | + return $k; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return null; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Deprecated. Verifies if a specified field type is in use. |
|
| 136 | + * |
|
| 137 | + * @param array $fields Field arrays. |
|
| 138 | + * @param array $field Field array. |
|
| 139 | + * |
|
| 140 | + * @return bool |
|
| 141 | + * @deprecated No longer using camelCase naming convention. |
|
| 142 | + */ |
|
| 143 | + public static function isFieldInUseByType( array $fields, array $field = array() ): bool { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 144 | + // phpcs:ignore Squiz.PHP.CommentedOutCode |
|
| 145 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0', 'Redux_Helpers::is_field_in_use_by_type( $parent, $field )' ); |
|
| 146 | + return self::is_field_in_use_by_type( $fields, $field ); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Verifies if a specified field type is in use. |
|
| 151 | + * |
|
| 152 | + * @param array $fields Field arrays. |
|
| 153 | + * @param array $field Field arrays to check. |
|
| 154 | + * |
|
| 155 | + * @return bool |
|
| 156 | + */ |
|
| 157 | + public static function is_field_in_use_by_type( array $fields, array $field = array() ): bool { |
|
| 158 | + foreach ( $field as $name ) { |
|
| 159 | + if ( array_key_exists( $name, $fields ) ) { |
|
| 160 | + return true; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + return false; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Deprecated Verifies if field is in use. |
|
| 169 | + * |
|
| 170 | + * @param object $redux ReduxFramework object. |
|
| 171 | + * @param string $field Field type. |
|
| 172 | + * |
|
| 173 | + * @return bool |
|
| 174 | + * @deprecated No longer using camelCase function names. |
|
| 175 | + */ |
|
| 176 | + public static function isFieldInUse( $redux, string $field ): bool { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 177 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0', 'Redux_Helpers::is_field_in_use( $parent, $field )' ); |
|
| 178 | + |
|
| 179 | + return self::is_field_in_use( $redux, $field ); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Verifies if field is in use. |
|
| 184 | + * |
|
| 185 | + * @param object $redux ReduxFramework object. |
|
| 186 | + * @param string $field Field type. |
|
| 187 | + * |
|
| 188 | + * @return bool |
|
| 189 | + */ |
|
| 190 | + public static function is_field_in_use( $redux, string $field ): bool { |
|
| 191 | + if ( empty( $redux->sections ) ) { |
|
| 192 | + return false; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + foreach ( $redux->sections as $section ) { |
|
| 196 | + if ( ! isset( $section['title'] ) ) { |
|
| 197 | + continue; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ( ! empty( $section['fields'] ) ) { |
|
| 201 | + if ( self::recursive_array_search( $field, $section['fields'] ) ) { |
|
| 202 | + return true; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + return false; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Returns major version from version number. |
|
| 212 | + * |
|
| 213 | + * @param string $v Version number. |
|
| 214 | + * |
|
| 215 | + * @return string |
|
| 216 | + */ |
|
| 217 | + public static function major_version( string $v ): string { |
|
| 218 | + $version = explode( '.', $v ); |
|
| 219 | + if ( count( $version ) > 1 ) { |
|
| 220 | + return $version[0] . '.' . $version[1]; |
|
| 221 | + } else { |
|
| 222 | + return $v; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Deprecated. Checks for localhost environment. |
|
| 229 | + * |
|
| 230 | + * @return bool |
|
| 231 | + * @deprecated No longer using camelCase naming convention. |
|
| 232 | + * @since 4.0 |
|
| 233 | + */ |
|
| 234 | + public static function isLocalHost(): bool { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 235 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0', 'Redux_Helpers::is_local_host()' ); |
|
| 236 | + |
|
| 237 | + return self::is_local_host(); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * Checks for localhost environment. |
|
| 242 | + * |
|
| 243 | + * @return bool |
|
| 244 | + */ |
|
| 245 | + public static function is_local_host(): bool { |
|
| 246 | + $is_local = false; |
|
| 247 | + |
|
| 248 | + $domains_to_check = array_unique( |
|
| 249 | + array( |
|
| 250 | + 'siteurl' => wp_parse_url( get_site_url(), PHP_URL_HOST ), |
|
| 251 | + 'homeurl' => wp_parse_url( get_home_url(), PHP_URL_HOST ), |
|
| 252 | + ) |
|
| 253 | + ); |
|
| 254 | + |
|
| 255 | + $forbidden_domains = array( |
|
| 256 | + 'wordpress.com', |
|
| 257 | + 'localhost', |
|
| 258 | + 'localhost.localdomain', |
|
| 259 | + '127.0.0.1', |
|
| 260 | + '::1', |
|
| 261 | + 'local.wordpress.test', // VVV pattern. |
|
| 262 | + 'local.wordpress-trunk.test', // VVV pattern. |
|
| 263 | + 'src.wordpress-develop.test', // VVV pattern. |
|
| 264 | + 'build.wordpress-develop.test', // VVV pattern. |
|
| 265 | + ); |
|
| 266 | + |
|
| 267 | + foreach ( $domains_to_check as $domain ) { |
|
| 268 | + // If it's empty, just fail out. |
|
| 269 | + if ( ! $domain ) { |
|
| 270 | + $is_local = true; |
|
| 271 | + break; |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // None of the explicit localhosts. |
|
| 275 | + if ( in_array( $domain, $forbidden_domains, true ) ) { |
|
| 276 | + $is_local = true; |
|
| 277 | + break; |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + // No .test or .local domains. |
|
| 281 | + if ( preg_match( '#\.(test|local)$#i', $domain ) ) { |
|
| 282 | + $is_local = true; |
|
| 283 | + break; |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + return $is_local; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Deprecated. Checks if WP_DEBUG is enabled. |
|
| 292 | + * |
|
| 293 | + * @return bool::is_wp_debug() |
|
| 294 | + * @deprecated No longer using camelCase naming convention. |
|
| 295 | + * @since 4.0 |
|
| 296 | + */ |
|
| 297 | + public static function isWpDebug(): bool { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 298 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0', 'Redux_Functions_Ex::is_wp_debug()' ); |
|
| 299 | + |
|
| 300 | + return self::is_wp_debug(); |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Checks if WP_DEBUG is enabled. |
|
| 305 | + * |
|
| 306 | + * @return bool |
|
| 307 | + */ |
|
| 308 | + public static function is_wp_debug(): bool { |
|
| 309 | + return ( defined( 'WP_DEBUG' ) && true === WP_DEBUG ); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + /** |
|
| 313 | + * Deprecated. Determines if theme is parent. |
|
| 314 | + * |
|
| 315 | + * @param string $file Path to file. |
|
| 316 | + * |
|
| 317 | + * @return bool |
|
| 318 | + * @deprecated No longer using camelCase naming convention. |
|
| 319 | + */ |
|
| 320 | + public static function isParentTheme( string $file ): bool { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 321 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0.0', 'Redux_Instances::is_parent_theme( $file )' ); |
|
| 322 | + |
|
| 323 | + return self::is_parent_theme( $file ); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Determines if theme is parent. |
|
| 328 | + * |
|
| 329 | + * @param string $file Path to theme dir. |
|
| 330 | + * |
|
| 331 | + * @return bool |
|
| 332 | + */ |
|
| 333 | + public static function is_parent_theme( string $file ): bool { |
|
| 334 | + $file = Redux_Functions_Ex::wp_normalize_path( $file ); |
|
| 335 | + $dir = Redux_Functions_Ex::wp_normalize_path( get_template_directory() ); |
|
| 336 | + |
|
| 337 | + $file = str_replace( '//', '/', $file ); |
|
| 338 | + $dir = str_replace( '//', '/', $dir ); |
|
| 339 | + |
|
| 340 | + if ( strpos( $file, $dir ) !== false ) { |
|
| 341 | + return true; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + return false; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + /** |
|
| 348 | + * Deprecated. Moved to another class. |
|
| 349 | + * |
|
| 350 | + * @param string $file Path to file. |
|
| 351 | + * |
|
| 352 | + * @return string |
|
| 353 | + * @deprecated Moved to another class. |
|
| 354 | + */ |
|
| 355 | + public static function wp_normalize_path( string $file ): string { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 356 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0.0', 'Redux_Functions_Ex::wp_normalize_path( $file )' ); |
|
| 357 | + |
|
| 358 | + return Redux_Functions_Ex::wp_normalize_path( $file ); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * Deprecated. Determines if the theme is child. |
|
| 363 | + * |
|
| 364 | + * @param string $file Path to file. |
|
| 365 | + * |
|
| 366 | + * @return bool |
|
| 367 | + * @deprecated No longer using camelCase naming convention. |
|
| 368 | + */ |
|
| 369 | + public static function isChildTheme( string $file ): bool { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 370 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0.0', 'Redux_Instances::is_child_theme( $file )' ); |
|
| 371 | + |
|
| 372 | + return self::is_child_theme( $file ); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Determines if the theme is child. |
|
| 377 | + * |
|
| 378 | + * @param string $file Path to theme dir. |
|
| 379 | + * |
|
| 380 | + * @return bool |
|
| 381 | + */ |
|
| 382 | + public static function is_child_theme( string $file ): bool { |
|
| 383 | + $file = Redux_Functions_Ex::wp_normalize_path( $file ); |
|
| 384 | + $dir = Redux_Functions_Ex::wp_normalize_path( get_stylesheet_directory() ); |
|
| 385 | + |
|
| 386 | + $file = str_replace( '//', '/', $file ); |
|
| 387 | + $dir = str_replace( '//', '/', $dir ); |
|
| 388 | + |
|
| 389 | + if ( strpos( $file, $dir ) !== false ) { |
|
| 390 | + return true; |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + return false; |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + /** |
|
| 397 | + * Deprecated. Determines if file is a theme. |
|
| 398 | + * |
|
| 399 | + * @param string $file Path to file. |
|
| 400 | + * |
|
| 401 | + * @return bool |
|
| 402 | + * @deprecated No longer using camelCase naming convention. |
|
| 403 | + */ |
|
| 404 | + public static function isTheme( string $file ): bool { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 405 | + // phpcs:ignore Squiz.PHP.CommentedOutCode |
|
| 406 | + // _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0.0', 'Redux_Instances::is_theme( $file )' ); |
|
| 407 | + |
|
| 408 | + return self::is_theme( $file ); |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Determines if file is a theme. |
|
| 413 | + * |
|
| 414 | + * @param string $file Path to fle to test. |
|
| 415 | + * |
|
| 416 | + * @return bool |
|
| 417 | + */ |
|
| 418 | + public static function is_theme( string $file ): bool { |
|
| 419 | + if ( true === self::is_child_theme( $file ) || true === self::is_parent_theme( $file ) ) { |
|
| 420 | + return true; |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + return false; |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + /** |
|
| 427 | + * Determines deep array status. |
|
| 428 | + * |
|
| 429 | + * @param array|string $needle array to test. |
|
| 430 | + * @param array $haystack Array to search. |
|
| 431 | + * |
|
| 432 | + * @return bool |
|
| 433 | + */ |
|
| 434 | + public static function array_in_array( $needle, array $haystack ): bool { |
|
| 435 | + // Make sure $needle is an array for foreach. |
|
| 436 | + if ( ! is_array( $needle ) ) { |
|
| 437 | + $needle = array( $needle ); |
|
| 438 | + } |
|
| 439 | + // For each value in $needle, return TRUE if in $haystack. |
|
| 440 | + foreach ( $needle as $pin ) { |
|
| 441 | + if ( in_array( $pin, $haystack, true ) ) { |
|
| 442 | + return true; |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + // Return FALSE if none of the values from $needle are found in $haystack. |
|
| 447 | + return false; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * Enum through an entire deep array. |
|
| 452 | + * |
|
| 453 | + * @param string|array $needle String to search for. |
|
| 454 | + * @param array $haystack Array in which to search. |
|
| 455 | + * |
|
| 456 | + * @return bool |
|
| 457 | + */ |
|
| 458 | + public static function recursive_array_search( $needle, array $haystack ): bool { |
|
| 459 | + foreach ( $haystack as $value ) { |
|
| 460 | + if ( $needle === $value || ( is_array( $value ) && self::recursive_array_search( $needle, $value ) !== false ) ) { |
|
| 461 | + return true; |
|
| 462 | + } |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + return false; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + /** |
|
| 469 | + * Take a path and return it clean. |
|
| 470 | + * |
|
| 471 | + * @param string $path Path to clean. |
|
| 472 | + * |
|
| 473 | + * @return string |
|
| 474 | + * @deprecated Replaced with wp_normalize_path. |
|
| 475 | + * @since 3.1.7 |
|
| 476 | + */ |
|
| 477 | + public static function cleanFilePath( string $path ): string { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 478 | + // phpcs:ignore Squiz.PHP.CommentedOutCode |
|
| 479 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0', 'Redux_Functions_Ex::wp_normalize_path( $path )' ); |
|
| 480 | + return Redux_Functions_Ex::wp_normalize_path( $path ); |
|
| 481 | + } |
|
| 482 | + |
|
| 483 | + /** |
|
| 484 | + * Get info for specified file. |
|
| 485 | + * |
|
| 486 | + * @param string $file File to check. |
|
| 487 | + * |
|
| 488 | + * @return array|bool |
|
| 489 | + */ |
|
| 490 | + public static function path_info( string $file ) { |
|
| 491 | + $theme_info = Redux_Functions_Ex::is_inside_theme( $file ); |
|
| 492 | + $plugin_info = Redux_Functions_Ex::is_inside_plugin( $file ); |
|
| 493 | + |
|
| 494 | + if ( false !== $theme_info ) { |
|
| 495 | + return $theme_info; |
|
| 496 | + } elseif ( false !== $plugin_info ) { |
|
| 497 | + return $plugin_info; |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + return array(); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * Compiles caller data for Redux. |
|
| 505 | + * |
|
| 506 | + * @param bool $simple Mode. |
|
| 507 | + * |
|
| 508 | + * @return array |
|
| 509 | + */ |
|
| 510 | + public static function process_redux_callers( bool $simple = false ): array { |
|
| 511 | + $data = array(); |
|
| 512 | + |
|
| 513 | + foreach ( Redux_Core::$callers as $opt_name => $callers ) { |
|
| 514 | + foreach ( $callers as $caller ) { |
|
| 515 | + $plugin_info = self::is_inside_plugin( $caller ); |
|
| 516 | + $theme_info = self::is_inside_theme( $caller ); |
|
| 517 | + |
|
| 518 | + if ( $theme_info ) { |
|
| 519 | + if ( ! isset( $data['theme'][ $theme_info['slug'] ] ) ) { |
|
| 520 | + $data['theme'][ $theme_info['slug'] ] = array(); |
|
| 521 | + } |
|
| 522 | + if ( ! isset( $data['theme'][ $theme_info['slug'] ][ $opt_name ] ) ) { |
|
| 523 | + $data['theme'][ $theme_info['slug'] ][ $opt_name ] = array(); |
|
| 524 | + } |
|
| 525 | + if ( $simple ) { |
|
| 526 | + $data['theme'][ $theme_info['slug'] ][ $opt_name ][] = $theme_info['basename']; |
|
| 527 | + } else { |
|
| 528 | + $data['theme'][ $theme_info['slug'] ][ $opt_name ][] = $theme_info; |
|
| 529 | + } |
|
| 530 | + } elseif ( $plugin_info ) { |
|
| 531 | + if ( ! isset( $data['plugin'][ $plugin_info['slug'] ] ) ) { |
|
| 532 | + $data['plugin'][ $plugin_info['slug'] ] = array(); |
|
| 533 | + } |
|
| 534 | + if ( ! in_array( $opt_name, $data['plugin'][ $plugin_info['slug'] ], true ) ) { |
|
| 535 | + if ( ! isset( $data['plugin'][ $plugin_info['slug'] ][ $opt_name ] ) ) { |
|
| 536 | + $data['plugin'][ $plugin_info['slug'] ][ $opt_name ] = array(); |
|
| 537 | + } |
|
| 538 | + if ( $simple ) { |
|
| 539 | + $data['plugin'][ $plugin_info['slug'] ][ $opt_name ][] = $plugin_info['basename']; |
|
| 540 | + } else { |
|
| 541 | + $data['plugin'][ $plugin_info['slug'] ][ $opt_name ][] = $plugin_info; |
|
| 542 | + } |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + return $data; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + /** |
|
| 552 | + * Field Render Function. |
|
| 553 | + * Takes the color hex value and converts to a rgba. |
|
| 554 | + * |
|
| 555 | + * @param string $hex Color value. |
|
| 556 | + * @param string $alpha Alpha value. |
|
| 557 | + * |
|
| 558 | + * @since ReduxFramework 3.0.4 |
|
| 559 | + */ |
|
| 560 | + public static function hex2rgba( string $hex, string $alpha = '' ): string { |
|
| 561 | + $hex = ltrim( $hex, '#' ); |
|
| 562 | + $hex = sanitize_hex_color_no_hash( $hex ); |
|
| 563 | + |
|
| 564 | + if ( '' === $hex ) { |
|
| 565 | + return ''; |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + if ( 3 === strlen( $hex ) ) { |
|
| 569 | + $r = hexdec( substr( $hex, 0, 1 ) . substr( $hex, 0, 1 ) ); |
|
| 570 | + $g = hexdec( substr( $hex, 1, 1 ) . substr( $hex, 1, 1 ) ); |
|
| 571 | + $b = hexdec( substr( $hex, 2, 1 ) . substr( $hex, 2, 1 ) ); |
|
| 572 | + } else { |
|
| 573 | + $r = hexdec( substr( $hex, 0, 2 ) ); |
|
| 574 | + $g = hexdec( substr( $hex, 2, 2 ) ); |
|
| 575 | + $b = hexdec( substr( $hex, 4, 2 ) ); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + $rgb = $r . ',' . $g . ',' . $b; |
|
| 579 | + |
|
| 580 | + if ( '' === $alpha ) { |
|
| 581 | + return $rgb; |
|
| 582 | + } else { |
|
| 583 | + $alpha = floatval( $alpha ); |
|
| 584 | + |
|
| 585 | + return 'rgba(' . $rgb . ',' . $alpha . ')'; |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + /** |
|
| 590 | + * Deprecated. Returns string boolean value. |
|
| 591 | + * |
|
| 592 | + * @param mixed $variable String to convert to true boolean. |
|
| 593 | + * |
|
| 594 | + * @return mixed|array |
|
| 595 | + * |
|
| 596 | + * @deprecated No longer using camelCase naming convention. |
|
| 597 | + */ |
|
| 598 | + public static function makeBoolStr( $variable ) { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 599 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0.0', 'Redux_Instances::make_bool_str( $var )' ); |
|
| 600 | + |
|
| 601 | + return self::make_bool_str( $variable ); |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + /** |
|
| 605 | + * Returns string boolean value. |
|
| 606 | + * |
|
| 607 | + * @param mixed $variable true|false to convert. |
|
| 608 | + * |
|
| 609 | + * @return mixed|array |
|
| 610 | + */ |
|
| 611 | + public static function make_bool_str( $variable ) { |
|
| 612 | + if ( 'false' === $variable || empty( $variable ) ) { |
|
| 613 | + return 'false'; |
|
| 614 | + } elseif ( true === $variable || 'true' === $variable || 1 === $variable || '1' === $variable ) { |
|
| 615 | + return 'true'; |
|
| 616 | + } else { |
|
| 617 | + return $variable; |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + /** |
|
| 622 | + * Compile a localized array. |
|
| 623 | + * |
|
| 624 | + * @param array $localize Array of localized strings. |
|
| 625 | + * |
|
| 626 | + * @return array |
|
| 627 | + */ |
|
| 628 | + public static function localize( array $localize ): array { |
|
| 629 | + |
|
| 630 | + return $localize; |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * Check mokama. |
|
| 635 | + * |
|
| 636 | + * @access public |
|
| 637 | + * @since 4.0.0 |
|
| 638 | + * @return bool |
|
| 639 | + */ |
|
| 640 | + public static function mokama(): bool { |
|
| 641 | + if ( defined( 'RDX_MOKAMA' ) ) { |
|
| 642 | + return Redux_Functions_Ex::s(); |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + return false; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + /** |
|
| 649 | + * Retrieves template version. |
|
| 650 | + * |
|
| 651 | + * @param string $file Path to template file. |
|
| 652 | + * |
|
| 653 | + * @return string |
|
| 654 | + */ |
|
| 655 | + public static function get_template_version( string $file ): string { |
|
| 656 | + $filesystem = Redux_Filesystem::get_instance(); |
|
| 657 | + // Avoid notices if file does not exist. |
|
| 658 | + if ( ! file_exists( $file ) ) { |
|
| 659 | + return ''; |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + $data = get_file_data( $file, array( 'version' ), 'plugin' ); |
|
| 663 | + |
|
| 664 | + if ( ! empty( $data[0] ) ) { |
|
| 665 | + return $data[0]; |
|
| 666 | + } else { |
|
| 667 | + $file_data = $filesystem->get_contents( $file ); |
|
| 668 | + |
|
| 669 | + $file_data = str_replace( "\r", "\n", $file_data ); |
|
| 670 | + $version = '1.0.0'; |
|
| 671 | + |
|
| 672 | + if ( preg_match( '/^[ \t\/*#@]*' . preg_quote( '@version', '/' ) . '(.*)$/mi', $file_data, $match ) && $match[1] ) { |
|
| 673 | + $version = _cleanup_header_comment( $match[1] ); |
|
| 674 | + } |
|
| 675 | + |
|
| 676 | + return $version; |
|
| 677 | + } |
|
| 678 | + } |
|
| 679 | + |
|
| 680 | + /** |
|
| 681 | + * Create HTML attribute string. |
|
| 682 | + * |
|
| 683 | + * @param array $attributes Array of attributes. |
|
| 684 | + */ |
|
| 685 | + public static function html_attributes( array $attributes = array() ): string { |
|
| 686 | + return join( |
|
| 687 | + ' ', |
|
| 688 | + array_map( |
|
| 689 | + function ( $key ) use ( $attributes ) { |
|
| 690 | + if ( is_bool( $attributes[ $key ] ) ) { |
|
| 691 | + return $attributes[ $key ] ? $key : ''; |
|
| 692 | + } |
|
| 693 | + |
|
| 694 | + return $key . '="' . $attributes[ $key ] . '"'; |
|
| 695 | + }, |
|
| 696 | + array_keys( $attributes ) |
|
| 697 | + ) |
|
| 698 | + ) . ' '; |
|
| 699 | + } |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * Normalize extensions dir. |
|
| 703 | + * |
|
| 704 | + * @param string $dir Path to extensions. |
|
| 705 | + * |
|
| 706 | + * @return string |
|
| 707 | + */ |
|
| 708 | + public static function get_extension_dir( string $dir ): string { |
|
| 709 | + return trailingslashit( Redux_Functions_Ex::wp_normalize_path( dirname( $dir ) ) ); |
|
| 710 | + } |
|
| 711 | + |
|
| 712 | + /** |
|
| 713 | + * Normalize extensions URL. |
|
| 714 | + * |
|
| 715 | + * @param string $dir Path to extensions. |
|
| 716 | + * |
|
| 717 | + * @return array|string|string[] |
|
| 718 | + */ |
|
| 719 | + public static function get_extension_url( string $dir ) { |
|
| 720 | + $ext_dir = self::get_extension_dir( $dir ); |
|
| 721 | + |
|
| 722 | + return str_replace( Redux_Functions_Ex::wp_normalize_path( WP_CONTENT_DIR ), WP_CONTENT_URL, $ext_dir ); |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + /** |
|
| 726 | + * Checks a nested capabilities array or string to determine if the current user meets the requirements. |
|
| 727 | + * |
|
| 728 | + * @param string|array $caps Permission string or array to check. See self::user_can() for details. |
|
| 729 | + * |
|
| 730 | + * @return bool Whether the user meets the requirements. False on invalid user. |
|
| 731 | + * @since 3.6.3.4 |
|
| 732 | + */ |
|
| 733 | + public static function current_user_can( $caps ): bool { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found |
|
| 734 | + $current_user = wp_get_current_user(); |
|
| 735 | + |
|
| 736 | + if ( empty( $current_user ) ) { |
|
| 737 | + return false; |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + $name_arr = func_get_args(); |
|
| 741 | + $args = array_merge( array( $current_user ), $name_arr ); |
|
| 742 | + |
|
| 743 | + return call_user_func_array( array( __CLASS__, 'user_can' ), $args ); |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * Checks a nested capabilities array or string to determine if the user meets the requirements. |
|
| 748 | + * You can pass in a simple string like 'edit_posts' or an array of conditions. |
|
| 749 | + * The capability 'relation' is reserved for controlling the relation mode (AND/OR), which defaults to AND. |
|
| 750 | + * Max depth of 30 levels. False is returned for any conditions exceeding max depth. |
|
| 751 | + * If you want to check meta caps, you must also pass the object ID on which to check against. |
|
| 752 | + * If you get the error: PHP Notice: Undefined offset: 0 in /wp-includes/capabilities.php, you didn't |
|
| 753 | + * pass the required $object_id. |
|
| 754 | + * |
|
| 755 | + * @param int|WP_User $user User ID or WP_User object to check. Defaults to the current user. |
|
| 756 | + * @param string|array $capabilities Capability string or array to check. The array lets you use multiple |
|
| 757 | + * conditions to determine if a user has permission. |
|
| 758 | + * Invalid conditions are skipped (conditions which aren't a string/array/bool/number(cast to bool)). |
|
| 759 | + * Example array where the user needs to have either the 'edit_posts' capability OR doesn't have the |
|
| 760 | + * 'delete_pages' cap OR has the 'update_plugins' AND 'add_users' capabilities. |
|
| 761 | + * array( |
|
| 762 | + * 'relation' => 'OR', // Optional, defaults to AND. |
|
| 763 | + * 'edit_posts', // Equivalent to 'edit_posts' => true, |
|
| 764 | + * 'delete_pages' => false, // Tests that the user DOESN'T have this capability |
|
| 765 | + * array( // Nested conditions array (up to 30 nestings) |
|
| 766 | + * 'update_plugins', |
|
| 767 | + * 'add_users', |
|
| 768 | + * ), |
|
| 769 | + * ). |
|
| 770 | + * @param int|null $object_id (Optional) ID of the specific object to check against if capability is a "meta" cap. |
|
| 771 | + * e.g. 'edit_post', 'edit_user', 'edit_page', etc. |
|
| 772 | + * |
|
| 773 | + * @return bool Whether the user meets the requirements. |
|
| 774 | + * Will always return false for: |
|
| 775 | + * - Invalid/missing user |
|
| 776 | + * - If the $capabilities is not a string or array |
|
| 777 | + * - Max nesting depth exceeded (for that level) |
|
| 778 | + * @since 3.6.3.4 |
|
| 779 | + * @example |
|
| 780 | + * user_can( 42, 'edit_pages' ); // Checks if user ID 42 has the 'edit_pages' cap. |
|
| 781 | + * user_can( 42, 'edit_page', 17433 ); // Checks if user ID 42 has the 'edit_page' cap for post-ID 17433. |
|
| 782 | + * user_can( 42, array( 'edit_pages', 'edit_posts' ) ); // Checks if user ID 42 has both the 'edit_pages' and 'edit_posts' caps. |
|
| 783 | + */ |
|
| 784 | + public static function user_can( $user, $capabilities, ?int $object_id = null ): bool { |
|
| 785 | + static $depth = 0; |
|
| 786 | + |
|
| 787 | + if ( $depth >= 30 ) { |
|
| 788 | + return false; |
|
| 789 | + } |
|
| 790 | + |
|
| 791 | + if ( empty( $user ) ) { |
|
| 792 | + return false; |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + if ( ! is_object( $user ) ) { |
|
| 796 | + $user = get_userdata( $user ); |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + if ( is_string( $capabilities ) ) { |
|
| 800 | + // Simple string capability check. |
|
| 801 | + $args = array( $user, $capabilities ); |
|
| 802 | + |
|
| 803 | + if ( null !== $object_id ) { |
|
| 804 | + $args[] = $object_id; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + return call_user_func_array( 'user_can', $args ); |
|
| 808 | + } elseif ( ! is_array( $capabilities ) ) { |
|
| 809 | + // Only strings and arrays are allowed as valid capabilities. |
|
| 810 | + return false; |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + // Capability array check. |
|
| 814 | + $or = false; |
|
| 815 | + |
|
| 816 | + foreach ( $capabilities as $key => $value ) { |
|
| 817 | + if ( 'relation' === $key ) { |
|
| 818 | + if ( 'OR' === $value ) { |
|
| 819 | + $or = true; |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + continue; |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + /** |
|
| 826 | + * Rules can be in 4 different formats: |
|
| 827 | + * [ |
|
| 828 | + * [0] => 'foobar', |
|
| 829 | + * [1] => array(...), |
|
| 830 | + * 'foobar' => false, |
|
| 831 | + * 'foobar' => array(...), |
|
| 832 | + * ] |
|
| 833 | + */ |
|
| 834 | + if ( is_numeric( $key ) ) { |
|
| 835 | + // Numeric key. |
|
| 836 | + if ( is_string( $value ) ) { |
|
| 837 | + // Numeric key with a string value is the capability string to check |
|
| 838 | + // [0] => 'foobar'. |
|
| 839 | + $args = array( $user, $value ); |
|
| 840 | + |
|
| 841 | + if ( null !== $object_id ) { |
|
| 842 | + $args[] = $object_id; |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + $expression_result = call_user_func_array( 'user_can', $args ) === true; |
|
| 846 | + } elseif ( is_array( $value ) ) { |
|
| 847 | + ++$depth; |
|
| 848 | + |
|
| 849 | + $expression_result = self::user_can( $user, $value, $object_id ); |
|
| 850 | + |
|
| 851 | + --$depth; |
|
| 852 | + } else { |
|
| 853 | + // Invalid types are skipped. |
|
| 854 | + continue; |
|
| 855 | + } |
|
| 856 | + } else { |
|
| 857 | + // Non-numeric key. |
|
| 858 | + if ( is_scalar( $value ) ) { |
|
| 859 | + $args = array( $user, $key ); |
|
| 860 | + |
|
| 861 | + if ( null !== $object_id ) { |
|
| 862 | + $args[] = $object_id; |
|
| 863 | + } |
|
| 864 | + |
|
| 865 | + $expression_result = call_user_func_array( 'user_can', $args ) === (bool) $value; |
|
| 866 | + } elseif ( is_array( $value ) ) { |
|
| 867 | + ++$depth; |
|
| 868 | + |
|
| 869 | + $expression_result = self::user_can( $user, $value, $object_id ); |
|
| 870 | + |
|
| 871 | + --$depth; |
|
| 872 | + } else { |
|
| 873 | + // Invalid types are skipped. |
|
| 874 | + continue; |
|
| 875 | + } |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + // Check after every evaluation if we know enough to return a definitive answer. |
|
| 879 | + if ( $or ) { |
|
| 880 | + if ( $expression_result ) { |
|
| 881 | + // If the relation is OR, return on the first true expression. |
|
| 882 | + return true; |
|
| 883 | + } |
|
| 884 | + } elseif ( ! $expression_result ) { |
|
| 885 | + // If the relation is AND, return on the first false expression. |
|
| 886 | + return false; |
|
| 887 | + } |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + // If we get this far on an OR, then it failed. |
|
| 891 | + // If we get this far on an AND, then it succeeded. |
|
| 892 | + return ! $or; |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + /** |
|
| 896 | + * Check if Google font update is needed. |
|
| 897 | + * |
|
| 898 | + * @return bool |
|
| 899 | + */ |
|
| 900 | + public static function google_fonts_update_needed(): bool { |
|
| 901 | + $path = trailingslashit( Redux_Core::$upload_dir ) . 'google_fonts.json'; |
|
| 902 | + $now = time(); |
|
| 903 | + $secs = 60 * 60 * 24 * 7; |
|
| 904 | + |
|
| 905 | + if ( file_exists( $path ) ) { |
|
| 906 | + if ( ( $now - filemtime( $path ) ) < $secs ) { |
|
| 907 | + return false; |
|
| 908 | + } |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + return true; |
|
| 912 | + } |
|
| 913 | + |
|
| 914 | + /** |
|
| 915 | + * Retrieve an updated Google font array. |
|
| 916 | + * |
|
| 917 | + * @param bool $download Flag to download to file. |
|
| 918 | + * |
|
| 919 | + * @return array|WP_Error |
|
| 920 | + */ |
|
| 921 | + public static function google_fonts_array( bool $download = false ) { |
|
| 922 | + if ( ! empty( Redux_Core::$updated_google_fonts ) && ! self::google_fonts_update_needed() ) { |
|
| 923 | + return Redux_Core::$updated_google_fonts; |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + $filesystem = Redux_Filesystem::get_instance(); |
|
| 927 | + |
|
| 928 | + $path = trailingslashit( Redux_Core::$upload_dir ) . 'google_fonts.json'; |
|
| 929 | + |
|
| 930 | + if ( ! file_exists( $path ) || ( file_exists( $path ) && $download && self::google_fonts_update_needed() ) ) { |
|
| 931 | + if ( $download ) { |
|
| 932 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 933 | + $url = apply_filters( 'redux/typography/google_fonts/url', 'https://raw.githubusercontent.com/reduxframework/google-fonts/master/google_fonts.json' ); |
|
| 934 | + |
|
| 935 | + $request = wp_remote_get( |
|
| 936 | + $url, |
|
| 937 | + array( |
|
| 938 | + 'timeout' => 20, |
|
| 939 | + ) |
|
| 940 | + ); |
|
| 941 | + |
|
| 942 | + if ( ! is_wp_error( $request ) ) { |
|
| 943 | + $body = wp_remote_retrieve_body( $request ); |
|
| 944 | + if ( ! empty( $body ) ) { |
|
| 945 | + $filesystem->put_contents( $path, $body ); |
|
| 946 | + Redux_Core::$updated_google_fonts = json_decode( $body, true ); |
|
| 947 | + } |
|
| 948 | + } else { |
|
| 949 | + return $request; |
|
| 950 | + } |
|
| 951 | + } |
|
| 952 | + } elseif ( file_exists( $path ) ) { |
|
| 953 | + Redux_Core::$updated_google_fonts = json_decode( $filesystem->get_contents( $path ), true ); |
|
| 954 | + if ( empty( Redux_Core::$updated_google_fonts ) ) { |
|
| 955 | + $filesystem->unlink( $path ); |
|
| 956 | + } |
|
| 957 | + } |
|
| 958 | + |
|
| 959 | + return Redux_Core::$updated_google_fonts; |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + /** |
|
| 963 | + * Deprecated. Gets all Redux instances |
|
| 964 | + * |
|
| 965 | + * @return array |
|
| 966 | + * @deprecated No longer using camelCase naming convention and moved to a different class. |
|
| 967 | + */ |
|
| 968 | + public static function getReduxInstances(): array { // phpcs:ignore WordPress.NamingConventions.ValidFunctionName |
|
| 969 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.0.0', 'Redux_Instances::get_all_instances()' ); |
|
| 970 | + |
|
| 971 | + return Redux_Instances::get_all_instances(); |
|
| 972 | + } |
|
| 973 | + |
|
| 974 | + /** |
|
| 975 | + * Is Inside Plugin |
|
| 976 | + * |
|
| 977 | + * @param string $file File name. |
|
| 978 | + * |
|
| 979 | + * @return array|bool |
|
| 980 | + */ |
|
| 981 | + public static function is_inside_plugin( string $file ) { |
|
| 982 | + |
|
| 983 | + // phpcs:ignore Squiz.PHP.CommentedOutCode |
|
| 984 | + // if ( substr( strtoupper( $file ), 0, 2 ) === 'C:' ) { |
|
| 985 | + // $file = ltrim( $file, 'C:' ); |
|
| 986 | + // $file = ltrim( $file, 'c:' ); |
|
| 987 | + // } . |
|
| 988 | + // |
|
| 989 | + $plugin_basename = plugin_basename( $file ); |
|
| 990 | + |
|
| 991 | + if ( Redux_Functions_Ex::wp_normalize_path( $file ) !== '/' . $plugin_basename ) { |
|
| 992 | + $slug = explode( '/', $plugin_basename ); |
|
| 993 | + $slug = $slug[0]; |
|
| 994 | + |
|
| 995 | + return array( |
|
| 996 | + 'slug' => $slug, |
|
| 997 | + 'basename' => $plugin_basename, |
|
| 998 | + 'path' => Redux_Functions_Ex::wp_normalize_path( $file ), |
|
| 999 | + 'url' => plugins_url( $plugin_basename ), |
|
| 1000 | + 'real_path' => Redux_Functions_Ex::wp_normalize_path( dirname( realpath( $file ) ) ), |
|
| 1001 | + ); |
|
| 1002 | + } |
|
| 1003 | + |
|
| 1004 | + return false; |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + /** |
|
| 1008 | + * Is inside theme. |
|
| 1009 | + * |
|
| 1010 | + * @param string $file File name. |
|
| 1011 | + * |
|
| 1012 | + * @return array|bool |
|
| 1013 | + */ |
|
| 1014 | + public static function is_inside_theme( string $file = '' ) { |
|
| 1015 | + $theme_paths = array( |
|
| 1016 | + Redux_Functions_Ex::wp_normalize_path( get_template_directory() ) => get_template_directory_uri(), |
|
| 1017 | + Redux_Functions_Ex::wp_normalize_path( get_stylesheet_directory() ) => get_stylesheet_directory_uri(), |
|
| 1018 | + ); |
|
| 1019 | + |
|
| 1020 | + $theme_paths = array_unique( $theme_paths ); |
|
| 1021 | + |
|
| 1022 | + $file_path = Redux_Functions_Ex::wp_normalize_path( $file ); |
|
| 1023 | + $filename = explode( '/', $file_path ); |
|
| 1024 | + $filename = end( $filename ); |
|
| 1025 | + foreach ( $theme_paths as $theme_path => $url ) { |
|
| 1026 | + |
|
| 1027 | + $real_path = Redux_Functions_Ex::wp_normalize_path( realpath( $theme_path ) ); |
|
| 1028 | + |
|
| 1029 | + if ( strpos( $file_path, trailingslashit( $real_path ) ) !== false ) { |
|
| 1030 | + $slug = explode( '/', Redux_Functions_Ex::wp_normalize_path( $theme_path ) ); |
|
| 1031 | + if ( empty( $slug ) ) { |
|
| 1032 | + continue; |
|
| 1033 | + } |
|
| 1034 | + $slug = end( $slug ); |
|
| 1035 | + $relative_path = explode( $slug, dirname( $file_path ) ); |
|
| 1036 | + |
|
| 1037 | + if ( 1 === count( $relative_path ) ) { |
|
| 1038 | + $relative_path = $file_path; |
|
| 1039 | + } else { |
|
| 1040 | + $relative_path = $relative_path[1]; |
|
| 1041 | + } |
|
| 1042 | + $relative_path = ltrim( $relative_path, '/' ); |
|
| 1043 | + |
|
| 1044 | + $data = array( |
|
| 1045 | + 'slug' => $slug, |
|
| 1046 | + 'path' => trailingslashit( trailingslashit( $theme_path ) . $relative_path ) . $filename, |
|
| 1047 | + 'real_path' => trailingslashit( trailingslashit( $real_path ) . $relative_path ) . $filename, |
|
| 1048 | + 'url' => trailingslashit( trailingslashit( $url ) . $relative_path ) . $filename, |
|
| 1049 | + ); |
|
| 1050 | + |
|
| 1051 | + $basename = explode( $data['slug'], $data['path'] ); |
|
| 1052 | + $basename = end( $basename ); |
|
| 1053 | + $basename = ltrim( $basename, '/' ); |
|
| 1054 | + $data['basename'] = trailingslashit( $data['slug'] ) . $basename; |
|
| 1055 | + |
|
| 1056 | + if ( is_child_theme() ) { |
|
| 1057 | + $parent = get_template_directory(); |
|
| 1058 | + $data['parent_slug'] = explode( '/', $parent ); |
|
| 1059 | + $data['parent_slug'] = end( $data['parent_slug'] ); |
|
| 1060 | + if ( $data['slug'] === $data['parent_slug'] ) { |
|
| 1061 | + unset( $data['parent_slug'] ); |
|
| 1062 | + } |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + return $data; |
|
| 1066 | + } |
|
| 1067 | + } |
|
| 1068 | + |
|
| 1069 | + return false; |
|
| 1070 | + } |
|
| 1071 | + |
|
| 1072 | + |
|
| 1073 | + /** |
|
| 1074 | + * Get plugin options. |
|
| 1075 | + * |
|
| 1076 | + * @return array|mixed|void |
|
| 1077 | + */ |
|
| 1078 | + public static function get_plugin_options() { |
|
| 1079 | + $defaults = array( |
|
| 1080 | + 'demo' => false, |
|
| 1081 | + ); |
|
| 1082 | + $options = array(); |
|
| 1083 | + |
|
| 1084 | + // If multisite is enabled. |
|
| 1085 | + if ( is_multisite() ) { |
|
| 1086 | + |
|
| 1087 | + // Get network activated plugins. |
|
| 1088 | + $plugins = get_site_option( 'active_sitewide_plugins' ); |
|
| 1089 | + |
|
| 1090 | + foreach ( $plugins as $file => $plugin ) { |
|
| 1091 | + if ( strpos( $file, 'redux-framework.php' ) !== false ) { |
|
| 1092 | + $options = get_site_option( 'ReduxFrameworkPlugin', $defaults ); |
|
| 1093 | + } |
|
| 1094 | + } |
|
| 1095 | + } |
|
| 1096 | + |
|
| 1097 | + // If options aren't set, grab them now! |
|
| 1098 | + if ( empty( $options ) ) { |
|
| 1099 | + $options = get_option( 'ReduxFrameworkPlugin', $defaults ); |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + return $options; |
|
| 1103 | + } |
|
| 1104 | + |
|
| 1105 | + /** |
|
| 1106 | + * Sanitize array keys and values. |
|
| 1107 | + * |
|
| 1108 | + * @param array $arr Array to sanitize. |
|
| 1109 | + */ |
|
| 1110 | + public static function sanitize_array( array $arr ): array { |
|
| 1111 | + return self::array_map_r( 'wp_kses_post', $arr ); |
|
| 1112 | + } |
|
| 1113 | + |
|
| 1114 | + /** |
|
| 1115 | + * Recursive array map. |
|
| 1116 | + * |
|
| 1117 | + * @param string $func function to run. |
|
| 1118 | + * @param array $arr Array to clean. |
|
| 1119 | + * |
|
| 1120 | + * @return array |
|
| 1121 | + */ |
|
| 1122 | + private static function array_map_r( string $func, array $arr ): array { |
|
| 1123 | + $new_arr = array(); |
|
| 1124 | + |
|
| 1125 | + foreach ( $arr as $key => $value ) { |
|
| 1126 | + $new_arr[ $key ] = ( is_array( $value ) ? self::array_map_r( $func, $value ) : ( is_array( $func ) ? call_user_func_array( $func, $value ) : $func( $value ) ) ); |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + return $new_arr; |
|
| 1130 | + } |
|
| 1131 | + |
|
| 1132 | + /** |
|
| 1133 | + * Material design colors. |
|
| 1134 | + * |
|
| 1135 | + * @param string $context Mode to use. |
|
| 1136 | + * |
|
| 1137 | + * @return array |
|
| 1138 | + */ |
|
| 1139 | + public static function get_material_design_colors( string $context = 'primary' ): array { |
|
| 1140 | + $colors = array( |
|
| 1141 | + 'primary' => array( '#FFFFFF', '#000000', '#F44336', '#E91E63', '#9C27B0', '#673AB7', '#3F51B5', '#2196F3', '#03A9F4', '#00BCD4', '#009688', '#4CAF50', '#8BC34A', '#CDDC39', '#FFEB3B', '#FFC107', '#FF9800', '#FF5722', '#795548', '#9E9E9E', '#607D8B' ), |
|
| 1142 | + 'red' => array( '#FFEBEE', '#FFCDD2', '#EF9A9A', '#E57373', '#EF5350', '#F44336', '#E53935', '#D32F2F', '#C62828', '#B71C1C', '#FF8A80', '#FF5252', '#FF1744', '#D50000' ), |
|
| 1143 | + 'pink' => array( '#FCE4EC', '#F8BBD0', '#F48FB1', '#F06292', '#EC407A', '#E91E63', '#D81B60', '#C2185B', '#AD1457', '#880E4F', '#FF80AB', '#FF4081', '#F50057', '#C51162' ), |
|
| 1144 | + 'purple' => array( '#F3E5F5', '#E1BEE7', '#CE93D8', '#BA68C8', '#AB47BC', '#9C27B0', '#8E24AA', '#7B1FA2', '#6A1B9A', '#4A148C', '#EA80FC', '#E040FB', '#D500F9', '#AA00FF' ), |
|
| 1145 | + 'deep-purple' => array( '#EDE7F6', '#D1C4E9', '#B39DDB', '#9575CD', '#7E57C2', '#673AB7', '#5E35B1', '#512DA8', '#4527A0', '#311B92', '#B388FF', '#7C4DFF', '#651FFF', '#6200EA' ), |
|
| 1146 | + 'indigo' => array( '#E8EAF6', '#C5CAE9', '#9FA8DA', '#7986CB', '#5C6BC0', '#3F51B5', '#3949AB', '#303F9F', '#283593', '#1A237E', '#8C9EFF', '#536DFE', '#3D5AFE', '#304FFE' ), |
|
| 1147 | + 'blue' => array( '#E3F2FD', '#BBDEFB', '#90CAF9', '#64B5F6', '#42A5F5', '#2196F3', '#1E88E5', '#1976D2', '#1565C0', '#0D47A1', '#82B1FF', '#448AFF', '#2979FF', '#2962FF' ), |
|
| 1148 | + 'light-blue' => array( '#E1F5FE', '#B3E5FC', '#81D4fA', '#4fC3F7', '#29B6FC', '#03A9F4', '#039BE5', '#0288D1', '#0277BD', '#01579B', '#80D8FF', '#40C4FF', '#00B0FF', '#0091EA' ), |
|
| 1149 | + 'cyan' => array( '#E0F7FA', '#B2EBF2', '#80DEEA', '#4DD0E1', '#26C6DA', '#00BCD4', '#00ACC1', '#0097A7', '#00838F', '#006064', '#84FFFF', '#18FFFF', '#00E5FF', '#00B8D4' ), |
|
| 1150 | + 'teal' => array( '#E0F2F1', '#B2DFDB', '#80CBC4', '#4DB6AC', '#26A69A', '#009688', '#00897B', '#00796B', '#00695C', '#004D40', '#A7FFEB', '#64FFDA', '#1DE9B6', '#00BFA5' ), |
|
| 1151 | + 'green' => array( '#E8F5E9', '#C8E6C9', '#A5D6A7', '#81C784', '#66BB6A', '#4CAF50', '#43A047', '#388E3C', '#2E7D32', '#1B5E20', '#B9F6CA', '#69F0AE', '#00E676', '#00C853' ), |
|
| 1152 | + 'light-green' => array( '#F1F8E9', '#DCEDC8', '#C5E1A5', '#AED581', '#9CCC65', '#8BC34A', '#7CB342', '#689F38', '#558B2F', '#33691E', '#CCFF90', '#B2FF59', '#76FF03', '#64DD17' ), |
|
| 1153 | + 'lime' => array( '#F9FBE7', '#F0F4C3', '#E6EE9C', '#DCE775', '#D4E157', '#CDDC39', '#C0CA33', '#A4B42B', '#9E9D24', '#827717', '#F4FF81', '#EEFF41', '#C6FF00', '#AEEA00' ), |
|
| 1154 | + 'yellow' => array( '#FFFDE7', '#FFF9C4', '#FFF590', '#FFF176', '#FFEE58', '#FFEB3B', '#FDD835', '#FBC02D', '#F9A825', '#F57F17', '#FFFF82', '#FFFF00', '#FFEA00', '#FFD600' ), |
|
| 1155 | + 'amber' => array( '#FFF8E1', '#FFECB3', '#FFE082', '#FFD54F', '#FFCA28', '#FFC107', '#FFB300', '#FFA000', '#FF8F00', '#FF6F00', '#FFE57F', '#FFD740', '#FFC400', '#FFAB00' ), |
|
| 1156 | + 'orange' => array( '#FFF3E0', '#FFE0B2', '#FFCC80', '#FFB74D', '#FFA726', '#FF9800', '#FB8C00', '#F57C00', '#EF6C00', '#E65100', '#FFD180', '#FFAB40', '#FF9100', '#FF6D00' ), |
|
| 1157 | + 'deep-orange' => array( '#FBE9A7', '#FFCCBC', '#FFAB91', '#FF8A65', '#FF7043', '#FF5722', '#F4511E', '#E64A19', '#D84315', '#BF360C', '#FF9E80', '#FF6E40', '#FF3D00', '#DD2600' ), |
|
| 1158 | + 'brown' => array( '#EFEBE9', '#D7CCC8', '#BCAAA4', '#A1887F', '#8D6E63', '#795548', '#6D4C41', '#5D4037', '#4E342E', '#3E2723' ), |
|
| 1159 | + 'gray' => array( '#FAFAFA', '#F5F5F5', '#EEEEEE', '#E0E0E0', '#BDBDBD', '#9E9E9E', '#757575', '#616161', '#424242', '#212121', '#000000', '#ffffff' ), |
|
| 1160 | + 'blue-gray' => array( '#ECEFF1', '#CFD8DC', '#B0BBC5', '#90A4AE', '#78909C', '#607D8B', '#546E7A', '#455A64', '#37474F', '#263238' ), |
|
| 1161 | + ); |
|
| 1162 | + |
|
| 1163 | + $mui_arr = array( |
|
| 1164 | + '50', |
|
| 1165 | + '100', |
|
| 1166 | + '200', |
|
| 1167 | + '300', |
|
| 1168 | + '400', |
|
| 1169 | + '500', |
|
| 1170 | + '600', |
|
| 1171 | + '700', |
|
| 1172 | + '800', |
|
| 1173 | + '900', |
|
| 1174 | + 'A100', |
|
| 1175 | + 'A200', |
|
| 1176 | + 'A400', |
|
| 1177 | + 'A700', |
|
| 1178 | + ); |
|
| 1179 | + |
|
| 1180 | + if ( in_array( $context, $mui_arr, true ) ) { |
|
| 1181 | + $key = absint( $context ) / 100; |
|
| 1182 | + |
|
| 1183 | + if ( 'A100' === $context ) { |
|
| 1184 | + $key = 10; |
|
| 1185 | + unset( $colors['grey'] ); |
|
| 1186 | + } elseif ( 'A200' === $context ) { |
|
| 1187 | + $key = 11; |
|
| 1188 | + unset( $colors['grey'] ); |
|
| 1189 | + } elseif ( 'A400' === $context ) { |
|
| 1190 | + $key = 12; |
|
| 1191 | + unset( $colors['grey'] ); |
|
| 1192 | + } elseif ( 'A700' === $context ) { |
|
| 1193 | + $key = 13; |
|
| 1194 | + unset( $colors['grey'] ); |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + unset( $colors['primary'] ); |
|
| 1198 | + |
|
| 1199 | + $position_colors = array(); |
|
| 1200 | + foreach ( $colors as $color_family ) { |
|
| 1201 | + if ( isset( $color_family[ $key ] ) ) { |
|
| 1202 | + $position_colors[] = $color_family[ $key ]; |
|
| 1203 | + } |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + return $position_colors; |
|
| 1207 | + } elseif ( 'all' === $context ) { |
|
| 1208 | + unset( $colors['primary'] ); |
|
| 1209 | + |
|
| 1210 | + $all_colors = array(); |
|
| 1211 | + foreach ( $colors as $color_family ) { |
|
| 1212 | + foreach ( $color_family as $color ) { |
|
| 1213 | + $all_colors[] = $color; |
|
| 1214 | + } |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + return $all_colors; |
|
| 1218 | + } elseif ( 'primary' === $context ) { |
|
| 1219 | + return $colors['primary']; |
|
| 1220 | + } else { |
|
| 1221 | + if ( isset( $colors[ $context ] ) ) { |
|
| 1222 | + return $colors[ $context ]; |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + return $colors['primary']; |
|
| 1226 | + } |
|
| 1227 | + } |
|
| 1228 | + } |
|
| 1229 | 1229 | } |
@@ -11,87 +11,87 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Validate', false ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Class Redux_Validate |
|
| 16 | - */ |
|
| 17 | - abstract class Redux_Validate { |
|
| 18 | - /** |
|
| 19 | - * ReduxFramework object. |
|
| 20 | - * |
|
| 21 | - * @var object |
|
| 22 | - */ |
|
| 23 | - public $parent; |
|
| 14 | + /** |
|
| 15 | + * Class Redux_Validate |
|
| 16 | + */ |
|
| 17 | + abstract class Redux_Validate { |
|
| 18 | + /** |
|
| 19 | + * ReduxFramework object. |
|
| 20 | + * |
|
| 21 | + * @var object |
|
| 22 | + */ |
|
| 23 | + public $parent; |
|
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Redux fields array. |
|
| 27 | - * |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - public $field = array(); |
|
| 25 | + /** |
|
| 26 | + * Redux fields array. |
|
| 27 | + * |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + public $field = array(); |
|
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * Redux values array|string. |
|
| 34 | - * |
|
| 35 | - * @var array|string |
|
| 36 | - */ |
|
| 37 | - public $value; |
|
| 32 | + /** |
|
| 33 | + * Redux values array|string. |
|
| 34 | + * |
|
| 35 | + * @var array|string |
|
| 36 | + */ |
|
| 37 | + public $value; |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * Validation current value. |
|
| 41 | - * |
|
| 42 | - * @var mixed |
|
| 43 | - */ |
|
| 44 | - public $current; |
|
| 39 | + /** |
|
| 40 | + * Validation current value. |
|
| 41 | + * |
|
| 42 | + * @var mixed |
|
| 43 | + */ |
|
| 44 | + public $current; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Warning array. |
|
| 48 | - * |
|
| 49 | - * @var array |
|
| 50 | - */ |
|
| 51 | - public $warning = array(); |
|
| 46 | + /** |
|
| 47 | + * Warning array. |
|
| 48 | + * |
|
| 49 | + * @var array |
|
| 50 | + */ |
|
| 51 | + public $warning = array(); |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Error array. |
|
| 55 | - * |
|
| 56 | - * @var array |
|
| 57 | - */ |
|
| 58 | - public $error = array(); |
|
| 53 | + /** |
|
| 54 | + * Error array. |
|
| 55 | + * |
|
| 56 | + * @var array |
|
| 57 | + */ |
|
| 58 | + public $error = array(); |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * Sanitize array. |
|
| 62 | - * |
|
| 63 | - * @var array |
|
| 64 | - */ |
|
| 65 | - public $sanitize = array(); |
|
| 60 | + /** |
|
| 61 | + * Sanitize array. |
|
| 62 | + * |
|
| 63 | + * @var array |
|
| 64 | + */ |
|
| 65 | + public $sanitize = array(); |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * Redux_Validate constructor. |
|
| 69 | - * |
|
| 70 | - * @param object $redux ReduxFramework pointer. |
|
| 71 | - * @param array $field Fields array. |
|
| 72 | - * @param array|string $value Values array. |
|
| 73 | - * @param mixed $current Current. |
|
| 74 | - */ |
|
| 75 | - public function __construct( $redux, array $field, $value, $current ) { |
|
| 76 | - $this->parent = $redux; |
|
| 77 | - $this->field = $field; |
|
| 78 | - $this->value = $value; |
|
| 79 | - $this->current = $current; |
|
| 67 | + /** |
|
| 68 | + * Redux_Validate constructor. |
|
| 69 | + * |
|
| 70 | + * @param object $redux ReduxFramework pointer. |
|
| 71 | + * @param array $field Fields array. |
|
| 72 | + * @param array|string $value Values array. |
|
| 73 | + * @param mixed $current Current. |
|
| 74 | + */ |
|
| 75 | + public function __construct( $redux, array $field, $value, $current ) { |
|
| 76 | + $this->parent = $redux; |
|
| 77 | + $this->field = $field; |
|
| 78 | + $this->value = $value; |
|
| 79 | + $this->current = $current; |
|
| 80 | 80 | |
| 81 | - if ( isset( $this->field['validate_msg'] ) ) { |
|
| 82 | - $this->field['msg'] = $this->field['validate_msg']; |
|
| 81 | + if ( isset( $this->field['validate_msg'] ) ) { |
|
| 82 | + $this->field['msg'] = $this->field['validate_msg']; |
|
| 83 | 83 | |
| 84 | - unset( $this->field['validate_msg'] ); |
|
| 85 | - } |
|
| 84 | + unset( $this->field['validate_msg'] ); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - $this->validate(); |
|
| 88 | - } |
|
| 87 | + $this->validate(); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Validate. |
|
| 92 | - * |
|
| 93 | - * @return mixed |
|
| 94 | - */ |
|
| 95 | - abstract public function validate(); |
|
| 96 | - } |
|
| 90 | + /** |
|
| 91 | + * Validate. |
|
| 92 | + * |
|
| 93 | + * @return mixed |
|
| 94 | + */ |
|
| 95 | + abstract public function validate(); |
|
| 96 | + } |
|
| 97 | 97 | } |
@@ -11,324 +11,324 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Colors', false ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Class Redux_Colors |
|
| 16 | - */ |
|
| 17 | - class Redux_Colors extends Redux_Class { |
|
| 14 | + /** |
|
| 15 | + * Class Redux_Colors |
|
| 16 | + */ |
|
| 17 | + class Redux_Colors extends Redux_Class { |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Sanitizes a HEX value. |
|
| 21 | - * The way this works is by splitting the string in 6 substrings. |
|
| 22 | - * Each sub-string is individually sanitized, and the result is then returned. |
|
| 23 | - * |
|
| 24 | - * @param string $color The hex value of a color. |
|
| 25 | - * @param boolean $hash Whether we want to include a hash (#) at the beginning or not. |
|
| 26 | - * |
|
| 27 | - * @return string The sanitized hex color. |
|
| 28 | - */ |
|
| 29 | - public static function sanitize_hex( string $color = '#FFFFFF', bool $hash = true ): string { |
|
| 30 | - $word_colors = array( |
|
| 31 | - 'aliceblue' => 'F0F8FF', |
|
| 32 | - 'antiquewhite' => 'FAEBD7', |
|
| 33 | - 'aqua' => '00FFFF', |
|
| 34 | - 'aquamarine' => '7FFFD4', |
|
| 35 | - 'azure' => 'F0FFFF', |
|
| 36 | - 'beige' => 'F5F5DC', |
|
| 37 | - 'bisque' => 'FFE4C4', |
|
| 38 | - 'black' => '000000', |
|
| 39 | - 'blanchedalmond' => 'FFEBCD', |
|
| 40 | - 'blue' => '0000FF', |
|
| 41 | - 'blueviolet' => '8A2BE2', |
|
| 42 | - 'brown' => 'A52A2A', |
|
| 43 | - 'burlywood' => 'DEB887', |
|
| 44 | - 'cadetblue' => '5F9EA0', |
|
| 45 | - 'chartreuse' => '7FFF00', |
|
| 46 | - 'chocolate' => 'D2691E', |
|
| 47 | - 'coral' => 'FF7F50', |
|
| 48 | - 'cornflowerblue' => '6495ED', |
|
| 49 | - 'cornsilk' => 'FFF8DC', |
|
| 50 | - 'crimson' => 'DC143C', |
|
| 51 | - 'cyan' => '00FFFF', |
|
| 52 | - 'darkblue' => '00008B', |
|
| 53 | - 'darkcyan' => '008B8B', |
|
| 54 | - 'darkgoldenrod' => 'B8860B', |
|
| 55 | - 'darkgray' => 'A9A9A9', |
|
| 56 | - 'darkgreen' => '006400', |
|
| 57 | - 'darkgrey' => 'A9A9A9', |
|
| 58 | - 'darkkhaki' => 'BDB76B', |
|
| 59 | - 'darkmagenta' => '8B008B', |
|
| 60 | - 'darkolivegreen' => '556B2F', |
|
| 61 | - 'darkorange' => 'FF8C00', |
|
| 62 | - 'darkorchid' => '9932CC', |
|
| 63 | - 'darkred' => '8B0000', |
|
| 64 | - 'darksalmon' => 'E9967A', |
|
| 65 | - 'darkseagreen' => '8FBC8F', |
|
| 66 | - 'darkslateblue' => '483D8B', |
|
| 67 | - 'darkslategray' => '2F4F4F', |
|
| 68 | - 'darkslategrey' => '2F4F4F', |
|
| 69 | - 'darkturquoise' => '00CED1', |
|
| 70 | - 'darkviolet' => '9400D3', |
|
| 71 | - 'deeppink' => 'FF1493', |
|
| 72 | - 'deepskyblue' => '00BFFF', |
|
| 73 | - 'dimgray' => '696969', |
|
| 74 | - 'dimgrey' => '696969', |
|
| 75 | - 'dodgerblue' => '1E90FF', |
|
| 76 | - 'firebrick' => 'B22222', |
|
| 77 | - 'floralwhite' => 'FFFAF0', |
|
| 78 | - 'forestgreen' => '228B22', |
|
| 79 | - 'fuchsia' => 'FF00FF', |
|
| 80 | - 'gainsboro' => 'DCDCDC', |
|
| 81 | - 'ghostwhite' => 'F8F8FF', |
|
| 82 | - 'gold' => 'FFD700', |
|
| 83 | - 'goldenrod' => 'DAA520', |
|
| 84 | - 'gray' => '808080', |
|
| 85 | - 'green' => '008000', |
|
| 86 | - 'greenyellow' => 'ADFF2F', |
|
| 87 | - 'grey' => '808080', |
|
| 88 | - 'honeydew' => 'F0FFF0', |
|
| 89 | - 'hotpink' => 'FF69B4', |
|
| 90 | - 'indianred' => 'CD5C5C', |
|
| 91 | - 'indigo' => '4B0082', |
|
| 92 | - 'ivory' => 'FFFFF0', |
|
| 93 | - 'khaki' => 'F0E68C', |
|
| 94 | - 'lavender' => 'E6E6FA', |
|
| 95 | - 'lavenderblush' => 'FFF0F5', |
|
| 96 | - 'lawngreen' => '7CFC00', |
|
| 97 | - 'lemonchiffon' => 'FFFACD', |
|
| 98 | - 'lightblue' => 'ADD8E6', |
|
| 99 | - 'lightcoral' => 'F08080', |
|
| 100 | - 'lightcyan' => 'E0FFFF', |
|
| 101 | - 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 102 | - 'lightgray' => 'D3D3D3', |
|
| 103 | - 'lightgreen' => '90EE90', |
|
| 104 | - 'lightgrey' => 'D3D3D3', |
|
| 105 | - 'lightpink' => 'FFB6C1', |
|
| 106 | - 'lightsalmon' => 'FFA07A', |
|
| 107 | - 'lightseagreen' => '20B2AA', |
|
| 108 | - 'lightskyblue' => '87CEFA', |
|
| 109 | - 'lightslategray' => '778899', |
|
| 110 | - 'lightslategrey' => '778899', |
|
| 111 | - 'lightsteelblue' => 'B0C4DE', |
|
| 112 | - 'lightyellow' => 'FFFFE0', |
|
| 113 | - 'lime' => '00FF00', |
|
| 114 | - 'limegreen' => '32CD32', |
|
| 115 | - 'linen' => 'FAF0E6', |
|
| 116 | - 'magenta' => 'FF00FF', |
|
| 117 | - 'maroon' => '800000', |
|
| 118 | - 'mediumaquamarine' => '66CDAA', |
|
| 119 | - 'mediumblue' => '0000CD', |
|
| 120 | - 'mediumorchid' => 'BA55D3', |
|
| 121 | - 'mediumpurple' => '9370D0', |
|
| 122 | - 'mediumseagreen' => '3CB371', |
|
| 123 | - 'mediumslateblue' => '7B68EE', |
|
| 124 | - 'mediumspringgreen' => '00FA9A', |
|
| 125 | - 'mediumturquoise' => '48D1CC', |
|
| 126 | - 'mediumvioletred' => 'C71585', |
|
| 127 | - 'midnightblue' => '191970', |
|
| 128 | - 'mintcream' => 'F5FFFA', |
|
| 129 | - 'mistyrose' => 'FFE4E1', |
|
| 130 | - 'moccasin' => 'FFE4B5', |
|
| 131 | - 'navajowhite' => 'FFDEAD', |
|
| 132 | - 'navy' => '000080', |
|
| 133 | - 'oldlace' => 'FDF5E6', |
|
| 134 | - 'olive' => '808000', |
|
| 135 | - 'olivedrab' => '6B8E23', |
|
| 136 | - 'orange' => 'FFA500', |
|
| 137 | - 'orangered' => 'FF4500', |
|
| 138 | - 'orchid' => 'DA70D6', |
|
| 139 | - 'palegoldenrod' => 'EEE8AA', |
|
| 140 | - 'palegreen' => '98FB98', |
|
| 141 | - 'paleturquoise' => 'AFEEEE', |
|
| 142 | - 'palevioletred' => 'DB7093', |
|
| 143 | - 'papayawhip' => 'FFEFD5', |
|
| 144 | - 'peachpuff' => 'FFDAB9', |
|
| 145 | - 'peru' => 'CD853F', |
|
| 146 | - 'pink' => 'FFC0CB', |
|
| 147 | - 'plum' => 'DDA0DD', |
|
| 148 | - 'powderblue' => 'B0E0E6', |
|
| 149 | - 'purple' => '800080', |
|
| 150 | - 'red' => 'FF0000', |
|
| 151 | - 'rosybrown' => 'BC8F8F', |
|
| 152 | - 'royalblue' => '4169E1', |
|
| 153 | - 'saddlebrown' => '8B4513', |
|
| 154 | - 'salmon' => 'FA8072', |
|
| 155 | - 'sandybrown' => 'F4A460', |
|
| 156 | - 'seagreen' => '2E8B57', |
|
| 157 | - 'seashell' => 'FFF5EE', |
|
| 158 | - 'sienna' => 'A0522D', |
|
| 159 | - 'silver' => 'C0C0C0', |
|
| 160 | - 'skyblue' => '87CEEB', |
|
| 161 | - 'slateblue' => '6A5ACD', |
|
| 162 | - 'slategray' => '708090', |
|
| 163 | - 'slategrey' => '708090', |
|
| 164 | - 'snow' => 'FFFAFA', |
|
| 165 | - 'springgreen' => '00FF7F', |
|
| 166 | - 'steelblue' => '4682B4', |
|
| 167 | - 'tan' => 'D2B48C', |
|
| 168 | - 'teal' => '008080', |
|
| 169 | - 'thistle' => 'D8BFD8', |
|
| 170 | - 'tomato' => 'FF6347', |
|
| 171 | - 'turquoise' => '40E0D0', |
|
| 172 | - 'violet' => 'EE82EE', |
|
| 173 | - 'wheat' => 'F5DEB3', |
|
| 174 | - 'white' => 'FFFFFF', |
|
| 175 | - 'whitesmoke' => 'F5F5F5', |
|
| 176 | - 'yellow' => 'FFFF00', |
|
| 177 | - 'yellowgreen' => '9ACD32', |
|
| 178 | - ); |
|
| 19 | + /** |
|
| 20 | + * Sanitizes a HEX value. |
|
| 21 | + * The way this works is by splitting the string in 6 substrings. |
|
| 22 | + * Each sub-string is individually sanitized, and the result is then returned. |
|
| 23 | + * |
|
| 24 | + * @param string $color The hex value of a color. |
|
| 25 | + * @param boolean $hash Whether we want to include a hash (#) at the beginning or not. |
|
| 26 | + * |
|
| 27 | + * @return string The sanitized hex color. |
|
| 28 | + */ |
|
| 29 | + public static function sanitize_hex( string $color = '#FFFFFF', bool $hash = true ): string { |
|
| 30 | + $word_colors = array( |
|
| 31 | + 'aliceblue' => 'F0F8FF', |
|
| 32 | + 'antiquewhite' => 'FAEBD7', |
|
| 33 | + 'aqua' => '00FFFF', |
|
| 34 | + 'aquamarine' => '7FFFD4', |
|
| 35 | + 'azure' => 'F0FFFF', |
|
| 36 | + 'beige' => 'F5F5DC', |
|
| 37 | + 'bisque' => 'FFE4C4', |
|
| 38 | + 'black' => '000000', |
|
| 39 | + 'blanchedalmond' => 'FFEBCD', |
|
| 40 | + 'blue' => '0000FF', |
|
| 41 | + 'blueviolet' => '8A2BE2', |
|
| 42 | + 'brown' => 'A52A2A', |
|
| 43 | + 'burlywood' => 'DEB887', |
|
| 44 | + 'cadetblue' => '5F9EA0', |
|
| 45 | + 'chartreuse' => '7FFF00', |
|
| 46 | + 'chocolate' => 'D2691E', |
|
| 47 | + 'coral' => 'FF7F50', |
|
| 48 | + 'cornflowerblue' => '6495ED', |
|
| 49 | + 'cornsilk' => 'FFF8DC', |
|
| 50 | + 'crimson' => 'DC143C', |
|
| 51 | + 'cyan' => '00FFFF', |
|
| 52 | + 'darkblue' => '00008B', |
|
| 53 | + 'darkcyan' => '008B8B', |
|
| 54 | + 'darkgoldenrod' => 'B8860B', |
|
| 55 | + 'darkgray' => 'A9A9A9', |
|
| 56 | + 'darkgreen' => '006400', |
|
| 57 | + 'darkgrey' => 'A9A9A9', |
|
| 58 | + 'darkkhaki' => 'BDB76B', |
|
| 59 | + 'darkmagenta' => '8B008B', |
|
| 60 | + 'darkolivegreen' => '556B2F', |
|
| 61 | + 'darkorange' => 'FF8C00', |
|
| 62 | + 'darkorchid' => '9932CC', |
|
| 63 | + 'darkred' => '8B0000', |
|
| 64 | + 'darksalmon' => 'E9967A', |
|
| 65 | + 'darkseagreen' => '8FBC8F', |
|
| 66 | + 'darkslateblue' => '483D8B', |
|
| 67 | + 'darkslategray' => '2F4F4F', |
|
| 68 | + 'darkslategrey' => '2F4F4F', |
|
| 69 | + 'darkturquoise' => '00CED1', |
|
| 70 | + 'darkviolet' => '9400D3', |
|
| 71 | + 'deeppink' => 'FF1493', |
|
| 72 | + 'deepskyblue' => '00BFFF', |
|
| 73 | + 'dimgray' => '696969', |
|
| 74 | + 'dimgrey' => '696969', |
|
| 75 | + 'dodgerblue' => '1E90FF', |
|
| 76 | + 'firebrick' => 'B22222', |
|
| 77 | + 'floralwhite' => 'FFFAF0', |
|
| 78 | + 'forestgreen' => '228B22', |
|
| 79 | + 'fuchsia' => 'FF00FF', |
|
| 80 | + 'gainsboro' => 'DCDCDC', |
|
| 81 | + 'ghostwhite' => 'F8F8FF', |
|
| 82 | + 'gold' => 'FFD700', |
|
| 83 | + 'goldenrod' => 'DAA520', |
|
| 84 | + 'gray' => '808080', |
|
| 85 | + 'green' => '008000', |
|
| 86 | + 'greenyellow' => 'ADFF2F', |
|
| 87 | + 'grey' => '808080', |
|
| 88 | + 'honeydew' => 'F0FFF0', |
|
| 89 | + 'hotpink' => 'FF69B4', |
|
| 90 | + 'indianred' => 'CD5C5C', |
|
| 91 | + 'indigo' => '4B0082', |
|
| 92 | + 'ivory' => 'FFFFF0', |
|
| 93 | + 'khaki' => 'F0E68C', |
|
| 94 | + 'lavender' => 'E6E6FA', |
|
| 95 | + 'lavenderblush' => 'FFF0F5', |
|
| 96 | + 'lawngreen' => '7CFC00', |
|
| 97 | + 'lemonchiffon' => 'FFFACD', |
|
| 98 | + 'lightblue' => 'ADD8E6', |
|
| 99 | + 'lightcoral' => 'F08080', |
|
| 100 | + 'lightcyan' => 'E0FFFF', |
|
| 101 | + 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 102 | + 'lightgray' => 'D3D3D3', |
|
| 103 | + 'lightgreen' => '90EE90', |
|
| 104 | + 'lightgrey' => 'D3D3D3', |
|
| 105 | + 'lightpink' => 'FFB6C1', |
|
| 106 | + 'lightsalmon' => 'FFA07A', |
|
| 107 | + 'lightseagreen' => '20B2AA', |
|
| 108 | + 'lightskyblue' => '87CEFA', |
|
| 109 | + 'lightslategray' => '778899', |
|
| 110 | + 'lightslategrey' => '778899', |
|
| 111 | + 'lightsteelblue' => 'B0C4DE', |
|
| 112 | + 'lightyellow' => 'FFFFE0', |
|
| 113 | + 'lime' => '00FF00', |
|
| 114 | + 'limegreen' => '32CD32', |
|
| 115 | + 'linen' => 'FAF0E6', |
|
| 116 | + 'magenta' => 'FF00FF', |
|
| 117 | + 'maroon' => '800000', |
|
| 118 | + 'mediumaquamarine' => '66CDAA', |
|
| 119 | + 'mediumblue' => '0000CD', |
|
| 120 | + 'mediumorchid' => 'BA55D3', |
|
| 121 | + 'mediumpurple' => '9370D0', |
|
| 122 | + 'mediumseagreen' => '3CB371', |
|
| 123 | + 'mediumslateblue' => '7B68EE', |
|
| 124 | + 'mediumspringgreen' => '00FA9A', |
|
| 125 | + 'mediumturquoise' => '48D1CC', |
|
| 126 | + 'mediumvioletred' => 'C71585', |
|
| 127 | + 'midnightblue' => '191970', |
|
| 128 | + 'mintcream' => 'F5FFFA', |
|
| 129 | + 'mistyrose' => 'FFE4E1', |
|
| 130 | + 'moccasin' => 'FFE4B5', |
|
| 131 | + 'navajowhite' => 'FFDEAD', |
|
| 132 | + 'navy' => '000080', |
|
| 133 | + 'oldlace' => 'FDF5E6', |
|
| 134 | + 'olive' => '808000', |
|
| 135 | + 'olivedrab' => '6B8E23', |
|
| 136 | + 'orange' => 'FFA500', |
|
| 137 | + 'orangered' => 'FF4500', |
|
| 138 | + 'orchid' => 'DA70D6', |
|
| 139 | + 'palegoldenrod' => 'EEE8AA', |
|
| 140 | + 'palegreen' => '98FB98', |
|
| 141 | + 'paleturquoise' => 'AFEEEE', |
|
| 142 | + 'palevioletred' => 'DB7093', |
|
| 143 | + 'papayawhip' => 'FFEFD5', |
|
| 144 | + 'peachpuff' => 'FFDAB9', |
|
| 145 | + 'peru' => 'CD853F', |
|
| 146 | + 'pink' => 'FFC0CB', |
|
| 147 | + 'plum' => 'DDA0DD', |
|
| 148 | + 'powderblue' => 'B0E0E6', |
|
| 149 | + 'purple' => '800080', |
|
| 150 | + 'red' => 'FF0000', |
|
| 151 | + 'rosybrown' => 'BC8F8F', |
|
| 152 | + 'royalblue' => '4169E1', |
|
| 153 | + 'saddlebrown' => '8B4513', |
|
| 154 | + 'salmon' => 'FA8072', |
|
| 155 | + 'sandybrown' => 'F4A460', |
|
| 156 | + 'seagreen' => '2E8B57', |
|
| 157 | + 'seashell' => 'FFF5EE', |
|
| 158 | + 'sienna' => 'A0522D', |
|
| 159 | + 'silver' => 'C0C0C0', |
|
| 160 | + 'skyblue' => '87CEEB', |
|
| 161 | + 'slateblue' => '6A5ACD', |
|
| 162 | + 'slategray' => '708090', |
|
| 163 | + 'slategrey' => '708090', |
|
| 164 | + 'snow' => 'FFFAFA', |
|
| 165 | + 'springgreen' => '00FF7F', |
|
| 166 | + 'steelblue' => '4682B4', |
|
| 167 | + 'tan' => 'D2B48C', |
|
| 168 | + 'teal' => '008080', |
|
| 169 | + 'thistle' => 'D8BFD8', |
|
| 170 | + 'tomato' => 'FF6347', |
|
| 171 | + 'turquoise' => '40E0D0', |
|
| 172 | + 'violet' => 'EE82EE', |
|
| 173 | + 'wheat' => 'F5DEB3', |
|
| 174 | + 'white' => 'FFFFFF', |
|
| 175 | + 'whitesmoke' => 'F5F5F5', |
|
| 176 | + 'yellow' => 'FFFF00', |
|
| 177 | + 'yellowgreen' => '9ACD32', |
|
| 178 | + ); |
|
| 179 | 179 | |
| 180 | - if ( is_array( $color ) ) { |
|
| 181 | - $color = $color[0]; |
|
| 182 | - } |
|
| 180 | + if ( is_array( $color ) ) { |
|
| 181 | + $color = $color[0]; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - // Remove any spaces and special characters before and after the string. |
|
| 185 | - $color = trim( $color ); |
|
| 184 | + // Remove any spaces and special characters before and after the string. |
|
| 185 | + $color = trim( $color ); |
|
| 186 | 186 | |
| 187 | - // Check if the color is a standard word-color. |
|
| 188 | - // If it is, then convert to hex. |
|
| 189 | - if ( array_key_exists( $color, $word_colors ) ) { |
|
| 190 | - $color = $word_colors[ $color ]; |
|
| 191 | - } |
|
| 187 | + // Check if the color is a standard word-color. |
|
| 188 | + // If it is, then convert to hex. |
|
| 189 | + if ( array_key_exists( $color, $word_colors ) ) { |
|
| 190 | + $color = $word_colors[ $color ]; |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - // Remove any trailing '#' symbols from the color value. |
|
| 194 | - $color = str_replace( '#', '', $color ); |
|
| 193 | + // Remove any trailing '#' symbols from the color value. |
|
| 194 | + $color = str_replace( '#', '', $color ); |
|
| 195 | 195 | |
| 196 | - // If the string is six characters long, then use it in pairs. |
|
| 197 | - if ( 3 === strlen( $color ) ) { |
|
| 198 | - $color = substr( $color, 0, 1 ) . substr( $color, 0, 1 ) . substr( $color, 1, 1 ) . substr( $color, 1, 1 ) . substr( $color, 2, 1 ) . substr( $color, 2, 1 ); |
|
| 199 | - } |
|
| 196 | + // If the string is six characters long, then use it in pairs. |
|
| 197 | + if ( 3 === strlen( $color ) ) { |
|
| 198 | + $color = substr( $color, 0, 1 ) . substr( $color, 0, 1 ) . substr( $color, 1, 1 ) . substr( $color, 1, 1 ) . substr( $color, 2, 1 ) . substr( $color, 2, 1 ); |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - $substr = array(); |
|
| 202 | - for ( $i = 0; $i <= 5; $i++ ) { |
|
| 203 | - $default = ( 0 === $i ) ? 'F' : ( $substr[ $i - 1 ] ); |
|
| 204 | - $substr[ $i ] = substr( $color, $i, 1 ); |
|
| 205 | - $substr[ $i ] = ( false === $substr[ $i ] || ! ctype_xdigit( $substr[ $i ] ) ) ? $default : $substr[ $i ]; |
|
| 206 | - } |
|
| 201 | + $substr = array(); |
|
| 202 | + for ( $i = 0; $i <= 5; $i++ ) { |
|
| 203 | + $default = ( 0 === $i ) ? 'F' : ( $substr[ $i - 1 ] ); |
|
| 204 | + $substr[ $i ] = substr( $color, $i, 1 ); |
|
| 205 | + $substr[ $i ] = ( false === $substr[ $i ] || ! ctype_xdigit( $substr[ $i ] ) ) ? $default : $substr[ $i ]; |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - $hex = implode( '', $substr ); |
|
| 208 | + $hex = implode( '', $substr ); |
|
| 209 | 209 | |
| 210 | - return ( ! $hash ) ? $hex : '#' . $hex; |
|
| 211 | - } |
|
| 210 | + return ( ! $hash ) ? $hex : '#' . $hex; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - /** |
|
| 214 | - * Sanitizes RGBA color. |
|
| 215 | - * |
|
| 216 | - * @param string $value RGBA value. |
|
| 217 | - * |
|
| 218 | - * @return string |
|
| 219 | - */ |
|
| 220 | - public static function sanitize_rgba( string $value ): string { |
|
| 221 | - // If empty or an array return transparent. |
|
| 222 | - if ( empty( $value ) ) { |
|
| 223 | - return 'rgba(0,0,0,0)'; |
|
| 224 | - } |
|
| 213 | + /** |
|
| 214 | + * Sanitizes RGBA color. |
|
| 215 | + * |
|
| 216 | + * @param string $value RGBA value. |
|
| 217 | + * |
|
| 218 | + * @return string |
|
| 219 | + */ |
|
| 220 | + public static function sanitize_rgba( string $value ): string { |
|
| 221 | + // If empty or an array return transparent. |
|
| 222 | + if ( empty( $value ) ) { |
|
| 223 | + return 'rgba(0,0,0,0)'; |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - // If string does not start with 'rgba', then treat as hex |
|
| 227 | - // sanitize the hex color and finally convert hex to rgba. |
|
| 228 | - if ( false === strpos( $value, 'rgba' ) ) { |
|
| 229 | - return self::get_rgba( self::sanitize_hex( $value ) ); |
|
| 230 | - } |
|
| 226 | + // If string does not start with 'rgba', then treat as hex |
|
| 227 | + // sanitize the hex color and finally convert hex to rgba. |
|
| 228 | + if ( false === strpos( $value, 'rgba' ) ) { |
|
| 229 | + return self::get_rgba( self::sanitize_hex( $value ) ); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - // By now we know the string is formatted as a rgba color, so we can just return it. |
|
| 233 | - $value = str_replace( array( ' ', 'rgba', '(', ')' ), '', $value ); |
|
| 234 | - $value = explode( ',', $value ); |
|
| 235 | - $red = ( isset( $value[0] ) ) ? intval( $value[0] ) : 255; |
|
| 236 | - $green = ( isset( $value[1] ) ) ? intval( $value[1] ) : 255; |
|
| 237 | - $blue = ( isset( $value[2] ) ) ? intval( $value[2] ) : 255; |
|
| 238 | - $alpha = ( isset( $value[3] ) ) ? filter_var( $value[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : 1; |
|
| 232 | + // By now we know the string is formatted as a rgba color, so we can just return it. |
|
| 233 | + $value = str_replace( array( ' ', 'rgba', '(', ')' ), '', $value ); |
|
| 234 | + $value = explode( ',', $value ); |
|
| 235 | + $red = ( isset( $value[0] ) ) ? intval( $value[0] ) : 255; |
|
| 236 | + $green = ( isset( $value[1] ) ) ? intval( $value[1] ) : 255; |
|
| 237 | + $blue = ( isset( $value[2] ) ) ? intval( $value[2] ) : 255; |
|
| 238 | + $alpha = ( isset( $value[3] ) ) ? filter_var( $value[3], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : 1; |
|
| 239 | 239 | |
| 240 | - return 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $alpha . ')'; |
|
| 241 | - } |
|
| 240 | + return 'rgba(' . $red . ',' . $green . ',' . $blue . ',' . $alpha . ')'; |
|
| 241 | + } |
|
| 242 | 242 | |
| 243 | - /** |
|
| 244 | - * Sanitize colors. |
|
| 245 | - * Determine if the current value is a hex or a rgba color and call the appropriate method. |
|
| 246 | - * |
|
| 247 | - * @param string|array $value hex or rgba color. |
|
| 248 | - * |
|
| 249 | - * @return string |
|
| 250 | - * @since 0.8.5 |
|
| 251 | - */ |
|
| 252 | - public static function sanitize_color( $value ): string { |
|
| 253 | - if ( is_array( $value ) ) { |
|
| 254 | - if ( isset( $value['rgba'] ) ) { |
|
| 255 | - $value = $value['rgba']; |
|
| 256 | - } elseif ( isset( $value['color'] ) ) { |
|
| 257 | - $opacity = ( isset( $value['opacity'] ) ) ? $value['opacity'] : null; |
|
| 258 | - $opacity = ( ! is_null( $opacity ) && isset( $value['alpha'] ) ) ? $value['alpha'] : null; |
|
| 259 | - $opacity = ( is_null( $opacity ) ) ? 1 : floatval( $opacity ); |
|
| 243 | + /** |
|
| 244 | + * Sanitize colors. |
|
| 245 | + * Determine if the current value is a hex or a rgba color and call the appropriate method. |
|
| 246 | + * |
|
| 247 | + * @param string|array $value hex or rgba color. |
|
| 248 | + * |
|
| 249 | + * @return string |
|
| 250 | + * @since 0.8.5 |
|
| 251 | + */ |
|
| 252 | + public static function sanitize_color( $value ): string { |
|
| 253 | + if ( is_array( $value ) ) { |
|
| 254 | + if ( isset( $value['rgba'] ) ) { |
|
| 255 | + $value = $value['rgba']; |
|
| 256 | + } elseif ( isset( $value['color'] ) ) { |
|
| 257 | + $opacity = ( isset( $value['opacity'] ) ) ? $value['opacity'] : null; |
|
| 258 | + $opacity = ( ! is_null( $opacity ) && isset( $value['alpha'] ) ) ? $value['alpha'] : null; |
|
| 259 | + $opacity = ( is_null( $opacity ) ) ? 1 : floatval( $opacity ); |
|
| 260 | 260 | |
| 261 | - $value = self::get_rgba( $value['color'], $opacity ); |
|
| 262 | - } else { |
|
| 263 | - return ''; |
|
| 264 | - } |
|
| 265 | - } |
|
| 261 | + $value = self::get_rgba( $value['color'], $opacity ); |
|
| 262 | + } else { |
|
| 263 | + return ''; |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - if ( 'transparent' === $value ) { |
|
| 268 | - return 'transparent'; |
|
| 269 | - } |
|
| 267 | + if ( 'transparent' === $value ) { |
|
| 268 | + return 'transparent'; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - // Is this a rgba color or a hex? |
|
| 272 | - $mode = ( false === strpos( $value, 'rgba' ) ) ? 'rgba' : 'hex'; |
|
| 271 | + // Is this a rgba color or a hex? |
|
| 272 | + $mode = ( false === strpos( $value, 'rgba' ) ) ? 'rgba' : 'hex'; |
|
| 273 | 273 | |
| 274 | - if ( 'rgba' === $mode ) { |
|
| 275 | - return self::sanitize_hex( $value ); |
|
| 276 | - } else { |
|
| 277 | - return self::sanitize_rgba( $value ); |
|
| 278 | - } |
|
| 279 | - } |
|
| 274 | + if ( 'rgba' === $mode ) { |
|
| 275 | + return self::sanitize_hex( $value ); |
|
| 276 | + } else { |
|
| 277 | + return self::sanitize_rgba( $value ); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Gets the rgb value of the $hex color. |
|
| 283 | - * |
|
| 284 | - * @param string $hex The hex value of a color. |
|
| 285 | - * @param boolean $implode Whether we want to implode the values or not. |
|
| 286 | - * |
|
| 287 | - * @return array|string array|string |
|
| 288 | - */ |
|
| 289 | - public static function get_rgb( string $hex, bool $implode = false ) { |
|
| 290 | - // Remove any trailing '#' symbols from the color value. |
|
| 291 | - $hex = self::sanitize_hex( $hex, false ); |
|
| 281 | + /** |
|
| 282 | + * Gets the rgb value of the $hex color. |
|
| 283 | + * |
|
| 284 | + * @param string $hex The hex value of a color. |
|
| 285 | + * @param boolean $implode Whether we want to implode the values or not. |
|
| 286 | + * |
|
| 287 | + * @return array|string array|string |
|
| 288 | + */ |
|
| 289 | + public static function get_rgb( string $hex, bool $implode = false ) { |
|
| 290 | + // Remove any trailing '#' symbols from the color value. |
|
| 291 | + $hex = self::sanitize_hex( $hex, false ); |
|
| 292 | 292 | |
| 293 | - // rgb is an array. |
|
| 294 | - $rgb = array( |
|
| 295 | - hexdec( substr( $hex, 0, 2 ) ), |
|
| 296 | - hexdec( substr( $hex, 2, 2 ) ), |
|
| 297 | - hexdec( substr( $hex, 4, 2 ) ), |
|
| 298 | - ); |
|
| 293 | + // rgb is an array. |
|
| 294 | + $rgb = array( |
|
| 295 | + hexdec( substr( $hex, 0, 2 ) ), |
|
| 296 | + hexdec( substr( $hex, 2, 2 ) ), |
|
| 297 | + hexdec( substr( $hex, 4, 2 ) ), |
|
| 298 | + ); |
|
| 299 | 299 | |
| 300 | - return ( $implode ) ? implode( ',', $rgb ) : $rgb; |
|
| 301 | - } |
|
| 300 | + return ( $implode ) ? implode( ',', $rgb ) : $rgb; |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - /** |
|
| 304 | - * Gets the rgb value of the $hex color. |
|
| 305 | - * |
|
| 306 | - * @param string $hex The hex value of a color. |
|
| 307 | - * @param int $opacity Opacity level (1-100). |
|
| 308 | - * |
|
| 309 | - * @return string |
|
| 310 | - */ |
|
| 311 | - public static function get_rgba( string $hex = '#fff', int $opacity = 100 ): string { |
|
| 312 | - $hex = self::sanitize_hex( $hex, false ); |
|
| 303 | + /** |
|
| 304 | + * Gets the rgb value of the $hex color. |
|
| 305 | + * |
|
| 306 | + * @param string $hex The hex value of a color. |
|
| 307 | + * @param int $opacity Opacity level (1-100). |
|
| 308 | + * |
|
| 309 | + * @return string |
|
| 310 | + */ |
|
| 311 | + public static function get_rgba( string $hex = '#fff', int $opacity = 100 ): string { |
|
| 312 | + $hex = self::sanitize_hex( $hex, false ); |
|
| 313 | 313 | |
| 314 | - /** |
|
| 315 | - * Make sure that opacity is properly formatted: |
|
| 316 | - * Set the opacity to 100 if a larger value has been entered by mistake. |
|
| 317 | - * If a negative value is used, then set to 0. |
|
| 318 | - * If an opacity value is entered in a decimal form (for example, 0.25), then multiply by 100. |
|
| 319 | - */ |
|
| 320 | - if ( $opacity >= 100 ) { |
|
| 321 | - $opacity = 100; |
|
| 322 | - } elseif ( $opacity < 0 ) { |
|
| 323 | - $opacity = 0; |
|
| 324 | - } elseif ( $opacity <= 1 && 0 !== $opacity ) { |
|
| 325 | - $opacity = ( $opacity * 100 ); |
|
| 326 | - } |
|
| 314 | + /** |
|
| 315 | + * Make sure that opacity is properly formatted: |
|
| 316 | + * Set the opacity to 100 if a larger value has been entered by mistake. |
|
| 317 | + * If a negative value is used, then set to 0. |
|
| 318 | + * If an opacity value is entered in a decimal form (for example, 0.25), then multiply by 100. |
|
| 319 | + */ |
|
| 320 | + if ( $opacity >= 100 ) { |
|
| 321 | + $opacity = 100; |
|
| 322 | + } elseif ( $opacity < 0 ) { |
|
| 323 | + $opacity = 0; |
|
| 324 | + } elseif ( $opacity <= 1 && 0 !== $opacity ) { |
|
| 325 | + $opacity = ( $opacity * 100 ); |
|
| 326 | + } |
|
| 327 | 327 | |
| 328 | - // Divide the opacity by 100 to end-up with a CSS value for the opacity. |
|
| 329 | - $opacity = ( $opacity / 100 ); |
|
| 328 | + // Divide the opacity by 100 to end-up with a CSS value for the opacity. |
|
| 329 | + $opacity = ( $opacity / 100 ); |
|
| 330 | 330 | |
| 331 | - return 'rgba(' . self::get_rgb( $hex, true ) . ', ' . $opacity . ')'; |
|
| 332 | - } |
|
| 333 | - } |
|
| 331 | + return 'rgba(' . self::get_rgb( $hex, true ) . ', ' . $opacity . ')'; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | 334 | } |
@@ -187,7 +187,7 @@ discard block |
||
| 187 | 187 | // Check if the color is a standard word-color. |
| 188 | 188 | // If it is, then convert to hex. |
| 189 | 189 | if ( array_key_exists( $color, $word_colors ) ) { |
| 190 | - $color = $word_colors[ $color ]; |
|
| 190 | + $color = $word_colors[$color]; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | // Remove any trailing '#' symbols from the color value. |
@@ -200,9 +200,9 @@ discard block |
||
| 200 | 200 | |
| 201 | 201 | $substr = array(); |
| 202 | 202 | for ( $i = 0; $i <= 5; $i++ ) { |
| 203 | - $default = ( 0 === $i ) ? 'F' : ( $substr[ $i - 1 ] ); |
|
| 204 | - $substr[ $i ] = substr( $color, $i, 1 ); |
|
| 205 | - $substr[ $i ] = ( false === $substr[ $i ] || ! ctype_xdigit( $substr[ $i ] ) ) ? $default : $substr[ $i ]; |
|
| 203 | + $default = ( 0 === $i ) ? 'F' : ( $substr[$i - 1] ); |
|
| 204 | + $substr[$i] = substr( $color, $i, 1 ); |
|
| 205 | + $substr[$i] = ( false === $substr[$i] || ! ctype_xdigit( $substr[$i] ) ) ? $default : $substr[$i]; |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | $hex = implode( '', $substr ); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | $instances = ReduxFrameworkInstances::get_all_instances(); |
| 104 | 104 | |
| 105 | 105 | foreach ( self::$fields as $opt_name => $fields ) { |
| 106 | - if ( ! isset( $instances[ $opt_name ] ) ) { |
|
| 106 | + if ( ! isset( $instances[$opt_name] ) ) { |
|
| 107 | 107 | Redux::set_args( |
| 108 | 108 | $opt_name, |
| 109 | 109 | array( |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | |
| 127 | 127 | $instances = ReduxFrameworkInstances::get_all_instances(); |
| 128 | 128 | |
| 129 | - add_action( 'admin_enqueue_scripts', array( $instances[ $opt_name ], 'enqueue' ), 1 ); |
|
| 129 | + add_action( 'admin_enqueue_scripts', array( $instances[$opt_name], 'enqueue' ), 1 ); |
|
| 130 | 130 | } |
| 131 | 131 | } |
| 132 | 132 | } |
@@ -158,7 +158,7 @@ discard block |
||
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | foreach ( self::$boxes as $opt_name => $the_boxes ) { |
| 161 | - if ( ! self::$init[ $opt_name ] ) { |
|
| 161 | + if ( ! self::$init[$opt_name] ) { |
|
| 162 | 162 | |
| 163 | 163 | // phpcs:ignore WordPress.NamingConventions.ValidHookName |
| 164 | 164 | add_action( 'redux/metaboxes/' . $opt_name . '/boxes', array( 'Redux_Metaboxes', 'addMetaboxes' ), 2 ); |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | public static function construct_args( string $opt_name ) { |
| 193 | 193 | Redux_Functions_Ex::record_caller( $opt_name ); |
| 194 | 194 | |
| 195 | - $args = self::$args[ $opt_name ]; |
|
| 195 | + $args = self::$args[$opt_name]; |
|
| 196 | 196 | $args['opt_name'] = $opt_name; |
| 197 | 197 | |
| 198 | 198 | if ( ! isset( $args['menu_title'] ) ) { |
@@ -237,11 +237,11 @@ discard block |
||
| 237 | 237 | Redux_Functions_Ex::record_caller( $opt_name ); |
| 238 | 238 | |
| 239 | 239 | $boxes = array(); |
| 240 | - if ( ! isset( self::$boxes[ $opt_name ] ) ) { |
|
| 240 | + if ( ! isset( self::$boxes[$opt_name] ) ) { |
|
| 241 | 241 | return $boxes; |
| 242 | 242 | } |
| 243 | 243 | |
| 244 | - foreach ( self::$boxes[ $opt_name ] as $box ) { |
|
| 244 | + foreach ( self::$boxes[$opt_name] as $box ) { |
|
| 245 | 245 | $box['sections'] = self::construct_sections( $opt_name, $box['id'] ); |
| 246 | 246 | $boxes[] = $box; |
| 247 | 247 | } |
@@ -279,20 +279,20 @@ discard block |
||
| 279 | 279 | Redux_Functions_Ex::record_caller( $opt_name ); |
| 280 | 280 | |
| 281 | 281 | $sections = array(); |
| 282 | - if ( ! isset( self::$sections[ $opt_name ] ) ) { |
|
| 282 | + if ( ! isset( self::$sections[$opt_name] ) ) { |
|
| 283 | 283 | return $sections; |
| 284 | 284 | } |
| 285 | 285 | |
| 286 | - foreach ( self::$sections[ $opt_name ] as $section_id => $section ) { |
|
| 286 | + foreach ( self::$sections[$opt_name] as $section_id => $section ) { |
|
| 287 | 287 | if ( $box_id === $section['box_id'] ) { |
| 288 | 288 | $p = $section['priority']; |
| 289 | 289 | |
| 290 | - while ( isset( $sections[ $p ] ) ) { |
|
| 290 | + while ( isset( $sections[$p] ) ) { |
|
| 291 | 291 | echo esc_html( $p++ ); |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | $section['fields'] = self::construct_fields( $opt_name, $section_id ); |
| 295 | - $sections[ $p ] = $section; |
|
| 295 | + $sections[$p] = $section; |
|
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | |
@@ -329,19 +329,19 @@ discard block |
||
| 329 | 329 | |
| 330 | 330 | $fields = array(); |
| 331 | 331 | |
| 332 | - if ( ! isset( self::$fields[ $opt_name ] ) ) { |
|
| 332 | + if ( ! isset( self::$fields[$opt_name] ) ) { |
|
| 333 | 333 | return $fields; |
| 334 | 334 | } |
| 335 | 335 | |
| 336 | - foreach ( self::$fields[ $opt_name ] as $field ) { |
|
| 336 | + foreach ( self::$fields[$opt_name] as $field ) { |
|
| 337 | 337 | if ( $section_id === $field['section_id'] ) { |
| 338 | 338 | $p = $field['priority']; |
| 339 | 339 | |
| 340 | - while ( isset( $fields[ $p ] ) ) { |
|
| 340 | + while ( isset( $fields[$p] ) ) { |
|
| 341 | 341 | echo esc_html( $p++ ); |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - $fields[ $p ] = $field; |
|
| 344 | + $fields[$p] = $field; |
|
| 345 | 345 | } |
| 346 | 346 | } |
| 347 | 347 | |
@@ -378,11 +378,11 @@ discard block |
||
| 378 | 378 | self::check_opt_name( $opt_name ); |
| 379 | 379 | |
| 380 | 380 | if ( ! empty( $opt_name ) && ! empty( $id ) ) { |
| 381 | - if ( ! isset( self::$sections[ $opt_name ][ $id ] ) ) { |
|
| 381 | + if ( ! isset( self::$sections[$opt_name][$id] ) ) { |
|
| 382 | 382 | $id = strtolower( sanitize_html_class( $id ) ); |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - return self::$sections[ $opt_name ][ $id ] ?? false; |
|
| 385 | + return self::$sections[$opt_name][$id] ?? false; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | return false; |
@@ -421,11 +421,11 @@ discard block |
||
| 421 | 421 | $section['id'] = 'section'; |
| 422 | 422 | } |
| 423 | 423 | |
| 424 | - if ( isset( self::$sections[ $opt_name ][ $section['id'] ] ) ) { |
|
| 424 | + if ( isset( self::$sections[$opt_name][$section['id']] ) ) { |
|
| 425 | 425 | $orig = $section['id']; |
| 426 | 426 | $i = 0; |
| 427 | 427 | |
| 428 | - while ( isset( self::$sections[ $opt_name ][ $section['id'] ] ) ) { |
|
| 428 | + while ( isset( self::$sections[$opt_name][$section['id']] ) ) { |
|
| 429 | 429 | $section['id'] = $orig . '_' . $i; |
| 430 | 430 | ++$i; |
| 431 | 431 | } |
@@ -442,10 +442,10 @@ discard block |
||
| 442 | 442 | } |
| 443 | 443 | unset( $section['fields'] ); |
| 444 | 444 | } |
| 445 | - self::$sections[ $opt_name ][ $section['id'] ] = $section; |
|
| 445 | + self::$sections[$opt_name][$section['id']] = $section; |
|
| 446 | 446 | |
| 447 | 447 | } else { |
| 448 | - self::$errors[ $opt_name ]['section']['empty'] = esc_html__( 'Unable to create a section due an empty section array or the section variable passed was not an array.', 'redux-framework' ); |
|
| 448 | + self::$errors[$opt_name]['section']['empty'] = esc_html__( 'Unable to create a section due an empty section array or the section variable passed was not an array.', 'redux-framework' ); |
|
| 449 | 449 | } |
| 450 | 450 | } |
| 451 | 451 | |
@@ -539,7 +539,7 @@ discard block |
||
| 539 | 539 | self::check_opt_name( $opt_name ); |
| 540 | 540 | |
| 541 | 541 | if ( ! empty( $opt_name ) && ! empty( $id ) ) { |
| 542 | - return self::$fields[ $opt_name ][ $id ] ?? false; |
|
| 542 | + return self::$fields[$opt_name][$id] ?? false; |
|
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | return false; |
@@ -575,7 +575,7 @@ discard block |
||
| 575 | 575 | $field['priority'] = self::get_priority( $opt_name, 'fields' ); |
| 576 | 576 | } |
| 577 | 577 | |
| 578 | - self::$fields[ $opt_name ][ $field['id'] ] = $field; |
|
| 578 | + self::$fields[$opt_name][$field['id']] = $field; |
|
| 579 | 579 | } |
| 580 | 580 | } |
| 581 | 581 | |
@@ -612,11 +612,11 @@ discard block |
||
| 612 | 612 | $box['id'] = 'box'; |
| 613 | 613 | } |
| 614 | 614 | |
| 615 | - if ( isset( self::$boxes[ $opt_name ][ $box['id'] ] ) ) { |
|
| 615 | + if ( isset( self::$boxes[$opt_name][$box['id']] ) ) { |
|
| 616 | 616 | $orig = $box['id']; |
| 617 | 617 | $i = 0; |
| 618 | 618 | |
| 619 | - while ( isset( self::$boxes[ $opt_name ][ $box['id'] ] ) ) { |
|
| 619 | + while ( isset( self::$boxes[$opt_name][$box['id']] ) ) { |
|
| 620 | 620 | $box['id'] = $orig . '_' . $i; |
| 621 | 621 | ++$i; |
| 622 | 622 | } |
@@ -631,9 +631,9 @@ discard block |
||
| 631 | 631 | unset( $box['sections'] ); |
| 632 | 632 | } |
| 633 | 633 | |
| 634 | - self::$boxes[ $opt_name ][ $box['id'] ] = $box; |
|
| 634 | + self::$boxes[$opt_name][$box['id']] = $box; |
|
| 635 | 635 | } else { |
| 636 | - self::$errors[ $opt_name ]['box']['empty'] = esc_html__( 'Unable to create a box due an empty box array or the box variable passed was not an array.', 'redux-framework' ); |
|
| 636 | + self::$errors[$opt_name]['box']['empty'] = esc_html__( 'Unable to create a box due an empty box array or the box variable passed was not an array.', 'redux-framework' ); |
|
| 637 | 637 | } |
| 638 | 638 | } |
| 639 | 639 | |
@@ -692,8 +692,8 @@ discard block |
||
| 692 | 692 | public static function get_boxes( string $opt_name = '' ) { |
| 693 | 693 | self::check_opt_name( $opt_name ); |
| 694 | 694 | |
| 695 | - if ( ! empty( $opt_name ) && ! empty( self::$boxes[ $opt_name ] ) ) { |
|
| 696 | - return self::$boxes[ $opt_name ]; |
|
| 695 | + if ( ! empty( $opt_name ) && ! empty( self::$boxes[$opt_name] ) ) { |
|
| 696 | + return self::$boxes[$opt_name]; |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | return null; |
@@ -726,8 +726,8 @@ discard block |
||
| 726 | 726 | public static function get_box( string $opt_name = '', string $key = '' ) { |
| 727 | 727 | self::check_opt_name( $opt_name ); |
| 728 | 728 | |
| 729 | - if ( ! empty( $opt_name ) && ! empty( $key ) && ! empty( self::$boxes[ $opt_name ] ) && isset( self::$boxes[ $opt_name ][ $key ] ) ) { |
|
| 730 | - return self::$boxes[ $opt_name ][ $key ]; |
|
| 729 | + if ( ! empty( $opt_name ) && ! empty( $key ) && ! empty( self::$boxes[$opt_name] ) && isset( self::$boxes[$opt_name][$key] ) ) { |
|
| 730 | + return self::$boxes[$opt_name][$key]; |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | return null; |
@@ -758,8 +758,8 @@ discard block |
||
| 758 | 758 | * @return mixed |
| 759 | 759 | */ |
| 760 | 760 | public static function get_priority( string $opt_name, string $type ) { |
| 761 | - $priority = self::$priority[ $opt_name ][ $type ]; |
|
| 762 | - self::$priority[ $opt_name ][ $type ] += 1; |
|
| 761 | + $priority = self::$priority[$opt_name][$type]; |
|
| 762 | + self::$priority[$opt_name][$type] += 1; |
|
| 763 | 763 | |
| 764 | 764 | return $priority; |
| 765 | 765 | } |
@@ -774,34 +774,34 @@ discard block |
||
| 774 | 774 | return; |
| 775 | 775 | } |
| 776 | 776 | |
| 777 | - if ( ! isset( self::$boxes[ $opt_name ] ) ) { |
|
| 778 | - self::$boxes[ $opt_name ] = array(); |
|
| 777 | + if ( ! isset( self::$boxes[$opt_name] ) ) { |
|
| 778 | + self::$boxes[$opt_name] = array(); |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | - if ( ! isset( self::$priority[ $opt_name ] ) ) { |
|
| 782 | - self::$priority[ $opt_name ]['args'] = 1; |
|
| 781 | + if ( ! isset( self::$priority[$opt_name] ) ) { |
|
| 782 | + self::$priority[$opt_name]['args'] = 1; |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | - if ( ! isset( self::$sections[ $opt_name ] ) ) { |
|
| 786 | - self::$sections[ $opt_name ] = array(); |
|
| 787 | - self::$priority[ $opt_name ]['sections'] = 1; |
|
| 785 | + if ( ! isset( self::$sections[$opt_name] ) ) { |
|
| 786 | + self::$sections[$opt_name] = array(); |
|
| 787 | + self::$priority[$opt_name]['sections'] = 1; |
|
| 788 | 788 | } |
| 789 | 789 | |
| 790 | - if ( ! isset( self::$fields[ $opt_name ] ) ) { |
|
| 791 | - self::$fields[ $opt_name ] = array(); |
|
| 792 | - self::$priority[ $opt_name ]['fields'] = 1; |
|
| 790 | + if ( ! isset( self::$fields[$opt_name] ) ) { |
|
| 791 | + self::$fields[$opt_name] = array(); |
|
| 792 | + self::$priority[$opt_name]['fields'] = 1; |
|
| 793 | 793 | } |
| 794 | 794 | |
| 795 | - if ( ! isset( self::$errors[ $opt_name ] ) ) { |
|
| 796 | - self::$errors[ $opt_name ] = array(); |
|
| 795 | + if ( ! isset( self::$errors[$opt_name] ) ) { |
|
| 796 | + self::$errors[$opt_name] = array(); |
|
| 797 | 797 | } |
| 798 | 798 | |
| 799 | - if ( ! isset( self::$init[ $opt_name ] ) ) { |
|
| 800 | - self::$init[ $opt_name ] = false; |
|
| 799 | + if ( ! isset( self::$init[$opt_name] ) ) { |
|
| 800 | + self::$init[$opt_name] = false; |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | - if ( ! isset( self::$args[ $opt_name ] ) ) { |
|
| 804 | - self::$args[ $opt_name ] = false; |
|
| 803 | + if ( ! isset( self::$args[$opt_name] ) ) { |
|
| 804 | + self::$args[$opt_name] = false; |
|
| 805 | 805 | } |
| 806 | 806 | } |
| 807 | 807 | } |
@@ -14,797 +14,797 @@ |
||
| 14 | 14 | // Don't duplicate me! |
| 15 | 15 | if ( ! class_exists( 'Redux_Metaboxes' ) ) { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Redux Metaboxes API Class |
|
| 19 | - * Simple API for Redux Framework |
|
| 20 | - * |
|
| 21 | - * @since 1.0.0 |
|
| 22 | - */ |
|
| 23 | - class Redux_Metaboxes { |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Boxes array. |
|
| 27 | - * |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - public static array $boxes = array(); |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Sections array. |
|
| 34 | - * |
|
| 35 | - * @var array |
|
| 36 | - */ |
|
| 37 | - public static array $sections = array(); |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Fields array. |
|
| 41 | - * |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - public static array $fields = array(); |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Priority array. |
|
| 48 | - * |
|
| 49 | - * @var array |
|
| 50 | - */ |
|
| 51 | - public static array $priority = array(); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Errors array. |
|
| 55 | - * |
|
| 56 | - * @var array |
|
| 57 | - */ |
|
| 58 | - public static array $errors = array(); |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Init array. |
|
| 62 | - * |
|
| 63 | - * @var array |
|
| 64 | - */ |
|
| 65 | - public static array $init = array(); |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Args array. |
|
| 69 | - * |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 72 | - public static array $args = array(); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Code has run flag. |
|
| 76 | - * |
|
| 77 | - * @var bool |
|
| 78 | - */ |
|
| 79 | - public static bool $has_run = false; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Class load. |
|
| 83 | - */ |
|
| 84 | - public static function load() { |
|
| 85 | - if ( version_compare( PHP_VERSION, '5.5.0', '<' ) ) { |
|
| 86 | - include_once Redux_Core::$dir . 'inc/lib/array-column.php'; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - add_action( 'init', array( 'Redux_Metaboxes', 'enqueue' ), 99 ); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Enqueue function. |
|
| 94 | - * |
|
| 95 | - * @throws ReflectionException Exception. |
|
| 96 | - */ |
|
| 97 | - public static function enqueue() { |
|
| 98 | - global $pagenow; |
|
| 99 | - |
|
| 100 | - // Check and run instances of Redux where the opt_name hasn't been run. |
|
| 101 | - $pagenows = array( 'post-new.php', 'post.php' ); |
|
| 102 | - if ( ! empty( self::$sections ) && in_array( $pagenow, $pagenows, true ) ) { |
|
| 103 | - $instances = ReduxFrameworkInstances::get_all_instances(); |
|
| 104 | - |
|
| 105 | - foreach ( self::$fields as $opt_name => $fields ) { |
|
| 106 | - if ( ! isset( $instances[ $opt_name ] ) ) { |
|
| 107 | - Redux::set_args( |
|
| 108 | - $opt_name, |
|
| 109 | - array( |
|
| 110 | - 'menu_type' => 'hidden', |
|
| 111 | - ) |
|
| 112 | - ); |
|
| 113 | - |
|
| 114 | - Redux::set_sections( |
|
| 115 | - $opt_name, |
|
| 116 | - array( |
|
| 117 | - array( |
|
| 118 | - 'id' => 'EXTENSION_FAKE_ID' . $opt_name, |
|
| 119 | - 'fields' => $fields, |
|
| 120 | - 'title' => 'N/A', |
|
| 121 | - ), |
|
| 122 | - ) |
|
| 123 | - ); |
|
| 124 | - |
|
| 125 | - Redux::init( $opt_name ); |
|
| 126 | - |
|
| 127 | - $instances = ReduxFrameworkInstances::get_all_instances(); |
|
| 128 | - |
|
| 129 | - add_action( 'admin_enqueue_scripts', array( $instances[ $opt_name ], 'enqueue' ), 1 ); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Filter Metaboxes function. |
|
| 137 | - * |
|
| 138 | - * @deprecated 4.0.0 No more camelCase. |
|
| 139 | - */ |
|
| 140 | - public static function filterMetaboxes() { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 141 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::filter_metaboxes()' ); |
|
| 142 | - |
|
| 143 | - self::filter_metaboxes(); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Filter Metaboxes function. |
|
| 148 | - */ |
|
| 149 | - public static function filter_metaboxes() { |
|
| 150 | - if ( true === self::$has_run ) { |
|
| 151 | - return; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - if ( ! class_exists( 'ReduxFramework' ) ) { |
|
| 155 | - echo '<div id="message" class="error"><p>Redux Framework is <strong>not installed</strong>. Please install it.</p></div>'; |
|
| 156 | - |
|
| 157 | - return; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - foreach ( self::$boxes as $opt_name => $the_boxes ) { |
|
| 161 | - if ( ! self::$init[ $opt_name ] ) { |
|
| 162 | - |
|
| 163 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 164 | - add_action( 'redux/metaboxes/' . $opt_name . '/boxes', array( 'Redux_Metaboxes', 'addMetaboxes' ), 2 ); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - self::$has_run = true; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Construct the global args array. |
|
| 173 | - * |
|
| 174 | - * @param string $opt_name Panel opt_name. |
|
| 175 | - * |
|
| 176 | - * @return mixed |
|
| 177 | - * @deprecated 4.0.0 No more camelCase. |
|
| 178 | - */ |
|
| 179 | - public static function constructArgs( string $opt_name ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 180 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::construct_args( $opt_name )' ); |
|
| 181 | - |
|
| 182 | - return self::construct_args( $opt_name ); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * Construct the global args array. |
|
| 187 | - * |
|
| 188 | - * @param string $opt_name Panel opt_name. |
|
| 189 | - * |
|
| 190 | - * @return mixed |
|
| 191 | - */ |
|
| 192 | - public static function construct_args( string $opt_name ) { |
|
| 193 | - Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 194 | - |
|
| 195 | - $args = self::$args[ $opt_name ]; |
|
| 196 | - $args['opt_name'] = $opt_name; |
|
| 197 | - |
|
| 198 | - if ( ! isset( $args['menu_title'] ) ) { |
|
| 199 | - $args['menu_title'] = ucfirst( $opt_name ) . ' Options'; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if ( ! isset( $args['page_title'] ) ) { |
|
| 203 | - $args['page_title'] = ucfirst( $opt_name ) . ' Options'; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ( ! isset( $args['page_slug'] ) ) { |
|
| 207 | - $args['page_slug'] = $opt_name . '_options'; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - return $args; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Construct metabox boxes array. |
|
| 215 | - * |
|
| 216 | - * @param string $opt_name Panel opt_name. |
|
| 217 | - * |
|
| 218 | - * @return array |
|
| 219 | - * |
|
| 220 | - * @deprecated 4.0.0 No more camelCase. |
|
| 221 | - */ |
|
| 222 | - public static function constructBoxes( string $opt_name ): array { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 223 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::construct_boxes( $opt_name )' ); |
|
| 224 | - |
|
| 225 | - return self::construct_boxes( $opt_name ); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Construct metabox boxes array. |
|
| 231 | - * |
|
| 232 | - * @param string $opt_name Panel opt_name. |
|
| 233 | - * |
|
| 234 | - * @return array |
|
| 235 | - */ |
|
| 236 | - public static function construct_boxes( string $opt_name ): array { |
|
| 237 | - Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 238 | - |
|
| 239 | - $boxes = array(); |
|
| 240 | - if ( ! isset( self::$boxes[ $opt_name ] ) ) { |
|
| 241 | - return $boxes; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - foreach ( self::$boxes[ $opt_name ] as $box ) { |
|
| 245 | - $box['sections'] = self::construct_sections( $opt_name, $box['id'] ); |
|
| 246 | - $boxes[] = $box; |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - ksort( $boxes ); |
|
| 250 | - |
|
| 251 | - return $boxes; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Construct sections. |
|
| 256 | - * |
|
| 257 | - * @param string $opt_name Panel opt_name. |
|
| 258 | - * @param string $box_id Metabox ID. |
|
| 259 | - * |
|
| 260 | - * @return array |
|
| 261 | - * |
|
| 262 | - * @deprecated 4.0.0 No more camelCase. |
|
| 263 | - */ |
|
| 264 | - public static function constructSections( string $opt_name, string $box_id ): array { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 265 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::construct_sections( $opt_name, $box_id )' ); |
|
| 266 | - |
|
| 267 | - return self::construct_sections( $opt_name, $box_id ); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * Construct sections. |
|
| 272 | - * |
|
| 273 | - * @param string $opt_name Panel opt_name. |
|
| 274 | - * @param string $box_id Metabox ID. |
|
| 275 | - * |
|
| 276 | - * @return array |
|
| 277 | - */ |
|
| 278 | - public static function construct_sections( string $opt_name, string $box_id ): array { |
|
| 279 | - Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 280 | - |
|
| 281 | - $sections = array(); |
|
| 282 | - if ( ! isset( self::$sections[ $opt_name ] ) ) { |
|
| 283 | - return $sections; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - foreach ( self::$sections[ $opt_name ] as $section_id => $section ) { |
|
| 287 | - if ( $box_id === $section['box_id'] ) { |
|
| 288 | - $p = $section['priority']; |
|
| 289 | - |
|
| 290 | - while ( isset( $sections[ $p ] ) ) { |
|
| 291 | - echo esc_html( $p++ ); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - $section['fields'] = self::construct_fields( $opt_name, $section_id ); |
|
| 295 | - $sections[ $p ] = $section; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - ksort( $sections ); |
|
| 300 | - |
|
| 301 | - return $sections; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Construct fields. |
|
| 306 | - * |
|
| 307 | - * @param string $opt_name Panel opt_name. |
|
| 308 | - * @param string|int $section_id Section ID. |
|
| 309 | - * |
|
| 310 | - * @return array |
|
| 311 | - * @deprecated 4.0.0 No moe camelCase. |
|
| 312 | - */ |
|
| 313 | - public static function constructFields( string $opt_name = '', $section_id = '' ): array { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 314 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::construct_fields( $opt_name, $section_id )' ); |
|
| 315 | - |
|
| 316 | - return self::construct_fields( $opt_name, $section_id ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Construct fields. |
|
| 321 | - * |
|
| 322 | - * @param string $opt_name Panel opt_name. |
|
| 323 | - * @param string|int $section_id Section ID. |
|
| 324 | - * |
|
| 325 | - * @return array |
|
| 326 | - */ |
|
| 327 | - public static function construct_fields( string $opt_name = '', $section_id = '' ): array { |
|
| 328 | - Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 329 | - |
|
| 330 | - $fields = array(); |
|
| 331 | - |
|
| 332 | - if ( ! isset( self::$fields[ $opt_name ] ) ) { |
|
| 333 | - return $fields; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - foreach ( self::$fields[ $opt_name ] as $field ) { |
|
| 337 | - if ( $section_id === $field['section_id'] ) { |
|
| 338 | - $p = $field['priority']; |
|
| 339 | - |
|
| 340 | - while ( isset( $fields[ $p ] ) ) { |
|
| 341 | - echo esc_html( $p++ ); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - $fields[ $p ] = $field; |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - ksort( $fields ); |
|
| 349 | - |
|
| 350 | - return $fields; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Retrieve the section array. |
|
| 355 | - * |
|
| 356 | - * @param string $opt_name Panel opt_name. |
|
| 357 | - * @param string|int $id Section ID. |
|
| 358 | - * |
|
| 359 | - * @deprecated 4.0.0 No more camelCase. |
|
| 360 | - * |
|
| 361 | - * @return bool |
|
| 362 | - */ |
|
| 363 | - public static function getSection( string $opt_name = '', $id = '' ): bool { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 364 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::get_section( $opt_name, $id )' ); |
|
| 365 | - |
|
| 366 | - return self::get_section( $opt_name, $id ); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Retrieve section ID. |
|
| 371 | - * |
|
| 372 | - * @param string $opt_name Panel opt_name. |
|
| 373 | - * @param string|int $id Section ID. |
|
| 374 | - * |
|
| 375 | - * @return bool |
|
| 376 | - */ |
|
| 377 | - public static function get_section( string $opt_name = '', $id = '' ): bool { |
|
| 378 | - self::check_opt_name( $opt_name ); |
|
| 379 | - |
|
| 380 | - if ( ! empty( $opt_name ) && ! empty( $id ) ) { |
|
| 381 | - if ( ! isset( self::$sections[ $opt_name ][ $id ] ) ) { |
|
| 382 | - $id = strtolower( sanitize_html_class( $id ) ); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - return self::$sections[ $opt_name ][ $id ] ?? false; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - return false; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * Set section array. |
|
| 393 | - * |
|
| 394 | - * @param string $opt_name Panel opt_name. |
|
| 395 | - * @param array $section Section array. |
|
| 396 | - * |
|
| 397 | - * @deprecated 4.0.0 No more camelCase. |
|
| 398 | - */ |
|
| 399 | - public static function setSection( string $opt_name = '', array $section = array() ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 400 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::set_section( $opt_name, $section )' ); |
|
| 401 | - |
|
| 402 | - self::set_section( $opt_name, $section ); |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * Set section array. |
|
| 407 | - * |
|
| 408 | - * @param string $opt_name Panel opt_name. |
|
| 409 | - * @param array $section Section array. |
|
| 410 | - */ |
|
| 411 | - public static function set_section( string $opt_name = '', array $section = array() ) { |
|
| 412 | - Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 413 | - |
|
| 414 | - self::check_opt_name( $opt_name ); |
|
| 415 | - |
|
| 416 | - if ( ! empty( $opt_name ) && is_array( $section ) && ! empty( $section ) ) { |
|
| 417 | - if ( ! isset( $section['id'] ) ) { |
|
| 418 | - if ( isset( $section['title'] ) ) { |
|
| 419 | - $section['id'] = strtolower( sanitize_html_class( $section['title'] ) ); |
|
| 420 | - } else { |
|
| 421 | - $section['id'] = 'section'; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - if ( isset( self::$sections[ $opt_name ][ $section['id'] ] ) ) { |
|
| 425 | - $orig = $section['id']; |
|
| 426 | - $i = 0; |
|
| 427 | - |
|
| 428 | - while ( isset( self::$sections[ $opt_name ][ $section['id'] ] ) ) { |
|
| 429 | - $section['id'] = $orig . '_' . $i; |
|
| 430 | - ++$i; |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - if ( ! isset( $section['priority'] ) ) { |
|
| 436 | - $section['priority'] = self::get_priority( $opt_name, 'sections' ); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - if ( isset( $section['fields'] ) ) { |
|
| 440 | - if ( ! empty( $section['fields'] ) && is_array( $section['fields'] ) ) { |
|
| 441 | - self::process_fields_array( $opt_name, $section['id'], $section['fields'] ); |
|
| 442 | - } |
|
| 443 | - unset( $section['fields'] ); |
|
| 444 | - } |
|
| 445 | - self::$sections[ $opt_name ][ $section['id'] ] = $section; |
|
| 446 | - |
|
| 447 | - } else { |
|
| 448 | - self::$errors[ $opt_name ]['section']['empty'] = esc_html__( 'Unable to create a section due an empty section array or the section variable passed was not an array.', 'redux-framework' ); |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * Process section arrays. |
|
| 454 | - * |
|
| 455 | - * @param string $opt_name Panel opt_name. |
|
| 456 | - * @param string|int $box_id Box ID. |
|
| 457 | - * @param array $sections Sections array. |
|
| 458 | - */ |
|
| 459 | - public static function process_sections_array( string $opt_name = '', $box_id = '', array $sections = array() ) { |
|
| 460 | - if ( ! empty( $opt_name ) && ! empty( $box_id ) && is_array( $sections ) && ! empty( $sections ) ) { |
|
| 461 | - foreach ( $sections as $section ) { |
|
| 462 | - if ( ! is_array( $section ) ) { |
|
| 463 | - continue; |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - $section['box_id'] = $box_id; |
|
| 467 | - |
|
| 468 | - if ( ! isset( $section['fields'] ) || ! is_array( $section['fields'] ) ) { |
|
| 469 | - $section['fields'] = array(); |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - self::set_section( $opt_name, $section ); |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * Process Field arrays. |
|
| 479 | - * |
|
| 480 | - * @param string $opt_name Panel opt_name. |
|
| 481 | - * @param string|int $section_id Section ID. |
|
| 482 | - * @param array $fields Field arrays. |
|
| 483 | - * |
|
| 484 | - * @deprecated 4.0.0 No more camelCase. |
|
| 485 | - */ |
|
| 486 | - public static function processFieldsArray( string $opt_name = '', $section_id = '', array $fields = array() ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 487 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::process_fields_array( $opt_name, $section_id, $fields )' ); |
|
| 488 | - |
|
| 489 | - self::process_fields_array( $opt_name, $section_id, $fields ); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * Process Field arrays. |
|
| 494 | - * |
|
| 495 | - * @param string $opt_name Panel opt_name. |
|
| 496 | - * @param string|int $section_id Section ID. |
|
| 497 | - * @param array $fields Field arrays. |
|
| 498 | - */ |
|
| 499 | - public static function process_fields_array( string $opt_name = '', $section_id = '', array $fields = array() ) { |
|
| 500 | - if ( ! empty( $opt_name ) && ! empty( $section_id ) && is_array( $fields ) && ! empty( $fields ) ) { |
|
| 501 | - |
|
| 502 | - foreach ( $fields as $field ) { |
|
| 503 | - if ( ! is_array( $field ) ) { |
|
| 504 | - continue; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - $field['section_id'] = $section_id; |
|
| 508 | - |
|
| 509 | - self::set_field( $opt_name, $field ); |
|
| 510 | - } |
|
| 511 | - } |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * Retrieves the field array. |
|
| 516 | - * |
|
| 517 | - * @param string $opt_name Panel opt_name. |
|
| 518 | - * @param string|int $id Field ID. |
|
| 519 | - * |
|
| 520 | - * @deprecated 4.0.0 No more camelCase. |
|
| 521 | - * |
|
| 522 | - * @return bool |
|
| 523 | - */ |
|
| 524 | - public static function getField( string $opt_name = '', $id = '' ): bool { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 525 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::get_field( $opt_name, $id )' ); |
|
| 526 | - |
|
| 527 | - return self::get_field( $opt_name, $id ); |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - /** |
|
| 531 | - * Retrieves the field array. |
|
| 532 | - * |
|
| 533 | - * @param string $opt_name Panel opt_name. |
|
| 534 | - * @param string|int $id Field ID. |
|
| 535 | - * |
|
| 536 | - * @return bool |
|
| 537 | - */ |
|
| 538 | - public static function get_field( string $opt_name = '', $id = '' ): bool { |
|
| 539 | - self::check_opt_name( $opt_name ); |
|
| 540 | - |
|
| 541 | - if ( ! empty( $opt_name ) && ! empty( $id ) ) { |
|
| 542 | - return self::$fields[ $opt_name ][ $id ] ?? false; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - return false; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - /** |
|
| 549 | - * Set field array. |
|
| 550 | - * |
|
| 551 | - * @param string $opt_name Panel opt_name. |
|
| 552 | - * @param array $field Field array. |
|
| 553 | - * |
|
| 554 | - * @deprecated 4.0.0 No more camelCase. |
|
| 555 | - */ |
|
| 556 | - public static function setField( string $opt_name = '', array $field = array() ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 557 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::set_field( $opt_name, $field )' ); |
|
| 558 | - |
|
| 559 | - self::set_field( $opt_name, $field ); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - /** |
|
| 563 | - * Set field array. |
|
| 564 | - * |
|
| 565 | - * @param string $opt_name Panel opt_name. |
|
| 566 | - * @param array $field Field array. |
|
| 567 | - */ |
|
| 568 | - public static function set_field( string $opt_name = '', array $field = array() ) { |
|
| 569 | - Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 570 | - |
|
| 571 | - self::check_opt_name( $opt_name ); |
|
| 572 | - |
|
| 573 | - if ( ! empty( $opt_name ) && is_array( $field ) && ! empty( $field ) ) { |
|
| 574 | - if ( ! isset( $field['priority'] ) ) { |
|
| 575 | - $field['priority'] = self::get_priority( $opt_name, 'fields' ); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - self::$fields[ $opt_name ][ $field['id'] ] = $field; |
|
| 579 | - } |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - /** |
|
| 583 | - * Set metabox box. |
|
| 584 | - * |
|
| 585 | - * @param string $opt_name Panel opt_name. |
|
| 586 | - * @param array $box Box array. |
|
| 587 | - * |
|
| 588 | - * @deprecated 4.0.0 No more camelCase. |
|
| 589 | - */ |
|
| 590 | - public static function setBox( string $opt_name = '', array $box = array() ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 591 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::set_box( $opt_name, $box )' ); |
|
| 592 | - |
|
| 593 | - self::set_box( $opt_name, $box ); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - /** |
|
| 597 | - * Set metabox box. |
|
| 598 | - * |
|
| 599 | - * @param string $opt_name Panel opt_name. |
|
| 600 | - * @param array $box Box array. |
|
| 601 | - */ |
|
| 602 | - public static function set_box( string $opt_name = '', array $box = array() ) { |
|
| 603 | - Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 604 | - |
|
| 605 | - self::check_opt_name( $opt_name ); |
|
| 606 | - |
|
| 607 | - if ( ! empty( $opt_name ) && is_array( $box ) && ! empty( $box ) ) { |
|
| 608 | - if ( ! isset( $box['id'] ) ) { |
|
| 609 | - if ( isset( $box['title'] ) ) { |
|
| 610 | - $box['id'] = strtolower( sanitize_html_class( $box['title'] ) ); |
|
| 611 | - } else { |
|
| 612 | - $box['id'] = 'box'; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - if ( isset( self::$boxes[ $opt_name ][ $box['id'] ] ) ) { |
|
| 616 | - $orig = $box['id']; |
|
| 617 | - $i = 0; |
|
| 618 | - |
|
| 619 | - while ( isset( self::$boxes[ $opt_name ][ $box['id'] ] ) ) { |
|
| 620 | - $box['id'] = $orig . '_' . $i; |
|
| 621 | - ++$i; |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - if ( isset( $box['sections'] ) ) { |
|
| 627 | - if ( ! empty( $box['sections'] ) && is_array( $box['sections'] ) ) { |
|
| 628 | - self::process_sections_array( $opt_name, $box['id'], $box['sections'] ); |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - unset( $box['sections'] ); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - self::$boxes[ $opt_name ][ $box['id'] ] = $box; |
|
| 635 | - } else { |
|
| 636 | - self::$errors[ $opt_name ]['box']['empty'] = esc_html__( 'Unable to create a box due an empty box array or the box variable passed was not an array.', 'redux-framework' ); |
|
| 637 | - } |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * Set Metaboxes. |
|
| 642 | - * |
|
| 643 | - * @param string $opt_name Panel opt_name. |
|
| 644 | - * @param array $boxes Boxes array. |
|
| 645 | - * |
|
| 646 | - * @deprecated 4.0.0 No more camelCase. |
|
| 647 | - */ |
|
| 648 | - public static function setBoxes( string $opt_name = '', array $boxes = array() ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 649 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::set_boxes( $opt_name, $boxes )' ); |
|
| 650 | - |
|
| 651 | - self::set_boxes( $opt_name, $boxes ); |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - /** |
|
| 655 | - * Set Metaboxes. |
|
| 656 | - * |
|
| 657 | - * @param string $opt_name Panel opt_name. |
|
| 658 | - * @param array $boxes Boxes array. |
|
| 659 | - */ |
|
| 660 | - public static function set_boxes( string $opt_name = '', array $boxes = array() ) { |
|
| 661 | - Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 662 | - |
|
| 663 | - if ( ! empty( $boxes ) && is_array( $boxes ) ) { |
|
| 664 | - foreach ( $boxes as $box ) { |
|
| 665 | - self::set_box( $opt_name, $box ); |
|
| 666 | - } |
|
| 667 | - } |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - /** |
|
| 671 | - * Retrieve Metabox arrays. |
|
| 672 | - * |
|
| 673 | - * @param string $opt_name Panel opt_name. |
|
| 674 | - * |
|
| 675 | - * @deprecated 4.0.0 No more camelCase. |
|
| 676 | - * |
|
| 677 | - * @return mixed |
|
| 678 | - */ |
|
| 679 | - public static function getBoxes( string $opt_name = '' ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 680 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::get_boxes( $opt_name )' ); |
|
| 681 | - |
|
| 682 | - return self::get_boxes( $opt_name ); |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - /** |
|
| 686 | - * Retrieve Metabox arrays. |
|
| 687 | - * |
|
| 688 | - * @param string $opt_name Panel opt_name. |
|
| 689 | - * |
|
| 690 | - * @return mixed |
|
| 691 | - */ |
|
| 692 | - public static function get_boxes( string $opt_name = '' ) { |
|
| 693 | - self::check_opt_name( $opt_name ); |
|
| 694 | - |
|
| 695 | - if ( ! empty( $opt_name ) && ! empty( self::$boxes[ $opt_name ] ) ) { |
|
| 696 | - return self::$boxes[ $opt_name ]; |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - return null; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * Get Metabox box. |
|
| 704 | - * |
|
| 705 | - * @param string $opt_name Panel opt_name. |
|
| 706 | - * @param string $key Box key. |
|
| 707 | - * |
|
| 708 | - * @deprecated 4.0.0 No more camelCase. |
|
| 709 | - * |
|
| 710 | - * @return mixed |
|
| 711 | - */ |
|
| 712 | - public static function getBox( string $opt_name = '', string $key = '' ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 713 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::get_box( $opt_name, $key )' ); |
|
| 714 | - |
|
| 715 | - return self::get_box( $opt_name, $key ); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * Get Metabox box. |
|
| 720 | - * |
|
| 721 | - * @param string $opt_name Panel opt_name. |
|
| 722 | - * @param string $key Box key. |
|
| 723 | - * |
|
| 724 | - * @return mixed |
|
| 725 | - */ |
|
| 726 | - public static function get_box( string $opt_name = '', string $key = '' ) { |
|
| 727 | - self::check_opt_name( $opt_name ); |
|
| 728 | - |
|
| 729 | - if ( ! empty( $opt_name ) && ! empty( $key ) && ! empty( self::$boxes[ $opt_name ] ) && isset( self::$boxes[ $opt_name ][ $key ] ) ) { |
|
| 730 | - return self::$boxes[ $opt_name ][ $key ]; |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - return null; |
|
| 734 | - } |
|
| 735 | - |
|
| 736 | - /** |
|
| 737 | - * Get priority. |
|
| 738 | - * |
|
| 739 | - * @param string $opt_name Panel opt_name. |
|
| 740 | - * @param string $type Type. |
|
| 741 | - * |
|
| 742 | - * @return mixed |
|
| 743 | - * |
|
| 744 | - * @deprecated 4.0.0 No more camelCase. |
|
| 745 | - */ |
|
| 746 | - public static function getPriority( string $opt_name, string $type ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 747 | - _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::get_priority( $opt_name, $type )' ); |
|
| 748 | - |
|
| 749 | - return self::get_priority( $opt_name, $type ); |
|
| 750 | - } |
|
| 751 | - |
|
| 752 | - /** |
|
| 753 | - * Get priority. |
|
| 754 | - * |
|
| 755 | - * @param string $opt_name Panel opt_name. |
|
| 756 | - * @param string $type Type. |
|
| 757 | - * |
|
| 758 | - * @return mixed |
|
| 759 | - */ |
|
| 760 | - public static function get_priority( string $opt_name, string $type ) { |
|
| 761 | - $priority = self::$priority[ $opt_name ][ $type ]; |
|
| 762 | - self::$priority[ $opt_name ][ $type ] += 1; |
|
| 763 | - |
|
| 764 | - return $priority; |
|
| 765 | - } |
|
| 766 | - |
|
| 767 | - /** |
|
| 768 | - * Check opt_name. |
|
| 769 | - * |
|
| 770 | - * @param string $opt_name Panel opt_name. |
|
| 771 | - */ |
|
| 772 | - public static function check_opt_name( string $opt_name = '' ) { |
|
| 773 | - if ( empty( $opt_name ) || is_array( $opt_name ) ) { |
|
| 774 | - return; |
|
| 775 | - } |
|
| 776 | - |
|
| 777 | - if ( ! isset( self::$boxes[ $opt_name ] ) ) { |
|
| 778 | - self::$boxes[ $opt_name ] = array(); |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - if ( ! isset( self::$priority[ $opt_name ] ) ) { |
|
| 782 | - self::$priority[ $opt_name ]['args'] = 1; |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - if ( ! isset( self::$sections[ $opt_name ] ) ) { |
|
| 786 | - self::$sections[ $opt_name ] = array(); |
|
| 787 | - self::$priority[ $opt_name ]['sections'] = 1; |
|
| 788 | - } |
|
| 789 | - |
|
| 790 | - if ( ! isset( self::$fields[ $opt_name ] ) ) { |
|
| 791 | - self::$fields[ $opt_name ] = array(); |
|
| 792 | - self::$priority[ $opt_name ]['fields'] = 1; |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - if ( ! isset( self::$errors[ $opt_name ] ) ) { |
|
| 796 | - self::$errors[ $opt_name ] = array(); |
|
| 797 | - } |
|
| 798 | - |
|
| 799 | - if ( ! isset( self::$init[ $opt_name ] ) ) { |
|
| 800 | - self::$init[ $opt_name ] = false; |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - if ( ! isset( self::$args[ $opt_name ] ) ) { |
|
| 804 | - self::$args[ $opt_name ] = false; |
|
| 805 | - } |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - Redux_Metaboxes::load(); |
|
| 17 | + /** |
|
| 18 | + * Redux Metaboxes API Class |
|
| 19 | + * Simple API for Redux Framework |
|
| 20 | + * |
|
| 21 | + * @since 1.0.0 |
|
| 22 | + */ |
|
| 23 | + class Redux_Metaboxes { |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Boxes array. |
|
| 27 | + * |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + public static array $boxes = array(); |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Sections array. |
|
| 34 | + * |
|
| 35 | + * @var array |
|
| 36 | + */ |
|
| 37 | + public static array $sections = array(); |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Fields array. |
|
| 41 | + * |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + public static array $fields = array(); |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Priority array. |
|
| 48 | + * |
|
| 49 | + * @var array |
|
| 50 | + */ |
|
| 51 | + public static array $priority = array(); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Errors array. |
|
| 55 | + * |
|
| 56 | + * @var array |
|
| 57 | + */ |
|
| 58 | + public static array $errors = array(); |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Init array. |
|
| 62 | + * |
|
| 63 | + * @var array |
|
| 64 | + */ |
|
| 65 | + public static array $init = array(); |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Args array. |
|
| 69 | + * |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | + public static array $args = array(); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Code has run flag. |
|
| 76 | + * |
|
| 77 | + * @var bool |
|
| 78 | + */ |
|
| 79 | + public static bool $has_run = false; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Class load. |
|
| 83 | + */ |
|
| 84 | + public static function load() { |
|
| 85 | + if ( version_compare( PHP_VERSION, '5.5.0', '<' ) ) { |
|
| 86 | + include_once Redux_Core::$dir . 'inc/lib/array-column.php'; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + add_action( 'init', array( 'Redux_Metaboxes', 'enqueue' ), 99 ); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Enqueue function. |
|
| 94 | + * |
|
| 95 | + * @throws ReflectionException Exception. |
|
| 96 | + */ |
|
| 97 | + public static function enqueue() { |
|
| 98 | + global $pagenow; |
|
| 99 | + |
|
| 100 | + // Check and run instances of Redux where the opt_name hasn't been run. |
|
| 101 | + $pagenows = array( 'post-new.php', 'post.php' ); |
|
| 102 | + if ( ! empty( self::$sections ) && in_array( $pagenow, $pagenows, true ) ) { |
|
| 103 | + $instances = ReduxFrameworkInstances::get_all_instances(); |
|
| 104 | + |
|
| 105 | + foreach ( self::$fields as $opt_name => $fields ) { |
|
| 106 | + if ( ! isset( $instances[ $opt_name ] ) ) { |
|
| 107 | + Redux::set_args( |
|
| 108 | + $opt_name, |
|
| 109 | + array( |
|
| 110 | + 'menu_type' => 'hidden', |
|
| 111 | + ) |
|
| 112 | + ); |
|
| 113 | + |
|
| 114 | + Redux::set_sections( |
|
| 115 | + $opt_name, |
|
| 116 | + array( |
|
| 117 | + array( |
|
| 118 | + 'id' => 'EXTENSION_FAKE_ID' . $opt_name, |
|
| 119 | + 'fields' => $fields, |
|
| 120 | + 'title' => 'N/A', |
|
| 121 | + ), |
|
| 122 | + ) |
|
| 123 | + ); |
|
| 124 | + |
|
| 125 | + Redux::init( $opt_name ); |
|
| 126 | + |
|
| 127 | + $instances = ReduxFrameworkInstances::get_all_instances(); |
|
| 128 | + |
|
| 129 | + add_action( 'admin_enqueue_scripts', array( $instances[ $opt_name ], 'enqueue' ), 1 ); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Filter Metaboxes function. |
|
| 137 | + * |
|
| 138 | + * @deprecated 4.0.0 No more camelCase. |
|
| 139 | + */ |
|
| 140 | + public static function filterMetaboxes() { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 141 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::filter_metaboxes()' ); |
|
| 142 | + |
|
| 143 | + self::filter_metaboxes(); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Filter Metaboxes function. |
|
| 148 | + */ |
|
| 149 | + public static function filter_metaboxes() { |
|
| 150 | + if ( true === self::$has_run ) { |
|
| 151 | + return; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + if ( ! class_exists( 'ReduxFramework' ) ) { |
|
| 155 | + echo '<div id="message" class="error"><p>Redux Framework is <strong>not installed</strong>. Please install it.</p></div>'; |
|
| 156 | + |
|
| 157 | + return; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + foreach ( self::$boxes as $opt_name => $the_boxes ) { |
|
| 161 | + if ( ! self::$init[ $opt_name ] ) { |
|
| 162 | + |
|
| 163 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 164 | + add_action( 'redux/metaboxes/' . $opt_name . '/boxes', array( 'Redux_Metaboxes', 'addMetaboxes' ), 2 ); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + self::$has_run = true; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Construct the global args array. |
|
| 173 | + * |
|
| 174 | + * @param string $opt_name Panel opt_name. |
|
| 175 | + * |
|
| 176 | + * @return mixed |
|
| 177 | + * @deprecated 4.0.0 No more camelCase. |
|
| 178 | + */ |
|
| 179 | + public static function constructArgs( string $opt_name ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 180 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::construct_args( $opt_name )' ); |
|
| 181 | + |
|
| 182 | + return self::construct_args( $opt_name ); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * Construct the global args array. |
|
| 187 | + * |
|
| 188 | + * @param string $opt_name Panel opt_name. |
|
| 189 | + * |
|
| 190 | + * @return mixed |
|
| 191 | + */ |
|
| 192 | + public static function construct_args( string $opt_name ) { |
|
| 193 | + Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 194 | + |
|
| 195 | + $args = self::$args[ $opt_name ]; |
|
| 196 | + $args['opt_name'] = $opt_name; |
|
| 197 | + |
|
| 198 | + if ( ! isset( $args['menu_title'] ) ) { |
|
| 199 | + $args['menu_title'] = ucfirst( $opt_name ) . ' Options'; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if ( ! isset( $args['page_title'] ) ) { |
|
| 203 | + $args['page_title'] = ucfirst( $opt_name ) . ' Options'; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ( ! isset( $args['page_slug'] ) ) { |
|
| 207 | + $args['page_slug'] = $opt_name . '_options'; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + return $args; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Construct metabox boxes array. |
|
| 215 | + * |
|
| 216 | + * @param string $opt_name Panel opt_name. |
|
| 217 | + * |
|
| 218 | + * @return array |
|
| 219 | + * |
|
| 220 | + * @deprecated 4.0.0 No more camelCase. |
|
| 221 | + */ |
|
| 222 | + public static function constructBoxes( string $opt_name ): array { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 223 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::construct_boxes( $opt_name )' ); |
|
| 224 | + |
|
| 225 | + return self::construct_boxes( $opt_name ); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Construct metabox boxes array. |
|
| 231 | + * |
|
| 232 | + * @param string $opt_name Panel opt_name. |
|
| 233 | + * |
|
| 234 | + * @return array |
|
| 235 | + */ |
|
| 236 | + public static function construct_boxes( string $opt_name ): array { |
|
| 237 | + Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 238 | + |
|
| 239 | + $boxes = array(); |
|
| 240 | + if ( ! isset( self::$boxes[ $opt_name ] ) ) { |
|
| 241 | + return $boxes; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + foreach ( self::$boxes[ $opt_name ] as $box ) { |
|
| 245 | + $box['sections'] = self::construct_sections( $opt_name, $box['id'] ); |
|
| 246 | + $boxes[] = $box; |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + ksort( $boxes ); |
|
| 250 | + |
|
| 251 | + return $boxes; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Construct sections. |
|
| 256 | + * |
|
| 257 | + * @param string $opt_name Panel opt_name. |
|
| 258 | + * @param string $box_id Metabox ID. |
|
| 259 | + * |
|
| 260 | + * @return array |
|
| 261 | + * |
|
| 262 | + * @deprecated 4.0.0 No more camelCase. |
|
| 263 | + */ |
|
| 264 | + public static function constructSections( string $opt_name, string $box_id ): array { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 265 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::construct_sections( $opt_name, $box_id )' ); |
|
| 266 | + |
|
| 267 | + return self::construct_sections( $opt_name, $box_id ); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * Construct sections. |
|
| 272 | + * |
|
| 273 | + * @param string $opt_name Panel opt_name. |
|
| 274 | + * @param string $box_id Metabox ID. |
|
| 275 | + * |
|
| 276 | + * @return array |
|
| 277 | + */ |
|
| 278 | + public static function construct_sections( string $opt_name, string $box_id ): array { |
|
| 279 | + Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 280 | + |
|
| 281 | + $sections = array(); |
|
| 282 | + if ( ! isset( self::$sections[ $opt_name ] ) ) { |
|
| 283 | + return $sections; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + foreach ( self::$sections[ $opt_name ] as $section_id => $section ) { |
|
| 287 | + if ( $box_id === $section['box_id'] ) { |
|
| 288 | + $p = $section['priority']; |
|
| 289 | + |
|
| 290 | + while ( isset( $sections[ $p ] ) ) { |
|
| 291 | + echo esc_html( $p++ ); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + $section['fields'] = self::construct_fields( $opt_name, $section_id ); |
|
| 295 | + $sections[ $p ] = $section; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + ksort( $sections ); |
|
| 300 | + |
|
| 301 | + return $sections; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Construct fields. |
|
| 306 | + * |
|
| 307 | + * @param string $opt_name Panel opt_name. |
|
| 308 | + * @param string|int $section_id Section ID. |
|
| 309 | + * |
|
| 310 | + * @return array |
|
| 311 | + * @deprecated 4.0.0 No moe camelCase. |
|
| 312 | + */ |
|
| 313 | + public static function constructFields( string $opt_name = '', $section_id = '' ): array { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 314 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::construct_fields( $opt_name, $section_id )' ); |
|
| 315 | + |
|
| 316 | + return self::construct_fields( $opt_name, $section_id ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Construct fields. |
|
| 321 | + * |
|
| 322 | + * @param string $opt_name Panel opt_name. |
|
| 323 | + * @param string|int $section_id Section ID. |
|
| 324 | + * |
|
| 325 | + * @return array |
|
| 326 | + */ |
|
| 327 | + public static function construct_fields( string $opt_name = '', $section_id = '' ): array { |
|
| 328 | + Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 329 | + |
|
| 330 | + $fields = array(); |
|
| 331 | + |
|
| 332 | + if ( ! isset( self::$fields[ $opt_name ] ) ) { |
|
| 333 | + return $fields; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + foreach ( self::$fields[ $opt_name ] as $field ) { |
|
| 337 | + if ( $section_id === $field['section_id'] ) { |
|
| 338 | + $p = $field['priority']; |
|
| 339 | + |
|
| 340 | + while ( isset( $fields[ $p ] ) ) { |
|
| 341 | + echo esc_html( $p++ ); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + $fields[ $p ] = $field; |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + ksort( $fields ); |
|
| 349 | + |
|
| 350 | + return $fields; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Retrieve the section array. |
|
| 355 | + * |
|
| 356 | + * @param string $opt_name Panel opt_name. |
|
| 357 | + * @param string|int $id Section ID. |
|
| 358 | + * |
|
| 359 | + * @deprecated 4.0.0 No more camelCase. |
|
| 360 | + * |
|
| 361 | + * @return bool |
|
| 362 | + */ |
|
| 363 | + public static function getSection( string $opt_name = '', $id = '' ): bool { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 364 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::get_section( $opt_name, $id )' ); |
|
| 365 | + |
|
| 366 | + return self::get_section( $opt_name, $id ); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Retrieve section ID. |
|
| 371 | + * |
|
| 372 | + * @param string $opt_name Panel opt_name. |
|
| 373 | + * @param string|int $id Section ID. |
|
| 374 | + * |
|
| 375 | + * @return bool |
|
| 376 | + */ |
|
| 377 | + public static function get_section( string $opt_name = '', $id = '' ): bool { |
|
| 378 | + self::check_opt_name( $opt_name ); |
|
| 379 | + |
|
| 380 | + if ( ! empty( $opt_name ) && ! empty( $id ) ) { |
|
| 381 | + if ( ! isset( self::$sections[ $opt_name ][ $id ] ) ) { |
|
| 382 | + $id = strtolower( sanitize_html_class( $id ) ); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + return self::$sections[ $opt_name ][ $id ] ?? false; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + return false; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * Set section array. |
|
| 393 | + * |
|
| 394 | + * @param string $opt_name Panel opt_name. |
|
| 395 | + * @param array $section Section array. |
|
| 396 | + * |
|
| 397 | + * @deprecated 4.0.0 No more camelCase. |
|
| 398 | + */ |
|
| 399 | + public static function setSection( string $opt_name = '', array $section = array() ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 400 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::set_section( $opt_name, $section )' ); |
|
| 401 | + |
|
| 402 | + self::set_section( $opt_name, $section ); |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * Set section array. |
|
| 407 | + * |
|
| 408 | + * @param string $opt_name Panel opt_name. |
|
| 409 | + * @param array $section Section array. |
|
| 410 | + */ |
|
| 411 | + public static function set_section( string $opt_name = '', array $section = array() ) { |
|
| 412 | + Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 413 | + |
|
| 414 | + self::check_opt_name( $opt_name ); |
|
| 415 | + |
|
| 416 | + if ( ! empty( $opt_name ) && is_array( $section ) && ! empty( $section ) ) { |
|
| 417 | + if ( ! isset( $section['id'] ) ) { |
|
| 418 | + if ( isset( $section['title'] ) ) { |
|
| 419 | + $section['id'] = strtolower( sanitize_html_class( $section['title'] ) ); |
|
| 420 | + } else { |
|
| 421 | + $section['id'] = 'section'; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + if ( isset( self::$sections[ $opt_name ][ $section['id'] ] ) ) { |
|
| 425 | + $orig = $section['id']; |
|
| 426 | + $i = 0; |
|
| 427 | + |
|
| 428 | + while ( isset( self::$sections[ $opt_name ][ $section['id'] ] ) ) { |
|
| 429 | + $section['id'] = $orig . '_' . $i; |
|
| 430 | + ++$i; |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + if ( ! isset( $section['priority'] ) ) { |
|
| 436 | + $section['priority'] = self::get_priority( $opt_name, 'sections' ); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + if ( isset( $section['fields'] ) ) { |
|
| 440 | + if ( ! empty( $section['fields'] ) && is_array( $section['fields'] ) ) { |
|
| 441 | + self::process_fields_array( $opt_name, $section['id'], $section['fields'] ); |
|
| 442 | + } |
|
| 443 | + unset( $section['fields'] ); |
|
| 444 | + } |
|
| 445 | + self::$sections[ $opt_name ][ $section['id'] ] = $section; |
|
| 446 | + |
|
| 447 | + } else { |
|
| 448 | + self::$errors[ $opt_name ]['section']['empty'] = esc_html__( 'Unable to create a section due an empty section array or the section variable passed was not an array.', 'redux-framework' ); |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * Process section arrays. |
|
| 454 | + * |
|
| 455 | + * @param string $opt_name Panel opt_name. |
|
| 456 | + * @param string|int $box_id Box ID. |
|
| 457 | + * @param array $sections Sections array. |
|
| 458 | + */ |
|
| 459 | + public static function process_sections_array( string $opt_name = '', $box_id = '', array $sections = array() ) { |
|
| 460 | + if ( ! empty( $opt_name ) && ! empty( $box_id ) && is_array( $sections ) && ! empty( $sections ) ) { |
|
| 461 | + foreach ( $sections as $section ) { |
|
| 462 | + if ( ! is_array( $section ) ) { |
|
| 463 | + continue; |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + $section['box_id'] = $box_id; |
|
| 467 | + |
|
| 468 | + if ( ! isset( $section['fields'] ) || ! is_array( $section['fields'] ) ) { |
|
| 469 | + $section['fields'] = array(); |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + self::set_section( $opt_name, $section ); |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * Process Field arrays. |
|
| 479 | + * |
|
| 480 | + * @param string $opt_name Panel opt_name. |
|
| 481 | + * @param string|int $section_id Section ID. |
|
| 482 | + * @param array $fields Field arrays. |
|
| 483 | + * |
|
| 484 | + * @deprecated 4.0.0 No more camelCase. |
|
| 485 | + */ |
|
| 486 | + public static function processFieldsArray( string $opt_name = '', $section_id = '', array $fields = array() ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 487 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::process_fields_array( $opt_name, $section_id, $fields )' ); |
|
| 488 | + |
|
| 489 | + self::process_fields_array( $opt_name, $section_id, $fields ); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * Process Field arrays. |
|
| 494 | + * |
|
| 495 | + * @param string $opt_name Panel opt_name. |
|
| 496 | + * @param string|int $section_id Section ID. |
|
| 497 | + * @param array $fields Field arrays. |
|
| 498 | + */ |
|
| 499 | + public static function process_fields_array( string $opt_name = '', $section_id = '', array $fields = array() ) { |
|
| 500 | + if ( ! empty( $opt_name ) && ! empty( $section_id ) && is_array( $fields ) && ! empty( $fields ) ) { |
|
| 501 | + |
|
| 502 | + foreach ( $fields as $field ) { |
|
| 503 | + if ( ! is_array( $field ) ) { |
|
| 504 | + continue; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + $field['section_id'] = $section_id; |
|
| 508 | + |
|
| 509 | + self::set_field( $opt_name, $field ); |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * Retrieves the field array. |
|
| 516 | + * |
|
| 517 | + * @param string $opt_name Panel opt_name. |
|
| 518 | + * @param string|int $id Field ID. |
|
| 519 | + * |
|
| 520 | + * @deprecated 4.0.0 No more camelCase. |
|
| 521 | + * |
|
| 522 | + * @return bool |
|
| 523 | + */ |
|
| 524 | + public static function getField( string $opt_name = '', $id = '' ): bool { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 525 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::get_field( $opt_name, $id )' ); |
|
| 526 | + |
|
| 527 | + return self::get_field( $opt_name, $id ); |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + /** |
|
| 531 | + * Retrieves the field array. |
|
| 532 | + * |
|
| 533 | + * @param string $opt_name Panel opt_name. |
|
| 534 | + * @param string|int $id Field ID. |
|
| 535 | + * |
|
| 536 | + * @return bool |
|
| 537 | + */ |
|
| 538 | + public static function get_field( string $opt_name = '', $id = '' ): bool { |
|
| 539 | + self::check_opt_name( $opt_name ); |
|
| 540 | + |
|
| 541 | + if ( ! empty( $opt_name ) && ! empty( $id ) ) { |
|
| 542 | + return self::$fields[ $opt_name ][ $id ] ?? false; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + return false; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + /** |
|
| 549 | + * Set field array. |
|
| 550 | + * |
|
| 551 | + * @param string $opt_name Panel opt_name. |
|
| 552 | + * @param array $field Field array. |
|
| 553 | + * |
|
| 554 | + * @deprecated 4.0.0 No more camelCase. |
|
| 555 | + */ |
|
| 556 | + public static function setField( string $opt_name = '', array $field = array() ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 557 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::set_field( $opt_name, $field )' ); |
|
| 558 | + |
|
| 559 | + self::set_field( $opt_name, $field ); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + /** |
|
| 563 | + * Set field array. |
|
| 564 | + * |
|
| 565 | + * @param string $opt_name Panel opt_name. |
|
| 566 | + * @param array $field Field array. |
|
| 567 | + */ |
|
| 568 | + public static function set_field( string $opt_name = '', array $field = array() ) { |
|
| 569 | + Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 570 | + |
|
| 571 | + self::check_opt_name( $opt_name ); |
|
| 572 | + |
|
| 573 | + if ( ! empty( $opt_name ) && is_array( $field ) && ! empty( $field ) ) { |
|
| 574 | + if ( ! isset( $field['priority'] ) ) { |
|
| 575 | + $field['priority'] = self::get_priority( $opt_name, 'fields' ); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + self::$fields[ $opt_name ][ $field['id'] ] = $field; |
|
| 579 | + } |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + /** |
|
| 583 | + * Set metabox box. |
|
| 584 | + * |
|
| 585 | + * @param string $opt_name Panel opt_name. |
|
| 586 | + * @param array $box Box array. |
|
| 587 | + * |
|
| 588 | + * @deprecated 4.0.0 No more camelCase. |
|
| 589 | + */ |
|
| 590 | + public static function setBox( string $opt_name = '', array $box = array() ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 591 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::set_box( $opt_name, $box )' ); |
|
| 592 | + |
|
| 593 | + self::set_box( $opt_name, $box ); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + /** |
|
| 597 | + * Set metabox box. |
|
| 598 | + * |
|
| 599 | + * @param string $opt_name Panel opt_name. |
|
| 600 | + * @param array $box Box array. |
|
| 601 | + */ |
|
| 602 | + public static function set_box( string $opt_name = '', array $box = array() ) { |
|
| 603 | + Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 604 | + |
|
| 605 | + self::check_opt_name( $opt_name ); |
|
| 606 | + |
|
| 607 | + if ( ! empty( $opt_name ) && is_array( $box ) && ! empty( $box ) ) { |
|
| 608 | + if ( ! isset( $box['id'] ) ) { |
|
| 609 | + if ( isset( $box['title'] ) ) { |
|
| 610 | + $box['id'] = strtolower( sanitize_html_class( $box['title'] ) ); |
|
| 611 | + } else { |
|
| 612 | + $box['id'] = 'box'; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + if ( isset( self::$boxes[ $opt_name ][ $box['id'] ] ) ) { |
|
| 616 | + $orig = $box['id']; |
|
| 617 | + $i = 0; |
|
| 618 | + |
|
| 619 | + while ( isset( self::$boxes[ $opt_name ][ $box['id'] ] ) ) { |
|
| 620 | + $box['id'] = $orig . '_' . $i; |
|
| 621 | + ++$i; |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + if ( isset( $box['sections'] ) ) { |
|
| 627 | + if ( ! empty( $box['sections'] ) && is_array( $box['sections'] ) ) { |
|
| 628 | + self::process_sections_array( $opt_name, $box['id'], $box['sections'] ); |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + unset( $box['sections'] ); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + self::$boxes[ $opt_name ][ $box['id'] ] = $box; |
|
| 635 | + } else { |
|
| 636 | + self::$errors[ $opt_name ]['box']['empty'] = esc_html__( 'Unable to create a box due an empty box array or the box variable passed was not an array.', 'redux-framework' ); |
|
| 637 | + } |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * Set Metaboxes. |
|
| 642 | + * |
|
| 643 | + * @param string $opt_name Panel opt_name. |
|
| 644 | + * @param array $boxes Boxes array. |
|
| 645 | + * |
|
| 646 | + * @deprecated 4.0.0 No more camelCase. |
|
| 647 | + */ |
|
| 648 | + public static function setBoxes( string $opt_name = '', array $boxes = array() ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 649 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::set_boxes( $opt_name, $boxes )' ); |
|
| 650 | + |
|
| 651 | + self::set_boxes( $opt_name, $boxes ); |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + /** |
|
| 655 | + * Set Metaboxes. |
|
| 656 | + * |
|
| 657 | + * @param string $opt_name Panel opt_name. |
|
| 658 | + * @param array $boxes Boxes array. |
|
| 659 | + */ |
|
| 660 | + public static function set_boxes( string $opt_name = '', array $boxes = array() ) { |
|
| 661 | + Redux_Functions_Ex::record_caller( $opt_name ); |
|
| 662 | + |
|
| 663 | + if ( ! empty( $boxes ) && is_array( $boxes ) ) { |
|
| 664 | + foreach ( $boxes as $box ) { |
|
| 665 | + self::set_box( $opt_name, $box ); |
|
| 666 | + } |
|
| 667 | + } |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + /** |
|
| 671 | + * Retrieve Metabox arrays. |
|
| 672 | + * |
|
| 673 | + * @param string $opt_name Panel opt_name. |
|
| 674 | + * |
|
| 675 | + * @deprecated 4.0.0 No more camelCase. |
|
| 676 | + * |
|
| 677 | + * @return mixed |
|
| 678 | + */ |
|
| 679 | + public static function getBoxes( string $opt_name = '' ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 680 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::get_boxes( $opt_name )' ); |
|
| 681 | + |
|
| 682 | + return self::get_boxes( $opt_name ); |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + /** |
|
| 686 | + * Retrieve Metabox arrays. |
|
| 687 | + * |
|
| 688 | + * @param string $opt_name Panel opt_name. |
|
| 689 | + * |
|
| 690 | + * @return mixed |
|
| 691 | + */ |
|
| 692 | + public static function get_boxes( string $opt_name = '' ) { |
|
| 693 | + self::check_opt_name( $opt_name ); |
|
| 694 | + |
|
| 695 | + if ( ! empty( $opt_name ) && ! empty( self::$boxes[ $opt_name ] ) ) { |
|
| 696 | + return self::$boxes[ $opt_name ]; |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + return null; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * Get Metabox box. |
|
| 704 | + * |
|
| 705 | + * @param string $opt_name Panel opt_name. |
|
| 706 | + * @param string $key Box key. |
|
| 707 | + * |
|
| 708 | + * @deprecated 4.0.0 No more camelCase. |
|
| 709 | + * |
|
| 710 | + * @return mixed |
|
| 711 | + */ |
|
| 712 | + public static function getBox( string $opt_name = '', string $key = '' ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 713 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::get_box( $opt_name, $key )' ); |
|
| 714 | + |
|
| 715 | + return self::get_box( $opt_name, $key ); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * Get Metabox box. |
|
| 720 | + * |
|
| 721 | + * @param string $opt_name Panel opt_name. |
|
| 722 | + * @param string $key Box key. |
|
| 723 | + * |
|
| 724 | + * @return mixed |
|
| 725 | + */ |
|
| 726 | + public static function get_box( string $opt_name = '', string $key = '' ) { |
|
| 727 | + self::check_opt_name( $opt_name ); |
|
| 728 | + |
|
| 729 | + if ( ! empty( $opt_name ) && ! empty( $key ) && ! empty( self::$boxes[ $opt_name ] ) && isset( self::$boxes[ $opt_name ][ $key ] ) ) { |
|
| 730 | + return self::$boxes[ $opt_name ][ $key ]; |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + return null; |
|
| 734 | + } |
|
| 735 | + |
|
| 736 | + /** |
|
| 737 | + * Get priority. |
|
| 738 | + * |
|
| 739 | + * @param string $opt_name Panel opt_name. |
|
| 740 | + * @param string $type Type. |
|
| 741 | + * |
|
| 742 | + * @return mixed |
|
| 743 | + * |
|
| 744 | + * @deprecated 4.0.0 No more camelCase. |
|
| 745 | + */ |
|
| 746 | + public static function getPriority( string $opt_name, string $type ) { // phpcs:ignore: WordPress.NamingConventions.ValidFunctionName |
|
| 747 | + _deprecated_function( __CLASS__ . '::' . __FUNCTION__, 'Redux 4.3', __CLASS__ . '::get_priority( $opt_name, $type )' ); |
|
| 748 | + |
|
| 749 | + return self::get_priority( $opt_name, $type ); |
|
| 750 | + } |
|
| 751 | + |
|
| 752 | + /** |
|
| 753 | + * Get priority. |
|
| 754 | + * |
|
| 755 | + * @param string $opt_name Panel opt_name. |
|
| 756 | + * @param string $type Type. |
|
| 757 | + * |
|
| 758 | + * @return mixed |
|
| 759 | + */ |
|
| 760 | + public static function get_priority( string $opt_name, string $type ) { |
|
| 761 | + $priority = self::$priority[ $opt_name ][ $type ]; |
|
| 762 | + self::$priority[ $opt_name ][ $type ] += 1; |
|
| 763 | + |
|
| 764 | + return $priority; |
|
| 765 | + } |
|
| 766 | + |
|
| 767 | + /** |
|
| 768 | + * Check opt_name. |
|
| 769 | + * |
|
| 770 | + * @param string $opt_name Panel opt_name. |
|
| 771 | + */ |
|
| 772 | + public static function check_opt_name( string $opt_name = '' ) { |
|
| 773 | + if ( empty( $opt_name ) || is_array( $opt_name ) ) { |
|
| 774 | + return; |
|
| 775 | + } |
|
| 776 | + |
|
| 777 | + if ( ! isset( self::$boxes[ $opt_name ] ) ) { |
|
| 778 | + self::$boxes[ $opt_name ] = array(); |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + if ( ! isset( self::$priority[ $opt_name ] ) ) { |
|
| 782 | + self::$priority[ $opt_name ]['args'] = 1; |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + if ( ! isset( self::$sections[ $opt_name ] ) ) { |
|
| 786 | + self::$sections[ $opt_name ] = array(); |
|
| 787 | + self::$priority[ $opt_name ]['sections'] = 1; |
|
| 788 | + } |
|
| 789 | + |
|
| 790 | + if ( ! isset( self::$fields[ $opt_name ] ) ) { |
|
| 791 | + self::$fields[ $opt_name ] = array(); |
|
| 792 | + self::$priority[ $opt_name ]['fields'] = 1; |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + if ( ! isset( self::$errors[ $opt_name ] ) ) { |
|
| 796 | + self::$errors[ $opt_name ] = array(); |
|
| 797 | + } |
|
| 798 | + |
|
| 799 | + if ( ! isset( self::$init[ $opt_name ] ) ) { |
|
| 800 | + self::$init[ $opt_name ] = false; |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + if ( ! isset( self::$args[ $opt_name ] ) ) { |
|
| 804 | + self::$args[ $opt_name ] = false; |
|
| 805 | + } |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + Redux_Metaboxes::load(); |
|
| 810 | 810 | } |
@@ -113,11 +113,11 @@ discard block |
||
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | foreach ( $field['data'] as $key => $data ) { |
| 116 | - if ( ! isset( $field['args'][ $key ] ) ) { |
|
| 117 | - $field['args'][ $key ] = array(); |
|
| 116 | + if ( ! isset( $field['args'][$key] ) ) { |
|
| 117 | + $field['args'][$key] = array(); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | - $field['options'][ $key ] = $this->parent->get_wordpress_data( $data, $field['args'][ $key ] ); |
|
| 120 | + $field['options'][$key] = $this->parent->get_wordpress_data( $data, $field['args'][$key] ); |
|
| 121 | 121 | } |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -125,14 +125,14 @@ discard block |
||
| 125 | 125 | $default = $field['default'] ?? ''; |
| 126 | 126 | |
| 127 | 127 | if ( ! empty( $this->repeater_values ) ) { |
| 128 | - $repeater['title'] = ! isset( $this->parent->options[ $this->field['id'] ][ $field['id'] ][ $x ] ) ? $default : $this->parent->options[ $this->field['id'] ][ $field['id'] ][ $x ]; |
|
| 128 | + $repeater['title'] = ! isset( $this->parent->options[$this->field['id']][$field['id']][$x] ) ? $default : $this->parent->options[$this->field['id']][$field['id']][$x]; |
|
| 129 | 129 | } else { |
| 130 | - $repeater['title'] = ! isset( $this->parent->options[ $field['id'] ][ $x ] ) ? $default : $this->parent->options[ $field['id'] ][ $x ]; |
|
| 130 | + $repeater['title'] = ! isset( $this->parent->options[$field['id']][$x] ) ? $default : $this->parent->options[$field['id']][$x]; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | if ( isset( $field['options'] ) && is_array( $field['options'] ) ) { |
| 134 | - if ( isset( $field['options'][ $repeater['title'] ] ) ) { |
|
| 135 | - $repeater['title'] = $field['options'][ $repeater['title'] ]; |
|
| 134 | + if ( isset( $field['options'][$repeater['title']] ) ) { |
|
| 135 | + $repeater['title'] = $field['options'][$repeater['title']]; |
|
| 136 | 136 | } |
| 137 | 137 | } |
| 138 | 138 | } |
@@ -194,8 +194,8 @@ discard block |
||
| 194 | 194 | echo '<table style="margin-top: 0;" class="redux-repeater-accordion redux-repeater form-table no-border">'; |
| 195 | 195 | echo '<fieldset class="redux-field" data-id="' . esc_attr( $this->field['id'] ) . '">'; |
| 196 | 196 | |
| 197 | - 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'] ) ) { |
|
| 198 | - $this->value['redux_repeater_data'][ $x ]['title'] = null; |
|
| 197 | + 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'] ) ) { |
|
| 198 | + $this->value['redux_repeater_data'][$x]['title'] = null; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | 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" />'; |
@@ -317,10 +317,10 @@ discard block |
||
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | foreach ( $field['data'] as $key => $data ) { |
| 320 | - if ( ! isset( $field['args'][ $key ] ) ) { |
|
| 321 | - $field['args'][ $key ] = array(); |
|
| 320 | + if ( ! isset( $field['args'][$key] ) ) { |
|
| 321 | + $field['args'][$key] = array(); |
|
| 322 | 322 | } |
| 323 | - $field['options'][ $key ] = $this->parent->get_wordpress_data( $data, $field['args'][ $key ] ); |
|
| 323 | + $field['options'][$key] = $this->parent->get_wordpress_data( $data, $field['args'][$key] ); |
|
| 324 | 324 | } |
| 325 | 325 | } |
| 326 | 326 | } |
@@ -328,9 +328,9 @@ discard block |
||
| 328 | 328 | $default = $field['default'] ?? ''; |
| 329 | 329 | |
| 330 | 330 | if ( ! empty( $this->repeater_values ) ) { |
| 331 | - $value = empty( $this->parent->options[ $this->field['id'] ][ $orig_field_id ][ $x ] ) ? $default : $this->parent->options[ $this->field['id'] ][ $orig_field_id ][ $x ]; |
|
| 331 | + $value = empty( $this->parent->options[$this->field['id']][$orig_field_id][$x] ) ? $default : $this->parent->options[$this->field['id']][$orig_field_id][$x]; |
|
| 332 | 332 | } else { |
| 333 | - $value = empty( $this->parent->options[ $orig_field_id ][ $x ] ) ? $default : $this->parent->options[ $orig_field_id ][ $x ]; |
|
| 333 | + $value = empty( $this->parent->options[$orig_field_id][$x] ) ? $default : $this->parent->options[$orig_field_id][$x]; |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | ob_start(); |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | |
| 443 | 443 | $data = $enqueue->localize( $field ); |
| 444 | 444 | |
| 445 | - $this->parent->enqueue_class->localize_data[ $field['type'] ][ $field['id'] ] = $data; |
|
| 445 | + $this->parent->enqueue_class->localize_data[$field['type']][$field['id']] = $data; |
|
| 446 | 446 | } |
| 447 | 447 | } |
| 448 | 448 | } |
@@ -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->get_wordpress_data( $data, $field['args'][ $key ] ); |
|
| 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->get_wordpress_data( $data, $field['args'][ $key ] ); |
|
| 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->get_wordpress_data( $data, $field['args'][ $key ] ); |
|
| 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->get_wordpress_data( $data, $field['args'][ $key ] ); |
|
| 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 | } |
@@ -10,20 +10,20 @@ |
||
| 10 | 10 | // Helper function to bypass WordPress hook priorities. |
| 11 | 11 | if ( ! function_exists( 'create_term_redux_taxonomy' ) ) { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Create. |
|
| 15 | - * |
|
| 16 | - * @param int $term_id Term ID. |
|
| 17 | - */ |
|
| 18 | - function create_term_redux_taxonomy( int $term_id ) { |
|
| 19 | - $instances = Redux::all_instances(); |
|
| 13 | + /** |
|
| 14 | + * Create. |
|
| 15 | + * |
|
| 16 | + * @param int $term_id Term ID. |
|
| 17 | + */ |
|
| 18 | + function create_term_redux_taxonomy( int $term_id ) { |
|
| 19 | + $instances = Redux::all_instances(); |
|
| 20 | 20 | |
| 21 | - foreach ( $_POST as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 22 | - if ( is_array( $value ) && isset( $instances[ $key ] ) ) { |
|
| 23 | - $instances[ $key ]->extensions['taxonomy']->meta_terms_save( $term_id ); |
|
| 24 | - } |
|
| 25 | - } |
|
| 26 | - } |
|
| 21 | + foreach ( $_POST as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 22 | + if ( is_array( $value ) && isset( $instances[ $key ] ) ) { |
|
| 23 | + $instances[ $key ]->extensions['taxonomy']->meta_terms_save( $term_id ); |
|
| 24 | + } |
|
| 25 | + } |
|
| 26 | + } |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | add_action( 'create_term', 'create_term_redux_taxonomy', 4 ); |
@@ -19,8 +19,8 @@ |
||
| 19 | 19 | $instances = Redux::all_instances(); |
| 20 | 20 | |
| 21 | 21 | foreach ( $_POST as $key => $value ) { // phpcs:ignore WordPress.Security.NonceVerification |
| 22 | - if ( is_array( $value ) && isset( $instances[ $key ] ) ) { |
|
| 23 | - $instances[ $key ]->extensions['taxonomy']->meta_terms_save( $term_id ); |
|
| 22 | + if ( is_array( $value ) && isset( $instances[$key] ) ) { |
|
| 23 | + $instances[$key]->extensions['taxonomy']->meta_terms_save( $term_id ); |
|
| 24 | 24 | } |
| 25 | 25 | } |
| 26 | 26 | } |