class-redux-extensions.php (4038B)
1 <?php 2 /** 3 * Register Extensions for use 4 * 5 * @package Redux Framework/Classes 6 * @since 3.0.0 7 */ 8 9 defined( 'ABSPATH' ) || exit; 10 11 if ( ! class_exists( 'Redux_Extensions', false ) ) { 12 13 /** 14 * Class Redux_Extensions 15 */ 16 class Redux_Extensions extends Redux_Class { 17 18 /** 19 * Redux_Extensions constructor. 20 * 21 * @param object $parent ReduxFramework object pointer. 22 */ 23 public function __construct( $parent ) { 24 parent::__construct( $parent ); 25 26 $this->load(); 27 } 28 29 /** 30 * Class load functions. 31 * 32 * @throws ReflectionException For fallback. 33 */ 34 private function load() { 35 $core = $this->core(); 36 37 $max = 1; 38 39 if ( Redux_Core::$pro_loaded ) { 40 $max = 2; 41 } 42 43 for ( $i = 1; $i <= $max; $i ++ ) { 44 $path = Redux_Core::$dir . 'inc/extensions/'; 45 46 if ( 2 === $i ) { 47 if ( class_exists( 'Redux_Pro' ) ) { 48 $path = Redux_Pro::$dir . 'core/inc/extensions/'; 49 } 50 } 51 52 // phpcs:ignore WordPress.NamingConventions.ValidHookName 53 $path = apply_filters( 'redux/' . $core->args['opt_name'] . '/extensions/dir', $path ); 54 55 /** 56 * Action 'redux/extensions/before' 57 * 58 * @param object $this ReduxFramework 59 */ 60 // phpcs:ignore WordPress.NamingConventions.ValidHookName 61 do_action( 'redux/extensions/before', $core ); 62 63 /** 64 * Action 'redux/extensions/{opt_name}/before' 65 * 66 * @param object $this ReduxFramework 67 */ 68 // phpcs:ignore WordPress.NamingConventions.ValidHookName 69 do_action( "redux/extensions/{$core->args['opt_name']}/before", $core ); 70 71 if ( isset( $core->old_opt_name ) && null !== $core->old_opt_name ) { 72 // phpcs:ignore WordPress.NamingConventions.ValidHookName 73 do_action( 'redux/extensions/' . $core->old_opt_name . '/before', $core ); 74 } 75 76 require_once Redux_Core::$dir . 'inc/classes/class-redux-extension-abstract.php'; 77 78 $path = untrailingslashit( $path ); 79 80 // Backwards compatibility for extensions. 81 $instance_extensions = Redux::get_extensions( $core->args['opt_name'] ); 82 if ( ! empty( $instance_extensions ) ) { 83 foreach ( $instance_extensions as $name => $extension ) { 84 if ( ! isset( $core->extensions[ $name ] ) ) { 85 if ( class_exists( 'ReduxFramework_Extension_' . $name ) ) { 86 $a = new ReflectionClass( 'ReduxFramework_Extension_' . $name ); 87 Redux::set_extensions( $core->args['opt_name'], dirname( $a->getFileName() ), true ); 88 } 89 } 90 if ( ! isset( $core->extensions[ $name ] ) ) { 91 /* translators: %s is the name of an extension */ 92 $msg = '<strong>' . sprintf( esc_html__( 'The `%s` extension was not located properly', 'redux-framework' ), $name ) . '</strong>'; 93 $data = array( 94 'parent' => $this->parent, 95 'type' => 'error', 96 'msg' => $msg, 97 'id' => $name . '_notice_', 98 'dismiss' => false, 99 ); 100 if ( method_exists( 'Redux_Admin_Notices', 'set_notice' ) ) { 101 Redux_Admin_Notices::set_notice( $data ); 102 } 103 continue; 104 } 105 if ( ! is_subclass_of( $core->extensions[ $name ], 'Redux_Extension_Abstract' ) ) { 106 $ext_class = get_class( $core->extensions[ $name ] ); 107 $new_class_name = $ext_class . '_extended'; 108 Redux::$extension_compatibility = true; 109 $core->extensions[ $name ] = Redux_Functions_Ex::extension_compatibility( $core, $extension['path'], $ext_class, $new_class_name, $name ); 110 } 111 } 112 } 113 114 Redux::set_extensions( $core->args['opt_name'], $path, true ); 115 116 /** 117 * Action 'redux/extensions/{opt_name}' 118 * 119 * @param object $this ReduxFramework 120 */ 121 // phpcs:ignore WordPress.NamingConventions.ValidHookName 122 do_action( "redux/extensions/{$core->args['opt_name']}", $core ); 123 124 if ( isset( $core->old_opt_name ) && null !== $core->old_opt_name ) { 125 // phpcs:ignore WordPress.NamingConventions.ValidHookName 126 do_action( 'redux/extensions/' . $core->old_opt_name, $core ); 127 } 128 } 129 } 130 } 131 }