@@ -11,677 +11,677 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_WordPress_Data', false ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Class Redux_WordPress_Data |
|
| 16 | - */ |
|
| 17 | - class Redux_WordPress_Data extends Redux_Class { |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Holds WordPress data. |
|
| 21 | - * |
|
| 22 | - * @var null |
|
| 23 | - */ |
|
| 24 | - private $wp_data = null; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Redux_WordPress_Data constructor. |
|
| 28 | - * |
|
| 29 | - * @param mixed $redux ReduxFramework pointer or opt_name. |
|
| 30 | - */ |
|
| 31 | - public function __construct( $redux = null ) { |
|
| 32 | - if ( is_string( $redux ) ) { |
|
| 33 | - $this->opt_name = $redux; |
|
| 34 | - } else { |
|
| 35 | - parent::__construct( $redux ); |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Get the data. |
|
| 41 | - * |
|
| 42 | - * @param string|array $type Type. |
|
| 43 | - * @param array|string $args Args. |
|
| 44 | - * @param string $opt_name Opt name. |
|
| 45 | - * @param string|int $current_value Current value. |
|
| 46 | - * @param bool $ajax Tells if this is an AJAX call. |
|
| 47 | - * |
|
| 48 | - * @return array|mixed|string |
|
| 49 | - */ |
|
| 50 | - public function get( $type, $args = array(), string $opt_name = '', $current_value = '', bool $ajax = false ) { |
|
| 51 | - if ( '' === $opt_name ) { |
|
| 52 | - $opt_name = $this->opt_name; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - // We don't want to run this, it's not a string value. Send it back! |
|
| 56 | - if ( is_array( $type ) ) { |
|
| 57 | - return $type; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Filter 'redux/options/{opt_name}/pre_data/{type}' |
|
| 62 | - * |
|
| 63 | - * @param string $data |
|
| 64 | - */ |
|
| 65 | - $pre_data = apply_filters( "redux/options/$opt_name/pre_data/$type", null ); // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 66 | - if ( null !== $pre_data || empty( $type ) ) { |
|
| 67 | - return $pre_data; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if ( isset( $args['data_sortby'] ) && in_array( $args['data_sortby'], array( 'value', 'key' ), true ) ) { |
|
| 71 | - $data_sort = $args['data_sortby']; |
|
| 72 | - unset( $args['data_sortby'] ); |
|
| 73 | - } else { |
|
| 74 | - $data_sort = 'value'; |
|
| 75 | - } |
|
| 76 | - if ( isset( $args['data_order'] ) && in_array( $args['data_order'], array( 'asc', 'desc' ), true ) ) { |
|
| 77 | - $data_order = $args['data_order']; |
|
| 78 | - unset( $args['data_order'] ); |
|
| 79 | - } else { |
|
| 80 | - $data_order = 'asc'; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - $this->maybe_get_translation( $type, $current_value, $args ); |
|
| 84 | - |
|
| 85 | - $current_data = array(); |
|
| 86 | - if ( empty( $current_value ) && ! Redux_Helpers::is_integer( $current_value ) ) { |
|
| 87 | - $current_value = null; |
|
| 88 | - } else { |
|
| 89 | - // Get the args to grab the current data. |
|
| 90 | - $current_data_args = $this->get_current_data_args( $type, $args, $current_value ); |
|
| 91 | - |
|
| 92 | - // Let's make a unique key for this arg array. |
|
| 93 | - $current_data_args_key = md5( maybe_serialize( $current_data_args ) ); |
|
| 94 | - |
|
| 95 | - // Check to make sure we haven't already run this call before. |
|
| 96 | - $current_data = $this->wp_data[ $type . $current_data_args_key ] ?? $this->get_data( $type, $current_data_args, $current_value ); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // If ajax is enabled AND $current_data is empty, set a dummy value for the init. |
|
| 100 | - if ( $ajax && ! wp_doing_ajax() ) { |
|
| 101 | - // Dummy is necessary otherwise empty. |
|
| 102 | - if ( empty( $current_data ) ) { |
|
| 103 | - $current_data = array( |
|
| 104 | - 'dummy' => '', |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - return $current_data; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // phpcs:ignore Squiz.PHP.CommentedOutCode |
|
| 112 | - $args_key = md5( maybe_serialize( $args ) ); |
|
| 113 | - |
|
| 114 | - // Data caching. |
|
| 115 | - if ( isset( $this->wp_data[ $type . $args_key ] ) ) { |
|
| 116 | - $data = $this->wp_data[ $type . $args_key ]; |
|
| 117 | - } else { |
|
| 118 | - /** |
|
| 119 | - * Use data from WordPress to populate an option array. |
|
| 120 | - * */ |
|
| 121 | - $data = $this->get_data( $type, $args, $current_value ); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - if ( ! empty( $current_data ) ) { |
|
| 125 | - $data += $current_data; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - if ( ! empty( $data ) ) { |
|
| 129 | - $data = $this->order_data( $data, $data_sort, $data_order ); |
|
| 130 | - $this->wp_data[ $type . $args_key ] = $data; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Filter 'redux/options/{opt_name}/data/{type}' |
|
| 135 | - * |
|
| 136 | - * @param string $data |
|
| 137 | - */ |
|
| 138 | - |
|
| 139 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 140 | - return apply_filters( "redux/options/$opt_name/data/$type", $data ); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Process the results into a proper array, fetching the data elements needed for each data type. |
|
| 146 | - * |
|
| 147 | - * @param array|WP_Error $results Results to process in the data array. |
|
| 148 | - * @param string|bool $id_key Key on object/array that represents the ID. |
|
| 149 | - * @param string|bool $name_key Key on object/array that represents the name/text. |
|
| 150 | - * @param bool $add_key If true, the display key will appear in the text. |
|
| 151 | - * @param string|bool $secondary_key If a data type, you'd rather display a different ID as the display key. |
|
| 152 | - * |
|
| 153 | - * @return array |
|
| 154 | - */ |
|
| 155 | - private function process_results( $results = array(), $id_key = '', $name_key = '', bool $add_key = true, $secondary_key = 'slug' ): array { |
|
| 156 | - $data = array(); |
|
| 157 | - if ( ! empty( $results ) && ! is_a( $results, 'WP_Error' ) ) { |
|
| 158 | - foreach ( $results as $k => $v ) { |
|
| 159 | - if ( empty( $id_key ) ) { |
|
| 160 | - $key = $k; |
|
| 161 | - } else { |
|
| 162 | - if ( is_object( $v ) ) { |
|
| 163 | - $key = $v->$id_key; |
|
| 164 | - } elseif ( is_array( $v ) ) { |
|
| 165 | - $key = $v[ $id_key ]; |
|
| 166 | - } else { |
|
| 167 | - $key = $k; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - if ( empty( $name_key ) ) { |
|
| 172 | - $value = $v; |
|
| 173 | - } else { |
|
| 174 | - if ( is_object( $v ) ) { |
|
| 175 | - $value = $v->$name_key; |
|
| 176 | - } elseif ( is_array( $v ) ) { |
|
| 177 | - $value = $v[ $name_key ]; |
|
| 178 | - } else { |
|
| 179 | - $value = $v; |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $display_key = $key; |
|
| 184 | - |
|
| 185 | - if ( is_object( $v ) && isset( $v->$secondary_key ) ) { |
|
| 186 | - $display_key = $v->$secondary_key; |
|
| 187 | - } elseif ( ! is_object( $v ) && isset( $v[ $secondary_key ] ) ) { |
|
| 188 | - $display_key = $v[ $secondary_key ]; |
|
| 189 | - } |
|
| 190 | - $data[ $key ] = $value; |
|
| 191 | - if ( $display_key !== $value && $add_key ) { |
|
| 192 | - $data[ $key ] = $data[ $key ] . ' [' . $display_key . ']'; |
|
| 193 | - } |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return $data; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - /** |
|
| 201 | - * Order / Sort the data. |
|
| 202 | - * |
|
| 203 | - * @param array $data Data to sort. |
|
| 204 | - * @param string $sort Way to sort. Accepts: key|value. |
|
| 205 | - * @param string $order Order of the sort. Accepts: asc|desc. |
|
| 206 | - * |
|
| 207 | - * @return array |
|
| 208 | - */ |
|
| 209 | - private function order_data( array $data = array(), string $sort = 'value', string $order = 'asc' ): array { |
|
| 210 | - if ( 'key' === $sort ) { |
|
| 211 | - if ( 'asc' === $order ) { |
|
| 212 | - ksort( $data ); |
|
| 213 | - } else { |
|
| 214 | - krsort( $data ); |
|
| 215 | - } |
|
| 216 | - } elseif ( 'value' === $sort ) { |
|
| 217 | - if ( 'asc' === $order ) { |
|
| 218 | - asort( $data ); |
|
| 219 | - } else { |
|
| 220 | - arsort( $data ); |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - return $data; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Fetch the data for a given type. |
|
| 229 | - * |
|
| 230 | - * @param string $type The data type we're fetching. |
|
| 231 | - * @param array|string $args Arguments to pass. |
|
| 232 | - * @param mixed|array $current_value If a current value already set in the database. |
|
| 233 | - * |
|
| 234 | - * @return array|null|string |
|
| 235 | - */ |
|
| 236 | - private function get_data( string $type, $args, $current_value ) { |
|
| 237 | - $args = $this->get_arg_defaults( $type, $args ); |
|
| 238 | - |
|
| 239 | - $opt_name = $this->opt_name; |
|
| 240 | - if ( empty( $args ) ) { |
|
| 241 | - $args = array(); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - $data = array(); |
|
| 245 | - if ( isset( $args['args'] ) && empty( $args['args'] ) ) { |
|
| 246 | - unset( $args['args'] ); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - $display_keys = false; |
|
| 250 | - if ( isset( $args['display_keys'] ) ) { |
|
| 251 | - $display_keys = true; |
|
| 252 | - unset( $args['display_keys'] ); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - $secondary_key = 'slug'; |
|
| 256 | - if ( isset( $args['secondary_key'] ) ) { |
|
| 257 | - $secondary_key = $args['secondary_key']; |
|
| 258 | - unset( $args['secondary_key'] ); |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - switch ( $type ) { |
|
| 262 | - case 'categories': |
|
| 263 | - case 'category': |
|
| 264 | - case 'terms': |
|
| 265 | - case 'term': |
|
| 266 | - if ( isset( $args['taxonomies'] ) ) { |
|
| 267 | - $args['taxonomy'] = $args['taxonomies']; |
|
| 268 | - unset( $args['taxonomies'] ); |
|
| 269 | - } |
|
| 270 | - $results = get_terms( $args ); |
|
| 271 | - $data = $this->process_results( $results, 'term_id', 'name', $display_keys, $secondary_key ); |
|
| 272 | - break; |
|
| 273 | - |
|
| 274 | - case 'pages': |
|
| 275 | - case 'page': |
|
| 276 | - $results = get_pages( $args ); |
|
| 277 | - $data = $this->process_results( $results, 'ID', 'post_title', $display_keys, $secondary_key ); |
|
| 278 | - break; |
|
| 279 | - |
|
| 280 | - case 'tags': |
|
| 281 | - case 'tag': |
|
| 282 | - $results = get_tags( $args ); |
|
| 283 | - $data = $this->process_results( $results, 'term_id', 'name', $display_keys, $secondary_key ); |
|
| 284 | - break; |
|
| 285 | - |
|
| 286 | - case 'menus': |
|
| 287 | - case 'menu': |
|
| 288 | - $results = wp_get_nav_menus( $args ); |
|
| 289 | - $data = $this->process_results( $results, 'term_id', 'name', $display_keys, $secondary_key ); |
|
| 290 | - break; |
|
| 291 | - |
|
| 292 | - case 'posts': |
|
| 293 | - case 'post': |
|
| 294 | - $results = get_posts( $args ); |
|
| 295 | - $data = $this->process_results( $results, 'ID', 'post_title', $display_keys, $secondary_key ); |
|
| 296 | - break; |
|
| 297 | - |
|
| 298 | - case 'users': |
|
| 299 | - case 'user': |
|
| 300 | - $results = get_users( $args ); |
|
| 301 | - $data = $this->process_results( $results, 'ID', 'display_name', $display_keys, $secondary_key ); |
|
| 302 | - break; |
|
| 303 | - |
|
| 304 | - case 'sites': |
|
| 305 | - case 'site': |
|
| 306 | - $sites = get_sites(); |
|
| 307 | - |
|
| 308 | - if ( isset( $sites ) ) { |
|
| 309 | - $results = array(); |
|
| 310 | - foreach ( $sites as $site ) { |
|
| 311 | - $site = (array) $site; |
|
| 312 | - $k = $site['blog_id']; |
|
| 313 | - $v = $site['domain'] . $site['path']; |
|
| 314 | - $name = get_blog_option( $k, 'blogname' ); |
|
| 315 | - if ( ! empty( $name ) ) { |
|
| 316 | - $v .= ' - [' . $name . ']'; |
|
| 317 | - } |
|
| 318 | - $results[ $k ] = $v; |
|
| 319 | - } |
|
| 320 | - $data = $this->process_results( $results, '', '', $display_keys, $secondary_key ); |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - break; |
|
| 324 | - |
|
| 325 | - case 'taxonomies': |
|
| 326 | - case 'taxonomy': |
|
| 327 | - case 'tax': |
|
| 328 | - $results = get_taxonomies( $args ); |
|
| 329 | - $data = $this->process_results( $results, '', '', $display_keys, $secondary_key ); |
|
| 330 | - break; |
|
| 331 | - |
|
| 332 | - case 'post_types': |
|
| 333 | - case 'post_type': |
|
| 334 | - global $wp_post_types; |
|
| 335 | - |
|
| 336 | - $output = $args['output']; |
|
| 337 | - unset( $args['output'] ); |
|
| 338 | - $operator = $args['operator']; |
|
| 339 | - unset( $args['operator'] ); |
|
| 340 | - |
|
| 341 | - $post_types = get_post_types( $args, $output, $operator ); |
|
| 342 | - |
|
| 343 | - foreach ( $post_types as $name => $title ) { |
|
| 344 | - if ( isset( $wp_post_types[ $name ]->labels->menu_name ) ) { |
|
| 345 | - $data[ $name ] = $wp_post_types[ $name ]->labels->menu_name; |
|
| 346 | - } else { |
|
| 347 | - $data[ $name ] = ucfirst( $name ); |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - break; |
|
| 351 | - |
|
| 352 | - case 'menu_locations': |
|
| 353 | - case 'menu_location': |
|
| 354 | - global $_wp_registered_nav_menus; |
|
| 355 | - foreach ( $_wp_registered_nav_menus as $k => $v ) { |
|
| 356 | - $data[ $k ] = $v; |
|
| 357 | - if ( ! has_nav_menu( $k ) ) { |
|
| 358 | - $data[ $k ] .= ' ' . __( '[unassigned]', 'redux-framework' ); |
|
| 359 | - } |
|
| 360 | - } |
|
| 361 | - break; |
|
| 362 | - |
|
| 363 | - case 'image_sizes': |
|
| 364 | - case 'image_size': |
|
| 365 | - global $_wp_additional_image_sizes; |
|
| 366 | - $results = array(); |
|
| 367 | - foreach ( $_wp_additional_image_sizes as $size_name => $size_attrs ) { |
|
| 368 | - $results[ $size_name ] = $size_name . ' - ' . $size_attrs['width'] . ' x ' . $size_attrs['height']; |
|
| 369 | - } |
|
| 370 | - $data = $this->process_results( $results, '', '', $display_keys, $secondary_key ); |
|
| 371 | - |
|
| 372 | - break; |
|
| 373 | - |
|
| 374 | - case 'elusive-icons': |
|
| 375 | - case 'elusive-icon': |
|
| 376 | - case 'elusive': |
|
| 377 | - case 'icons': |
|
| 378 | - case 'font-icon': |
|
| 379 | - case 'font-icons': |
|
| 380 | - $fs = Redux_Filesystem::get_instance(); |
|
| 381 | - $fonts = $fs->get_contents( Redux_Core::$dir . 'assets/css/vendor/elusive-icons.css' ); |
|
| 382 | - if ( ! empty( $fonts ) ) { |
|
| 383 | - preg_match_all( '@\.el-(\w+)::before@', $fonts, $matches ); |
|
| 384 | - foreach ( $matches[1] as $item ) { |
|
| 385 | - if ( 'before' === $item ) { |
|
| 386 | - continue; |
|
| 387 | - } |
|
| 388 | - $data[ 'el el-' . $item ] = $item; |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Filter 'redux/font-icons' |
|
| 394 | - * |
|
| 395 | - * @param array $font_icons array of elusive icon classes |
|
| 396 | - * |
|
| 397 | - * @deprecated |
|
| 398 | - */ |
|
| 399 | - |
|
| 400 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 401 | - $font_icons = apply_filters_deprecated( 'redux/font-icons', array( $data ), '4.3', 'redux/$opt_name/field/font/icons' ); |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * Filter 'redux/{opt_name}/field/font/icons' |
|
| 405 | - * |
|
| 406 | - * @param array $font_icons array of elusive icon classes |
|
| 407 | - */ |
|
| 408 | - |
|
| 409 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 410 | - $data = apply_filters( "redux/$opt_name/field/font/icons", $font_icons ); |
|
| 411 | - |
|
| 412 | - break; |
|
| 413 | - |
|
| 414 | - case 'dashicons': |
|
| 415 | - case 'dashicon': |
|
| 416 | - case 'dash': |
|
| 417 | - $fs = Redux_Filesystem::get_instance(); |
|
| 418 | - $fonts = $fs->get_contents( ABSPATH . WPINC . '/css/dashicons.css' ); |
|
| 419 | - if ( ! empty( $fonts ) ) { |
|
| 420 | - preg_match_all( '@\.dashicons-(\w+):before@', $fonts, $matches ); |
|
| 421 | - foreach ( $matches[1] as $item ) { |
|
| 422 | - if ( 'before' === $item ) { |
|
| 423 | - continue; |
|
| 424 | - } |
|
| 425 | - $data[ 'dashicons dashicons-' . $item ] = $item; |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - break; |
|
| 429 | - |
|
| 430 | - case 'roles': |
|
| 431 | - case 'role': |
|
| 432 | - global $wp_roles; |
|
| 433 | - $results = $wp_roles->get_names(); |
|
| 434 | - $data = $this->process_results( $results, '', '', $display_keys, $secondary_key ); |
|
| 435 | - |
|
| 436 | - break; |
|
| 437 | - |
|
| 438 | - case 'sidebars': |
|
| 439 | - case 'sidebar': |
|
| 440 | - global $wp_registered_sidebars; |
|
| 441 | - $data = $this->process_results( $wp_registered_sidebars, '', 'name', $display_keys, $secondary_key ); |
|
| 442 | - break; |
|
| 443 | - case 'capabilities': |
|
| 444 | - case 'capability': |
|
| 445 | - global $wp_roles; |
|
| 446 | - $results = array(); |
|
| 447 | - foreach ( $wp_roles->roles as $role ) { |
|
| 448 | - foreach ( $role['capabilities'] as $key => $cap ) { |
|
| 449 | - $results[ $key ] = ucwords( str_replace( '_', ' ', $key ) ); |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - $data = $this->process_results( $results, '', '', $display_keys, $secondary_key ); |
|
| 453 | - |
|
| 454 | - break; |
|
| 455 | - |
|
| 456 | - case 'capabilities_grouped': |
|
| 457 | - case 'capability_grouped': |
|
| 458 | - case 'capabilities_group': |
|
| 459 | - case 'capability_group': |
|
| 460 | - global $wp_roles; |
|
| 461 | - |
|
| 462 | - foreach ( $wp_roles->roles as $role ) { |
|
| 463 | - $caps = array(); |
|
| 464 | - foreach ( $role['capabilities'] as $key => $cap ) { |
|
| 465 | - $caps[ $key ] = ucwords( str_replace( '_', ' ', $key ) ); |
|
| 466 | - } |
|
| 467 | - asort( $caps ); |
|
| 468 | - $data[ $role['name'] ] = $caps; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - break; |
|
| 472 | - |
|
| 473 | - case 'callback': |
|
| 474 | - if ( ! empty( $args ) && is_callable( $args ) ) { |
|
| 475 | - $data = call_user_func( $args, $current_value ); |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - break; |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - return $data; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - |
|
| 485 | - /** |
|
| 486 | - * Router for translation based on the given post-type. |
|
| 487 | - * |
|
| 488 | - * @param string $type Type of data request. |
|
| 489 | - * @param mixed|array $current_value Current value stored in DB. |
|
| 490 | - * @param array|string $args Arguments for the call. |
|
| 491 | - */ |
|
| 492 | - private function maybe_get_translation( string $type, &$current_value = '', $args = array() ) { |
|
| 493 | - switch ( $type ) { |
|
| 494 | - case 'categories': |
|
| 495 | - case 'category': |
|
| 496 | - $this->maybe_translate( $current_value, 'category' ); |
|
| 497 | - break; |
|
| 498 | - |
|
| 499 | - case 'pages': |
|
| 500 | - case 'page': |
|
| 501 | - $this->maybe_translate( $current_value, 'page' ); |
|
| 502 | - break; |
|
| 503 | - |
|
| 504 | - case 'terms': |
|
| 505 | - case 'term': |
|
| 506 | - $this->maybe_translate( $current_value, $args['taxonomy'] ?? '' ); |
|
| 507 | - break; |
|
| 508 | - |
|
| 509 | - case 'tags': |
|
| 510 | - case 'tag': |
|
| 511 | - $this->maybe_translate( $current_value, 'post_tag' ); |
|
| 512 | - break; |
|
| 513 | - |
|
| 514 | - case 'menus': |
|
| 515 | - case 'menu': |
|
| 516 | - $this->maybe_translate( $current_value, 'nav_menu' ); |
|
| 517 | - break; |
|
| 518 | - |
|
| 519 | - case 'post': |
|
| 520 | - case 'posts': |
|
| 521 | - $this->maybe_translate( $current_value, 'post' ); |
|
| 522 | - break; |
|
| 523 | - default: |
|
| 524 | - $this->maybe_translate( $current_value, '' ); |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * Maybe translate the values. |
|
| 530 | - * |
|
| 531 | - * @param mixed|array $value Value. |
|
| 532 | - * @param mixed|array $post_type Post type. |
|
| 533 | - */ |
|
| 534 | - private function maybe_translate( &$value, $post_type ) { |
|
| 535 | - |
|
| 536 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 537 | - $value = apply_filters( "redux/options/$this->opt_name/wordpress_data/translate/post_type_value", $value, $post_type ); |
|
| 538 | - |
|
| 539 | - // WPML Integration, see https://wpml.org/documentation/support/creating-multilingual-wordpress-themes/language-dependent-ids/. |
|
| 540 | - if ( function_exists( 'icl_object_id' ) ) { |
|
| 541 | - if ( has_filter( 'wpml_object_id' ) ) { |
|
| 542 | - if ( Redux_Helpers::is_integer( $value ) ) { |
|
| 543 | - $value = apply_filters( 'wpml_object_id', $value, $post_type, true ); |
|
| 544 | - } elseif ( is_array( $value ) ) { |
|
| 545 | - $value = array_map( |
|
| 546 | - function ( $val ) use ( $post_type ) { |
|
| 547 | - return apply_filters( 'wpml_object_id', $val, $post_type, true ); |
|
| 548 | - }, |
|
| 549 | - $value |
|
| 550 | - ); |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Set the default arguments for a current query (existing data). |
|
| 558 | - * |
|
| 559 | - * @param string $type Type of data request. |
|
| 560 | - * @param array|string $args Arguments for the call. |
|
| 561 | - * @param mixed|array $current_value Current value stored in DB. |
|
| 562 | - * |
|
| 563 | - * @return array |
|
| 564 | - */ |
|
| 565 | - private function get_current_data_args( string $type, $args, $current_value ): array { |
|
| 566 | - // In this section, we set the default arguments for each data type. |
|
| 567 | - switch ( $type ) { |
|
| 568 | - case 'categories': |
|
| 569 | - case 'category': |
|
| 570 | - case 'pages': |
|
| 571 | - case 'page': |
|
| 572 | - case 'terms': |
|
| 573 | - case 'term': |
|
| 574 | - case 'users': |
|
| 575 | - case 'user': |
|
| 576 | - $args['include'] = $current_value; |
|
| 577 | - break; |
|
| 578 | - case 'tags': |
|
| 579 | - case 'tag': |
|
| 580 | - $args['get'] = 'all'; |
|
| 581 | - break; |
|
| 582 | - case 'menus': |
|
| 583 | - case 'menu': |
|
| 584 | - $args['object_ids'] = $current_value; |
|
| 585 | - break; |
|
| 586 | - case 'post': |
|
| 587 | - case 'posts': |
|
| 588 | - if ( ! empty( $current_value ) ) { |
|
| 589 | - $args['post__in'] = is_array( $current_value ) ? $current_value : array( $current_value ); |
|
| 590 | - } |
|
| 591 | - break; |
|
| 592 | - |
|
| 593 | - default: |
|
| 594 | - $args = array(); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - return $args; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - |
|
| 601 | - /** |
|
| 602 | - * Get default arguments for a given data type. |
|
| 603 | - * |
|
| 604 | - * @param string $type Type of data request. |
|
| 605 | - * @param array|string $args Arguments for the call. |
|
| 606 | - * |
|
| 607 | - * @return array|string |
|
| 608 | - */ |
|
| 609 | - private function get_arg_defaults( string $type, $args = array() ) { |
|
| 610 | - // In this section, we set the default arguments for each data type. |
|
| 611 | - switch ( $type ) { |
|
| 612 | - case 'categories': |
|
| 613 | - case 'category': |
|
| 614 | - $args = wp_parse_args( |
|
| 615 | - $args, |
|
| 616 | - array( |
|
| 617 | - 'taxonomy' => 'category', |
|
| 618 | - ) |
|
| 619 | - ); |
|
| 620 | - break; |
|
| 621 | - |
|
| 622 | - case 'pages': |
|
| 623 | - case 'page': |
|
| 624 | - $args = wp_parse_args( |
|
| 625 | - $args, |
|
| 626 | - array( |
|
| 627 | - 'display_keys' => true, |
|
| 628 | - 'posts_per_page' => 20, |
|
| 629 | - ) |
|
| 630 | - ); |
|
| 631 | - break; |
|
| 632 | - |
|
| 633 | - case 'post_type': |
|
| 634 | - case 'post_types': |
|
| 635 | - $args = wp_parse_args( |
|
| 636 | - $args, |
|
| 637 | - array( |
|
| 638 | - 'public' => true, |
|
| 639 | - 'exclude_from_search' => false, |
|
| 640 | - 'output' => 'names', |
|
| 641 | - 'operator' => 'and', |
|
| 642 | - ) |
|
| 643 | - ); |
|
| 644 | - |
|
| 645 | - break; |
|
| 646 | - |
|
| 647 | - case 'tag': |
|
| 648 | - case 'tags': |
|
| 649 | - $args = wp_parse_args( |
|
| 650 | - $args, |
|
| 651 | - array( |
|
| 652 | - 'get' => 'all', |
|
| 653 | - 'display_keys' => true, |
|
| 654 | - ) |
|
| 655 | - ); |
|
| 656 | - break; |
|
| 657 | - |
|
| 658 | - case 'sidebars': |
|
| 659 | - case 'sidebar': |
|
| 660 | - case 'capabilities': |
|
| 661 | - case 'capability': |
|
| 662 | - $args = wp_parse_args( |
|
| 663 | - $args, |
|
| 664 | - array( |
|
| 665 | - 'display_keys' => true, |
|
| 666 | - ) |
|
| 667 | - ); |
|
| 668 | - break; |
|
| 669 | - |
|
| 670 | - case 'capabilities_grouped': |
|
| 671 | - case 'capability_grouped': |
|
| 672 | - case 'capabilities_group': |
|
| 673 | - case 'capability_group': |
|
| 674 | - $args = wp_parse_args( |
|
| 675 | - $args, |
|
| 676 | - array( |
|
| 677 | - 'data_sortby' => '', |
|
| 678 | - ) |
|
| 679 | - ); |
|
| 680 | - break; |
|
| 681 | - |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - return $args; |
|
| 685 | - } |
|
| 686 | - } |
|
| 14 | + /** |
|
| 15 | + * Class Redux_WordPress_Data |
|
| 16 | + */ |
|
| 17 | + class Redux_WordPress_Data extends Redux_Class { |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Holds WordPress data. |
|
| 21 | + * |
|
| 22 | + * @var null |
|
| 23 | + */ |
|
| 24 | + private $wp_data = null; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Redux_WordPress_Data constructor. |
|
| 28 | + * |
|
| 29 | + * @param mixed $redux ReduxFramework pointer or opt_name. |
|
| 30 | + */ |
|
| 31 | + public function __construct( $redux = null ) { |
|
| 32 | + if ( is_string( $redux ) ) { |
|
| 33 | + $this->opt_name = $redux; |
|
| 34 | + } else { |
|
| 35 | + parent::__construct( $redux ); |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Get the data. |
|
| 41 | + * |
|
| 42 | + * @param string|array $type Type. |
|
| 43 | + * @param array|string $args Args. |
|
| 44 | + * @param string $opt_name Opt name. |
|
| 45 | + * @param string|int $current_value Current value. |
|
| 46 | + * @param bool $ajax Tells if this is an AJAX call. |
|
| 47 | + * |
|
| 48 | + * @return array|mixed|string |
|
| 49 | + */ |
|
| 50 | + public function get( $type, $args = array(), string $opt_name = '', $current_value = '', bool $ajax = false ) { |
|
| 51 | + if ( '' === $opt_name ) { |
|
| 52 | + $opt_name = $this->opt_name; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + // We don't want to run this, it's not a string value. Send it back! |
|
| 56 | + if ( is_array( $type ) ) { |
|
| 57 | + return $type; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Filter 'redux/options/{opt_name}/pre_data/{type}' |
|
| 62 | + * |
|
| 63 | + * @param string $data |
|
| 64 | + */ |
|
| 65 | + $pre_data = apply_filters( "redux/options/$opt_name/pre_data/$type", null ); // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 66 | + if ( null !== $pre_data || empty( $type ) ) { |
|
| 67 | + return $pre_data; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if ( isset( $args['data_sortby'] ) && in_array( $args['data_sortby'], array( 'value', 'key' ), true ) ) { |
|
| 71 | + $data_sort = $args['data_sortby']; |
|
| 72 | + unset( $args['data_sortby'] ); |
|
| 73 | + } else { |
|
| 74 | + $data_sort = 'value'; |
|
| 75 | + } |
|
| 76 | + if ( isset( $args['data_order'] ) && in_array( $args['data_order'], array( 'asc', 'desc' ), true ) ) { |
|
| 77 | + $data_order = $args['data_order']; |
|
| 78 | + unset( $args['data_order'] ); |
|
| 79 | + } else { |
|
| 80 | + $data_order = 'asc'; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + $this->maybe_get_translation( $type, $current_value, $args ); |
|
| 84 | + |
|
| 85 | + $current_data = array(); |
|
| 86 | + if ( empty( $current_value ) && ! Redux_Helpers::is_integer( $current_value ) ) { |
|
| 87 | + $current_value = null; |
|
| 88 | + } else { |
|
| 89 | + // Get the args to grab the current data. |
|
| 90 | + $current_data_args = $this->get_current_data_args( $type, $args, $current_value ); |
|
| 91 | + |
|
| 92 | + // Let's make a unique key for this arg array. |
|
| 93 | + $current_data_args_key = md5( maybe_serialize( $current_data_args ) ); |
|
| 94 | + |
|
| 95 | + // Check to make sure we haven't already run this call before. |
|
| 96 | + $current_data = $this->wp_data[ $type . $current_data_args_key ] ?? $this->get_data( $type, $current_data_args, $current_value ); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // If ajax is enabled AND $current_data is empty, set a dummy value for the init. |
|
| 100 | + if ( $ajax && ! wp_doing_ajax() ) { |
|
| 101 | + // Dummy is necessary otherwise empty. |
|
| 102 | + if ( empty( $current_data ) ) { |
|
| 103 | + $current_data = array( |
|
| 104 | + 'dummy' => '', |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + return $current_data; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // phpcs:ignore Squiz.PHP.CommentedOutCode |
|
| 112 | + $args_key = md5( maybe_serialize( $args ) ); |
|
| 113 | + |
|
| 114 | + // Data caching. |
|
| 115 | + if ( isset( $this->wp_data[ $type . $args_key ] ) ) { |
|
| 116 | + $data = $this->wp_data[ $type . $args_key ]; |
|
| 117 | + } else { |
|
| 118 | + /** |
|
| 119 | + * Use data from WordPress to populate an option array. |
|
| 120 | + * */ |
|
| 121 | + $data = $this->get_data( $type, $args, $current_value ); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + if ( ! empty( $current_data ) ) { |
|
| 125 | + $data += $current_data; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + if ( ! empty( $data ) ) { |
|
| 129 | + $data = $this->order_data( $data, $data_sort, $data_order ); |
|
| 130 | + $this->wp_data[ $type . $args_key ] = $data; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Filter 'redux/options/{opt_name}/data/{type}' |
|
| 135 | + * |
|
| 136 | + * @param string $data |
|
| 137 | + */ |
|
| 138 | + |
|
| 139 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 140 | + return apply_filters( "redux/options/$opt_name/data/$type", $data ); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Process the results into a proper array, fetching the data elements needed for each data type. |
|
| 146 | + * |
|
| 147 | + * @param array|WP_Error $results Results to process in the data array. |
|
| 148 | + * @param string|bool $id_key Key on object/array that represents the ID. |
|
| 149 | + * @param string|bool $name_key Key on object/array that represents the name/text. |
|
| 150 | + * @param bool $add_key If true, the display key will appear in the text. |
|
| 151 | + * @param string|bool $secondary_key If a data type, you'd rather display a different ID as the display key. |
|
| 152 | + * |
|
| 153 | + * @return array |
|
| 154 | + */ |
|
| 155 | + private function process_results( $results = array(), $id_key = '', $name_key = '', bool $add_key = true, $secondary_key = 'slug' ): array { |
|
| 156 | + $data = array(); |
|
| 157 | + if ( ! empty( $results ) && ! is_a( $results, 'WP_Error' ) ) { |
|
| 158 | + foreach ( $results as $k => $v ) { |
|
| 159 | + if ( empty( $id_key ) ) { |
|
| 160 | + $key = $k; |
|
| 161 | + } else { |
|
| 162 | + if ( is_object( $v ) ) { |
|
| 163 | + $key = $v->$id_key; |
|
| 164 | + } elseif ( is_array( $v ) ) { |
|
| 165 | + $key = $v[ $id_key ]; |
|
| 166 | + } else { |
|
| 167 | + $key = $k; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + if ( empty( $name_key ) ) { |
|
| 172 | + $value = $v; |
|
| 173 | + } else { |
|
| 174 | + if ( is_object( $v ) ) { |
|
| 175 | + $value = $v->$name_key; |
|
| 176 | + } elseif ( is_array( $v ) ) { |
|
| 177 | + $value = $v[ $name_key ]; |
|
| 178 | + } else { |
|
| 179 | + $value = $v; |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $display_key = $key; |
|
| 184 | + |
|
| 185 | + if ( is_object( $v ) && isset( $v->$secondary_key ) ) { |
|
| 186 | + $display_key = $v->$secondary_key; |
|
| 187 | + } elseif ( ! is_object( $v ) && isset( $v[ $secondary_key ] ) ) { |
|
| 188 | + $display_key = $v[ $secondary_key ]; |
|
| 189 | + } |
|
| 190 | + $data[ $key ] = $value; |
|
| 191 | + if ( $display_key !== $value && $add_key ) { |
|
| 192 | + $data[ $key ] = $data[ $key ] . ' [' . $display_key . ']'; |
|
| 193 | + } |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $data; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + /** |
|
| 201 | + * Order / Sort the data. |
|
| 202 | + * |
|
| 203 | + * @param array $data Data to sort. |
|
| 204 | + * @param string $sort Way to sort. Accepts: key|value. |
|
| 205 | + * @param string $order Order of the sort. Accepts: asc|desc. |
|
| 206 | + * |
|
| 207 | + * @return array |
|
| 208 | + */ |
|
| 209 | + private function order_data( array $data = array(), string $sort = 'value', string $order = 'asc' ): array { |
|
| 210 | + if ( 'key' === $sort ) { |
|
| 211 | + if ( 'asc' === $order ) { |
|
| 212 | + ksort( $data ); |
|
| 213 | + } else { |
|
| 214 | + krsort( $data ); |
|
| 215 | + } |
|
| 216 | + } elseif ( 'value' === $sort ) { |
|
| 217 | + if ( 'asc' === $order ) { |
|
| 218 | + asort( $data ); |
|
| 219 | + } else { |
|
| 220 | + arsort( $data ); |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + return $data; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Fetch the data for a given type. |
|
| 229 | + * |
|
| 230 | + * @param string $type The data type we're fetching. |
|
| 231 | + * @param array|string $args Arguments to pass. |
|
| 232 | + * @param mixed|array $current_value If a current value already set in the database. |
|
| 233 | + * |
|
| 234 | + * @return array|null|string |
|
| 235 | + */ |
|
| 236 | + private function get_data( string $type, $args, $current_value ) { |
|
| 237 | + $args = $this->get_arg_defaults( $type, $args ); |
|
| 238 | + |
|
| 239 | + $opt_name = $this->opt_name; |
|
| 240 | + if ( empty( $args ) ) { |
|
| 241 | + $args = array(); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + $data = array(); |
|
| 245 | + if ( isset( $args['args'] ) && empty( $args['args'] ) ) { |
|
| 246 | + unset( $args['args'] ); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + $display_keys = false; |
|
| 250 | + if ( isset( $args['display_keys'] ) ) { |
|
| 251 | + $display_keys = true; |
|
| 252 | + unset( $args['display_keys'] ); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + $secondary_key = 'slug'; |
|
| 256 | + if ( isset( $args['secondary_key'] ) ) { |
|
| 257 | + $secondary_key = $args['secondary_key']; |
|
| 258 | + unset( $args['secondary_key'] ); |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + switch ( $type ) { |
|
| 262 | + case 'categories': |
|
| 263 | + case 'category': |
|
| 264 | + case 'terms': |
|
| 265 | + case 'term': |
|
| 266 | + if ( isset( $args['taxonomies'] ) ) { |
|
| 267 | + $args['taxonomy'] = $args['taxonomies']; |
|
| 268 | + unset( $args['taxonomies'] ); |
|
| 269 | + } |
|
| 270 | + $results = get_terms( $args ); |
|
| 271 | + $data = $this->process_results( $results, 'term_id', 'name', $display_keys, $secondary_key ); |
|
| 272 | + break; |
|
| 273 | + |
|
| 274 | + case 'pages': |
|
| 275 | + case 'page': |
|
| 276 | + $results = get_pages( $args ); |
|
| 277 | + $data = $this->process_results( $results, 'ID', 'post_title', $display_keys, $secondary_key ); |
|
| 278 | + break; |
|
| 279 | + |
|
| 280 | + case 'tags': |
|
| 281 | + case 'tag': |
|
| 282 | + $results = get_tags( $args ); |
|
| 283 | + $data = $this->process_results( $results, 'term_id', 'name', $display_keys, $secondary_key ); |
|
| 284 | + break; |
|
| 285 | + |
|
| 286 | + case 'menus': |
|
| 287 | + case 'menu': |
|
| 288 | + $results = wp_get_nav_menus( $args ); |
|
| 289 | + $data = $this->process_results( $results, 'term_id', 'name', $display_keys, $secondary_key ); |
|
| 290 | + break; |
|
| 291 | + |
|
| 292 | + case 'posts': |
|
| 293 | + case 'post': |
|
| 294 | + $results = get_posts( $args ); |
|
| 295 | + $data = $this->process_results( $results, 'ID', 'post_title', $display_keys, $secondary_key ); |
|
| 296 | + break; |
|
| 297 | + |
|
| 298 | + case 'users': |
|
| 299 | + case 'user': |
|
| 300 | + $results = get_users( $args ); |
|
| 301 | + $data = $this->process_results( $results, 'ID', 'display_name', $display_keys, $secondary_key ); |
|
| 302 | + break; |
|
| 303 | + |
|
| 304 | + case 'sites': |
|
| 305 | + case 'site': |
|
| 306 | + $sites = get_sites(); |
|
| 307 | + |
|
| 308 | + if ( isset( $sites ) ) { |
|
| 309 | + $results = array(); |
|
| 310 | + foreach ( $sites as $site ) { |
|
| 311 | + $site = (array) $site; |
|
| 312 | + $k = $site['blog_id']; |
|
| 313 | + $v = $site['domain'] . $site['path']; |
|
| 314 | + $name = get_blog_option( $k, 'blogname' ); |
|
| 315 | + if ( ! empty( $name ) ) { |
|
| 316 | + $v .= ' - [' . $name . ']'; |
|
| 317 | + } |
|
| 318 | + $results[ $k ] = $v; |
|
| 319 | + } |
|
| 320 | + $data = $this->process_results( $results, '', '', $display_keys, $secondary_key ); |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + break; |
|
| 324 | + |
|
| 325 | + case 'taxonomies': |
|
| 326 | + case 'taxonomy': |
|
| 327 | + case 'tax': |
|
| 328 | + $results = get_taxonomies( $args ); |
|
| 329 | + $data = $this->process_results( $results, '', '', $display_keys, $secondary_key ); |
|
| 330 | + break; |
|
| 331 | + |
|
| 332 | + case 'post_types': |
|
| 333 | + case 'post_type': |
|
| 334 | + global $wp_post_types; |
|
| 335 | + |
|
| 336 | + $output = $args['output']; |
|
| 337 | + unset( $args['output'] ); |
|
| 338 | + $operator = $args['operator']; |
|
| 339 | + unset( $args['operator'] ); |
|
| 340 | + |
|
| 341 | + $post_types = get_post_types( $args, $output, $operator ); |
|
| 342 | + |
|
| 343 | + foreach ( $post_types as $name => $title ) { |
|
| 344 | + if ( isset( $wp_post_types[ $name ]->labels->menu_name ) ) { |
|
| 345 | + $data[ $name ] = $wp_post_types[ $name ]->labels->menu_name; |
|
| 346 | + } else { |
|
| 347 | + $data[ $name ] = ucfirst( $name ); |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + break; |
|
| 351 | + |
|
| 352 | + case 'menu_locations': |
|
| 353 | + case 'menu_location': |
|
| 354 | + global $_wp_registered_nav_menus; |
|
| 355 | + foreach ( $_wp_registered_nav_menus as $k => $v ) { |
|
| 356 | + $data[ $k ] = $v; |
|
| 357 | + if ( ! has_nav_menu( $k ) ) { |
|
| 358 | + $data[ $k ] .= ' ' . __( '[unassigned]', 'redux-framework' ); |
|
| 359 | + } |
|
| 360 | + } |
|
| 361 | + break; |
|
| 362 | + |
|
| 363 | + case 'image_sizes': |
|
| 364 | + case 'image_size': |
|
| 365 | + global $_wp_additional_image_sizes; |
|
| 366 | + $results = array(); |
|
| 367 | + foreach ( $_wp_additional_image_sizes as $size_name => $size_attrs ) { |
|
| 368 | + $results[ $size_name ] = $size_name . ' - ' . $size_attrs['width'] . ' x ' . $size_attrs['height']; |
|
| 369 | + } |
|
| 370 | + $data = $this->process_results( $results, '', '', $display_keys, $secondary_key ); |
|
| 371 | + |
|
| 372 | + break; |
|
| 373 | + |
|
| 374 | + case 'elusive-icons': |
|
| 375 | + case 'elusive-icon': |
|
| 376 | + case 'elusive': |
|
| 377 | + case 'icons': |
|
| 378 | + case 'font-icon': |
|
| 379 | + case 'font-icons': |
|
| 380 | + $fs = Redux_Filesystem::get_instance(); |
|
| 381 | + $fonts = $fs->get_contents( Redux_Core::$dir . 'assets/css/vendor/elusive-icons.css' ); |
|
| 382 | + if ( ! empty( $fonts ) ) { |
|
| 383 | + preg_match_all( '@\.el-(\w+)::before@', $fonts, $matches ); |
|
| 384 | + foreach ( $matches[1] as $item ) { |
|
| 385 | + if ( 'before' === $item ) { |
|
| 386 | + continue; |
|
| 387 | + } |
|
| 388 | + $data[ 'el el-' . $item ] = $item; |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Filter 'redux/font-icons' |
|
| 394 | + * |
|
| 395 | + * @param array $font_icons array of elusive icon classes |
|
| 396 | + * |
|
| 397 | + * @deprecated |
|
| 398 | + */ |
|
| 399 | + |
|
| 400 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 401 | + $font_icons = apply_filters_deprecated( 'redux/font-icons', array( $data ), '4.3', 'redux/$opt_name/field/font/icons' ); |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * Filter 'redux/{opt_name}/field/font/icons' |
|
| 405 | + * |
|
| 406 | + * @param array $font_icons array of elusive icon classes |
|
| 407 | + */ |
|
| 408 | + |
|
| 409 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 410 | + $data = apply_filters( "redux/$opt_name/field/font/icons", $font_icons ); |
|
| 411 | + |
|
| 412 | + break; |
|
| 413 | + |
|
| 414 | + case 'dashicons': |
|
| 415 | + case 'dashicon': |
|
| 416 | + case 'dash': |
|
| 417 | + $fs = Redux_Filesystem::get_instance(); |
|
| 418 | + $fonts = $fs->get_contents( ABSPATH . WPINC . '/css/dashicons.css' ); |
|
| 419 | + if ( ! empty( $fonts ) ) { |
|
| 420 | + preg_match_all( '@\.dashicons-(\w+):before@', $fonts, $matches ); |
|
| 421 | + foreach ( $matches[1] as $item ) { |
|
| 422 | + if ( 'before' === $item ) { |
|
| 423 | + continue; |
|
| 424 | + } |
|
| 425 | + $data[ 'dashicons dashicons-' . $item ] = $item; |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + break; |
|
| 429 | + |
|
| 430 | + case 'roles': |
|
| 431 | + case 'role': |
|
| 432 | + global $wp_roles; |
|
| 433 | + $results = $wp_roles->get_names(); |
|
| 434 | + $data = $this->process_results( $results, '', '', $display_keys, $secondary_key ); |
|
| 435 | + |
|
| 436 | + break; |
|
| 437 | + |
|
| 438 | + case 'sidebars': |
|
| 439 | + case 'sidebar': |
|
| 440 | + global $wp_registered_sidebars; |
|
| 441 | + $data = $this->process_results( $wp_registered_sidebars, '', 'name', $display_keys, $secondary_key ); |
|
| 442 | + break; |
|
| 443 | + case 'capabilities': |
|
| 444 | + case 'capability': |
|
| 445 | + global $wp_roles; |
|
| 446 | + $results = array(); |
|
| 447 | + foreach ( $wp_roles->roles as $role ) { |
|
| 448 | + foreach ( $role['capabilities'] as $key => $cap ) { |
|
| 449 | + $results[ $key ] = ucwords( str_replace( '_', ' ', $key ) ); |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + $data = $this->process_results( $results, '', '', $display_keys, $secondary_key ); |
|
| 453 | + |
|
| 454 | + break; |
|
| 455 | + |
|
| 456 | + case 'capabilities_grouped': |
|
| 457 | + case 'capability_grouped': |
|
| 458 | + case 'capabilities_group': |
|
| 459 | + case 'capability_group': |
|
| 460 | + global $wp_roles; |
|
| 461 | + |
|
| 462 | + foreach ( $wp_roles->roles as $role ) { |
|
| 463 | + $caps = array(); |
|
| 464 | + foreach ( $role['capabilities'] as $key => $cap ) { |
|
| 465 | + $caps[ $key ] = ucwords( str_replace( '_', ' ', $key ) ); |
|
| 466 | + } |
|
| 467 | + asort( $caps ); |
|
| 468 | + $data[ $role['name'] ] = $caps; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + break; |
|
| 472 | + |
|
| 473 | + case 'callback': |
|
| 474 | + if ( ! empty( $args ) && is_callable( $args ) ) { |
|
| 475 | + $data = call_user_func( $args, $current_value ); |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + break; |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + return $data; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + |
|
| 485 | + /** |
|
| 486 | + * Router for translation based on the given post-type. |
|
| 487 | + * |
|
| 488 | + * @param string $type Type of data request. |
|
| 489 | + * @param mixed|array $current_value Current value stored in DB. |
|
| 490 | + * @param array|string $args Arguments for the call. |
|
| 491 | + */ |
|
| 492 | + private function maybe_get_translation( string $type, &$current_value = '', $args = array() ) { |
|
| 493 | + switch ( $type ) { |
|
| 494 | + case 'categories': |
|
| 495 | + case 'category': |
|
| 496 | + $this->maybe_translate( $current_value, 'category' ); |
|
| 497 | + break; |
|
| 498 | + |
|
| 499 | + case 'pages': |
|
| 500 | + case 'page': |
|
| 501 | + $this->maybe_translate( $current_value, 'page' ); |
|
| 502 | + break; |
|
| 503 | + |
|
| 504 | + case 'terms': |
|
| 505 | + case 'term': |
|
| 506 | + $this->maybe_translate( $current_value, $args['taxonomy'] ?? '' ); |
|
| 507 | + break; |
|
| 508 | + |
|
| 509 | + case 'tags': |
|
| 510 | + case 'tag': |
|
| 511 | + $this->maybe_translate( $current_value, 'post_tag' ); |
|
| 512 | + break; |
|
| 513 | + |
|
| 514 | + case 'menus': |
|
| 515 | + case 'menu': |
|
| 516 | + $this->maybe_translate( $current_value, 'nav_menu' ); |
|
| 517 | + break; |
|
| 518 | + |
|
| 519 | + case 'post': |
|
| 520 | + case 'posts': |
|
| 521 | + $this->maybe_translate( $current_value, 'post' ); |
|
| 522 | + break; |
|
| 523 | + default: |
|
| 524 | + $this->maybe_translate( $current_value, '' ); |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * Maybe translate the values. |
|
| 530 | + * |
|
| 531 | + * @param mixed|array $value Value. |
|
| 532 | + * @param mixed|array $post_type Post type. |
|
| 533 | + */ |
|
| 534 | + private function maybe_translate( &$value, $post_type ) { |
|
| 535 | + |
|
| 536 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 537 | + $value = apply_filters( "redux/options/$this->opt_name/wordpress_data/translate/post_type_value", $value, $post_type ); |
|
| 538 | + |
|
| 539 | + // WPML Integration, see https://wpml.org/documentation/support/creating-multilingual-wordpress-themes/language-dependent-ids/. |
|
| 540 | + if ( function_exists( 'icl_object_id' ) ) { |
|
| 541 | + if ( has_filter( 'wpml_object_id' ) ) { |
|
| 542 | + if ( Redux_Helpers::is_integer( $value ) ) { |
|
| 543 | + $value = apply_filters( 'wpml_object_id', $value, $post_type, true ); |
|
| 544 | + } elseif ( is_array( $value ) ) { |
|
| 545 | + $value = array_map( |
|
| 546 | + function ( $val ) use ( $post_type ) { |
|
| 547 | + return apply_filters( 'wpml_object_id', $val, $post_type, true ); |
|
| 548 | + }, |
|
| 549 | + $value |
|
| 550 | + ); |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Set the default arguments for a current query (existing data). |
|
| 558 | + * |
|
| 559 | + * @param string $type Type of data request. |
|
| 560 | + * @param array|string $args Arguments for the call. |
|
| 561 | + * @param mixed|array $current_value Current value stored in DB. |
|
| 562 | + * |
|
| 563 | + * @return array |
|
| 564 | + */ |
|
| 565 | + private function get_current_data_args( string $type, $args, $current_value ): array { |
|
| 566 | + // In this section, we set the default arguments for each data type. |
|
| 567 | + switch ( $type ) { |
|
| 568 | + case 'categories': |
|
| 569 | + case 'category': |
|
| 570 | + case 'pages': |
|
| 571 | + case 'page': |
|
| 572 | + case 'terms': |
|
| 573 | + case 'term': |
|
| 574 | + case 'users': |
|
| 575 | + case 'user': |
|
| 576 | + $args['include'] = $current_value; |
|
| 577 | + break; |
|
| 578 | + case 'tags': |
|
| 579 | + case 'tag': |
|
| 580 | + $args['get'] = 'all'; |
|
| 581 | + break; |
|
| 582 | + case 'menus': |
|
| 583 | + case 'menu': |
|
| 584 | + $args['object_ids'] = $current_value; |
|
| 585 | + break; |
|
| 586 | + case 'post': |
|
| 587 | + case 'posts': |
|
| 588 | + if ( ! empty( $current_value ) ) { |
|
| 589 | + $args['post__in'] = is_array( $current_value ) ? $current_value : array( $current_value ); |
|
| 590 | + } |
|
| 591 | + break; |
|
| 592 | + |
|
| 593 | + default: |
|
| 594 | + $args = array(); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + return $args; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + |
|
| 601 | + /** |
|
| 602 | + * Get default arguments for a given data type. |
|
| 603 | + * |
|
| 604 | + * @param string $type Type of data request. |
|
| 605 | + * @param array|string $args Arguments for the call. |
|
| 606 | + * |
|
| 607 | + * @return array|string |
|
| 608 | + */ |
|
| 609 | + private function get_arg_defaults( string $type, $args = array() ) { |
|
| 610 | + // In this section, we set the default arguments for each data type. |
|
| 611 | + switch ( $type ) { |
|
| 612 | + case 'categories': |
|
| 613 | + case 'category': |
|
| 614 | + $args = wp_parse_args( |
|
| 615 | + $args, |
|
| 616 | + array( |
|
| 617 | + 'taxonomy' => 'category', |
|
| 618 | + ) |
|
| 619 | + ); |
|
| 620 | + break; |
|
| 621 | + |
|
| 622 | + case 'pages': |
|
| 623 | + case 'page': |
|
| 624 | + $args = wp_parse_args( |
|
| 625 | + $args, |
|
| 626 | + array( |
|
| 627 | + 'display_keys' => true, |
|
| 628 | + 'posts_per_page' => 20, |
|
| 629 | + ) |
|
| 630 | + ); |
|
| 631 | + break; |
|
| 632 | + |
|
| 633 | + case 'post_type': |
|
| 634 | + case 'post_types': |
|
| 635 | + $args = wp_parse_args( |
|
| 636 | + $args, |
|
| 637 | + array( |
|
| 638 | + 'public' => true, |
|
| 639 | + 'exclude_from_search' => false, |
|
| 640 | + 'output' => 'names', |
|
| 641 | + 'operator' => 'and', |
|
| 642 | + ) |
|
| 643 | + ); |
|
| 644 | + |
|
| 645 | + break; |
|
| 646 | + |
|
| 647 | + case 'tag': |
|
| 648 | + case 'tags': |
|
| 649 | + $args = wp_parse_args( |
|
| 650 | + $args, |
|
| 651 | + array( |
|
| 652 | + 'get' => 'all', |
|
| 653 | + 'display_keys' => true, |
|
| 654 | + ) |
|
| 655 | + ); |
|
| 656 | + break; |
|
| 657 | + |
|
| 658 | + case 'sidebars': |
|
| 659 | + case 'sidebar': |
|
| 660 | + case 'capabilities': |
|
| 661 | + case 'capability': |
|
| 662 | + $args = wp_parse_args( |
|
| 663 | + $args, |
|
| 664 | + array( |
|
| 665 | + 'display_keys' => true, |
|
| 666 | + ) |
|
| 667 | + ); |
|
| 668 | + break; |
|
| 669 | + |
|
| 670 | + case 'capabilities_grouped': |
|
| 671 | + case 'capability_grouped': |
|
| 672 | + case 'capabilities_group': |
|
| 673 | + case 'capability_group': |
|
| 674 | + $args = wp_parse_args( |
|
| 675 | + $args, |
|
| 676 | + array( |
|
| 677 | + 'data_sortby' => '', |
|
| 678 | + ) |
|
| 679 | + ); |
|
| 680 | + break; |
|
| 681 | + |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + return $args; |
|
| 685 | + } |
|
| 686 | + } |
|
| 687 | 687 | } |
@@ -14,1184 +14,1184 @@ discard block |
||
| 14 | 14 | // Don't duplicate me! |
| 15 | 15 | if ( ! class_exists( 'Redux_Extension_Metaboxes', false ) ) { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Main Redux_Extension_Metaboxes class |
|
| 19 | - * |
|
| 20 | - * @since 1.0.0 |
|
| 21 | - */ |
|
| 22 | - class Redux_Extension_Metaboxes extends Redux_Extension_Abstract { |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Extension version. |
|
| 26 | - * |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - public static $version = '4.2.0'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Extension friendly name. |
|
| 33 | - * |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - public string $extension_name = 'Metaboxes'; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Boxes array. |
|
| 40 | - * |
|
| 41 | - * @var array|null |
|
| 42 | - */ |
|
| 43 | - public ?array $boxes = array(); |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Post types array. |
|
| 47 | - * |
|
| 48 | - * @var array|null |
|
| 49 | - */ |
|
| 50 | - public ?array $post_types = array(); |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Post type. |
|
| 54 | - * |
|
| 55 | - * @var string|null |
|
| 56 | - */ |
|
| 57 | - public ?string $post_type; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Sections array. |
|
| 61 | - * |
|
| 62 | - * @var array|null |
|
| 63 | - */ |
|
| 64 | - public ?array $orig_args; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * Sections array. |
|
| 68 | - * |
|
| 69 | - * @var array|null |
|
| 70 | - */ |
|
| 71 | - public ?array $sections = array(); |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * CSS output array. |
|
| 75 | - * |
|
| 76 | - * @var array|null |
|
| 77 | - */ |
|
| 78 | - public ?array $output = array(); |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Options array. |
|
| 82 | - * |
|
| 83 | - * @var array |
|
| 84 | - */ |
|
| 85 | - public array $options = array(); |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Parent options array. |
|
| 89 | - * |
|
| 90 | - * @var array |
|
| 91 | - */ |
|
| 92 | - public array $parent_options = array(); |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * Parent defaults array. |
|
| 96 | - * |
|
| 97 | - * @var array |
|
| 98 | - */ |
|
| 99 | - public array $parent_defaults = array(); |
|
| 100 | - |
|
| 101 | - /** |
|
| 102 | - * Post type fields array. |
|
| 103 | - * |
|
| 104 | - * @var array |
|
| 105 | - */ |
|
| 106 | - public array $post_type_fields = array(); |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * Options defaults array. |
|
| 110 | - * |
|
| 111 | - * @var array |
|
| 112 | - */ |
|
| 113 | - public array $options_defaults = array(); |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * Replace array. |
|
| 117 | - * |
|
| 118 | - * @var array |
|
| 119 | - */ |
|
| 120 | - public array $to_replace = array(); |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Meta data array. |
|
| 124 | - * |
|
| 125 | - * @var array |
|
| 126 | - */ |
|
| 127 | - public array $meta = array(); |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Post ID. |
|
| 131 | - * |
|
| 132 | - * @var null|int |
|
| 133 | - */ |
|
| 134 | - public ?int $post_id = 0; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Base URI. |
|
| 138 | - * |
|
| 139 | - * @var string|null |
|
| 140 | - */ |
|
| 141 | - public ?string $base_url; |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * WP_Links array. |
|
| 145 | - * |
|
| 146 | - * @var array |
|
| 147 | - */ |
|
| 148 | - public array $wp_links = array(); |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * Notices. |
|
| 152 | - * |
|
| 153 | - * @var array |
|
| 154 | - */ |
|
| 155 | - private array $notices = array(); |
|
| 156 | - |
|
| 157 | - /** |
|
| 158 | - * ReduxFramework_extension_metaboxes constructor. |
|
| 159 | - * |
|
| 160 | - * @param object $redux ReduxFramework object. |
|
| 161 | - */ |
|
| 162 | - public function __construct( $redux ) { |
|
| 163 | - global $pagenow; |
|
| 164 | - |
|
| 165 | - parent::__construct( $redux, __FILE__ ); |
|
| 166 | - |
|
| 167 | - $this->parent->extensions['metaboxes'] = $this; |
|
| 168 | - |
|
| 169 | - $this->extension_dir = trailingslashit( str_replace( '\\', '/', __DIR__ ) ); |
|
| 170 | - $this->extension_url = site_url( str_replace( trailingslashit( str_replace( '\\', '/', ABSPATH ) ), '', $this->extension_dir ) ); |
|
| 171 | - |
|
| 172 | - // Only run metaboxes on the pages/posts, not the front-end. |
|
| 173 | - // The DOING_AJAX check allows for redux_post_meta to work inside |
|
| 174 | - // AJAX calls. - kp. |
|
| 175 | - if ( 'post-new.php' !== $pagenow && 'post.php' !== $pagenow ) { |
|
| 176 | - if ( is_admin() ) { |
|
| 177 | - if ( defined( 'DOING_AJAX' ) && ! DOING_AJAX ) { |
|
| 178 | - return; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - return; |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - if ( 'wp-cron.php' === $pagenow || 'wp-comments-post.php' === $pagenow ) { |
|
| 186 | - return; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // Must not update the DB when just updating metaboxes. Sheesh. |
|
| 190 | - if ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) { |
|
| 191 | - $this->parent->never_save_to_db = true; |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - include_once Redux_Core::$dir . 'inc/extensions/metaboxes/redux-metaboxes-helpers.php'; |
|
| 195 | - |
|
| 196 | - // phpcs:ignore Generic.Strings.UnnecessaryStringConcat |
|
| 197 | - add_action( 'add_' . 'meta_' . 'boxes', array( $this, 'add' ) ); |
|
| 198 | - add_action( 'save_post', array( $this, 'meta_boxes_save' ), 1, 2 ); |
|
| 199 | - add_action( 'pre_post_update', array( $this, 'pre_post_update' ) ); |
|
| 200 | - add_action( 'admin_notices', array( $this, 'meta_boxes_show_errors' ), 0 ); |
|
| 201 | - add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ), 20 ); |
|
| 202 | - |
|
| 203 | - // Global variable overrides for within loops. |
|
| 204 | - add_action( 'the_post', array( $this, 'loop_start' ), 0 ); |
|
| 205 | - add_action( 'loop_end', array( $this, 'loop_end' ), 0 ); |
|
| 206 | - |
|
| 207 | - $this->init(); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Added class names to metabox DIV. |
|
| 212 | - * |
|
| 213 | - * @param array $classes Class array. |
|
| 214 | - * |
|
| 215 | - * @return array |
|
| 216 | - */ |
|
| 217 | - public function add_box_classes( array $classes ): array { |
|
| 218 | - $classes[] = 'redux-metabox'; |
|
| 219 | - $classes[] = 'redux-' . $this->parent->args['opt_name']; |
|
| 220 | - |
|
| 221 | - if ( '' !== $this->parent->args['class'] ) { |
|
| 222 | - $classes[] = $this->parent->args['class']; |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - return $classes; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * Class init. |
|
| 230 | - */ |
|
| 231 | - public function init() { |
|
| 232 | - global $pagenow; |
|
| 233 | - |
|
| 234 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 235 | - $this->boxes = apply_filters( 'redux/metaboxes/' . $this->parent->args['opt_name'] . '/boxes', $this->boxes, $this->parent->args['opt_name'] ); |
|
| 236 | - |
|
| 237 | - if ( empty( $this->boxes ) && class_exists( 'Redux_Metaboxes' ) ) { |
|
| 238 | - $this->boxes = Redux_Metaboxes::construct_boxes( $this->parent->args['opt_name'] ); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - if ( empty( $this->boxes ) || ! is_array( $this->boxes ) ) { |
|
| 242 | - return; |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - if ( isset( Redux_Core::$server['HTTP_HOST'] ) && isset( Redux_Core::$server['REQUEST_URI'] ) ) { |
|
| 246 | - $this->base_url = ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( wp_unslash( Redux_Core::$server['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( Redux_Core::$server['REQUEST_URI'] ) ); // Safe & Reliable. |
|
| 247 | - $this->post_id = $this->url_to_postid( ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( wp_unslash( Redux_Core::$server['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( Redux_Core::$server['REQUEST_URI'] ) ) ); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - if ( is_admin() && isset( $_GET['post_type'] ) && ! empty( $_GET['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 251 | - $this->post_type = sanitize_text_field( wp_unslash( $_GET['post_type'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 252 | - } else { |
|
| 253 | - $this->post_type = get_post_type( $this->post_id ); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - foreach ( $this->boxes as $bk => $box ) { |
|
| 257 | - |
|
| 258 | - // If the post-ids for this box are set, we're limiting to the current post id. |
|
| 259 | - if ( ! empty( $box['post_ids'] ) ) { |
|
| 260 | - if ( ! is_array( $box['post_ids'] ) ) { |
|
| 261 | - $box['post_ids'] = array( $box['post_ids'] ); |
|
| 262 | - } |
|
| 263 | - if ( ! in_array( $this->post_id, $box['post_ids'], true ) ) { |
|
| 264 | - continue; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - if ( ! empty( $box['sections'] ) ) { |
|
| 269 | - $this->sections = wp_parse_args( $this->sections, $box['sections'] ); |
|
| 270 | - |
|
| 271 | - $this->post_types = wp_parse_args( $this->post_types, $box['post_types'] ); |
|
| 272 | - |
|
| 273 | - // Checking to override the parent variables. |
|
| 274 | - $add_field = false; |
|
| 275 | - |
|
| 276 | - foreach ( $box['post_types'] as $type ) { |
|
| 277 | - if ( $this->post_type === $type ) { |
|
| 278 | - $add_field = true; |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // Replacing all the fields. |
|
| 283 | - if ( $add_field || ( ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) || ( ! is_admin() ) ) ) { |
|
| 284 | - $run_hooks = true; |
|
| 285 | - |
|
| 286 | - $box_id = 'redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id']; |
|
| 287 | - |
|
| 288 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 289 | - do_action( 'redux/' . $this->parent->args['opt_name'] . '/extensions/metabox/init', $this, $box ); |
|
| 290 | - |
|
| 291 | - if ( isset( $box['page_template'] ) && 'page' === $this->post_type ) { |
|
| 292 | - if ( ! is_array( $box['page_template'] ) ) { |
|
| 293 | - $box['page_template'] = array( $box['page_template'] ); |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - $this->wp_links[ $box_id ]['page_template'] = isset( $this->wp_links[ $box_id ]['page_template'] ) ? wp_parse_args( $this->wp_links[ $box_id ]['page_template'], $box['page_template'] ) : $box['page_template']; |
|
| 297 | - } |
|
| 298 | - |
|
| 299 | - if ( isset( $box['post_format'] ) && ( in_array( $this->post_type, $this->post_types, true ) || '' === $this->post_type || false === $this->post_type ) ) { |
|
| 300 | - if ( ! is_array( $box['post_format'] ) ) { |
|
| 301 | - $box['post_format'] = array( $box['post_format'] ); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - $this->wp_links[ $box_id ]['post_format'] = isset( $this->wp_links[ $box_id ]['post_format'] ) ? wp_parse_args( $this->wp_links[ $box_id ]['post_format'], $box['post_format'] ) : $box['post_format']; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - $this->meta[ $this->post_id ] = $this->get_meta( $this->post_id ); |
|
| 308 | - |
|
| 309 | - foreach ( $box['sections'] as $sk => $section ) { |
|
| 310 | - if ( ! empty( $section['fields'] ) ) { |
|
| 311 | - foreach ( $section['fields'] as $fk => $field ) { |
|
| 312 | - if ( ! isset( $field['class'] ) ) { |
|
| 313 | - $field['class'] = ''; |
|
| 314 | - |
|
| 315 | - $this->boxes[ $bk ]['sections'][ $sk ]['fields'][ $fk ] = $field; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - if ( $add_field || ( ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) || ( ! is_admin() ) ) ) { |
|
| 319 | - if ( empty( $field['id'] ) ) { |
|
| 320 | - continue; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - if ( isset( $field['default'] ) ) { |
|
| 324 | - $this->options_defaults[ $field['id'] ] = $field['default']; |
|
| 325 | - } else { |
|
| 326 | - $this->options_defaults[ $field['id'] ] = $this->field_default( $field ); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - foreach ( $box['post_types'] as $type ) { |
|
| 330 | - $this->post_type_fields[ $type ][ $field['id'] ] = 1; |
|
| 331 | - |
|
| 332 | - if ( 'repeater' === $field['type'] ) { |
|
| 333 | - foreach ( $field['fields'] as $val ) { |
|
| 334 | - $this->post_type_fields[ $type ][ $val['id'] ] = 1; |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - if ( ! empty( $field['output'] ) ) { |
|
| 340 | - $this->output[ $field['id'] ] = isset( $this->output[ $field['id'] ] ) ? array_merge( $field['output'], $this->output[ $field['id'] ] ) : $field['output']; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - // Detect what field types are being used. |
|
| 344 | - if ( ! isset( $this->parent->fields[ $field['type'] ][ $field['id'] ] ) ) { |
|
| 345 | - $this->parent->fields[ $field['type'] ][ $field['id'] ] = 1; |
|
| 346 | - } else { |
|
| 347 | - $this->parent->fields[ $field['type'] ] = array( $field['id'] => 1 ); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - if ( isset( $this->options_defaults[ $field['id'] ] ) ) { |
|
| 351 | - $this->to_replace[ $field['id'] ] = $field; |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - if ( ! isset( $this->parent->options[ $field['id'] ] ) ) { |
|
| 356 | - $this->parent->sections[ ( count( $this->parent->sections ) - 1 ) ]['fields'][] = $field; |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - if ( ! isset( $this->meta[ $this->post_id ][ $field['id'] ] ) ) { |
|
| 360 | - $this->meta[ $this->post_id ][ $field['id'] ] = $this->options_defaults[ $field['id'] ]; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - // Only override if it exists, and it's not the default. |
|
| 364 | - // phpcs:ignore Squiz.PHP.CommentedOutCode |
|
| 365 | - // if ( isset( $this->meta[ $this->post_id ][ $field['id'] ] ) && isset( $field['default'] ) && $this->meta[ $this->post_id ][ $field['id'] ] === $field['default'] ) { |
|
| 366 | - // unset($this->meta[$this->post_id][$field['id']]); |
|
| 367 | - // } . |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - if ( isset( $run_hooks ) && true === $run_hooks ) { |
|
| 376 | - $this->parent_options = array(); |
|
| 377 | - |
|
| 378 | - if ( ! empty( $this->to_replace ) ) { |
|
| 379 | - foreach ( $this->to_replace as $id => $field ) { |
|
| 380 | - |
|
| 381 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 382 | - add_filter( "redux/options/{$this->parent->args['opt_name']}/field/$id/register", array( $this, 'replace_field' ) ); |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - add_filter( "redux/options/{$this->parent->args['opt_name']}/options", array( $this, 'override_options' ) ); |
|
| 387 | - add_filter( "redux/field/{$this->parent->args['opt_name']}/_can_output_css", array( $this, 'override_can_output_css' ) ); |
|
| 388 | - add_filter( "redux/field/{$this->parent->args['opt_name']}/output_css", array( $this, 'output_css' ) ); |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Replace Field. |
|
| 394 | - * |
|
| 395 | - * @param array $field Field array. |
|
| 396 | - * |
|
| 397 | - * @return mixed |
|
| 398 | - */ |
|
| 399 | - public function replace_field( array $field ) { |
|
| 400 | - if ( isset( $this->to_replace[ $field['id'] ] ) ) { |
|
| 401 | - $field = $this->to_replace[ $field['id'] ]; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - return $field; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * Override CSS output. |
|
| 409 | - * |
|
| 410 | - * @param array $field Field array. |
|
| 411 | - * |
|
| 412 | - * @return array |
|
| 413 | - */ |
|
| 414 | - public function override_can_output_css( array $field ): array { |
|
| 415 | - if ( isset( $this->output[ $field['id'] ] ) ) { |
|
| 416 | - $field['force_output'] = true; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - return $field; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * Output CSS. |
|
| 424 | - * |
|
| 425 | - * @param array $field Field array. |
|
| 426 | - * |
|
| 427 | - * @return array |
|
| 428 | - */ |
|
| 429 | - public function output_css( array $field ): array { |
|
| 430 | - if ( isset( $this->output[ $field['id'] ] ) ) { |
|
| 431 | - $field['output'] = $this->output[ $field['id'] ]; |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - return $field; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - /** |
|
| 438 | - * Make sure the defaults are the defaults |
|
| 439 | - * |
|
| 440 | - * @param array $options Options array. |
|
| 441 | - * |
|
| 442 | - * @return array |
|
| 443 | - */ |
|
| 444 | - public function override_options( array $options ): array { |
|
| 445 | - $this->parent->default_values(); |
|
| 446 | - $this->parent_defaults = $this->parent->options_defaults; |
|
| 447 | - |
|
| 448 | - $meta = $this->get_meta( $this->post_id ); |
|
| 449 | - $data = wp_parse_args( $meta, $this->options_defaults ); |
|
| 450 | - |
|
| 451 | - foreach ( $data as $key => $value ) { |
|
| 452 | - if ( isset( $meta[ $key ] ) && '' !== $meta[ $key ] ) { |
|
| 453 | - $data[ $key ] = $meta[ $key ]; |
|
| 454 | - continue; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - if ( isset( $options[ $key ] ) ) { |
|
| 458 | - $data[ $key ] = $options[ $key ]; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - $this->parent->options_defaults = wp_parse_args( $this->options_defaults, $this->parent->options_defaults ); |
|
| 463 | - |
|
| 464 | - return wp_parse_args( $data, $options ); |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Loop start. |
|
| 469 | - * |
|
| 470 | - * @param mixed $the_post WP_Post object. |
|
| 471 | - * |
|
| 472 | - * @return array|void |
|
| 473 | - */ |
|
| 474 | - public function loop_start( $the_post = array() ) { |
|
| 475 | - if ( is_admin() ) { |
|
| 476 | - return $the_post; |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - if ( isset( $the_post ) && is_array( $the_post ) ) { |
|
| 480 | - global $post; |
|
| 481 | - $the_post = $post; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - if ( isset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ) ) { |
|
| 485 | - $GLOBALS[ $this->parent->args['global_variable'] ] = $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ]; |
|
| 486 | - unset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ); |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - // Override these values if they differ from the admin panel defaults. ;) . |
|
| 490 | - if ( in_array( $the_post->post_type, $this->post_types, true ) ) { |
|
| 491 | - $meta = $this->get_meta( $the_post->ID ); |
|
| 492 | - if ( empty( $meta ) ) { |
|
| 493 | - return; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - // Backup the args. |
|
| 497 | - $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] = $GLOBALS[ $this->parent->args['global_variable'] ]; |
|
| 498 | - $GLOBALS[ $this->parent->args['global_variable'] ] = wp_parse_args( $meta, $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ); |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Loop end. |
|
| 504 | - */ |
|
| 505 | - public function loop_end() { |
|
| 506 | - if ( isset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ) ) { |
|
| 507 | - $GLOBALS[ $this->parent->args['global_variable'] ] = $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ]; |
|
| 508 | - |
|
| 509 | - unset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ); |
|
| 510 | - } |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * Enqueue fields. |
|
| 515 | - */ |
|
| 516 | - public function enqueue() { |
|
| 517 | - global $pagenow; |
|
| 518 | - |
|
| 519 | - $types = array(); |
|
| 520 | - |
|
| 521 | - // Enqueue CSS. |
|
| 522 | - foreach ( $this->boxes as $key => $box ) { |
|
| 523 | - if ( empty( $box['sections'] ) ) { |
|
| 524 | - continue; |
|
| 525 | - } |
|
| 526 | - |
|
| 527 | - if ( isset( $box['post_types'] ) ) { |
|
| 528 | - $types = array_merge( $box['post_types'], $types ); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - if ( ! empty( $box['post_types'] ) ) { |
|
| 532 | - if ( ! is_array( $box['post_types'] ) ) { |
|
| 533 | - $box['post_types'] = array( $box['post_types'] ); |
|
| 534 | - $this->boxes[ $key ]['post_types'] = $box['post_types']; |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - if ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) { |
|
| 540 | - global $post; |
|
| 541 | - |
|
| 542 | - if ( in_array( $post->post_type, $types, true ) ) { |
|
| 543 | - $this->parent->transients = get_transient( $this->parent->args['opt_name'] . '-transients-metaboxes' ); |
|
| 544 | - $this->parent->transients_check = $this->parent->transients; |
|
| 545 | - |
|
| 546 | - if ( isset( $this->parent->transients['notices'] ) ) { |
|
| 547 | - $this->notices = $this->parent->transients['notices']; |
|
| 548 | - $this->parent->transients['last_save_mode'] = 'metaboxes'; |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - delete_transient( $this->parent->args['opt_name'] . '-transients-metaboxes' ); |
|
| 552 | - $this->parent->enqueue_class->init(); |
|
| 553 | - |
|
| 554 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 555 | - do_action( "redux/metaboxes/{$this->parent->args['opt_name']}/enqueue" ); |
|
| 556 | - |
|
| 557 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 558 | - do_action( "redux/{$this->parent->args['opt_name']}/extensions/metaboxes/enqueue" ); |
|
| 559 | - |
|
| 560 | - /** |
|
| 561 | - * Redux metaboxes CSS |
|
| 562 | - * filter 'redux/page/{opt_name}/enqueue/redux-extension-metaboxes-css' |
|
| 563 | - */ |
|
| 564 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 565 | - wp_enqueue_style( |
|
| 566 | - 'redux-extension-metaboxes', |
|
| 567 | - apply_filters( "redux/metaboxes/{$this->parent->args['opt_name']}/enqueue/redux-extension-metaboxes-css", $this->extension_url . 'redux-extension-metaboxes.css' ), // phpcs:ignore: WordPress.NamingConventions.ValidHookName |
|
| 568 | - array(), |
|
| 569 | - self::$version |
|
| 570 | - ); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - /** |
|
| 574 | - * Redux metaboxes JS |
|
| 575 | - * filter 'redux/page/{opt_name}/enqueue/redux-extension-metaboxes-js |
|
| 576 | - */ |
|
| 577 | - wp_enqueue_script( |
|
| 578 | - 'redux-extension-metaboxes', |
|
| 579 | - apply_filters( "redux/metaboxes/{$this->parent->args['opt_name']}/enqueue/redux-extension-metaboxes-js", $this->extension_url . 'redux-extension-metaboxes' . Redux_Functions::isMin() . '.js' ), // phpcs:ignore: WordPress.NamingConventions.ValidHookName |
|
| 580 | - array( 'jquery', 'redux-js' ), |
|
| 581 | - self::$version, |
|
| 582 | - true |
|
| 583 | - ); |
|
| 584 | - |
|
| 585 | - // Values used by the javascript. |
|
| 586 | - wp_localize_script( |
|
| 587 | - 'redux-extension-metaboxes', |
|
| 588 | - 'reduxMetaboxes', |
|
| 589 | - $this->wp_links |
|
| 590 | - ); |
|
| 591 | - |
|
| 592 | - wp_localize_script( |
|
| 593 | - 'redux-extension-metaboxes', |
|
| 594 | - 'reduxMetaboxesPageTemplate', |
|
| 595 | - array( |
|
| 596 | - '_wp_page_template' => get_post_meta( get_the_ID(), '_wp_page_template', true ), |
|
| 597 | - ) |
|
| 598 | - ); |
|
| 599 | - } |
|
| 600 | - } |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - /* Post URLs to IDs function, supports custom post types - borrowed and modified from url_to_postid() in wp-includes/rewrite.php */ |
|
| 604 | - |
|
| 605 | - // Taken from http://betterwp.net/wordpress-tips/url_to_postid-for-custom-post-types/ |
|
| 606 | - // Customized to work with non-rewrite URLs |
|
| 607 | - // Modified by Dovy Paukstys (@dovy) of Redux Framework. |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * URL to PostID. |
|
| 611 | - * |
|
| 612 | - * @param string $url URL. |
|
| 613 | - * |
|
| 614 | - * @return int|mixed|void |
|
| 615 | - */ |
|
| 616 | - private function url_to_postid( string $url ) { |
|
| 617 | - global $wp_rewrite, $pagenow; |
|
| 618 | - |
|
| 619 | - if ( ! empty( $this->post_id ) ) { |
|
| 620 | - return $this->post_id; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - if ( isset( $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 624 | - $post = (int) sanitize_text_field( wp_unslash( $_GET['post'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 625 | - |
|
| 626 | - if ( ! empty( $post ) ) { |
|
| 627 | - return $post; |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - if ( 'post-new.php' === $pagenow || 'wp-login.php' === $pagenow ) { |
|
| 632 | - return; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - if ( is_admin() && 'post.php' === $pagenow && isset( $_POST['post_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 636 | - $post_id = sanitize_text_field( wp_unslash( $_POST['post_ID'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 637 | - |
|
| 638 | - if ( ! empty( $post_id ) && is_numeric( $post_id ) ) { |
|
| 639 | - return $post_id; |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - $post_id = url_to_postid( $url ); |
|
| 644 | - |
|
| 645 | - if ( isset( $post_id ) && '' !== (string) $post_id && 0 !== $post_id ) { |
|
| 646 | - return $post_id; |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - // First, check to see if there is a 'p=N' or 'page_id=N' to match against. |
|
| 650 | - if ( preg_match( '#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values ) ) { |
|
| 651 | - $id = absint( $values[2] ); |
|
| 652 | - if ( $id ) { |
|
| 653 | - return $id; |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - // Check to see if we are using rewrite rules. |
|
| 658 | - if ( isset( $wp_rewrite ) ) { |
|
| 659 | - $rewrite = $wp_rewrite->wp_rewrite_rules(); |
|
| 660 | - } |
|
| 661 | - |
|
| 662 | - // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options. |
|
| 663 | - if ( empty( $rewrite ) ) { |
|
| 664 | - if ( ! empty( $_GET ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 665 | - |
|
| 666 | - /************************************************************************ |
|
| 17 | + /** |
|
| 18 | + * Main Redux_Extension_Metaboxes class |
|
| 19 | + * |
|
| 20 | + * @since 1.0.0 |
|
| 21 | + */ |
|
| 22 | + class Redux_Extension_Metaboxes extends Redux_Extension_Abstract { |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Extension version. |
|
| 26 | + * |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + public static $version = '4.2.0'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Extension friendly name. |
|
| 33 | + * |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + public string $extension_name = 'Metaboxes'; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Boxes array. |
|
| 40 | + * |
|
| 41 | + * @var array|null |
|
| 42 | + */ |
|
| 43 | + public ?array $boxes = array(); |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Post types array. |
|
| 47 | + * |
|
| 48 | + * @var array|null |
|
| 49 | + */ |
|
| 50 | + public ?array $post_types = array(); |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Post type. |
|
| 54 | + * |
|
| 55 | + * @var string|null |
|
| 56 | + */ |
|
| 57 | + public ?string $post_type; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Sections array. |
|
| 61 | + * |
|
| 62 | + * @var array|null |
|
| 63 | + */ |
|
| 64 | + public ?array $orig_args; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * Sections array. |
|
| 68 | + * |
|
| 69 | + * @var array|null |
|
| 70 | + */ |
|
| 71 | + public ?array $sections = array(); |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * CSS output array. |
|
| 75 | + * |
|
| 76 | + * @var array|null |
|
| 77 | + */ |
|
| 78 | + public ?array $output = array(); |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Options array. |
|
| 82 | + * |
|
| 83 | + * @var array |
|
| 84 | + */ |
|
| 85 | + public array $options = array(); |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Parent options array. |
|
| 89 | + * |
|
| 90 | + * @var array |
|
| 91 | + */ |
|
| 92 | + public array $parent_options = array(); |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * Parent defaults array. |
|
| 96 | + * |
|
| 97 | + * @var array |
|
| 98 | + */ |
|
| 99 | + public array $parent_defaults = array(); |
|
| 100 | + |
|
| 101 | + /** |
|
| 102 | + * Post type fields array. |
|
| 103 | + * |
|
| 104 | + * @var array |
|
| 105 | + */ |
|
| 106 | + public array $post_type_fields = array(); |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * Options defaults array. |
|
| 110 | + * |
|
| 111 | + * @var array |
|
| 112 | + */ |
|
| 113 | + public array $options_defaults = array(); |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * Replace array. |
|
| 117 | + * |
|
| 118 | + * @var array |
|
| 119 | + */ |
|
| 120 | + public array $to_replace = array(); |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Meta data array. |
|
| 124 | + * |
|
| 125 | + * @var array |
|
| 126 | + */ |
|
| 127 | + public array $meta = array(); |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Post ID. |
|
| 131 | + * |
|
| 132 | + * @var null|int |
|
| 133 | + */ |
|
| 134 | + public ?int $post_id = 0; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Base URI. |
|
| 138 | + * |
|
| 139 | + * @var string|null |
|
| 140 | + */ |
|
| 141 | + public ?string $base_url; |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * WP_Links array. |
|
| 145 | + * |
|
| 146 | + * @var array |
|
| 147 | + */ |
|
| 148 | + public array $wp_links = array(); |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * Notices. |
|
| 152 | + * |
|
| 153 | + * @var array |
|
| 154 | + */ |
|
| 155 | + private array $notices = array(); |
|
| 156 | + |
|
| 157 | + /** |
|
| 158 | + * ReduxFramework_extension_metaboxes constructor. |
|
| 159 | + * |
|
| 160 | + * @param object $redux ReduxFramework object. |
|
| 161 | + */ |
|
| 162 | + public function __construct( $redux ) { |
|
| 163 | + global $pagenow; |
|
| 164 | + |
|
| 165 | + parent::__construct( $redux, __FILE__ ); |
|
| 166 | + |
|
| 167 | + $this->parent->extensions['metaboxes'] = $this; |
|
| 168 | + |
|
| 169 | + $this->extension_dir = trailingslashit( str_replace( '\\', '/', __DIR__ ) ); |
|
| 170 | + $this->extension_url = site_url( str_replace( trailingslashit( str_replace( '\\', '/', ABSPATH ) ), '', $this->extension_dir ) ); |
|
| 171 | + |
|
| 172 | + // Only run metaboxes on the pages/posts, not the front-end. |
|
| 173 | + // The DOING_AJAX check allows for redux_post_meta to work inside |
|
| 174 | + // AJAX calls. - kp. |
|
| 175 | + if ( 'post-new.php' !== $pagenow && 'post.php' !== $pagenow ) { |
|
| 176 | + if ( is_admin() ) { |
|
| 177 | + if ( defined( 'DOING_AJAX' ) && ! DOING_AJAX ) { |
|
| 178 | + return; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + return; |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + if ( 'wp-cron.php' === $pagenow || 'wp-comments-post.php' === $pagenow ) { |
|
| 186 | + return; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // Must not update the DB when just updating metaboxes. Sheesh. |
|
| 190 | + if ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) { |
|
| 191 | + $this->parent->never_save_to_db = true; |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + include_once Redux_Core::$dir . 'inc/extensions/metaboxes/redux-metaboxes-helpers.php'; |
|
| 195 | + |
|
| 196 | + // phpcs:ignore Generic.Strings.UnnecessaryStringConcat |
|
| 197 | + add_action( 'add_' . 'meta_' . 'boxes', array( $this, 'add' ) ); |
|
| 198 | + add_action( 'save_post', array( $this, 'meta_boxes_save' ), 1, 2 ); |
|
| 199 | + add_action( 'pre_post_update', array( $this, 'pre_post_update' ) ); |
|
| 200 | + add_action( 'admin_notices', array( $this, 'meta_boxes_show_errors' ), 0 ); |
|
| 201 | + add_action( 'admin_enqueue_scripts', array( $this, 'enqueue' ), 20 ); |
|
| 202 | + |
|
| 203 | + // Global variable overrides for within loops. |
|
| 204 | + add_action( 'the_post', array( $this, 'loop_start' ), 0 ); |
|
| 205 | + add_action( 'loop_end', array( $this, 'loop_end' ), 0 ); |
|
| 206 | + |
|
| 207 | + $this->init(); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Added class names to metabox DIV. |
|
| 212 | + * |
|
| 213 | + * @param array $classes Class array. |
|
| 214 | + * |
|
| 215 | + * @return array |
|
| 216 | + */ |
|
| 217 | + public function add_box_classes( array $classes ): array { |
|
| 218 | + $classes[] = 'redux-metabox'; |
|
| 219 | + $classes[] = 'redux-' . $this->parent->args['opt_name']; |
|
| 220 | + |
|
| 221 | + if ( '' !== $this->parent->args['class'] ) { |
|
| 222 | + $classes[] = $this->parent->args['class']; |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + return $classes; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * Class init. |
|
| 230 | + */ |
|
| 231 | + public function init() { |
|
| 232 | + global $pagenow; |
|
| 233 | + |
|
| 234 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 235 | + $this->boxes = apply_filters( 'redux/metaboxes/' . $this->parent->args['opt_name'] . '/boxes', $this->boxes, $this->parent->args['opt_name'] ); |
|
| 236 | + |
|
| 237 | + if ( empty( $this->boxes ) && class_exists( 'Redux_Metaboxes' ) ) { |
|
| 238 | + $this->boxes = Redux_Metaboxes::construct_boxes( $this->parent->args['opt_name'] ); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + if ( empty( $this->boxes ) || ! is_array( $this->boxes ) ) { |
|
| 242 | + return; |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + if ( isset( Redux_Core::$server['HTTP_HOST'] ) && isset( Redux_Core::$server['REQUEST_URI'] ) ) { |
|
| 246 | + $this->base_url = ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( wp_unslash( Redux_Core::$server['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( Redux_Core::$server['REQUEST_URI'] ) ); // Safe & Reliable. |
|
| 247 | + $this->post_id = $this->url_to_postid( ( is_ssl() ? 'https://' : 'http://' ) . sanitize_text_field( wp_unslash( Redux_Core::$server['HTTP_HOST'] ) ) . sanitize_text_field( wp_unslash( Redux_Core::$server['REQUEST_URI'] ) ) ); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + if ( is_admin() && isset( $_GET['post_type'] ) && ! empty( $_GET['post_type'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 251 | + $this->post_type = sanitize_text_field( wp_unslash( $_GET['post_type'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 252 | + } else { |
|
| 253 | + $this->post_type = get_post_type( $this->post_id ); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + foreach ( $this->boxes as $bk => $box ) { |
|
| 257 | + |
|
| 258 | + // If the post-ids for this box are set, we're limiting to the current post id. |
|
| 259 | + if ( ! empty( $box['post_ids'] ) ) { |
|
| 260 | + if ( ! is_array( $box['post_ids'] ) ) { |
|
| 261 | + $box['post_ids'] = array( $box['post_ids'] ); |
|
| 262 | + } |
|
| 263 | + if ( ! in_array( $this->post_id, $box['post_ids'], true ) ) { |
|
| 264 | + continue; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + if ( ! empty( $box['sections'] ) ) { |
|
| 269 | + $this->sections = wp_parse_args( $this->sections, $box['sections'] ); |
|
| 270 | + |
|
| 271 | + $this->post_types = wp_parse_args( $this->post_types, $box['post_types'] ); |
|
| 272 | + |
|
| 273 | + // Checking to override the parent variables. |
|
| 274 | + $add_field = false; |
|
| 275 | + |
|
| 276 | + foreach ( $box['post_types'] as $type ) { |
|
| 277 | + if ( $this->post_type === $type ) { |
|
| 278 | + $add_field = true; |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // Replacing all the fields. |
|
| 283 | + if ( $add_field || ( ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) || ( ! is_admin() ) ) ) { |
|
| 284 | + $run_hooks = true; |
|
| 285 | + |
|
| 286 | + $box_id = 'redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id']; |
|
| 287 | + |
|
| 288 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 289 | + do_action( 'redux/' . $this->parent->args['opt_name'] . '/extensions/metabox/init', $this, $box ); |
|
| 290 | + |
|
| 291 | + if ( isset( $box['page_template'] ) && 'page' === $this->post_type ) { |
|
| 292 | + if ( ! is_array( $box['page_template'] ) ) { |
|
| 293 | + $box['page_template'] = array( $box['page_template'] ); |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + $this->wp_links[ $box_id ]['page_template'] = isset( $this->wp_links[ $box_id ]['page_template'] ) ? wp_parse_args( $this->wp_links[ $box_id ]['page_template'], $box['page_template'] ) : $box['page_template']; |
|
| 297 | + } |
|
| 298 | + |
|
| 299 | + if ( isset( $box['post_format'] ) && ( in_array( $this->post_type, $this->post_types, true ) || '' === $this->post_type || false === $this->post_type ) ) { |
|
| 300 | + if ( ! is_array( $box['post_format'] ) ) { |
|
| 301 | + $box['post_format'] = array( $box['post_format'] ); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + $this->wp_links[ $box_id ]['post_format'] = isset( $this->wp_links[ $box_id ]['post_format'] ) ? wp_parse_args( $this->wp_links[ $box_id ]['post_format'], $box['post_format'] ) : $box['post_format']; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + $this->meta[ $this->post_id ] = $this->get_meta( $this->post_id ); |
|
| 308 | + |
|
| 309 | + foreach ( $box['sections'] as $sk => $section ) { |
|
| 310 | + if ( ! empty( $section['fields'] ) ) { |
|
| 311 | + foreach ( $section['fields'] as $fk => $field ) { |
|
| 312 | + if ( ! isset( $field['class'] ) ) { |
|
| 313 | + $field['class'] = ''; |
|
| 314 | + |
|
| 315 | + $this->boxes[ $bk ]['sections'][ $sk ]['fields'][ $fk ] = $field; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + if ( $add_field || ( ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) || ( ! is_admin() ) ) ) { |
|
| 319 | + if ( empty( $field['id'] ) ) { |
|
| 320 | + continue; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + if ( isset( $field['default'] ) ) { |
|
| 324 | + $this->options_defaults[ $field['id'] ] = $field['default']; |
|
| 325 | + } else { |
|
| 326 | + $this->options_defaults[ $field['id'] ] = $this->field_default( $field ); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + foreach ( $box['post_types'] as $type ) { |
|
| 330 | + $this->post_type_fields[ $type ][ $field['id'] ] = 1; |
|
| 331 | + |
|
| 332 | + if ( 'repeater' === $field['type'] ) { |
|
| 333 | + foreach ( $field['fields'] as $val ) { |
|
| 334 | + $this->post_type_fields[ $type ][ $val['id'] ] = 1; |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + if ( ! empty( $field['output'] ) ) { |
|
| 340 | + $this->output[ $field['id'] ] = isset( $this->output[ $field['id'] ] ) ? array_merge( $field['output'], $this->output[ $field['id'] ] ) : $field['output']; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + // Detect what field types are being used. |
|
| 344 | + if ( ! isset( $this->parent->fields[ $field['type'] ][ $field['id'] ] ) ) { |
|
| 345 | + $this->parent->fields[ $field['type'] ][ $field['id'] ] = 1; |
|
| 346 | + } else { |
|
| 347 | + $this->parent->fields[ $field['type'] ] = array( $field['id'] => 1 ); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + if ( isset( $this->options_defaults[ $field['id'] ] ) ) { |
|
| 351 | + $this->to_replace[ $field['id'] ] = $field; |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + if ( ! isset( $this->parent->options[ $field['id'] ] ) ) { |
|
| 356 | + $this->parent->sections[ ( count( $this->parent->sections ) - 1 ) ]['fields'][] = $field; |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + if ( ! isset( $this->meta[ $this->post_id ][ $field['id'] ] ) ) { |
|
| 360 | + $this->meta[ $this->post_id ][ $field['id'] ] = $this->options_defaults[ $field['id'] ]; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + // Only override if it exists, and it's not the default. |
|
| 364 | + // phpcs:ignore Squiz.PHP.CommentedOutCode |
|
| 365 | + // if ( isset( $this->meta[ $this->post_id ][ $field['id'] ] ) && isset( $field['default'] ) && $this->meta[ $this->post_id ][ $field['id'] ] === $field['default'] ) { |
|
| 366 | + // unset($this->meta[$this->post_id][$field['id']]); |
|
| 367 | + // } . |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + if ( isset( $run_hooks ) && true === $run_hooks ) { |
|
| 376 | + $this->parent_options = array(); |
|
| 377 | + |
|
| 378 | + if ( ! empty( $this->to_replace ) ) { |
|
| 379 | + foreach ( $this->to_replace as $id => $field ) { |
|
| 380 | + |
|
| 381 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 382 | + add_filter( "redux/options/{$this->parent->args['opt_name']}/field/$id/register", array( $this, 'replace_field' ) ); |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + add_filter( "redux/options/{$this->parent->args['opt_name']}/options", array( $this, 'override_options' ) ); |
|
| 387 | + add_filter( "redux/field/{$this->parent->args['opt_name']}/_can_output_css", array( $this, 'override_can_output_css' ) ); |
|
| 388 | + add_filter( "redux/field/{$this->parent->args['opt_name']}/output_css", array( $this, 'output_css' ) ); |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Replace Field. |
|
| 394 | + * |
|
| 395 | + * @param array $field Field array. |
|
| 396 | + * |
|
| 397 | + * @return mixed |
|
| 398 | + */ |
|
| 399 | + public function replace_field( array $field ) { |
|
| 400 | + if ( isset( $this->to_replace[ $field['id'] ] ) ) { |
|
| 401 | + $field = $this->to_replace[ $field['id'] ]; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + return $field; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * Override CSS output. |
|
| 409 | + * |
|
| 410 | + * @param array $field Field array. |
|
| 411 | + * |
|
| 412 | + * @return array |
|
| 413 | + */ |
|
| 414 | + public function override_can_output_css( array $field ): array { |
|
| 415 | + if ( isset( $this->output[ $field['id'] ] ) ) { |
|
| 416 | + $field['force_output'] = true; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + return $field; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * Output CSS. |
|
| 424 | + * |
|
| 425 | + * @param array $field Field array. |
|
| 426 | + * |
|
| 427 | + * @return array |
|
| 428 | + */ |
|
| 429 | + public function output_css( array $field ): array { |
|
| 430 | + if ( isset( $this->output[ $field['id'] ] ) ) { |
|
| 431 | + $field['output'] = $this->output[ $field['id'] ]; |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + return $field; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + /** |
|
| 438 | + * Make sure the defaults are the defaults |
|
| 439 | + * |
|
| 440 | + * @param array $options Options array. |
|
| 441 | + * |
|
| 442 | + * @return array |
|
| 443 | + */ |
|
| 444 | + public function override_options( array $options ): array { |
|
| 445 | + $this->parent->default_values(); |
|
| 446 | + $this->parent_defaults = $this->parent->options_defaults; |
|
| 447 | + |
|
| 448 | + $meta = $this->get_meta( $this->post_id ); |
|
| 449 | + $data = wp_parse_args( $meta, $this->options_defaults ); |
|
| 450 | + |
|
| 451 | + foreach ( $data as $key => $value ) { |
|
| 452 | + if ( isset( $meta[ $key ] ) && '' !== $meta[ $key ] ) { |
|
| 453 | + $data[ $key ] = $meta[ $key ]; |
|
| 454 | + continue; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + if ( isset( $options[ $key ] ) ) { |
|
| 458 | + $data[ $key ] = $options[ $key ]; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + $this->parent->options_defaults = wp_parse_args( $this->options_defaults, $this->parent->options_defaults ); |
|
| 463 | + |
|
| 464 | + return wp_parse_args( $data, $options ); |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Loop start. |
|
| 469 | + * |
|
| 470 | + * @param mixed $the_post WP_Post object. |
|
| 471 | + * |
|
| 472 | + * @return array|void |
|
| 473 | + */ |
|
| 474 | + public function loop_start( $the_post = array() ) { |
|
| 475 | + if ( is_admin() ) { |
|
| 476 | + return $the_post; |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + if ( isset( $the_post ) && is_array( $the_post ) ) { |
|
| 480 | + global $post; |
|
| 481 | + $the_post = $post; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + if ( isset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ) ) { |
|
| 485 | + $GLOBALS[ $this->parent->args['global_variable'] ] = $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ]; |
|
| 486 | + unset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ); |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + // Override these values if they differ from the admin panel defaults. ;) . |
|
| 490 | + if ( in_array( $the_post->post_type, $this->post_types, true ) ) { |
|
| 491 | + $meta = $this->get_meta( $the_post->ID ); |
|
| 492 | + if ( empty( $meta ) ) { |
|
| 493 | + return; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + // Backup the args. |
|
| 497 | + $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] = $GLOBALS[ $this->parent->args['global_variable'] ]; |
|
| 498 | + $GLOBALS[ $this->parent->args['global_variable'] ] = wp_parse_args( $meta, $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ); |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Loop end. |
|
| 504 | + */ |
|
| 505 | + public function loop_end() { |
|
| 506 | + if ( isset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ) ) { |
|
| 507 | + $GLOBALS[ $this->parent->args['global_variable'] ] = $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ]; |
|
| 508 | + |
|
| 509 | + unset( $GLOBALS[ $this->parent->args['global_variable'] . '-loop' ] ); |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * Enqueue fields. |
|
| 515 | + */ |
|
| 516 | + public function enqueue() { |
|
| 517 | + global $pagenow; |
|
| 518 | + |
|
| 519 | + $types = array(); |
|
| 520 | + |
|
| 521 | + // Enqueue CSS. |
|
| 522 | + foreach ( $this->boxes as $key => $box ) { |
|
| 523 | + if ( empty( $box['sections'] ) ) { |
|
| 524 | + continue; |
|
| 525 | + } |
|
| 526 | + |
|
| 527 | + if ( isset( $box['post_types'] ) ) { |
|
| 528 | + $types = array_merge( $box['post_types'], $types ); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + if ( ! empty( $box['post_types'] ) ) { |
|
| 532 | + if ( ! is_array( $box['post_types'] ) ) { |
|
| 533 | + $box['post_types'] = array( $box['post_types'] ); |
|
| 534 | + $this->boxes[ $key ]['post_types'] = $box['post_types']; |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + if ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) { |
|
| 540 | + global $post; |
|
| 541 | + |
|
| 542 | + if ( in_array( $post->post_type, $types, true ) ) { |
|
| 543 | + $this->parent->transients = get_transient( $this->parent->args['opt_name'] . '-transients-metaboxes' ); |
|
| 544 | + $this->parent->transients_check = $this->parent->transients; |
|
| 545 | + |
|
| 546 | + if ( isset( $this->parent->transients['notices'] ) ) { |
|
| 547 | + $this->notices = $this->parent->transients['notices']; |
|
| 548 | + $this->parent->transients['last_save_mode'] = 'metaboxes'; |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + delete_transient( $this->parent->args['opt_name'] . '-transients-metaboxes' ); |
|
| 552 | + $this->parent->enqueue_class->init(); |
|
| 553 | + |
|
| 554 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 555 | + do_action( "redux/metaboxes/{$this->parent->args['opt_name']}/enqueue" ); |
|
| 556 | + |
|
| 557 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 558 | + do_action( "redux/{$this->parent->args['opt_name']}/extensions/metaboxes/enqueue" ); |
|
| 559 | + |
|
| 560 | + /** |
|
| 561 | + * Redux metaboxes CSS |
|
| 562 | + * filter 'redux/page/{opt_name}/enqueue/redux-extension-metaboxes-css' |
|
| 563 | + */ |
|
| 564 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 565 | + wp_enqueue_style( |
|
| 566 | + 'redux-extension-metaboxes', |
|
| 567 | + apply_filters( "redux/metaboxes/{$this->parent->args['opt_name']}/enqueue/redux-extension-metaboxes-css", $this->extension_url . 'redux-extension-metaboxes.css' ), // phpcs:ignore: WordPress.NamingConventions.ValidHookName |
|
| 568 | + array(), |
|
| 569 | + self::$version |
|
| 570 | + ); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * Redux metaboxes JS |
|
| 575 | + * filter 'redux/page/{opt_name}/enqueue/redux-extension-metaboxes-js |
|
| 576 | + */ |
|
| 577 | + wp_enqueue_script( |
|
| 578 | + 'redux-extension-metaboxes', |
|
| 579 | + apply_filters( "redux/metaboxes/{$this->parent->args['opt_name']}/enqueue/redux-extension-metaboxes-js", $this->extension_url . 'redux-extension-metaboxes' . Redux_Functions::isMin() . '.js' ), // phpcs:ignore: WordPress.NamingConventions.ValidHookName |
|
| 580 | + array( 'jquery', 'redux-js' ), |
|
| 581 | + self::$version, |
|
| 582 | + true |
|
| 583 | + ); |
|
| 584 | + |
|
| 585 | + // Values used by the javascript. |
|
| 586 | + wp_localize_script( |
|
| 587 | + 'redux-extension-metaboxes', |
|
| 588 | + 'reduxMetaboxes', |
|
| 589 | + $this->wp_links |
|
| 590 | + ); |
|
| 591 | + |
|
| 592 | + wp_localize_script( |
|
| 593 | + 'redux-extension-metaboxes', |
|
| 594 | + 'reduxMetaboxesPageTemplate', |
|
| 595 | + array( |
|
| 596 | + '_wp_page_template' => get_post_meta( get_the_ID(), '_wp_page_template', true ), |
|
| 597 | + ) |
|
| 598 | + ); |
|
| 599 | + } |
|
| 600 | + } |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + /* Post URLs to IDs function, supports custom post types - borrowed and modified from url_to_postid() in wp-includes/rewrite.php */ |
|
| 604 | + |
|
| 605 | + // Taken from http://betterwp.net/wordpress-tips/url_to_postid-for-custom-post-types/ |
|
| 606 | + // Customized to work with non-rewrite URLs |
|
| 607 | + // Modified by Dovy Paukstys (@dovy) of Redux Framework. |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * URL to PostID. |
|
| 611 | + * |
|
| 612 | + * @param string $url URL. |
|
| 613 | + * |
|
| 614 | + * @return int|mixed|void |
|
| 615 | + */ |
|
| 616 | + private function url_to_postid( string $url ) { |
|
| 617 | + global $wp_rewrite, $pagenow; |
|
| 618 | + |
|
| 619 | + if ( ! empty( $this->post_id ) ) { |
|
| 620 | + return $this->post_id; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + if ( isset( $_GET['post'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 624 | + $post = (int) sanitize_text_field( wp_unslash( $_GET['post'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 625 | + |
|
| 626 | + if ( ! empty( $post ) ) { |
|
| 627 | + return $post; |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + if ( 'post-new.php' === $pagenow || 'wp-login.php' === $pagenow ) { |
|
| 632 | + return; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + if ( is_admin() && 'post.php' === $pagenow && isset( $_POST['post_ID'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 636 | + $post_id = sanitize_text_field( wp_unslash( $_POST['post_ID'] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 637 | + |
|
| 638 | + if ( ! empty( $post_id ) && is_numeric( $post_id ) ) { |
|
| 639 | + return $post_id; |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + $post_id = url_to_postid( $url ); |
|
| 644 | + |
|
| 645 | + if ( isset( $post_id ) && '' !== (string) $post_id && 0 !== $post_id ) { |
|
| 646 | + return $post_id; |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + // First, check to see if there is a 'p=N' or 'page_id=N' to match against. |
|
| 650 | + if ( preg_match( '#[?&](p|page_id|attachment_id)=(\d+)#', $url, $values ) ) { |
|
| 651 | + $id = absint( $values[2] ); |
|
| 652 | + if ( $id ) { |
|
| 653 | + return $id; |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + // Check to see if we are using rewrite rules. |
|
| 658 | + if ( isset( $wp_rewrite ) ) { |
|
| 659 | + $rewrite = $wp_rewrite->wp_rewrite_rules(); |
|
| 660 | + } |
|
| 661 | + |
|
| 662 | + // Not using rewrite rules, and 'p=N' and 'page_id=N' methods failed, so we're out of options. |
|
| 663 | + if ( empty( $rewrite ) ) { |
|
| 664 | + if ( ! empty( $_GET ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 665 | + |
|
| 666 | + /************************************************************************ |
|
| 667 | 667 | * ADDED: Trys checks URL for ?posttype=postname |
| 668 | 668 | ************************************************************************ */ |
| 669 | 669 | |
| 670 | - // Assign $url to $temp_url just in case. :) . |
|
| 671 | - $temp_url = $url; |
|
| 672 | - |
|
| 673 | - // Get rid of the #anchor. |
|
| 674 | - $url_split = explode( '#', $temp_url ); |
|
| 675 | - $temp_url = $url_split[0]; |
|
| 676 | - |
|
| 677 | - // Get rid of URL ?query=string. |
|
| 678 | - $url_query = explode( '&', $temp_url ); |
|
| 679 | - $temp_url = $url_query[0]; |
|
| 680 | - |
|
| 681 | - // Get rid of ? mark. |
|
| 682 | - $url_query = explode( '?', $temp_url ); |
|
| 683 | - |
|
| 684 | - if ( ! empty( $url_query[1] ) && strpos( $url_query[1], '=' ) ) { |
|
| 685 | - $url_query = explode( '=', $url_query[1] ); |
|
| 686 | - |
|
| 687 | - if ( isset( $url_query[0] ) && isset( $url_query[1] ) ) { |
|
| 688 | - $args = array( |
|
| 689 | - 'name' => $url_query[1], |
|
| 690 | - 'post_type' => $url_query[0], |
|
| 691 | - 'showposts' => 1, |
|
| 692 | - ); |
|
| 693 | - |
|
| 694 | - if ( get_posts( $args ) === $post ) { |
|
| 695 | - return $post[0]->ID; |
|
| 696 | - } |
|
| 697 | - } |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - foreach ( $GLOBALS['wp_post_types'] as $key => $value ) { |
|
| 701 | - if ( ! empty( $_GET[ $key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 702 | - $args = array( |
|
| 703 | - 'name' => sanitize_text_field( wp_unslash( $_GET[ $key ] ) ), // phpcs:ignore WordPress.Security.NonceVerification |
|
| 704 | - 'post_type' => $key, |
|
| 705 | - 'showposts' => 1, |
|
| 706 | - ); |
|
| 707 | - |
|
| 708 | - if ( get_posts( $args ) === $post ) { |
|
| 709 | - return $post[0]->ID; |
|
| 710 | - } |
|
| 711 | - } |
|
| 712 | - } |
|
| 713 | - } |
|
| 714 | - } |
|
| 715 | - |
|
| 716 | - // Get rid of the #anchor. |
|
| 717 | - $url_split = explode( '#', $url ); |
|
| 718 | - $url = $url_split[0]; |
|
| 719 | - |
|
| 720 | - // Get rid of URL ?query=string. |
|
| 721 | - $url_query = explode( '?', $url ); |
|
| 722 | - $url = $url_query[0]; |
|
| 723 | - |
|
| 724 | - // Set the correct URL scheme. |
|
| 725 | - $scheme = wp_parse_url( home_url(), PHP_URL_SCHEME ); |
|
| 726 | - $url = set_url_scheme( $url, $scheme ); |
|
| 727 | - |
|
| 728 | - // Add 'www.' if it is absent and should be there. |
|
| 729 | - if ( false !== strpos( home_url(), '://www.' ) && false === strpos( $url, '://www.' ) ) { |
|
| 730 | - $url = str_replace( '://', '://www.', $url ); |
|
| 731 | - } |
|
| 732 | - |
|
| 733 | - // Strip 'www.' if it is present and shouldn't be. |
|
| 734 | - if ( false === strpos( home_url(), '://www.' ) ) { |
|
| 735 | - $url = str_replace( '://www.', '://', $url ); |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - // Strip 'index.php/' if we're not using path info permalinks. |
|
| 739 | - if ( isset( $wp_rewrite ) && ! $wp_rewrite->using_index_permalinks() ) { |
|
| 740 | - $url = str_replace( 'index.php/', '', $url ); |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - if ( false !== strpos( $url, home_url() ) ) { |
|
| 744 | - // Chop off http://domain.com. |
|
| 745 | - $url = str_replace( home_url(), '', $url ); |
|
| 746 | - } else { |
|
| 747 | - // Chop off /path/to/blog. |
|
| 748 | - $home_path = wp_parse_url( home_url() ); |
|
| 749 | - $home_path = $home_path['path'] ?? ''; |
|
| 750 | - $url = str_replace( $home_path, '', $url ); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - // Trim leading and lagging slashes. |
|
| 754 | - $url = trim( $url, '/' ); |
|
| 755 | - |
|
| 756 | - $request = $url; |
|
| 757 | - |
|
| 758 | - if ( empty( $request ) && ( empty( $_GET ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 759 | - return get_option( 'page_on_front' ); |
|
| 760 | - } |
|
| 761 | - |
|
| 762 | - // Look for matches. |
|
| 763 | - $request_match = $request; |
|
| 764 | - |
|
| 765 | - foreach ( $rewrite as $match => $query ) { |
|
| 766 | - // If the requesting file is the anchor of the match, prepend it |
|
| 767 | - // to the path info. |
|
| 768 | - if ( ! empty( $url ) && ( $url !== $request ) && ( strpos( $match, $url ) === 0 ) ) { |
|
| 769 | - $request_match = $url . '/' . $request; |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - if ( preg_match( "!^$match!", $request_match, $matches ) ) { |
|
| 773 | - global $wp; |
|
| 774 | - |
|
| 775 | - // Got a match. |
|
| 776 | - // Trim the query of everything up to the '?'. |
|
| 777 | - $query = preg_replace( '!^.+\?!', '', $query ); |
|
| 778 | - |
|
| 779 | - // Substitute the substring matches into the query. |
|
| 780 | - $query = addslashes( WP_MatchesMapRegex::apply( $query, $matches ) ); |
|
| 781 | - |
|
| 782 | - // Filter out non-public query vars. |
|
| 783 | - parse_str( $query, $query_vars ); |
|
| 784 | - |
|
| 785 | - $query = array(); |
|
| 786 | - |
|
| 787 | - foreach ( $query_vars as $key => $value ) { |
|
| 788 | - if ( in_array( $key, $wp->public_query_vars, true ) ) { |
|
| 789 | - $query[ $key ] = $value; |
|
| 790 | - } |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - /************************************************************************ |
|
| 670 | + // Assign $url to $temp_url just in case. :) . |
|
| 671 | + $temp_url = $url; |
|
| 672 | + |
|
| 673 | + // Get rid of the #anchor. |
|
| 674 | + $url_split = explode( '#', $temp_url ); |
|
| 675 | + $temp_url = $url_split[0]; |
|
| 676 | + |
|
| 677 | + // Get rid of URL ?query=string. |
|
| 678 | + $url_query = explode( '&', $temp_url ); |
|
| 679 | + $temp_url = $url_query[0]; |
|
| 680 | + |
|
| 681 | + // Get rid of ? mark. |
|
| 682 | + $url_query = explode( '?', $temp_url ); |
|
| 683 | + |
|
| 684 | + if ( ! empty( $url_query[1] ) && strpos( $url_query[1], '=' ) ) { |
|
| 685 | + $url_query = explode( '=', $url_query[1] ); |
|
| 686 | + |
|
| 687 | + if ( isset( $url_query[0] ) && isset( $url_query[1] ) ) { |
|
| 688 | + $args = array( |
|
| 689 | + 'name' => $url_query[1], |
|
| 690 | + 'post_type' => $url_query[0], |
|
| 691 | + 'showposts' => 1, |
|
| 692 | + ); |
|
| 693 | + |
|
| 694 | + if ( get_posts( $args ) === $post ) { |
|
| 695 | + return $post[0]->ID; |
|
| 696 | + } |
|
| 697 | + } |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + foreach ( $GLOBALS['wp_post_types'] as $key => $value ) { |
|
| 701 | + if ( ! empty( $_GET[ $key ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 702 | + $args = array( |
|
| 703 | + 'name' => sanitize_text_field( wp_unslash( $_GET[ $key ] ) ), // phpcs:ignore WordPress.Security.NonceVerification |
|
| 704 | + 'post_type' => $key, |
|
| 705 | + 'showposts' => 1, |
|
| 706 | + ); |
|
| 707 | + |
|
| 708 | + if ( get_posts( $args ) === $post ) { |
|
| 709 | + return $post[0]->ID; |
|
| 710 | + } |
|
| 711 | + } |
|
| 712 | + } |
|
| 713 | + } |
|
| 714 | + } |
|
| 715 | + |
|
| 716 | + // Get rid of the #anchor. |
|
| 717 | + $url_split = explode( '#', $url ); |
|
| 718 | + $url = $url_split[0]; |
|
| 719 | + |
|
| 720 | + // Get rid of URL ?query=string. |
|
| 721 | + $url_query = explode( '?', $url ); |
|
| 722 | + $url = $url_query[0]; |
|
| 723 | + |
|
| 724 | + // Set the correct URL scheme. |
|
| 725 | + $scheme = wp_parse_url( home_url(), PHP_URL_SCHEME ); |
|
| 726 | + $url = set_url_scheme( $url, $scheme ); |
|
| 727 | + |
|
| 728 | + // Add 'www.' if it is absent and should be there. |
|
| 729 | + if ( false !== strpos( home_url(), '://www.' ) && false === strpos( $url, '://www.' ) ) { |
|
| 730 | + $url = str_replace( '://', '://www.', $url ); |
|
| 731 | + } |
|
| 732 | + |
|
| 733 | + // Strip 'www.' if it is present and shouldn't be. |
|
| 734 | + if ( false === strpos( home_url(), '://www.' ) ) { |
|
| 735 | + $url = str_replace( '://www.', '://', $url ); |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + // Strip 'index.php/' if we're not using path info permalinks. |
|
| 739 | + if ( isset( $wp_rewrite ) && ! $wp_rewrite->using_index_permalinks() ) { |
|
| 740 | + $url = str_replace( 'index.php/', '', $url ); |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + if ( false !== strpos( $url, home_url() ) ) { |
|
| 744 | + // Chop off http://domain.com. |
|
| 745 | + $url = str_replace( home_url(), '', $url ); |
|
| 746 | + } else { |
|
| 747 | + // Chop off /path/to/blog. |
|
| 748 | + $home_path = wp_parse_url( home_url() ); |
|
| 749 | + $home_path = $home_path['path'] ?? ''; |
|
| 750 | + $url = str_replace( $home_path, '', $url ); |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + // Trim leading and lagging slashes. |
|
| 754 | + $url = trim( $url, '/' ); |
|
| 755 | + |
|
| 756 | + $request = $url; |
|
| 757 | + |
|
| 758 | + if ( empty( $request ) && ( empty( $_GET ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 759 | + return get_option( 'page_on_front' ); |
|
| 760 | + } |
|
| 761 | + |
|
| 762 | + // Look for matches. |
|
| 763 | + $request_match = $request; |
|
| 764 | + |
|
| 765 | + foreach ( $rewrite as $match => $query ) { |
|
| 766 | + // If the requesting file is the anchor of the match, prepend it |
|
| 767 | + // to the path info. |
|
| 768 | + if ( ! empty( $url ) && ( $url !== $request ) && ( strpos( $match, $url ) === 0 ) ) { |
|
| 769 | + $request_match = $url . '/' . $request; |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + if ( preg_match( "!^$match!", $request_match, $matches ) ) { |
|
| 773 | + global $wp; |
|
| 774 | + |
|
| 775 | + // Got a match. |
|
| 776 | + // Trim the query of everything up to the '?'. |
|
| 777 | + $query = preg_replace( '!^.+\?!', '', $query ); |
|
| 778 | + |
|
| 779 | + // Substitute the substring matches into the query. |
|
| 780 | + $query = addslashes( WP_MatchesMapRegex::apply( $query, $matches ) ); |
|
| 781 | + |
|
| 782 | + // Filter out non-public query vars. |
|
| 783 | + parse_str( $query, $query_vars ); |
|
| 784 | + |
|
| 785 | + $query = array(); |
|
| 786 | + |
|
| 787 | + foreach ( $query_vars as $key => $value ) { |
|
| 788 | + if ( in_array( $key, $wp->public_query_vars, true ) ) { |
|
| 789 | + $query[ $key ] = $value; |
|
| 790 | + } |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + /************************************************************************ |
|
| 794 | 794 | * ADDED: $GLOBALS['wp_post_types'] doesn't seem to have custom posttypes |
| 795 | 795 | * Trying below to find posttypes in $rewrite rules |
| 796 | 796 | ************************************************************************ */ |
| 797 | 797 | |
| 798 | - // PostType Array. |
|
| 799 | - $post_types = array(); |
|
| 800 | - |
|
| 801 | - foreach ( $rewrite as $value ) { |
|
| 802 | - if ( preg_match( '/post_type=([^&]+)/i', $value, $matched ) ) { |
|
| 803 | - if ( isset( $matched[1] ) && ! in_array( $matched[1], $post_types, true ) ) { |
|
| 804 | - $post_types[] = $matched[1]; |
|
| 805 | - } |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - foreach ( $query_vars as $key => $value ) { |
|
| 810 | - if ( in_array( $key, $post_types, true ) ) { |
|
| 811 | - $query['post_type'] = $key; |
|
| 812 | - $query['postname'] = $value; |
|
| 813 | - } |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - /************************************************************************ |
|
| 798 | + // PostType Array. |
|
| 799 | + $post_types = array(); |
|
| 800 | + |
|
| 801 | + foreach ( $rewrite as $value ) { |
|
| 802 | + if ( preg_match( '/post_type=([^&]+)/i', $value, $matched ) ) { |
|
| 803 | + if ( isset( $matched[1] ) && ! in_array( $matched[1], $post_types, true ) ) { |
|
| 804 | + $post_types[] = $matched[1]; |
|
| 805 | + } |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + foreach ( $query_vars as $key => $value ) { |
|
| 810 | + if ( in_array( $key, $post_types, true ) ) { |
|
| 811 | + $query['post_type'] = $key; |
|
| 812 | + $query['postname'] = $value; |
|
| 813 | + } |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + /************************************************************************ |
|
| 817 | 817 | * END ADD |
| 818 | 818 | ************************************************************************ */ |
| 819 | 819 | |
| 820 | - // Taken from class-wp.php. |
|
| 821 | - foreach ( $GLOBALS['wp_post_types'] as $post_type => $t ) { |
|
| 822 | - if ( isset( $t->query_var ) ) { |
|
| 823 | - $post_type_query_vars[ $t->query_var ] = $post_type; |
|
| 824 | - } |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - foreach ( $wp->public_query_vars as $wpvar ) { |
|
| 828 | - if ( isset( $wp->extra_query_vars[ $wpvar ] ) ) { |
|
| 829 | - $query[ $wpvar ] = $wp->extra_query_vars[ $wpvar ]; |
|
| 830 | - } elseif ( isset( $_POST[ $wpvar ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 831 | - $query[ $wpvar ] = sanitize_text_field( wp_unslash( $_POST[ $wpvar ] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 832 | - } elseif ( isset( $_GET[ $wpvar ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 833 | - $query[ $wpvar ] = sanitize_text_field( wp_unslash( $_GET[ $wpvar ] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 834 | - } elseif ( isset( $query_vars[ $wpvar ] ) ) { |
|
| 835 | - $query[ $wpvar ] = $query_vars[ $wpvar ]; |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - if ( ! empty( $query[ $wpvar ] ) ) { |
|
| 839 | - if ( ! is_array( $query[ $wpvar ] ) ) { |
|
| 840 | - $query[ $wpvar ] = (string) $query[ $wpvar ]; |
|
| 841 | - } else { |
|
| 842 | - foreach ( $query[ $wpvar ] as $vkey => $v ) { |
|
| 843 | - if ( ! is_object( $v ) ) { |
|
| 844 | - $query[ $wpvar ][ $vkey ] = (string) $v; |
|
| 845 | - } |
|
| 846 | - } |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - if ( isset( $post_type_query_vars[ $wpvar ] ) ) { |
|
| 850 | - $query['post_type'] = $post_type_query_vars[ $wpvar ]; |
|
| 851 | - $query['name'] = $query[ $wpvar ]; |
|
| 852 | - } |
|
| 853 | - } |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - // Do the query. |
|
| 857 | - if ( ! empty( $query['pagename'] ) ) { |
|
| 858 | - $args = array( |
|
| 859 | - 'name' => $query['pagename'], |
|
| 860 | - 'post_type' => 'page', |
|
| 861 | - 'showposts' => 1, |
|
| 862 | - ); |
|
| 863 | - |
|
| 864 | - if ( isset( $post ) && get_posts( $args ) === $post ) { |
|
| 865 | - return $post[0]->ID; |
|
| 866 | - } |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - $query = new WP_Query( $query ); |
|
| 870 | - |
|
| 871 | - if ( ! empty( $query->posts ) && $query->is_singular ) { |
|
| 872 | - return $query->post->ID; |
|
| 873 | - } else { |
|
| 874 | - |
|
| 875 | - // WooCommerce override. |
|
| 876 | - if ( isset( $query->query['post_type'] ) && 'product' === $query->query['post_type'] && class_exists( 'WooCommerce' ) ) { |
|
| 877 | - return get_option( 'woocommerce_shop_page_id' ); |
|
| 878 | - } |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - if ( ( empty( $query['page'] ) ) && ( empty( $query['pagename'] ) ) ) { |
|
| 882 | - return 0; |
|
| 883 | - } |
|
| 884 | - } |
|
| 885 | - } |
|
| 886 | - |
|
| 887 | - return 0; |
|
| 888 | - } |
|
| 889 | - |
|
| 890 | - /** |
|
| 891 | - * Get default values. |
|
| 892 | - */ |
|
| 893 | - public function default_values() { |
|
| 894 | - if ( ! empty( $this->boxes ) && empty( $this->options_defaults ) ) { |
|
| 895 | - foreach ( $this->boxes as $key => $box ) { |
|
| 896 | - if ( empty( $box['sections'] ) ) { |
|
| 897 | - continue; |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - // fill the cache. |
|
| 901 | - foreach ( $box['sections'] as $sk => $section ) { |
|
| 902 | - if ( ! isset( $section['id'] ) ) { |
|
| 903 | - if ( ! is_numeric( $sk ) || ! isset( $section['title'] ) ) { |
|
| 904 | - $section['id'] = $sk; |
|
| 905 | - } else { |
|
| 906 | - $section['id'] = sanitize_text_field( $section['title'] ); |
|
| 907 | - } |
|
| 908 | - $this->boxes[ $key ]['sections'][ $sk ] = $section; |
|
| 909 | - } |
|
| 910 | - if ( isset( $section['fields'] ) ) { |
|
| 911 | - foreach ( $section['fields'] as $k => $field ) { |
|
| 912 | - |
|
| 913 | - if ( empty( $field['id'] ) && empty( $field['type'] ) ) { |
|
| 914 | - continue; |
|
| 915 | - } |
|
| 916 | - |
|
| 917 | - if ( 'ace_editor' === $field['type'] && isset( $field['options'] ) ) { |
|
| 918 | - $this->boxes[ $key ]['sections'][ $sk ]['fields'][ $k ]['args'] = $field['options']; |
|
| 919 | - unset( $this->boxes[ $key ]['sections'][ $sk ]['fields'][ $k ]['options'] ); |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - if ( 'section' === $field['type'] && isset( $field['indent'] ) && ( true === $field['indent'] || 'true' === $field['indent'] ) ) { |
|
| 923 | - $field['class'] = $field['class'] ?? ''; |
|
| 924 | - $field['class'] .= 'redux-section-indent-start'; |
|
| 925 | - |
|
| 926 | - $this->boxes[ $key ]['sections'][ $sk ]['fields'][ $k ] = $field; |
|
| 927 | - } |
|
| 928 | - |
|
| 929 | - if ( ! isset( $this->parent->options_defaults_class ) ) { |
|
| 930 | - $this->parent->options_defaults_class = new Redux_Options_Defaults(); |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - $this->parent->options_defaults_class->field_default_values( $this->parent->args['opt_name'], $field ); |
|
| 934 | - |
|
| 935 | - if ( 'repeater' === $field['type'] ) { |
|
| 936 | - foreach ( $field['fields'] as $f ) { |
|
| 937 | - $this->parent->options_defaults_class->field_default_values( $this->parent->args['opt_name'], $f, null, true ); |
|
| 938 | - } |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - $this->parent->options_defaults = $this->parent->options_defaults_class->options_defaults; |
|
| 942 | - } |
|
| 943 | - } |
|
| 944 | - } |
|
| 945 | - } |
|
| 946 | - } |
|
| 947 | - |
|
| 948 | - if ( empty( $this->meta[ $this->post_id ] ) ) { |
|
| 949 | - $this->meta[ $this->post_id ] = $this->get_meta( $this->post_id ); |
|
| 950 | - } |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - /** |
|
| 954 | - * Add Meta Boxes |
|
| 955 | - */ |
|
| 956 | - public function add() { |
|
| 957 | - if ( empty( $this->boxes ) || ! is_array( $this->boxes ) ) { |
|
| 958 | - return; |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - foreach ( $this->boxes as $key => $box ) { |
|
| 962 | - if ( empty( $box['sections'] ) ) { |
|
| 963 | - continue; |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - // Save users from themselves. |
|
| 967 | - if ( isset( $box['position'] ) && ! in_array( strtolower( $box['position'] ), array( 'normal', 'advanced', 'side' ), true ) ) { |
|
| 968 | - unset( $box['position'] ); |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - if ( isset( $box['priority'] ) && ! in_array( strtolower( $box['priority'] ), array( 'high', 'core', 'default', 'low' ), true ) ) { |
|
| 972 | - unset( $box['priority'] ); |
|
| 973 | - } |
|
| 974 | - |
|
| 975 | - $defaults = array( |
|
| 976 | - 'id' => $key . '-' . $this->parent->args['opt_name'], |
|
| 977 | - 'post_types' => array( 'page', 'post' ), |
|
| 978 | - 'position' => 'normal', |
|
| 979 | - 'priority' => 'high', |
|
| 980 | - ); |
|
| 981 | - |
|
| 982 | - $box = wp_parse_args( $box, $defaults ); |
|
| 983 | - if ( ! empty( $box['post_types'] ) ) { |
|
| 984 | - foreach ( $box['post_types'] as $posttype ) { |
|
| 985 | - if ( isset( $box['title'] ) ) { |
|
| 986 | - $title = $box['title']; |
|
| 987 | - } elseif ( isset( $box['sections'] ) && 1 === count( $box['sections'] ) && isset( $box['sections'][0]['fields'] ) && 1 === count( $box['sections'][0]['fields'] ) && isset( $box['sections'][0]['fields'][0]['title'] ) ) { |
|
| 988 | - |
|
| 989 | - // If only one field in this box. |
|
| 990 | - $title = $box['sections'][0]['fields'][0]['title']; |
|
| 991 | - } else { |
|
| 992 | - $title = ucfirst( $posttype ) . ' ' . __( 'Options', 'redux-framework' ); |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - $args = array( |
|
| 996 | - 'position' => $box['position'], |
|
| 997 | - 'sections' => $box['sections'], |
|
| 998 | - 'key' => $key, |
|
| 999 | - ); |
|
| 1000 | - |
|
| 1001 | - // Override the parent args on a metabox level. |
|
| 1002 | - if ( empty( $this->orig_args ) ) { |
|
| 1003 | - $this->orig_args = $this->parent->args; |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - if ( isset( $box['args'] ) ) { |
|
| 1007 | - $this->parent->args = wp_parse_args( $box['args'], $this->orig_args ); |
|
| 1008 | - } elseif ( $this->parent->args !== $this->orig_args ) { |
|
| 1009 | - $this->parent->args = $this->orig_args; |
|
| 1010 | - } |
|
| 1011 | - |
|
| 1012 | - add_filter( 'postbox_classes_' . $posttype . '_redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id'], array( $this, 'add_box_classes' ) ); |
|
| 1013 | - |
|
| 1014 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1015 | - do_action( 'redux/' . $this->parent->args['opt_name'] . '/extensions/metabox/add', $this, $box, $posttype ); |
|
| 1016 | - |
|
| 1017 | - if ( isset( $box['post_format'] ) ) { |
|
| 1018 | - add_filter( 'postbox_classes_' . $posttype . '_redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id'], array( $this, 'add_box_hide_class' ) ); |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - // phpcs:ignore Generic.Strings.UnnecessaryStringConcat |
|
| 1022 | - call_user_func( 'add' . '_meta' . '_box', 'redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id'], $title, array( $this, 'generate_boxes' ), $posttype, $box['position'], $box['priority'], $args ); |
|
| 1023 | - } |
|
| 1024 | - } |
|
| 1025 | - } |
|
| 1026 | - } |
|
| 1027 | - |
|
| 1028 | - /** |
|
| 1029 | - * Add hidden class to metabox DIV. |
|
| 1030 | - * |
|
| 1031 | - * @param array $classes Class array. |
|
| 1032 | - * |
|
| 1033 | - * @return array |
|
| 1034 | - */ |
|
| 1035 | - public function add_box_hide_class( array $classes ): array { |
|
| 1036 | - $classes[] = 'hide'; |
|
| 1037 | - |
|
| 1038 | - return $classes; |
|
| 1039 | - } |
|
| 1040 | - |
|
| 1041 | - /** |
|
| 1042 | - * Field Defaults. |
|
| 1043 | - * |
|
| 1044 | - * @param mixed $field_id ID. |
|
| 1045 | - * |
|
| 1046 | - * @return mixed|string |
|
| 1047 | - */ |
|
| 1048 | - private function field_default( $field_id ) { |
|
| 1049 | - if ( ! isset( $this->parent->options_defaults ) ) { |
|
| 1050 | - $this->parent->options_defaults = $this->parent->default_values(); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - if ( ! isset( $this->parent->options ) || empty( $this->parent->options ) ) { |
|
| 1054 | - if ( ! isset( $this->parent->options_class ) ) { |
|
| 1055 | - $this->parent->options_class = new Redux_Options_Constructor( $this->parent ); |
|
| 1056 | - } |
|
| 1057 | - |
|
| 1058 | - $this->parent->options_class->get(); |
|
| 1059 | - } |
|
| 1060 | - |
|
| 1061 | - $this->options = $this->parent->options; |
|
| 1062 | - |
|
| 1063 | - if ( isset( $this->parent->options[ $field_id['id'] ] ) && isset( $this->parent->options_defaults[ $field_id['id'] ] ) && $this->parent->options[ $field_id['id'] ] !== $this->parent->options_defaults[ $field_id['id'] ] ) { |
|
| 1064 | - return $this->parent->options[ $field_id['id'] ]; |
|
| 1065 | - } else { |
|
| 1066 | - if ( empty( $this->options_defaults ) ) { |
|
| 1067 | - $this->default_values(); // fill cache. |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - $data = ''; |
|
| 1071 | - if ( ! empty( $this->options_defaults ) ) { |
|
| 1072 | - $data = $this->options_defaults[ $field_id['id'] ] ?? ''; |
|
| 1073 | - } |
|
| 1074 | - |
|
| 1075 | - if ( empty( $data ) && isset( $this->parent->options_defaults[ $field_id['id'] ] ) ) { |
|
| 1076 | - $data = $this->parent->options_defaults[ $field_id['id'] ] ?? ''; |
|
| 1077 | - } |
|
| 1078 | - |
|
| 1079 | - return $data; |
|
| 1080 | - } |
|
| 1081 | - } |
|
| 1082 | - |
|
| 1083 | - /** |
|
| 1084 | - * Function to get and cache the post meta. |
|
| 1085 | - * |
|
| 1086 | - * @param mixed $id ID. |
|
| 1087 | - * |
|
| 1088 | - * @return array |
|
| 1089 | - */ |
|
| 1090 | - private function get_meta( $id ): array { |
|
| 1091 | - if ( ! isset( $this->meta[ $id ] ) ) { |
|
| 1092 | - $this->meta[ $id ] = array(); |
|
| 1093 | - $o_data = get_post_meta( $id ); |
|
| 1094 | - |
|
| 1095 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1096 | - $o_data = apply_filters( "redux/metaboxes/{$this->parent->args['opt_name']}/get_meta", $o_data ); |
|
| 1097 | - |
|
| 1098 | - if ( ! empty( $o_data ) ) { |
|
| 1099 | - foreach ( $o_data as $key => $value ) { |
|
| 1100 | - if ( 1 === count( $value ) ) { |
|
| 1101 | - $this->meta[ $id ][ $key ] = maybe_unserialize( $value[0] ); |
|
| 1102 | - } else { |
|
| 1103 | - $new_value = array_map( 'maybe_unserialize', $value ); |
|
| 1104 | - |
|
| 1105 | - $this->meta[ $id ][ $key ] = $new_value[0]; |
|
| 1106 | - } |
|
| 1107 | - } |
|
| 1108 | - } |
|
| 1109 | - |
|
| 1110 | - if ( isset( $this->meta[ $id ][ $this->parent->args['opt_name'] ] ) ) { |
|
| 1111 | - $data = maybe_unserialize( $this->meta[ $id ][ $this->parent->args['opt_name'] ] ); |
|
| 1112 | - |
|
| 1113 | - foreach ( $data as $key => $value ) { |
|
| 1114 | - $this->meta[ $id ][ $key ] = $value; |
|
| 1115 | - update_post_meta( $id, $key, $value ); |
|
| 1116 | - } |
|
| 1117 | - |
|
| 1118 | - unset( $this->meta[ $id ][ $this->parent->args['opt_name'] ] ); |
|
| 1119 | - |
|
| 1120 | - delete_post_meta( $id, $this->parent->args['opt_name'] ); |
|
| 1121 | - } |
|
| 1122 | - } |
|
| 1123 | - |
|
| 1124 | - return $this->meta[ $id ]; |
|
| 1125 | - } |
|
| 1126 | - |
|
| 1127 | - /** |
|
| 1128 | - * Get values. |
|
| 1129 | - * |
|
| 1130 | - * @param mixed $the_post Post object/id. |
|
| 1131 | - * @param string $meta_key Meta key. |
|
| 1132 | - * @param mixed $def_val Def value. |
|
| 1133 | - * |
|
| 1134 | - * @return array|mixed|string |
|
| 1135 | - */ |
|
| 1136 | - public function get_values( $the_post, string $meta_key = '', $def_val = '' ) { |
|
| 1137 | - |
|
| 1138 | - // Override these values if they differ from the admin panel defaults. ;) . |
|
| 1139 | - if ( isset( $the_post->post_type ) && in_array( $the_post->post_type, $this->post_types, true ) ) { |
|
| 1140 | - if ( isset( $this->post_type_values[ $the_post->post_type ] ) ) { |
|
| 1141 | - $meta = $this->post_type_fields[ $the_post->post_type ]; |
|
| 1142 | - } else { |
|
| 1143 | - $defaults = array(); |
|
| 1144 | - if ( ! empty( $this->post_type_fields[ $the_post->post_type ] ) ) { |
|
| 1145 | - foreach ( $this->post_type_fields[ $the_post->post_type ] as $key => $null ) { |
|
| 1146 | - if ( isset( $this->options_defaults[ $key ] ) ) { |
|
| 1147 | - $defaults[ $key ] = $this->options_defaults[ $key ]; |
|
| 1148 | - } |
|
| 1149 | - } |
|
| 1150 | - } |
|
| 1151 | - |
|
| 1152 | - $meta = wp_parse_args( $this->get_meta( $the_post->ID ), $defaults ); |
|
| 1153 | - |
|
| 1154 | - $this->post_type_fields[ $the_post->post_type ] = $meta; |
|
| 1155 | - } |
|
| 1156 | - |
|
| 1157 | - if ( ! empty( $meta_key ) ) { |
|
| 1158 | - if ( ! isset( $meta[ $meta_key ] ) ) { |
|
| 1159 | - $meta[ $meta_key ] = $def_val; |
|
| 1160 | - } |
|
| 1161 | - |
|
| 1162 | - return $meta[ $meta_key ]; |
|
| 1163 | - } else { |
|
| 1164 | - return $meta; |
|
| 1165 | - } |
|
| 1166 | - } |
|
| 1167 | - |
|
| 1168 | - return $def_val; |
|
| 1169 | - } |
|
| 1170 | - |
|
| 1171 | - /** |
|
| 1172 | - * Generate Boxes. |
|
| 1173 | - * |
|
| 1174 | - * @param mixed $post Post. |
|
| 1175 | - * @param array $metabox Metabox array. |
|
| 1176 | - */ |
|
| 1177 | - public function generate_boxes( $post, array $metabox ) { |
|
| 1178 | - if ( ! empty( $metabox['args']['permissions'] ) && ! Redux_Helpers::current_user_can( $metabox['args']['permissions'] ) ) { |
|
| 1179 | - return; |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - $sections = $metabox['args']['sections']; |
|
| 1183 | - |
|
| 1184 | - wp_nonce_field( 'redux_metaboxes_meta_nonce', 'redux_metaboxes_meta_nonce' ); |
|
| 1185 | - |
|
| 1186 | - wp_dequeue_script( 'json-view-js' ); |
|
| 1187 | - |
|
| 1188 | - $sidebar = true; |
|
| 1189 | - |
|
| 1190 | - if ( 'side' === $metabox['args']['position'] || 1 === count( $sections ) || ( isset( $metabox['args']['sidebar'] ) && false === $metabox['args']['sidebar'] ) ) { |
|
| 1191 | - $sidebar = false; // Show the section dividers or not. |
|
| 1192 | - } |
|
| 1193 | - |
|
| 1194 | - ?> |
|
| 820 | + // Taken from class-wp.php. |
|
| 821 | + foreach ( $GLOBALS['wp_post_types'] as $post_type => $t ) { |
|
| 822 | + if ( isset( $t->query_var ) ) { |
|
| 823 | + $post_type_query_vars[ $t->query_var ] = $post_type; |
|
| 824 | + } |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + foreach ( $wp->public_query_vars as $wpvar ) { |
|
| 828 | + if ( isset( $wp->extra_query_vars[ $wpvar ] ) ) { |
|
| 829 | + $query[ $wpvar ] = $wp->extra_query_vars[ $wpvar ]; |
|
| 830 | + } elseif ( isset( $_POST[ $wpvar ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 831 | + $query[ $wpvar ] = sanitize_text_field( wp_unslash( $_POST[ $wpvar ] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 832 | + } elseif ( isset( $_GET[ $wpvar ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 833 | + $query[ $wpvar ] = sanitize_text_field( wp_unslash( $_GET[ $wpvar ] ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 834 | + } elseif ( isset( $query_vars[ $wpvar ] ) ) { |
|
| 835 | + $query[ $wpvar ] = $query_vars[ $wpvar ]; |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + if ( ! empty( $query[ $wpvar ] ) ) { |
|
| 839 | + if ( ! is_array( $query[ $wpvar ] ) ) { |
|
| 840 | + $query[ $wpvar ] = (string) $query[ $wpvar ]; |
|
| 841 | + } else { |
|
| 842 | + foreach ( $query[ $wpvar ] as $vkey => $v ) { |
|
| 843 | + if ( ! is_object( $v ) ) { |
|
| 844 | + $query[ $wpvar ][ $vkey ] = (string) $v; |
|
| 845 | + } |
|
| 846 | + } |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + if ( isset( $post_type_query_vars[ $wpvar ] ) ) { |
|
| 850 | + $query['post_type'] = $post_type_query_vars[ $wpvar ]; |
|
| 851 | + $query['name'] = $query[ $wpvar ]; |
|
| 852 | + } |
|
| 853 | + } |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + // Do the query. |
|
| 857 | + if ( ! empty( $query['pagename'] ) ) { |
|
| 858 | + $args = array( |
|
| 859 | + 'name' => $query['pagename'], |
|
| 860 | + 'post_type' => 'page', |
|
| 861 | + 'showposts' => 1, |
|
| 862 | + ); |
|
| 863 | + |
|
| 864 | + if ( isset( $post ) && get_posts( $args ) === $post ) { |
|
| 865 | + return $post[0]->ID; |
|
| 866 | + } |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + $query = new WP_Query( $query ); |
|
| 870 | + |
|
| 871 | + if ( ! empty( $query->posts ) && $query->is_singular ) { |
|
| 872 | + return $query->post->ID; |
|
| 873 | + } else { |
|
| 874 | + |
|
| 875 | + // WooCommerce override. |
|
| 876 | + if ( isset( $query->query['post_type'] ) && 'product' === $query->query['post_type'] && class_exists( 'WooCommerce' ) ) { |
|
| 877 | + return get_option( 'woocommerce_shop_page_id' ); |
|
| 878 | + } |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + if ( ( empty( $query['page'] ) ) && ( empty( $query['pagename'] ) ) ) { |
|
| 882 | + return 0; |
|
| 883 | + } |
|
| 884 | + } |
|
| 885 | + } |
|
| 886 | + |
|
| 887 | + return 0; |
|
| 888 | + } |
|
| 889 | + |
|
| 890 | + /** |
|
| 891 | + * Get default values. |
|
| 892 | + */ |
|
| 893 | + public function default_values() { |
|
| 894 | + if ( ! empty( $this->boxes ) && empty( $this->options_defaults ) ) { |
|
| 895 | + foreach ( $this->boxes as $key => $box ) { |
|
| 896 | + if ( empty( $box['sections'] ) ) { |
|
| 897 | + continue; |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + // fill the cache. |
|
| 901 | + foreach ( $box['sections'] as $sk => $section ) { |
|
| 902 | + if ( ! isset( $section['id'] ) ) { |
|
| 903 | + if ( ! is_numeric( $sk ) || ! isset( $section['title'] ) ) { |
|
| 904 | + $section['id'] = $sk; |
|
| 905 | + } else { |
|
| 906 | + $section['id'] = sanitize_text_field( $section['title'] ); |
|
| 907 | + } |
|
| 908 | + $this->boxes[ $key ]['sections'][ $sk ] = $section; |
|
| 909 | + } |
|
| 910 | + if ( isset( $section['fields'] ) ) { |
|
| 911 | + foreach ( $section['fields'] as $k => $field ) { |
|
| 912 | + |
|
| 913 | + if ( empty( $field['id'] ) && empty( $field['type'] ) ) { |
|
| 914 | + continue; |
|
| 915 | + } |
|
| 916 | + |
|
| 917 | + if ( 'ace_editor' === $field['type'] && isset( $field['options'] ) ) { |
|
| 918 | + $this->boxes[ $key ]['sections'][ $sk ]['fields'][ $k ]['args'] = $field['options']; |
|
| 919 | + unset( $this->boxes[ $key ]['sections'][ $sk ]['fields'][ $k ]['options'] ); |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + if ( 'section' === $field['type'] && isset( $field['indent'] ) && ( true === $field['indent'] || 'true' === $field['indent'] ) ) { |
|
| 923 | + $field['class'] = $field['class'] ?? ''; |
|
| 924 | + $field['class'] .= 'redux-section-indent-start'; |
|
| 925 | + |
|
| 926 | + $this->boxes[ $key ]['sections'][ $sk ]['fields'][ $k ] = $field; |
|
| 927 | + } |
|
| 928 | + |
|
| 929 | + if ( ! isset( $this->parent->options_defaults_class ) ) { |
|
| 930 | + $this->parent->options_defaults_class = new Redux_Options_Defaults(); |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + $this->parent->options_defaults_class->field_default_values( $this->parent->args['opt_name'], $field ); |
|
| 934 | + |
|
| 935 | + if ( 'repeater' === $field['type'] ) { |
|
| 936 | + foreach ( $field['fields'] as $f ) { |
|
| 937 | + $this->parent->options_defaults_class->field_default_values( $this->parent->args['opt_name'], $f, null, true ); |
|
| 938 | + } |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + $this->parent->options_defaults = $this->parent->options_defaults_class->options_defaults; |
|
| 942 | + } |
|
| 943 | + } |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | + } |
|
| 947 | + |
|
| 948 | + if ( empty( $this->meta[ $this->post_id ] ) ) { |
|
| 949 | + $this->meta[ $this->post_id ] = $this->get_meta( $this->post_id ); |
|
| 950 | + } |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + /** |
|
| 954 | + * Add Meta Boxes |
|
| 955 | + */ |
|
| 956 | + public function add() { |
|
| 957 | + if ( empty( $this->boxes ) || ! is_array( $this->boxes ) ) { |
|
| 958 | + return; |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + foreach ( $this->boxes as $key => $box ) { |
|
| 962 | + if ( empty( $box['sections'] ) ) { |
|
| 963 | + continue; |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + // Save users from themselves. |
|
| 967 | + if ( isset( $box['position'] ) && ! in_array( strtolower( $box['position'] ), array( 'normal', 'advanced', 'side' ), true ) ) { |
|
| 968 | + unset( $box['position'] ); |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + if ( isset( $box['priority'] ) && ! in_array( strtolower( $box['priority'] ), array( 'high', 'core', 'default', 'low' ), true ) ) { |
|
| 972 | + unset( $box['priority'] ); |
|
| 973 | + } |
|
| 974 | + |
|
| 975 | + $defaults = array( |
|
| 976 | + 'id' => $key . '-' . $this->parent->args['opt_name'], |
|
| 977 | + 'post_types' => array( 'page', 'post' ), |
|
| 978 | + 'position' => 'normal', |
|
| 979 | + 'priority' => 'high', |
|
| 980 | + ); |
|
| 981 | + |
|
| 982 | + $box = wp_parse_args( $box, $defaults ); |
|
| 983 | + if ( ! empty( $box['post_types'] ) ) { |
|
| 984 | + foreach ( $box['post_types'] as $posttype ) { |
|
| 985 | + if ( isset( $box['title'] ) ) { |
|
| 986 | + $title = $box['title']; |
|
| 987 | + } elseif ( isset( $box['sections'] ) && 1 === count( $box['sections'] ) && isset( $box['sections'][0]['fields'] ) && 1 === count( $box['sections'][0]['fields'] ) && isset( $box['sections'][0]['fields'][0]['title'] ) ) { |
|
| 988 | + |
|
| 989 | + // If only one field in this box. |
|
| 990 | + $title = $box['sections'][0]['fields'][0]['title']; |
|
| 991 | + } else { |
|
| 992 | + $title = ucfirst( $posttype ) . ' ' . __( 'Options', 'redux-framework' ); |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + $args = array( |
|
| 996 | + 'position' => $box['position'], |
|
| 997 | + 'sections' => $box['sections'], |
|
| 998 | + 'key' => $key, |
|
| 999 | + ); |
|
| 1000 | + |
|
| 1001 | + // Override the parent args on a metabox level. |
|
| 1002 | + if ( empty( $this->orig_args ) ) { |
|
| 1003 | + $this->orig_args = $this->parent->args; |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + if ( isset( $box['args'] ) ) { |
|
| 1007 | + $this->parent->args = wp_parse_args( $box['args'], $this->orig_args ); |
|
| 1008 | + } elseif ( $this->parent->args !== $this->orig_args ) { |
|
| 1009 | + $this->parent->args = $this->orig_args; |
|
| 1010 | + } |
|
| 1011 | + |
|
| 1012 | + add_filter( 'postbox_classes_' . $posttype . '_redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id'], array( $this, 'add_box_classes' ) ); |
|
| 1013 | + |
|
| 1014 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1015 | + do_action( 'redux/' . $this->parent->args['opt_name'] . '/extensions/metabox/add', $this, $box, $posttype ); |
|
| 1016 | + |
|
| 1017 | + if ( isset( $box['post_format'] ) ) { |
|
| 1018 | + add_filter( 'postbox_classes_' . $posttype . '_redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id'], array( $this, 'add_box_hide_class' ) ); |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + // phpcs:ignore Generic.Strings.UnnecessaryStringConcat |
|
| 1022 | + call_user_func( 'add' . '_meta' . '_box', 'redux-' . $this->parent->args['opt_name'] . '-metabox-' . $box['id'], $title, array( $this, 'generate_boxes' ), $posttype, $box['position'], $box['priority'], $args ); |
|
| 1023 | + } |
|
| 1024 | + } |
|
| 1025 | + } |
|
| 1026 | + } |
|
| 1027 | + |
|
| 1028 | + /** |
|
| 1029 | + * Add hidden class to metabox DIV. |
|
| 1030 | + * |
|
| 1031 | + * @param array $classes Class array. |
|
| 1032 | + * |
|
| 1033 | + * @return array |
|
| 1034 | + */ |
|
| 1035 | + public function add_box_hide_class( array $classes ): array { |
|
| 1036 | + $classes[] = 'hide'; |
|
| 1037 | + |
|
| 1038 | + return $classes; |
|
| 1039 | + } |
|
| 1040 | + |
|
| 1041 | + /** |
|
| 1042 | + * Field Defaults. |
|
| 1043 | + * |
|
| 1044 | + * @param mixed $field_id ID. |
|
| 1045 | + * |
|
| 1046 | + * @return mixed|string |
|
| 1047 | + */ |
|
| 1048 | + private function field_default( $field_id ) { |
|
| 1049 | + if ( ! isset( $this->parent->options_defaults ) ) { |
|
| 1050 | + $this->parent->options_defaults = $this->parent->default_values(); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + if ( ! isset( $this->parent->options ) || empty( $this->parent->options ) ) { |
|
| 1054 | + if ( ! isset( $this->parent->options_class ) ) { |
|
| 1055 | + $this->parent->options_class = new Redux_Options_Constructor( $this->parent ); |
|
| 1056 | + } |
|
| 1057 | + |
|
| 1058 | + $this->parent->options_class->get(); |
|
| 1059 | + } |
|
| 1060 | + |
|
| 1061 | + $this->options = $this->parent->options; |
|
| 1062 | + |
|
| 1063 | + if ( isset( $this->parent->options[ $field_id['id'] ] ) && isset( $this->parent->options_defaults[ $field_id['id'] ] ) && $this->parent->options[ $field_id['id'] ] !== $this->parent->options_defaults[ $field_id['id'] ] ) { |
|
| 1064 | + return $this->parent->options[ $field_id['id'] ]; |
|
| 1065 | + } else { |
|
| 1066 | + if ( empty( $this->options_defaults ) ) { |
|
| 1067 | + $this->default_values(); // fill cache. |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + $data = ''; |
|
| 1071 | + if ( ! empty( $this->options_defaults ) ) { |
|
| 1072 | + $data = $this->options_defaults[ $field_id['id'] ] ?? ''; |
|
| 1073 | + } |
|
| 1074 | + |
|
| 1075 | + if ( empty( $data ) && isset( $this->parent->options_defaults[ $field_id['id'] ] ) ) { |
|
| 1076 | + $data = $this->parent->options_defaults[ $field_id['id'] ] ?? ''; |
|
| 1077 | + } |
|
| 1078 | + |
|
| 1079 | + return $data; |
|
| 1080 | + } |
|
| 1081 | + } |
|
| 1082 | + |
|
| 1083 | + /** |
|
| 1084 | + * Function to get and cache the post meta. |
|
| 1085 | + * |
|
| 1086 | + * @param mixed $id ID. |
|
| 1087 | + * |
|
| 1088 | + * @return array |
|
| 1089 | + */ |
|
| 1090 | + private function get_meta( $id ): array { |
|
| 1091 | + if ( ! isset( $this->meta[ $id ] ) ) { |
|
| 1092 | + $this->meta[ $id ] = array(); |
|
| 1093 | + $o_data = get_post_meta( $id ); |
|
| 1094 | + |
|
| 1095 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1096 | + $o_data = apply_filters( "redux/metaboxes/{$this->parent->args['opt_name']}/get_meta", $o_data ); |
|
| 1097 | + |
|
| 1098 | + if ( ! empty( $o_data ) ) { |
|
| 1099 | + foreach ( $o_data as $key => $value ) { |
|
| 1100 | + if ( 1 === count( $value ) ) { |
|
| 1101 | + $this->meta[ $id ][ $key ] = maybe_unserialize( $value[0] ); |
|
| 1102 | + } else { |
|
| 1103 | + $new_value = array_map( 'maybe_unserialize', $value ); |
|
| 1104 | + |
|
| 1105 | + $this->meta[ $id ][ $key ] = $new_value[0]; |
|
| 1106 | + } |
|
| 1107 | + } |
|
| 1108 | + } |
|
| 1109 | + |
|
| 1110 | + if ( isset( $this->meta[ $id ][ $this->parent->args['opt_name'] ] ) ) { |
|
| 1111 | + $data = maybe_unserialize( $this->meta[ $id ][ $this->parent->args['opt_name'] ] ); |
|
| 1112 | + |
|
| 1113 | + foreach ( $data as $key => $value ) { |
|
| 1114 | + $this->meta[ $id ][ $key ] = $value; |
|
| 1115 | + update_post_meta( $id, $key, $value ); |
|
| 1116 | + } |
|
| 1117 | + |
|
| 1118 | + unset( $this->meta[ $id ][ $this->parent->args['opt_name'] ] ); |
|
| 1119 | + |
|
| 1120 | + delete_post_meta( $id, $this->parent->args['opt_name'] ); |
|
| 1121 | + } |
|
| 1122 | + } |
|
| 1123 | + |
|
| 1124 | + return $this->meta[ $id ]; |
|
| 1125 | + } |
|
| 1126 | + |
|
| 1127 | + /** |
|
| 1128 | + * Get values. |
|
| 1129 | + * |
|
| 1130 | + * @param mixed $the_post Post object/id. |
|
| 1131 | + * @param string $meta_key Meta key. |
|
| 1132 | + * @param mixed $def_val Def value. |
|
| 1133 | + * |
|
| 1134 | + * @return array|mixed|string |
|
| 1135 | + */ |
|
| 1136 | + public function get_values( $the_post, string $meta_key = '', $def_val = '' ) { |
|
| 1137 | + |
|
| 1138 | + // Override these values if they differ from the admin panel defaults. ;) . |
|
| 1139 | + if ( isset( $the_post->post_type ) && in_array( $the_post->post_type, $this->post_types, true ) ) { |
|
| 1140 | + if ( isset( $this->post_type_values[ $the_post->post_type ] ) ) { |
|
| 1141 | + $meta = $this->post_type_fields[ $the_post->post_type ]; |
|
| 1142 | + } else { |
|
| 1143 | + $defaults = array(); |
|
| 1144 | + if ( ! empty( $this->post_type_fields[ $the_post->post_type ] ) ) { |
|
| 1145 | + foreach ( $this->post_type_fields[ $the_post->post_type ] as $key => $null ) { |
|
| 1146 | + if ( isset( $this->options_defaults[ $key ] ) ) { |
|
| 1147 | + $defaults[ $key ] = $this->options_defaults[ $key ]; |
|
| 1148 | + } |
|
| 1149 | + } |
|
| 1150 | + } |
|
| 1151 | + |
|
| 1152 | + $meta = wp_parse_args( $this->get_meta( $the_post->ID ), $defaults ); |
|
| 1153 | + |
|
| 1154 | + $this->post_type_fields[ $the_post->post_type ] = $meta; |
|
| 1155 | + } |
|
| 1156 | + |
|
| 1157 | + if ( ! empty( $meta_key ) ) { |
|
| 1158 | + if ( ! isset( $meta[ $meta_key ] ) ) { |
|
| 1159 | + $meta[ $meta_key ] = $def_val; |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + return $meta[ $meta_key ]; |
|
| 1163 | + } else { |
|
| 1164 | + return $meta; |
|
| 1165 | + } |
|
| 1166 | + } |
|
| 1167 | + |
|
| 1168 | + return $def_val; |
|
| 1169 | + } |
|
| 1170 | + |
|
| 1171 | + /** |
|
| 1172 | + * Generate Boxes. |
|
| 1173 | + * |
|
| 1174 | + * @param mixed $post Post. |
|
| 1175 | + * @param array $metabox Metabox array. |
|
| 1176 | + */ |
|
| 1177 | + public function generate_boxes( $post, array $metabox ) { |
|
| 1178 | + if ( ! empty( $metabox['args']['permissions'] ) && ! Redux_Helpers::current_user_can( $metabox['args']['permissions'] ) ) { |
|
| 1179 | + return; |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + $sections = $metabox['args']['sections']; |
|
| 1183 | + |
|
| 1184 | + wp_nonce_field( 'redux_metaboxes_meta_nonce', 'redux_metaboxes_meta_nonce' ); |
|
| 1185 | + |
|
| 1186 | + wp_dequeue_script( 'json-view-js' ); |
|
| 1187 | + |
|
| 1188 | + $sidebar = true; |
|
| 1189 | + |
|
| 1190 | + if ( 'side' === $metabox['args']['position'] || 1 === count( $sections ) || ( isset( $metabox['args']['sidebar'] ) && false === $metabox['args']['sidebar'] ) ) { |
|
| 1191 | + $sidebar = false; // Show the section dividers or not. |
|
| 1192 | + } |
|
| 1193 | + |
|
| 1194 | + ?> |
|
| 1195 | 1195 | <input |
| 1196 | 1196 | type="hidden" |
| 1197 | 1197 | id="currentSection" |
@@ -1221,21 +1221,21 @@ discard block |
||
| 1221 | 1221 | </div> |
| 1222 | 1222 | </div> |
| 1223 | 1223 | <?php |
| 1224 | - echo '<a href="javascript:void(0);" class="expand_options hide" style="display:none;">' . esc_html__( 'Expand', 'redux-framework' ) . '</a>'; |
|
| 1225 | - if ( $sidebar ) { |
|
| 1226 | - ?> |
|
| 1224 | + echo '<a href="javascript:void(0);" class="expand_options hide" style="display:none;">' . esc_html__( 'Expand', 'redux-framework' ) . '</a>'; |
|
| 1225 | + if ( $sidebar ) { |
|
| 1226 | + ?> |
|
| 1227 | 1227 | <div class="redux-sidebar"> |
| 1228 | 1228 | <ul class="redux-group-menu"> |
| 1229 | 1229 | <?php |
| 1230 | 1230 | |
| 1231 | - foreach ( $sections as $s_key => $section ) { |
|
| 1232 | - if ( ! empty( $section['permissions'] ) && ! Redux_Helpers::current_user_can( $section['permissions'] ) ) { |
|
| 1233 | - continue; |
|
| 1234 | - } |
|
| 1231 | + foreach ( $sections as $s_key => $section ) { |
|
| 1232 | + if ( ! empty( $section['permissions'] ) && ! Redux_Helpers::current_user_can( $section['permissions'] ) ) { |
|
| 1233 | + continue; |
|
| 1234 | + } |
|
| 1235 | 1235 | |
| 1236 | - echo $this->parent->render_class->section_menu( $s_key, $section, '_box_' . $metabox['id'], $sections ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1237 | - } |
|
| 1238 | - ?> |
|
| 1236 | + echo $this->parent->render_class->section_menu( $s_key, $section, '_box_' . $metabox['id'], $sections ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1237 | + } |
|
| 1238 | + ?> |
|
| 1239 | 1239 | </ul> |
| 1240 | 1240 | </div> |
| 1241 | 1241 | <?php } ?> |
@@ -1243,295 +1243,295 @@ discard block |
||
| 1243 | 1243 | <div class="redux-main"> |
| 1244 | 1244 | <?php |
| 1245 | 1245 | |
| 1246 | - foreach ( $sections as $s_key => $section ) { |
|
| 1247 | - if ( ! empty( $section['permissions'] ) && ! Redux_Helpers::current_user_can( $section['permissions'] ) ) { |
|
| 1248 | - continue; |
|
| 1249 | - } |
|
| 1250 | - if ( ! empty( $section['fields'] ) ) { |
|
| 1251 | - if ( isset( $section['args'] ) ) { |
|
| 1252 | - $this->parent->args = wp_parse_args( $section['args'], $this->orig_args ); |
|
| 1253 | - } elseif ( $this->parent->args !== $this->orig_args ) { |
|
| 1254 | - $this->parent->args = $this->orig_args; |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - $hide = $sidebar ? '' : ' display-group'; |
|
| 1258 | - $section['class'] = isset( $section['class'] ) ? ' ' . $section['class'] : ''; |
|
| 1259 | - echo '<div id="' . esc_attr( $s_key ) . '_box_' . esc_attr( $metabox['id'] ) . '_section_group" class="redux-group-tab' . esc_attr( $section['class'] ) . ' redux_metabox_panel' . esc_attr( $hide ) . '">'; |
|
| 1260 | - |
|
| 1261 | - if ( ! empty( $section['title'] ) ) { |
|
| 1262 | - echo '<h3 class="redux-section-title">' . wp_kses_post( $section['title'] ) . '</h3>'; |
|
| 1263 | - } |
|
| 1264 | - |
|
| 1265 | - if ( ! empty( $section['desc'] ) ) { |
|
| 1266 | - echo '<div class="redux-section-desc">' . wp_kses_post( $section['desc'] ) . '</div>'; |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - echo '<table class="form-table"><tbody>'; |
|
| 1270 | - foreach ( $section['fields'] as $field ) { |
|
| 1271 | - if ( ! empty( $field['permissions'] ) && ! Redux_Helpers::current_user_can( $field['permissions'] ) ) { |
|
| 1272 | - continue; |
|
| 1273 | - } |
|
| 1274 | - $field['name'] = $this->parent->args['opt_name'] . '[' . $field['id'] . ']'; |
|
| 1275 | - |
|
| 1276 | - $is_hidden = false; |
|
| 1277 | - $ex_style = ''; |
|
| 1278 | - if ( isset( $field['hidden'] ) && $field['hidden'] ) { |
|
| 1279 | - $is_hidden = true; |
|
| 1280 | - $ex_style = ' style="border-bottom: none;"'; |
|
| 1281 | - } |
|
| 1282 | - |
|
| 1283 | - echo '<tr valign="top"' . $ex_style . '>'; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1284 | - |
|
| 1285 | - $th = $this->parent->render_class->get_header_html( $field ); |
|
| 1286 | - |
|
| 1287 | - if ( $is_hidden ) { |
|
| 1288 | - $str_pos = strpos( $th, 'redux_field_th' ); |
|
| 1289 | - |
|
| 1290 | - if ( $str_pos > - 1 ) { |
|
| 1291 | - $th = str_replace( 'redux_field_th', 'redux_field_th hide', $th ); |
|
| 1292 | - } |
|
| 1293 | - } |
|
| 1294 | - |
|
| 1295 | - if ( $sidebar ) { |
|
| 1296 | - if ( ! ( isset( $metabox['args']['sections'] ) && 1 === count( $metabox['args']['sections'] ) && isset( $metabox['args']['sections'][0]['fields'] ) && 1 === count( $metabox['args']['sections'][0]['fields'] ) ) && isset( $field['title'] ) ) { |
|
| 1297 | - echo '<th scope="row">'; |
|
| 1298 | - if ( ! empty( $th ) ) { |
|
| 1299 | - echo $th; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1300 | - } |
|
| 1301 | - echo '</th>'; |
|
| 1302 | - echo '<td>'; |
|
| 1303 | - } |
|
| 1304 | - } else { |
|
| 1305 | - echo '<td>' . $th; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - if ( 'section' === $field['type'] && ( 'true' === $field['indent'] || true === $field['indent'] ) ) { |
|
| 1309 | - $field['class'] = $field['class'] ?? ''; |
|
| 1310 | - $field['class'] .= 'redux-section-indent-start'; |
|
| 1311 | - } |
|
| 1312 | - |
|
| 1313 | - if ( ! isset( $this->meta[ $this->post_id ][ $field['id'] ] ) ) { |
|
| 1314 | - $this->meta[ $this->post_id ][ $field['id'] ] = ''; |
|
| 1315 | - } |
|
| 1316 | - |
|
| 1317 | - $this->parent->render_class->field_input( $field, $this->meta[ $this->post_id ][ $field['id'] ], true ); |
|
| 1318 | - echo '</td></tr>'; |
|
| 1319 | - } |
|
| 1320 | - echo '</tbody></table>'; |
|
| 1321 | - echo '</div>'; |
|
| 1322 | - } |
|
| 1323 | - } |
|
| 1324 | - ?> |
|
| 1246 | + foreach ( $sections as $s_key => $section ) { |
|
| 1247 | + if ( ! empty( $section['permissions'] ) && ! Redux_Helpers::current_user_can( $section['permissions'] ) ) { |
|
| 1248 | + continue; |
|
| 1249 | + } |
|
| 1250 | + if ( ! empty( $section['fields'] ) ) { |
|
| 1251 | + if ( isset( $section['args'] ) ) { |
|
| 1252 | + $this->parent->args = wp_parse_args( $section['args'], $this->orig_args ); |
|
| 1253 | + } elseif ( $this->parent->args !== $this->orig_args ) { |
|
| 1254 | + $this->parent->args = $this->orig_args; |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + $hide = $sidebar ? '' : ' display-group'; |
|
| 1258 | + $section['class'] = isset( $section['class'] ) ? ' ' . $section['class'] : ''; |
|
| 1259 | + echo '<div id="' . esc_attr( $s_key ) . '_box_' . esc_attr( $metabox['id'] ) . '_section_group" class="redux-group-tab' . esc_attr( $section['class'] ) . ' redux_metabox_panel' . esc_attr( $hide ) . '">'; |
|
| 1260 | + |
|
| 1261 | + if ( ! empty( $section['title'] ) ) { |
|
| 1262 | + echo '<h3 class="redux-section-title">' . wp_kses_post( $section['title'] ) . '</h3>'; |
|
| 1263 | + } |
|
| 1264 | + |
|
| 1265 | + if ( ! empty( $section['desc'] ) ) { |
|
| 1266 | + echo '<div class="redux-section-desc">' . wp_kses_post( $section['desc'] ) . '</div>'; |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + echo '<table class="form-table"><tbody>'; |
|
| 1270 | + foreach ( $section['fields'] as $field ) { |
|
| 1271 | + if ( ! empty( $field['permissions'] ) && ! Redux_Helpers::current_user_can( $field['permissions'] ) ) { |
|
| 1272 | + continue; |
|
| 1273 | + } |
|
| 1274 | + $field['name'] = $this->parent->args['opt_name'] . '[' . $field['id'] . ']'; |
|
| 1275 | + |
|
| 1276 | + $is_hidden = false; |
|
| 1277 | + $ex_style = ''; |
|
| 1278 | + if ( isset( $field['hidden'] ) && $field['hidden'] ) { |
|
| 1279 | + $is_hidden = true; |
|
| 1280 | + $ex_style = ' style="border-bottom: none;"'; |
|
| 1281 | + } |
|
| 1282 | + |
|
| 1283 | + echo '<tr valign="top"' . $ex_style . '>'; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1284 | + |
|
| 1285 | + $th = $this->parent->render_class->get_header_html( $field ); |
|
| 1286 | + |
|
| 1287 | + if ( $is_hidden ) { |
|
| 1288 | + $str_pos = strpos( $th, 'redux_field_th' ); |
|
| 1289 | + |
|
| 1290 | + if ( $str_pos > - 1 ) { |
|
| 1291 | + $th = str_replace( 'redux_field_th', 'redux_field_th hide', $th ); |
|
| 1292 | + } |
|
| 1293 | + } |
|
| 1294 | + |
|
| 1295 | + if ( $sidebar ) { |
|
| 1296 | + if ( ! ( isset( $metabox['args']['sections'] ) && 1 === count( $metabox['args']['sections'] ) && isset( $metabox['args']['sections'][0]['fields'] ) && 1 === count( $metabox['args']['sections'][0]['fields'] ) ) && isset( $field['title'] ) ) { |
|
| 1297 | + echo '<th scope="row">'; |
|
| 1298 | + if ( ! empty( $th ) ) { |
|
| 1299 | + echo $th; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1300 | + } |
|
| 1301 | + echo '</th>'; |
|
| 1302 | + echo '<td>'; |
|
| 1303 | + } |
|
| 1304 | + } else { |
|
| 1305 | + echo '<td>' . $th; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + if ( 'section' === $field['type'] && ( 'true' === $field['indent'] || true === $field['indent'] ) ) { |
|
| 1309 | + $field['class'] = $field['class'] ?? ''; |
|
| 1310 | + $field['class'] .= 'redux-section-indent-start'; |
|
| 1311 | + } |
|
| 1312 | + |
|
| 1313 | + if ( ! isset( $this->meta[ $this->post_id ][ $field['id'] ] ) ) { |
|
| 1314 | + $this->meta[ $this->post_id ][ $field['id'] ] = ''; |
|
| 1315 | + } |
|
| 1316 | + |
|
| 1317 | + $this->parent->render_class->field_input( $field, $this->meta[ $this->post_id ][ $field['id'] ], true ); |
|
| 1318 | + echo '</td></tr>'; |
|
| 1319 | + } |
|
| 1320 | + echo '</tbody></table>'; |
|
| 1321 | + echo '</div>'; |
|
| 1322 | + } |
|
| 1323 | + } |
|
| 1324 | + ?> |
|
| 1325 | 1325 | </div> |
| 1326 | 1326 | <div class="clear"></div> |
| 1327 | 1327 | </div> |
| 1328 | 1328 | <?php |
| 1329 | - } |
|
| 1330 | - |
|
| 1331 | - /** |
|
| 1332 | - * Save meta boxes |
|
| 1333 | - * Runs when a post is saved and does an action which the write panel save scripts can hook into. |
|
| 1334 | - * |
|
| 1335 | - * @access public |
|
| 1336 | - * |
|
| 1337 | - * @param mixed $post_id Post ID. |
|
| 1338 | - * @param mixed $post Post. |
|
| 1339 | - * |
|
| 1340 | - * @return mixed |
|
| 1341 | - */ |
|
| 1342 | - public function meta_boxes_save( $post_id, $post ) { |
|
| 1343 | - if ( isset( $_POST['vc_inline'] ) && sanitize_text_field( wp_unslash( $_POST['vc_inline'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1344 | - return $post_id; |
|
| 1345 | - } |
|
| 1346 | - |
|
| 1347 | - if ( isset( $_POST['post_ID'] ) && strval( $post_id ) !== $_POST['post_ID'] ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1348 | - return $post_id; |
|
| 1349 | - } |
|
| 1350 | - |
|
| 1351 | - // Check if our nonce is set. |
|
| 1352 | - if ( ! isset( $_POST['redux_metaboxes_meta_nonce'] ) || ! isset( $_POST[ $this->parent->args['opt_name'] ] ) ) { |
|
| 1353 | - return $post_id; |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - // Verify that the nonce is valid. |
|
| 1357 | - // Validate fields (if needed). |
|
| 1358 | - if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['redux_metaboxes_meta_nonce'] ) ), 'redux_metaboxes_meta_nonce' ) ) { |
|
| 1359 | - return $post_id; |
|
| 1360 | - } |
|
| 1361 | - |
|
| 1362 | - // If this is an autosave, our form has not been submitted, so we don't want to do anything. |
|
| 1363 | - if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
| 1364 | - return $post_id; |
|
| 1365 | - } |
|
| 1366 | - |
|
| 1367 | - // Check the user's permissions, even allowing custom capabilities. |
|
| 1368 | - $obj = get_post_type_object( $post->post_type ); |
|
| 1369 | - if ( ! current_user_can( $obj->cap->edit_post, $post_id ) ) { |
|
| 1370 | - return $post_id; |
|
| 1371 | - } |
|
| 1372 | - |
|
| 1373 | - // Import. |
|
| 1374 | - if ( isset( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ) && ! empty( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ) ) { |
|
| 1375 | - $import = json_decode( sanitize_text_field( wp_unslash( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ) ), true ); |
|
| 1376 | - unset( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ); |
|
| 1377 | - |
|
| 1378 | - foreach ( Redux_Helpers::sanitize_array( wp_unslash( $_POST[ $this->parent->args['opt_name'] ] ) ) as $key => $value ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput |
|
| 1379 | - if ( ! isset( $import[ $key ] ) ) { |
|
| 1380 | - $import[ $key ] = $value; |
|
| 1381 | - } |
|
| 1382 | - } |
|
| 1383 | - |
|
| 1384 | - $_POST[ $this->parent->args['opt_name'] ] = $import; |
|
| 1385 | - } |
|
| 1386 | - |
|
| 1387 | - $to_save = array(); |
|
| 1388 | - $to_compare = array(); |
|
| 1389 | - $to_delete = array(); |
|
| 1390 | - $dont_save = true; |
|
| 1391 | - |
|
| 1392 | - if ( isset( $this->parent->args['metaboxes_save_defaults'] ) && $this->parent->args['metaboxes_save_defaults'] ) { |
|
| 1393 | - $dont_save = false; |
|
| 1394 | - } |
|
| 1395 | - |
|
| 1396 | - foreach ( Redux_Helpers::sanitize_array( wp_unslash( $_POST[ $this->parent->args['opt_name'] ] ) ) as $key => $value ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput |
|
| 1397 | - |
|
| 1398 | - // Have to remove the escaping for array comparison. |
|
| 1399 | - if ( is_array( $value ) ) { |
|
| 1400 | - foreach ( $value as $k => $v ) { |
|
| 1401 | - if ( ! is_array( $v ) ) { |
|
| 1402 | - $value[ $k ] = wp_unslash( $v ); |
|
| 1403 | - } |
|
| 1404 | - } |
|
| 1405 | - } |
|
| 1406 | - |
|
| 1407 | - $save = true; |
|
| 1408 | - |
|
| 1409 | - // parent_options. |
|
| 1410 | - if ( ! $dont_save && isset( $this->options_defaults[ $key ] ) && $value === $this->options_defaults[ $key ] ) { |
|
| 1411 | - $save = false; |
|
| 1412 | - } |
|
| 1413 | - |
|
| 1414 | - if ( $save && isset( $this->parent_options[ $key ] ) && $this->parent_options[ $key ] !== $value ) { |
|
| 1415 | - $save = false; |
|
| 1416 | - } |
|
| 1417 | - |
|
| 1418 | - if ( $save ) { |
|
| 1419 | - $to_save[ $key ] = $value; |
|
| 1420 | - $to_compare[ $key ] = $this->parent->options[ $key ] ?? ''; |
|
| 1421 | - } else { |
|
| 1422 | - $to_delete[ $key ] = $value; |
|
| 1423 | - } |
|
| 1424 | - } |
|
| 1425 | - |
|
| 1426 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1427 | - $to_save = apply_filters( 'redux/metaboxes/save/before_validate', $to_save, $to_compare, $this->sections ); |
|
| 1428 | - |
|
| 1429 | - $validate = $this->parent->validate_class->validate( $to_save, $to_compare, $this->sections ); |
|
| 1430 | - |
|
| 1431 | - // Validate fields (if needed). |
|
| 1432 | - foreach ( $to_save as $key => $value ) { |
|
| 1433 | - if ( isset( $validate[ $key ] ) && $value !== $validate[ $key ] ) { |
|
| 1434 | - if ( isset( $this->parent->options[ $key ] ) && $validate[ $key ] === $this->parent->options[ $key ] ) { |
|
| 1435 | - unset( $to_save[ $key ] ); |
|
| 1436 | - } else { |
|
| 1437 | - $to_save[ $key ] = $validate[ $key ]; |
|
| 1438 | - } |
|
| 1439 | - } |
|
| 1440 | - } |
|
| 1441 | - |
|
| 1442 | - if ( ! empty( $this->parent->errors ) || ! empty( $this->parent->warnings ) ) { |
|
| 1443 | - $this->parent->transients['notices'] = ( isset( $this->parent->transients['notices'] ) && is_array( $this->parent->transients['notices'] ) ) ? $this->parent->transients['notices'] : array(); |
|
| 1444 | - |
|
| 1445 | - if ( ! isset( $this->parent->transients['notices']['errors'] ) || $this->parent->transients['notices']['errors'] !== $this->parent->errors ) { |
|
| 1446 | - $this->parent->transients['notices']['errors'] = $this->parent->errors; |
|
| 1447 | - $update_transients = true; |
|
| 1448 | - } |
|
| 1449 | - |
|
| 1450 | - if ( ! isset( $this->parent->transients['notices']['warnings'] ) || $this->parent->transients['notices']['warnings'] !== $this->parent->warnings ) { |
|
| 1451 | - $this->parent->transients['notices']['warnings'] = $this->parent->warnings; |
|
| 1452 | - $update_transients = true; |
|
| 1453 | - } |
|
| 1454 | - |
|
| 1455 | - if ( isset( $update_transients ) ) { |
|
| 1456 | - $this->parent->transients['notices']['override'] = 1; |
|
| 1457 | - set_transient( $this->parent->args['opt_name'] . '-transients-metaboxes', $this->parent->transients ); |
|
| 1458 | - } |
|
| 1459 | - } |
|
| 1460 | - |
|
| 1461 | - if ( isset( $_POST['post_type'] ) ) { |
|
| 1462 | - $check = $this->post_type_fields[ sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) ]; |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1466 | - $to_save = apply_filters( 'redux/metaboxes/save', $to_save, $to_compare, $this->sections ); |
|
| 1467 | - |
|
| 1468 | - foreach ( $to_save as $key => $value ) { |
|
| 1469 | - $prev_value = $this->meta[ $post_id ][ $key ] ?? ''; |
|
| 1470 | - |
|
| 1471 | - if ( isset( $check[ $key ] ) ) { |
|
| 1472 | - unset( $check[ $key ] ); |
|
| 1473 | - } |
|
| 1474 | - |
|
| 1475 | - update_post_meta( $post_id, $key, $value, $prev_value ); |
|
| 1476 | - } |
|
| 1477 | - |
|
| 1478 | - foreach ( $to_delete as $key => $value ) { |
|
| 1479 | - if ( isset( $check[ $key ] ) ) { |
|
| 1480 | - unset( $check[ $key ] ); |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - $prev_value = $this->meta[ $post_id ][ $key ] ?? ''; |
|
| 1484 | - delete_post_meta( $post_id, $key, $prev_value ); |
|
| 1485 | - } |
|
| 1486 | - |
|
| 1487 | - if ( ! empty( $check ) ) { |
|
| 1488 | - foreach ( $check as $key => $value ) { |
|
| 1489 | - delete_post_meta( $post_id, $key ); |
|
| 1490 | - } |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - return $post_id; |
|
| 1494 | - } |
|
| 1495 | - |
|
| 1496 | - /** |
|
| 1497 | - * Some functions, like the term recount, require the visibility to be set prior. Lets save that here. |
|
| 1498 | - * |
|
| 1499 | - * @access public |
|
| 1500 | - * |
|
| 1501 | - * @param mixed $post_id Post ID. |
|
| 1502 | - * |
|
| 1503 | - * @return void |
|
| 1504 | - */ |
|
| 1505 | - public function pre_post_update( $post_id ) { |
|
| 1506 | - if ( isset( $_POST['_visibility'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1507 | - update_post_meta( $post_id, '_visibility', sanitize_text_field( wp_unslash( $_POST['_visibility'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1508 | - } |
|
| 1509 | - |
|
| 1510 | - if ( isset( $_POST['_stock_status'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1511 | - update_post_meta( $post_id, '_stock_status', sanitize_text_field( wp_unslash( $_POST['_stock_status'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1512 | - } |
|
| 1513 | - } |
|
| 1514 | - |
|
| 1515 | - /** |
|
| 1516 | - * Show any stored error messages. |
|
| 1517 | - * |
|
| 1518 | - * @access public |
|
| 1519 | - * @return void |
|
| 1520 | - */ |
|
| 1521 | - public function meta_boxes_show_errors() { |
|
| 1522 | - if ( isset( $this->notices['errors'] ) && ! empty( $this->notices['errors'] ) ) { |
|
| 1523 | - echo '<div id="redux_metaboxes_errors" class="error fade">'; |
|
| 1524 | - echo '<p><strong><span></span> ' . count( $this->notices['errors'] ) . ' ' . esc_html__( 'error(s) were found!', 'redux-framework' ) . '</strong></p>'; |
|
| 1525 | - echo '</div>'; |
|
| 1526 | - } |
|
| 1527 | - |
|
| 1528 | - if ( isset( $this->notices['warnings'] ) && ! empty( $this->notices['warnings'] ) ) { |
|
| 1529 | - echo '<div id="redux_metaboxes_warnings" class="error fade" style="border-left-color: #E8E20C;">'; |
|
| 1530 | - echo '<p><strong><span></span> ' . count( $this->notices['warnings'] ) . ' ' . esc_html__( 'warnings(s) were found!', 'redux-framework' ) . '</strong></p>'; |
|
| 1531 | - echo '</div>'; |
|
| 1532 | - } |
|
| 1533 | - } |
|
| 1534 | - } |
|
| 1535 | - |
|
| 1536 | - class_alias( Redux_Extension_Metaboxes::class, 'ReduxFramework_Extension_metaboxes' ); |
|
| 1329 | + } |
|
| 1330 | + |
|
| 1331 | + /** |
|
| 1332 | + * Save meta boxes |
|
| 1333 | + * Runs when a post is saved and does an action which the write panel save scripts can hook into. |
|
| 1334 | + * |
|
| 1335 | + * @access public |
|
| 1336 | + * |
|
| 1337 | + * @param mixed $post_id Post ID. |
|
| 1338 | + * @param mixed $post Post. |
|
| 1339 | + * |
|
| 1340 | + * @return mixed |
|
| 1341 | + */ |
|
| 1342 | + public function meta_boxes_save( $post_id, $post ) { |
|
| 1343 | + if ( isset( $_POST['vc_inline'] ) && sanitize_text_field( wp_unslash( $_POST['vc_inline'] ) ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1344 | + return $post_id; |
|
| 1345 | + } |
|
| 1346 | + |
|
| 1347 | + if ( isset( $_POST['post_ID'] ) && strval( $post_id ) !== $_POST['post_ID'] ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1348 | + return $post_id; |
|
| 1349 | + } |
|
| 1350 | + |
|
| 1351 | + // Check if our nonce is set. |
|
| 1352 | + if ( ! isset( $_POST['redux_metaboxes_meta_nonce'] ) || ! isset( $_POST[ $this->parent->args['opt_name'] ] ) ) { |
|
| 1353 | + return $post_id; |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + // Verify that the nonce is valid. |
|
| 1357 | + // Validate fields (if needed). |
|
| 1358 | + if ( ! wp_verify_nonce( sanitize_key( wp_unslash( $_POST['redux_metaboxes_meta_nonce'] ) ), 'redux_metaboxes_meta_nonce' ) ) { |
|
| 1359 | + return $post_id; |
|
| 1360 | + } |
|
| 1361 | + |
|
| 1362 | + // If this is an autosave, our form has not been submitted, so we don't want to do anything. |
|
| 1363 | + if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
|
| 1364 | + return $post_id; |
|
| 1365 | + } |
|
| 1366 | + |
|
| 1367 | + // Check the user's permissions, even allowing custom capabilities. |
|
| 1368 | + $obj = get_post_type_object( $post->post_type ); |
|
| 1369 | + if ( ! current_user_can( $obj->cap->edit_post, $post_id ) ) { |
|
| 1370 | + return $post_id; |
|
| 1371 | + } |
|
| 1372 | + |
|
| 1373 | + // Import. |
|
| 1374 | + if ( isset( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ) && ! empty( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ) ) { |
|
| 1375 | + $import = json_decode( sanitize_text_field( wp_unslash( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ) ), true ); |
|
| 1376 | + unset( $_POST[ $this->parent->args['opt_name'] ]['import_code'] ); |
|
| 1377 | + |
|
| 1378 | + foreach ( Redux_Helpers::sanitize_array( wp_unslash( $_POST[ $this->parent->args['opt_name'] ] ) ) as $key => $value ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput |
|
| 1379 | + if ( ! isset( $import[ $key ] ) ) { |
|
| 1380 | + $import[ $key ] = $value; |
|
| 1381 | + } |
|
| 1382 | + } |
|
| 1383 | + |
|
| 1384 | + $_POST[ $this->parent->args['opt_name'] ] = $import; |
|
| 1385 | + } |
|
| 1386 | + |
|
| 1387 | + $to_save = array(); |
|
| 1388 | + $to_compare = array(); |
|
| 1389 | + $to_delete = array(); |
|
| 1390 | + $dont_save = true; |
|
| 1391 | + |
|
| 1392 | + if ( isset( $this->parent->args['metaboxes_save_defaults'] ) && $this->parent->args['metaboxes_save_defaults'] ) { |
|
| 1393 | + $dont_save = false; |
|
| 1394 | + } |
|
| 1395 | + |
|
| 1396 | + foreach ( Redux_Helpers::sanitize_array( wp_unslash( $_POST[ $this->parent->args['opt_name'] ] ) ) as $key => $value ) { // phpcs:ignore WordPress.Security.ValidatedSanitizedInput |
|
| 1397 | + |
|
| 1398 | + // Have to remove the escaping for array comparison. |
|
| 1399 | + if ( is_array( $value ) ) { |
|
| 1400 | + foreach ( $value as $k => $v ) { |
|
| 1401 | + if ( ! is_array( $v ) ) { |
|
| 1402 | + $value[ $k ] = wp_unslash( $v ); |
|
| 1403 | + } |
|
| 1404 | + } |
|
| 1405 | + } |
|
| 1406 | + |
|
| 1407 | + $save = true; |
|
| 1408 | + |
|
| 1409 | + // parent_options. |
|
| 1410 | + if ( ! $dont_save && isset( $this->options_defaults[ $key ] ) && $value === $this->options_defaults[ $key ] ) { |
|
| 1411 | + $save = false; |
|
| 1412 | + } |
|
| 1413 | + |
|
| 1414 | + if ( $save && isset( $this->parent_options[ $key ] ) && $this->parent_options[ $key ] !== $value ) { |
|
| 1415 | + $save = false; |
|
| 1416 | + } |
|
| 1417 | + |
|
| 1418 | + if ( $save ) { |
|
| 1419 | + $to_save[ $key ] = $value; |
|
| 1420 | + $to_compare[ $key ] = $this->parent->options[ $key ] ?? ''; |
|
| 1421 | + } else { |
|
| 1422 | + $to_delete[ $key ] = $value; |
|
| 1423 | + } |
|
| 1424 | + } |
|
| 1425 | + |
|
| 1426 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1427 | + $to_save = apply_filters( 'redux/metaboxes/save/before_validate', $to_save, $to_compare, $this->sections ); |
|
| 1428 | + |
|
| 1429 | + $validate = $this->parent->validate_class->validate( $to_save, $to_compare, $this->sections ); |
|
| 1430 | + |
|
| 1431 | + // Validate fields (if needed). |
|
| 1432 | + foreach ( $to_save as $key => $value ) { |
|
| 1433 | + if ( isset( $validate[ $key ] ) && $value !== $validate[ $key ] ) { |
|
| 1434 | + if ( isset( $this->parent->options[ $key ] ) && $validate[ $key ] === $this->parent->options[ $key ] ) { |
|
| 1435 | + unset( $to_save[ $key ] ); |
|
| 1436 | + } else { |
|
| 1437 | + $to_save[ $key ] = $validate[ $key ]; |
|
| 1438 | + } |
|
| 1439 | + } |
|
| 1440 | + } |
|
| 1441 | + |
|
| 1442 | + if ( ! empty( $this->parent->errors ) || ! empty( $this->parent->warnings ) ) { |
|
| 1443 | + $this->parent->transients['notices'] = ( isset( $this->parent->transients['notices'] ) && is_array( $this->parent->transients['notices'] ) ) ? $this->parent->transients['notices'] : array(); |
|
| 1444 | + |
|
| 1445 | + if ( ! isset( $this->parent->transients['notices']['errors'] ) || $this->parent->transients['notices']['errors'] !== $this->parent->errors ) { |
|
| 1446 | + $this->parent->transients['notices']['errors'] = $this->parent->errors; |
|
| 1447 | + $update_transients = true; |
|
| 1448 | + } |
|
| 1449 | + |
|
| 1450 | + if ( ! isset( $this->parent->transients['notices']['warnings'] ) || $this->parent->transients['notices']['warnings'] !== $this->parent->warnings ) { |
|
| 1451 | + $this->parent->transients['notices']['warnings'] = $this->parent->warnings; |
|
| 1452 | + $update_transients = true; |
|
| 1453 | + } |
|
| 1454 | + |
|
| 1455 | + if ( isset( $update_transients ) ) { |
|
| 1456 | + $this->parent->transients['notices']['override'] = 1; |
|
| 1457 | + set_transient( $this->parent->args['opt_name'] . '-transients-metaboxes', $this->parent->transients ); |
|
| 1458 | + } |
|
| 1459 | + } |
|
| 1460 | + |
|
| 1461 | + if ( isset( $_POST['post_type'] ) ) { |
|
| 1462 | + $check = $this->post_type_fields[ sanitize_text_field( wp_unslash( $_POST['post_type'] ) ) ]; |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 1466 | + $to_save = apply_filters( 'redux/metaboxes/save', $to_save, $to_compare, $this->sections ); |
|
| 1467 | + |
|
| 1468 | + foreach ( $to_save as $key => $value ) { |
|
| 1469 | + $prev_value = $this->meta[ $post_id ][ $key ] ?? ''; |
|
| 1470 | + |
|
| 1471 | + if ( isset( $check[ $key ] ) ) { |
|
| 1472 | + unset( $check[ $key ] ); |
|
| 1473 | + } |
|
| 1474 | + |
|
| 1475 | + update_post_meta( $post_id, $key, $value, $prev_value ); |
|
| 1476 | + } |
|
| 1477 | + |
|
| 1478 | + foreach ( $to_delete as $key => $value ) { |
|
| 1479 | + if ( isset( $check[ $key ] ) ) { |
|
| 1480 | + unset( $check[ $key ] ); |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + $prev_value = $this->meta[ $post_id ][ $key ] ?? ''; |
|
| 1484 | + delete_post_meta( $post_id, $key, $prev_value ); |
|
| 1485 | + } |
|
| 1486 | + |
|
| 1487 | + if ( ! empty( $check ) ) { |
|
| 1488 | + foreach ( $check as $key => $value ) { |
|
| 1489 | + delete_post_meta( $post_id, $key ); |
|
| 1490 | + } |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + return $post_id; |
|
| 1494 | + } |
|
| 1495 | + |
|
| 1496 | + /** |
|
| 1497 | + * Some functions, like the term recount, require the visibility to be set prior. Lets save that here. |
|
| 1498 | + * |
|
| 1499 | + * @access public |
|
| 1500 | + * |
|
| 1501 | + * @param mixed $post_id Post ID. |
|
| 1502 | + * |
|
| 1503 | + * @return void |
|
| 1504 | + */ |
|
| 1505 | + public function pre_post_update( $post_id ) { |
|
| 1506 | + if ( isset( $_POST['_visibility'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1507 | + update_post_meta( $post_id, '_visibility', sanitize_text_field( wp_unslash( $_POST['_visibility'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1508 | + } |
|
| 1509 | + |
|
| 1510 | + if ( isset( $_POST['_stock_status'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1511 | + update_post_meta( $post_id, '_stock_status', sanitize_text_field( wp_unslash( $_POST['_stock_status'] ) ) ); // phpcs:ignore WordPress.Security.NonceVerification |
|
| 1512 | + } |
|
| 1513 | + } |
|
| 1514 | + |
|
| 1515 | + /** |
|
| 1516 | + * Show any stored error messages. |
|
| 1517 | + * |
|
| 1518 | + * @access public |
|
| 1519 | + * @return void |
|
| 1520 | + */ |
|
| 1521 | + public function meta_boxes_show_errors() { |
|
| 1522 | + if ( isset( $this->notices['errors'] ) && ! empty( $this->notices['errors'] ) ) { |
|
| 1523 | + echo '<div id="redux_metaboxes_errors" class="error fade">'; |
|
| 1524 | + echo '<p><strong><span></span> ' . count( $this->notices['errors'] ) . ' ' . esc_html__( 'error(s) were found!', 'redux-framework' ) . '</strong></p>'; |
|
| 1525 | + echo '</div>'; |
|
| 1526 | + } |
|
| 1527 | + |
|
| 1528 | + if ( isset( $this->notices['warnings'] ) && ! empty( $this->notices['warnings'] ) ) { |
|
| 1529 | + echo '<div id="redux_metaboxes_warnings" class="error fade" style="border-left-color: #E8E20C;">'; |
|
| 1530 | + echo '<p><strong><span></span> ' . count( $this->notices['warnings'] ) . ' ' . esc_html__( 'warnings(s) were found!', 'redux-framework' ) . '</strong></p>'; |
|
| 1531 | + echo '</div>'; |
|
| 1532 | + } |
|
| 1533 | + } |
|
| 1534 | + } |
|
| 1535 | + |
|
| 1536 | + class_alias( Redux_Extension_Metaboxes::class, 'ReduxFramework_Extension_metaboxes' ); |
|
| 1537 | 1537 | } |
@@ -8,93 +8,93 @@ |
||
| 8 | 8 | defined( 'ABSPATH' ) || exit; |
| 9 | 9 | |
| 10 | 10 | if ( ! function_exists( 'redux_social_profile_value_from_id' ) ) { |
| 11 | - /** |
|
| 12 | - * Returns social profile value from passed profile ID. |
|
| 13 | - * |
|
| 14 | - * @param string $opt_name Redux Framework opt_name. |
|
| 15 | - * @param string $id Profile ID. |
|
| 16 | - * @param string $value Social profile value to return (icon, name, background, color, url, or order). |
|
| 17 | - * |
|
| 18 | - * @return string Returns HTML string when $echo is set to false. Otherwise, true. |
|
| 19 | - * @since 1.0.0 |
|
| 20 | - * @access public |
|
| 21 | - */ |
|
| 22 | - function redux_social_profile_value_from_id( string $opt_name, string $id, string $value ): string { |
|
| 23 | - if ( empty( $opt_name ) || empty( $id ) || empty( $value ) ) { |
|
| 24 | - return ''; |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - $redux = ReduxFrameworkInstances::get_instance( $opt_name ); |
|
| 28 | - $social_profiles = $redux->extensions['social_profiles']; |
|
| 29 | - |
|
| 30 | - $redux_options = get_option( $social_profiles->opt_name ); |
|
| 31 | - $settings = $redux_options[ $social_profiles->field_id ]; |
|
| 32 | - |
|
| 33 | - foreach ( $settings as $arr ) { |
|
| 34 | - if ( $id === $arr['id'] ) { |
|
| 35 | - if ( $arr['enabled'] ) { |
|
| 36 | - if ( isset( $arr[ $value ] ) ) { |
|
| 37 | - return $arr[ $value ]; |
|
| 38 | - } |
|
| 39 | - } else { |
|
| 40 | - return ''; |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - return ''; |
|
| 46 | - } |
|
| 11 | + /** |
|
| 12 | + * Returns social profile value from passed profile ID. |
|
| 13 | + * |
|
| 14 | + * @param string $opt_name Redux Framework opt_name. |
|
| 15 | + * @param string $id Profile ID. |
|
| 16 | + * @param string $value Social profile value to return (icon, name, background, color, url, or order). |
|
| 17 | + * |
|
| 18 | + * @return string Returns HTML string when $echo is set to false. Otherwise, true. |
|
| 19 | + * @since 1.0.0 |
|
| 20 | + * @access public |
|
| 21 | + */ |
|
| 22 | + function redux_social_profile_value_from_id( string $opt_name, string $id, string $value ): string { |
|
| 23 | + if ( empty( $opt_name ) || empty( $id ) || empty( $value ) ) { |
|
| 24 | + return ''; |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + $redux = ReduxFrameworkInstances::get_instance( $opt_name ); |
|
| 28 | + $social_profiles = $redux->extensions['social_profiles']; |
|
| 29 | + |
|
| 30 | + $redux_options = get_option( $social_profiles->opt_name ); |
|
| 31 | + $settings = $redux_options[ $social_profiles->field_id ]; |
|
| 32 | + |
|
| 33 | + foreach ( $settings as $arr ) { |
|
| 34 | + if ( $id === $arr['id'] ) { |
|
| 35 | + if ( $arr['enabled'] ) { |
|
| 36 | + if ( isset( $arr[ $value ] ) ) { |
|
| 37 | + return $arr[ $value ]; |
|
| 38 | + } |
|
| 39 | + } else { |
|
| 40 | + return ''; |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + return ''; |
|
| 46 | + } |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | if ( ! function_exists( 'redux_render_icon_from_id' ) ) { |
| 50 | - /** |
|
| 51 | - * Renders social icon from passed profile ID. |
|
| 52 | - * |
|
| 53 | - * @param string $opt_name Redux Framework opt_name. |
|
| 54 | - * @param string $id Profile ID. |
|
| 55 | - * @param boolean $output Echos icon HTML when true. Returns icon HTML when false. |
|
| 56 | - * @param string $a_class Class name for a tag. |
|
| 57 | - * |
|
| 58 | - * @return string Returns HTML string when $echo is set to false. Otherwise, true. |
|
| 59 | - * @since 1.0.0 |
|
| 60 | - * @access public |
|
| 61 | - */ |
|
| 62 | - function redux_render_icon_from_id( string $opt_name, string $id, bool $output = true, string $a_class = '' ) { |
|
| 63 | - if ( empty( $opt_name ) || empty( $id ) ) { |
|
| 64 | - return ''; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - include_once 'social_profiles/inc/class-redux-social-profiles-functions.php'; |
|
| 68 | - |
|
| 69 | - $redux = ReduxFrameworkInstances::get_instance( $opt_name ); |
|
| 70 | - $social_profiles = $redux->extensions['social_profiles']; |
|
| 71 | - |
|
| 72 | - $redux_options = get_option( $social_profiles->opt_name ); |
|
| 73 | - $settings = $redux_options[ $social_profiles->field_id ]; |
|
| 74 | - |
|
| 75 | - foreach ( $settings as $arr ) { |
|
| 76 | - if ( $id === $arr['id'] ) { |
|
| 77 | - if ( $arr['enabled'] ) { |
|
| 78 | - $arr['class'] = $arr['class'] ?? 'fa'; |
|
| 79 | - |
|
| 80 | - if ( $output ) { |
|
| 81 | - echo '<a class="' . esc_attr( $a_class ) . '" href="' . esc_url( $arr['url'] ) . '">'; |
|
| 82 | - Redux_Social_Profiles_Functions::render_icon( $arr['class'], $arr['icon'], $arr['color'], $arr['background'], '' ); |
|
| 83 | - echo '</a>'; |
|
| 84 | - |
|
| 85 | - return true; |
|
| 86 | - } else { |
|
| 87 | - $html = '<a class="' . $a_class . '"href="' . $arr['url'] . '">'; |
|
| 88 | - |
|
| 89 | - $html .= Redux_Social_Profiles_Functions::render_icon( $arr['class'], $arr['icon'], $arr['color'], $arr['background'], '', false ); |
|
| 90 | - $html .= '</a>'; |
|
| 91 | - |
|
| 92 | - return $html; |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - return ''; |
|
| 99 | - } |
|
| 50 | + /** |
|
| 51 | + * Renders social icon from passed profile ID. |
|
| 52 | + * |
|
| 53 | + * @param string $opt_name Redux Framework opt_name. |
|
| 54 | + * @param string $id Profile ID. |
|
| 55 | + * @param boolean $output Echos icon HTML when true. Returns icon HTML when false. |
|
| 56 | + * @param string $a_class Class name for a tag. |
|
| 57 | + * |
|
| 58 | + * @return string Returns HTML string when $echo is set to false. Otherwise, true. |
|
| 59 | + * @since 1.0.0 |
|
| 60 | + * @access public |
|
| 61 | + */ |
|
| 62 | + function redux_render_icon_from_id( string $opt_name, string $id, bool $output = true, string $a_class = '' ) { |
|
| 63 | + if ( empty( $opt_name ) || empty( $id ) ) { |
|
| 64 | + return ''; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + include_once 'social_profiles/inc/class-redux-social-profiles-functions.php'; |
|
| 68 | + |
|
| 69 | + $redux = ReduxFrameworkInstances::get_instance( $opt_name ); |
|
| 70 | + $social_profiles = $redux->extensions['social_profiles']; |
|
| 71 | + |
|
| 72 | + $redux_options = get_option( $social_profiles->opt_name ); |
|
| 73 | + $settings = $redux_options[ $social_profiles->field_id ]; |
|
| 74 | + |
|
| 75 | + foreach ( $settings as $arr ) { |
|
| 76 | + if ( $id === $arr['id'] ) { |
|
| 77 | + if ( $arr['enabled'] ) { |
|
| 78 | + $arr['class'] = $arr['class'] ?? 'fa'; |
|
| 79 | + |
|
| 80 | + if ( $output ) { |
|
| 81 | + echo '<a class="' . esc_attr( $a_class ) . '" href="' . esc_url( $arr['url'] ) . '">'; |
|
| 82 | + Redux_Social_Profiles_Functions::render_icon( $arr['class'], $arr['icon'], $arr['color'], $arr['background'], '' ); |
|
| 83 | + echo '</a>'; |
|
| 84 | + |
|
| 85 | + return true; |
|
| 86 | + } else { |
|
| 87 | + $html = '<a class="' . $a_class . '"href="' . $arr['url'] . '">'; |
|
| 88 | + |
|
| 89 | + $html .= Redux_Social_Profiles_Functions::render_icon( $arr['class'], $arr['icon'], $arr['color'], $arr['background'], '', false ); |
|
| 90 | + $html .= '</a>'; |
|
| 91 | + |
|
| 92 | + return $html; |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + return ''; |
|
| 99 | + } |
|
| 100 | 100 | } |
@@ -11,73 +11,73 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Social_Profiles_Shortcode' ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Class Redux_Social_Profiles_Shortcode |
|
| 16 | - */ |
|
| 17 | - class Redux_Social_Profiles_Shortcode { |
|
| 14 | + /** |
|
| 15 | + * Class Redux_Social_Profiles_Shortcode |
|
| 16 | + */ |
|
| 17 | + class Redux_Social_Profiles_Shortcode { |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * ReduxFramework object pointer. |
|
| 21 | - * |
|
| 22 | - * @var ReduxFramework |
|
| 23 | - */ |
|
| 24 | - private ReduxFramework $parent; |
|
| 19 | + /** |
|
| 20 | + * ReduxFramework object pointer. |
|
| 21 | + * |
|
| 22 | + * @var ReduxFramework |
|
| 23 | + */ |
|
| 24 | + private ReduxFramework $parent; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * Field ID. |
|
| 28 | - * |
|
| 29 | - * @var string |
|
| 30 | - */ |
|
| 31 | - private string $field_id; |
|
| 26 | + /** |
|
| 27 | + * Field ID. |
|
| 28 | + * |
|
| 29 | + * @var string |
|
| 30 | + */ |
|
| 31 | + private string $field_id; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * Redux_Social_Profiles_Shortcode constructor. |
|
| 35 | - * |
|
| 36 | - * @param ReduxFramework $redux ReduxFramework object. |
|
| 37 | - * @param string $field_id Field ID. |
|
| 38 | - */ |
|
| 39 | - public function __construct( ReduxFramework $redux, string $field_id ) { |
|
| 40 | - $this->parent = $redux; |
|
| 41 | - $this->field_id = $field_id; |
|
| 33 | + /** |
|
| 34 | + * Redux_Social_Profiles_Shortcode constructor. |
|
| 35 | + * |
|
| 36 | + * @param ReduxFramework $redux ReduxFramework object. |
|
| 37 | + * @param string $field_id Field ID. |
|
| 38 | + */ |
|
| 39 | + public function __construct( ReduxFramework $redux, string $field_id ) { |
|
| 40 | + $this->parent = $redux; |
|
| 41 | + $this->field_id = $field_id; |
|
| 42 | 42 | |
| 43 | - add_shortcode( 'social_profiles', array( $this, 'redux_social_profiles' ) ); |
|
| 44 | - } |
|
| 43 | + add_shortcode( 'social_profiles', array( $this, 'redux_social_profiles' ) ); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Render shortcode. |
|
| 48 | - * |
|
| 49 | - * @return string |
|
| 50 | - */ |
|
| 51 | - public function redux_social_profiles(): string { |
|
| 52 | - $redux_options = get_option( $this->parent->args['opt_name'] ); |
|
| 53 | - $social_items = $redux_options[ $this->field_id ]; |
|
| 46 | + /** |
|
| 47 | + * Render shortcode. |
|
| 48 | + * |
|
| 49 | + * @return string |
|
| 50 | + */ |
|
| 51 | + public function redux_social_profiles(): string { |
|
| 52 | + $redux_options = get_option( $this->parent->args['opt_name'] ); |
|
| 53 | + $social_items = $redux_options[ $this->field_id ]; |
|
| 54 | 54 | |
| 55 | - $html = '<ul class="redux-social-media-list clearfix">'; |
|
| 55 | + $html = '<ul class="redux-social-media-list clearfix">'; |
|
| 56 | 56 | |
| 57 | - if ( is_array( $social_items ) ) { |
|
| 58 | - foreach ( $social_items as $social_item ) { |
|
| 59 | - if ( $social_item['enabled'] ) { |
|
| 60 | - $icon = $social_item['icon']; |
|
| 61 | - $class = $social_item['class'] ?? 'fa'; |
|
| 62 | - $color = $social_item['color']; |
|
| 63 | - $background = $social_item['background']; |
|
| 64 | - $base_url = $social_item['url']; |
|
| 65 | - $id = $social_item['id']; |
|
| 57 | + if ( is_array( $social_items ) ) { |
|
| 58 | + foreach ( $social_items as $social_item ) { |
|
| 59 | + if ( $social_item['enabled'] ) { |
|
| 60 | + $icon = $social_item['icon']; |
|
| 61 | + $class = $social_item['class'] ?? 'fa'; |
|
| 62 | + $color = $social_item['color']; |
|
| 63 | + $background = $social_item['background']; |
|
| 64 | + $base_url = $social_item['url']; |
|
| 65 | + $id = $social_item['id']; |
|
| 66 | 66 | |
| 67 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 68 | - $url = apply_filters( 'redux/extensions/social_profiles/' . $this->parent->args['opt_name'] . '/icon_url', $id, $base_url ); |
|
| 67 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 68 | + $url = apply_filters( 'redux/extensions/social_profiles/' . $this->parent->args['opt_name'] . '/icon_url', $id, $base_url ); |
|
| 69 | 69 | |
| 70 | - $html .= '<li style="list-style: none;">'; |
|
| 71 | - $html .= "<a href='" . $url . "'>"; |
|
| 72 | - $html .= Redux_Social_Profiles_Functions::render_icon( $class, $icon, $color, $background, '', false ); |
|
| 73 | - $html .= '</a>'; |
|
| 74 | - $html .= '</li>'; |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - $html .= '</ul>'; |
|
| 70 | + $html .= '<li style="list-style: none;">'; |
|
| 71 | + $html .= "<a href='" . $url . "'>"; |
|
| 72 | + $html .= Redux_Social_Profiles_Functions::render_icon( $class, $icon, $color, $background, '', false ); |
|
| 73 | + $html .= '</a>'; |
|
| 74 | + $html .= '</li>'; |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + $html .= '</ul>'; |
|
| 79 | 79 | |
| 80 | - return $html; |
|
| 81 | - } |
|
| 82 | - } |
|
| 80 | + return $html; |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | 83 | } |
@@ -11,330 +11,330 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Social_Profiles_Functions' ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Class Redux_Social_Profiles_Functions |
|
| 16 | - */ |
|
| 17 | - class Redux_Social_Profiles_Functions { |
|
| 18 | - /** |
|
| 19 | - * ReduxFramework object pointer. |
|
| 20 | - * |
|
| 21 | - * @var ReduxFramework |
|
| 22 | - */ |
|
| 23 | - public static ReduxFramework $parent; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Field ID. |
|
| 27 | - * |
|
| 28 | - * @var null|string |
|
| 29 | - */ |
|
| 30 | - public static ?string $field_id; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Field array. |
|
| 34 | - * |
|
| 35 | - * @var array|null |
|
| 36 | - */ |
|
| 37 | - public static ?array $field; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * WordPress upload directory. |
|
| 41 | - * |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 44 | - public static string $upload_dir; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * WordPress upload URI. |
|
| 48 | - * |
|
| 49 | - * @var string |
|
| 50 | - */ |
|
| 51 | - public static string $upload_url; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Init helper library. |
|
| 55 | - * |
|
| 56 | - * @param ReduxFramework $redux ReduxFramework object. |
|
| 57 | - */ |
|
| 58 | - public static function init( ReduxFramework $redux ) { |
|
| 59 | - self::$parent = $redux; |
|
| 60 | - |
|
| 61 | - if ( empty( self::$field_id ) ) { |
|
| 62 | - self::$field = self::get_field( $redux ); |
|
| 63 | - |
|
| 64 | - if ( ! is_array( self::$field ) ) { |
|
| 65 | - return; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - self::$field_id = self::$field['id']; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // Make sanitized upload dir DIR. |
|
| 72 | - self::$upload_dir = Redux_Functions_Ex::wp_normalize_path( Redux_Core::$upload_dir . 'social-profiles/' ); |
|
| 73 | - |
|
| 74 | - // Make sanitized upload dir URL. |
|
| 75 | - self::$upload_url = Redux_Functions_Ex::wp_normalize_path( Redux_Core::$upload_url . 'social-profiles/' ); |
|
| 76 | - |
|
| 77 | - Redux_Functions::init_wp_filesystem(); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - /** |
|
| 81 | - * Read data file. |
|
| 82 | - * |
|
| 83 | - * @return array|bool|mixed|object |
|
| 84 | - */ |
|
| 85 | - public static function read_data_file() { |
|
| 86 | - $file = self::get_data_path(); |
|
| 87 | - |
|
| 88 | - if ( file_exists( $file ) ) { |
|
| 89 | - |
|
| 90 | - // Get the contents of the file and stuff it in a variable. |
|
| 91 | - $data = Redux_Core::$filesystem->execute( 'get_contents', $file ); |
|
| 92 | - |
|
| 93 | - // Error or null, set the result to false. |
|
| 94 | - if ( false === $data || null === $data ) { |
|
| 95 | - $arr_data = false; |
|
| 96 | - |
|
| 97 | - // Otherwise, decode the json object and return it. |
|
| 98 | - } else { |
|
| 99 | - $arr = json_decode( $data, true ); |
|
| 100 | - $arr_data = $arr; |
|
| 101 | - } |
|
| 102 | - } else { |
|
| 103 | - $arr_data = false; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $arr_data; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Write data file. |
|
| 111 | - * |
|
| 112 | - * @param array $arr_data Data. |
|
| 113 | - * @param string $file Filename. |
|
| 114 | - * |
|
| 115 | - * @return bool |
|
| 116 | - */ |
|
| 117 | - public static function write_data_file( array $arr_data, string $file = '' ): bool { |
|
| 118 | - if ( ! is_dir( self::$upload_dir ) ) { |
|
| 119 | - return false; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - $file = ( '' === $file ) ? self::get_data_path() : self::$upload_dir . $file; |
|
| 123 | - |
|
| 124 | - // Encode the array data. |
|
| 125 | - $data = wp_json_encode( $arr_data ); |
|
| 126 | - |
|
| 127 | - // Write to its file on the server, return the return value |
|
| 128 | - // True on success, false on error. |
|
| 129 | - return Redux_Core::$filesystem->execute( 'put_contents', $file, array( 'content' => $data ) ); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Get the data path. |
|
| 134 | - * |
|
| 135 | - * @return mixed|Redux_Functions_Ex|string |
|
| 136 | - */ |
|
| 137 | - public static function get_data_path() { |
|
| 138 | - return Redux_Functions_Ex::wp_normalize_path( self::$upload_dir . '/' . self::$parent->args['opt_name'] . '-' . self::$field_id . '.json' ); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Get field. |
|
| 143 | - * |
|
| 144 | - * @param array|ReduxFramework $redux ReduxFramework object. |
|
| 145 | - * |
|
| 146 | - * @return mixed |
|
| 147 | - */ |
|
| 148 | - public static function get_field( $redux = array() ) { |
|
| 149 | - global $pagenow; |
|
| 150 | - |
|
| 151 | - if ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) { |
|
| 152 | - $inst = Redux_Instances::get_instance( self::$parent->args['opt_name'] ); |
|
| 153 | - |
|
| 154 | - $ext = $inst->extensions; |
|
| 155 | - |
|
| 156 | - if ( isset( $ext['metaboxes'] ) ) { |
|
| 157 | - $obj = $ext['metaboxes']; |
|
| 158 | - $boxes = ( $obj->boxes ); |
|
| 159 | - |
|
| 160 | - foreach ( $boxes as $sections ) { |
|
| 161 | - foreach ( $sections['sections'] as $fields ) { |
|
| 162 | - if ( isset( $fields['fields'] ) ) { |
|
| 163 | - foreach ( $fields['fields'] as $f ) { |
|
| 164 | - if ( 'social_profiles' === $f['type'] ) { |
|
| 165 | - return $f; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - if ( 'repeater' === $f['type'] ) { |
|
| 169 | - foreach ( $f['fields'] as $r ) { |
|
| 170 | - if ( 'social_profiles' === $r['type'] ) { |
|
| 171 | - return $r; |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - } else { |
|
| 181 | - if ( ! empty( $redux ) ) { |
|
| 182 | - self::$parent = $redux; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - if ( isset( self::$parent->field_sections['social_profiles'] ) ) { |
|
| 186 | - return reset( self::$parent->field_sections['social_profiles'] ); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $arr = self::$parent; |
|
| 190 | - |
|
| 191 | - foreach ( $arr as $part => $bla ) { |
|
| 192 | - if ( 'sections' === $part ) { |
|
| 193 | - foreach ( $bla as $field ) { |
|
| 194 | - |
|
| 195 | - foreach ( $field as $arg => $val ) { |
|
| 196 | - if ( 'fields' === $arg ) { |
|
| 197 | - foreach ( $val as $v ) { |
|
| 198 | - if ( ! empty( $v ) ) { |
|
| 199 | - foreach ( $v as $id => $x ) { |
|
| 200 | - if ( 'type' === $id ) { |
|
| 201 | - if ( 'social_profiles' === $x ) { |
|
| 202 | - return $v; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - return null; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Add extra icons. |
|
| 220 | - * |
|
| 221 | - * @param array $defaults Default values. |
|
| 222 | - * |
|
| 223 | - * @return array |
|
| 224 | - */ |
|
| 225 | - public static function add_extra_icons( array $defaults ): array { |
|
| 226 | - if ( empty( self::$field ) ) { |
|
| 227 | - self::$field = self::get_field(); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - if ( isset( self::$field['icons'] ) && ! empty( self::$field['icons'] ) ) { |
|
| 231 | - $cur_count = count( $defaults ); |
|
| 232 | - |
|
| 233 | - foreach ( self::$field['icons'] as $arr ) { |
|
| 234 | - |
|
| 235 | - $skip_add = false; |
|
| 236 | - foreach ( $defaults as $i => $v ) { |
|
| 237 | - if ( $arr['id'] === $v['id'] ) { |
|
| 238 | - |
|
| 239 | - $defaults[ $i ] = array_replace( $v, $arr ); |
|
| 240 | - $skip_add = true; |
|
| 241 | - break; |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - if ( ! $skip_add ) { |
|
| 246 | - $arr['order'] = $cur_count; |
|
| 247 | - $arr['class'] = $arr['class'] ?? 'fa'; |
|
| 248 | - $defaults[ $cur_count ] = $arr; |
|
| 249 | - ++$cur_count; |
|
| 250 | - } |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - return $defaults; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * Get Included files. |
|
| 259 | - * |
|
| 260 | - * @param array $val Value. |
|
| 261 | - * |
|
| 262 | - * @return array |
|
| 263 | - */ |
|
| 264 | - private static function get_includes( array $val ): array { |
|
| 265 | - if ( empty( self::$field ) ) { |
|
| 266 | - self::$field = self::get_field(); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - if ( isset( self::$field['include'] ) && is_array( self::$field['include'] ) && ! empty( self::$field['include'] ) ) { |
|
| 270 | - $icons = self::$field['include']; |
|
| 271 | - |
|
| 272 | - $new_arr = array(); |
|
| 273 | - |
|
| 274 | - $idx = 0; |
|
| 275 | - foreach ( $val as $arr ) { |
|
| 276 | - foreach ( $icons as $icon ) { |
|
| 277 | - if ( $icon === $arr['id'] ) { |
|
| 278 | - $arr['order'] = $idx; |
|
| 279 | - $new_arr[ $idx ] = $arr; |
|
| 280 | - ++$idx; |
|
| 281 | - break; |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - } else { |
|
| 286 | - $new_arr = $val; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - return $new_arr; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - /** |
|
| 293 | - * Returns default data from config. |
|
| 294 | - * |
|
| 295 | - * @return array |
|
| 296 | - */ |
|
| 297 | - public static function get_default_data(): array { |
|
| 298 | - $data = Redux_Social_Profiles_Defaults::get_social_media_defaults(); |
|
| 299 | - $data = self::get_includes( $data ); |
|
| 300 | - |
|
| 301 | - return self::add_extra_icons( $data ); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Static function to render the social icon. |
|
| 306 | - * |
|
| 307 | - * @param string $icon_class Icon class. |
|
| 308 | - * @param string $icon Icon css. |
|
| 309 | - * @param string $color Hex color. |
|
| 310 | - * @param string $background Background color. |
|
| 311 | - * @param string $title Icon title. |
|
| 312 | - * @param bool $output Print or echo. |
|
| 313 | - * |
|
| 314 | - * @return string|void |
|
| 315 | - */ |
|
| 316 | - public static function render_icon( string $icon_class, string $icon, string $color, string $background, string $title, bool $output = true ) { |
|
| 317 | - if ( $color || $background ) { |
|
| 318 | - if ( '' === $color ) { |
|
| 319 | - $color = 'transparent'; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - if ( '' === $background ) { |
|
| 323 | - $background = 'transparent'; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - $inline = 'style="color:' . esc_attr( $color ) . ';background-color:' . esc_attr( $background ) . ';"'; |
|
| 327 | - } else { |
|
| 328 | - $inline = ''; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - $str = '<i class="' . $icon_class . ' ' . $icon . '" ' . $inline . ' title="' . $title . '"></i>'; |
|
| 332 | - |
|
| 333 | - if ( $output ) { |
|
| 334 | - echo $str; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 335 | - } else { |
|
| 336 | - return $str; |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - } |
|
| 14 | + /** |
|
| 15 | + * Class Redux_Social_Profiles_Functions |
|
| 16 | + */ |
|
| 17 | + class Redux_Social_Profiles_Functions { |
|
| 18 | + /** |
|
| 19 | + * ReduxFramework object pointer. |
|
| 20 | + * |
|
| 21 | + * @var ReduxFramework |
|
| 22 | + */ |
|
| 23 | + public static ReduxFramework $parent; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Field ID. |
|
| 27 | + * |
|
| 28 | + * @var null|string |
|
| 29 | + */ |
|
| 30 | + public static ?string $field_id; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Field array. |
|
| 34 | + * |
|
| 35 | + * @var array|null |
|
| 36 | + */ |
|
| 37 | + public static ?array $field; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * WordPress upload directory. |
|
| 41 | + * |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | + public static string $upload_dir; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * WordPress upload URI. |
|
| 48 | + * |
|
| 49 | + * @var string |
|
| 50 | + */ |
|
| 51 | + public static string $upload_url; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Init helper library. |
|
| 55 | + * |
|
| 56 | + * @param ReduxFramework $redux ReduxFramework object. |
|
| 57 | + */ |
|
| 58 | + public static function init( ReduxFramework $redux ) { |
|
| 59 | + self::$parent = $redux; |
|
| 60 | + |
|
| 61 | + if ( empty( self::$field_id ) ) { |
|
| 62 | + self::$field = self::get_field( $redux ); |
|
| 63 | + |
|
| 64 | + if ( ! is_array( self::$field ) ) { |
|
| 65 | + return; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + self::$field_id = self::$field['id']; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // Make sanitized upload dir DIR. |
|
| 72 | + self::$upload_dir = Redux_Functions_Ex::wp_normalize_path( Redux_Core::$upload_dir . 'social-profiles/' ); |
|
| 73 | + |
|
| 74 | + // Make sanitized upload dir URL. |
|
| 75 | + self::$upload_url = Redux_Functions_Ex::wp_normalize_path( Redux_Core::$upload_url . 'social-profiles/' ); |
|
| 76 | + |
|
| 77 | + Redux_Functions::init_wp_filesystem(); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + /** |
|
| 81 | + * Read data file. |
|
| 82 | + * |
|
| 83 | + * @return array|bool|mixed|object |
|
| 84 | + */ |
|
| 85 | + public static function read_data_file() { |
|
| 86 | + $file = self::get_data_path(); |
|
| 87 | + |
|
| 88 | + if ( file_exists( $file ) ) { |
|
| 89 | + |
|
| 90 | + // Get the contents of the file and stuff it in a variable. |
|
| 91 | + $data = Redux_Core::$filesystem->execute( 'get_contents', $file ); |
|
| 92 | + |
|
| 93 | + // Error or null, set the result to false. |
|
| 94 | + if ( false === $data || null === $data ) { |
|
| 95 | + $arr_data = false; |
|
| 96 | + |
|
| 97 | + // Otherwise, decode the json object and return it. |
|
| 98 | + } else { |
|
| 99 | + $arr = json_decode( $data, true ); |
|
| 100 | + $arr_data = $arr; |
|
| 101 | + } |
|
| 102 | + } else { |
|
| 103 | + $arr_data = false; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $arr_data; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Write data file. |
|
| 111 | + * |
|
| 112 | + * @param array $arr_data Data. |
|
| 113 | + * @param string $file Filename. |
|
| 114 | + * |
|
| 115 | + * @return bool |
|
| 116 | + */ |
|
| 117 | + public static function write_data_file( array $arr_data, string $file = '' ): bool { |
|
| 118 | + if ( ! is_dir( self::$upload_dir ) ) { |
|
| 119 | + return false; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + $file = ( '' === $file ) ? self::get_data_path() : self::$upload_dir . $file; |
|
| 123 | + |
|
| 124 | + // Encode the array data. |
|
| 125 | + $data = wp_json_encode( $arr_data ); |
|
| 126 | + |
|
| 127 | + // Write to its file on the server, return the return value |
|
| 128 | + // True on success, false on error. |
|
| 129 | + return Redux_Core::$filesystem->execute( 'put_contents', $file, array( 'content' => $data ) ); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Get the data path. |
|
| 134 | + * |
|
| 135 | + * @return mixed|Redux_Functions_Ex|string |
|
| 136 | + */ |
|
| 137 | + public static function get_data_path() { |
|
| 138 | + return Redux_Functions_Ex::wp_normalize_path( self::$upload_dir . '/' . self::$parent->args['opt_name'] . '-' . self::$field_id . '.json' ); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Get field. |
|
| 143 | + * |
|
| 144 | + * @param array|ReduxFramework $redux ReduxFramework object. |
|
| 145 | + * |
|
| 146 | + * @return mixed |
|
| 147 | + */ |
|
| 148 | + public static function get_field( $redux = array() ) { |
|
| 149 | + global $pagenow; |
|
| 150 | + |
|
| 151 | + if ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) { |
|
| 152 | + $inst = Redux_Instances::get_instance( self::$parent->args['opt_name'] ); |
|
| 153 | + |
|
| 154 | + $ext = $inst->extensions; |
|
| 155 | + |
|
| 156 | + if ( isset( $ext['metaboxes'] ) ) { |
|
| 157 | + $obj = $ext['metaboxes']; |
|
| 158 | + $boxes = ( $obj->boxes ); |
|
| 159 | + |
|
| 160 | + foreach ( $boxes as $sections ) { |
|
| 161 | + foreach ( $sections['sections'] as $fields ) { |
|
| 162 | + if ( isset( $fields['fields'] ) ) { |
|
| 163 | + foreach ( $fields['fields'] as $f ) { |
|
| 164 | + if ( 'social_profiles' === $f['type'] ) { |
|
| 165 | + return $f; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + if ( 'repeater' === $f['type'] ) { |
|
| 169 | + foreach ( $f['fields'] as $r ) { |
|
| 170 | + if ( 'social_profiles' === $r['type'] ) { |
|
| 171 | + return $r; |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + } else { |
|
| 181 | + if ( ! empty( $redux ) ) { |
|
| 182 | + self::$parent = $redux; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + if ( isset( self::$parent->field_sections['social_profiles'] ) ) { |
|
| 186 | + return reset( self::$parent->field_sections['social_profiles'] ); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $arr = self::$parent; |
|
| 190 | + |
|
| 191 | + foreach ( $arr as $part => $bla ) { |
|
| 192 | + if ( 'sections' === $part ) { |
|
| 193 | + foreach ( $bla as $field ) { |
|
| 194 | + |
|
| 195 | + foreach ( $field as $arg => $val ) { |
|
| 196 | + if ( 'fields' === $arg ) { |
|
| 197 | + foreach ( $val as $v ) { |
|
| 198 | + if ( ! empty( $v ) ) { |
|
| 199 | + foreach ( $v as $id => $x ) { |
|
| 200 | + if ( 'type' === $id ) { |
|
| 201 | + if ( 'social_profiles' === $x ) { |
|
| 202 | + return $v; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + return null; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Add extra icons. |
|
| 220 | + * |
|
| 221 | + * @param array $defaults Default values. |
|
| 222 | + * |
|
| 223 | + * @return array |
|
| 224 | + */ |
|
| 225 | + public static function add_extra_icons( array $defaults ): array { |
|
| 226 | + if ( empty( self::$field ) ) { |
|
| 227 | + self::$field = self::get_field(); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + if ( isset( self::$field['icons'] ) && ! empty( self::$field['icons'] ) ) { |
|
| 231 | + $cur_count = count( $defaults ); |
|
| 232 | + |
|
| 233 | + foreach ( self::$field['icons'] as $arr ) { |
|
| 234 | + |
|
| 235 | + $skip_add = false; |
|
| 236 | + foreach ( $defaults as $i => $v ) { |
|
| 237 | + if ( $arr['id'] === $v['id'] ) { |
|
| 238 | + |
|
| 239 | + $defaults[ $i ] = array_replace( $v, $arr ); |
|
| 240 | + $skip_add = true; |
|
| 241 | + break; |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + if ( ! $skip_add ) { |
|
| 246 | + $arr['order'] = $cur_count; |
|
| 247 | + $arr['class'] = $arr['class'] ?? 'fa'; |
|
| 248 | + $defaults[ $cur_count ] = $arr; |
|
| 249 | + ++$cur_count; |
|
| 250 | + } |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + return $defaults; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * Get Included files. |
|
| 259 | + * |
|
| 260 | + * @param array $val Value. |
|
| 261 | + * |
|
| 262 | + * @return array |
|
| 263 | + */ |
|
| 264 | + private static function get_includes( array $val ): array { |
|
| 265 | + if ( empty( self::$field ) ) { |
|
| 266 | + self::$field = self::get_field(); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + if ( isset( self::$field['include'] ) && is_array( self::$field['include'] ) && ! empty( self::$field['include'] ) ) { |
|
| 270 | + $icons = self::$field['include']; |
|
| 271 | + |
|
| 272 | + $new_arr = array(); |
|
| 273 | + |
|
| 274 | + $idx = 0; |
|
| 275 | + foreach ( $val as $arr ) { |
|
| 276 | + foreach ( $icons as $icon ) { |
|
| 277 | + if ( $icon === $arr['id'] ) { |
|
| 278 | + $arr['order'] = $idx; |
|
| 279 | + $new_arr[ $idx ] = $arr; |
|
| 280 | + ++$idx; |
|
| 281 | + break; |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + } else { |
|
| 286 | + $new_arr = $val; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + return $new_arr; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + /** |
|
| 293 | + * Returns default data from config. |
|
| 294 | + * |
|
| 295 | + * @return array |
|
| 296 | + */ |
|
| 297 | + public static function get_default_data(): array { |
|
| 298 | + $data = Redux_Social_Profiles_Defaults::get_social_media_defaults(); |
|
| 299 | + $data = self::get_includes( $data ); |
|
| 300 | + |
|
| 301 | + return self::add_extra_icons( $data ); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Static function to render the social icon. |
|
| 306 | + * |
|
| 307 | + * @param string $icon_class Icon class. |
|
| 308 | + * @param string $icon Icon css. |
|
| 309 | + * @param string $color Hex color. |
|
| 310 | + * @param string $background Background color. |
|
| 311 | + * @param string $title Icon title. |
|
| 312 | + * @param bool $output Print or echo. |
|
| 313 | + * |
|
| 314 | + * @return string|void |
|
| 315 | + */ |
|
| 316 | + public static function render_icon( string $icon_class, string $icon, string $color, string $background, string $title, bool $output = true ) { |
|
| 317 | + if ( $color || $background ) { |
|
| 318 | + if ( '' === $color ) { |
|
| 319 | + $color = 'transparent'; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + if ( '' === $background ) { |
|
| 323 | + $background = 'transparent'; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + $inline = 'style="color:' . esc_attr( $color ) . ';background-color:' . esc_attr( $background ) . ';"'; |
|
| 327 | + } else { |
|
| 328 | + $inline = ''; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + $str = '<i class="' . $icon_class . ' ' . $icon . '" ' . $inline . ' title="' . $title . '"></i>'; |
|
| 332 | + |
|
| 333 | + if ( $output ) { |
|
| 334 | + echo $str; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 335 | + } else { |
|
| 336 | + return $str; |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | 340 | } |
@@ -11,922 +11,922 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Social_Profiles_Defaults' ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Class Redux_Social_Profiles_Defaults |
|
| 16 | - */ |
|
| 17 | - class Redux_Social_Profiles_Defaults { |
|
| 14 | + /** |
|
| 15 | + * Class Redux_Social_Profiles_Defaults |
|
| 16 | + */ |
|
| 17 | + class Redux_Social_Profiles_Defaults { |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Get defaults array. |
|
| 21 | - * |
|
| 22 | - * @return array |
|
| 23 | - */ |
|
| 24 | - public static function get_social_media_defaults(): array { |
|
| 25 | - return array( |
|
| 26 | - 0 => array( |
|
| 27 | - 'id' => 'adn', |
|
| 28 | - 'icon' => 'fa-adn', |
|
| 29 | - 'class' => 'fa', |
|
| 30 | - 'enabled' => false, |
|
| 31 | - 'name' => esc_html__( 'ADN', 'redux-framework' ), |
|
| 32 | - 'background' => '', |
|
| 33 | - 'color' => '#000000', |
|
| 34 | - 'url' => '', |
|
| 35 | - 'order' => 0, |
|
| 36 | - ), |
|
| 37 | - 1 => array( |
|
| 38 | - 'id' => 'android', |
|
| 39 | - 'icon' => 'fa-android', |
|
| 40 | - 'class' => 'fa', |
|
| 41 | - 'enabled' => false, |
|
| 42 | - 'name' => esc_html__( 'Android', 'redux-framework' ), |
|
| 43 | - 'background' => '', |
|
| 44 | - 'color' => '#A4C639', |
|
| 45 | - 'url' => '', |
|
| 46 | - 'order' => 1, |
|
| 47 | - ), |
|
| 48 | - 2 => array( |
|
| 49 | - 'id' => 'apple', |
|
| 50 | - 'icon' => 'fa-apple', |
|
| 51 | - 'class' => 'fa', |
|
| 52 | - 'enabled' => false, |
|
| 53 | - 'name' => esc_html__( 'Apple', 'redux-framework' ), |
|
| 54 | - 'style' => '', |
|
| 55 | - 'background' => '', |
|
| 56 | - 'color' => '#e4e4e5', |
|
| 57 | - 'url' => '', |
|
| 58 | - 'order' => 2, |
|
| 59 | - ), |
|
| 60 | - 3 => array( |
|
| 61 | - 'id' => 'behance', |
|
| 62 | - 'icon' => 'fa-behance', |
|
| 63 | - 'class' => 'fa', |
|
| 64 | - 'enabled' => false, |
|
| 65 | - 'name' => esc_html__( 'behance', 'redux-framework' ), |
|
| 66 | - 'background' => '', |
|
| 67 | - 'color' => '#1769ff', |
|
| 68 | - 'url' => '', |
|
| 69 | - 'order' => 3, |
|
| 70 | - ), |
|
| 71 | - 4 => array( |
|
| 72 | - 'id' => 'behance-square', |
|
| 73 | - 'icon' => 'fa-behance-square', |
|
| 74 | - 'class' => 'fa', |
|
| 75 | - 'enabled' => false, |
|
| 76 | - 'name' => esc_html__( 'behance square', 'redux-framework' ), |
|
| 77 | - 'background' => '', |
|
| 78 | - 'color' => '#1769ff', |
|
| 79 | - 'url' => '', |
|
| 80 | - 'order' => 4, |
|
| 81 | - ), |
|
| 82 | - 5 => array( |
|
| 83 | - 'id' => 'bitbucket', |
|
| 84 | - 'icon' => 'fa-bitbucket', |
|
| 85 | - 'class' => 'fa', |
|
| 86 | - 'enabled' => false, |
|
| 87 | - 'name' => esc_html__( 'Bitbucket', 'redux-framework' ), |
|
| 88 | - 'background' => '', |
|
| 89 | - 'color' => '#205081', |
|
| 90 | - 'url' => '', |
|
| 91 | - 'order' => 5, |
|
| 92 | - ), |
|
| 93 | - 6 => array( |
|
| 94 | - 'id' => 'bitbucket-square', |
|
| 95 | - 'icon' => 'fa-bitbucket-square', |
|
| 96 | - 'class' => 'fa', |
|
| 97 | - 'enabled' => false, |
|
| 98 | - 'name' => esc_html__( 'Bitbucket square', 'redux-framework' ), |
|
| 99 | - 'background' => '', |
|
| 100 | - 'color' => '#205081', |
|
| 101 | - 'url' => '', |
|
| 102 | - 'order' => 6, |
|
| 103 | - ), |
|
| 104 | - 7 => array( |
|
| 105 | - 'id' => 'bitcoin', |
|
| 106 | - 'icon' => 'fa-btc', |
|
| 107 | - 'class' => 'fa', |
|
| 108 | - 'enabled' => false, |
|
| 109 | - 'name' => esc_html__( 'Bitcoin', 'redux-framework' ), |
|
| 110 | - 'background' => '', |
|
| 111 | - 'color' => '#000000', |
|
| 112 | - 'url' => '', |
|
| 113 | - 'order' => 7, |
|
| 114 | - ), |
|
| 115 | - 8 => array( |
|
| 116 | - 'id' => 'codepen', |
|
| 117 | - 'icon' => 'fa-codepen', |
|
| 118 | - 'class' => 'fa', |
|
| 119 | - 'enabled' => false, |
|
| 120 | - 'name' => esc_html__( 'CodePen', 'redux-framework' ), |
|
| 121 | - 'background' => '', |
|
| 122 | - 'color' => '#000000', |
|
| 123 | - 'url' => '', |
|
| 124 | - 'order' => 8, |
|
| 125 | - ), |
|
| 126 | - 9 => array( |
|
| 127 | - 'id' => 'css3', |
|
| 128 | - 'icon' => 'fa-css3', |
|
| 129 | - 'class' => 'fa', |
|
| 130 | - 'enabled' => false, |
|
| 131 | - 'name' => esc_html__( 'CSS3', 'redux-framework' ), |
|
| 132 | - 'background' => '', |
|
| 133 | - 'color' => '#000000', |
|
| 134 | - 'url' => '', |
|
| 135 | - 'order' => 9, |
|
| 136 | - ), |
|
| 137 | - 10 => array( |
|
| 138 | - 'id' => 'delicious', |
|
| 139 | - 'icon' => 'fa-delicious', |
|
| 140 | - 'class' => 'fa', |
|
| 141 | - 'enabled' => false, |
|
| 142 | - 'name' => esc_html__( 'Delicious', 'redux-framework' ), |
|
| 143 | - 'background' => '', |
|
| 144 | - 'color' => '#3399ff', |
|
| 145 | - 'url' => '', |
|
| 146 | - 'order' => 10, |
|
| 147 | - ), |
|
| 148 | - 11 => array( |
|
| 149 | - 'id' => 'deviantart', |
|
| 150 | - 'icon' => 'fa-deviantart', |
|
| 151 | - 'class' => 'fa', |
|
| 152 | - 'enabled' => false, |
|
| 153 | - 'name' => esc_html__( 'Deviantart', 'redux-framework' ), |
|
| 154 | - 'background' => '', |
|
| 155 | - 'color' => '#4e6252', |
|
| 156 | - 'url' => '', |
|
| 157 | - 'order' => 11, |
|
| 158 | - ), |
|
| 159 | - 12 => array( |
|
| 160 | - 'id' => 'digg', |
|
| 161 | - 'icon' => 'fa-digg', |
|
| 162 | - 'class' => 'fa', |
|
| 163 | - 'enabled' => false, |
|
| 164 | - 'name' => esc_html__( 'Digg', 'redux-framework' ), |
|
| 165 | - 'background' => '', |
|
| 166 | - 'color' => '#000000', |
|
| 167 | - 'url' => '', |
|
| 168 | - 'order' => 12, |
|
| 169 | - ), |
|
| 170 | - 13 => array( |
|
| 171 | - 'id' => 'dribbble', |
|
| 172 | - 'icon' => 'fa-dribbble', |
|
| 173 | - 'class' => 'fa', |
|
| 174 | - 'enabled' => false, |
|
| 175 | - 'name' => esc_html__( 'Dribbble', 'redux-framework' ), |
|
| 176 | - 'background' => '', |
|
| 177 | - 'color' => '#444444', |
|
| 178 | - 'url' => '', |
|
| 179 | - 'order' => 13, |
|
| 180 | - ), |
|
| 181 | - 14 => array( |
|
| 182 | - 'id' => 'dropbox', |
|
| 183 | - 'icon' => 'fa-dropbox', |
|
| 184 | - 'class' => 'fa', |
|
| 185 | - 'enabled' => false, |
|
| 186 | - 'name' => esc_html__( 'Dropbox', 'redux-framework' ), |
|
| 187 | - 'background' => '', |
|
| 188 | - 'color' => '#007ee5', |
|
| 189 | - 'url' => '', |
|
| 190 | - 'order' => 14, |
|
| 191 | - ), |
|
| 192 | - 15 => array( |
|
| 193 | - 'id' => 'drupal', |
|
| 194 | - 'icon' => 'fa-drupal', |
|
| 195 | - 'class' => 'fa', |
|
| 196 | - 'enabled' => false, |
|
| 197 | - 'name' => esc_html__( 'Drupal', 'redux-framework' ), |
|
| 198 | - 'background' => '', |
|
| 199 | - 'color' => '#0077c0', |
|
| 200 | - 'url' => '', |
|
| 201 | - 'order' => 15, |
|
| 202 | - ), |
|
| 203 | - 16 => array( |
|
| 204 | - 'id' => 'empire', |
|
| 205 | - 'icon' => 'fa-empire', |
|
| 206 | - 'class' => 'fa', |
|
| 207 | - 'enabled' => false, |
|
| 208 | - 'name' => esc_html__( 'Empire', 'redux-framework' ), |
|
| 209 | - 'background' => '', |
|
| 210 | - 'color' => '#000000', |
|
| 211 | - 'url' => '', |
|
| 212 | - 'order' => 16, |
|
| 213 | - ), |
|
| 214 | - 17 => array( |
|
| 215 | - 'id' => 'facebook', |
|
| 216 | - 'icon' => 'fa-facebook', |
|
| 217 | - 'class' => 'fa', |
|
| 218 | - 'enabled' => false, |
|
| 219 | - 'name' => esc_html__( 'Facebook', 'redux-framework' ), |
|
| 220 | - 'background' => '', |
|
| 221 | - 'color' => '#3b5998', |
|
| 222 | - 'url' => '', |
|
| 223 | - 'order' => 17, |
|
| 224 | - ), |
|
| 225 | - 18 => array( |
|
| 226 | - 'id' => 'facebook-square', |
|
| 227 | - 'icon' => 'fa-facebook-square', |
|
| 228 | - 'class' => 'fa', |
|
| 229 | - 'enabled' => false, |
|
| 230 | - 'name' => esc_html__( 'Facebook square', 'redux-framework' ), |
|
| 231 | - 'background' => '', |
|
| 232 | - 'color' => '#3b5998', |
|
| 233 | - 'url' => '', |
|
| 234 | - 'order' => 18, |
|
| 235 | - ), |
|
| 236 | - 19 => array( |
|
| 237 | - 'id' => 'flickr', |
|
| 238 | - 'icon' => 'fa-flickr', |
|
| 239 | - 'class' => 'fa', |
|
| 240 | - 'enabled' => false, |
|
| 241 | - 'name' => esc_html__( 'Flickr', 'redux-framework' ), |
|
| 242 | - 'background' => '', |
|
| 243 | - 'color' => '#0063dc', |
|
| 244 | - 'url' => '', |
|
| 245 | - 'order' => 19, |
|
| 246 | - ), |
|
| 247 | - 20 => array( |
|
| 248 | - 'id' => 'foursquare', |
|
| 249 | - 'icon' => 'fa-foursquare', |
|
| 250 | - 'class' => 'fa', |
|
| 251 | - 'enabled' => false, |
|
| 252 | - 'name' => esc_html__( 'FourSquare', 'redux-framework' ), |
|
| 253 | - 'background' => '', |
|
| 254 | - 'color' => '#0072b1', |
|
| 255 | - 'url' => '', |
|
| 256 | - 'order' => 20, |
|
| 257 | - ), |
|
| 258 | - 21 => array( |
|
| 259 | - 'id' => 'git', |
|
| 260 | - 'icon' => 'fa-git', |
|
| 261 | - 'class' => 'fa', |
|
| 262 | - 'enabled' => false, |
|
| 263 | - 'name' => esc_html__( 'git', 'redux-framework' ), |
|
| 264 | - 'background' => '', |
|
| 265 | - 'color' => '#000000', |
|
| 266 | - 'url' => '', |
|
| 267 | - 'order' => 21, |
|
| 268 | - ), |
|
| 269 | - 22 => array( |
|
| 270 | - 'id' => 'git-square', |
|
| 271 | - 'icon' => 'fa-git-square', |
|
| 272 | - 'class' => 'fa', |
|
| 273 | - 'enabled' => false, |
|
| 274 | - 'name' => esc_html__( 'git square', 'redux-framework' ), |
|
| 275 | - 'background' => '', |
|
| 276 | - 'color' => '#000000', |
|
| 277 | - 'url' => '', |
|
| 278 | - 'order' => 22, |
|
| 279 | - ), |
|
| 280 | - 23 => array( |
|
| 281 | - 'id' => 'github', |
|
| 282 | - 'icon' => 'fa-github', |
|
| 283 | - 'class' => 'fa', |
|
| 284 | - 'enabled' => false, |
|
| 285 | - 'name' => esc_html__( 'github', 'redux-framework' ), |
|
| 286 | - 'background' => '', |
|
| 287 | - 'color' => '#4183c4', |
|
| 288 | - 'url' => '', |
|
| 289 | - 'order' => 23, |
|
| 290 | - ), |
|
| 291 | - 24 => array( |
|
| 292 | - 'id' => 'github-alt', |
|
| 293 | - 'icon' => 'fa-github-alt', |
|
| 294 | - 'class' => 'fa', |
|
| 295 | - 'enabled' => false, |
|
| 296 | - 'name' => esc_html__( 'github alt', 'redux-framework' ), |
|
| 297 | - 'background' => '', |
|
| 298 | - 'color' => '#4183c4', |
|
| 299 | - 'url' => '', |
|
| 300 | - 'order' => 24, |
|
| 301 | - ), |
|
| 302 | - 25 => array( |
|
| 303 | - 'id' => 'github-square', |
|
| 304 | - 'icon' => 'fa-github-square', |
|
| 305 | - 'class' => 'fa', |
|
| 306 | - 'enabled' => false, |
|
| 307 | - 'name' => esc_html__( 'github square', 'redux-framework' ), |
|
| 308 | - 'background' => '', |
|
| 309 | - 'color' => '#4183c4', |
|
| 310 | - 'url' => '', |
|
| 311 | - 'order' => 25, |
|
| 312 | - ), |
|
| 313 | - 26 => array( |
|
| 314 | - 'id' => 'gittip', |
|
| 315 | - 'icon' => 'fa-gittip', |
|
| 316 | - 'class' => 'fa', |
|
| 317 | - 'enabled' => false, |
|
| 318 | - 'name' => esc_html__( 'git tip', 'redux-framework' ), |
|
| 319 | - 'background' => '', |
|
| 320 | - 'color' => '#000000', |
|
| 321 | - 'url' => '', |
|
| 322 | - 'order' => 26, |
|
| 323 | - ), |
|
| 324 | - 27 => array( |
|
| 325 | - 'id' => 'google', |
|
| 326 | - 'icon' => 'fa-google', |
|
| 327 | - 'class' => 'fa', |
|
| 328 | - 'enabled' => false, |
|
| 329 | - 'name' => esc_html__( 'Google', 'redux-framework' ), |
|
| 330 | - 'background' => '', |
|
| 331 | - 'color' => '#dd4b39', |
|
| 332 | - 'url' => '', |
|
| 333 | - 'order' => 27, |
|
| 334 | - ), |
|
| 335 | - 28 => array( |
|
| 336 | - 'id' => 'google-plus', |
|
| 337 | - 'icon' => 'fa-google-plus', |
|
| 338 | - 'class' => 'fa', |
|
| 339 | - 'enabled' => false, |
|
| 340 | - 'name' => esc_html__( 'Google Plus', 'redux-framework' ), |
|
| 341 | - 'background' => '', |
|
| 342 | - 'color' => '#dd4b39', |
|
| 343 | - 'url' => '', |
|
| 344 | - 'order' => 28, |
|
| 345 | - ), |
|
| 346 | - 29 => array( |
|
| 347 | - 'id' => 'google-plus-square', |
|
| 348 | - 'icon' => 'fa-google-plus-square', |
|
| 349 | - 'class' => 'fa', |
|
| 350 | - 'enabled' => false, |
|
| 351 | - 'name' => esc_html__( 'Google Plus square', 'redux-framework' ), |
|
| 352 | - 'background' => '', |
|
| 353 | - 'color' => '#dd4b39', |
|
| 354 | - 'url' => '', |
|
| 355 | - 'order' => 29, |
|
| 356 | - ), |
|
| 357 | - 30 => array( |
|
| 358 | - 'id' => 'hacker-news', |
|
| 359 | - 'icon' => 'fa-hacker-news', |
|
| 360 | - 'class' => 'fa', |
|
| 361 | - 'enabled' => false, |
|
| 362 | - 'name' => esc_html__( 'Hacker News', 'redux-framework' ), |
|
| 363 | - 'background' => '', |
|
| 364 | - 'color' => '#ff6600', |
|
| 365 | - 'url' => '', |
|
| 366 | - 'order' => 30, |
|
| 367 | - ), |
|
| 368 | - 31 => array( |
|
| 369 | - 'id' => 'html5', |
|
| 370 | - 'icon' => 'fa-html5', |
|
| 371 | - 'class' => 'fa', |
|
| 372 | - 'enabled' => false, |
|
| 373 | - 'name' => esc_html__( 'HTML5', 'redux-framework' ), |
|
| 374 | - 'background' => '', |
|
| 375 | - 'color' => '#e34f26', |
|
| 376 | - 'url' => '', |
|
| 377 | - 'order' => 31, |
|
| 378 | - ), |
|
| 379 | - 32 => array( |
|
| 380 | - 'id' => 'instagram', |
|
| 381 | - 'icon' => 'fa-instagram', |
|
| 382 | - 'class' => 'fa', |
|
| 383 | - 'enabled' => false, |
|
| 384 | - 'name' => esc_html__( 'Instagram', 'redux-framework' ), |
|
| 385 | - 'background' => '', |
|
| 386 | - 'color' => '#3f729b', |
|
| 387 | - 'url' => '', |
|
| 388 | - 'order' => 32, |
|
| 389 | - ), |
|
| 390 | - 33 => array( |
|
| 391 | - 'id' => 'joomla', |
|
| 392 | - 'icon' => 'fa-joomla', |
|
| 393 | - 'class' => 'fa', |
|
| 394 | - 'enabled' => false, |
|
| 395 | - 'name' => esc_html__( 'Joomla', 'redux-framework' ), |
|
| 396 | - 'background' => '', |
|
| 397 | - 'color' => '#000000', |
|
| 398 | - 'url' => '', |
|
| 399 | - 'order' => 33, |
|
| 400 | - ), |
|
| 401 | - 34 => array( |
|
| 402 | - 'id' => 'jsfiddle', |
|
| 403 | - 'icon' => 'fa-jsfiddle', |
|
| 404 | - 'class' => 'fa', |
|
| 405 | - 'enabled' => false, |
|
| 406 | - 'name' => esc_html__( 'JS Fiddle', 'redux-framework' ), |
|
| 407 | - 'background' => '', |
|
| 408 | - 'color' => '#000000', |
|
| 409 | - 'url' => '', |
|
| 410 | - 'order' => 34, |
|
| 411 | - ), |
|
| 412 | - 35 => array( |
|
| 413 | - 'id' => 'linkedin', |
|
| 414 | - 'icon' => 'fa-linkedin', |
|
| 415 | - 'class' => 'fa', |
|
| 416 | - 'enabled' => false, |
|
| 417 | - 'name' => esc_html__( 'LinkedIn', 'redux-framework' ), |
|
| 418 | - 'background' => '', |
|
| 419 | - 'color' => '#0976b4', |
|
| 420 | - 'url' => '', |
|
| 421 | - 'order' => 35, |
|
| 422 | - ), |
|
| 423 | - 36 => array( |
|
| 424 | - 'id' => 'linkedin-square', |
|
| 425 | - 'icon' => 'fa-linkedin-square', |
|
| 426 | - 'class' => 'fa', |
|
| 427 | - 'enabled' => false, |
|
| 428 | - 'name' => esc_html__( 'LinkedIn square', 'redux-framework' ), |
|
| 429 | - 'background' => '', |
|
| 430 | - 'color' => '#0976b4', |
|
| 431 | - 'url' => '', |
|
| 432 | - 'order' => 36, |
|
| 433 | - ), |
|
| 434 | - 37 => array( |
|
| 435 | - 'id' => 'linux', |
|
| 436 | - 'icon' => 'fa-linux', |
|
| 437 | - 'class' => 'fa', |
|
| 438 | - 'enabled' => false, |
|
| 439 | - 'name' => esc_html__( 'Linux', 'redux-framework' ), |
|
| 440 | - 'background' => '', |
|
| 441 | - 'color' => '#333333', |
|
| 442 | - 'url' => '', |
|
| 443 | - 'order' => 37, |
|
| 444 | - ), |
|
| 445 | - 38 => array( |
|
| 446 | - 'id' => 'maxcdn', |
|
| 447 | - 'icon' => 'fa-maxcdn', |
|
| 448 | - 'class' => 'fa', |
|
| 449 | - 'enabled' => false, |
|
| 450 | - 'name' => esc_html__( 'MaxCDN', 'redux-framework' ), |
|
| 451 | - 'background' => '', |
|
| 452 | - 'color' => '#f8711e', |
|
| 453 | - 'url' => '', |
|
| 454 | - 'order' => 38, |
|
| 455 | - ), |
|
| 456 | - 39 => array( |
|
| 457 | - 'id' => 'openid', |
|
| 458 | - 'icon' => 'fa-openid', |
|
| 459 | - 'class' => 'fa', |
|
| 460 | - 'enabled' => false, |
|
| 461 | - 'name' => esc_html__( 'OpenID', 'redux-framework' ), |
|
| 462 | - 'background' => '', |
|
| 463 | - 'color' => '#000000', |
|
| 464 | - 'url' => '', |
|
| 465 | - 'order' => 39, |
|
| 466 | - ), |
|
| 467 | - 40 => array( |
|
| 468 | - 'id' => 'pagelines', |
|
| 469 | - 'icon' => 'fa-pagelines', |
|
| 470 | - 'class' => 'fa', |
|
| 471 | - 'enabled' => false, |
|
| 472 | - 'name' => esc_html__( 'Page Lines', 'redux-framework' ), |
|
| 473 | - 'background' => '', |
|
| 474 | - 'color' => '#000000', |
|
| 475 | - 'url' => '', |
|
| 476 | - 'order' => 40, |
|
| 477 | - ), |
|
| 478 | - 41 => array( |
|
| 479 | - 'id' => 'pied-piper', |
|
| 480 | - 'icon' => 'fa-pied-piper', |
|
| 481 | - 'class' => 'fa', |
|
| 482 | - 'enabled' => false, |
|
| 483 | - 'name' => esc_html__( 'Pied Piper', 'redux-framework' ), |
|
| 484 | - 'background' => '', |
|
| 485 | - 'color' => '#000000', |
|
| 486 | - 'url' => '', |
|
| 487 | - 'order' => 41, |
|
| 488 | - ), |
|
| 489 | - 42 => array( |
|
| 490 | - 'id' => 'pied-piper-alt', |
|
| 491 | - 'icon' => 'fa-pied-piper-alt', |
|
| 492 | - 'class' => 'fa', |
|
| 493 | - 'enabled' => false, |
|
| 494 | - 'name' => esc_html__( 'Pied Piper alt', 'redux-framework' ), |
|
| 495 | - 'background' => '', |
|
| 496 | - 'color' => '#000000', |
|
| 497 | - 'url' => '', |
|
| 498 | - 'order' => 42, |
|
| 499 | - ), |
|
| 500 | - 43 => array( |
|
| 501 | - 'id' => 'pinterest', |
|
| 502 | - 'icon' => 'fa-pinterest', |
|
| 503 | - 'class' => 'fa', |
|
| 504 | - 'enabled' => false, |
|
| 505 | - 'name' => esc_html__( 'Pinterest', 'redux-framework' ), |
|
| 506 | - 'background' => '', |
|
| 507 | - 'color' => '#1769ff', |
|
| 508 | - 'url' => '', |
|
| 509 | - 'order' => 43, |
|
| 510 | - ), |
|
| 511 | - 44 => array( |
|
| 512 | - 'id' => 'pinterest-square', |
|
| 513 | - 'icon' => 'fa-pinterest-square', |
|
| 514 | - 'class' => 'fa', |
|
| 515 | - 'enabled' => false, |
|
| 516 | - 'name' => esc_html__( 'Pinterest square', 'redux-framework' ), |
|
| 517 | - 'background' => '', |
|
| 518 | - 'color' => '#1769ff', |
|
| 519 | - 'url' => '', |
|
| 520 | - 'order' => 44, |
|
| 521 | - ), |
|
| 522 | - 45 => array( |
|
| 523 | - 'id' => 'qq', |
|
| 524 | - 'icon' => 'fa-qq', |
|
| 525 | - 'class' => 'fa', |
|
| 526 | - 'enabled' => false, |
|
| 527 | - 'name' => esc_html__( 'QQ', 'redux-framework' ), |
|
| 528 | - 'background' => '', |
|
| 529 | - 'color' => '#000000', |
|
| 530 | - 'url' => '', |
|
| 531 | - 'order' => 45, |
|
| 532 | - ), |
|
| 533 | - 46 => array( |
|
| 534 | - 'id' => 'rebel', |
|
| 535 | - 'icon' => 'fa-rebel', |
|
| 536 | - 'class' => 'fa', |
|
| 537 | - 'enabled' => false, |
|
| 538 | - 'name' => esc_html__( 'Rebel', 'redux-framework' ), |
|
| 539 | - 'background' => '', |
|
| 540 | - 'color' => '#517fa4', |
|
| 541 | - 'url' => '', |
|
| 542 | - 'order' => 46, |
|
| 543 | - ), |
|
| 544 | - 47 => array( |
|
| 545 | - 'id' => 'reddit', |
|
| 546 | - 'icon' => 'fa-reddit', |
|
| 547 | - 'class' => 'fa', |
|
| 548 | - 'enabled' => false, |
|
| 549 | - 'name' => esc_html__( 'Reddit', 'redux-framework' ), |
|
| 550 | - 'background' => '', |
|
| 551 | - 'color' => '#ff4500', |
|
| 552 | - 'url' => '', |
|
| 553 | - 'order' => 47, |
|
| 554 | - ), |
|
| 555 | - 48 => array( |
|
| 556 | - 'id' => 'reddit-square', |
|
| 557 | - 'icon' => 'fa-reddit-square', |
|
| 558 | - 'class' => 'fa', |
|
| 559 | - 'enabled' => false, |
|
| 560 | - 'name' => esc_html__( 'Reddit square', 'redux-framework' ), |
|
| 561 | - 'background' => '', |
|
| 562 | - 'color' => '#ff4500', |
|
| 563 | - 'url' => '', |
|
| 564 | - 'order' => 48, |
|
| 565 | - ), |
|
| 566 | - 49 => array( |
|
| 567 | - 'id' => 'renren', |
|
| 568 | - 'icon' => 'fa-renren', |
|
| 569 | - 'class' => 'fa', |
|
| 570 | - 'enabled' => false, |
|
| 571 | - 'name' => esc_html__( 'Ren Ren', 'redux-framework' ), |
|
| 572 | - 'background' => '', |
|
| 573 | - 'color' => '#007bb6', |
|
| 574 | - 'url' => '', |
|
| 575 | - 'order' => 49, |
|
| 576 | - ), |
|
| 577 | - 50 => array( |
|
| 578 | - 'id' => 'share-alt', |
|
| 579 | - 'icon' => 'fa-share-alt', |
|
| 580 | - 'class' => 'fa', |
|
| 581 | - 'enabled' => false, |
|
| 582 | - 'name' => esc_html__( 'Share alt', 'redux-framework' ), |
|
| 583 | - 'background' => '', |
|
| 584 | - 'color' => '#000000', |
|
| 585 | - 'url' => '', |
|
| 586 | - 'order' => 50, |
|
| 587 | - ), |
|
| 588 | - 51 => array( |
|
| 589 | - 'id' => 'share-alt-square', |
|
| 590 | - 'icon' => 'fa-share-alt-square', |
|
| 591 | - 'class' => 'fa', |
|
| 592 | - 'enabled' => false, |
|
| 593 | - 'name' => esc_html__( 'Share square', 'redux-framework' ), |
|
| 594 | - 'background' => '', |
|
| 595 | - 'color' => '#000000', |
|
| 596 | - 'url' => '', |
|
| 597 | - 'order' => 51, |
|
| 598 | - ), |
|
| 599 | - 52 => array( |
|
| 600 | - 'id' => 'skype', |
|
| 601 | - 'icon' => 'fa-skype', |
|
| 602 | - 'class' => 'fa', |
|
| 603 | - 'enabled' => false, |
|
| 604 | - 'name' => esc_html__( 'Skype', 'redux-framework' ), |
|
| 605 | - 'background' => '', |
|
| 606 | - 'color' => '#00aff0', |
|
| 607 | - 'url' => '', |
|
| 608 | - 'order' => 52, |
|
| 609 | - ), |
|
| 610 | - 53 => array( |
|
| 611 | - 'id' => 'slack', |
|
| 612 | - 'icon' => 'fa-slack', |
|
| 613 | - 'class' => 'fa', |
|
| 614 | - 'enabled' => false, |
|
| 615 | - 'name' => esc_html__( 'Slack', 'redux-framework' ), |
|
| 616 | - 'background' => '', |
|
| 617 | - 'color' => '#000000', |
|
| 618 | - 'url' => '', |
|
| 619 | - 'order' => 53, |
|
| 620 | - ), |
|
| 621 | - 54 => array( |
|
| 622 | - 'id' => 'soundcloud', |
|
| 623 | - 'icon' => 'fa-soundcloud', |
|
| 624 | - 'class' => 'fa', |
|
| 625 | - 'enabled' => false, |
|
| 626 | - 'name' => esc_html__( 'Sound Cloud', 'redux-framework' ), |
|
| 627 | - 'background' => '', |
|
| 628 | - 'color' => '#f80', |
|
| 629 | - 'url' => '', |
|
| 630 | - 'order' => 54, |
|
| 631 | - ), |
|
| 632 | - 55 => array( |
|
| 633 | - 'id' => 'spotify', |
|
| 634 | - 'icon' => 'fa-spotify', |
|
| 635 | - 'class' => 'fa', |
|
| 636 | - 'enabled' => false, |
|
| 637 | - 'name' => esc_html__( 'Spotify', 'redux-framework' ), |
|
| 638 | - 'background' => '', |
|
| 639 | - 'color' => '#7ab800', |
|
| 640 | - 'url' => '', |
|
| 641 | - 'order' => 55, |
|
| 642 | - ), |
|
| 643 | - 56 => array( |
|
| 644 | - 'id' => 'stack-exchange', |
|
| 645 | - 'icon' => 'fa-stack-exchange', |
|
| 646 | - 'class' => 'fa', |
|
| 647 | - 'enabled' => false, |
|
| 648 | - 'name' => esc_html__( 'Stack Exchange', 'redux-framework' ), |
|
| 649 | - 'background' => '', |
|
| 650 | - 'color' => '#000000', |
|
| 651 | - 'url' => '', |
|
| 652 | - 'order' => 56, |
|
| 653 | - ), |
|
| 654 | - 57 => array( |
|
| 655 | - 'id' => 'stack-overflow', |
|
| 656 | - 'icon' => 'fa-stack-overflow', |
|
| 657 | - 'class' => 'fa', |
|
| 658 | - 'enabled' => false, |
|
| 659 | - 'name' => esc_html__( 'Stack Overflow', 'redux-framework' ), |
|
| 660 | - 'background' => '', |
|
| 661 | - 'color' => '#fe7a15', |
|
| 662 | - 'url' => '', |
|
| 663 | - 'order' => 57, |
|
| 664 | - ), |
|
| 665 | - 58 => array( |
|
| 666 | - 'id' => 'steam', |
|
| 667 | - 'icon' => 'fa-steam', |
|
| 668 | - 'class' => 'fa', |
|
| 669 | - 'enabled' => false, |
|
| 670 | - 'name' => esc_html__( 'Steam', 'redux-framework' ), |
|
| 671 | - 'background' => '', |
|
| 672 | - 'color' => '#000000', |
|
| 673 | - 'url' => '', |
|
| 674 | - 'order' => 58, |
|
| 675 | - ), |
|
| 676 | - 59 => array( |
|
| 677 | - 'id' => 'steam-square', |
|
| 678 | - 'icon' => 'fa-steam-square', |
|
| 679 | - 'class' => 'fa', |
|
| 680 | - 'enabled' => false, |
|
| 681 | - 'name' => esc_html__( 'Steam square', 'redux-framework' ), |
|
| 682 | - 'background' => '', |
|
| 683 | - 'color' => '#000000', |
|
| 684 | - 'url' => '', |
|
| 685 | - 'order' => 59, |
|
| 686 | - ), |
|
| 687 | - 60 => array( |
|
| 688 | - 'id' => 'stumbleupon', |
|
| 689 | - 'icon' => 'fa-stumbleupon', |
|
| 690 | - 'class' => 'fa', |
|
| 691 | - 'enabled' => false, |
|
| 692 | - 'name' => esc_html__( 'Stumble Upon', 'redux-framework' ), |
|
| 693 | - 'background' => '', |
|
| 694 | - 'color' => '#eb4924', |
|
| 695 | - 'url' => '', |
|
| 696 | - 'order' => 60, |
|
| 697 | - ), |
|
| 698 | - 61 => array( |
|
| 699 | - 'id' => 'stumbleupon-circle', |
|
| 700 | - 'icon' => 'fa-stumbleupon-circle', |
|
| 701 | - 'class' => 'fa', |
|
| 702 | - 'enabled' => false, |
|
| 703 | - 'name' => esc_html__( 'Stumble Upon circle', 'redux-framework' ), |
|
| 704 | - 'background' => '', |
|
| 705 | - 'color' => '#eb4924', |
|
| 706 | - 'url' => '', |
|
| 707 | - 'order' => 61, |
|
| 708 | - ), |
|
| 709 | - 62 => array( |
|
| 710 | - 'id' => 'tencent-weibo', |
|
| 711 | - 'icon' => 'fa-tencent-weibo', |
|
| 712 | - 'class' => 'fa', |
|
| 713 | - 'enabled' => false, |
|
| 714 | - 'name' => esc_html__( 'Tencent Weibo', 'redux-framework' ), |
|
| 715 | - 'background' => '', |
|
| 716 | - 'color' => '#000000', |
|
| 717 | - 'url' => '', |
|
| 718 | - 'order' => 62, |
|
| 719 | - ), |
|
| 720 | - 63 => array( |
|
| 721 | - 'id' => 'trello', |
|
| 722 | - 'icon' => 'fa-trello', |
|
| 723 | - 'class' => 'fa', |
|
| 724 | - 'enabled' => false, |
|
| 725 | - 'name' => esc_html__( 'Trello', 'redux-framework' ), |
|
| 726 | - 'background' => '', |
|
| 727 | - 'color' => '#256a92', |
|
| 728 | - 'url' => '', |
|
| 729 | - 'order' => 63, |
|
| 730 | - ), |
|
| 731 | - 64 => array( |
|
| 732 | - 'id' => 'tumblr', |
|
| 733 | - 'icon' => 'fa-tumblr', |
|
| 734 | - 'class' => 'fa', |
|
| 735 | - 'enabled' => false, |
|
| 736 | - 'name' => esc_html__( 'Tumblr', 'redux-framework' ), |
|
| 737 | - 'background' => '', |
|
| 738 | - 'color' => '#35465c', |
|
| 739 | - 'url' => '', |
|
| 740 | - 'order' => 64, |
|
| 741 | - ), |
|
| 742 | - 65 => array( |
|
| 743 | - 'id' => 'tumblr-square', |
|
| 744 | - 'icon' => 'fa-tumblr-square', |
|
| 745 | - 'class' => 'fa', |
|
| 746 | - 'enabled' => false, |
|
| 747 | - 'name' => esc_html__( 'Tumblr square', 'redux-framework' ), |
|
| 748 | - 'background' => '', |
|
| 749 | - 'color' => '#35465c', |
|
| 750 | - 'url' => '', |
|
| 751 | - 'order' => 65, |
|
| 752 | - ), |
|
| 753 | - 66 => array( |
|
| 754 | - 'id' => 'twitter', |
|
| 755 | - 'icon' => 'fa-x-twitter', |
|
| 756 | - 'class' => 'fa-brands', |
|
| 757 | - 'enabled' => false, |
|
| 758 | - 'name' => esc_html__( 'X', 'redux-framework' ), |
|
| 759 | - 'background' => '', |
|
| 760 | - 'color' => '#55acee', |
|
| 761 | - 'url' => '', |
|
| 762 | - 'order' => 66, |
|
| 763 | - ), |
|
| 764 | - 67 => array( |
|
| 765 | - 'id' => 'twitter-square', |
|
| 766 | - 'icon' => 'fa-square-x-twitter', |
|
| 767 | - 'class' => 'fa-brands', |
|
| 768 | - 'enabled' => false, |
|
| 769 | - 'name' => esc_html__( 'X square', 'redux-framework' ), |
|
| 770 | - 'background' => '', |
|
| 771 | - 'color' => '#55acee', |
|
| 772 | - 'url' => '', |
|
| 773 | - 'order' => 67, |
|
| 774 | - ), |
|
| 775 | - 68 => array( |
|
| 776 | - 'id' => 'vimeo-square', |
|
| 777 | - 'icon' => 'fa-vimeo-square', |
|
| 778 | - 'class' => 'fa', |
|
| 779 | - 'enabled' => false, |
|
| 780 | - 'name' => esc_html__( 'Vimeo square', 'redux-framework' ), |
|
| 781 | - 'background' => '', |
|
| 782 | - 'color' => '#1ab7ea', |
|
| 783 | - 'url' => '', |
|
| 784 | - 'order' => 68, |
|
| 785 | - ), |
|
| 786 | - 69 => array( |
|
| 787 | - 'id' => 'vine', |
|
| 788 | - 'icon' => 'fa-vine', |
|
| 789 | - 'class' => 'fa', |
|
| 790 | - 'enabled' => false, |
|
| 791 | - 'name' => esc_html__( 'Vine', 'redux-framework' ), |
|
| 792 | - 'background' => '', |
|
| 793 | - 'color' => '#00b488', |
|
| 794 | - 'url' => '', |
|
| 795 | - 'order' => 69, |
|
| 796 | - ), |
|
| 797 | - 70 => array( |
|
| 798 | - 'id' => 'vk', |
|
| 799 | - 'icon' => 'fa-vk', |
|
| 800 | - 'class' => 'fa', |
|
| 801 | - 'enabled' => false, |
|
| 802 | - 'name' => esc_html__( 'VK', 'redux-framework' ), |
|
| 803 | - 'background' => '', |
|
| 804 | - 'color' => '#000000', |
|
| 805 | - 'url' => '', |
|
| 806 | - 'order' => 70, |
|
| 807 | - ), |
|
| 808 | - 71 => array( |
|
| 809 | - 'id' => 'weibo', |
|
| 810 | - 'icon' => 'fa-weibo', |
|
| 811 | - 'class' => 'fa', |
|
| 812 | - 'enabled' => false, |
|
| 813 | - 'name' => esc_html__( 'Weibo', 'redux-framework' ), |
|
| 814 | - 'background' => '', |
|
| 815 | - 'color' => '#000000', |
|
| 816 | - 'url' => '', |
|
| 817 | - 'order' => 71, |
|
| 818 | - ), |
|
| 819 | - 72 => array( |
|
| 820 | - 'id' => 'weixin', |
|
| 821 | - 'icon' => 'fa-weixin', |
|
| 822 | - 'class' => 'fa', |
|
| 823 | - 'enabled' => false, |
|
| 824 | - 'name' => esc_html__( 'Weixin', 'redux-framework' ), |
|
| 825 | - 'background' => '', |
|
| 826 | - 'color' => '#000000', |
|
| 827 | - 'url' => '', |
|
| 828 | - 'order' => 72, |
|
| 829 | - ), |
|
| 830 | - 73 => array( |
|
| 831 | - 'id' => 'windows', |
|
| 832 | - 'icon' => 'fa-windows', |
|
| 833 | - 'class' => 'fa', |
|
| 834 | - 'enabled' => false, |
|
| 835 | - 'name' => esc_html__( 'Windows', 'redux-framework' ), |
|
| 836 | - 'background' => '', |
|
| 837 | - 'color' => '#00bcf2', |
|
| 838 | - 'url' => '', |
|
| 839 | - 'order' => 73, |
|
| 840 | - ), |
|
| 841 | - 74 => array( |
|
| 842 | - 'id' => 'wordpress', |
|
| 843 | - 'icon' => 'fa-wordpress', |
|
| 844 | - 'class' => 'fa', |
|
| 845 | - 'enabled' => false, |
|
| 846 | - 'name' => esc_html__( 'WordPress', 'redux-framework' ), |
|
| 847 | - 'background' => '', |
|
| 848 | - 'color' => '#21759b', |
|
| 849 | - 'url' => '', |
|
| 850 | - 'order' => 74, |
|
| 851 | - ), |
|
| 852 | - 75 => array( |
|
| 853 | - 'id' => 'xing', |
|
| 854 | - 'icon' => 'fa-xing', |
|
| 855 | - 'class' => 'fa', |
|
| 856 | - 'enabled' => false, |
|
| 857 | - 'name' => esc_html__( 'Xing', 'redux-framework' ), |
|
| 858 | - 'background' => '', |
|
| 859 | - 'color' => '#026466', |
|
| 860 | - 'url' => '', |
|
| 861 | - 'order' => 75, |
|
| 862 | - ), |
|
| 863 | - 76 => array( |
|
| 864 | - 'id' => 'xing-square', |
|
| 865 | - 'icon' => 'fa-xing-square', |
|
| 866 | - 'class' => 'fa', |
|
| 867 | - 'enabled' => false, |
|
| 868 | - 'name' => esc_html__( 'Xing square', 'redux-framework' ), |
|
| 869 | - 'background' => '', |
|
| 870 | - 'color' => '#026466', |
|
| 871 | - 'url' => '', |
|
| 872 | - 'order' => 76, |
|
| 873 | - ), |
|
| 874 | - 77 => array( |
|
| 875 | - 'id' => 'yahoo', |
|
| 876 | - 'icon' => 'fa-yahoo', |
|
| 877 | - 'class' => 'fa', |
|
| 878 | - 'enabled' => false, |
|
| 879 | - 'name' => esc_html__( 'Yahoo', 'redux-framework' ), |
|
| 880 | - 'background' => '', |
|
| 881 | - 'color' => '#400191', |
|
| 882 | - 'url' => '', |
|
| 883 | - 'order' => 77, |
|
| 884 | - ), |
|
| 885 | - 78 => array( |
|
| 886 | - 'id' => 'yelp', |
|
| 887 | - 'icon' => 'fa-yelp', |
|
| 888 | - 'class' => 'fa', |
|
| 889 | - 'enabled' => false, |
|
| 890 | - 'name' => esc_html__( 'Yelp', 'redux-framework' ), |
|
| 891 | - 'background' => '', |
|
| 892 | - 'color' => '#C93C27', |
|
| 893 | - 'url' => '', |
|
| 894 | - 'order' => 78, |
|
| 895 | - ), |
|
| 896 | - 79 => array( |
|
| 897 | - 'id' => 'youtube', |
|
| 898 | - 'icon' => 'fa-youtube', |
|
| 899 | - 'class' => 'fa', |
|
| 900 | - 'enabled' => false, |
|
| 901 | - 'name' => esc_html__( 'YouTube', 'redux-framework' ), |
|
| 902 | - 'background' => '', |
|
| 903 | - 'color' => '#e52d27', |
|
| 904 | - 'url' => '', |
|
| 905 | - 'order' => 79, |
|
| 906 | - ), |
|
| 907 | - 80 => array( |
|
| 908 | - 'id' => 'youtube-play', |
|
| 909 | - 'icon' => 'fa-youtube-play', |
|
| 910 | - 'class' => 'fa', |
|
| 911 | - 'enabled' => false, |
|
| 912 | - 'name' => esc_html__( 'YouTube play', 'redux-framework' ), |
|
| 913 | - 'background' => '', |
|
| 914 | - 'color' => '#e52d27', |
|
| 915 | - 'url' => '', |
|
| 916 | - 'order' => 80, |
|
| 917 | - ), |
|
| 918 | - 81 => array( |
|
| 919 | - 'id' => 'youtube-square', |
|
| 920 | - 'icon' => 'fa-youtube-square', |
|
| 921 | - 'class' => 'fa', |
|
| 922 | - 'enabled' => false, |
|
| 923 | - 'name' => esc_html__( 'YouTube square', 'redux-framework' ), |
|
| 924 | - 'background' => '', |
|
| 925 | - 'color' => '#e52d27', |
|
| 926 | - 'url' => '', |
|
| 927 | - 'order' => 81, |
|
| 928 | - ), |
|
| 929 | - ); |
|
| 930 | - } |
|
| 931 | - } |
|
| 19 | + /** |
|
| 20 | + * Get defaults array. |
|
| 21 | + * |
|
| 22 | + * @return array |
|
| 23 | + */ |
|
| 24 | + public static function get_social_media_defaults(): array { |
|
| 25 | + return array( |
|
| 26 | + 0 => array( |
|
| 27 | + 'id' => 'adn', |
|
| 28 | + 'icon' => 'fa-adn', |
|
| 29 | + 'class' => 'fa', |
|
| 30 | + 'enabled' => false, |
|
| 31 | + 'name' => esc_html__( 'ADN', 'redux-framework' ), |
|
| 32 | + 'background' => '', |
|
| 33 | + 'color' => '#000000', |
|
| 34 | + 'url' => '', |
|
| 35 | + 'order' => 0, |
|
| 36 | + ), |
|
| 37 | + 1 => array( |
|
| 38 | + 'id' => 'android', |
|
| 39 | + 'icon' => 'fa-android', |
|
| 40 | + 'class' => 'fa', |
|
| 41 | + 'enabled' => false, |
|
| 42 | + 'name' => esc_html__( 'Android', 'redux-framework' ), |
|
| 43 | + 'background' => '', |
|
| 44 | + 'color' => '#A4C639', |
|
| 45 | + 'url' => '', |
|
| 46 | + 'order' => 1, |
|
| 47 | + ), |
|
| 48 | + 2 => array( |
|
| 49 | + 'id' => 'apple', |
|
| 50 | + 'icon' => 'fa-apple', |
|
| 51 | + 'class' => 'fa', |
|
| 52 | + 'enabled' => false, |
|
| 53 | + 'name' => esc_html__( 'Apple', 'redux-framework' ), |
|
| 54 | + 'style' => '', |
|
| 55 | + 'background' => '', |
|
| 56 | + 'color' => '#e4e4e5', |
|
| 57 | + 'url' => '', |
|
| 58 | + 'order' => 2, |
|
| 59 | + ), |
|
| 60 | + 3 => array( |
|
| 61 | + 'id' => 'behance', |
|
| 62 | + 'icon' => 'fa-behance', |
|
| 63 | + 'class' => 'fa', |
|
| 64 | + 'enabled' => false, |
|
| 65 | + 'name' => esc_html__( 'behance', 'redux-framework' ), |
|
| 66 | + 'background' => '', |
|
| 67 | + 'color' => '#1769ff', |
|
| 68 | + 'url' => '', |
|
| 69 | + 'order' => 3, |
|
| 70 | + ), |
|
| 71 | + 4 => array( |
|
| 72 | + 'id' => 'behance-square', |
|
| 73 | + 'icon' => 'fa-behance-square', |
|
| 74 | + 'class' => 'fa', |
|
| 75 | + 'enabled' => false, |
|
| 76 | + 'name' => esc_html__( 'behance square', 'redux-framework' ), |
|
| 77 | + 'background' => '', |
|
| 78 | + 'color' => '#1769ff', |
|
| 79 | + 'url' => '', |
|
| 80 | + 'order' => 4, |
|
| 81 | + ), |
|
| 82 | + 5 => array( |
|
| 83 | + 'id' => 'bitbucket', |
|
| 84 | + 'icon' => 'fa-bitbucket', |
|
| 85 | + 'class' => 'fa', |
|
| 86 | + 'enabled' => false, |
|
| 87 | + 'name' => esc_html__( 'Bitbucket', 'redux-framework' ), |
|
| 88 | + 'background' => '', |
|
| 89 | + 'color' => '#205081', |
|
| 90 | + 'url' => '', |
|
| 91 | + 'order' => 5, |
|
| 92 | + ), |
|
| 93 | + 6 => array( |
|
| 94 | + 'id' => 'bitbucket-square', |
|
| 95 | + 'icon' => 'fa-bitbucket-square', |
|
| 96 | + 'class' => 'fa', |
|
| 97 | + 'enabled' => false, |
|
| 98 | + 'name' => esc_html__( 'Bitbucket square', 'redux-framework' ), |
|
| 99 | + 'background' => '', |
|
| 100 | + 'color' => '#205081', |
|
| 101 | + 'url' => '', |
|
| 102 | + 'order' => 6, |
|
| 103 | + ), |
|
| 104 | + 7 => array( |
|
| 105 | + 'id' => 'bitcoin', |
|
| 106 | + 'icon' => 'fa-btc', |
|
| 107 | + 'class' => 'fa', |
|
| 108 | + 'enabled' => false, |
|
| 109 | + 'name' => esc_html__( 'Bitcoin', 'redux-framework' ), |
|
| 110 | + 'background' => '', |
|
| 111 | + 'color' => '#000000', |
|
| 112 | + 'url' => '', |
|
| 113 | + 'order' => 7, |
|
| 114 | + ), |
|
| 115 | + 8 => array( |
|
| 116 | + 'id' => 'codepen', |
|
| 117 | + 'icon' => 'fa-codepen', |
|
| 118 | + 'class' => 'fa', |
|
| 119 | + 'enabled' => false, |
|
| 120 | + 'name' => esc_html__( 'CodePen', 'redux-framework' ), |
|
| 121 | + 'background' => '', |
|
| 122 | + 'color' => '#000000', |
|
| 123 | + 'url' => '', |
|
| 124 | + 'order' => 8, |
|
| 125 | + ), |
|
| 126 | + 9 => array( |
|
| 127 | + 'id' => 'css3', |
|
| 128 | + 'icon' => 'fa-css3', |
|
| 129 | + 'class' => 'fa', |
|
| 130 | + 'enabled' => false, |
|
| 131 | + 'name' => esc_html__( 'CSS3', 'redux-framework' ), |
|
| 132 | + 'background' => '', |
|
| 133 | + 'color' => '#000000', |
|
| 134 | + 'url' => '', |
|
| 135 | + 'order' => 9, |
|
| 136 | + ), |
|
| 137 | + 10 => array( |
|
| 138 | + 'id' => 'delicious', |
|
| 139 | + 'icon' => 'fa-delicious', |
|
| 140 | + 'class' => 'fa', |
|
| 141 | + 'enabled' => false, |
|
| 142 | + 'name' => esc_html__( 'Delicious', 'redux-framework' ), |
|
| 143 | + 'background' => '', |
|
| 144 | + 'color' => '#3399ff', |
|
| 145 | + 'url' => '', |
|
| 146 | + 'order' => 10, |
|
| 147 | + ), |
|
| 148 | + 11 => array( |
|
| 149 | + 'id' => 'deviantart', |
|
| 150 | + 'icon' => 'fa-deviantart', |
|
| 151 | + 'class' => 'fa', |
|
| 152 | + 'enabled' => false, |
|
| 153 | + 'name' => esc_html__( 'Deviantart', 'redux-framework' ), |
|
| 154 | + 'background' => '', |
|
| 155 | + 'color' => '#4e6252', |
|
| 156 | + 'url' => '', |
|
| 157 | + 'order' => 11, |
|
| 158 | + ), |
|
| 159 | + 12 => array( |
|
| 160 | + 'id' => 'digg', |
|
| 161 | + 'icon' => 'fa-digg', |
|
| 162 | + 'class' => 'fa', |
|
| 163 | + 'enabled' => false, |
|
| 164 | + 'name' => esc_html__( 'Digg', 'redux-framework' ), |
|
| 165 | + 'background' => '', |
|
| 166 | + 'color' => '#000000', |
|
| 167 | + 'url' => '', |
|
| 168 | + 'order' => 12, |
|
| 169 | + ), |
|
| 170 | + 13 => array( |
|
| 171 | + 'id' => 'dribbble', |
|
| 172 | + 'icon' => 'fa-dribbble', |
|
| 173 | + 'class' => 'fa', |
|
| 174 | + 'enabled' => false, |
|
| 175 | + 'name' => esc_html__( 'Dribbble', 'redux-framework' ), |
|
| 176 | + 'background' => '', |
|
| 177 | + 'color' => '#444444', |
|
| 178 | + 'url' => '', |
|
| 179 | + 'order' => 13, |
|
| 180 | + ), |
|
| 181 | + 14 => array( |
|
| 182 | + 'id' => 'dropbox', |
|
| 183 | + 'icon' => 'fa-dropbox', |
|
| 184 | + 'class' => 'fa', |
|
| 185 | + 'enabled' => false, |
|
| 186 | + 'name' => esc_html__( 'Dropbox', 'redux-framework' ), |
|
| 187 | + 'background' => '', |
|
| 188 | + 'color' => '#007ee5', |
|
| 189 | + 'url' => '', |
|
| 190 | + 'order' => 14, |
|
| 191 | + ), |
|
| 192 | + 15 => array( |
|
| 193 | + 'id' => 'drupal', |
|
| 194 | + 'icon' => 'fa-drupal', |
|
| 195 | + 'class' => 'fa', |
|
| 196 | + 'enabled' => false, |
|
| 197 | + 'name' => esc_html__( 'Drupal', 'redux-framework' ), |
|
| 198 | + 'background' => '', |
|
| 199 | + 'color' => '#0077c0', |
|
| 200 | + 'url' => '', |
|
| 201 | + 'order' => 15, |
|
| 202 | + ), |
|
| 203 | + 16 => array( |
|
| 204 | + 'id' => 'empire', |
|
| 205 | + 'icon' => 'fa-empire', |
|
| 206 | + 'class' => 'fa', |
|
| 207 | + 'enabled' => false, |
|
| 208 | + 'name' => esc_html__( 'Empire', 'redux-framework' ), |
|
| 209 | + 'background' => '', |
|
| 210 | + 'color' => '#000000', |
|
| 211 | + 'url' => '', |
|
| 212 | + 'order' => 16, |
|
| 213 | + ), |
|
| 214 | + 17 => array( |
|
| 215 | + 'id' => 'facebook', |
|
| 216 | + 'icon' => 'fa-facebook', |
|
| 217 | + 'class' => 'fa', |
|
| 218 | + 'enabled' => false, |
|
| 219 | + 'name' => esc_html__( 'Facebook', 'redux-framework' ), |
|
| 220 | + 'background' => '', |
|
| 221 | + 'color' => '#3b5998', |
|
| 222 | + 'url' => '', |
|
| 223 | + 'order' => 17, |
|
| 224 | + ), |
|
| 225 | + 18 => array( |
|
| 226 | + 'id' => 'facebook-square', |
|
| 227 | + 'icon' => 'fa-facebook-square', |
|
| 228 | + 'class' => 'fa', |
|
| 229 | + 'enabled' => false, |
|
| 230 | + 'name' => esc_html__( 'Facebook square', 'redux-framework' ), |
|
| 231 | + 'background' => '', |
|
| 232 | + 'color' => '#3b5998', |
|
| 233 | + 'url' => '', |
|
| 234 | + 'order' => 18, |
|
| 235 | + ), |
|
| 236 | + 19 => array( |
|
| 237 | + 'id' => 'flickr', |
|
| 238 | + 'icon' => 'fa-flickr', |
|
| 239 | + 'class' => 'fa', |
|
| 240 | + 'enabled' => false, |
|
| 241 | + 'name' => esc_html__( 'Flickr', 'redux-framework' ), |
|
| 242 | + 'background' => '', |
|
| 243 | + 'color' => '#0063dc', |
|
| 244 | + 'url' => '', |
|
| 245 | + 'order' => 19, |
|
| 246 | + ), |
|
| 247 | + 20 => array( |
|
| 248 | + 'id' => 'foursquare', |
|
| 249 | + 'icon' => 'fa-foursquare', |
|
| 250 | + 'class' => 'fa', |
|
| 251 | + 'enabled' => false, |
|
| 252 | + 'name' => esc_html__( 'FourSquare', 'redux-framework' ), |
|
| 253 | + 'background' => '', |
|
| 254 | + 'color' => '#0072b1', |
|
| 255 | + 'url' => '', |
|
| 256 | + 'order' => 20, |
|
| 257 | + ), |
|
| 258 | + 21 => array( |
|
| 259 | + 'id' => 'git', |
|
| 260 | + 'icon' => 'fa-git', |
|
| 261 | + 'class' => 'fa', |
|
| 262 | + 'enabled' => false, |
|
| 263 | + 'name' => esc_html__( 'git', 'redux-framework' ), |
|
| 264 | + 'background' => '', |
|
| 265 | + 'color' => '#000000', |
|
| 266 | + 'url' => '', |
|
| 267 | + 'order' => 21, |
|
| 268 | + ), |
|
| 269 | + 22 => array( |
|
| 270 | + 'id' => 'git-square', |
|
| 271 | + 'icon' => 'fa-git-square', |
|
| 272 | + 'class' => 'fa', |
|
| 273 | + 'enabled' => false, |
|
| 274 | + 'name' => esc_html__( 'git square', 'redux-framework' ), |
|
| 275 | + 'background' => '', |
|
| 276 | + 'color' => '#000000', |
|
| 277 | + 'url' => '', |
|
| 278 | + 'order' => 22, |
|
| 279 | + ), |
|
| 280 | + 23 => array( |
|
| 281 | + 'id' => 'github', |
|
| 282 | + 'icon' => 'fa-github', |
|
| 283 | + 'class' => 'fa', |
|
| 284 | + 'enabled' => false, |
|
| 285 | + 'name' => esc_html__( 'github', 'redux-framework' ), |
|
| 286 | + 'background' => '', |
|
| 287 | + 'color' => '#4183c4', |
|
| 288 | + 'url' => '', |
|
| 289 | + 'order' => 23, |
|
| 290 | + ), |
|
| 291 | + 24 => array( |
|
| 292 | + 'id' => 'github-alt', |
|
| 293 | + 'icon' => 'fa-github-alt', |
|
| 294 | + 'class' => 'fa', |
|
| 295 | + 'enabled' => false, |
|
| 296 | + 'name' => esc_html__( 'github alt', 'redux-framework' ), |
|
| 297 | + 'background' => '', |
|
| 298 | + 'color' => '#4183c4', |
|
| 299 | + 'url' => '', |
|
| 300 | + 'order' => 24, |
|
| 301 | + ), |
|
| 302 | + 25 => array( |
|
| 303 | + 'id' => 'github-square', |
|
| 304 | + 'icon' => 'fa-github-square', |
|
| 305 | + 'class' => 'fa', |
|
| 306 | + 'enabled' => false, |
|
| 307 | + 'name' => esc_html__( 'github square', 'redux-framework' ), |
|
| 308 | + 'background' => '', |
|
| 309 | + 'color' => '#4183c4', |
|
| 310 | + 'url' => '', |
|
| 311 | + 'order' => 25, |
|
| 312 | + ), |
|
| 313 | + 26 => array( |
|
| 314 | + 'id' => 'gittip', |
|
| 315 | + 'icon' => 'fa-gittip', |
|
| 316 | + 'class' => 'fa', |
|
| 317 | + 'enabled' => false, |
|
| 318 | + 'name' => esc_html__( 'git tip', 'redux-framework' ), |
|
| 319 | + 'background' => '', |
|
| 320 | + 'color' => '#000000', |
|
| 321 | + 'url' => '', |
|
| 322 | + 'order' => 26, |
|
| 323 | + ), |
|
| 324 | + 27 => array( |
|
| 325 | + 'id' => 'google', |
|
| 326 | + 'icon' => 'fa-google', |
|
| 327 | + 'class' => 'fa', |
|
| 328 | + 'enabled' => false, |
|
| 329 | + 'name' => esc_html__( 'Google', 'redux-framework' ), |
|
| 330 | + 'background' => '', |
|
| 331 | + 'color' => '#dd4b39', |
|
| 332 | + 'url' => '', |
|
| 333 | + 'order' => 27, |
|
| 334 | + ), |
|
| 335 | + 28 => array( |
|
| 336 | + 'id' => 'google-plus', |
|
| 337 | + 'icon' => 'fa-google-plus', |
|
| 338 | + 'class' => 'fa', |
|
| 339 | + 'enabled' => false, |
|
| 340 | + 'name' => esc_html__( 'Google Plus', 'redux-framework' ), |
|
| 341 | + 'background' => '', |
|
| 342 | + 'color' => '#dd4b39', |
|
| 343 | + 'url' => '', |
|
| 344 | + 'order' => 28, |
|
| 345 | + ), |
|
| 346 | + 29 => array( |
|
| 347 | + 'id' => 'google-plus-square', |
|
| 348 | + 'icon' => 'fa-google-plus-square', |
|
| 349 | + 'class' => 'fa', |
|
| 350 | + 'enabled' => false, |
|
| 351 | + 'name' => esc_html__( 'Google Plus square', 'redux-framework' ), |
|
| 352 | + 'background' => '', |
|
| 353 | + 'color' => '#dd4b39', |
|
| 354 | + 'url' => '', |
|
| 355 | + 'order' => 29, |
|
| 356 | + ), |
|
| 357 | + 30 => array( |
|
| 358 | + 'id' => 'hacker-news', |
|
| 359 | + 'icon' => 'fa-hacker-news', |
|
| 360 | + 'class' => 'fa', |
|
| 361 | + 'enabled' => false, |
|
| 362 | + 'name' => esc_html__( 'Hacker News', 'redux-framework' ), |
|
| 363 | + 'background' => '', |
|
| 364 | + 'color' => '#ff6600', |
|
| 365 | + 'url' => '', |
|
| 366 | + 'order' => 30, |
|
| 367 | + ), |
|
| 368 | + 31 => array( |
|
| 369 | + 'id' => 'html5', |
|
| 370 | + 'icon' => 'fa-html5', |
|
| 371 | + 'class' => 'fa', |
|
| 372 | + 'enabled' => false, |
|
| 373 | + 'name' => esc_html__( 'HTML5', 'redux-framework' ), |
|
| 374 | + 'background' => '', |
|
| 375 | + 'color' => '#e34f26', |
|
| 376 | + 'url' => '', |
|
| 377 | + 'order' => 31, |
|
| 378 | + ), |
|
| 379 | + 32 => array( |
|
| 380 | + 'id' => 'instagram', |
|
| 381 | + 'icon' => 'fa-instagram', |
|
| 382 | + 'class' => 'fa', |
|
| 383 | + 'enabled' => false, |
|
| 384 | + 'name' => esc_html__( 'Instagram', 'redux-framework' ), |
|
| 385 | + 'background' => '', |
|
| 386 | + 'color' => '#3f729b', |
|
| 387 | + 'url' => '', |
|
| 388 | + 'order' => 32, |
|
| 389 | + ), |
|
| 390 | + 33 => array( |
|
| 391 | + 'id' => 'joomla', |
|
| 392 | + 'icon' => 'fa-joomla', |
|
| 393 | + 'class' => 'fa', |
|
| 394 | + 'enabled' => false, |
|
| 395 | + 'name' => esc_html__( 'Joomla', 'redux-framework' ), |
|
| 396 | + 'background' => '', |
|
| 397 | + 'color' => '#000000', |
|
| 398 | + 'url' => '', |
|
| 399 | + 'order' => 33, |
|
| 400 | + ), |
|
| 401 | + 34 => array( |
|
| 402 | + 'id' => 'jsfiddle', |
|
| 403 | + 'icon' => 'fa-jsfiddle', |
|
| 404 | + 'class' => 'fa', |
|
| 405 | + 'enabled' => false, |
|
| 406 | + 'name' => esc_html__( 'JS Fiddle', 'redux-framework' ), |
|
| 407 | + 'background' => '', |
|
| 408 | + 'color' => '#000000', |
|
| 409 | + 'url' => '', |
|
| 410 | + 'order' => 34, |
|
| 411 | + ), |
|
| 412 | + 35 => array( |
|
| 413 | + 'id' => 'linkedin', |
|
| 414 | + 'icon' => 'fa-linkedin', |
|
| 415 | + 'class' => 'fa', |
|
| 416 | + 'enabled' => false, |
|
| 417 | + 'name' => esc_html__( 'LinkedIn', 'redux-framework' ), |
|
| 418 | + 'background' => '', |
|
| 419 | + 'color' => '#0976b4', |
|
| 420 | + 'url' => '', |
|
| 421 | + 'order' => 35, |
|
| 422 | + ), |
|
| 423 | + 36 => array( |
|
| 424 | + 'id' => 'linkedin-square', |
|
| 425 | + 'icon' => 'fa-linkedin-square', |
|
| 426 | + 'class' => 'fa', |
|
| 427 | + 'enabled' => false, |
|
| 428 | + 'name' => esc_html__( 'LinkedIn square', 'redux-framework' ), |
|
| 429 | + 'background' => '', |
|
| 430 | + 'color' => '#0976b4', |
|
| 431 | + 'url' => '', |
|
| 432 | + 'order' => 36, |
|
| 433 | + ), |
|
| 434 | + 37 => array( |
|
| 435 | + 'id' => 'linux', |
|
| 436 | + 'icon' => 'fa-linux', |
|
| 437 | + 'class' => 'fa', |
|
| 438 | + 'enabled' => false, |
|
| 439 | + 'name' => esc_html__( 'Linux', 'redux-framework' ), |
|
| 440 | + 'background' => '', |
|
| 441 | + 'color' => '#333333', |
|
| 442 | + 'url' => '', |
|
| 443 | + 'order' => 37, |
|
| 444 | + ), |
|
| 445 | + 38 => array( |
|
| 446 | + 'id' => 'maxcdn', |
|
| 447 | + 'icon' => 'fa-maxcdn', |
|
| 448 | + 'class' => 'fa', |
|
| 449 | + 'enabled' => false, |
|
| 450 | + 'name' => esc_html__( 'MaxCDN', 'redux-framework' ), |
|
| 451 | + 'background' => '', |
|
| 452 | + 'color' => '#f8711e', |
|
| 453 | + 'url' => '', |
|
| 454 | + 'order' => 38, |
|
| 455 | + ), |
|
| 456 | + 39 => array( |
|
| 457 | + 'id' => 'openid', |
|
| 458 | + 'icon' => 'fa-openid', |
|
| 459 | + 'class' => 'fa', |
|
| 460 | + 'enabled' => false, |
|
| 461 | + 'name' => esc_html__( 'OpenID', 'redux-framework' ), |
|
| 462 | + 'background' => '', |
|
| 463 | + 'color' => '#000000', |
|
| 464 | + 'url' => '', |
|
| 465 | + 'order' => 39, |
|
| 466 | + ), |
|
| 467 | + 40 => array( |
|
| 468 | + 'id' => 'pagelines', |
|
| 469 | + 'icon' => 'fa-pagelines', |
|
| 470 | + 'class' => 'fa', |
|
| 471 | + 'enabled' => false, |
|
| 472 | + 'name' => esc_html__( 'Page Lines', 'redux-framework' ), |
|
| 473 | + 'background' => '', |
|
| 474 | + 'color' => '#000000', |
|
| 475 | + 'url' => '', |
|
| 476 | + 'order' => 40, |
|
| 477 | + ), |
|
| 478 | + 41 => array( |
|
| 479 | + 'id' => 'pied-piper', |
|
| 480 | + 'icon' => 'fa-pied-piper', |
|
| 481 | + 'class' => 'fa', |
|
| 482 | + 'enabled' => false, |
|
| 483 | + 'name' => esc_html__( 'Pied Piper', 'redux-framework' ), |
|
| 484 | + 'background' => '', |
|
| 485 | + 'color' => '#000000', |
|
| 486 | + 'url' => '', |
|
| 487 | + 'order' => 41, |
|
| 488 | + ), |
|
| 489 | + 42 => array( |
|
| 490 | + 'id' => 'pied-piper-alt', |
|
| 491 | + 'icon' => 'fa-pied-piper-alt', |
|
| 492 | + 'class' => 'fa', |
|
| 493 | + 'enabled' => false, |
|
| 494 | + 'name' => esc_html__( 'Pied Piper alt', 'redux-framework' ), |
|
| 495 | + 'background' => '', |
|
| 496 | + 'color' => '#000000', |
|
| 497 | + 'url' => '', |
|
| 498 | + 'order' => 42, |
|
| 499 | + ), |
|
| 500 | + 43 => array( |
|
| 501 | + 'id' => 'pinterest', |
|
| 502 | + 'icon' => 'fa-pinterest', |
|
| 503 | + 'class' => 'fa', |
|
| 504 | + 'enabled' => false, |
|
| 505 | + 'name' => esc_html__( 'Pinterest', 'redux-framework' ), |
|
| 506 | + 'background' => '', |
|
| 507 | + 'color' => '#1769ff', |
|
| 508 | + 'url' => '', |
|
| 509 | + 'order' => 43, |
|
| 510 | + ), |
|
| 511 | + 44 => array( |
|
| 512 | + 'id' => 'pinterest-square', |
|
| 513 | + 'icon' => 'fa-pinterest-square', |
|
| 514 | + 'class' => 'fa', |
|
| 515 | + 'enabled' => false, |
|
| 516 | + 'name' => esc_html__( 'Pinterest square', 'redux-framework' ), |
|
| 517 | + 'background' => '', |
|
| 518 | + 'color' => '#1769ff', |
|
| 519 | + 'url' => '', |
|
| 520 | + 'order' => 44, |
|
| 521 | + ), |
|
| 522 | + 45 => array( |
|
| 523 | + 'id' => 'qq', |
|
| 524 | + 'icon' => 'fa-qq', |
|
| 525 | + 'class' => 'fa', |
|
| 526 | + 'enabled' => false, |
|
| 527 | + 'name' => esc_html__( 'QQ', 'redux-framework' ), |
|
| 528 | + 'background' => '', |
|
| 529 | + 'color' => '#000000', |
|
| 530 | + 'url' => '', |
|
| 531 | + 'order' => 45, |
|
| 532 | + ), |
|
| 533 | + 46 => array( |
|
| 534 | + 'id' => 'rebel', |
|
| 535 | + 'icon' => 'fa-rebel', |
|
| 536 | + 'class' => 'fa', |
|
| 537 | + 'enabled' => false, |
|
| 538 | + 'name' => esc_html__( 'Rebel', 'redux-framework' ), |
|
| 539 | + 'background' => '', |
|
| 540 | + 'color' => '#517fa4', |
|
| 541 | + 'url' => '', |
|
| 542 | + 'order' => 46, |
|
| 543 | + ), |
|
| 544 | + 47 => array( |
|
| 545 | + 'id' => 'reddit', |
|
| 546 | + 'icon' => 'fa-reddit', |
|
| 547 | + 'class' => 'fa', |
|
| 548 | + 'enabled' => false, |
|
| 549 | + 'name' => esc_html__( 'Reddit', 'redux-framework' ), |
|
| 550 | + 'background' => '', |
|
| 551 | + 'color' => '#ff4500', |
|
| 552 | + 'url' => '', |
|
| 553 | + 'order' => 47, |
|
| 554 | + ), |
|
| 555 | + 48 => array( |
|
| 556 | + 'id' => 'reddit-square', |
|
| 557 | + 'icon' => 'fa-reddit-square', |
|
| 558 | + 'class' => 'fa', |
|
| 559 | + 'enabled' => false, |
|
| 560 | + 'name' => esc_html__( 'Reddit square', 'redux-framework' ), |
|
| 561 | + 'background' => '', |
|
| 562 | + 'color' => '#ff4500', |
|
| 563 | + 'url' => '', |
|
| 564 | + 'order' => 48, |
|
| 565 | + ), |
|
| 566 | + 49 => array( |
|
| 567 | + 'id' => 'renren', |
|
| 568 | + 'icon' => 'fa-renren', |
|
| 569 | + 'class' => 'fa', |
|
| 570 | + 'enabled' => false, |
|
| 571 | + 'name' => esc_html__( 'Ren Ren', 'redux-framework' ), |
|
| 572 | + 'background' => '', |
|
| 573 | + 'color' => '#007bb6', |
|
| 574 | + 'url' => '', |
|
| 575 | + 'order' => 49, |
|
| 576 | + ), |
|
| 577 | + 50 => array( |
|
| 578 | + 'id' => 'share-alt', |
|
| 579 | + 'icon' => 'fa-share-alt', |
|
| 580 | + 'class' => 'fa', |
|
| 581 | + 'enabled' => false, |
|
| 582 | + 'name' => esc_html__( 'Share alt', 'redux-framework' ), |
|
| 583 | + 'background' => '', |
|
| 584 | + 'color' => '#000000', |
|
| 585 | + 'url' => '', |
|
| 586 | + 'order' => 50, |
|
| 587 | + ), |
|
| 588 | + 51 => array( |
|
| 589 | + 'id' => 'share-alt-square', |
|
| 590 | + 'icon' => 'fa-share-alt-square', |
|
| 591 | + 'class' => 'fa', |
|
| 592 | + 'enabled' => false, |
|
| 593 | + 'name' => esc_html__( 'Share square', 'redux-framework' ), |
|
| 594 | + 'background' => '', |
|
| 595 | + 'color' => '#000000', |
|
| 596 | + 'url' => '', |
|
| 597 | + 'order' => 51, |
|
| 598 | + ), |
|
| 599 | + 52 => array( |
|
| 600 | + 'id' => 'skype', |
|
| 601 | + 'icon' => 'fa-skype', |
|
| 602 | + 'class' => 'fa', |
|
| 603 | + 'enabled' => false, |
|
| 604 | + 'name' => esc_html__( 'Skype', 'redux-framework' ), |
|
| 605 | + 'background' => '', |
|
| 606 | + 'color' => '#00aff0', |
|
| 607 | + 'url' => '', |
|
| 608 | + 'order' => 52, |
|
| 609 | + ), |
|
| 610 | + 53 => array( |
|
| 611 | + 'id' => 'slack', |
|
| 612 | + 'icon' => 'fa-slack', |
|
| 613 | + 'class' => 'fa', |
|
| 614 | + 'enabled' => false, |
|
| 615 | + 'name' => esc_html__( 'Slack', 'redux-framework' ), |
|
| 616 | + 'background' => '', |
|
| 617 | + 'color' => '#000000', |
|
| 618 | + 'url' => '', |
|
| 619 | + 'order' => 53, |
|
| 620 | + ), |
|
| 621 | + 54 => array( |
|
| 622 | + 'id' => 'soundcloud', |
|
| 623 | + 'icon' => 'fa-soundcloud', |
|
| 624 | + 'class' => 'fa', |
|
| 625 | + 'enabled' => false, |
|
| 626 | + 'name' => esc_html__( 'Sound Cloud', 'redux-framework' ), |
|
| 627 | + 'background' => '', |
|
| 628 | + 'color' => '#f80', |
|
| 629 | + 'url' => '', |
|
| 630 | + 'order' => 54, |
|
| 631 | + ), |
|
| 632 | + 55 => array( |
|
| 633 | + 'id' => 'spotify', |
|
| 634 | + 'icon' => 'fa-spotify', |
|
| 635 | + 'class' => 'fa', |
|
| 636 | + 'enabled' => false, |
|
| 637 | + 'name' => esc_html__( 'Spotify', 'redux-framework' ), |
|
| 638 | + 'background' => '', |
|
| 639 | + 'color' => '#7ab800', |
|
| 640 | + 'url' => '', |
|
| 641 | + 'order' => 55, |
|
| 642 | + ), |
|
| 643 | + 56 => array( |
|
| 644 | + 'id' => 'stack-exchange', |
|
| 645 | + 'icon' => 'fa-stack-exchange', |
|
| 646 | + 'class' => 'fa', |
|
| 647 | + 'enabled' => false, |
|
| 648 | + 'name' => esc_html__( 'Stack Exchange', 'redux-framework' ), |
|
| 649 | + 'background' => '', |
|
| 650 | + 'color' => '#000000', |
|
| 651 | + 'url' => '', |
|
| 652 | + 'order' => 56, |
|
| 653 | + ), |
|
| 654 | + 57 => array( |
|
| 655 | + 'id' => 'stack-overflow', |
|
| 656 | + 'icon' => 'fa-stack-overflow', |
|
| 657 | + 'class' => 'fa', |
|
| 658 | + 'enabled' => false, |
|
| 659 | + 'name' => esc_html__( 'Stack Overflow', 'redux-framework' ), |
|
| 660 | + 'background' => '', |
|
| 661 | + 'color' => '#fe7a15', |
|
| 662 | + 'url' => '', |
|
| 663 | + 'order' => 57, |
|
| 664 | + ), |
|
| 665 | + 58 => array( |
|
| 666 | + 'id' => 'steam', |
|
| 667 | + 'icon' => 'fa-steam', |
|
| 668 | + 'class' => 'fa', |
|
| 669 | + 'enabled' => false, |
|
| 670 | + 'name' => esc_html__( 'Steam', 'redux-framework' ), |
|
| 671 | + 'background' => '', |
|
| 672 | + 'color' => '#000000', |
|
| 673 | + 'url' => '', |
|
| 674 | + 'order' => 58, |
|
| 675 | + ), |
|
| 676 | + 59 => array( |
|
| 677 | + 'id' => 'steam-square', |
|
| 678 | + 'icon' => 'fa-steam-square', |
|
| 679 | + 'class' => 'fa', |
|
| 680 | + 'enabled' => false, |
|
| 681 | + 'name' => esc_html__( 'Steam square', 'redux-framework' ), |
|
| 682 | + 'background' => '', |
|
| 683 | + 'color' => '#000000', |
|
| 684 | + 'url' => '', |
|
| 685 | + 'order' => 59, |
|
| 686 | + ), |
|
| 687 | + 60 => array( |
|
| 688 | + 'id' => 'stumbleupon', |
|
| 689 | + 'icon' => 'fa-stumbleupon', |
|
| 690 | + 'class' => 'fa', |
|
| 691 | + 'enabled' => false, |
|
| 692 | + 'name' => esc_html__( 'Stumble Upon', 'redux-framework' ), |
|
| 693 | + 'background' => '', |
|
| 694 | + 'color' => '#eb4924', |
|
| 695 | + 'url' => '', |
|
| 696 | + 'order' => 60, |
|
| 697 | + ), |
|
| 698 | + 61 => array( |
|
| 699 | + 'id' => 'stumbleupon-circle', |
|
| 700 | + 'icon' => 'fa-stumbleupon-circle', |
|
| 701 | + 'class' => 'fa', |
|
| 702 | + 'enabled' => false, |
|
| 703 | + 'name' => esc_html__( 'Stumble Upon circle', 'redux-framework' ), |
|
| 704 | + 'background' => '', |
|
| 705 | + 'color' => '#eb4924', |
|
| 706 | + 'url' => '', |
|
| 707 | + 'order' => 61, |
|
| 708 | + ), |
|
| 709 | + 62 => array( |
|
| 710 | + 'id' => 'tencent-weibo', |
|
| 711 | + 'icon' => 'fa-tencent-weibo', |
|
| 712 | + 'class' => 'fa', |
|
| 713 | + 'enabled' => false, |
|
| 714 | + 'name' => esc_html__( 'Tencent Weibo', 'redux-framework' ), |
|
| 715 | + 'background' => '', |
|
| 716 | + 'color' => '#000000', |
|
| 717 | + 'url' => '', |
|
| 718 | + 'order' => 62, |
|
| 719 | + ), |
|
| 720 | + 63 => array( |
|
| 721 | + 'id' => 'trello', |
|
| 722 | + 'icon' => 'fa-trello', |
|
| 723 | + 'class' => 'fa', |
|
| 724 | + 'enabled' => false, |
|
| 725 | + 'name' => esc_html__( 'Trello', 'redux-framework' ), |
|
| 726 | + 'background' => '', |
|
| 727 | + 'color' => '#256a92', |
|
| 728 | + 'url' => '', |
|
| 729 | + 'order' => 63, |
|
| 730 | + ), |
|
| 731 | + 64 => array( |
|
| 732 | + 'id' => 'tumblr', |
|
| 733 | + 'icon' => 'fa-tumblr', |
|
| 734 | + 'class' => 'fa', |
|
| 735 | + 'enabled' => false, |
|
| 736 | + 'name' => esc_html__( 'Tumblr', 'redux-framework' ), |
|
| 737 | + 'background' => '', |
|
| 738 | + 'color' => '#35465c', |
|
| 739 | + 'url' => '', |
|
| 740 | + 'order' => 64, |
|
| 741 | + ), |
|
| 742 | + 65 => array( |
|
| 743 | + 'id' => 'tumblr-square', |
|
| 744 | + 'icon' => 'fa-tumblr-square', |
|
| 745 | + 'class' => 'fa', |
|
| 746 | + 'enabled' => false, |
|
| 747 | + 'name' => esc_html__( 'Tumblr square', 'redux-framework' ), |
|
| 748 | + 'background' => '', |
|
| 749 | + 'color' => '#35465c', |
|
| 750 | + 'url' => '', |
|
| 751 | + 'order' => 65, |
|
| 752 | + ), |
|
| 753 | + 66 => array( |
|
| 754 | + 'id' => 'twitter', |
|
| 755 | + 'icon' => 'fa-x-twitter', |
|
| 756 | + 'class' => 'fa-brands', |
|
| 757 | + 'enabled' => false, |
|
| 758 | + 'name' => esc_html__( 'X', 'redux-framework' ), |
|
| 759 | + 'background' => '', |
|
| 760 | + 'color' => '#55acee', |
|
| 761 | + 'url' => '', |
|
| 762 | + 'order' => 66, |
|
| 763 | + ), |
|
| 764 | + 67 => array( |
|
| 765 | + 'id' => 'twitter-square', |
|
| 766 | + 'icon' => 'fa-square-x-twitter', |
|
| 767 | + 'class' => 'fa-brands', |
|
| 768 | + 'enabled' => false, |
|
| 769 | + 'name' => esc_html__( 'X square', 'redux-framework' ), |
|
| 770 | + 'background' => '', |
|
| 771 | + 'color' => '#55acee', |
|
| 772 | + 'url' => '', |
|
| 773 | + 'order' => 67, |
|
| 774 | + ), |
|
| 775 | + 68 => array( |
|
| 776 | + 'id' => 'vimeo-square', |
|
| 777 | + 'icon' => 'fa-vimeo-square', |
|
| 778 | + 'class' => 'fa', |
|
| 779 | + 'enabled' => false, |
|
| 780 | + 'name' => esc_html__( 'Vimeo square', 'redux-framework' ), |
|
| 781 | + 'background' => '', |
|
| 782 | + 'color' => '#1ab7ea', |
|
| 783 | + 'url' => '', |
|
| 784 | + 'order' => 68, |
|
| 785 | + ), |
|
| 786 | + 69 => array( |
|
| 787 | + 'id' => 'vine', |
|
| 788 | + 'icon' => 'fa-vine', |
|
| 789 | + 'class' => 'fa', |
|
| 790 | + 'enabled' => false, |
|
| 791 | + 'name' => esc_html__( 'Vine', 'redux-framework' ), |
|
| 792 | + 'background' => '', |
|
| 793 | + 'color' => '#00b488', |
|
| 794 | + 'url' => '', |
|
| 795 | + 'order' => 69, |
|
| 796 | + ), |
|
| 797 | + 70 => array( |
|
| 798 | + 'id' => 'vk', |
|
| 799 | + 'icon' => 'fa-vk', |
|
| 800 | + 'class' => 'fa', |
|
| 801 | + 'enabled' => false, |
|
| 802 | + 'name' => esc_html__( 'VK', 'redux-framework' ), |
|
| 803 | + 'background' => '', |
|
| 804 | + 'color' => '#000000', |
|
| 805 | + 'url' => '', |
|
| 806 | + 'order' => 70, |
|
| 807 | + ), |
|
| 808 | + 71 => array( |
|
| 809 | + 'id' => 'weibo', |
|
| 810 | + 'icon' => 'fa-weibo', |
|
| 811 | + 'class' => 'fa', |
|
| 812 | + 'enabled' => false, |
|
| 813 | + 'name' => esc_html__( 'Weibo', 'redux-framework' ), |
|
| 814 | + 'background' => '', |
|
| 815 | + 'color' => '#000000', |
|
| 816 | + 'url' => '', |
|
| 817 | + 'order' => 71, |
|
| 818 | + ), |
|
| 819 | + 72 => array( |
|
| 820 | + 'id' => 'weixin', |
|
| 821 | + 'icon' => 'fa-weixin', |
|
| 822 | + 'class' => 'fa', |
|
| 823 | + 'enabled' => false, |
|
| 824 | + 'name' => esc_html__( 'Weixin', 'redux-framework' ), |
|
| 825 | + 'background' => '', |
|
| 826 | + 'color' => '#000000', |
|
| 827 | + 'url' => '', |
|
| 828 | + 'order' => 72, |
|
| 829 | + ), |
|
| 830 | + 73 => array( |
|
| 831 | + 'id' => 'windows', |
|
| 832 | + 'icon' => 'fa-windows', |
|
| 833 | + 'class' => 'fa', |
|
| 834 | + 'enabled' => false, |
|
| 835 | + 'name' => esc_html__( 'Windows', 'redux-framework' ), |
|
| 836 | + 'background' => '', |
|
| 837 | + 'color' => '#00bcf2', |
|
| 838 | + 'url' => '', |
|
| 839 | + 'order' => 73, |
|
| 840 | + ), |
|
| 841 | + 74 => array( |
|
| 842 | + 'id' => 'wordpress', |
|
| 843 | + 'icon' => 'fa-wordpress', |
|
| 844 | + 'class' => 'fa', |
|
| 845 | + 'enabled' => false, |
|
| 846 | + 'name' => esc_html__( 'WordPress', 'redux-framework' ), |
|
| 847 | + 'background' => '', |
|
| 848 | + 'color' => '#21759b', |
|
| 849 | + 'url' => '', |
|
| 850 | + 'order' => 74, |
|
| 851 | + ), |
|
| 852 | + 75 => array( |
|
| 853 | + 'id' => 'xing', |
|
| 854 | + 'icon' => 'fa-xing', |
|
| 855 | + 'class' => 'fa', |
|
| 856 | + 'enabled' => false, |
|
| 857 | + 'name' => esc_html__( 'Xing', 'redux-framework' ), |
|
| 858 | + 'background' => '', |
|
| 859 | + 'color' => '#026466', |
|
| 860 | + 'url' => '', |
|
| 861 | + 'order' => 75, |
|
| 862 | + ), |
|
| 863 | + 76 => array( |
|
| 864 | + 'id' => 'xing-square', |
|
| 865 | + 'icon' => 'fa-xing-square', |
|
| 866 | + 'class' => 'fa', |
|
| 867 | + 'enabled' => false, |
|
| 868 | + 'name' => esc_html__( 'Xing square', 'redux-framework' ), |
|
| 869 | + 'background' => '', |
|
| 870 | + 'color' => '#026466', |
|
| 871 | + 'url' => '', |
|
| 872 | + 'order' => 76, |
|
| 873 | + ), |
|
| 874 | + 77 => array( |
|
| 875 | + 'id' => 'yahoo', |
|
| 876 | + 'icon' => 'fa-yahoo', |
|
| 877 | + 'class' => 'fa', |
|
| 878 | + 'enabled' => false, |
|
| 879 | + 'name' => esc_html__( 'Yahoo', 'redux-framework' ), |
|
| 880 | + 'background' => '', |
|
| 881 | + 'color' => '#400191', |
|
| 882 | + 'url' => '', |
|
| 883 | + 'order' => 77, |
|
| 884 | + ), |
|
| 885 | + 78 => array( |
|
| 886 | + 'id' => 'yelp', |
|
| 887 | + 'icon' => 'fa-yelp', |
|
| 888 | + 'class' => 'fa', |
|
| 889 | + 'enabled' => false, |
|
| 890 | + 'name' => esc_html__( 'Yelp', 'redux-framework' ), |
|
| 891 | + 'background' => '', |
|
| 892 | + 'color' => '#C93C27', |
|
| 893 | + 'url' => '', |
|
| 894 | + 'order' => 78, |
|
| 895 | + ), |
|
| 896 | + 79 => array( |
|
| 897 | + 'id' => 'youtube', |
|
| 898 | + 'icon' => 'fa-youtube', |
|
| 899 | + 'class' => 'fa', |
|
| 900 | + 'enabled' => false, |
|
| 901 | + 'name' => esc_html__( 'YouTube', 'redux-framework' ), |
|
| 902 | + 'background' => '', |
|
| 903 | + 'color' => '#e52d27', |
|
| 904 | + 'url' => '', |
|
| 905 | + 'order' => 79, |
|
| 906 | + ), |
|
| 907 | + 80 => array( |
|
| 908 | + 'id' => 'youtube-play', |
|
| 909 | + 'icon' => 'fa-youtube-play', |
|
| 910 | + 'class' => 'fa', |
|
| 911 | + 'enabled' => false, |
|
| 912 | + 'name' => esc_html__( 'YouTube play', 'redux-framework' ), |
|
| 913 | + 'background' => '', |
|
| 914 | + 'color' => '#e52d27', |
|
| 915 | + 'url' => '', |
|
| 916 | + 'order' => 80, |
|
| 917 | + ), |
|
| 918 | + 81 => array( |
|
| 919 | + 'id' => 'youtube-square', |
|
| 920 | + 'icon' => 'fa-youtube-square', |
|
| 921 | + 'class' => 'fa', |
|
| 922 | + 'enabled' => false, |
|
| 923 | + 'name' => esc_html__( 'YouTube square', 'redux-framework' ), |
|
| 924 | + 'background' => '', |
|
| 925 | + 'color' => '#e52d27', |
|
| 926 | + 'url' => '', |
|
| 927 | + 'order' => 81, |
|
| 928 | + ), |
|
| 929 | + ); |
|
| 930 | + } |
|
| 931 | + } |
|
| 932 | 932 | } |
@@ -11,358 +11,358 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Social_Profiles' ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Main Redux_Social_Profiles class |
|
| 16 | - * |
|
| 17 | - * @since 1.0.0 |
|
| 18 | - */ |
|
| 19 | - class Redux_Social_Profiles extends Redux_Field { |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Field ID. |
|
| 23 | - * |
|
| 24 | - * @var null|string |
|
| 25 | - */ |
|
| 26 | - public ?string $field_id; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * Panel opt_name. |
|
| 30 | - * |
|
| 31 | - * @var null|string |
|
| 32 | - */ |
|
| 33 | - public ?string $opt_name; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Defaults array. |
|
| 37 | - * |
|
| 38 | - * @var null|array |
|
| 39 | - */ |
|
| 40 | - |
|
| 41 | - private ?array $defaults = array(); |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Set defaults. |
|
| 45 | - */ |
|
| 46 | - public function set_defaults() { |
|
| 47 | - $this->opt_name = $this->parent->args['opt_name']; |
|
| 48 | - $this->field_id = $this->field['id']; |
|
| 49 | - |
|
| 50 | - $this->defaults = Redux_Social_Profiles_Functions::get_default_data(); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Rebuild Settings. |
|
| 55 | - * |
|
| 56 | - * @param array $settings Settings array. |
|
| 57 | - * |
|
| 58 | - * @return array |
|
| 59 | - */ |
|
| 60 | - private function rebuild_setttings( array $settings ): array { |
|
| 61 | - $fixed_arr = array(); |
|
| 62 | - $stock = ''; |
|
| 63 | - |
|
| 64 | - foreach ( $this->defaults as $key => $arr ) { |
|
| 65 | - $search_default = true; |
|
| 66 | - |
|
| 67 | - $default_id = $arr['id']; |
|
| 68 | - |
|
| 69 | - foreach ( $settings as $a ) { |
|
| 70 | - if ( isset( $a['data'] ) ) { |
|
| 71 | - $a['data'] = rawurldecode( $a['data'] ); |
|
| 72 | - $a = (array) json_decode( $a['data'] ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - if ( $default_id === $a['id'] ) { |
|
| 76 | - $search_default = false; |
|
| 77 | - $fixed_arr[ $key ] = $a; |
|
| 78 | - break; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if ( $search_default ) { |
|
| 83 | - if ( '' === $stock ) { |
|
| 84 | - $stock = Redux_Social_Profiles_Defaults::get_social_media_defaults(); |
|
| 85 | - $stock = Redux_Social_Profiles_Functions::add_extra_icons( $stock ); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - foreach ( $stock as $def_arr ) { |
|
| 89 | - if ( $default_id === $def_arr['id'] ) { |
|
| 90 | - $fixed_arr[ $key ] = $def_arr; |
|
| 91 | - break; |
|
| 92 | - } |
|
| 93 | - } |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return $fixed_arr; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Field Render Function. |
|
| 102 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 103 | - * |
|
| 104 | - * @since 1.0.0 |
|
| 105 | - * @access public |
|
| 106 | - * @return void |
|
| 107 | - */ |
|
| 108 | - public function render() { |
|
| 109 | - if ( empty( $this->field ) ) { |
|
| 110 | - return; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - global $pagenow, $post; |
|
| 114 | - |
|
| 115 | - $redux_settings = get_option( $this->opt_name ); |
|
| 116 | - $settings = $redux_settings[ $this->field_id ] ?? array(); |
|
| 117 | - |
|
| 118 | - if ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) { |
|
| 119 | - $post_settings = get_post_meta( $post->ID, $this->field_id, true ); |
|
| 120 | - |
|
| 121 | - if ( ! empty( $post_settings ) ) { |
|
| 122 | - $settings = $post_settings; |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - $color_pickers = $this->field['color_pickers'] ?? true; |
|
| 127 | - |
|
| 128 | - // Icon container. |
|
| 129 | - echo '<div |
|
| 14 | + /** |
|
| 15 | + * Main Redux_Social_Profiles class |
|
| 16 | + * |
|
| 17 | + * @since 1.0.0 |
|
| 18 | + */ |
|
| 19 | + class Redux_Social_Profiles extends Redux_Field { |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Field ID. |
|
| 23 | + * |
|
| 24 | + * @var null|string |
|
| 25 | + */ |
|
| 26 | + public ?string $field_id; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * Panel opt_name. |
|
| 30 | + * |
|
| 31 | + * @var null|string |
|
| 32 | + */ |
|
| 33 | + public ?string $opt_name; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Defaults array. |
|
| 37 | + * |
|
| 38 | + * @var null|array |
|
| 39 | + */ |
|
| 40 | + |
|
| 41 | + private ?array $defaults = array(); |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Set defaults. |
|
| 45 | + */ |
|
| 46 | + public function set_defaults() { |
|
| 47 | + $this->opt_name = $this->parent->args['opt_name']; |
|
| 48 | + $this->field_id = $this->field['id']; |
|
| 49 | + |
|
| 50 | + $this->defaults = Redux_Social_Profiles_Functions::get_default_data(); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Rebuild Settings. |
|
| 55 | + * |
|
| 56 | + * @param array $settings Settings array. |
|
| 57 | + * |
|
| 58 | + * @return array |
|
| 59 | + */ |
|
| 60 | + private function rebuild_setttings( array $settings ): array { |
|
| 61 | + $fixed_arr = array(); |
|
| 62 | + $stock = ''; |
|
| 63 | + |
|
| 64 | + foreach ( $this->defaults as $key => $arr ) { |
|
| 65 | + $search_default = true; |
|
| 66 | + |
|
| 67 | + $default_id = $arr['id']; |
|
| 68 | + |
|
| 69 | + foreach ( $settings as $a ) { |
|
| 70 | + if ( isset( $a['data'] ) ) { |
|
| 71 | + $a['data'] = rawurldecode( $a['data'] ); |
|
| 72 | + $a = (array) json_decode( $a['data'] ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + if ( $default_id === $a['id'] ) { |
|
| 76 | + $search_default = false; |
|
| 77 | + $fixed_arr[ $key ] = $a; |
|
| 78 | + break; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if ( $search_default ) { |
|
| 83 | + if ( '' === $stock ) { |
|
| 84 | + $stock = Redux_Social_Profiles_Defaults::get_social_media_defaults(); |
|
| 85 | + $stock = Redux_Social_Profiles_Functions::add_extra_icons( $stock ); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + foreach ( $stock as $def_arr ) { |
|
| 89 | + if ( $default_id === $def_arr['id'] ) { |
|
| 90 | + $fixed_arr[ $key ] = $def_arr; |
|
| 91 | + break; |
|
| 92 | + } |
|
| 93 | + } |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return $fixed_arr; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Field Render Function. |
|
| 102 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 103 | + * |
|
| 104 | + * @since 1.0.0 |
|
| 105 | + * @access public |
|
| 106 | + * @return void |
|
| 107 | + */ |
|
| 108 | + public function render() { |
|
| 109 | + if ( empty( $this->field ) ) { |
|
| 110 | + return; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + global $pagenow, $post; |
|
| 114 | + |
|
| 115 | + $redux_settings = get_option( $this->opt_name ); |
|
| 116 | + $settings = $redux_settings[ $this->field_id ] ?? array(); |
|
| 117 | + |
|
| 118 | + if ( is_admin() && ( 'post-new.php' === $pagenow || 'post.php' === $pagenow ) ) { |
|
| 119 | + $post_settings = get_post_meta( $post->ID, $this->field_id, true ); |
|
| 120 | + |
|
| 121 | + if ( ! empty( $post_settings ) ) { |
|
| 122 | + $settings = $post_settings; |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + $color_pickers = $this->field['color_pickers'] ?? true; |
|
| 127 | + |
|
| 128 | + // Icon container. |
|
| 129 | + echo '<div |
|
| 130 | 130 | class="redux-social-profiles-container ' . esc_attr( $this->field['class'] ) . '" |
| 131 | 131 | data-opt-name="' . esc_attr( $this->opt_name ) . '" |
| 132 | 132 | data-id="' . esc_attr( $this->field_id ) . '" |
| 133 | 133 | >'; |
| 134 | 134 | |
| 135 | - $show_msg = $this->field['hide_widget_msg'] ?? true; |
|
| 135 | + $show_msg = $this->field['hide_widget_msg'] ?? true; |
|
| 136 | 136 | |
| 137 | - // translators: %1$s: Widget page HTML/URL. %s: widget admin URL. |
|
| 138 | - $def_msg = sprintf( esc_html__( 'Go to the %1$s page to add the Redux Social Widget to any active widget area.', 'redux-framework' ), sprintf( '<a href="%s">' . esc_html__( 'Widgets', 'redux-framework' ) . '</a> ', admin_url( 'widgets.php' ) ) ); |
|
| 137 | + // translators: %1$s: Widget page HTML/URL. %s: widget admin URL. |
|
| 138 | + $def_msg = sprintf( esc_html__( 'Go to the %1$s page to add the Redux Social Widget to any active widget area.', 'redux-framework' ), sprintf( '<a href="%s">' . esc_html__( 'Widgets', 'redux-framework' ) . '</a> ', admin_url( 'widgets.php' ) ) ); |
|
| 139 | 139 | |
| 140 | - $msg = $this->field['widget_msg'] ?? $def_msg; |
|
| 140 | + $msg = $this->field['widget_msg'] ?? $def_msg; |
|
| 141 | 141 | |
| 142 | - if ( ! $show_msg ) { |
|
| 143 | - echo '<div class="redux-social-profiles-header">'; |
|
| 144 | - echo $msg; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 145 | - echo '</div>'; |
|
| 146 | - } |
|
| 142 | + if ( ! $show_msg ) { |
|
| 143 | + echo '<div class="redux-social-profiles-header">'; |
|
| 144 | + echo $msg; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 145 | + echo '</div>'; |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - echo '<div class="redux-social-profiles-selector-container">'; |
|
| 149 | - echo '<ul id="redux-social-profiles-selector-list">'; |
|
| 148 | + echo '<div class="redux-social-profiles-selector-container">'; |
|
| 149 | + echo '<ul id="redux-social-profiles-selector-list">'; |
|
| 150 | 150 | |
| 151 | - $settings = $this->rebuild_setttings( $settings ); |
|
| 151 | + $settings = $this->rebuild_setttings( $settings ); |
|
| 152 | 152 | |
| 153 | - foreach ( $this->defaults as $key => $social_provider_default ) { |
|
| 154 | - $social_provider_option = ( $settings && is_array( $settings ) && array_key_exists( $key, $settings ) ) ? $settings[ $key ] : null; |
|
| 153 | + foreach ( $this->defaults as $key => $social_provider_default ) { |
|
| 154 | + $social_provider_option = ( $settings && is_array( $settings ) && array_key_exists( $key, $settings ) ) ? $settings[ $key ] : null; |
|
| 155 | 155 | |
| 156 | - $icon = ( $social_provider_option && array_key_exists( 'icon', $social_provider_option ) && $social_provider_option['icon'] ) ? $social_provider_option['icon'] : $social_provider_default['icon']; |
|
| 157 | - $name = ( $social_provider_option && array_key_exists( 'name', $social_provider_option ) && $social_provider_option['name'] ) ? $social_provider_option['name'] : $social_provider_default['name']; |
|
| 158 | - $class = ( $social_provider_option && array_key_exists( 'class', $social_provider_option ) && $social_provider_option['class'] ) ? $social_provider_option['class'] : $social_provider_default['class']; |
|
| 159 | - $order = ( $social_provider_option && array_key_exists( 'order', $social_provider_option ) ) ? $social_provider_option['order'] : $key; |
|
| 160 | - $order = intval( $order ); |
|
| 161 | - $enabled = ( $social_provider_option && array_key_exists( 'enabled', $social_provider_option ) && $social_provider_option['enabled'] ) ? $social_provider_option['enabled'] : $social_provider_default['enabled']; |
|
| 162 | - $display = ( $enabled ) ? 'enabled' : ''; |
|
| 156 | + $icon = ( $social_provider_option && array_key_exists( 'icon', $social_provider_option ) && $social_provider_option['icon'] ) ? $social_provider_option['icon'] : $social_provider_default['icon']; |
|
| 157 | + $name = ( $social_provider_option && array_key_exists( 'name', $social_provider_option ) && $social_provider_option['name'] ) ? $social_provider_option['name'] : $social_provider_default['name']; |
|
| 158 | + $class = ( $social_provider_option && array_key_exists( 'class', $social_provider_option ) && $social_provider_option['class'] ) ? $social_provider_option['class'] : $social_provider_default['class']; |
|
| 159 | + $order = ( $social_provider_option && array_key_exists( 'order', $social_provider_option ) ) ? $social_provider_option['order'] : $key; |
|
| 160 | + $order = intval( $order ); |
|
| 161 | + $enabled = ( $social_provider_option && array_key_exists( 'enabled', $social_provider_option ) && $social_provider_option['enabled'] ) ? $social_provider_option['enabled'] : $social_provider_default['enabled']; |
|
| 162 | + $display = ( $enabled ) ? 'enabled' : ''; |
|
| 163 | 163 | |
| 164 | - echo '<li class="redux-social-profiles-item-enable ' . esc_attr( $display ) . '" id="redux-social-profiles-item-enable-' . esc_attr( $key ) . '" data-key="' . esc_attr( $key ) . '" data-order="' . esc_attr( $order ) . '">'; |
|
| 165 | - Redux_Social_Profiles_Functions::render_icon( $class, $icon, '', '', $name ); |
|
| 166 | - echo '</li>'; |
|
| 167 | - } |
|
| 164 | + echo '<li class="redux-social-profiles-item-enable ' . esc_attr( $display ) . '" id="redux-social-profiles-item-enable-' . esc_attr( $key ) . '" data-key="' . esc_attr( $key ) . '" data-order="' . esc_attr( $order ) . '">'; |
|
| 165 | + Redux_Social_Profiles_Functions::render_icon( $class, $icon, '', '', $name ); |
|
| 166 | + echo '</li>'; |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - echo '</ul>'; |
|
| 170 | - echo '</div>'; |
|
| 169 | + echo '</ul>'; |
|
| 170 | + echo '</div>'; |
|
| 171 | 171 | |
| 172 | - echo '<ul id="redux-social-profiles-list">'; |
|
| 172 | + echo '<ul id="redux-social-profiles-list">'; |
|
| 173 | 173 | |
| 174 | - foreach ( $this->defaults as $key => $social_provider_default ) { |
|
| 175 | - echo '<li id="redux-social-item-' . esc_attr( $key ) . '" data-key="' . esc_attr( $key ) . '" style="display: none;">'; |
|
| 176 | - echo '<div class="redux-social-item-container">'; |
|
| 174 | + foreach ( $this->defaults as $key => $social_provider_default ) { |
|
| 175 | + echo '<li id="redux-social-item-' . esc_attr( $key ) . '" data-key="' . esc_attr( $key ) . '" style="display: none;">'; |
|
| 176 | + echo '<div class="redux-social-item-container">'; |
|
| 177 | 177 | |
| 178 | - $social_provider_option = ( $settings && is_array( $settings ) && array_key_exists( $key, $settings ) ) ? $settings[ $key ] : null; |
|
| 179 | - $icon = ( $social_provider_option && array_key_exists( 'icon', $social_provider_option ) && $social_provider_option['icon'] ) ? $social_provider_option['icon'] : $social_provider_default['icon']; |
|
| 180 | - $id = ( $social_provider_option && array_key_exists( 'id', $social_provider_option ) && $social_provider_option['id'] ) ? $social_provider_option['id'] : $social_provider_default['id']; |
|
| 181 | - $class = ( $social_provider_option && array_key_exists( 'class', $social_provider_option ) && $social_provider_option['class'] ) ? $social_provider_option['class'] : $social_provider_default['class']; |
|
| 182 | - $enabled = ( $social_provider_option && array_key_exists( 'enabled', $social_provider_option ) && $social_provider_option['enabled'] ) ? $social_provider_option['enabled'] : $social_provider_default['enabled']; |
|
| 183 | - $name = ( $social_provider_option && array_key_exists( 'name', $social_provider_option ) && $social_provider_option['name'] ) ? $social_provider_option['name'] : $social_provider_default['name']; |
|
| 178 | + $social_provider_option = ( $settings && is_array( $settings ) && array_key_exists( $key, $settings ) ) ? $settings[ $key ] : null; |
|
| 179 | + $icon = ( $social_provider_option && array_key_exists( 'icon', $social_provider_option ) && $social_provider_option['icon'] ) ? $social_provider_option['icon'] : $social_provider_default['icon']; |
|
| 180 | + $id = ( $social_provider_option && array_key_exists( 'id', $social_provider_option ) && $social_provider_option['id'] ) ? $social_provider_option['id'] : $social_provider_default['id']; |
|
| 181 | + $class = ( $social_provider_option && array_key_exists( 'class', $social_provider_option ) && $social_provider_option['class'] ) ? $social_provider_option['class'] : $social_provider_default['class']; |
|
| 182 | + $enabled = ( $social_provider_option && array_key_exists( 'enabled', $social_provider_option ) && $social_provider_option['enabled'] ) ? $social_provider_option['enabled'] : $social_provider_default['enabled']; |
|
| 183 | + $name = ( $social_provider_option && array_key_exists( 'name', $social_provider_option ) && $social_provider_option['name'] ) ? $social_provider_option['name'] : $social_provider_default['name']; |
|
| 184 | 184 | |
| 185 | - $label = ( $social_provider_option && array_key_exists( 'label', $social_provider_option ) && $social_provider_option['label'] ) ? $social_provider_option['label'] : __( 'Link URL', 'redux-framework' ); |
|
| 185 | + $label = ( $social_provider_option && array_key_exists( 'label', $social_provider_option ) && $social_provider_option['label'] ) ? $social_provider_option['label'] : __( 'Link URL', 'redux-framework' ); |
|
| 186 | 186 | |
| 187 | - $color = ( $social_provider_option && array_key_exists( 'color', $social_provider_option ) ) ? $social_provider_option['color'] : $social_provider_default['color']; |
|
| 188 | - $color = esc_attr( $color ); |
|
| 187 | + $color = ( $social_provider_option && array_key_exists( 'color', $social_provider_option ) ) ? $social_provider_option['color'] : $social_provider_default['color']; |
|
| 188 | + $color = esc_attr( $color ); |
|
| 189 | 189 | |
| 190 | - $background = ( $social_provider_option && array_key_exists( 'background', $social_provider_option ) ) ? $social_provider_option['background'] : $social_provider_default['background']; |
|
| 191 | - $background = esc_attr( $background ); |
|
| 190 | + $background = ( $social_provider_option && array_key_exists( 'background', $social_provider_option ) ) ? $social_provider_option['background'] : $social_provider_default['background']; |
|
| 191 | + $background = esc_attr( $background ); |
|
| 192 | 192 | |
| 193 | - $order = ( $social_provider_option && array_key_exists( 'order', $social_provider_option ) ) ? $social_provider_option['order'] : $key; |
|
| 194 | - $order = intval( $order ); |
|
| 193 | + $order = ( $social_provider_option && array_key_exists( 'order', $social_provider_option ) ) ? $social_provider_option['order'] : $key; |
|
| 194 | + $order = intval( $order ); |
|
| 195 | 195 | |
| 196 | - $url = ( $social_provider_option && array_key_exists( 'url', $social_provider_option ) ) ? $social_provider_option['url'] : $social_provider_default['url']; |
|
| 197 | - $url = esc_attr( $url ); |
|
| 196 | + $url = ( $social_provider_option && array_key_exists( 'url', $social_provider_option ) ) ? $social_provider_option['url'] : $social_provider_default['url']; |
|
| 197 | + $url = esc_attr( $url ); |
|
| 198 | 198 | |
| 199 | - $profile_data = array( |
|
| 200 | - 'id' => $id, |
|
| 201 | - 'class' => $class, |
|
| 202 | - 'icon' => $icon, |
|
| 203 | - 'enabled' => $enabled, |
|
| 204 | - 'url' => $url, |
|
| 205 | - 'color' => $color, |
|
| 206 | - 'background' => $background, |
|
| 207 | - 'order' => $order, |
|
| 208 | - 'name' => $name, |
|
| 209 | - 'label' => $label, |
|
| 210 | - ); |
|
| 199 | + $profile_data = array( |
|
| 200 | + 'id' => $id, |
|
| 201 | + 'class' => $class, |
|
| 202 | + 'icon' => $icon, |
|
| 203 | + 'enabled' => $enabled, |
|
| 204 | + 'url' => $url, |
|
| 205 | + 'color' => $color, |
|
| 206 | + 'background' => $background, |
|
| 207 | + 'order' => $order, |
|
| 208 | + 'name' => $name, |
|
| 209 | + 'label' => $label, |
|
| 210 | + ); |
|
| 211 | 211 | |
| 212 | - $profile_data = rawurlencode( wp_json_encode( $profile_data ) ); |
|
| 212 | + $profile_data = rawurlencode( wp_json_encode( $profile_data ) ); |
|
| 213 | 213 | |
| 214 | - echo '<input |
|
| 214 | + echo '<input |
|
| 215 | 215 | type="hidden" |
| 216 | 216 | class="redux-social-profiles-hidden-data-' . esc_attr( $key ) . '" |
| 217 | 217 | id="' . esc_attr( $this->field_id ) . '-' . esc_attr( $id ) . '-data" |
| 218 | 218 | name="' . esc_attr( $this->field['name'] ) . esc_attr( $this->field['name_suffix'] ) . '[' . esc_attr( $key ) . '][data]" |
| 219 | 219 | value="' . $profile_data . '" />'; // phpcs:ignore WordPress.Security.EscapeOutput |
| 220 | 220 | |
| 221 | - echo '<div class="redux-icon-preview">'; |
|
| 222 | - Redux_Social_Profiles_Functions::render_icon( $class, $icon, $color, $background, $name ); |
|
| 223 | - echo ' </div>'; |
|
| 221 | + echo '<div class="redux-icon-preview">'; |
|
| 222 | + Redux_Social_Profiles_Functions::render_icon( $class, $icon, $color, $background, $name ); |
|
| 223 | + echo ' </div>'; |
|
| 224 | 224 | |
| 225 | - echo '<div class="redux-social-profiles-item-name">'; |
|
| 226 | - echo esc_html( $name ); |
|
| 227 | - echo '</div>'; |
|
| 225 | + echo '<div class="redux-social-profiles-item-name">'; |
|
| 226 | + echo esc_html( $name ); |
|
| 227 | + echo '</div>'; |
|
| 228 | 228 | |
| 229 | - echo '<div class="redux-social-profiles-item-enabled">'; |
|
| 230 | - $checked = ( $enabled ) ? 'checked' : ''; |
|
| 231 | - echo '<input type="checkbox" id="' . esc_attr( $this->field['id'] ) . '-checkbox-' . esc_attr( $key ) . '" class="checkbox-' . esc_attr( $key ) . '" data-key="' . esc_attr( $key ) . '" value="1" ' . esc_attr( $checked ) . '/>'; |
|
| 232 | - esc_html_e( 'Enabled', 'redux-framework' ); |
|
| 233 | - echo '</div>'; |
|
| 229 | + echo '<div class="redux-social-profiles-item-enabled">'; |
|
| 230 | + $checked = ( $enabled ) ? 'checked' : ''; |
|
| 231 | + echo '<input type="checkbox" id="' . esc_attr( $this->field['id'] ) . '-checkbox-' . esc_attr( $key ) . '" class="checkbox-' . esc_attr( $key ) . '" data-key="' . esc_attr( $key ) . '" value="1" ' . esc_attr( $checked ) . '/>'; |
|
| 232 | + esc_html_e( 'Enabled', 'redux-framework' ); |
|
| 233 | + echo '</div>'; |
|
| 234 | 234 | |
| 235 | - $color_class = $color_pickers ? '' : ' no-color-pickers'; |
|
| 235 | + $color_class = $color_pickers ? '' : ' no-color-pickers'; |
|
| 236 | 236 | |
| 237 | - echo '<div class="redux-social-profiles-link-url input_wrapper' . esc_attr( $color_class ) . '">'; |
|
| 238 | - echo '<label for="redux-social-profiles-url-' . esc_attr( $key ) . '-text" class="redux-text-url-label">' . esc_html( $label ) . '</label>'; |
|
| 239 | - echo '<input id="redux-social-profiles-url-' . esc_attr( $key ) . '-text" class="redux-social-profiles-url-text" data-key="' . esc_attr( $key ) . '" type="text" value="' . esc_url( $url ) . '" />'; |
|
| 240 | - echo '</div>'; |
|
| 237 | + echo '<div class="redux-social-profiles-link-url input_wrapper' . esc_attr( $color_class ) . '">'; |
|
| 238 | + echo '<label for="redux-social-profiles-url-' . esc_attr( $key ) . '-text" class="redux-text-url-label">' . esc_html( $label ) . '</label>'; |
|
| 239 | + echo '<input id="redux-social-profiles-url-' . esc_attr( $key ) . '-text" class="redux-social-profiles-url-text" data-key="' . esc_attr( $key ) . '" type="text" value="' . esc_url( $url ) . '" />'; |
|
| 240 | + echo '</div>'; |
|
| 241 | 241 | |
| 242 | - $reset_text = __( 'Reset', 'redux-framework' ); |
|
| 243 | - echo '<div class="redux-social-profiles-item-reset">'; |
|
| 244 | - echo '<a class="button" data-value="' . esc_attr( $key ) . '" value="' . esc_attr( $reset_text ) . '" />' . esc_html( $reset_text ) . '</a>'; |
|
| 245 | - echo '</div>'; |
|
| 242 | + $reset_text = __( 'Reset', 'redux-framework' ); |
|
| 243 | + echo '<div class="redux-social-profiles-item-reset">'; |
|
| 244 | + echo '<a class="button" data-value="' . esc_attr( $key ) . '" value="' . esc_attr( $reset_text ) . '" />' . esc_html( $reset_text ) . '</a>'; |
|
| 245 | + echo '</div>'; |
|
| 246 | 246 | |
| 247 | - if ( $color_pickers ) { |
|
| 248 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 249 | - $label = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/color_picker/text', esc_html__( 'Text', 'redux-framework' ) ); |
|
| 247 | + if ( $color_pickers ) { |
|
| 248 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 249 | + $label = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/color_picker/text', esc_html__( 'Text', 'redux-framework' ) ); |
|
| 250 | 250 | |
| 251 | - echo '<div class="redux-social-profiles-text-color picker_wrapper" >'; |
|
| 252 | - echo '<label for="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' text" class="redux-text-color-label">' . esc_html( $label ) . '</label>'; |
|
| 253 | - echo '<input |
|
| 251 | + echo '<div class="redux-social-profiles-text-color picker_wrapper" >'; |
|
| 252 | + echo '<label for="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' text" class="redux-text-color-label">' . esc_html( $label ) . '</label>'; |
|
| 253 | + echo '<input |
|
| 254 | 254 | class="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' text" |
| 255 | 255 | id="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' text" |
| 256 | 256 | type="text" |
| 257 | 257 | value="' . esc_attr( $color ) . '" |
| 258 | 258 | data-key="' . esc_attr( $key ) . '" |
| 259 | 259 | />'; |
| 260 | - echo '</div>'; |
|
| 260 | + echo '</div>'; |
|
| 261 | 261 | |
| 262 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 263 | - $label = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/color_picker/background', esc_html__( 'Background', 'redux-framework' ) ); |
|
| 262 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 263 | + $label = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/color_picker/background', esc_html__( 'Background', 'redux-framework' ) ); |
|
| 264 | 264 | |
| 265 | - echo '<div class="redux-social-profiles-background-color picker_wrapper">'; |
|
| 266 | - echo '<label for="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' background" class="redux-background-color-label" for="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' background">' . esc_html( $label ) . '</label>'; |
|
| 267 | - echo '<input |
|
| 265 | + echo '<div class="redux-social-profiles-background-color picker_wrapper">'; |
|
| 266 | + echo '<label for="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' background" class="redux-background-color-label" for="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' background">' . esc_html( $label ) . '</label>'; |
|
| 267 | + echo '<input |
|
| 268 | 268 | class="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' background" |
| 269 | 269 | id="redux-social-profiles-color-picker-' . esc_attr( $key ) . ' background" |
| 270 | 270 | type="text" |
| 271 | 271 | value="' . esc_attr( $background ) . '" |
| 272 | 272 | data-key="' . esc_attr( $key ) . '" |
| 273 | 273 | />'; |
| 274 | - echo '</div>'; |
|
| 275 | - } |
|
| 274 | + echo '</div>'; |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - echo '<div class="redux-social-profiles-item-order">'; |
|
| 278 | - echo '<input |
|
| 277 | + echo '<div class="redux-social-profiles-item-order">'; |
|
| 278 | + echo '<input |
|
| 279 | 279 | id="' . esc_attr( $this->field['id'] ) . '-item-order-' . esc_attr( $key ) . '" |
| 280 | 280 | type="hidden" |
| 281 | 281 | value="' . esc_attr( $order ) . '" |
| 282 | 282 | />'; |
| 283 | - echo '</div>'; |
|
| 284 | - |
|
| 285 | - echo '</div>'; |
|
| 286 | - echo '</li>'; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - echo '</ul>'; |
|
| 290 | - echo '</div>'; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * This function is unused, but necessary to trigger output. |
|
| 295 | - * |
|
| 296 | - * @param mixed $data CSS data. |
|
| 297 | - * |
|
| 298 | - * @return mixed|string|void |
|
| 299 | - */ |
|
| 300 | - public function css_style( $data ) { |
|
| 301 | - return $data; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Used to enqueue to the front-end |
|
| 306 | - * |
|
| 307 | - * @param string|null|array $style Style. |
|
| 308 | - */ |
|
| 309 | - public function output( $style = '' ) { |
|
| 310 | - if ( ! empty( $this->value ) ) { |
|
| 311 | - foreach ( $this->value as $arr ) { |
|
| 312 | - |
|
| 313 | - // For customizer. |
|
| 314 | - if ( isset( $arr['data'] ) ) { |
|
| 315 | - $arr = rawurldecode( $arr['data'] ); |
|
| 316 | - $arr = (array) json_decode( $arr ); |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - if ( $arr['enabled'] ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement |
|
| 320 | - Redux_Functions_Ex::enqueue_font_awesome(); |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - /** |
|
| 327 | - * Enqueue Function. |
|
| 328 | - * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 329 | - * |
|
| 330 | - * @since 1.0.0 |
|
| 331 | - * @access public |
|
| 332 | - * @return void |
|
| 333 | - */ |
|
| 334 | - public function enqueue() { |
|
| 335 | - if ( empty( $this->field ) ) { |
|
| 336 | - return; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - $min = Redux_Functions::isMin(); |
|
| 340 | - |
|
| 341 | - Redux_Functions_Ex::enqueue_font_awesome(); |
|
| 342 | - |
|
| 343 | - // Field dependent JS. |
|
| 344 | - wp_enqueue_script( |
|
| 345 | - 'redux-field-social-profiles', |
|
| 346 | - $this->url . 'redux-social-profiles' . $min . '.js', |
|
| 347 | - array( 'jquery', 'jquery-ui-sortable', 'redux-spectrum-js', 'redux-js' ), |
|
| 348 | - Redux_Extension_Social_Profiles::$version, |
|
| 349 | - true |
|
| 350 | - ); |
|
| 351 | - |
|
| 352 | - wp_localize_script( |
|
| 353 | - 'redux-field-social-profiles', |
|
| 354 | - 'reduxSocialDefaults', |
|
| 355 | - $this->defaults |
|
| 356 | - ); |
|
| 357 | - |
|
| 358 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 359 | - wp_enqueue_style( |
|
| 360 | - 'redux-field-social-profiles', |
|
| 361 | - $this->url . 'redux-social-profiles.css', |
|
| 362 | - array( 'redux-spectrum-css' ), |
|
| 363 | - Redux_Extension_Social_Profiles::$version |
|
| 364 | - ); |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - } |
|
| 283 | + echo '</div>'; |
|
| 284 | + |
|
| 285 | + echo '</div>'; |
|
| 286 | + echo '</li>'; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + echo '</ul>'; |
|
| 290 | + echo '</div>'; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * This function is unused, but necessary to trigger output. |
|
| 295 | + * |
|
| 296 | + * @param mixed $data CSS data. |
|
| 297 | + * |
|
| 298 | + * @return mixed|string|void |
|
| 299 | + */ |
|
| 300 | + public function css_style( $data ) { |
|
| 301 | + return $data; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Used to enqueue to the front-end |
|
| 306 | + * |
|
| 307 | + * @param string|null|array $style Style. |
|
| 308 | + */ |
|
| 309 | + public function output( $style = '' ) { |
|
| 310 | + if ( ! empty( $this->value ) ) { |
|
| 311 | + foreach ( $this->value as $arr ) { |
|
| 312 | + |
|
| 313 | + // For customizer. |
|
| 314 | + if ( isset( $arr['data'] ) ) { |
|
| 315 | + $arr = rawurldecode( $arr['data'] ); |
|
| 316 | + $arr = (array) json_decode( $arr ); |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + if ( $arr['enabled'] ) { // phpcs:ignore Generic.CodeAnalysis.EmptyStatement |
|
| 320 | + Redux_Functions_Ex::enqueue_font_awesome(); |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + /** |
|
| 327 | + * Enqueue Function. |
|
| 328 | + * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 329 | + * |
|
| 330 | + * @since 1.0.0 |
|
| 331 | + * @access public |
|
| 332 | + * @return void |
|
| 333 | + */ |
|
| 334 | + public function enqueue() { |
|
| 335 | + if ( empty( $this->field ) ) { |
|
| 336 | + return; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + $min = Redux_Functions::isMin(); |
|
| 340 | + |
|
| 341 | + Redux_Functions_Ex::enqueue_font_awesome(); |
|
| 342 | + |
|
| 343 | + // Field dependent JS. |
|
| 344 | + wp_enqueue_script( |
|
| 345 | + 'redux-field-social-profiles', |
|
| 346 | + $this->url . 'redux-social-profiles' . $min . '.js', |
|
| 347 | + array( 'jquery', 'jquery-ui-sortable', 'redux-spectrum-js', 'redux-js' ), |
|
| 348 | + Redux_Extension_Social_Profiles::$version, |
|
| 349 | + true |
|
| 350 | + ); |
|
| 351 | + |
|
| 352 | + wp_localize_script( |
|
| 353 | + 'redux-field-social-profiles', |
|
| 354 | + 'reduxSocialDefaults', |
|
| 355 | + $this->defaults |
|
| 356 | + ); |
|
| 357 | + |
|
| 358 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 359 | + wp_enqueue_style( |
|
| 360 | + 'redux-field-social-profiles', |
|
| 361 | + $this->url . 'redux-social-profiles.css', |
|
| 362 | + array( 'redux-spectrum-css' ), |
|
| 363 | + Redux_Extension_Social_Profiles::$version |
|
| 364 | + ); |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | 368 | } |
@@ -15,272 +15,272 @@ |
||
| 15 | 15 | if ( ! class_exists( 'Redux_Extension_Social_Profiles' ) ) { |
| 16 | 16 | |
| 17 | 17 | |
| 18 | - /** |
|
| 19 | - * Main ReduxFramework social profiles extension class |
|
| 20 | - * |
|
| 21 | - * @since 1.0.0 |
|
| 22 | - */ |
|
| 23 | - class Redux_Extension_Social_Profiles extends Redux_Extension_Abstract { |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * Extension version. |
|
| 27 | - * |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - public static $version = '4.5.8'; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Extension friendly name. |
|
| 34 | - * |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 37 | - public string $extension_name = 'Social Profiles'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * Field ID. |
|
| 41 | - * |
|
| 42 | - * @var mixed|null |
|
| 43 | - */ |
|
| 44 | - private $field_id = null; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Field array. |
|
| 48 | - * |
|
| 49 | - * @var array|null |
|
| 50 | - */ |
|
| 51 | - public ?array $field = array(); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Panel opt_name. |
|
| 55 | - * |
|
| 56 | - * @var string |
|
| 57 | - */ |
|
| 58 | - public string $opt_name; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * Class Constructor. Defines the args for the extensions class |
|
| 62 | - * |
|
| 63 | - * @since 1.0.0 |
|
| 64 | - * @access public |
|
| 65 | - * |
|
| 66 | - * @param ReduxFramework $redux Parent settings. |
|
| 67 | - * |
|
| 68 | - * @return void |
|
| 69 | - */ |
|
| 70 | - public function __construct( $redux ) { |
|
| 71 | - parent::__construct( $redux, __FILE__ ); |
|
| 72 | - |
|
| 73 | - $this->add_field( 'social_profiles' ); |
|
| 74 | - |
|
| 75 | - require_once __DIR__ . '/redux-social-profiles-helpers.php'; |
|
| 76 | - |
|
| 77 | - include_once 'social_profiles/inc/class-redux-social-profiles-defaults.php'; |
|
| 78 | - include_once 'social_profiles/inc/class-redux-social-profiles-functions.php'; |
|
| 79 | - |
|
| 80 | - Redux_Social_Profiles_Functions::init( $redux ); |
|
| 81 | - |
|
| 82 | - $this->field = Redux_Social_Profiles_Functions::get_field( $redux ); |
|
| 83 | - |
|
| 84 | - if ( ! is_array( $this->field ) ) { |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $this->field_id = $this->field['id']; |
|
| 89 | - $this->opt_name = $redux->args['opt_name']; |
|
| 90 | - |
|
| 91 | - $upload_dir = Redux_Social_Profiles_Functions::$upload_dir; |
|
| 92 | - |
|
| 93 | - if ( ! is_dir( $upload_dir ) ) { |
|
| 94 | - Redux_Core::$filesystem->execute( 'mkdir', $upload_dir ); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - if ( ! class_exists( 'Redux_Social_Profiles_Widget' ) ) { |
|
| 98 | - $enable = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/widget/enable', true ); // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 99 | - |
|
| 100 | - if ( $enable ) { |
|
| 101 | - include_once 'social_profiles/inc/class-redux-social-profiles-widget.php'; |
|
| 102 | - new Redux_Social_Profiles_Widget( $redux, $this->field_id ); |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - if ( ! class_exists( 'Redux_Social_Profiles_Shortcode' ) ) { |
|
| 107 | - $enable = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/shortcode/enable', true ); // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 108 | - |
|
| 109 | - if ( $enable ) { |
|
| 110 | - include_once 'social_profiles/inc/class-redux-social-profiles-shortcode.php'; |
|
| 111 | - new Redux_Social_Profiles_Shortcode( $redux, $this->field_id ); |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); |
|
| 116 | - |
|
| 117 | - add_filter( "redux/options/{$this->parent->args['opt_name']}/defaults", array( $this, 'set_defaults' ) ); |
|
| 118 | - add_action( 'redux/validate/' . $this->parent->args['opt_name'] . '/before_validation', array( $this, 'save_me' ), 0, 3 ); |
|
| 119 | - add_filter( 'redux/metaboxes/save/before_validate', array( $this, 'save_me' ), 0, 3 ); |
|
| 120 | - |
|
| 121 | - // Reset hooks. |
|
| 122 | - add_action( 'redux/validate/' . $this->parent->args['opt_name'] . '/defaults', array( $this, 'reset_defaults' ), 0, 3 ); |
|
| 123 | - add_action( 'redux/validate/' . $this->parent->args['opt_name'] . '/defaults_section', array( $this, 'reset_defaults_section' ), 0, 3 ); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Reset section defaults. |
|
| 128 | - * |
|
| 129 | - * @param array $defaults Default values. |
|
| 130 | - * |
|
| 131 | - * @return array |
|
| 132 | - */ |
|
| 133 | - public function reset_defaults_section( array $defaults = array() ): array { |
|
| 134 | - if ( isset( $_COOKIE[ 'redux_current_tab_' . $this->parent->args['opt_name'] ] ) ) { |
|
| 135 | - $cur_tab = sanitize_title( wp_unslash( $_COOKIE[ 'redux_current_tab_' . $this->parent->args['opt_name'] ] ) ); |
|
| 136 | - $tab_num = strval( $this->parent->field_sections['social_profiles'][ $this->field_id ] ); |
|
| 137 | - |
|
| 138 | - if ( $cur_tab === $tab_num ) { |
|
| 139 | - if ( '' !== $this->field_id && isset( $this->parent->options_defaults[ $this->field_id ] ) ) { |
|
| 140 | - $data = Redux_Social_Profiles_Functions::get_default_data(); |
|
| 141 | - |
|
| 142 | - Redux_Social_Profiles_Functions::write_data_file( $data ); |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $defaults[ $this->field_id ] = Redux_Social_Profiles_Functions::read_data_file(); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return $defaults; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Reset defaults. |
|
| 154 | - * |
|
| 155 | - * @param array $defaults Default values. |
|
| 156 | - * |
|
| 157 | - * @return array |
|
| 158 | - */ |
|
| 159 | - public function reset_defaults( array $defaults = array() ): array { |
|
| 160 | - if ( '' !== $this->field_id && isset( $this->parent->options_defaults[ $this->field_id ] ) ) { |
|
| 161 | - $data = Redux_Social_Profiles_Functions::get_default_data(); |
|
| 162 | - |
|
| 163 | - Redux_Social_Profiles_Functions::write_data_file( $data ); |
|
| 164 | - |
|
| 165 | - $defaults[ $this->field_id ] = $data; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - return $defaults; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Set default values. |
|
| 173 | - * |
|
| 174 | - * @param array $defaults Default values. |
|
| 175 | - * |
|
| 176 | - * @return array |
|
| 177 | - */ |
|
| 178 | - public function set_defaults( array $defaults = array() ): array { |
|
| 179 | - if ( empty( $this->field_id ) ) { |
|
| 180 | - return $defaults; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $comp_file = Redux_Social_Profiles_Functions::get_data_path(); |
|
| 184 | - |
|
| 185 | - if ( ! file_exists( $comp_file ) ) { |
|
| 186 | - $data = Redux_Social_Profiles_Functions::get_default_data(); |
|
| 187 | - |
|
| 188 | - Redux_Social_Profiles_Functions::write_data_file( $data ); |
|
| 189 | - |
|
| 190 | - $this->parent->options[ $this->field_id ] = $data; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - return $defaults; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - /** |
|
| 197 | - * Save Data. |
|
| 198 | - * |
|
| 199 | - * @param array $saved_options Saved options. |
|
| 200 | - * @param array $changed_values Changed values. |
|
| 201 | - * |
|
| 202 | - * @return array |
|
| 203 | - */ |
|
| 204 | - public function save_me( array $saved_options = array(), array $changed_values = array() ): array { |
|
| 205 | - if ( empty( $this->field ) ) { |
|
| 206 | - $this->field = Redux_Social_Profiles_Functions::get_field(); |
|
| 207 | - $this->field_id = $this->field['id']; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - if ( ! isset( $saved_options[ $this->field_id ] ) || empty( $saved_options[ $this->field_id ] ) || ( is_array( $saved_options[ $this->field_id ] ) && $saved_options === $changed_values ) || ! array_key_exists( $this->field_id, $saved_options ) ) { |
|
| 211 | - return $saved_options; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - // We'll use the reset hook instead. |
|
| 215 | - if ( ! empty( $saved_options['defaults'] ) || ! empty( $saved_options['defaults-section'] ) ) { |
|
| 216 | - return $saved_options; |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - $first_value = reset( $saved_options[ $this->field_id ] ); // First Element's Value. |
|
| 220 | - |
|
| 221 | - if ( isset( $first_value['data'] ) ) { |
|
| 222 | - $raw_data = $saved_options[ $this->field_id ]; |
|
| 223 | - |
|
| 224 | - $save_data = array(); |
|
| 225 | - |
|
| 226 | - // Enum through saved data. |
|
| 227 | - foreach ( $raw_data as $val ) { |
|
| 228 | - if ( is_array( $val ) ) { |
|
| 229 | - |
|
| 230 | - if ( ! isset( $val['data'] ) ) { |
|
| 231 | - return array(); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - $data = json_decode( rawurldecode( $val['data'] ), true ); |
|
| 235 | - |
|
| 236 | - $save_data[] = array( |
|
| 237 | - 'id' => $data['id'], |
|
| 238 | - 'class' => $data['class'] ?? 'fa', |
|
| 239 | - 'icon' => $data['icon'], |
|
| 240 | - 'enabled' => $data['enabled'], |
|
| 241 | - 'url' => $data['url'], |
|
| 242 | - 'color' => $data['color'], |
|
| 243 | - 'background' => $data['background'], |
|
| 244 | - 'order' => $data['order'], |
|
| 245 | - 'name' => $data['name'], |
|
| 246 | - 'label' => $data['label'], |
|
| 247 | - ); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $save_file = false; |
|
| 252 | - |
|
| 253 | - if ( ! isset( $old_options[ $this->field_id ] ) || ( isset( $old_options[ $this->field_id ] ) && ! empty( $old_options[ $this->field_id ] ) ) ) { |
|
| 254 | - $save_file = true; |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - if ( ! empty( $old_options[ $this->field_id ] ) && $old_options[ $this->field_id ] !== $saved_options[ $this->field_id ] ) { |
|
| 258 | - $save_file = true; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if ( $save_file ) { |
|
| 262 | - Redux_Social_Profiles_Functions::write_data_file( $save_data ); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - $saved_options[ $this->field_id ] = $save_data; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - return $saved_options; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Enqueue scripts/styles. |
|
| 273 | - */ |
|
| 274 | - public function enqueue_styles() { |
|
| 275 | - // Field CSS. |
|
| 276 | - wp_enqueue_style( |
|
| 277 | - 'redux-field-social-profiles-frontend', |
|
| 278 | - $this->extension_url . 'social_profiles/css/field_social_profiles_frontend.css', |
|
| 279 | - array(), |
|
| 280 | - self::$version |
|
| 281 | - ); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - class_alias( Redux_Extension_Social_Profiles::class, 'ReduxFramework_Extension_social_profiles' ); |
|
| 18 | + /** |
|
| 19 | + * Main ReduxFramework social profiles extension class |
|
| 20 | + * |
|
| 21 | + * @since 1.0.0 |
|
| 22 | + */ |
|
| 23 | + class Redux_Extension_Social_Profiles extends Redux_Extension_Abstract { |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * Extension version. |
|
| 27 | + * |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + public static $version = '4.5.8'; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Extension friendly name. |
|
| 34 | + * |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | + public string $extension_name = 'Social Profiles'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * Field ID. |
|
| 41 | + * |
|
| 42 | + * @var mixed|null |
|
| 43 | + */ |
|
| 44 | + private $field_id = null; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Field array. |
|
| 48 | + * |
|
| 49 | + * @var array|null |
|
| 50 | + */ |
|
| 51 | + public ?array $field = array(); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Panel opt_name. |
|
| 55 | + * |
|
| 56 | + * @var string |
|
| 57 | + */ |
|
| 58 | + public string $opt_name; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * Class Constructor. Defines the args for the extensions class |
|
| 62 | + * |
|
| 63 | + * @since 1.0.0 |
|
| 64 | + * @access public |
|
| 65 | + * |
|
| 66 | + * @param ReduxFramework $redux Parent settings. |
|
| 67 | + * |
|
| 68 | + * @return void |
|
| 69 | + */ |
|
| 70 | + public function __construct( $redux ) { |
|
| 71 | + parent::__construct( $redux, __FILE__ ); |
|
| 72 | + |
|
| 73 | + $this->add_field( 'social_profiles' ); |
|
| 74 | + |
|
| 75 | + require_once __DIR__ . '/redux-social-profiles-helpers.php'; |
|
| 76 | + |
|
| 77 | + include_once 'social_profiles/inc/class-redux-social-profiles-defaults.php'; |
|
| 78 | + include_once 'social_profiles/inc/class-redux-social-profiles-functions.php'; |
|
| 79 | + |
|
| 80 | + Redux_Social_Profiles_Functions::init( $redux ); |
|
| 81 | + |
|
| 82 | + $this->field = Redux_Social_Profiles_Functions::get_field( $redux ); |
|
| 83 | + |
|
| 84 | + if ( ! is_array( $this->field ) ) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $this->field_id = $this->field['id']; |
|
| 89 | + $this->opt_name = $redux->args['opt_name']; |
|
| 90 | + |
|
| 91 | + $upload_dir = Redux_Social_Profiles_Functions::$upload_dir; |
|
| 92 | + |
|
| 93 | + if ( ! is_dir( $upload_dir ) ) { |
|
| 94 | + Redux_Core::$filesystem->execute( 'mkdir', $upload_dir ); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + if ( ! class_exists( 'Redux_Social_Profiles_Widget' ) ) { |
|
| 98 | + $enable = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/widget/enable', true ); // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 99 | + |
|
| 100 | + if ( $enable ) { |
|
| 101 | + include_once 'social_profiles/inc/class-redux-social-profiles-widget.php'; |
|
| 102 | + new Redux_Social_Profiles_Widget( $redux, $this->field_id ); |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + if ( ! class_exists( 'Redux_Social_Profiles_Shortcode' ) ) { |
|
| 107 | + $enable = apply_filters( 'redux/extensions/social_profiles/' . $this->opt_name . '/shortcode/enable', true ); // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 108 | + |
|
| 109 | + if ( $enable ) { |
|
| 110 | + include_once 'social_profiles/inc/class-redux-social-profiles-shortcode.php'; |
|
| 111 | + new Redux_Social_Profiles_Shortcode( $redux, $this->field_id ); |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) ); |
|
| 116 | + |
|
| 117 | + add_filter( "redux/options/{$this->parent->args['opt_name']}/defaults", array( $this, 'set_defaults' ) ); |
|
| 118 | + add_action( 'redux/validate/' . $this->parent->args['opt_name'] . '/before_validation', array( $this, 'save_me' ), 0, 3 ); |
|
| 119 | + add_filter( 'redux/metaboxes/save/before_validate', array( $this, 'save_me' ), 0, 3 ); |
|
| 120 | + |
|
| 121 | + // Reset hooks. |
|
| 122 | + add_action( 'redux/validate/' . $this->parent->args['opt_name'] . '/defaults', array( $this, 'reset_defaults' ), 0, 3 ); |
|
| 123 | + add_action( 'redux/validate/' . $this->parent->args['opt_name'] . '/defaults_section', array( $this, 'reset_defaults_section' ), 0, 3 ); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Reset section defaults. |
|
| 128 | + * |
|
| 129 | + * @param array $defaults Default values. |
|
| 130 | + * |
|
| 131 | + * @return array |
|
| 132 | + */ |
|
| 133 | + public function reset_defaults_section( array $defaults = array() ): array { |
|
| 134 | + if ( isset( $_COOKIE[ 'redux_current_tab_' . $this->parent->args['opt_name'] ] ) ) { |
|
| 135 | + $cur_tab = sanitize_title( wp_unslash( $_COOKIE[ 'redux_current_tab_' . $this->parent->args['opt_name'] ] ) ); |
|
| 136 | + $tab_num = strval( $this->parent->field_sections['social_profiles'][ $this->field_id ] ); |
|
| 137 | + |
|
| 138 | + if ( $cur_tab === $tab_num ) { |
|
| 139 | + if ( '' !== $this->field_id && isset( $this->parent->options_defaults[ $this->field_id ] ) ) { |
|
| 140 | + $data = Redux_Social_Profiles_Functions::get_default_data(); |
|
| 141 | + |
|
| 142 | + Redux_Social_Profiles_Functions::write_data_file( $data ); |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + $defaults[ $this->field_id ] = Redux_Social_Profiles_Functions::read_data_file(); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return $defaults; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Reset defaults. |
|
| 154 | + * |
|
| 155 | + * @param array $defaults Default values. |
|
| 156 | + * |
|
| 157 | + * @return array |
|
| 158 | + */ |
|
| 159 | + public function reset_defaults( array $defaults = array() ): array { |
|
| 160 | + if ( '' !== $this->field_id && isset( $this->parent->options_defaults[ $this->field_id ] ) ) { |
|
| 161 | + $data = Redux_Social_Profiles_Functions::get_default_data(); |
|
| 162 | + |
|
| 163 | + Redux_Social_Profiles_Functions::write_data_file( $data ); |
|
| 164 | + |
|
| 165 | + $defaults[ $this->field_id ] = $data; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + return $defaults; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Set default values. |
|
| 173 | + * |
|
| 174 | + * @param array $defaults Default values. |
|
| 175 | + * |
|
| 176 | + * @return array |
|
| 177 | + */ |
|
| 178 | + public function set_defaults( array $defaults = array() ): array { |
|
| 179 | + if ( empty( $this->field_id ) ) { |
|
| 180 | + return $defaults; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $comp_file = Redux_Social_Profiles_Functions::get_data_path(); |
|
| 184 | + |
|
| 185 | + if ( ! file_exists( $comp_file ) ) { |
|
| 186 | + $data = Redux_Social_Profiles_Functions::get_default_data(); |
|
| 187 | + |
|
| 188 | + Redux_Social_Profiles_Functions::write_data_file( $data ); |
|
| 189 | + |
|
| 190 | + $this->parent->options[ $this->field_id ] = $data; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + return $defaults; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + /** |
|
| 197 | + * Save Data. |
|
| 198 | + * |
|
| 199 | + * @param array $saved_options Saved options. |
|
| 200 | + * @param array $changed_values Changed values. |
|
| 201 | + * |
|
| 202 | + * @return array |
|
| 203 | + */ |
|
| 204 | + public function save_me( array $saved_options = array(), array $changed_values = array() ): array { |
|
| 205 | + if ( empty( $this->field ) ) { |
|
| 206 | + $this->field = Redux_Social_Profiles_Functions::get_field(); |
|
| 207 | + $this->field_id = $this->field['id']; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + if ( ! isset( $saved_options[ $this->field_id ] ) || empty( $saved_options[ $this->field_id ] ) || ( is_array( $saved_options[ $this->field_id ] ) && $saved_options === $changed_values ) || ! array_key_exists( $this->field_id, $saved_options ) ) { |
|
| 211 | + return $saved_options; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + // We'll use the reset hook instead. |
|
| 215 | + if ( ! empty( $saved_options['defaults'] ) || ! empty( $saved_options['defaults-section'] ) ) { |
|
| 216 | + return $saved_options; |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + $first_value = reset( $saved_options[ $this->field_id ] ); // First Element's Value. |
|
| 220 | + |
|
| 221 | + if ( isset( $first_value['data'] ) ) { |
|
| 222 | + $raw_data = $saved_options[ $this->field_id ]; |
|
| 223 | + |
|
| 224 | + $save_data = array(); |
|
| 225 | + |
|
| 226 | + // Enum through saved data. |
|
| 227 | + foreach ( $raw_data as $val ) { |
|
| 228 | + if ( is_array( $val ) ) { |
|
| 229 | + |
|
| 230 | + if ( ! isset( $val['data'] ) ) { |
|
| 231 | + return array(); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + $data = json_decode( rawurldecode( $val['data'] ), true ); |
|
| 235 | + |
|
| 236 | + $save_data[] = array( |
|
| 237 | + 'id' => $data['id'], |
|
| 238 | + 'class' => $data['class'] ?? 'fa', |
|
| 239 | + 'icon' => $data['icon'], |
|
| 240 | + 'enabled' => $data['enabled'], |
|
| 241 | + 'url' => $data['url'], |
|
| 242 | + 'color' => $data['color'], |
|
| 243 | + 'background' => $data['background'], |
|
| 244 | + 'order' => $data['order'], |
|
| 245 | + 'name' => $data['name'], |
|
| 246 | + 'label' => $data['label'], |
|
| 247 | + ); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $save_file = false; |
|
| 252 | + |
|
| 253 | + if ( ! isset( $old_options[ $this->field_id ] ) || ( isset( $old_options[ $this->field_id ] ) && ! empty( $old_options[ $this->field_id ] ) ) ) { |
|
| 254 | + $save_file = true; |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + if ( ! empty( $old_options[ $this->field_id ] ) && $old_options[ $this->field_id ] !== $saved_options[ $this->field_id ] ) { |
|
| 258 | + $save_file = true; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if ( $save_file ) { |
|
| 262 | + Redux_Social_Profiles_Functions::write_data_file( $save_data ); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + $saved_options[ $this->field_id ] = $save_data; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + return $saved_options; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Enqueue scripts/styles. |
|
| 273 | + */ |
|
| 274 | + public function enqueue_styles() { |
|
| 275 | + // Field CSS. |
|
| 276 | + wp_enqueue_style( |
|
| 277 | + 'redux-field-social-profiles-frontend', |
|
| 278 | + $this->extension_url . 'social_profiles/css/field_social_profiles_frontend.css', |
|
| 279 | + array(), |
|
| 280 | + self::$version |
|
| 281 | + ); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + class_alias( Redux_Extension_Social_Profiles::class, 'ReduxFramework_Extension_social_profiles' ); |
|
| 286 | 286 | } |
@@ -16,82 +16,82 @@ |
||
| 16 | 16 | require_once Redux_Core::$dir . 'inc/extensions/icon_select/font-awesome-5-free.php'; |
| 17 | 17 | |
| 18 | 18 | Redux::set_section( |
| 19 | - $opt_name, |
|
| 20 | - array( |
|
| 21 | - 'title' => esc_html__( 'Icon Select', 'your-textdomain-here' ), |
|
| 22 | - 'desc' => esc_html__( 'For full documentation on this field, visit: ', 'your-textdomain-here' ) . '<a href="https://devs.redux.io/core-extensions/icon-select.html" target="_blank">https://devs.redux.io/core-extensions/icon-select.html</a>', |
|
| 23 | - 'subsection' => true, |
|
| 24 | - 'fields' => array( |
|
| 19 | + $opt_name, |
|
| 20 | + array( |
|
| 21 | + 'title' => esc_html__( 'Icon Select', 'your-textdomain-here' ), |
|
| 22 | + 'desc' => esc_html__( 'For full documentation on this field, visit: ', 'your-textdomain-here' ) . '<a href="https://devs.redux.io/core-extensions/icon-select.html" target="_blank">https://devs.redux.io/core-extensions/icon-select.html</a>', |
|
| 23 | + 'subsection' => true, |
|
| 24 | + 'fields' => array( |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * This field was left in the sample config to display that every effort to maintain backward compatibility with older |
|
| 28 | - * versions of Icon Select has been implemented. |
|
| 29 | - * Please do NOT use argument in this field in your projects. |
|
| 30 | - * They are considered deprecated. |
|
| 31 | - */ |
|
| 32 | - array( |
|
| 33 | - 'id' => 'icon-select-legacy', |
|
| 34 | - 'type' => 'icon_select', |
|
| 35 | - 'title' => esc_html__( 'Legacy Icon Select', 'your-textdomain-here' ), |
|
| 36 | - 'subtitle' => esc_html__( 'Original Icon Select field that maintains backward compatibility with the original extension.', 'your-textdomain-here' ), |
|
| 37 | - 'default' => '', |
|
| 38 | - 'options' => redux_icon_select_fa_5_free(), |
|
| 26 | + /** |
|
| 27 | + * This field was left in the sample config to display that every effort to maintain backward compatibility with older |
|
| 28 | + * versions of Icon Select has been implemented. |
|
| 29 | + * Please do NOT use argument in this field in your projects. |
|
| 30 | + * They are considered deprecated. |
|
| 31 | + */ |
|
| 32 | + array( |
|
| 33 | + 'id' => 'icon-select-legacy', |
|
| 34 | + 'type' => 'icon_select', |
|
| 35 | + 'title' => esc_html__( 'Legacy Icon Select', 'your-textdomain-here' ), |
|
| 36 | + 'subtitle' => esc_html__( 'Original Icon Select field that maintains backward compatibility with the original extension.', 'your-textdomain-here' ), |
|
| 37 | + 'default' => '', |
|
| 38 | + 'options' => redux_icon_select_fa_5_free(), |
|
| 39 | 39 | |
| 40 | - // Disable auto-enqueue of stylesheet if present in the panel. |
|
| 41 | - 'enqueue' => true, |
|
| 40 | + // Disable auto-enqueue of stylesheet if present in the panel. |
|
| 41 | + 'enqueue' => true, |
|
| 42 | 42 | |
| 43 | - // Disable auto-enqueue of stylesheet on the front-end. |
|
| 44 | - 'enqueue_frontend' => true, |
|
| 43 | + // Disable auto-enqueue of stylesheet on the front-end. |
|
| 44 | + 'enqueue_frontend' => true, |
|
| 45 | 45 | |
| 46 | - // Stylesheet URL. |
|
| 47 | - //'stylesheet' => 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.css', |
|
| 46 | + // Stylesheet URL. |
|
| 47 | + //'stylesheet' => 'https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.9.0/css/all.css', |
|
| 48 | 48 | |
| 49 | - // (Optional) Specify a class prefix if one is needed to initialize the icon. |
|
| 50 | - 'prefix' => 'fa', |
|
| 51 | - ), |
|
| 49 | + // (Optional) Specify a class prefix if one is needed to initialize the icon. |
|
| 50 | + 'prefix' => 'fa', |
|
| 51 | + ), |
|
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * When creating fields for Icon Select, use this as a template instead. |
|
| 55 | - * For detailed documentation, see: https://devs.redux.io/core-extensions/icon-select.html |
|
| 56 | - */ |
|
| 57 | - array( |
|
| 58 | - 'id' => 'icon-select', |
|
| 59 | - 'type' => 'icon_select', |
|
| 60 | - 'title' => esc_html__( 'Icon Select', 'your-textdomain-here' ), |
|
| 61 | - 'subtitle' => esc_html__( 'Select an icon.', 'your-textdomain-here' ), |
|
| 62 | - 'default' => 'fas fa-1', |
|
| 53 | + /** |
|
| 54 | + * When creating fields for Icon Select, use this as a template instead. |
|
| 55 | + * For detailed documentation, see: https://devs.redux.io/core-extensions/icon-select.html |
|
| 56 | + */ |
|
| 57 | + array( |
|
| 58 | + 'id' => 'icon-select', |
|
| 59 | + 'type' => 'icon_select', |
|
| 60 | + 'title' => esc_html__( 'Icon Select', 'your-textdomain-here' ), |
|
| 61 | + 'subtitle' => esc_html__( 'Select an icon.', 'your-textdomain-here' ), |
|
| 62 | + 'default' => 'fas fa-1', |
|
| 63 | 63 | |
| 64 | - // Disable auto-enqueue of stylesheet if present in the panel. |
|
| 65 | - 'enqueue' => true, |
|
| 64 | + // Disable auto-enqueue of stylesheet if present in the panel. |
|
| 65 | + 'enqueue' => true, |
|
| 66 | 66 | |
| 67 | - // Disable auto-enqueue of stylesheet on the front-end. |
|
| 68 | - 'enqueue_frontend' => true, |
|
| 67 | + // Disable auto-enqueue of stylesheet on the front-end. |
|
| 68 | + 'enqueue_frontend' => true, |
|
| 69 | 69 | |
| 70 | - // Stylesheet data. |
|
| 71 | - 'stylesheet' => array( |
|
| 72 | - array( |
|
| 73 | - 'url' => 'https://cdnjs.cloudflare.com/ajax/libs/MaterialDesign-Webfont/7.2.96/css/materialdesignicons.css', |
|
| 74 | - 'title' => 'Material Icons', |
|
| 75 | - 'prefix' => 'mdi-set', |
|
| 76 | - ), |
|
| 77 | - array( |
|
| 78 | - 'url' => 'https://icons.getbootstrap.com/assets/font/bootstrap-icons.min.css', |
|
| 79 | - 'title' => 'Bootstrap', |
|
| 80 | - 'prefix' => 'bi', |
|
| 81 | - ), |
|
| 82 | - array( |
|
| 83 | - 'url' => 'https://cdn.lineicons.com/4.0/lineicons.css', |
|
| 84 | - 'title' => 'Line Icons', |
|
| 85 | - 'prefix' => 'lni', |
|
| 86 | - ), |
|
| 87 | - array( |
|
| 88 | - 'url' => 'https://cdn.jsdelivr.net/gh/devicons/[email protected]/devicon.min.css', |
|
| 89 | - 'title' => 'Dev Icons', |
|
| 90 | - 'prefix' => '', |
|
| 91 | - ), |
|
| 92 | - ), |
|
| 93 | - ), |
|
| 94 | - ), |
|
| 95 | - ) |
|
| 70 | + // Stylesheet data. |
|
| 71 | + 'stylesheet' => array( |
|
| 72 | + array( |
|
| 73 | + 'url' => 'https://cdnjs.cloudflare.com/ajax/libs/MaterialDesign-Webfont/7.2.96/css/materialdesignicons.css', |
|
| 74 | + 'title' => 'Material Icons', |
|
| 75 | + 'prefix' => 'mdi-set', |
|
| 76 | + ), |
|
| 77 | + array( |
|
| 78 | + 'url' => 'https://icons.getbootstrap.com/assets/font/bootstrap-icons.min.css', |
|
| 79 | + 'title' => 'Bootstrap', |
|
| 80 | + 'prefix' => 'bi', |
|
| 81 | + ), |
|
| 82 | + array( |
|
| 83 | + 'url' => 'https://cdn.lineicons.com/4.0/lineicons.css', |
|
| 84 | + 'title' => 'Line Icons', |
|
| 85 | + 'prefix' => 'lni', |
|
| 86 | + ), |
|
| 87 | + array( |
|
| 88 | + 'url' => 'https://cdn.jsdelivr.net/gh/devicons/[email protected]/devicon.min.css', |
|
| 89 | + 'title' => 'Dev Icons', |
|
| 90 | + 'prefix' => '', |
|
| 91 | + ), |
|
| 92 | + ), |
|
| 93 | + ), |
|
| 94 | + ), |
|
| 95 | + ) |
|
| 96 | 96 | ); |
| 97 | 97 | // phpcs:enable |