framework.php (18779B)
1 <?php // phpcs:ignore WordPress.Files.FileName 2 /** 3 * Redux Framework is free software: you can redistribute it and/or modify 4 * it under the terms of the GNU General Public License as published by 5 * the Free Software Foundation, either version 3 of the License, or 6 * any later version. 7 * 8 * Redux Framework is distributed in the hope that it will be useful, 9 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * GNU General Public License for more details. 12 * You should have received a copy of the GNU General Public License 13 * along with Redux Framework. If not, see <http://www.gnu.org/licenses/>. 14 * 15 * The addition of the noinspection tags is because there are devs writing their 16 * in-house extensions improperly, and we have to compensate for that. 17 * 18 * @package Redux_Framework 19 * @subpackage Core 20 * @subpackage Core 21 * @author Redux Framework Team 22 * 23 * @noinspection PhpMissingParamTypeInspection 24 * @noinspection PhpMissingReturnTypeInspection 25 */ 26 27 // Exit if accessed directly. 28 defined( 'ABSPATH' ) || exit; 29 30 require_once dirname( __FILE__ ) . '/class-redux-core.php'; 31 32 Redux_Core::$version = '4.3.1'; 33 Redux_Core::$redux_path = dirname( __FILE__ ); 34 Redux_Core::instance(); 35 36 // Don't duplicate me! 37 if ( ! class_exists( 'ReduxFramework', false ) ) { 38 39 /** 40 * Main ReduxFramework class 41 * 42 * @since 1.0.0 43 */ 44 class ReduxFramework { 45 46 /** 47 * ReduxFramework instance storage. 48 * 49 * @var null 50 * @access public 51 */ 52 public static $instance = null; 53 54 /** 55 * Redux current version. 56 * 57 * @var string 58 * @access public 59 */ 60 public static $_version = ''; // phpcs:ignore PSR2.Classes.PropertyDeclaration 61 62 /** 63 * Absolute directory of the Redux instance. 64 * 65 * @var string 66 * @access public 67 */ 68 public static $_dir = ''; // phpcs:ignore PSR2.Classes.PropertyDeclaration 69 70 /** 71 * Full URL of the Redux instance. 72 * 73 * @var string 74 * @access public 75 */ 76 public static $_url = ''; // phpcs:ignore PSR2.Classes.PropertyDeclaration 77 78 /** 79 * Current WordPress upload directory. 80 * 81 * @var string 82 * @access public 83 */ 84 public static $_upload_dir = ''; // phpcs:ignore PSR2.Classes.PropertyDeclaration 85 86 /** 87 * Current WordPress upload URL 88 * 89 * @var string 90 * @access public 91 */ 92 public static $_upload_url; // phpcs:ignore PSR2.Classes.PropertyDeclaration 93 94 /** 95 * Init 96 * 97 * Backward compatibility for previous version of Redux. 98 */ 99 public static function init() { 100 101 // Backward compatibility for extensions. 102 self::$_version = Redux_Core::$version; 103 self::$_dir = Redux_Core::$dir; 104 self::$_url = Redux_Core::$url; 105 self::$_upload_dir = Redux_Core::$upload_dir; 106 self::$_upload_url = Redux_Core::$upload_url; 107 self::$_as_plugin = Redux_Core::$as_plugin; 108 self::$_is_plugin = Redux_Core::$is_plugin; 109 } 110 111 /** 112 * Array of field arrays. 113 * 114 * @var array 115 */ 116 public $fields = array(); 117 118 /** 119 * Array of extensions by type used in the panel. 120 * 121 * @var array 122 */ 123 public $extensions = array(); 124 125 /** 126 * Array of sections and fields arrays. 127 * 128 * @var array|mixed|void 129 */ 130 public $sections = array(); 131 132 /** 133 * Array of generated errors from the panel for localization. 134 * 135 * @var array 136 */ 137 public $errors = array(); 138 139 /** 140 * Array of generated warnings from the panel for localization. 141 * 142 * @var array 143 */ 144 public $warnings = array(); 145 146 /** 147 * Array of generated sanitize notices from the panel for localization. 148 * 149 * @var array 150 */ 151 public $sanitize = array(); 152 153 /** 154 * Array of current option values. 155 * 156 * @var array 157 */ 158 public $options = array(); 159 160 /** 161 * Array of option defaults. 162 * 163 * @var null 164 */ 165 public $options_defaults = null; 166 167 /** 168 * Array of fields set to trigger the compiler hook. 169 * 170 * @var array 171 */ 172 public $compiler_fields = array(); 173 174 /** 175 * Field folding information for localization. 176 * 177 * @var array 178 */ 179 public $required = array(); 180 181 /** 182 * Field child folding information for localization. 183 * 184 * @var array 185 */ 186 public $required_child = array(); 187 188 /** 189 * Array of fonts used by the panel for localization. 190 * 191 * @var array 192 */ 193 public $fonts = array(); 194 195 /** 196 * Array of fields to be folded. 197 * 198 * @var array 199 */ 200 public $folds = array(); 201 202 /** 203 * Array of fields with CSS output selectors. 204 * 205 * @var array 206 */ 207 public $output = array(); 208 209 /** 210 * Autogenerated CSS appended to the header (snake case mantained for backward compatibility). 211 * 212 * @var string 213 */ 214 public $outputCSS = ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName 215 216 /** 217 * Autogenerated variables appended to dynamic output. 218 * 219 * @var array 220 */ 221 public $output_variables = array(); 222 223 /** 224 * CSS sent to the compiler hook (snake case maintained for backward compatibility). 225 * 226 * @var string 227 */ 228 public $compilerCSS = ''; // phpcs:ignore WordPress.NamingConventions.ValidVariableName 229 230 /** 231 * Array of fields that didn't pass the fold dependency test and are hidden. 232 * 233 * @var array 234 */ 235 public $fields_hidden = array(); 236 237 /** 238 * Array of fields to use as pointers in extensions. 239 * 240 * @var array 241 */ 242 public $field_sections = array(); 243 244 /** 245 * Values to generate google font CSS. 246 * 247 * @var string 248 */ 249 public $typography = array(); 250 251 /** 252 * Array of global arguments. 253 * 254 * @var array|mixed 255 */ 256 public $args = array(); 257 258 /** 259 * Used in customizer hooks. 260 * 261 * @var string 262 */ 263 public $old_opt_name = ''; 264 265 /** 266 * File system object usedfor I/O file operations. DOnr the WordPress way. 267 * 268 * @var null|object 269 */ 270 public $filesystem = null; 271 272 /** 273 * Array of various font groups used within the typography field. 274 * 275 * @var array 276 */ 277 public $font_groups = array(); 278 279 /** 280 * Pointer to the Redux_Options_Default class. 281 * 282 * @var null|Redux_Options_Defaults 283 */ 284 public $options_defaults_class = null; 285 286 /** 287 * Pointer to the Redux_Options class. 288 * 289 * @var null|Redux_Options 290 */ 291 public $options_class = null; 292 293 /** 294 * Pointer to the Redux_Required class 295 * 296 * @var null|Redux_Required 297 */ 298 public $required_class = null; 299 300 /** 301 * Pointer to the Redux_Output class. 302 * 303 * @var null|Redux_Output 304 */ 305 public $output_class = null; 306 307 /** 308 * Pointer to the Redux_Page_Render class. 309 * 310 * @var null|Redux_Page_Render 311 */ 312 public $render_class = null; 313 314 /** 315 * Pointer to the Redux_Enqueue class. 316 * 317 * @var null|Redux_Enqueue 318 */ 319 public $enqueue_class = null; 320 321 /** 322 * Pointer to the Redux_Transients class. 323 * 324 * @var null|Redux_Transients 325 */ 326 public $transient_class = null; 327 328 /** 329 * Pointer to the Redux_wordPress_Data class. 330 * 331 * @var null|Redux_WordPress_Data 332 */ 333 public $wordpress_data = null; 334 335 /** 336 * Poiner to the Redux_Validation class. 337 * 338 * @var null|Redux_Validation 339 */ 340 public $validate_class = null; 341 342 /** 343 * Poiner to the Redux_Sanitize class. 344 * 345 * @var null|Redux_Validation 346 */ 347 public $sanitize_class = null; 348 349 /** 350 * Pointer to the Redux_Args class. 351 * 352 * @var null|Redux_Args 353 */ 354 public $args_class = null; 355 356 /** 357 * Array of active transients used by Redux. 358 * 359 * @var araray 360 */ 361 public $transients = array(); 362 363 /** 364 * Deprecated shim for v3 templates. 365 * 366 * @var array 367 * 368 * @deprecated 4.0.0 369 */ 370 public $hidden_perm_sections = array(); 371 372 /** 373 * Deprecated shim for v3 as plugin check. 374 * 375 * @var bool 376 * 377 * @deprecated 4.0.0 378 */ 379 public static $_as_plugin = false; // phpcs:ignore PSR2.Classes.PropertyDeclaration 380 381 /** 382 * Deprecated shim for v3 as plugin check. 383 * 384 * @var bool 385 * 386 * @deprecated 4.0.0 387 */ 388 public static $_is_plugin = false; // phpcs:ignore PSR2.Classes.PropertyDeclaration 389 390 /** 391 * Cloning is forbidden. 392 * 393 * @since 4.0.0 394 */ 395 public function __clone() { 396 _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ eh?', 'redux-framework' ), '4.0' ); 397 } 398 399 /** 400 * Unserializing instances of this class is forbidden. 401 * 402 * @since 4.0.0 403 */ 404 public function __wakeup() { 405 _doing_it_wrong( __FUNCTION__, esc_html__( 'Cheatin’ eh?', 'redux-framework' ), '4.0' ); 406 } 407 408 /** 409 * Class Constructor. Defines the args for the theme options class 410 * 411 * @since 1.0.0 412 * 413 * @param array $sections Panel sections. 414 * @param array $args Class constructor arguments. 415 */ 416 public function __construct( array $sections = array(), array $args = array() ) { 417 global $pagenow; 418 419 if ( Redux_Core::is_heartbeat() ) { 420 return; 421 } 422 423 $args['load_on_cron'] = $args['load_on_cron'] ?? false; 424 425 if ( false === $args['load_on_cron'] && 'wp-cron.php' === $pagenow ) { 426 return; 427 } 428 429 if ( empty( $args ) || ! isset( $args['opt_name'] ) || ( isset( $args['opt_name'] ) && empty( $args['opt_name'] ) ) ) { 430 return; 431 } 432 433 if ( ! isset( Redux::$init[ $args['opt_name'] ] ) ) { 434 // Let's go back to the Redux API instead of having it run directly. 435 Redux_Functions_Ex::record_caller( $args['opt_name'] ); 436 Redux::set_args( $args['opt_name'], $args ); 437 if ( ! empty( $sections ) ) { 438 Redux::set_sections( $args['opt_name'], $sections ); 439 } 440 $sections = Redux::construct_sections( $args['opt_name'] ); 441 $args = Redux::construct_args( $args['opt_name'] ); 442 Redux::set_defaults( $args['opt_name'] ); 443 Redux::$init[ $args['opt_name'] ] = 1; 444 } 445 446 $args = new Redux_Args( $this, $args ); 447 $this->args_class = $args; 448 $this->args = $args->get; 449 450 Redux_Core::core_construct( $this, $this->args ); 451 452 new Redux_Admin_Notices( $this ); 453 454 if ( ! empty( $this->args['opt_name'] ) ) { 455 new Redux_Instances( $this ); 456 457 $this->filesystem = Redux_Filesystem::get_instance( $this ); 458 459 /** 460 * Filter 'redux/options/{opt_name}/sections' 461 * 462 * @param array $sections field option sections 463 */ 464 465 // phpcs:ignore WordPress.NamingConventions.ValidHookName 466 $this->sections = apply_filters( "redux/options/{$this->args['opt_name']}/sections", $sections ); 467 468 /** 469 * Construct hook 470 * action 'redux/construct' 471 * 472 * @param object $this ReduxFramework 473 */ 474 475 // phpcs:ignore WordPress.NamingConventions.ValidHookName 476 do_action( 'redux/construct', $this ); 477 478 // Internataionalization. 479 new Redux_I18n( $this, __FILE__ ); 480 481 $this->required_class = new Redux_Required( $this ); 482 $this->transient_class = new Redux_Transients( $this ); 483 $this->wordpress_data = new Redux_WordPress_Data( $this ); 484 $this->validate_class = new Redux_Validation( $this ); 485 $this->sanitize_class = new Redux_Sanitize( $this ); 486 487 // Register extra extensions. 488 new Redux_Extensions( $this ); 489 490 // Grab database values. 491 $this->options_defaults_class = new Redux_Options_Defaults(); 492 $this->options_class = new Redux_Options_Constructor( $this ); 493 $this->options_class->get(); 494 495 $this->output_class = new Redux_Output( $this ); 496 $this->render_class = new Redux_Page_Render( $this ); 497 $this->enqueue_class = new Redux_Enqueue( $this ); 498 499 new Redux_AJAX_Save( $this ); 500 new Redux_AJAX_Typography( $this ); 501 new Redux_AJAX_Select2( $this ); 502 new Redux_Health( $this ); 503 } 504 505 /** 506 * Loaded hook 507 * action 'redux/loaded' 508 * 509 * @param object $this ReduxFramework 510 */ 511 512 // phpcs:ignore WordPress.NamingConventions.ValidHookName 513 do_action( 'redux/loaded', $this ); 514 } 515 516 /** 517 * Begin backward compatibility shims for Redux v3 configs and extensions. 518 */ 519 520 /** 521 * SHIM: _register_settings 522 */ 523 public function _register_settings() { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore 524 $this->options_class->register(); 525 } 526 527 /** 528 * SHIM: _field_input 529 * 530 * @param array $field Field array. 531 * @param string|array $v Field values. 532 */ 533 public function _field_input( array $field, $v = null ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore 534 $this->render_class->field_input( $field, $v ); 535 } 536 537 /** 538 * SHIM: field_default_values 539 * 540 * @param array $field Field array. 541 */ 542 public function field_default_values( array $field ) { 543 $this->options_defaults_class->field_default_values( '', $field ); 544 } 545 546 /** 547 * SHIM: set_options 548 * 549 * @param string|array $value Option values. 550 */ 551 public function set_options( $value ) { 552 $this->options_class->set( $value ); 553 } 554 555 /** 556 * SHIM: get_options 557 */ 558 public function get_options() { 559 $this->options_class->get(); 560 } 561 562 /** 563 * SHIM: _default_values 564 * 565 * @return array 566 */ 567 public function _default_values() { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore 568 if ( ! isset( $this->options_class ) ) { 569 $this->options_defaults_class = new Redux_Options_Defaults(); 570 $this->options_class = new Redux_Options_Constructor( $this ); 571 } 572 573 return $this->options_class->default_values(); 574 } 575 576 /** 577 * SHIM: check_dependencies 578 * 579 * @param array $field Field array. 580 */ 581 public function check_dependencies( array $field ) { 582 $this->required_class->check_dependencies( $field ); 583 } 584 585 /** 586 * SHIM: _enqueue_output 587 */ 588 public function _enqueue_output() { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore 589 if ( empty( $this->output_class ) ) { 590 $obj = new ReduxFramework( $this->sections, $this->args ); 591 $obj->options = $this->options; 592 $obj->output_class->enqueue(); 593 $this->outputCSS = $obj->outputCSS; // phpcs:ignore WordPress.NamingConventions.ValidVariableName 594 } else { 595 $this->output_class->enqueue(); 596 } 597 } 598 599 /** 600 * SHIM: _enqueue 601 */ 602 public function _enqueue() { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore 603 $this->enqueue_class->init(); 604 } 605 606 /** 607 * SHIM: generate_panel 608 * 609 * @since 1.0.0 610 * @access public 611 * @return void 612 */ 613 public function generate_panel() { 614 $this->render_class->generate_panel(); 615 } 616 617 /** 618 * SHIM: get_default_values 619 * 620 * @param string $key Key value. 621 * @param bool $array_key Flag to determine array status. 622 * 623 * @return array 624 */ 625 public function get_default_values( $key, $array_key = false ) { 626 if ( ! isset( $this->options_class ) ) { 627 $this->options_defaults_class = new Redux_Options_Defaults(); 628 $this->options_class = new Redux_Options_Constructor( $this ); 629 } 630 631 return $this->options_class->get_default_value( $key, $array_key ); 632 } 633 634 /** 635 * SHIM: get_default_value 636 * 637 * @param string $key Key value. 638 * @param bool $array_key Flag to determine array status. 639 * 640 * @return array 641 */ 642 public function get_default_value( $key, $array_key = false ) { 643 if ( ! isset( $this->options_class ) ) { 644 $this->options_defaults_class = new Redux_Options_Defaults(); 645 $this->options_class = new Redux_Options_Constructor( $this ); 646 } 647 648 return $this->options_class->get_default_value( $key, $array_key ); 649 } 650 651 /** 652 * SHIM: get_wordpress_data 653 * 654 * @param bool $type data type. 655 * @param array $args args to pass to WordPress API. 656 * @param string|array $current_value Current value. 657 * 658 * @return array|mixed|string|void 659 */ 660 public function get_wordpress_data( $type = false, $args = array(), $current_value = null ) { 661 return $this->wordpress_data->get( $type, $args, $this->args['opt_name'], $current_value ); 662 } 663 664 /** 665 * SHIM: _validate_values 666 * 667 * @param array $plugin_options Current panel options. 668 * @param array $options Options to validate. 669 * @param array $sections Sections array. 670 * 671 * @return array 672 */ 673 public function _validate_values( $plugin_options, $options, $sections ) { // phpcs:ignore PSR2.Methods.MethodDeclaration.Underscore 674 if ( ! isset( $this->validate_class ) ) { 675 $this->validate_class = new Redux_Validation( $this ); 676 } 677 return $this->validate_class->validate( $plugin_options, $options, $sections ); 678 } 679 680 /** 681 * SHIM: set_transients 682 * 683 * @return void 684 */ 685 public function set_transients() {} 686 687 /** 688 * SHIM: section_menu 689 * 690 * @param int $k Array Key. 691 * @param array $section Section array. 692 * @param string $suffix Unique string. 693 * @param array $sections Section array. 694 * 695 * @return string 696 */ 697 public function section_menu( $k, $section, $suffix = '', $sections = array() ) { 698 return $this->render_class->section_menu( $k, $section, $suffix, $sections ); 699 } 700 701 /** 702 * SHIM: get_header_html 703 * 704 * @param array $field Field array. 705 * 706 * @return string 707 */ 708 public function get_header_html( $field ) { 709 return $this->render_class->get_header_html( $field ); 710 } 711 712 /** 713 * SHIM: current_user_can 714 * 715 * @param string $permission User permission. 716 * 717 * @return bool 718 */ 719 public function current_user_can( $permission ) { 720 _deprecated_function( __FUNCTION__, '4.0.0', 'Redux_Helpers::current_user_can' ); 721 722 return Redux_Helpers::current_user_can( $permission ); 723 } 724 725 /** 726 * End backward compatibility shims for Redux v3 configs and extensions. 727 */ 728 729 /** 730 * Pointer to the ReduxFramework instance. 731 * 732 * @return ReduxFramework|null 733 */ 734 public function get_instance(): ?ReduxFramework { 735 return self::$instance; 736 } 737 738 /** 739 * ->get(); This is used to return and option value from the options array 740 * 741 * @since 1.0.0 742 * @access public 743 * 744 * @param string $opt_name The option name to return. 745 * @param mixed $default (null) The value to return if option not set. 746 * 747 * @return mixed 748 */ 749 public function get( string $opt_name, $default = null ) { 750 return ( ! empty( $this->options[ $opt_name ] ) ) ? $this->options[ $opt_name ] : $this->options_class->get_default( $opt_name, $default ); 751 } 752 753 /** 754 * ->set(); This is used to set an arbitrary option in the options array 755 * 756 * @since 1.0.0 757 * @access public 758 * 759 * @param string $opt_name The name of the option being added. 760 * @param mixed $values The value of the option being added. 761 * 762 * @return void 763 */ 764 public function set( string $opt_name = '', $values = array() ) { 765 if ( ! empty( $opt_name ) && is_array( $values ) ) { 766 $this->options[ $opt_name ] = $values; 767 $this->options_class->set( $values ); 768 } 769 } 770 } 771 772 ReduxFramework::init(); 773 774 /** 775 * Action 'redux/init' 776 * 777 * @param null 778 */ 779 do_action( 'redux/init' ); // phpcs:ignore WordPress.NamingConventions.ValidHookName 780 }