@@ -10,80 +10,80 @@ |
||
| 10 | 10 | |
| 11 | 11 | if ( ! class_exists( 'Redux_Extensions', false ) ) { |
| 12 | 12 | |
| 13 | - /** |
|
| 14 | - * Class Redux_Extensions |
|
| 15 | - */ |
|
| 16 | - class Redux_Extensions extends Redux_Class { |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Redux_Extensions constructor. |
|
| 20 | - * |
|
| 21 | - * @param object $redux ReduxFramework object pointer. |
|
| 22 | - * |
|
| 23 | - * @throws ReflectionException Exception. |
|
| 24 | - */ |
|
| 25 | - public function __construct( $redux ) { |
|
| 26 | - parent::__construct( $redux ); |
|
| 27 | - |
|
| 28 | - $this->load(); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Class load functions. |
|
| 33 | - * |
|
| 34 | - * @throws ReflectionException For fallback. |
|
| 35 | - */ |
|
| 36 | - private function load() { |
|
| 37 | - $core = $this->core(); |
|
| 38 | - |
|
| 39 | - $max = 1; |
|
| 40 | - |
|
| 41 | - for ( $i = 1; $i <= $max; $i++ ) { |
|
| 42 | - $path = Redux_Core::$dir . 'inc/extensions/'; |
|
| 43 | - |
|
| 44 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 45 | - $path = apply_filters( 'redux/' . $core->args['opt_name'] . '/extensions/dir', $path ); |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Action 'redux/extensions/before' |
|
| 49 | - * |
|
| 50 | - * @param object $this ReduxFramework |
|
| 51 | - */ |
|
| 52 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 53 | - do_action( 'redux/extensions/before', $core ); |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Action 'redux/extensions/{opt_name}/before' |
|
| 57 | - * |
|
| 58 | - * @param object $this ReduxFramework |
|
| 59 | - */ |
|
| 60 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 61 | - do_action( "redux/extensions/{$core->args['opt_name']}/before", $core ); |
|
| 62 | - |
|
| 63 | - if ( isset( $core->old_opt_name ) ) { |
|
| 64 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 65 | - do_action( 'redux/extensions/' . $core->old_opt_name . '/before', $core ); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - require_once Redux_Core::$dir . 'inc/classes/class-redux-extension-abstract.php'; |
|
| 69 | - |
|
| 70 | - $path = untrailingslashit( $path ); |
|
| 71 | - |
|
| 72 | - Redux::set_extensions( $core->args['opt_name'], $path, true ); |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * Action 'redux/extensions/{opt_name}' |
|
| 76 | - * |
|
| 77 | - * @param object $this ReduxFramework |
|
| 78 | - */ |
|
| 79 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 80 | - do_action( "redux/extensions/{$core->args['opt_name']}", $core ); |
|
| 81 | - |
|
| 82 | - if ( isset( $core->old_opt_name ) ) { |
|
| 83 | - // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 84 | - do_action( 'redux/extensions/' . $core->old_opt_name, $core ); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 13 | + /** |
|
| 14 | + * Class Redux_Extensions |
|
| 15 | + */ |
|
| 16 | + class Redux_Extensions extends Redux_Class { |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Redux_Extensions constructor. |
|
| 20 | + * |
|
| 21 | + * @param object $redux ReduxFramework object pointer. |
|
| 22 | + * |
|
| 23 | + * @throws ReflectionException Exception. |
|
| 24 | + */ |
|
| 25 | + public function __construct( $redux ) { |
|
| 26 | + parent::__construct( $redux ); |
|
| 27 | + |
|
| 28 | + $this->load(); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Class load functions. |
|
| 33 | + * |
|
| 34 | + * @throws ReflectionException For fallback. |
|
| 35 | + */ |
|
| 36 | + private function load() { |
|
| 37 | + $core = $this->core(); |
|
| 38 | + |
|
| 39 | + $max = 1; |
|
| 40 | + |
|
| 41 | + for ( $i = 1; $i <= $max; $i++ ) { |
|
| 42 | + $path = Redux_Core::$dir . 'inc/extensions/'; |
|
| 43 | + |
|
| 44 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 45 | + $path = apply_filters( 'redux/' . $core->args['opt_name'] . '/extensions/dir', $path ); |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Action 'redux/extensions/before' |
|
| 49 | + * |
|
| 50 | + * @param object $this ReduxFramework |
|
| 51 | + */ |
|
| 52 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 53 | + do_action( 'redux/extensions/before', $core ); |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Action 'redux/extensions/{opt_name}/before' |
|
| 57 | + * |
|
| 58 | + * @param object $this ReduxFramework |
|
| 59 | + */ |
|
| 60 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 61 | + do_action( "redux/extensions/{$core->args['opt_name']}/before", $core ); |
|
| 62 | + |
|
| 63 | + if ( isset( $core->old_opt_name ) ) { |
|
| 64 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 65 | + do_action( 'redux/extensions/' . $core->old_opt_name . '/before', $core ); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + require_once Redux_Core::$dir . 'inc/classes/class-redux-extension-abstract.php'; |
|
| 69 | + |
|
| 70 | + $path = untrailingslashit( $path ); |
|
| 71 | + |
|
| 72 | + Redux::set_extensions( $core->args['opt_name'], $path, true ); |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * Action 'redux/extensions/{opt_name}' |
|
| 76 | + * |
|
| 77 | + * @param object $this ReduxFramework |
|
| 78 | + */ |
|
| 79 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 80 | + do_action( "redux/extensions/{$core->args['opt_name']}", $core ); |
|
| 81 | + |
|
| 82 | + if ( isset( $core->old_opt_name ) ) { |
|
| 83 | + // phpcs:ignore WordPress.NamingConventions.ValidHookName |
|
| 84 | + do_action( 'redux/extensions/' . $core->old_opt_name, $core ); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | 89 | } |
@@ -11,27 +11,27 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Path', false ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Class Redux_Path |
|
| 16 | - */ |
|
| 17 | - class Redux_Path { |
|
| 14 | + /** |
|
| 15 | + * Class Redux_Path |
|
| 16 | + */ |
|
| 17 | + class Redux_Path { |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Class init |
|
| 21 | - */ |
|
| 22 | - public static function init() {} |
|
| 19 | + /** |
|
| 20 | + * Class init |
|
| 21 | + */ |
|
| 22 | + public static function init() {} |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Gets Redux path. |
|
| 26 | - * |
|
| 27 | - * @param string $relative_path Self-explanatory. |
|
| 28 | - * |
|
| 29 | - * @return string |
|
| 30 | - */ |
|
| 31 | - public static function get_path( string $relative_path ): string { |
|
| 32 | - return Redux_Core::$redux_path . $relative_path; |
|
| 33 | - } |
|
| 34 | - } |
|
| 24 | + /** |
|
| 25 | + * Gets Redux path. |
|
| 26 | + * |
|
| 27 | + * @param string $relative_path Self-explanatory. |
|
| 28 | + * |
|
| 29 | + * @return string |
|
| 30 | + */ |
|
| 31 | + public static function get_path( string $relative_path ): string { |
|
| 32 | + return Redux_Core::$redux_path . $relative_path; |
|
| 33 | + } |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - Redux_Path::init(); |
|
| 36 | + Redux_Path::init(); |
|
| 37 | 37 | } |
@@ -12,100 +12,100 @@ |
||
| 12 | 12 | // Don't duplicate me! |
| 13 | 13 | if ( ! class_exists( 'Redux_Content', false ) ) { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Main Redux_Content class |
|
| 17 | - * |
|
| 18 | - * @since 1.0.0 |
|
| 19 | - */ |
|
| 20 | - class Redux_Content extends Redux_Field { |
|
| 15 | + /** |
|
| 16 | + * Main Redux_Content class |
|
| 17 | + * |
|
| 18 | + * @since 1.0.0 |
|
| 19 | + */ |
|
| 20 | + class Redux_Content extends Redux_Field { |
|
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * Set field and value defaults. |
|
| 24 | - */ |
|
| 25 | - public function set_defaults() { |
|
| 26 | - $defaults = array( |
|
| 27 | - 'content' => '', |
|
| 28 | - 'class' => '', |
|
| 29 | - 'mode' => 'content', |
|
| 30 | - 'icon' => '', |
|
| 31 | - 'style' => 'normal', |
|
| 32 | - ); |
|
| 22 | + /** |
|
| 23 | + * Set field and value defaults. |
|
| 24 | + */ |
|
| 25 | + public function set_defaults() { |
|
| 26 | + $defaults = array( |
|
| 27 | + 'content' => '', |
|
| 28 | + 'class' => '', |
|
| 29 | + 'mode' => 'content', |
|
| 30 | + 'icon' => '', |
|
| 31 | + 'style' => 'normal', |
|
| 32 | + ); |
|
| 33 | 33 | |
| 34 | - $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 35 | - } |
|
| 34 | + $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Field Render Function. |
|
| 39 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 40 | - * |
|
| 41 | - * @since 1.0.0 |
|
| 42 | - * @access public |
|
| 43 | - * @return void |
|
| 44 | - */ |
|
| 45 | - public function render() { |
|
| 46 | - echo '</td></tr></table>'; |
|
| 37 | + /** |
|
| 38 | + * Field Render Function. |
|
| 39 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 40 | + * |
|
| 41 | + * @since 1.0.0 |
|
| 42 | + * @access public |
|
| 43 | + * @return void |
|
| 44 | + */ |
|
| 45 | + public function render() { |
|
| 46 | + echo '</td></tr></table>'; |
|
| 47 | 47 | |
| 48 | - if ( 'content' === $this->field['mode'] ) { |
|
| 49 | - echo '<div |
|
| 48 | + if ( 'content' === $this->field['mode'] ) { |
|
| 49 | + echo '<div |
|
| 50 | 50 | id="content-' . esc_attr( $this->field['id'] ) . '" |
| 51 | 51 | class="redux-field redux-field-borders ' . esc_attr( $this->field['class'] ) . ' redux-field-' . esc_attr( $this->field['mode'] ) . '"' . |
| 52 | - '>'; |
|
| 52 | + '>'; |
|
| 53 | 53 | |
| 54 | - echo wp_kses_post( $this->field['content'] ); |
|
| 55 | - } elseif ( 'heading' === $this->field['mode'] ) { |
|
| 56 | - $has_icon = isset( $this->field['icon'] ) && ! empty( $this->field['icon'] ) && true !== $this->field['icon'] ? 'hasIcon ' : ''; |
|
| 54 | + echo wp_kses_post( $this->field['content'] ); |
|
| 55 | + } elseif ( 'heading' === $this->field['mode'] ) { |
|
| 56 | + $has_icon = isset( $this->field['icon'] ) && ! empty( $this->field['icon'] ) && true !== $this->field['icon'] ? 'hasIcon ' : ''; |
|
| 57 | 57 | |
| 58 | - echo '<div |
|
| 58 | + echo '<div |
|
| 59 | 59 | id="heading-' . esc_attr( $this->field['id'] ) . '" |
| 60 | 60 | class="redux-field redux-field-borders ' . esc_attr( $has_icon ) . esc_attr( $this->field['class'] ) . ' redux-field-' . esc_attr( $this->field['mode'] ) . '"' . |
| 61 | - '>'; |
|
| 61 | + '>'; |
|
| 62 | 62 | |
| 63 | - if ( isset( $this->field['icon'] ) && ! empty( $this->field['icon'] ) && true !== $this->field['icon'] ) { |
|
| 64 | - echo '<p class="redux-heading-icon"><i class="' . esc_attr( $this->field['icon'] ) . ' icon-large"></i></p>'; |
|
| 65 | - } |
|
| 63 | + if ( isset( $this->field['icon'] ) && ! empty( $this->field['icon'] ) && true !== $this->field['icon'] ) { |
|
| 64 | + echo '<p class="redux-heading-icon"><i class="' . esc_attr( $this->field['icon'] ) . ' icon-large"></i></p>'; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - echo '<h2 class="redux-heading-text">' . wp_kses_post( $this->field['content'] ) . '</h2>'; |
|
| 68 | - } elseif ( 'subheading' === $this->field['mode'] ) { |
|
| 69 | - echo '<div |
|
| 67 | + echo '<h2 class="redux-heading-text">' . wp_kses_post( $this->field['content'] ) . '</h2>'; |
|
| 68 | + } elseif ( 'subheading' === $this->field['mode'] ) { |
|
| 69 | + echo '<div |
|
| 70 | 70 | id="subheading-' . esc_attr( $this->field['id'] ) . '" |
| 71 | 71 | class="redux-field redux-field-borders ' . esc_attr( $this->field['class'] ) . ' redux-field-' . esc_attr( $this->field['mode'] ) . '"' . |
| 72 | - '>'; |
|
| 72 | + '>'; |
|
| 73 | 73 | |
| 74 | - echo wp_kses_post( $this->field['content'] ); |
|
| 75 | - } elseif ( 'submessage' === $this->field['mode'] ) { |
|
| 76 | - echo '<div |
|
| 74 | + echo wp_kses_post( $this->field['content'] ); |
|
| 75 | + } elseif ( 'submessage' === $this->field['mode'] ) { |
|
| 76 | + echo '<div |
|
| 77 | 77 | id="submessage-' . esc_attr( $this->field['id'] ) . '" |
| 78 | 78 | class="redux-field redux-field-no-borders redux-submessage-' . esc_attr( $this->field['style'] ) . ' ' . esc_attr( $this->field['class'] ) . ' redux-field-' . esc_attr( $this->field['mode'] ) . '"' . |
| 79 | - '>'; |
|
| 79 | + '>'; |
|
| 80 | 80 | |
| 81 | - echo wp_kses_post( $this->field['content'] ); |
|
| 82 | - } |
|
| 81 | + echo wp_kses_post( $this->field['content'] ); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - echo '</div>'; |
|
| 85 | - echo '<table class="form-table no-border" style="display:none;">'; |
|
| 86 | - echo '<tbody>'; |
|
| 87 | - echo '<tr style="border-bottom:0; display:none;">'; |
|
| 88 | - echo '<th style="padding-top:0;"></th>'; |
|
| 89 | - echo '<td style="padding-top:0;">'; |
|
| 90 | - } |
|
| 84 | + echo '</div>'; |
|
| 85 | + echo '<table class="form-table no-border" style="display:none;">'; |
|
| 86 | + echo '<tbody>'; |
|
| 87 | + echo '<tr style="border-bottom:0; display:none;">'; |
|
| 88 | + echo '<th style="padding-top:0;"></th>'; |
|
| 89 | + echo '<td style="padding-top:0;">'; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * Enqueue Function. |
|
| 94 | - * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 95 | - * |
|
| 96 | - * @since 1.0.0 |
|
| 97 | - * @access public |
|
| 98 | - * @return void |
|
| 99 | - */ |
|
| 100 | - public function enqueue() { |
|
| 101 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 102 | - wp_enqueue_style( |
|
| 103 | - 'redux-field-content', |
|
| 104 | - Redux_Core::$url . 'inc/fields/content/redux-content.css', |
|
| 105 | - array(), |
|
| 106 | - $this->timestamp |
|
| 107 | - ); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - } |
|
| 92 | + /** |
|
| 93 | + * Enqueue Function. |
|
| 94 | + * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 95 | + * |
|
| 96 | + * @since 1.0.0 |
|
| 97 | + * @access public |
|
| 98 | + * @return void |
|
| 99 | + */ |
|
| 100 | + public function enqueue() { |
|
| 101 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 102 | + wp_enqueue_style( |
|
| 103 | + 'redux-field-content', |
|
| 104 | + Redux_Core::$url . 'inc/fields/content/redux-content.css', |
|
| 105 | + array(), |
|
| 106 | + $this->timestamp |
|
| 107 | + ); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | 111 | } |
@@ -12,133 +12,133 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | if ( ! class_exists( 'Redux_Dimensions', false ) ) { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Class Redux_Dimensions |
|
| 17 | - */ |
|
| 18 | - class Redux_Dimensions extends Redux_Field { |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Set field and value defaults. |
|
| 22 | - */ |
|
| 23 | - public function set_defaults() { |
|
| 24 | - // No errors, please. |
|
| 25 | - $defaults = array( |
|
| 26 | - 'width' => true, |
|
| 27 | - 'height' => true, |
|
| 28 | - 'units_extended' => false, |
|
| 29 | - 'units' => 'px', |
|
| 30 | - 'mode' => array( |
|
| 31 | - 'width' => false, |
|
| 32 | - 'height' => false, |
|
| 33 | - ), |
|
| 34 | - ); |
|
| 35 | - |
|
| 36 | - $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 37 | - |
|
| 38 | - $defaults = array( |
|
| 39 | - 'width' => '', |
|
| 40 | - 'height' => '', |
|
| 41 | - 'units' => 'px', |
|
| 42 | - ); |
|
| 43 | - |
|
| 44 | - $this->value = wp_parse_args( $this->value, $defaults ); |
|
| 45 | - |
|
| 46 | - if ( isset( $this->value['unit'] ) ) { |
|
| 47 | - $this->value['units'] = $this->value['unit']; |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * Field Render Function. |
|
| 53 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 54 | - * |
|
| 55 | - * @since ReduxFramework 1.0.0 |
|
| 56 | - */ |
|
| 57 | - public function render() { |
|
| 58 | - /* |
|
| 15 | + /** |
|
| 16 | + * Class Redux_Dimensions |
|
| 17 | + */ |
|
| 18 | + class Redux_Dimensions extends Redux_Field { |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Set field and value defaults. |
|
| 22 | + */ |
|
| 23 | + public function set_defaults() { |
|
| 24 | + // No errors, please. |
|
| 25 | + $defaults = array( |
|
| 26 | + 'width' => true, |
|
| 27 | + 'height' => true, |
|
| 28 | + 'units_extended' => false, |
|
| 29 | + 'units' => 'px', |
|
| 30 | + 'mode' => array( |
|
| 31 | + 'width' => false, |
|
| 32 | + 'height' => false, |
|
| 33 | + ), |
|
| 34 | + ); |
|
| 35 | + |
|
| 36 | + $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 37 | + |
|
| 38 | + $defaults = array( |
|
| 39 | + 'width' => '', |
|
| 40 | + 'height' => '', |
|
| 41 | + 'units' => 'px', |
|
| 42 | + ); |
|
| 43 | + |
|
| 44 | + $this->value = wp_parse_args( $this->value, $defaults ); |
|
| 45 | + |
|
| 46 | + if ( isset( $this->value['unit'] ) ) { |
|
| 47 | + $this->value['units'] = $this->value['unit']; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * Field Render Function. |
|
| 53 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 54 | + * |
|
| 55 | + * @since ReduxFramework 1.0.0 |
|
| 56 | + */ |
|
| 57 | + public function render() { |
|
| 58 | + /* |
|
| 59 | 59 | * Acceptable values checks. If the passed variable doesn't pass muster, we unset them |
| 60 | 60 | * and reset them with default values to avoid errors. |
| 61 | 61 | */ |
| 62 | 62 | |
| 63 | - $arr_units = Redux_Helpers::$array_units; |
|
| 63 | + $arr_units = Redux_Helpers::$array_units; |
|
| 64 | 64 | |
| 65 | - $unit_check = $arr_units; |
|
| 66 | - $unit_check[] = false; |
|
| 65 | + $unit_check = $arr_units; |
|
| 66 | + $unit_check[] = false; |
|
| 67 | 67 | |
| 68 | - // If units field has a value but is not an acceptable value, unset the variable. |
|
| 69 | - if ( isset( $this->field['units'] ) && ! Redux_Helpers::array_in_array( $this->field['units'], $unit_check ) ) { |
|
| 70 | - unset( $this->field['units'] ); |
|
| 71 | - } |
|
| 68 | + // If units field has a value but is not an acceptable value, unset the variable. |
|
| 69 | + if ( isset( $this->field['units'] ) && ! Redux_Helpers::array_in_array( $this->field['units'], $unit_check ) ) { |
|
| 70 | + unset( $this->field['units'] ); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - // If there is a default unit value but is not an accepted value, unset the variable. |
|
| 74 | - if ( isset( $this->value['units'] ) && ! Redux_Helpers::array_in_array( $this->value['units'], $unit_check ) ) { |
|
| 75 | - unset( $this->value['units'] ); |
|
| 76 | - } |
|
| 73 | + // If there is a default unit value but is not an accepted value, unset the variable. |
|
| 74 | + if ( isset( $this->value['units'] ) && ! Redux_Helpers::array_in_array( $this->value['units'], $unit_check ) ) { |
|
| 75 | + unset( $this->value['units'] ); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /* |
|
| 78 | + /* |
|
| 79 | 79 | * Since the unit field could be an array, string value or bool (to hide the unit field) |
| 80 | 80 | * we need to separate our functions to avoid those nasty PHP index notices! |
| 81 | 81 | */ |
| 82 | 82 | |
| 83 | - // if field units have a value and ARE an array, then evaluate as needed. |
|
| 84 | - if ( isset( $this->field['units'] ) && ! is_array( $this->field['units'] ) ) { |
|
| 85 | - |
|
| 86 | - // If units fields has a value but units value does not then make units value the field value. |
|
| 87 | - if ( isset( $this->field['units'] ) && ! isset( $this->value['units'] ) || false === $this->field['units'] ) { |
|
| 88 | - $this->value['units'] = $this->field['units']; |
|
| 89 | - |
|
| 90 | - // If unit field does NOT have a value and units value does NOT have a value, set both to blank (default?). |
|
| 91 | - } elseif ( ! isset( $this->field['units'] ) && ! isset( $this->value['units'] ) ) { |
|
| 92 | - $this->field['units'] = 'px'; |
|
| 93 | - $this->value['units'] = 'px'; |
|
| 94 | - |
|
| 95 | - // If unit field has NO value but units value does, then set unit field to value field. |
|
| 96 | - } elseif ( ! isset( $this->field['units'] ) && isset( $this->value['units'] ) ) { |
|
| 97 | - $this->field['units'] = $this->value['units']; |
|
| 98 | - |
|
| 99 | - // if unit value is set and unit value doesn't equal unit field (coz who knows why) |
|
| 100 | - // then set unit value to unit field. |
|
| 101 | - } elseif ( isset( $this->value['units'] ) && $this->value['units'] !== $this->field['units'] ) { |
|
| 102 | - $this->value['units'] = $this->field['units']; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // do stuff based on unit field NOT set as an array. |
|
| 106 | - // phpcs:ignore Generic.CodeAnalysis.EmptyStatement |
|
| 107 | - } elseif ( isset( $this->field['units'] ) && is_array( $this->field['units'] ) ) { |
|
| 108 | - // nothing to do here, but I'm leaving the construct just in case I have to debug this again. |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - echo '<fieldset id="' . esc_attr( $this->field['id'] ) . '-fieldset" class="redux-dimensions-container" data-id="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 112 | - |
|
| 113 | - $this->select2_config['allowClear'] = false; |
|
| 114 | - |
|
| 115 | - if ( isset( $this->field['select2'] ) ) { |
|
| 116 | - $this->field['select2'] = wp_parse_args( $this->field['select2'], $this->select2_config ); |
|
| 117 | - } else { |
|
| 118 | - $this->field['select2'] = $this->select2_config; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - $this->field['select2'] = Redux_Functions::sanitize_camel_case_array_keys( $this->field['select2'] ); |
|
| 122 | - |
|
| 123 | - $select2_data = Redux_Functions::create_data_string( $this->field['select2'] ); |
|
| 124 | - |
|
| 125 | - // This used to be unit field, but was giving the PHP index error when it was an array, |
|
| 126 | - // so I changed it. |
|
| 127 | - echo '<input type="hidden" id="' . esc_attr( $this->field['id'] ) . '-units" class="field-units" value="' . esc_attr( $this->value['units'] ) . '">'; |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Width |
|
| 131 | - * */ |
|
| 132 | - if ( true === $this->field['width'] ) { |
|
| 133 | - if ( ! empty( $this->value['width'] ) && false !== $this->value['units'] && strpos( $this->value['width'], strval( $this->value['units'] ) ) === false ) { |
|
| 134 | - $this->value['width'] = filter_var( $this->value['width'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ); |
|
| 135 | - if ( false !== $this->field['units'] ) { |
|
| 136 | - $this->value['width'] .= $this->value['units']; |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - echo '<div class="field-dimensions-input input-prepend">'; |
|
| 140 | - echo '<span class="add-on"><i class="el el-resize-horizontal icon-large"></i></span>'; |
|
| 141 | - echo '<input |
|
| 83 | + // if field units have a value and ARE an array, then evaluate as needed. |
|
| 84 | + if ( isset( $this->field['units'] ) && ! is_array( $this->field['units'] ) ) { |
|
| 85 | + |
|
| 86 | + // If units fields has a value but units value does not then make units value the field value. |
|
| 87 | + if ( isset( $this->field['units'] ) && ! isset( $this->value['units'] ) || false === $this->field['units'] ) { |
|
| 88 | + $this->value['units'] = $this->field['units']; |
|
| 89 | + |
|
| 90 | + // If unit field does NOT have a value and units value does NOT have a value, set both to blank (default?). |
|
| 91 | + } elseif ( ! isset( $this->field['units'] ) && ! isset( $this->value['units'] ) ) { |
|
| 92 | + $this->field['units'] = 'px'; |
|
| 93 | + $this->value['units'] = 'px'; |
|
| 94 | + |
|
| 95 | + // If unit field has NO value but units value does, then set unit field to value field. |
|
| 96 | + } elseif ( ! isset( $this->field['units'] ) && isset( $this->value['units'] ) ) { |
|
| 97 | + $this->field['units'] = $this->value['units']; |
|
| 98 | + |
|
| 99 | + // if unit value is set and unit value doesn't equal unit field (coz who knows why) |
|
| 100 | + // then set unit value to unit field. |
|
| 101 | + } elseif ( isset( $this->value['units'] ) && $this->value['units'] !== $this->field['units'] ) { |
|
| 102 | + $this->value['units'] = $this->field['units']; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // do stuff based on unit field NOT set as an array. |
|
| 106 | + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement |
|
| 107 | + } elseif ( isset( $this->field['units'] ) && is_array( $this->field['units'] ) ) { |
|
| 108 | + // nothing to do here, but I'm leaving the construct just in case I have to debug this again. |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + echo '<fieldset id="' . esc_attr( $this->field['id'] ) . '-fieldset" class="redux-dimensions-container" data-id="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 112 | + |
|
| 113 | + $this->select2_config['allowClear'] = false; |
|
| 114 | + |
|
| 115 | + if ( isset( $this->field['select2'] ) ) { |
|
| 116 | + $this->field['select2'] = wp_parse_args( $this->field['select2'], $this->select2_config ); |
|
| 117 | + } else { |
|
| 118 | + $this->field['select2'] = $this->select2_config; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + $this->field['select2'] = Redux_Functions::sanitize_camel_case_array_keys( $this->field['select2'] ); |
|
| 122 | + |
|
| 123 | + $select2_data = Redux_Functions::create_data_string( $this->field['select2'] ); |
|
| 124 | + |
|
| 125 | + // This used to be unit field, but was giving the PHP index error when it was an array, |
|
| 126 | + // so I changed it. |
|
| 127 | + echo '<input type="hidden" id="' . esc_attr( $this->field['id'] ) . '-units" class="field-units" value="' . esc_attr( $this->value['units'] ) . '">'; |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Width |
|
| 131 | + * */ |
|
| 132 | + if ( true === $this->field['width'] ) { |
|
| 133 | + if ( ! empty( $this->value['width'] ) && false !== $this->value['units'] && strpos( $this->value['width'], strval( $this->value['units'] ) ) === false ) { |
|
| 134 | + $this->value['width'] = filter_var( $this->value['width'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ); |
|
| 135 | + if ( false !== $this->field['units'] ) { |
|
| 136 | + $this->value['width'] .= $this->value['units']; |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + echo '<div class="field-dimensions-input input-prepend">'; |
|
| 140 | + echo '<span class="add-on"><i class="el el-resize-horizontal icon-large"></i></span>'; |
|
| 141 | + echo '<input |
|
| 142 | 142 | type="text" |
| 143 | 143 | id="' . esc_attr( $this->field['id'] ) . '-width" |
| 144 | 144 | class="redux-dimensions-input redux-dimensions-width mini ' . esc_attr( $this->field['class'] ) . '" |
@@ -146,29 +146,29 @@ discard block |
||
| 146 | 146 | rel="' . esc_attr( $this->field['id'] ) . '-width-hidden" |
| 147 | 147 | value="' . esc_attr( filter_var( $this->value['width'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) ) . '">'; |
| 148 | 148 | |
| 149 | - echo '<input |
|
| 149 | + echo '<input |
|
| 150 | 150 | data-id="' . esc_attr( $this->field['id'] ) . '" |
| 151 | 151 | type="hidden" |
| 152 | 152 | id="' . esc_attr( $this->field['id'] ) . '-width-hidden" |
| 153 | 153 | name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[width]" |
| 154 | 154 | value="' . esc_attr( $this->value['width'] ) . '">'; |
| 155 | 155 | |
| 156 | - echo '</div>'; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - /** |
|
| 160 | - * Height |
|
| 161 | - * */ |
|
| 162 | - if ( true === $this->field['height'] ) { |
|
| 163 | - if ( ! empty( $this->value['height'] ) && false !== $this->value['units'] && strpos( $this->value['height'], strval( $this->value['units'] ) ) === false ) { |
|
| 164 | - $this->value['height'] = filter_var( $this->value['height'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ); |
|
| 165 | - if ( false !== $this->field['units'] ) { |
|
| 166 | - $this->value['height'] .= $this->value['units']; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - echo '<div class="field-dimensions-input input-prepend">'; |
|
| 170 | - echo '<span class="add-on"><i class="el el-resize-vertical icon-large"></i></span>'; |
|
| 171 | - echo '<input |
|
| 156 | + echo '</div>'; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + /** |
|
| 160 | + * Height |
|
| 161 | + * */ |
|
| 162 | + if ( true === $this->field['height'] ) { |
|
| 163 | + if ( ! empty( $this->value['height'] ) && false !== $this->value['units'] && strpos( $this->value['height'], strval( $this->value['units'] ) ) === false ) { |
|
| 164 | + $this->value['height'] = filter_var( $this->value['height'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ); |
|
| 165 | + if ( false !== $this->field['units'] ) { |
|
| 166 | + $this->value['height'] .= $this->value['units']; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + echo '<div class="field-dimensions-input input-prepend">'; |
|
| 170 | + echo '<span class="add-on"><i class="el el-resize-vertical icon-large"></i></span>'; |
|
| 171 | + echo '<input |
|
| 172 | 172 | type="text" |
| 173 | 173 | id="' . esc_attr( $this->field['id'] ) . '-height" |
| 174 | 174 | class="redux-dimensions-input redux-dimensions-height mini ' . esc_attr( $this->field['class'] ) . '" |
@@ -176,156 +176,156 @@ discard block |
||
| 176 | 176 | rel="' . esc_attr( $this->field['id'] ) . '-height-hidden" |
| 177 | 177 | value="' . esc_attr( filter_var( $this->value['height'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) ) . '">'; |
| 178 | 178 | |
| 179 | - echo '<input |
|
| 179 | + echo '<input |
|
| 180 | 180 | data-id="' . esc_attr( $this->field['id'] ) . '" |
| 181 | 181 | type="hidden" |
| 182 | 182 | id="' . esc_attr( $this->field['id'] ) . '-height-hidden" |
| 183 | 183 | name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[height]" |
| 184 | 184 | value="' . esc_attr( $this->value['height'] ) . '">'; |
| 185 | - echo '</div>'; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Units |
|
| 190 | - * */ |
|
| 191 | - // If units field is set and units field NOT false then fill out the options object and show it, otherwise it's hidden |
|
| 192 | - // and the default units value will apply. |
|
| 193 | - if ( isset( $this->field['units'] ) && false !== $this->field['units'] ) { |
|
| 194 | - echo '<div |
|
| 185 | + echo '</div>'; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Units |
|
| 190 | + * */ |
|
| 191 | + // If units field is set and units field NOT false then fill out the options object and show it, otherwise it's hidden |
|
| 192 | + // and the default units value will apply. |
|
| 193 | + if ( isset( $this->field['units'] ) && false !== $this->field['units'] ) { |
|
| 194 | + echo '<div |
|
| 195 | 195 | class="select_wrapper dimensions-units" |
| 196 | 196 | original-title="' . esc_html__( 'Units', 'redux-framework' ) . '">'; |
| 197 | 197 | |
| 198 | - echo '<select |
|
| 198 | + echo '<select |
|
| 199 | 199 | data-id="' . esc_attr( $this->field['id'] ) . '" |
| 200 | 200 | data-placeholder="' . esc_html__( 'Units', 'redux-framework' ) . '" |
| 201 | 201 | class="redux-dimensions redux-dimensions-units select ' . esc_attr( $this->field['class'] ) . '" |
| 202 | 202 | original-title="' . esc_html__( 'Units', 'redux-framework' ) . '" |
| 203 | 203 | name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[units]"' . esc_attr( $select2_data ) . '>'; |
| 204 | 204 | |
| 205 | - // Extended units, show 'em all. |
|
| 206 | - if ( $this->field['units_extended'] ) { |
|
| 207 | - $test_units = $arr_units; |
|
| 208 | - } else { |
|
| 209 | - $test_units = array( 'px', 'em', 'rem', '%' ); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - if ( '' !== $this->field['units'] && is_array( $this->field['units'] ) ) { |
|
| 213 | - $test_units = $this->field['units']; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - if ( in_array( $this->field['units'], $test_units, true ) ) { |
|
| 217 | - echo '<option value="' . esc_attr( $this->field['units'] ) . '" selected="selected">' . esc_attr( $this->field['units'] ) . '</option>'; |
|
| 218 | - } else { |
|
| 219 | - foreach ( $test_units as $a_unit ) { |
|
| 220 | - echo '<option value="' . esc_attr( $a_unit ) . '" ' . selected( $this->value['units'], $a_unit, false ) . '>' . esc_attr( $a_unit ) . '</option>'; |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - echo '</select></div>'; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - echo '</fieldset>'; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Enqueue Function. |
|
| 231 | - * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 232 | - * |
|
| 233 | - * @since ReduxFramework 1.0.0 |
|
| 234 | - */ |
|
| 235 | - public function enqueue() { |
|
| 236 | - wp_enqueue_style( 'select2-css' ); |
|
| 237 | - |
|
| 238 | - wp_enqueue_script( |
|
| 239 | - 'redux-field-dimensions', |
|
| 240 | - Redux_Core::$url . 'inc/fields/dimensions/redux-dimensions' . Redux_Functions::is_min() . '.js', |
|
| 241 | - array( 'jquery', 'select2-js', 'redux-js' ), |
|
| 242 | - $this->timestamp, |
|
| 243 | - true |
|
| 244 | - ); |
|
| 245 | - |
|
| 246 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 247 | - wp_enqueue_style( |
|
| 248 | - 'redux-field-dimensions', |
|
| 249 | - Redux_Core::$url . 'inc/fields/dimensions/redux-dimensions.css', |
|
| 250 | - array(), |
|
| 251 | - $this->timestamp |
|
| 252 | - ); |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * Compile CSS styles for output. |
|
| 258 | - * |
|
| 259 | - * @param string $data CSS data. |
|
| 260 | - * |
|
| 261 | - * @return string |
|
| 262 | - */ |
|
| 263 | - public function css_style( $data ): string { |
|
| 264 | - $style = ''; |
|
| 265 | - |
|
| 266 | - // If field units has a value and IS an array, then evaluate as needed. |
|
| 267 | - if ( isset( $this->field['units'] ) && ! is_array( $this->field['units'] ) ) { |
|
| 268 | - |
|
| 269 | - // If units fields has a value but units value does not then make units value the field value. |
|
| 270 | - if ( isset( $this->field['units'] ) && ! isset( $this->value['units'] ) || false === $this->field['units'] ) { |
|
| 271 | - $this->value['units'] = $this->field['units']; |
|
| 272 | - |
|
| 273 | - // If units field does NOT have a value and units value does NOT have a value, set both to blank (default?). |
|
| 274 | - } elseif ( ! isset( $this->field['units'] ) && ! isset( $this->value['units'] ) ) { |
|
| 275 | - $this->field['units'] = 'px'; |
|
| 276 | - $this->value['units'] = 'px'; |
|
| 277 | - |
|
| 278 | - // If units field has NO value but units value does, then set unit field to value field. |
|
| 279 | - } elseif ( ! isset( $this->field['units'] ) && isset( $this->value['units'] ) ) { |
|
| 280 | - $this->field['units'] = $this->value['units']; |
|
| 281 | - |
|
| 282 | - // If unit value is set and unit value doesn't equal unit field (coz who knows why) |
|
| 283 | - // then set unit value to unit field. |
|
| 284 | - } elseif ( isset( $this->value['units'] ) && $this->field['units'] !== $this->value['units'] ) { |
|
| 285 | - $this->value['units'] = $this->field['units']; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - // Do stuff based on unit field NOT set as an array. |
|
| 289 | - // phpcs:ignore Generic.CodeAnalysis.EmptyStatement |
|
| 290 | - } elseif ( isset( $this->field['units'] ) && is_array( $this->field['units'] ) ) { |
|
| 291 | - // nothing to do here, but I'm leaving the construct just in case I have to debug this again. |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - $units = $this->value['units'] ?? ''; |
|
| 295 | - |
|
| 296 | - if ( ! is_array( $this->field['mode'] ) ) { |
|
| 297 | - $height = isset( $this->field['mode'] ) && ! empty( $this->field['mode'] ) ? $this->field['mode'] : 'height'; |
|
| 298 | - $width = isset( $this->field['mode'] ) && ! empty( $this->field['mode'] ) ? $this->field['mode'] : 'width'; |
|
| 299 | - } else { |
|
| 300 | - $height = false !== $this->field['mode']['height'] ? $this->field['mode']['height'] : 'height'; |
|
| 301 | - $width = false !== $this->field['mode']['width'] ? $this->field['mode']['width'] : 'width'; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - $clean_value = array( |
|
| 305 | - $height => isset( $this->value['height'] ) ? filter_var( $this->value['height'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : '', |
|
| 306 | - $width => isset( $this->value['width'] ) ? filter_var( $this->value['width'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : '', |
|
| 307 | - ); |
|
| 308 | - |
|
| 309 | - foreach ( $clean_value as $key => $value ) { |
|
| 310 | - // Output if it's a numeric entry. |
|
| 311 | - if ( isset( $value ) && is_numeric( $value ) ) { |
|
| 312 | - $style .= $key . ':' . $value . $units . ';'; |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - return $style; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Enable output_variables to be generated. |
|
| 321 | - * |
|
| 322 | - * @since 4.0.3 |
|
| 323 | - * @return void |
|
| 324 | - */ |
|
| 325 | - public function output_variables() { |
|
| 326 | - // No code needed, just defining the method is enough. |
|
| 327 | - } |
|
| 328 | - } |
|
| 205 | + // Extended units, show 'em all. |
|
| 206 | + if ( $this->field['units_extended'] ) { |
|
| 207 | + $test_units = $arr_units; |
|
| 208 | + } else { |
|
| 209 | + $test_units = array( 'px', 'em', 'rem', '%' ); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + if ( '' !== $this->field['units'] && is_array( $this->field['units'] ) ) { |
|
| 213 | + $test_units = $this->field['units']; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + if ( in_array( $this->field['units'], $test_units, true ) ) { |
|
| 217 | + echo '<option value="' . esc_attr( $this->field['units'] ) . '" selected="selected">' . esc_attr( $this->field['units'] ) . '</option>'; |
|
| 218 | + } else { |
|
| 219 | + foreach ( $test_units as $a_unit ) { |
|
| 220 | + echo '<option value="' . esc_attr( $a_unit ) . '" ' . selected( $this->value['units'], $a_unit, false ) . '>' . esc_attr( $a_unit ) . '</option>'; |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + echo '</select></div>'; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + echo '</fieldset>'; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Enqueue Function. |
|
| 231 | + * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 232 | + * |
|
| 233 | + * @since ReduxFramework 1.0.0 |
|
| 234 | + */ |
|
| 235 | + public function enqueue() { |
|
| 236 | + wp_enqueue_style( 'select2-css' ); |
|
| 237 | + |
|
| 238 | + wp_enqueue_script( |
|
| 239 | + 'redux-field-dimensions', |
|
| 240 | + Redux_Core::$url . 'inc/fields/dimensions/redux-dimensions' . Redux_Functions::is_min() . '.js', |
|
| 241 | + array( 'jquery', 'select2-js', 'redux-js' ), |
|
| 242 | + $this->timestamp, |
|
| 243 | + true |
|
| 244 | + ); |
|
| 245 | + |
|
| 246 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 247 | + wp_enqueue_style( |
|
| 248 | + 'redux-field-dimensions', |
|
| 249 | + Redux_Core::$url . 'inc/fields/dimensions/redux-dimensions.css', |
|
| 250 | + array(), |
|
| 251 | + $this->timestamp |
|
| 252 | + ); |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * Compile CSS styles for output. |
|
| 258 | + * |
|
| 259 | + * @param string $data CSS data. |
|
| 260 | + * |
|
| 261 | + * @return string |
|
| 262 | + */ |
|
| 263 | + public function css_style( $data ): string { |
|
| 264 | + $style = ''; |
|
| 265 | + |
|
| 266 | + // If field units has a value and IS an array, then evaluate as needed. |
|
| 267 | + if ( isset( $this->field['units'] ) && ! is_array( $this->field['units'] ) ) { |
|
| 268 | + |
|
| 269 | + // If units fields has a value but units value does not then make units value the field value. |
|
| 270 | + if ( isset( $this->field['units'] ) && ! isset( $this->value['units'] ) || false === $this->field['units'] ) { |
|
| 271 | + $this->value['units'] = $this->field['units']; |
|
| 272 | + |
|
| 273 | + // If units field does NOT have a value and units value does NOT have a value, set both to blank (default?). |
|
| 274 | + } elseif ( ! isset( $this->field['units'] ) && ! isset( $this->value['units'] ) ) { |
|
| 275 | + $this->field['units'] = 'px'; |
|
| 276 | + $this->value['units'] = 'px'; |
|
| 277 | + |
|
| 278 | + // If units field has NO value but units value does, then set unit field to value field. |
|
| 279 | + } elseif ( ! isset( $this->field['units'] ) && isset( $this->value['units'] ) ) { |
|
| 280 | + $this->field['units'] = $this->value['units']; |
|
| 281 | + |
|
| 282 | + // If unit value is set and unit value doesn't equal unit field (coz who knows why) |
|
| 283 | + // then set unit value to unit field. |
|
| 284 | + } elseif ( isset( $this->value['units'] ) && $this->field['units'] !== $this->value['units'] ) { |
|
| 285 | + $this->value['units'] = $this->field['units']; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + // Do stuff based on unit field NOT set as an array. |
|
| 289 | + // phpcs:ignore Generic.CodeAnalysis.EmptyStatement |
|
| 290 | + } elseif ( isset( $this->field['units'] ) && is_array( $this->field['units'] ) ) { |
|
| 291 | + // nothing to do here, but I'm leaving the construct just in case I have to debug this again. |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + $units = $this->value['units'] ?? ''; |
|
| 295 | + |
|
| 296 | + if ( ! is_array( $this->field['mode'] ) ) { |
|
| 297 | + $height = isset( $this->field['mode'] ) && ! empty( $this->field['mode'] ) ? $this->field['mode'] : 'height'; |
|
| 298 | + $width = isset( $this->field['mode'] ) && ! empty( $this->field['mode'] ) ? $this->field['mode'] : 'width'; |
|
| 299 | + } else { |
|
| 300 | + $height = false !== $this->field['mode']['height'] ? $this->field['mode']['height'] : 'height'; |
|
| 301 | + $width = false !== $this->field['mode']['width'] ? $this->field['mode']['width'] : 'width'; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + $clean_value = array( |
|
| 305 | + $height => isset( $this->value['height'] ) ? filter_var( $this->value['height'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : '', |
|
| 306 | + $width => isset( $this->value['width'] ) ? filter_var( $this->value['width'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : '', |
|
| 307 | + ); |
|
| 308 | + |
|
| 309 | + foreach ( $clean_value as $key => $value ) { |
|
| 310 | + // Output if it's a numeric entry. |
|
| 311 | + if ( isset( $value ) && is_numeric( $value ) ) { |
|
| 312 | + $style .= $key . ':' . $value . $units . ';'; |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + return $style; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Enable output_variables to be generated. |
|
| 321 | + * |
|
| 322 | + * @since 4.0.3 |
|
| 323 | + * @return void |
|
| 324 | + */ |
|
| 325 | + public function output_variables() { |
|
| 326 | + // No code needed, just defining the method is enough. |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | class_alias( 'Redux_Dimensions', 'ReduxFramework_Dimensions' ); |
@@ -12,370 +12,370 @@ |
||
| 12 | 12 | // Don't duplicate me! |
| 13 | 13 | if ( ! class_exists( 'Redux_Border', false ) ) { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Class Redux_Border |
|
| 17 | - */ |
|
| 18 | - class Redux_Border extends Redux_Field { |
|
| 19 | - |
|
| 20 | - /** |
|
| 21 | - * Set field and value defaults. |
|
| 22 | - */ |
|
| 23 | - public function set_defaults() { |
|
| 24 | - // No errors, please. |
|
| 25 | - $defaults = array( |
|
| 26 | - 'top' => true, |
|
| 27 | - 'bottom' => true, |
|
| 28 | - 'all' => true, |
|
| 29 | - 'style' => true, |
|
| 30 | - 'color' => true, |
|
| 31 | - 'left' => true, |
|
| 32 | - 'right' => true, |
|
| 33 | - ); |
|
| 34 | - |
|
| 35 | - $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 36 | - |
|
| 37 | - $defaults = array( |
|
| 38 | - 'top' => '', |
|
| 39 | - 'right' => '', |
|
| 40 | - 'bottom' => '', |
|
| 41 | - 'left' => '', |
|
| 42 | - 'color' => '', |
|
| 43 | - 'style' => '', |
|
| 44 | - ); |
|
| 45 | - |
|
| 46 | - $this->value = wp_parse_args( $this->value, $defaults ); |
|
| 47 | - } |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Field Render Function. |
|
| 51 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 52 | - * |
|
| 53 | - * @since ReduxFramework 1.0.0 |
|
| 54 | - */ |
|
| 55 | - public function render() { |
|
| 56 | - $value = array( |
|
| 57 | - 'top' => isset( $this->value['border-top'] ) ? filter_var( $this->value['border-top'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['top'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 58 | - 'right' => isset( $this->value['border-right'] ) ? filter_var( $this->value['border-right'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['right'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 59 | - 'bottom' => isset( $this->value['border-bottom'] ) ? filter_var( $this->value['border-bottom'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['bottom'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 60 | - 'left' => isset( $this->value['border-left'] ) ? filter_var( $this->value['border-left'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['left'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 61 | - 'color' => $this->value['border-color'] ?? $this->value['color'], |
|
| 62 | - 'style' => $this->value['border-style'] ?? $this->value['style'], |
|
| 63 | - ); |
|
| 64 | - |
|
| 65 | - if ( ( isset( $this->value['width'] ) || isset( $this->value['border-width'] ) ) ) { |
|
| 66 | - if ( isset( $this->value['border-width'] ) && ! empty( $this->value['border-width'] ) ) { |
|
| 67 | - $this->value['width'] = $this->value['border-width']; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - $this->value['width'] = $this->strip_alphas( $this->value['width'] ); |
|
| 71 | - |
|
| 72 | - $value['top'] = $this->value['width']; |
|
| 73 | - $value['right'] = $this->value['width']; |
|
| 74 | - $value['bottom'] = $this->value['width']; |
|
| 75 | - $value['left'] = $this->value['width']; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $this->value = $value; |
|
| 79 | - |
|
| 80 | - $defaults = array( |
|
| 81 | - 'top' => '', |
|
| 82 | - 'right' => '', |
|
| 83 | - 'bottom' => '', |
|
| 84 | - 'left' => '', |
|
| 85 | - ); |
|
| 86 | - |
|
| 87 | - $this->check_for_all(); |
|
| 88 | - |
|
| 89 | - $this->value = wp_parse_args( $this->value, $defaults ); |
|
| 90 | - |
|
| 91 | - $this->select2_config['allowClear'] = false; |
|
| 92 | - |
|
| 93 | - if ( isset( $this->field['select2'] ) ) { |
|
| 94 | - $this->field['select2'] = wp_parse_args( $this->field['select2'], $this->select2_config ); |
|
| 95 | - } else { |
|
| 96 | - $this->field['select2'] = $this->select2_config; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $this->field['select2'] = Redux_Functions::sanitize_camel_case_array_keys( $this->field['select2'] ); |
|
| 100 | - |
|
| 101 | - $select2_data = Redux_Functions::create_data_string( $this->field['select2'] ); |
|
| 102 | - |
|
| 103 | - echo '<input type="hidden" class="field-units" value="px">'; |
|
| 104 | - |
|
| 105 | - if ( isset( $this->field['all'] ) && true === $this->field['all'] ) { |
|
| 106 | - echo '<div class="field-border-input input-prepend"><span class="add-on"><i class="el el-fullscreen icon-large"></i></span><input type="text" class="redux-border-all redux-border-input mini ' . esc_attr( $this->field['class'] ) . '" placeholder="' . esc_html__( 'All', 'redux-framework' ) . '" rel="' . esc_attr( $this->field['id'] ) . '-all" value="' . esc_attr( $this->value['top'] ) . '"></div>'; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - echo '<input type="hidden" class="redux-border-value" id="' . esc_attr( $this->field['id'] ) . '-top-hidden" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-top]" value="' . ( isset( $this->value['top'] ) && '' !== $this->value['top'] ? esc_attr( $this->value['top'] ) . 'px' : '' ) . '">'; |
|
| 110 | - echo '<input type="hidden" class="redux-border-value" id="' . esc_attr( $this->field['id'] ) . '-right-hidden" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-right]" value="' . ( isset( $this->value['right'] ) && '' !== $this->value['right'] ? esc_attr( $this->value['right'] ) . 'px' : '' ) . '">'; |
|
| 111 | - echo '<input type="hidden" class="redux-border-value" id="' . esc_attr( $this->field['id'] ) . '-bottom-hidden" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-bottom]" value="' . ( isset( $this->value['bottom'] ) && '' !== $this->value['bottom'] ? esc_attr( $this->value['bottom'] ) . 'px' : '' ) . '">'; |
|
| 112 | - echo '<input type="hidden" class="redux-border-value" id="' . esc_attr( $this->field['id'] ) . '-left-hidden" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-left]" value="' . ( isset( $this->value['left'] ) && '' !== $this->value['left'] ? esc_attr( $this->value['left'] ) . 'px' : '' ) . '">'; |
|
| 113 | - |
|
| 114 | - if ( ! isset( $this->field['all'] ) || true !== $this->field['all'] ) { |
|
| 115 | - /** |
|
| 116 | - * Top |
|
| 117 | - * */ |
|
| 118 | - if ( true === $this->field['top'] ) { |
|
| 119 | - echo '<div class="field-border-input input-prepend"> |
|
| 15 | + /** |
|
| 16 | + * Class Redux_Border |
|
| 17 | + */ |
|
| 18 | + class Redux_Border extends Redux_Field { |
|
| 19 | + |
|
| 20 | + /** |
|
| 21 | + * Set field and value defaults. |
|
| 22 | + */ |
|
| 23 | + public function set_defaults() { |
|
| 24 | + // No errors, please. |
|
| 25 | + $defaults = array( |
|
| 26 | + 'top' => true, |
|
| 27 | + 'bottom' => true, |
|
| 28 | + 'all' => true, |
|
| 29 | + 'style' => true, |
|
| 30 | + 'color' => true, |
|
| 31 | + 'left' => true, |
|
| 32 | + 'right' => true, |
|
| 33 | + ); |
|
| 34 | + |
|
| 35 | + $this->field = wp_parse_args( $this->field, $defaults ); |
|
| 36 | + |
|
| 37 | + $defaults = array( |
|
| 38 | + 'top' => '', |
|
| 39 | + 'right' => '', |
|
| 40 | + 'bottom' => '', |
|
| 41 | + 'left' => '', |
|
| 42 | + 'color' => '', |
|
| 43 | + 'style' => '', |
|
| 44 | + ); |
|
| 45 | + |
|
| 46 | + $this->value = wp_parse_args( $this->value, $defaults ); |
|
| 47 | + } |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Field Render Function. |
|
| 51 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 52 | + * |
|
| 53 | + * @since ReduxFramework 1.0.0 |
|
| 54 | + */ |
|
| 55 | + public function render() { |
|
| 56 | + $value = array( |
|
| 57 | + 'top' => isset( $this->value['border-top'] ) ? filter_var( $this->value['border-top'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['top'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 58 | + 'right' => isset( $this->value['border-right'] ) ? filter_var( $this->value['border-right'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['right'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 59 | + 'bottom' => isset( $this->value['border-bottom'] ) ? filter_var( $this->value['border-bottom'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['bottom'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 60 | + 'left' => isset( $this->value['border-left'] ) ? filter_var( $this->value['border-left'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ) : filter_var( $this->value['left'], FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION ), |
|
| 61 | + 'color' => $this->value['border-color'] ?? $this->value['color'], |
|
| 62 | + 'style' => $this->value['border-style'] ?? $this->value['style'], |
|
| 63 | + ); |
|
| 64 | + |
|
| 65 | + if ( ( isset( $this->value['width'] ) || isset( $this->value['border-width'] ) ) ) { |
|
| 66 | + if ( isset( $this->value['border-width'] ) && ! empty( $this->value['border-width'] ) ) { |
|
| 67 | + $this->value['width'] = $this->value['border-width']; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + $this->value['width'] = $this->strip_alphas( $this->value['width'] ); |
|
| 71 | + |
|
| 72 | + $value['top'] = $this->value['width']; |
|
| 73 | + $value['right'] = $this->value['width']; |
|
| 74 | + $value['bottom'] = $this->value['width']; |
|
| 75 | + $value['left'] = $this->value['width']; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $this->value = $value; |
|
| 79 | + |
|
| 80 | + $defaults = array( |
|
| 81 | + 'top' => '', |
|
| 82 | + 'right' => '', |
|
| 83 | + 'bottom' => '', |
|
| 84 | + 'left' => '', |
|
| 85 | + ); |
|
| 86 | + |
|
| 87 | + $this->check_for_all(); |
|
| 88 | + |
|
| 89 | + $this->value = wp_parse_args( $this->value, $defaults ); |
|
| 90 | + |
|
| 91 | + $this->select2_config['allowClear'] = false; |
|
| 92 | + |
|
| 93 | + if ( isset( $this->field['select2'] ) ) { |
|
| 94 | + $this->field['select2'] = wp_parse_args( $this->field['select2'], $this->select2_config ); |
|
| 95 | + } else { |
|
| 96 | + $this->field['select2'] = $this->select2_config; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $this->field['select2'] = Redux_Functions::sanitize_camel_case_array_keys( $this->field['select2'] ); |
|
| 100 | + |
|
| 101 | + $select2_data = Redux_Functions::create_data_string( $this->field['select2'] ); |
|
| 102 | + |
|
| 103 | + echo '<input type="hidden" class="field-units" value="px">'; |
|
| 104 | + |
|
| 105 | + if ( isset( $this->field['all'] ) && true === $this->field['all'] ) { |
|
| 106 | + echo '<div class="field-border-input input-prepend"><span class="add-on"><i class="el el-fullscreen icon-large"></i></span><input type="text" class="redux-border-all redux-border-input mini ' . esc_attr( $this->field['class'] ) . '" placeholder="' . esc_html__( 'All', 'redux-framework' ) . '" rel="' . esc_attr( $this->field['id'] ) . '-all" value="' . esc_attr( $this->value['top'] ) . '"></div>'; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + echo '<input type="hidden" class="redux-border-value" id="' . esc_attr( $this->field['id'] ) . '-top-hidden" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-top]" value="' . ( isset( $this->value['top'] ) && '' !== $this->value['top'] ? esc_attr( $this->value['top'] ) . 'px' : '' ) . '">'; |
|
| 110 | + echo '<input type="hidden" class="redux-border-value" id="' . esc_attr( $this->field['id'] ) . '-right-hidden" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-right]" value="' . ( isset( $this->value['right'] ) && '' !== $this->value['right'] ? esc_attr( $this->value['right'] ) . 'px' : '' ) . '">'; |
|
| 111 | + echo '<input type="hidden" class="redux-border-value" id="' . esc_attr( $this->field['id'] ) . '-bottom-hidden" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-bottom]" value="' . ( isset( $this->value['bottom'] ) && '' !== $this->value['bottom'] ? esc_attr( $this->value['bottom'] ) . 'px' : '' ) . '">'; |
|
| 112 | + echo '<input type="hidden" class="redux-border-value" id="' . esc_attr( $this->field['id'] ) . '-left-hidden" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-left]" value="' . ( isset( $this->value['left'] ) && '' !== $this->value['left'] ? esc_attr( $this->value['left'] ) . 'px' : '' ) . '">'; |
|
| 113 | + |
|
| 114 | + if ( ! isset( $this->field['all'] ) || true !== $this->field['all'] ) { |
|
| 115 | + /** |
|
| 116 | + * Top |
|
| 117 | + * */ |
|
| 118 | + if ( true === $this->field['top'] ) { |
|
| 119 | + echo '<div class="field-border-input input-prepend"> |
|
| 120 | 120 | <span class="add-on"> |
| 121 | 121 | <i class="el el-arrow-up icon-large"></i> |
| 122 | 122 | </span> |
| 123 | 123 | <input type="text" id="' . esc_attr( $this->field['id'] ) . '-top" class="redux-border-top redux-border-input mini ' . esc_attr( $this->field['class'] ) . '" placeholder="' . esc_html__( 'Top', 'redux-framework' ) . '" rel="' . esc_attr( $this->field['id'] ) . '-top-hidden" value="' . esc_attr( $this->value['top'] ) . '"> |
| 124 | 124 | </div>'; |
| 125 | - } |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Right |
|
| 129 | - * */ |
|
| 130 | - if ( true === $this->field['right'] ) { |
|
| 131 | - echo '<div class="field-border-input input-prepend"> |
|
| 127 | + /** |
|
| 128 | + * Right |
|
| 129 | + * */ |
|
| 130 | + if ( true === $this->field['right'] ) { |
|
| 131 | + echo '<div class="field-border-input input-prepend"> |
|
| 132 | 132 | <span class="add-on"> |
| 133 | 133 | <i class="el el-arrow-right icon-large"></i> |
| 134 | 134 | </span> |
| 135 | 135 | <input type="text" id="' . esc_attr( $this->field['id'] ) . '-right" class="redux-border-right redux-border-input mini ' . esc_attr( $this->field['class'] ) . '" placeholder="' . esc_html__( 'Right', 'redux-framework' ) . '" rel="' . esc_attr( $this->field['id'] ) . '-right-hidden" value="' . esc_attr( $this->value['right'] ) . '"> |
| 136 | 136 | </div>'; |
| 137 | - } |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Bottom |
|
| 141 | - * */ |
|
| 142 | - if ( true === $this->field['bottom'] ) { |
|
| 143 | - echo '<div class="field-border-input input-prepend"> |
|
| 139 | + /** |
|
| 140 | + * Bottom |
|
| 141 | + * */ |
|
| 142 | + if ( true === $this->field['bottom'] ) { |
|
| 143 | + echo '<div class="field-border-input input-prepend"> |
|
| 144 | 144 | <span class="add-on"> |
| 145 | 145 | <i class="el el-arrow-down icon-large"></i> |
| 146 | 146 | </span> |
| 147 | 147 | <input type="text" id="' . esc_attr( $this->field['id'] ) . '-bottom" class="redux-border-bottom redux-border-input mini ' . esc_attr( $this->field['class'] ) . '" placeholder="' . esc_html__( 'Bottom', 'redux-framework' ) . '" rel="' . esc_attr( $this->field['id'] ) . '-bottom-hidden" value="' . esc_attr( $this->value['bottom'] ) . '"> |
| 148 | 148 | </div>'; |
| 149 | - } |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - /** |
|
| 152 | - * Left |
|
| 153 | - * */ |
|
| 154 | - if ( true === $this->field['left'] ) { |
|
| 155 | - echo '<div class="field-border-input input-prepend"> |
|
| 151 | + /** |
|
| 152 | + * Left |
|
| 153 | + * */ |
|
| 154 | + if ( true === $this->field['left'] ) { |
|
| 155 | + echo '<div class="field-border-input input-prepend"> |
|
| 156 | 156 | <span class="add-on"> |
| 157 | 157 | <i class="el el-arrow-left icon-large"></i> |
| 158 | 158 | </span> |
| 159 | 159 | <input type="text" id="' . esc_attr( $this->field['id'] ) . '-left" class="redux-border-left redux-border-input mini ' . esc_attr( $this->field['class'] ) . '" placeholder="' . esc_html__( 'Left', 'redux-framework' ) . '" rel="' . esc_attr( $this->field['id'] ) . '-left-hidden" value="' . esc_attr( $this->value['left'] ) . '"> |
| 160 | 160 | </div>'; |
| 161 | - } |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Border-style |
|
| 166 | - * */ |
|
| 167 | - if ( false !== $this->field['style'] ) { |
|
| 168 | - $options = array( |
|
| 169 | - 'solid' => esc_html__( 'Solid', 'redux-framework' ), |
|
| 170 | - 'dashed' => esc_html__( 'Dashed', 'redux-framework' ), |
|
| 171 | - 'dotted' => esc_html__( 'Dotted', 'redux-framework' ), |
|
| 172 | - 'double' => esc_html__( 'Double', 'redux-framework' ), |
|
| 173 | - 'none' => esc_html__( 'None', 'redux-framework' ), |
|
| 174 | - ); |
|
| 175 | - |
|
| 176 | - echo '<select data-placeholder="' . esc_html__( 'Border style', 'redux-framework' ) . '" id="' . esc_attr( $this->field['id'] ) . '[border-style]" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-style]" class="tips redux-border-style ' . esc_attr( $this->field['class'] ) . '" rows="6" data-id="' . esc_attr( $this->field['id'] ) . '"' . esc_attr( $select2_data ) . '>'; |
|
| 177 | - |
|
| 178 | - foreach ( $options as $k => $v ) { |
|
| 179 | - echo '<option value="' . esc_attr( $k ) . '" ' . selected( $value['style'], $k, false ) . '>' . esc_html( $v ) . '</option>'; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - echo '</select>'; |
|
| 183 | - } else { |
|
| 184 | - echo '<input type="hidden" id="' . esc_attr( $this->field['id'] ) . '[border-style]" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-style]" value="' . esc_attr( $this->value['style'] ) . '" data-id="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Color |
|
| 189 | - * */ |
|
| 190 | - if ( false !== $this->field['color'] ) { |
|
| 191 | - $default = $this->field['default']['border-color'] ?? ''; |
|
| 192 | - |
|
| 193 | - if ( empty( $default ) ) { |
|
| 194 | - $default = ( isset( $this->field['default']['color'] ) ) ? $this->field['default']['color'] : '#ffffff'; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - echo '<input '; |
|
| 198 | - echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-color]"'; |
|
| 199 | - echo 'id="' . esc_attr( $this->field['id'] ) . '-border"'; |
|
| 200 | - echo 'class="color-picker redux-border-color redux-color redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 201 | - echo 'type="text"'; |
|
| 202 | - echo 'value="' . esc_attr( $this->value['color'] ) . '"'; |
|
| 203 | - echo 'data-default-color="' . esc_attr( $default ) . '"'; |
|
| 204 | - echo 'data-id="' . esc_attr( $this->field['id'] ) . '"'; |
|
| 205 | - |
|
| 206 | - $data = array( |
|
| 207 | - 'field' => $this->field, |
|
| 208 | - 'index' => '', |
|
| 209 | - ); |
|
| 210 | - |
|
| 211 | - echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 212 | - |
|
| 213 | - echo '>'; |
|
| 214 | - } else { |
|
| 215 | - echo '<input type="hidden" id="' . esc_attr( $this->field['id'] ) . '[border-color]" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-color]" value="' . esc_attr( $this->value['color'] ) . '" data-id="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Do enqueue for each field instance. |
|
| 222 | - * |
|
| 223 | - * @return void |
|
| 224 | - */ |
|
| 225 | - public function always_enqueue() { |
|
| 226 | - if ( isset( $this->field['color_alpha'] ) && $this->field['color_alpha'] ) { |
|
| 227 | - if ( ! wp_script_is( 'redux-wp-color-picker-alpha' ) ) { |
|
| 228 | - wp_enqueue_script( 'redux-wp-color-picker-alpha' ); |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Enqueue Function. |
|
| 235 | - * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 236 | - * |
|
| 237 | - * @since ReduxFramework 1.0.0 |
|
| 238 | - */ |
|
| 239 | - public function enqueue() { |
|
| 240 | - $min = Redux_Functions::is_min(); |
|
| 241 | - |
|
| 242 | - if ( ! wp_style_is( 'select2-css' ) ) { |
|
| 243 | - wp_enqueue_style( 'select2-css' ); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - if ( ! wp_style_is( 'wp-color-picker' ) ) { |
|
| 247 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $dep_array = array( 'jquery', 'select2-js', 'wp-color-picker', 'redux-js' ); |
|
| 251 | - |
|
| 252 | - wp_enqueue_script( |
|
| 253 | - 'redux-field-border', |
|
| 254 | - Redux_Core::$url . 'inc/fields/border/redux-border' . $min . '.js', |
|
| 255 | - $dep_array, |
|
| 256 | - $this->timestamp, |
|
| 257 | - true |
|
| 258 | - ); |
|
| 259 | - |
|
| 260 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 261 | - if ( ! wp_style_is( 'redux-color-picker' ) ) { |
|
| 262 | - wp_enqueue_style( 'redux-color-picker' ); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - wp_enqueue_style( |
|
| 266 | - 'redux-field-border', |
|
| 267 | - Redux_Core::$url . 'inc/fields/border/redux-border.css', |
|
| 268 | - array(), |
|
| 269 | - $this->timestamp |
|
| 270 | - ); |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - /** |
|
| 275 | - * Check to make sure all is properly set. |
|
| 276 | - * |
|
| 277 | - * @return void |
|
| 278 | - */ |
|
| 279 | - private function check_for_all() { |
|
| 280 | - if ( true === $this->field['all'] ) { |
|
| 281 | - if ( 1 !== $this->field['top'] || 1 !== $this->field['bottom'] || 1 !== $this->field['left'] || 1 !== $this->field['right'] ) { |
|
| 282 | - $this->field['all'] = false; |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /** |
|
| 288 | - * Output CSS styling. |
|
| 289 | - * |
|
| 290 | - * @param mixed $data Value array. |
|
| 291 | - * |
|
| 292 | - * @return string |
|
| 293 | - */ |
|
| 294 | - public function css_style( $data ): string { |
|
| 295 | - $style = ''; |
|
| 296 | - |
|
| 297 | - $this->check_for_all(); |
|
| 298 | - |
|
| 299 | - if ( isset( $this->field['all'] ) && true === $this->field['all'] ) { |
|
| 300 | - $border_width = $data['border-width'] ?? '0px'; |
|
| 301 | - $val = $data['border-top'] ?? $border_width; |
|
| 302 | - |
|
| 303 | - $data['border-top'] = $val; |
|
| 304 | - $data['border-bottom'] = $val; |
|
| 305 | - $data['border-left'] = $val; |
|
| 306 | - $data['border-right'] = $val; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $clean_value = array( |
|
| 310 | - 'color' => ! empty( $data['border-color'] ) ? $data['border-color'] : '', |
|
| 311 | - 'style' => ! empty( $data['border-style'] ) ? $data['border-style'] : '', |
|
| 312 | - ); |
|
| 313 | - |
|
| 314 | - $border_width = ''; |
|
| 315 | - if ( isset( $data['border-width'] ) ) { |
|
| 316 | - $border_width = $data['border-width']; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $this->field['top'] = $this->field['top'] ?? true; |
|
| 320 | - $this->field['bottom'] = $this->field['bottom'] ?? true; |
|
| 321 | - $this->field['left'] = $this->field['left'] ?? true; |
|
| 322 | - $this->field['right'] = $this->field['right'] ?? true; |
|
| 323 | - |
|
| 324 | - if ( true === $this->field['top'] ) { |
|
| 325 | - $clean_value['top'] = ! empty( $data['border-top'] ) ? $data['border-top'] : $border_width; |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - if ( true === $this->field['bottom'] ) { |
|
| 329 | - $clean_value['bottom'] = ! empty( $data['border-bottom'] ) ? $data['border-bottom'] : $border_width; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - if ( true === $this->field['left'] ) { |
|
| 333 | - $clean_value['left'] = ! empty( $data['border-left'] ) ? $data['border-left'] : $border_width; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - if ( true === $this->field['right'] ) { |
|
| 337 | - $clean_value['right'] = ! empty( $data['border-right'] ) ? $data['border-right'] : $border_width; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - // absolute, padding, margin. |
|
| 341 | - if ( ! isset( $this->field['all'] ) || true !== $this->field['all'] ) { |
|
| 342 | - foreach ( $clean_value as $key => $value ) { |
|
| 343 | - if ( 'color' === $key || 'style' === $key ) { |
|
| 344 | - continue; |
|
| 345 | - } |
|
| 346 | - if ( ! empty( $value ) ) { |
|
| 347 | - $style .= 'border-' . $key . ':' . $value . ' ' . $clean_value['style'] . ' ' . $clean_value['color'] . ';'; |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - } elseif ( ! empty( $clean_value['top'] ) ) { |
|
| 351 | - $style .= 'border:' . $clean_value['top'] . ' ' . $clean_value['style'] . ' ' . $clean_value['color'] . ';'; |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - return $style; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - /** |
|
| 358 | - * Strip alpha chars. |
|
| 359 | - * |
|
| 360 | - * @param string $s Criteria. |
|
| 361 | - * |
|
| 362 | - * @return null|string|string[] |
|
| 363 | - */ |
|
| 364 | - private function strip_alphas( string $s ) { |
|
| 365 | - // Regex is our friend. THERE ARE FOUR LIGHTS!! |
|
| 366 | - return preg_replace( '/[^\d.-]/', '', $s ); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Enable output_variables to be generated. |
|
| 371 | - * |
|
| 372 | - * @since 4.0.3 |
|
| 373 | - * @return void |
|
| 374 | - */ |
|
| 375 | - public function output_variables() { |
|
| 376 | - // No code needed, just defining the method is enough. |
|
| 377 | - } |
|
| 378 | - } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Border-style |
|
| 166 | + * */ |
|
| 167 | + if ( false !== $this->field['style'] ) { |
|
| 168 | + $options = array( |
|
| 169 | + 'solid' => esc_html__( 'Solid', 'redux-framework' ), |
|
| 170 | + 'dashed' => esc_html__( 'Dashed', 'redux-framework' ), |
|
| 171 | + 'dotted' => esc_html__( 'Dotted', 'redux-framework' ), |
|
| 172 | + 'double' => esc_html__( 'Double', 'redux-framework' ), |
|
| 173 | + 'none' => esc_html__( 'None', 'redux-framework' ), |
|
| 174 | + ); |
|
| 175 | + |
|
| 176 | + echo '<select data-placeholder="' . esc_html__( 'Border style', 'redux-framework' ) . '" id="' . esc_attr( $this->field['id'] ) . '[border-style]" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-style]" class="tips redux-border-style ' . esc_attr( $this->field['class'] ) . '" rows="6" data-id="' . esc_attr( $this->field['id'] ) . '"' . esc_attr( $select2_data ) . '>'; |
|
| 177 | + |
|
| 178 | + foreach ( $options as $k => $v ) { |
|
| 179 | + echo '<option value="' . esc_attr( $k ) . '" ' . selected( $value['style'], $k, false ) . '>' . esc_html( $v ) . '</option>'; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + echo '</select>'; |
|
| 183 | + } else { |
|
| 184 | + echo '<input type="hidden" id="' . esc_attr( $this->field['id'] ) . '[border-style]" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-style]" value="' . esc_attr( $this->value['style'] ) . '" data-id="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Color |
|
| 189 | + * */ |
|
| 190 | + if ( false !== $this->field['color'] ) { |
|
| 191 | + $default = $this->field['default']['border-color'] ?? ''; |
|
| 192 | + |
|
| 193 | + if ( empty( $default ) ) { |
|
| 194 | + $default = ( isset( $this->field['default']['color'] ) ) ? $this->field['default']['color'] : '#ffffff'; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + echo '<input '; |
|
| 198 | + echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-color]"'; |
|
| 199 | + echo 'id="' . esc_attr( $this->field['id'] ) . '-border"'; |
|
| 200 | + echo 'class="color-picker redux-border-color redux-color redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 201 | + echo 'type="text"'; |
|
| 202 | + echo 'value="' . esc_attr( $this->value['color'] ) . '"'; |
|
| 203 | + echo 'data-default-color="' . esc_attr( $default ) . '"'; |
|
| 204 | + echo 'data-id="' . esc_attr( $this->field['id'] ) . '"'; |
|
| 205 | + |
|
| 206 | + $data = array( |
|
| 207 | + 'field' => $this->field, |
|
| 208 | + 'index' => '', |
|
| 209 | + ); |
|
| 210 | + |
|
| 211 | + echo Redux_Functions_Ex::output_alpha_data( $data ); // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 212 | + |
|
| 213 | + echo '>'; |
|
| 214 | + } else { |
|
| 215 | + echo '<input type="hidden" id="' . esc_attr( $this->field['id'] ) . '[border-color]" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[border-color]" value="' . esc_attr( $this->value['color'] ) . '" data-id="' . esc_attr( $this->field['id'] ) . '">'; |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Do enqueue for each field instance. |
|
| 222 | + * |
|
| 223 | + * @return void |
|
| 224 | + */ |
|
| 225 | + public function always_enqueue() { |
|
| 226 | + if ( isset( $this->field['color_alpha'] ) && $this->field['color_alpha'] ) { |
|
| 227 | + if ( ! wp_script_is( 'redux-wp-color-picker-alpha' ) ) { |
|
| 228 | + wp_enqueue_script( 'redux-wp-color-picker-alpha' ); |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Enqueue Function. |
|
| 235 | + * If this field requires any scripts, or css define this function and register/enqueue the scripts/css |
|
| 236 | + * |
|
| 237 | + * @since ReduxFramework 1.0.0 |
|
| 238 | + */ |
|
| 239 | + public function enqueue() { |
|
| 240 | + $min = Redux_Functions::is_min(); |
|
| 241 | + |
|
| 242 | + if ( ! wp_style_is( 'select2-css' ) ) { |
|
| 243 | + wp_enqueue_style( 'select2-css' ); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + if ( ! wp_style_is( 'wp-color-picker' ) ) { |
|
| 247 | + wp_enqueue_style( 'wp-color-picker' ); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $dep_array = array( 'jquery', 'select2-js', 'wp-color-picker', 'redux-js' ); |
|
| 251 | + |
|
| 252 | + wp_enqueue_script( |
|
| 253 | + 'redux-field-border', |
|
| 254 | + Redux_Core::$url . 'inc/fields/border/redux-border' . $min . '.js', |
|
| 255 | + $dep_array, |
|
| 256 | + $this->timestamp, |
|
| 257 | + true |
|
| 258 | + ); |
|
| 259 | + |
|
| 260 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 261 | + if ( ! wp_style_is( 'redux-color-picker' ) ) { |
|
| 262 | + wp_enqueue_style( 'redux-color-picker' ); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + wp_enqueue_style( |
|
| 266 | + 'redux-field-border', |
|
| 267 | + Redux_Core::$url . 'inc/fields/border/redux-border.css', |
|
| 268 | + array(), |
|
| 269 | + $this->timestamp |
|
| 270 | + ); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + /** |
|
| 275 | + * Check to make sure all is properly set. |
|
| 276 | + * |
|
| 277 | + * @return void |
|
| 278 | + */ |
|
| 279 | + private function check_for_all() { |
|
| 280 | + if ( true === $this->field['all'] ) { |
|
| 281 | + if ( 1 !== $this->field['top'] || 1 !== $this->field['bottom'] || 1 !== $this->field['left'] || 1 !== $this->field['right'] ) { |
|
| 282 | + $this->field['all'] = false; |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /** |
|
| 288 | + * Output CSS styling. |
|
| 289 | + * |
|
| 290 | + * @param mixed $data Value array. |
|
| 291 | + * |
|
| 292 | + * @return string |
|
| 293 | + */ |
|
| 294 | + public function css_style( $data ): string { |
|
| 295 | + $style = ''; |
|
| 296 | + |
|
| 297 | + $this->check_for_all(); |
|
| 298 | + |
|
| 299 | + if ( isset( $this->field['all'] ) && true === $this->field['all'] ) { |
|
| 300 | + $border_width = $data['border-width'] ?? '0px'; |
|
| 301 | + $val = $data['border-top'] ?? $border_width; |
|
| 302 | + |
|
| 303 | + $data['border-top'] = $val; |
|
| 304 | + $data['border-bottom'] = $val; |
|
| 305 | + $data['border-left'] = $val; |
|
| 306 | + $data['border-right'] = $val; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + $clean_value = array( |
|
| 310 | + 'color' => ! empty( $data['border-color'] ) ? $data['border-color'] : '', |
|
| 311 | + 'style' => ! empty( $data['border-style'] ) ? $data['border-style'] : '', |
|
| 312 | + ); |
|
| 313 | + |
|
| 314 | + $border_width = ''; |
|
| 315 | + if ( isset( $data['border-width'] ) ) { |
|
| 316 | + $border_width = $data['border-width']; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $this->field['top'] = $this->field['top'] ?? true; |
|
| 320 | + $this->field['bottom'] = $this->field['bottom'] ?? true; |
|
| 321 | + $this->field['left'] = $this->field['left'] ?? true; |
|
| 322 | + $this->field['right'] = $this->field['right'] ?? true; |
|
| 323 | + |
|
| 324 | + if ( true === $this->field['top'] ) { |
|
| 325 | + $clean_value['top'] = ! empty( $data['border-top'] ) ? $data['border-top'] : $border_width; |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + if ( true === $this->field['bottom'] ) { |
|
| 329 | + $clean_value['bottom'] = ! empty( $data['border-bottom'] ) ? $data['border-bottom'] : $border_width; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + if ( true === $this->field['left'] ) { |
|
| 333 | + $clean_value['left'] = ! empty( $data['border-left'] ) ? $data['border-left'] : $border_width; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + if ( true === $this->field['right'] ) { |
|
| 337 | + $clean_value['right'] = ! empty( $data['border-right'] ) ? $data['border-right'] : $border_width; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + // absolute, padding, margin. |
|
| 341 | + if ( ! isset( $this->field['all'] ) || true !== $this->field['all'] ) { |
|
| 342 | + foreach ( $clean_value as $key => $value ) { |
|
| 343 | + if ( 'color' === $key || 'style' === $key ) { |
|
| 344 | + continue; |
|
| 345 | + } |
|
| 346 | + if ( ! empty( $value ) ) { |
|
| 347 | + $style .= 'border-' . $key . ':' . $value . ' ' . $clean_value['style'] . ' ' . $clean_value['color'] . ';'; |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + } elseif ( ! empty( $clean_value['top'] ) ) { |
|
| 351 | + $style .= 'border:' . $clean_value['top'] . ' ' . $clean_value['style'] . ' ' . $clean_value['color'] . ';'; |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + return $style; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + /** |
|
| 358 | + * Strip alpha chars. |
|
| 359 | + * |
|
| 360 | + * @param string $s Criteria. |
|
| 361 | + * |
|
| 362 | + * @return null|string|string[] |
|
| 363 | + */ |
|
| 364 | + private function strip_alphas( string $s ) { |
|
| 365 | + // Regex is our friend. THERE ARE FOUR LIGHTS!! |
|
| 366 | + return preg_replace( '/[^\d.-]/', '', $s ); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Enable output_variables to be generated. |
|
| 371 | + * |
|
| 372 | + * @since 4.0.3 |
|
| 373 | + * @return void |
|
| 374 | + */ |
|
| 375 | + public function output_variables() { |
|
| 376 | + // No code needed, just defining the method is enough. |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | class_alias( 'Redux_Border', 'ReduxFramework_Border' ); |
@@ -12,104 +12,104 @@ discard block |
||
| 12 | 12 | |
| 13 | 13 | if ( ! class_exists( 'Redux_Box_Shadow', false ) ) { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * Main Redux_Box_Shadow class |
|
| 17 | - * |
|
| 18 | - * @since 4.0.0 |
|
| 19 | - */ |
|
| 20 | - class Redux_Box_Shadow extends Redux_Field { |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Set defaults. |
|
| 24 | - */ |
|
| 25 | - public function set_defaults() { |
|
| 26 | - |
|
| 27 | - $defaults = array( |
|
| 28 | - 'inset-shadow' => true, |
|
| 29 | - 'drop-shadow' => true, |
|
| 30 | - 'preview-color' => '#f1f1f1', |
|
| 31 | - ); |
|
| 32 | - |
|
| 33 | - $this->field = Redux_Functions::parse_args( $this->field, $defaults ); |
|
| 34 | - |
|
| 35 | - $defaults = array( |
|
| 36 | - 'inset' => true, |
|
| 37 | - 'drop' => true, |
|
| 38 | - 'inset-shadow' => array( |
|
| 39 | - 'checked' => false, |
|
| 40 | - 'color' => '#ABABAB', |
|
| 41 | - 'horizontal' => 0, |
|
| 42 | - 'vertical' => 0, |
|
| 43 | - 'blur' => 10, |
|
| 44 | - 'spread' => 0, |
|
| 45 | - ), |
|
| 46 | - 'drop-shadow' => array( |
|
| 47 | - 'checked' => true, |
|
| 48 | - 'color' => '#dddddd', |
|
| 49 | - 'horizontal' => 5, |
|
| 50 | - 'vertical' => 5, |
|
| 51 | - 'blur' => 5, |
|
| 52 | - 'spread' => 1, |
|
| 53 | - ), |
|
| 54 | - ); |
|
| 55 | - |
|
| 56 | - $this->value = Redux_Functions::parse_args( $this->value, $defaults ); |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * Field Render Function. |
|
| 61 | - * Takes the vars and outputs the HTML for the field in the settings |
|
| 62 | - * |
|
| 63 | - * @since 1.0.0 |
|
| 64 | - * @access public |
|
| 65 | - * @return void |
|
| 66 | - */ |
|
| 67 | - public function render() { |
|
| 68 | - $shadow_arr = array( |
|
| 69 | - 'inset', |
|
| 70 | - 'drop', |
|
| 71 | - ); |
|
| 72 | - |
|
| 73 | - echo '<div class="box-shadow-inset">'; |
|
| 74 | - echo '<div class="box-shadow-controls row">'; |
|
| 75 | - |
|
| 76 | - foreach ( $shadow_arr as $shadow_type ) { |
|
| 77 | - if ( $this->field[ $shadow_type . '-shadow' ] ) { |
|
| 78 | - $disabled = ' shadow-disabled'; |
|
| 79 | - |
|
| 80 | - if ( $this->value[ $shadow_type . '-shadow' ]['checked'] ) { |
|
| 81 | - $disabled = ''; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $slider_disable = disabled( filter_var( $this->value[ $shadow_type . '-shadow' ]['checked'], FILTER_VALIDATE_BOOLEAN ), false, false ); |
|
| 85 | - |
|
| 86 | - echo '<div class="col-2 shadow-' . esc_attr( $shadow_type ) . ' " data-shadow="' . esc_attr( $shadow_type ) . '">'; |
|
| 87 | - echo '<ul>'; |
|
| 88 | - echo '<li>'; |
|
| 89 | - echo '<label for="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-shadow" class="' . esc_attr( $disabled ) . '">'; |
|
| 90 | - echo '<input type="checkbox" id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-shadow" class="checkbox" value="1"' . checked( $this->value[ $shadow_type . '-shadow' ]['checked'], '1', false ) . '/>'; |
|
| 91 | - echo '<input type="hidden" data-val="1" value="' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['checked'] ) . '" class="checkbox-check" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[' . esc_attr( $shadow_type ) . '-shadow][checked]"/>'; |
|
| 92 | - echo esc_html( ucfirst( $shadow_type ) ) . ' ' . esc_html__( 'Shadow', 'redux-framework' ); |
|
| 93 | - echo '</label>'; |
|
| 94 | - echo '</li>'; |
|
| 95 | - echo '<li>'; |
|
| 96 | - |
|
| 97 | - $def_color = $this->field['default'][ $shadow_type . '-shadow' ]['color'] ?? ''; |
|
| 98 | - |
|
| 99 | - echo '<input '; |
|
| 100 | - echo 'data-id="' . esc_attr( $this->field['id'] ) . '"'; |
|
| 101 | - echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[' . esc_attr( $shadow_type ) . '-shadow][color]"'; |
|
| 102 | - echo 'id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-color"'; |
|
| 103 | - echo 'class="color-picker redux-color redux-box-shadow-' . esc_attr( $shadow_type ) . '-input redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 104 | - echo 'type="text" value="' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['color'] ) . '"'; |
|
| 105 | - echo 'data-default-color="' . esc_attr( $def_color ) . '"'; |
|
| 106 | - |
|
| 107 | - echo '/>'; |
|
| 108 | - echo '</li>'; |
|
| 109 | - echo '<li>'; |
|
| 110 | - echo '<div class="slider-' . esc_attr( $shadow_type ) . '-horizontal">'; |
|
| 111 | - echo esc_html__( 'Horizontal Length', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[ $shadow_type . '-shadow' ]['horizontal'] ) . 'px</strong>'; |
|
| 112 | - echo '<div |
|
| 15 | + /** |
|
| 16 | + * Main Redux_Box_Shadow class |
|
| 17 | + * |
|
| 18 | + * @since 4.0.0 |
|
| 19 | + */ |
|
| 20 | + class Redux_Box_Shadow extends Redux_Field { |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Set defaults. |
|
| 24 | + */ |
|
| 25 | + public function set_defaults() { |
|
| 26 | + |
|
| 27 | + $defaults = array( |
|
| 28 | + 'inset-shadow' => true, |
|
| 29 | + 'drop-shadow' => true, |
|
| 30 | + 'preview-color' => '#f1f1f1', |
|
| 31 | + ); |
|
| 32 | + |
|
| 33 | + $this->field = Redux_Functions::parse_args( $this->field, $defaults ); |
|
| 34 | + |
|
| 35 | + $defaults = array( |
|
| 36 | + 'inset' => true, |
|
| 37 | + 'drop' => true, |
|
| 38 | + 'inset-shadow' => array( |
|
| 39 | + 'checked' => false, |
|
| 40 | + 'color' => '#ABABAB', |
|
| 41 | + 'horizontal' => 0, |
|
| 42 | + 'vertical' => 0, |
|
| 43 | + 'blur' => 10, |
|
| 44 | + 'spread' => 0, |
|
| 45 | + ), |
|
| 46 | + 'drop-shadow' => array( |
|
| 47 | + 'checked' => true, |
|
| 48 | + 'color' => '#dddddd', |
|
| 49 | + 'horizontal' => 5, |
|
| 50 | + 'vertical' => 5, |
|
| 51 | + 'blur' => 5, |
|
| 52 | + 'spread' => 1, |
|
| 53 | + ), |
|
| 54 | + ); |
|
| 55 | + |
|
| 56 | + $this->value = Redux_Functions::parse_args( $this->value, $defaults ); |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * Field Render Function. |
|
| 61 | + * Takes the vars and outputs the HTML for the field in the settings |
|
| 62 | + * |
|
| 63 | + * @since 1.0.0 |
|
| 64 | + * @access public |
|
| 65 | + * @return void |
|
| 66 | + */ |
|
| 67 | + public function render() { |
|
| 68 | + $shadow_arr = array( |
|
| 69 | + 'inset', |
|
| 70 | + 'drop', |
|
| 71 | + ); |
|
| 72 | + |
|
| 73 | + echo '<div class="box-shadow-inset">'; |
|
| 74 | + echo '<div class="box-shadow-controls row">'; |
|
| 75 | + |
|
| 76 | + foreach ( $shadow_arr as $shadow_type ) { |
|
| 77 | + if ( $this->field[ $shadow_type . '-shadow' ] ) { |
|
| 78 | + $disabled = ' shadow-disabled'; |
|
| 79 | + |
|
| 80 | + if ( $this->value[ $shadow_type . '-shadow' ]['checked'] ) { |
|
| 81 | + $disabled = ''; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $slider_disable = disabled( filter_var( $this->value[ $shadow_type . '-shadow' ]['checked'], FILTER_VALIDATE_BOOLEAN ), false, false ); |
|
| 85 | + |
|
| 86 | + echo '<div class="col-2 shadow-' . esc_attr( $shadow_type ) . ' " data-shadow="' . esc_attr( $shadow_type ) . '">'; |
|
| 87 | + echo '<ul>'; |
|
| 88 | + echo '<li>'; |
|
| 89 | + echo '<label for="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-shadow" class="' . esc_attr( $disabled ) . '">'; |
|
| 90 | + echo '<input type="checkbox" id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-shadow" class="checkbox" value="1"' . checked( $this->value[ $shadow_type . '-shadow' ]['checked'], '1', false ) . '/>'; |
|
| 91 | + echo '<input type="hidden" data-val="1" value="' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['checked'] ) . '" class="checkbox-check" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[' . esc_attr( $shadow_type ) . '-shadow][checked]"/>'; |
|
| 92 | + echo esc_html( ucfirst( $shadow_type ) ) . ' ' . esc_html__( 'Shadow', 'redux-framework' ); |
|
| 93 | + echo '</label>'; |
|
| 94 | + echo '</li>'; |
|
| 95 | + echo '<li>'; |
|
| 96 | + |
|
| 97 | + $def_color = $this->field['default'][ $shadow_type . '-shadow' ]['color'] ?? ''; |
|
| 98 | + |
|
| 99 | + echo '<input '; |
|
| 100 | + echo 'data-id="' . esc_attr( $this->field['id'] ) . '"'; |
|
| 101 | + echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[' . esc_attr( $shadow_type ) . '-shadow][color]"'; |
|
| 102 | + echo 'id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-color"'; |
|
| 103 | + echo 'class="color-picker redux-color redux-box-shadow-' . esc_attr( $shadow_type ) . '-input redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
|
| 104 | + echo 'type="text" value="' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['color'] ) . '"'; |
|
| 105 | + echo 'data-default-color="' . esc_attr( $def_color ) . '"'; |
|
| 106 | + |
|
| 107 | + echo '/>'; |
|
| 108 | + echo '</li>'; |
|
| 109 | + echo '<li>'; |
|
| 110 | + echo '<div class="slider-' . esc_attr( $shadow_type ) . '-horizontal">'; |
|
| 111 | + echo esc_html__( 'Horizontal Length', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[ $shadow_type . '-shadow' ]['horizontal'] ) . 'px</strong>'; |
|
| 112 | + echo '<div |
|
| 113 | 113 | class="redux-box-shadow-slider redux-box-shadow-' . esc_attr( $shadow_type ) . ' redux-' . esc_attr( $shadow_type ) . '-horizontal ' . esc_attr( $shadow_type ) . '-horizontal-input ' . esc_attr( $this->field['class'] ) . '" |
| 114 | 114 | id="' . esc_attr( $this->field['id'] ) . '" |
| 115 | 115 | data-id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-horizontal" |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | data-label="' . esc_attr__( 'Horizontal Length', 'redux-framework' ) . '" |
| 121 | 121 | data-default = "' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['horizontal'] ) . '" ' . esc_html( $slider_disable ) . '> |
| 122 | 122 | </div>'; |
| 123 | - echo '<input |
|
| 123 | + echo '<input |
|
| 124 | 124 | type="hidden" |
| 125 | 125 | id="redux-slider-value-' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-horizontal" |
| 126 | 126 | class="' . esc_attr( $shadow_type ) . '-horizontal" |
@@ -128,12 +128,12 @@ discard block |
||
| 128 | 128 | value="' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['horizontal'] ) . '" |
| 129 | 129 | data-id="' . esc_attr( $this->field['id'] ) . '" |
| 130 | 130 | />'; |
| 131 | - echo '</div>'; |
|
| 132 | - echo '</li>'; |
|
| 133 | - echo '<li>'; |
|
| 134 | - echo '<div class="slider-' . esc_attr( $shadow_type ) . '-vertical">'; |
|
| 135 | - echo esc_html__( 'Vertical Length', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[ $shadow_type . '-shadow' ]['vertical'] ) . 'px</strong>'; |
|
| 136 | - echo '<div |
|
| 131 | + echo '</div>'; |
|
| 132 | + echo '</li>'; |
|
| 133 | + echo '<li>'; |
|
| 134 | + echo '<div class="slider-' . esc_attr( $shadow_type ) . '-vertical">'; |
|
| 135 | + echo esc_html__( 'Vertical Length', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[ $shadow_type . '-shadow' ]['vertical'] ) . 'px</strong>'; |
|
| 136 | + echo '<div |
|
| 137 | 137 | class="redux-box-shadow-slider redux-box-shadow-' . esc_attr( $shadow_type ) . ' redux-' . esc_attr( $shadow_type ) . '-vertical ' . esc_attr( $shadow_type ) . '-vertical-input ' . esc_attr( $this->field['class'] ) . '" |
| 138 | 138 | id="' . esc_attr( $this->field['id'] ) . '" |
| 139 | 139 | data-id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-vertical" |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | data-label="' . esc_attr__( 'Vertical Length', 'redux-framework' ) . '" |
| 145 | 145 | data-default = "' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['vertical'] ) . '" ' . esc_html( $slider_disable ) . '> |
| 146 | 146 | </div>'; |
| 147 | - echo '<input |
|
| 147 | + echo '<input |
|
| 148 | 148 | type="hidden" |
| 149 | 149 | id="redux-slider-value-' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-vertical" |
| 150 | 150 | class="' . esc_attr( $shadow_type ) . '-vertical" |
@@ -152,12 +152,12 @@ discard block |
||
| 152 | 152 | value="' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['vertical'] ) . '" |
| 153 | 153 | data-id="' . esc_attr( $this->field['id'] ) . '" |
| 154 | 154 | />'; |
| 155 | - echo '</div>'; |
|
| 156 | - echo '</li>'; |
|
| 157 | - echo '<li>'; |
|
| 158 | - echo '<div class="slider-' . esc_attr( $shadow_type ) . '-blur">'; |
|
| 159 | - echo esc_html__( 'Blur Radius', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[ $shadow_type . '-shadow' ]['blur'] ) . 'px</strong>'; |
|
| 160 | - echo '<div |
|
| 155 | + echo '</div>'; |
|
| 156 | + echo '</li>'; |
|
| 157 | + echo '<li>'; |
|
| 158 | + echo '<div class="slider-' . esc_attr( $shadow_type ) . '-blur">'; |
|
| 159 | + echo esc_html__( 'Blur Radius', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[ $shadow_type . '-shadow' ]['blur'] ) . 'px</strong>'; |
|
| 160 | + echo '<div |
|
| 161 | 161 | class="redux-box-shadow-slider redux-box-shadow-' . esc_attr( $shadow_type ) . ' redux-' . esc_attr( $shadow_type ) . '-blur ' . esc_attr( $shadow_type ) . '-blur-input ' . esc_attr( $this->field['class'] ) . '" |
| 162 | 162 | id="' . esc_attr( $this->field['id'] ) . '" |
| 163 | 163 | data-id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-blur" |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | data-label="' . esc_attr__( 'Blur Radius', 'redux-framework' ) . '" |
| 169 | 169 | data-default = "' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['blur'] ) . '" ' . esc_html( $slider_disable ) . '> |
| 170 | 170 | </div>'; |
| 171 | - echo '<input |
|
| 171 | + echo '<input |
|
| 172 | 172 | type="hidden" |
| 173 | 173 | id="redux-slider-value-' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-blur" |
| 174 | 174 | class="' . esc_attr( $shadow_type ) . '-blur" |
@@ -176,12 +176,12 @@ discard block |
||
| 176 | 176 | value="' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['blur'] ) . '" |
| 177 | 177 | data-id="' . esc_attr( $this->field['id'] ) . '" |
| 178 | 178 | />'; |
| 179 | - echo '</div>'; |
|
| 180 | - echo '</li>'; |
|
| 181 | - echo '<li>'; |
|
| 182 | - echo '<div class="slider-' . esc_attr( $shadow_type ) . '-spread">'; |
|
| 183 | - echo esc_html__( 'Spread', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[ $shadow_type . '-shadow' ]['spread'] ) . 'px</strong>'; |
|
| 184 | - echo '<div |
|
| 179 | + echo '</div>'; |
|
| 180 | + echo '</li>'; |
|
| 181 | + echo '<li>'; |
|
| 182 | + echo '<div class="slider-' . esc_attr( $shadow_type ) . '-spread">'; |
|
| 183 | + echo esc_html__( 'Spread', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[ $shadow_type . '-shadow' ]['spread'] ) . 'px</strong>'; |
|
| 184 | + echo '<div |
|
| 185 | 185 | class="redux-box-shadow-slider redux-box-shadow-' . esc_attr( $shadow_type ) . ' redux-' . esc_attr( $shadow_type ) . '-spread ' . esc_attr( $shadow_type ) . '-spread-input ' . esc_attr( $this->field['class'] ) . '" |
| 186 | 186 | id="' . esc_attr( $this->field['id'] ) . '" |
| 187 | 187 | data-id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-spread" |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | data-label="' . esc_attr__( 'Spread', 'redux-framework' ) . '" |
| 193 | 193 | data-default = "' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['spread'] ) . '" ' . esc_html( $slider_disable ) . '> |
| 194 | 194 | </div>'; |
| 195 | - echo '<input |
|
| 195 | + echo '<input |
|
| 196 | 196 | type="hidden" |
| 197 | 197 | id="redux-slider-value-' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-spread" |
| 198 | 198 | class="' . esc_attr( $shadow_type ) . '-spread" |
@@ -200,131 +200,131 @@ discard block |
||
| 200 | 200 | value="' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['spread'] ) . '" |
| 201 | 201 | data-id="' . esc_attr( $this->field['id'] ) . '" |
| 202 | 202 | />'; |
| 203 | - echo '</div>'; |
|
| 204 | - echo '</li>'; |
|
| 205 | - echo '</ul>'; |
|
| 206 | - echo '</div>'; |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - $css = $this->css_style( $this->value ); |
|
| 211 | - $css .= 'background:' . esc_html( $this->field['preview-color'] ); |
|
| 212 | - |
|
| 213 | - echo '</div>'; |
|
| 214 | - echo '<div class="" id="shadow-result" style="' . $css . '"></div>'; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 215 | - echo '</div>'; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Compile CSS output. |
|
| 220 | - * |
|
| 221 | - * @param mixed $data Data. |
|
| 222 | - * |
|
| 223 | - * @return string |
|
| 224 | - */ |
|
| 225 | - public function css_style( $data ): string { |
|
| 226 | - $css = ''; |
|
| 227 | - |
|
| 228 | - if ( $this->field['inset-shadow'] ) { |
|
| 229 | - $inset = $data['inset-shadow']; |
|
| 230 | - |
|
| 231 | - if ( filter_var( $inset['checked'], FILTER_VALIDATE_BOOLEAN ) ) { |
|
| 232 | - $h = $inset['horizontal']; |
|
| 233 | - $v = $inset['vertical']; |
|
| 234 | - $b = $inset['blur']; |
|
| 235 | - $s = $inset['spread']; |
|
| 236 | - $color = $inset['color']; |
|
| 237 | - |
|
| 238 | - $css .= 'inset ' . $h . 'px ' . $v . 'px ' . $b . 'px ' . $s . 'px ' . $color; |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - if ( $this->field['drop-shadow'] ) { |
|
| 243 | - $drop = $data['drop-shadow']; |
|
| 244 | - |
|
| 245 | - if ( filter_var( $drop['checked'], FILTER_VALIDATE_BOOLEAN ) ) { |
|
| 246 | - $h = $drop['horizontal']; |
|
| 247 | - $v = $drop['vertical']; |
|
| 248 | - $b = $drop['blur']; |
|
| 249 | - $s = $drop['spread']; |
|
| 250 | - $color = $drop['color']; |
|
| 251 | - |
|
| 252 | - if ( '' !== $css ) { |
|
| 253 | - $css .= ','; |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - $css .= $h . 'px ' . $v . 'px ' . $b . 'px ' . $s . 'px ' . $color; |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - if ( '' !== $css ) { |
|
| 261 | - $css = 'box-shadow:' . $css . ';-webkit-box-shadow:' . $css . ';-moz-box-shadow:' . $css . ';-o-box-shadow:' . $css . ';'; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - return $css; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * Do enqueue for each field instance. |
|
| 269 | - * |
|
| 270 | - * @return void |
|
| 271 | - */ |
|
| 272 | - public function always_enqueue() { |
|
| 273 | - if ( isset( $this->field['color_alpha'] ) && ( $this->field['color_alpha'] || ( $this->field['color_alpha']['inset-shadow'] || $this->field['color_alpha']['drop-shadow'] ) ) ) { |
|
| 274 | - wp_enqueue_script( 'redux-wp-color-picker-alpha' ); |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - /** |
|
| 279 | - * Enqueue Function. |
|
| 280 | - * If this field requires any scripts, or CSS define this function and register/enqueue the scripts/css |
|
| 281 | - * |
|
| 282 | - * @since 1.0.0 |
|
| 283 | - * @access public |
|
| 284 | - * @return void |
|
| 285 | - */ |
|
| 286 | - public function enqueue() { |
|
| 287 | - $min = Redux_Functions::is_min(); |
|
| 288 | - |
|
| 289 | - if ( ! wp_style_is( 'wp-color-picker' ) ) { |
|
| 290 | - wp_enqueue_style( 'wp-color-picker' ); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - $dep_array = array( 'jquery', 'wp-color-picker', 'redux-js' ); |
|
| 294 | - |
|
| 295 | - wp_enqueue_script( |
|
| 296 | - 'redux-field-box-shadow', |
|
| 297 | - Redux_Core::$url . 'inc/fields/box_shadow/redux-box-shadow' . $min . '.js', |
|
| 298 | - $dep_array, |
|
| 299 | - $this->timestamp, |
|
| 300 | - true |
|
| 301 | - ); |
|
| 302 | - |
|
| 303 | - wp_enqueue_style( |
|
| 304 | - 'redux-nouislider', |
|
| 305 | - Redux_Core::$url . 'assets/css/vendor/nouislider' . $min . '.css', |
|
| 306 | - array(), |
|
| 307 | - '5.0.0' |
|
| 308 | - ); |
|
| 309 | - |
|
| 310 | - wp_enqueue_script( |
|
| 311 | - 'redux-nouislider', |
|
| 312 | - Redux_Core::$url . 'assets/js/vendor/nouislider/redux.jquery.nouislider' . $min . '.js', |
|
| 313 | - array( 'jquery' ), |
|
| 314 | - '5.0.0', |
|
| 315 | - true |
|
| 316 | - ); |
|
| 317 | - |
|
| 318 | - if ( $this->parent->args['dev_mode'] ) { |
|
| 319 | - wp_enqueue_style( |
|
| 320 | - 'redux-field-box-shadow', |
|
| 321 | - Redux_Core::$url . 'inc/fields/box_shadow/redux-box-shadow.css', |
|
| 322 | - array(), |
|
| 323 | - time() |
|
| 324 | - ); |
|
| 325 | - |
|
| 326 | - wp_enqueue_style( 'redux-color-picker' ); |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - } |
|
| 203 | + echo '</div>'; |
|
| 204 | + echo '</li>'; |
|
| 205 | + echo '</ul>'; |
|
| 206 | + echo '</div>'; |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + $css = $this->css_style( $this->value ); |
|
| 211 | + $css .= 'background:' . esc_html( $this->field['preview-color'] ); |
|
| 212 | + |
|
| 213 | + echo '</div>'; |
|
| 214 | + echo '<div class="" id="shadow-result" style="' . $css . '"></div>'; // phpcs:ignore WordPress.Security.EscapeOutput |
|
| 215 | + echo '</div>'; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Compile CSS output. |
|
| 220 | + * |
|
| 221 | + * @param mixed $data Data. |
|
| 222 | + * |
|
| 223 | + * @return string |
|
| 224 | + */ |
|
| 225 | + public function css_style( $data ): string { |
|
| 226 | + $css = ''; |
|
| 227 | + |
|
| 228 | + if ( $this->field['inset-shadow'] ) { |
|
| 229 | + $inset = $data['inset-shadow']; |
|
| 230 | + |
|
| 231 | + if ( filter_var( $inset['checked'], FILTER_VALIDATE_BOOLEAN ) ) { |
|
| 232 | + $h = $inset['horizontal']; |
|
| 233 | + $v = $inset['vertical']; |
|
| 234 | + $b = $inset['blur']; |
|
| 235 | + $s = $inset['spread']; |
|
| 236 | + $color = $inset['color']; |
|
| 237 | + |
|
| 238 | + $css .= 'inset ' . $h . 'px ' . $v . 'px ' . $b . 'px ' . $s . 'px ' . $color; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + if ( $this->field['drop-shadow'] ) { |
|
| 243 | + $drop = $data['drop-shadow']; |
|
| 244 | + |
|
| 245 | + if ( filter_var( $drop['checked'], FILTER_VALIDATE_BOOLEAN ) ) { |
|
| 246 | + $h = $drop['horizontal']; |
|
| 247 | + $v = $drop['vertical']; |
|
| 248 | + $b = $drop['blur']; |
|
| 249 | + $s = $drop['spread']; |
|
| 250 | + $color = $drop['color']; |
|
| 251 | + |
|
| 252 | + if ( '' !== $css ) { |
|
| 253 | + $css .= ','; |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + $css .= $h . 'px ' . $v . 'px ' . $b . 'px ' . $s . 'px ' . $color; |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + if ( '' !== $css ) { |
|
| 261 | + $css = 'box-shadow:' . $css . ';-webkit-box-shadow:' . $css . ';-moz-box-shadow:' . $css . ';-o-box-shadow:' . $css . ';'; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + return $css; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * Do enqueue for each field instance. |
|
| 269 | + * |
|
| 270 | + * @return void |
|
| 271 | + */ |
|
| 272 | + public function always_enqueue() { |
|
| 273 | + if ( isset( $this->field['color_alpha'] ) && ( $this->field['color_alpha'] || ( $this->field['color_alpha']['inset-shadow'] || $this->field['color_alpha']['drop-shadow'] ) ) ) { |
|
| 274 | + wp_enqueue_script( 'redux-wp-color-picker-alpha' ); |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + /** |
|
| 279 | + * Enqueue Function. |
|
| 280 | + * If this field requires any scripts, or CSS define this function and register/enqueue the scripts/css |
|
| 281 | + * |
|
| 282 | + * @since 1.0.0 |
|
| 283 | + * @access public |
|
| 284 | + * @return void |
|
| 285 | + */ |
|
| 286 | + public function enqueue() { |
|
| 287 | + $min = Redux_Functions::is_min(); |
|
| 288 | + |
|
| 289 | + if ( ! wp_style_is( 'wp-color-picker' ) ) { |
|
| 290 | + wp_enqueue_style( 'wp-color-picker' ); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + $dep_array = array( 'jquery', 'wp-color-picker', 'redux-js' ); |
|
| 294 | + |
|
| 295 | + wp_enqueue_script( |
|
| 296 | + 'redux-field-box-shadow', |
|
| 297 | + Redux_Core::$url . 'inc/fields/box_shadow/redux-box-shadow' . $min . '.js', |
|
| 298 | + $dep_array, |
|
| 299 | + $this->timestamp, |
|
| 300 | + true |
|
| 301 | + ); |
|
| 302 | + |
|
| 303 | + wp_enqueue_style( |
|
| 304 | + 'redux-nouislider', |
|
| 305 | + Redux_Core::$url . 'assets/css/vendor/nouislider' . $min . '.css', |
|
| 306 | + array(), |
|
| 307 | + '5.0.0' |
|
| 308 | + ); |
|
| 309 | + |
|
| 310 | + wp_enqueue_script( |
|
| 311 | + 'redux-nouislider', |
|
| 312 | + Redux_Core::$url . 'assets/js/vendor/nouislider/redux.jquery.nouislider' . $min . '.js', |
|
| 313 | + array( 'jquery' ), |
|
| 314 | + '5.0.0', |
|
| 315 | + true |
|
| 316 | + ); |
|
| 317 | + |
|
| 318 | + if ( $this->parent->args['dev_mode'] ) { |
|
| 319 | + wp_enqueue_style( |
|
| 320 | + 'redux-field-box-shadow', |
|
| 321 | + Redux_Core::$url . 'inc/fields/box_shadow/redux-box-shadow.css', |
|
| 322 | + array(), |
|
| 323 | + time() |
|
| 324 | + ); |
|
| 325 | + |
|
| 326 | + wp_enqueue_style( 'redux-color-picker' ); |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | 330 | } |
@@ -74,41 +74,41 @@ discard block |
||
| 74 | 74 | echo '<div class="box-shadow-controls row">'; |
| 75 | 75 | |
| 76 | 76 | foreach ( $shadow_arr as $shadow_type ) { |
| 77 | - if ( $this->field[ $shadow_type . '-shadow' ] ) { |
|
| 77 | + if ( $this->field[$shadow_type . '-shadow'] ) { |
|
| 78 | 78 | $disabled = ' shadow-disabled'; |
| 79 | 79 | |
| 80 | - if ( $this->value[ $shadow_type . '-shadow' ]['checked'] ) { |
|
| 80 | + if ( $this->value[$shadow_type . '-shadow']['checked'] ) { |
|
| 81 | 81 | $disabled = ''; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | - $slider_disable = disabled( filter_var( $this->value[ $shadow_type . '-shadow' ]['checked'], FILTER_VALIDATE_BOOLEAN ), false, false ); |
|
| 84 | + $slider_disable = disabled( filter_var( $this->value[$shadow_type . '-shadow']['checked'], FILTER_VALIDATE_BOOLEAN ), false, false ); |
|
| 85 | 85 | |
| 86 | 86 | echo '<div class="col-2 shadow-' . esc_attr( $shadow_type ) . ' " data-shadow="' . esc_attr( $shadow_type ) . '">'; |
| 87 | 87 | echo '<ul>'; |
| 88 | 88 | echo '<li>'; |
| 89 | 89 | echo '<label for="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-shadow" class="' . esc_attr( $disabled ) . '">'; |
| 90 | - echo '<input type="checkbox" id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-shadow" class="checkbox" value="1"' . checked( $this->value[ $shadow_type . '-shadow' ]['checked'], '1', false ) . '/>'; |
|
| 91 | - echo '<input type="hidden" data-val="1" value="' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['checked'] ) . '" class="checkbox-check" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[' . esc_attr( $shadow_type ) . '-shadow][checked]"/>'; |
|
| 90 | + echo '<input type="checkbox" id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-shadow" class="checkbox" value="1"' . checked( $this->value[$shadow_type . '-shadow']['checked'], '1', false ) . '/>'; |
|
| 91 | + echo '<input type="hidden" data-val="1" value="' . esc_attr( $this->value[$shadow_type . '-shadow']['checked'] ) . '" class="checkbox-check" name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[' . esc_attr( $shadow_type ) . '-shadow][checked]"/>'; |
|
| 92 | 92 | echo esc_html( ucfirst( $shadow_type ) ) . ' ' . esc_html__( 'Shadow', 'redux-framework' ); |
| 93 | 93 | echo '</label>'; |
| 94 | 94 | echo '</li>'; |
| 95 | 95 | echo '<li>'; |
| 96 | 96 | |
| 97 | - $def_color = $this->field['default'][ $shadow_type . '-shadow' ]['color'] ?? ''; |
|
| 97 | + $def_color = $this->field['default'][$shadow_type . '-shadow']['color'] ?? ''; |
|
| 98 | 98 | |
| 99 | 99 | echo '<input '; |
| 100 | 100 | echo 'data-id="' . esc_attr( $this->field['id'] ) . '"'; |
| 101 | 101 | echo 'name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[' . esc_attr( $shadow_type ) . '-shadow][color]"'; |
| 102 | 102 | echo 'id="' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-color"'; |
| 103 | 103 | echo 'class="color-picker redux-color redux-box-shadow-' . esc_attr( $shadow_type ) . '-input redux-color-init ' . esc_attr( $this->field['class'] ) . '"'; |
| 104 | - echo 'type="text" value="' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['color'] ) . '"'; |
|
| 104 | + echo 'type="text" value="' . esc_attr( $this->value[$shadow_type . '-shadow']['color'] ) . '"'; |
|
| 105 | 105 | echo 'data-default-color="' . esc_attr( $def_color ) . '"'; |
| 106 | 106 | |
| 107 | 107 | echo '/>'; |
| 108 | 108 | echo '</li>'; |
| 109 | 109 | echo '<li>'; |
| 110 | 110 | echo '<div class="slider-' . esc_attr( $shadow_type ) . '-horizontal">'; |
| 111 | - echo esc_html__( 'Horizontal Length', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[ $shadow_type . '-shadow' ]['horizontal'] ) . 'px</strong>'; |
|
| 111 | + echo esc_html__( 'Horizontal Length', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[$shadow_type . '-shadow']['horizontal'] ) . 'px</strong>'; |
|
| 112 | 112 | echo '<div |
| 113 | 113 | class="redux-box-shadow-slider redux-box-shadow-' . esc_attr( $shadow_type ) . ' redux-' . esc_attr( $shadow_type ) . '-horizontal ' . esc_attr( $shadow_type ) . '-horizontal-input ' . esc_attr( $this->field['class'] ) . '" |
| 114 | 114 | id="' . esc_attr( $this->field['id'] ) . '" |
@@ -118,21 +118,21 @@ discard block |
||
| 118 | 118 | data-step="1" |
| 119 | 119 | data-rtl="' . esc_attr( is_rtl() ) . '" |
| 120 | 120 | data-label="' . esc_attr__( 'Horizontal Length', 'redux-framework' ) . '" |
| 121 | - data-default = "' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['horizontal'] ) . '" ' . esc_html( $slider_disable ) . '> |
|
| 121 | + data-default = "' . esc_attr( $this->value[$shadow_type . '-shadow']['horizontal'] ) . '" ' . esc_html( $slider_disable ) . '> |
|
| 122 | 122 | </div>'; |
| 123 | 123 | echo '<input |
| 124 | 124 | type="hidden" |
| 125 | 125 | id="redux-slider-value-' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-horizontal" |
| 126 | 126 | class="' . esc_attr( $shadow_type ) . '-horizontal" |
| 127 | 127 | name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[' . esc_attr( $shadow_type ) . '-shadow][horizontal]" |
| 128 | - value="' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['horizontal'] ) . '" |
|
| 128 | + value="' . esc_attr( $this->value[$shadow_type . '-shadow']['horizontal'] ) . '" |
|
| 129 | 129 | data-id="' . esc_attr( $this->field['id'] ) . '" |
| 130 | 130 | />'; |
| 131 | 131 | echo '</div>'; |
| 132 | 132 | echo '</li>'; |
| 133 | 133 | echo '<li>'; |
| 134 | 134 | echo '<div class="slider-' . esc_attr( $shadow_type ) . '-vertical">'; |
| 135 | - echo esc_html__( 'Vertical Length', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[ $shadow_type . '-shadow' ]['vertical'] ) . 'px</strong>'; |
|
| 135 | + echo esc_html__( 'Vertical Length', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[$shadow_type . '-shadow']['vertical'] ) . 'px</strong>'; |
|
| 136 | 136 | echo '<div |
| 137 | 137 | class="redux-box-shadow-slider redux-box-shadow-' . esc_attr( $shadow_type ) . ' redux-' . esc_attr( $shadow_type ) . '-vertical ' . esc_attr( $shadow_type ) . '-vertical-input ' . esc_attr( $this->field['class'] ) . '" |
| 138 | 138 | id="' . esc_attr( $this->field['id'] ) . '" |
@@ -142,21 +142,21 @@ discard block |
||
| 142 | 142 | data-step="1" |
| 143 | 143 | data-rtl="' . esc_attr( is_rtl() ) . '" |
| 144 | 144 | data-label="' . esc_attr__( 'Vertical Length', 'redux-framework' ) . '" |
| 145 | - data-default = "' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['vertical'] ) . '" ' . esc_html( $slider_disable ) . '> |
|
| 145 | + data-default = "' . esc_attr( $this->value[$shadow_type . '-shadow']['vertical'] ) . '" ' . esc_html( $slider_disable ) . '> |
|
| 146 | 146 | </div>'; |
| 147 | 147 | echo '<input |
| 148 | 148 | type="hidden" |
| 149 | 149 | id="redux-slider-value-' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-vertical" |
| 150 | 150 | class="' . esc_attr( $shadow_type ) . '-vertical" |
| 151 | 151 | name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[' . esc_attr( $shadow_type ) . '-shadow][vertical]" |
| 152 | - value="' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['vertical'] ) . '" |
|
| 152 | + value="' . esc_attr( $this->value[$shadow_type . '-shadow']['vertical'] ) . '" |
|
| 153 | 153 | data-id="' . esc_attr( $this->field['id'] ) . '" |
| 154 | 154 | />'; |
| 155 | 155 | echo '</div>'; |
| 156 | 156 | echo '</li>'; |
| 157 | 157 | echo '<li>'; |
| 158 | 158 | echo '<div class="slider-' . esc_attr( $shadow_type ) . '-blur">'; |
| 159 | - echo esc_html__( 'Blur Radius', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[ $shadow_type . '-shadow' ]['blur'] ) . 'px</strong>'; |
|
| 159 | + echo esc_html__( 'Blur Radius', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[$shadow_type . '-shadow']['blur'] ) . 'px</strong>'; |
|
| 160 | 160 | echo '<div |
| 161 | 161 | class="redux-box-shadow-slider redux-box-shadow-' . esc_attr( $shadow_type ) . ' redux-' . esc_attr( $shadow_type ) . '-blur ' . esc_attr( $shadow_type ) . '-blur-input ' . esc_attr( $this->field['class'] ) . '" |
| 162 | 162 | id="' . esc_attr( $this->field['id'] ) . '" |
@@ -166,21 +166,21 @@ discard block |
||
| 166 | 166 | data-step="1" |
| 167 | 167 | data-rtl="' . esc_attr( is_rtl() ) . '" |
| 168 | 168 | data-label="' . esc_attr__( 'Blur Radius', 'redux-framework' ) . '" |
| 169 | - data-default = "' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['blur'] ) . '" ' . esc_html( $slider_disable ) . '> |
|
| 169 | + data-default = "' . esc_attr( $this->value[$shadow_type . '-shadow']['blur'] ) . '" ' . esc_html( $slider_disable ) . '> |
|
| 170 | 170 | </div>'; |
| 171 | 171 | echo '<input |
| 172 | 172 | type="hidden" |
| 173 | 173 | id="redux-slider-value-' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-blur" |
| 174 | 174 | class="' . esc_attr( $shadow_type ) . '-blur" |
| 175 | 175 | name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[' . esc_attr( $shadow_type ) . '-shadow][blur]" |
| 176 | - value="' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['blur'] ) . '" |
|
| 176 | + value="' . esc_attr( $this->value[$shadow_type . '-shadow']['blur'] ) . '" |
|
| 177 | 177 | data-id="' . esc_attr( $this->field['id'] ) . '" |
| 178 | 178 | />'; |
| 179 | 179 | echo '</div>'; |
| 180 | 180 | echo '</li>'; |
| 181 | 181 | echo '<li>'; |
| 182 | 182 | echo '<div class="slider-' . esc_attr( $shadow_type ) . '-spread">'; |
| 183 | - echo esc_html__( 'Spread', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[ $shadow_type . '-shadow' ]['spread'] ) . 'px</strong>'; |
|
| 183 | + echo esc_html__( 'Spread', 'redux-framework' ) . ': <strong>' . esc_html( $this->value[$shadow_type . '-shadow']['spread'] ) . 'px</strong>'; |
|
| 184 | 184 | echo '<div |
| 185 | 185 | class="redux-box-shadow-slider redux-box-shadow-' . esc_attr( $shadow_type ) . ' redux-' . esc_attr( $shadow_type ) . '-spread ' . esc_attr( $shadow_type ) . '-spread-input ' . esc_attr( $this->field['class'] ) . '" |
| 186 | 186 | id="' . esc_attr( $this->field['id'] ) . '" |
@@ -190,14 +190,14 @@ discard block |
||
| 190 | 190 | data-step="1" |
| 191 | 191 | data-rtl="' . esc_attr( is_rtl() ) . '" |
| 192 | 192 | data-label="' . esc_attr__( 'Spread', 'redux-framework' ) . '" |
| 193 | - data-default = "' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['spread'] ) . '" ' . esc_html( $slider_disable ) . '> |
|
| 193 | + data-default = "' . esc_attr( $this->value[$shadow_type . '-shadow']['spread'] ) . '" ' . esc_html( $slider_disable ) . '> |
|
| 194 | 194 | </div>'; |
| 195 | 195 | echo '<input |
| 196 | 196 | type="hidden" |
| 197 | 197 | id="redux-slider-value-' . esc_attr( $this->field['id'] ) . '-' . esc_attr( $shadow_type ) . '-spread" |
| 198 | 198 | class="' . esc_attr( $shadow_type ) . '-spread" |
| 199 | 199 | name="' . esc_attr( $this->field['name'] . $this->field['name_suffix'] ) . '[' . esc_attr( $shadow_type ) . '-shadow][spread]" |
| 200 | - value="' . esc_attr( $this->value[ $shadow_type . '-shadow' ]['spread'] ) . '" |
|
| 200 | + value="' . esc_attr( $this->value[$shadow_type . '-shadow']['spread'] ) . '" |
|
| 201 | 201 | data-id="' . esc_attr( $this->field['id'] ) . '" |
| 202 | 202 | />'; |
| 203 | 203 | echo '</div>'; |
@@ -11,179 +11,179 @@ |
||
| 11 | 11 | |
| 12 | 12 | if ( ! class_exists( 'Redux_Image_Filters' ) ) { |
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * Class Redux_Image_Filters |
|
| 16 | - */ |
|
| 17 | - class Redux_Image_Filters { |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Render preview. |
|
| 21 | - * |
|
| 22 | - * @param array $data Data. |
|
| 23 | - * |
|
| 24 | - * @return string |
|
| 25 | - */ |
|
| 26 | - public static function render( array $data ): string { |
|
| 27 | - extract( $data ); // phpcs:ignore WordPress.PHP.DontExtract |
|
| 28 | - |
|
| 29 | - $output = ''; |
|
| 30 | - |
|
| 31 | - $filter_arr = array( |
|
| 32 | - 'grayscale', |
|
| 33 | - 'blur', |
|
| 34 | - 'sepia', |
|
| 35 | - 'saturate', |
|
| 36 | - 'opacity', |
|
| 37 | - 'brightness', |
|
| 38 | - 'contrast', |
|
| 39 | - 'hue-rotate', |
|
| 40 | - 'invert', |
|
| 41 | - ); |
|
| 42 | - |
|
| 43 | - // Make an array of in use filters. |
|
| 44 | - $in_use_filters = array(); |
|
| 45 | - |
|
| 46 | - foreach ( $filter_arr as $filter ) { |
|
| 47 | - if ( $field['filter'][ $filter ] ) { |
|
| 48 | - $in_use_filters[] = $filter; |
|
| 49 | - } |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - $filters = rawurlencode( wp_json_encode( $in_use_filters ) ); |
|
| 53 | - |
|
| 54 | - $output .= '<div class="redux-' . $mode . '-filter-container" data-filters="' . $filters . '">'; |
|
| 55 | - $output .= '<div class="container-label">' . esc_html__( 'Filters', 'redux-framework' ) . '</div>'; |
|
| 56 | - |
|
| 57 | - foreach ( $in_use_filters as $filter ) { |
|
| 58 | - $step = 1; |
|
| 59 | - $unit = self::get_filter_unit( $filter ); |
|
| 60 | - |
|
| 61 | - if ( 'grayscale' === $filter || 'invert' === $filter ) { |
|
| 62 | - $min = 0; |
|
| 63 | - $max = 100; |
|
| 64 | - } elseif ( 'blur' === $filter ) { |
|
| 65 | - $min = 0; |
|
| 66 | - $max = 30; |
|
| 67 | - } elseif ( 'sepia' === $filter || 'saturate' === $filter || 'opacity' === $filter ) { |
|
| 68 | - $min = 0; |
|
| 69 | - $max = 1; |
|
| 70 | - $step = .01; |
|
| 71 | - } elseif ( 'brightness' === $filter || 'contrast' === $filter ) { |
|
| 72 | - $min = 0; |
|
| 73 | - $max = 200; |
|
| 74 | - } elseif ( 'hue-rotate' === $filter ) { |
|
| 75 | - $min = 0; |
|
| 76 | - $max = 360; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - $disabled = 'filters-disabled'; |
|
| 80 | - if ( $value['filter'][ $filter ]['checked'] ) { |
|
| 81 | - $disabled = ''; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $output .= '<div class="filter filter-' . $filter . '">'; |
|
| 85 | - $output .= '<label for="' . esc_attr( $field['id'] ) . '-' . $filter . '" class="' . $disabled . '">'; |
|
| 86 | - $output .= '<input type="checkbox" id="' . esc_attr( $field['id'] ) . '-' . $filter . '" class="checkbox" value="1"' . checked( $value['filter'][ $filter ]['checked'], '1', false ) . '/>'; |
|
| 87 | - $output .= '<input type="hidden" data-val="1" value="' . esc_attr( $value['filter'][ $filter ]['checked'] ) . '" class="checkbox-check" name="' . esc_attr( $field['name'] . $field['name_suffix'] ) . '[filter][' . $filter . '][checked]"/>'; |
|
| 88 | - $output .= ucfirst( $filter ) . ': '; |
|
| 89 | - $output .= '<span class="filter-value"><strong>' . $value['filter'][ $filter ]['value'] . $unit . '</strong></span>'; |
|
| 90 | - $output .= '</label>'; |
|
| 91 | - |
|
| 92 | - $output .= '<div '; |
|
| 93 | - $output .= 'class="redux-' . $mode . '-slider redux-' . $mode . '-filter redux-filter redux-filter-' . $filter . esc_attr( $field['class'] ) . '"'; |
|
| 94 | - $output .= 'id="' . esc_attr( $field['id'] ) . '"'; |
|
| 95 | - $output .= 'data-id="' . esc_attr( $field['id'] . '-' . $filter ) . '"'; |
|
| 96 | - $output .= 'data-min="' . $min . '"'; |
|
| 97 | - $output .= 'data-max="' . $max . '"'; |
|
| 98 | - $output .= 'data-step="' . $step . '"'; |
|
| 99 | - $output .= 'data-rtl="' . esc_attr( is_rtl() ) . '"'; |
|
| 100 | - $output .= 'data-unit="' . $unit . '"'; |
|
| 101 | - $output .= 'data-default = "' . esc_attr( $value['filter'][ $filter ]['value'] ) . '" '; |
|
| 102 | - $output .= disabled( filter_var( $value['filter'][ $filter ]['checked'], FILTER_VALIDATE_BOOLEAN ), false, false ); |
|
| 103 | - $output .= '>'; |
|
| 104 | - $output .= '</div>'; |
|
| 105 | - |
|
| 106 | - if ( '°' === $unit ) { |
|
| 107 | - $unit = 'deg'; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $output .= '<input '; |
|
| 111 | - $output .= 'type="hidden"'; |
|
| 112 | - $output .= 'id="redux-slider-value-' . esc_attr( $field['id'] ) . '-' . $filter . '"'; |
|
| 113 | - $output .= 'class="' . $mode . '-filter-' . $filter . '"'; |
|
| 114 | - $output .= 'name="' . esc_attr( $field['name'] . $field['name_suffix'] ) . '[filter][' . $filter . '][value]"'; |
|
| 115 | - $output .= 'value="' . esc_attr( $value['filter'][ $filter ]['value'] ) . '"'; |
|
| 116 | - $output .= 'data-id="' . esc_attr( $field['id'] ) . '"'; |
|
| 117 | - $output .= 'data-unit="' . $unit . '"'; |
|
| 118 | - $output .= '/>'; |
|
| 119 | - $output .= '</div>'; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - $output .= '</div>'; |
|
| 123 | - |
|
| 124 | - return $output; |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * Get filter unit. |
|
| 129 | - * |
|
| 130 | - * @param string $filter Filter type. |
|
| 131 | - * |
|
| 132 | - * @return string |
|
| 133 | - */ |
|
| 134 | - public static function get_filter_unit( string $filter ): string { |
|
| 135 | - if ( 'grayscale' === $filter || 'invert' === $filter || 'brightness' === $filter || 'contrast' === $filter ) { |
|
| 136 | - return '%'; |
|
| 137 | - } elseif ( 'blur' === $filter ) { |
|
| 138 | - return 'px'; |
|
| 139 | - } elseif ( 'hue-rotate' === $filter ) { |
|
| 140 | - return '°'; |
|
| 141 | - } else { |
|
| 142 | - return ''; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Enqueue support files. |
|
| 148 | - * |
|
| 149 | - * @param bool $filters_enabled Filtered enabled bit. |
|
| 150 | - */ |
|
| 151 | - public static function enqueue( bool $filters_enabled ) { |
|
| 152 | - $min = Redux_Functions::is_min(); |
|
| 153 | - |
|
| 154 | - if ( $filters_enabled ) { |
|
| 155 | - if ( ! wp_style_is( 'redux-nouislider' ) ) { |
|
| 156 | - wp_enqueue_style( |
|
| 157 | - 'redux-nouislider', |
|
| 158 | - Redux_Core::$url . 'assets/css/vendor/nouislider/redux.jquery.nouislider.css', |
|
| 159 | - array(), |
|
| 160 | - '5.0.0' |
|
| 161 | - ); |
|
| 162 | - |
|
| 163 | - wp_enqueue_script( |
|
| 164 | - 'redux-nouislider', |
|
| 165 | - Redux_Core::$url . 'assets/js/vendor/nouislider/redux.jquery.nouislider' . $min . '.js', |
|
| 166 | - array( 'jquery' ), |
|
| 167 | - '5.0.0', |
|
| 168 | - true |
|
| 169 | - ); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - wp_enqueue_script( |
|
| 173 | - 'redux-image-filters', |
|
| 174 | - Redux_Core::$url . 'inc/lib/image-filters/image-filters' . $min . '.js', |
|
| 175 | - array( 'jquery' ), |
|
| 176 | - Redux_Core::$version, |
|
| 177 | - true |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - wp_enqueue_style( |
|
| 181 | - 'redux-image-filters', |
|
| 182 | - Redux_Core::$url . 'inc/lib/image-filters/image-filters.css', |
|
| 183 | - array(), |
|
| 184 | - Redux_Core::$version |
|
| 185 | - ); |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - } |
|
| 14 | + /** |
|
| 15 | + * Class Redux_Image_Filters |
|
| 16 | + */ |
|
| 17 | + class Redux_Image_Filters { |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Render preview. |
|
| 21 | + * |
|
| 22 | + * @param array $data Data. |
|
| 23 | + * |
|
| 24 | + * @return string |
|
| 25 | + */ |
|
| 26 | + public static function render( array $data ): string { |
|
| 27 | + extract( $data ); // phpcs:ignore WordPress.PHP.DontExtract |
|
| 28 | + |
|
| 29 | + $output = ''; |
|
| 30 | + |
|
| 31 | + $filter_arr = array( |
|
| 32 | + 'grayscale', |
|
| 33 | + 'blur', |
|
| 34 | + 'sepia', |
|
| 35 | + 'saturate', |
|
| 36 | + 'opacity', |
|
| 37 | + 'brightness', |
|
| 38 | + 'contrast', |
|
| 39 | + 'hue-rotate', |
|
| 40 | + 'invert', |
|
| 41 | + ); |
|
| 42 | + |
|
| 43 | + // Make an array of in use filters. |
|
| 44 | + $in_use_filters = array(); |
|
| 45 | + |
|
| 46 | + foreach ( $filter_arr as $filter ) { |
|
| 47 | + if ( $field['filter'][ $filter ] ) { |
|
| 48 | + $in_use_filters[] = $filter; |
|
| 49 | + } |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + $filters = rawurlencode( wp_json_encode( $in_use_filters ) ); |
|
| 53 | + |
|
| 54 | + $output .= '<div class="redux-' . $mode . '-filter-container" data-filters="' . $filters . '">'; |
|
| 55 | + $output .= '<div class="container-label">' . esc_html__( 'Filters', 'redux-framework' ) . '</div>'; |
|
| 56 | + |
|
| 57 | + foreach ( $in_use_filters as $filter ) { |
|
| 58 | + $step = 1; |
|
| 59 | + $unit = self::get_filter_unit( $filter ); |
|
| 60 | + |
|
| 61 | + if ( 'grayscale' === $filter || 'invert' === $filter ) { |
|
| 62 | + $min = 0; |
|
| 63 | + $max = 100; |
|
| 64 | + } elseif ( 'blur' === $filter ) { |
|
| 65 | + $min = 0; |
|
| 66 | + $max = 30; |
|
| 67 | + } elseif ( 'sepia' === $filter || 'saturate' === $filter || 'opacity' === $filter ) { |
|
| 68 | + $min = 0; |
|
| 69 | + $max = 1; |
|
| 70 | + $step = .01; |
|
| 71 | + } elseif ( 'brightness' === $filter || 'contrast' === $filter ) { |
|
| 72 | + $min = 0; |
|
| 73 | + $max = 200; |
|
| 74 | + } elseif ( 'hue-rotate' === $filter ) { |
|
| 75 | + $min = 0; |
|
| 76 | + $max = 360; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + $disabled = 'filters-disabled'; |
|
| 80 | + if ( $value['filter'][ $filter ]['checked'] ) { |
|
| 81 | + $disabled = ''; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $output .= '<div class="filter filter-' . $filter . '">'; |
|
| 85 | + $output .= '<label for="' . esc_attr( $field['id'] ) . '-' . $filter . '" class="' . $disabled . '">'; |
|
| 86 | + $output .= '<input type="checkbox" id="' . esc_attr( $field['id'] ) . '-' . $filter . '" class="checkbox" value="1"' . checked( $value['filter'][ $filter ]['checked'], '1', false ) . '/>'; |
|
| 87 | + $output .= '<input type="hidden" data-val="1" value="' . esc_attr( $value['filter'][ $filter ]['checked'] ) . '" class="checkbox-check" name="' . esc_attr( $field['name'] . $field['name_suffix'] ) . '[filter][' . $filter . '][checked]"/>'; |
|
| 88 | + $output .= ucfirst( $filter ) . ': '; |
|
| 89 | + $output .= '<span class="filter-value"><strong>' . $value['filter'][ $filter ]['value'] . $unit . '</strong></span>'; |
|
| 90 | + $output .= '</label>'; |
|
| 91 | + |
|
| 92 | + $output .= '<div '; |
|
| 93 | + $output .= 'class="redux-' . $mode . '-slider redux-' . $mode . '-filter redux-filter redux-filter-' . $filter . esc_attr( $field['class'] ) . '"'; |
|
| 94 | + $output .= 'id="' . esc_attr( $field['id'] ) . '"'; |
|
| 95 | + $output .= 'data-id="' . esc_attr( $field['id'] . '-' . $filter ) . '"'; |
|
| 96 | + $output .= 'data-min="' . $min . '"'; |
|
| 97 | + $output .= 'data-max="' . $max . '"'; |
|
| 98 | + $output .= 'data-step="' . $step . '"'; |
|
| 99 | + $output .= 'data-rtl="' . esc_attr( is_rtl() ) . '"'; |
|
| 100 | + $output .= 'data-unit="' . $unit . '"'; |
|
| 101 | + $output .= 'data-default = "' . esc_attr( $value['filter'][ $filter ]['value'] ) . '" '; |
|
| 102 | + $output .= disabled( filter_var( $value['filter'][ $filter ]['checked'], FILTER_VALIDATE_BOOLEAN ), false, false ); |
|
| 103 | + $output .= '>'; |
|
| 104 | + $output .= '</div>'; |
|
| 105 | + |
|
| 106 | + if ( '°' === $unit ) { |
|
| 107 | + $unit = 'deg'; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $output .= '<input '; |
|
| 111 | + $output .= 'type="hidden"'; |
|
| 112 | + $output .= 'id="redux-slider-value-' . esc_attr( $field['id'] ) . '-' . $filter . '"'; |
|
| 113 | + $output .= 'class="' . $mode . '-filter-' . $filter . '"'; |
|
| 114 | + $output .= 'name="' . esc_attr( $field['name'] . $field['name_suffix'] ) . '[filter][' . $filter . '][value]"'; |
|
| 115 | + $output .= 'value="' . esc_attr( $value['filter'][ $filter ]['value'] ) . '"'; |
|
| 116 | + $output .= 'data-id="' . esc_attr( $field['id'] ) . '"'; |
|
| 117 | + $output .= 'data-unit="' . $unit . '"'; |
|
| 118 | + $output .= '/>'; |
|
| 119 | + $output .= '</div>'; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + $output .= '</div>'; |
|
| 123 | + |
|
| 124 | + return $output; |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * Get filter unit. |
|
| 129 | + * |
|
| 130 | + * @param string $filter Filter type. |
|
| 131 | + * |
|
| 132 | + * @return string |
|
| 133 | + */ |
|
| 134 | + public static function get_filter_unit( string $filter ): string { |
|
| 135 | + if ( 'grayscale' === $filter || 'invert' === $filter || 'brightness' === $filter || 'contrast' === $filter ) { |
|
| 136 | + return '%'; |
|
| 137 | + } elseif ( 'blur' === $filter ) { |
|
| 138 | + return 'px'; |
|
| 139 | + } elseif ( 'hue-rotate' === $filter ) { |
|
| 140 | + return '°'; |
|
| 141 | + } else { |
|
| 142 | + return ''; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Enqueue support files. |
|
| 148 | + * |
|
| 149 | + * @param bool $filters_enabled Filtered enabled bit. |
|
| 150 | + */ |
|
| 151 | + public static function enqueue( bool $filters_enabled ) { |
|
| 152 | + $min = Redux_Functions::is_min(); |
|
| 153 | + |
|
| 154 | + if ( $filters_enabled ) { |
|
| 155 | + if ( ! wp_style_is( 'redux-nouislider' ) ) { |
|
| 156 | + wp_enqueue_style( |
|
| 157 | + 'redux-nouislider', |
|
| 158 | + Redux_Core::$url . 'assets/css/vendor/nouislider/redux.jquery.nouislider.css', |
|
| 159 | + array(), |
|
| 160 | + '5.0.0' |
|
| 161 | + ); |
|
| 162 | + |
|
| 163 | + wp_enqueue_script( |
|
| 164 | + 'redux-nouislider', |
|
| 165 | + Redux_Core::$url . 'assets/js/vendor/nouislider/redux.jquery.nouislider' . $min . '.js', |
|
| 166 | + array( 'jquery' ), |
|
| 167 | + '5.0.0', |
|
| 168 | + true |
|
| 169 | + ); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + wp_enqueue_script( |
|
| 173 | + 'redux-image-filters', |
|
| 174 | + Redux_Core::$url . 'inc/lib/image-filters/image-filters' . $min . '.js', |
|
| 175 | + array( 'jquery' ), |
|
| 176 | + Redux_Core::$version, |
|
| 177 | + true |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + wp_enqueue_style( |
|
| 181 | + 'redux-image-filters', |
|
| 182 | + Redux_Core::$url . 'inc/lib/image-filters/image-filters.css', |
|
| 183 | + array(), |
|
| 184 | + Redux_Core::$version |
|
| 185 | + ); |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | 189 | } |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | $in_use_filters = array(); |
| 45 | 45 | |
| 46 | 46 | foreach ( $filter_arr as $filter ) { |
| 47 | - if ( $field['filter'][ $filter ] ) { |
|
| 47 | + if ( $field['filter'][$filter] ) { |
|
| 48 | 48 | $in_use_filters[] = $filter; |
| 49 | 49 | } |
| 50 | 50 | } |
@@ -77,16 +77,16 @@ discard block |
||
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | $disabled = 'filters-disabled'; |
| 80 | - if ( $value['filter'][ $filter ]['checked'] ) { |
|
| 80 | + if ( $value['filter'][$filter]['checked'] ) { |
|
| 81 | 81 | $disabled = ''; |
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | $output .= '<div class="filter filter-' . $filter . '">'; |
| 85 | 85 | $output .= '<label for="' . esc_attr( $field['id'] ) . '-' . $filter . '" class="' . $disabled . '">'; |
| 86 | - $output .= '<input type="checkbox" id="' . esc_attr( $field['id'] ) . '-' . $filter . '" class="checkbox" value="1"' . checked( $value['filter'][ $filter ]['checked'], '1', false ) . '/>'; |
|
| 87 | - $output .= '<input type="hidden" data-val="1" value="' . esc_attr( $value['filter'][ $filter ]['checked'] ) . '" class="checkbox-check" name="' . esc_attr( $field['name'] . $field['name_suffix'] ) . '[filter][' . $filter . '][checked]"/>'; |
|
| 86 | + $output .= '<input type="checkbox" id="' . esc_attr( $field['id'] ) . '-' . $filter . '" class="checkbox" value="1"' . checked( $value['filter'][$filter]['checked'], '1', false ) . '/>'; |
|
| 87 | + $output .= '<input type="hidden" data-val="1" value="' . esc_attr( $value['filter'][$filter]['checked'] ) . '" class="checkbox-check" name="' . esc_attr( $field['name'] . $field['name_suffix'] ) . '[filter][' . $filter . '][checked]"/>'; |
|
| 88 | 88 | $output .= ucfirst( $filter ) . ': '; |
| 89 | - $output .= '<span class="filter-value"><strong>' . $value['filter'][ $filter ]['value'] . $unit . '</strong></span>'; |
|
| 89 | + $output .= '<span class="filter-value"><strong>' . $value['filter'][$filter]['value'] . $unit . '</strong></span>'; |
|
| 90 | 90 | $output .= '</label>'; |
| 91 | 91 | |
| 92 | 92 | $output .= '<div '; |
@@ -98,8 +98,8 @@ discard block |
||
| 98 | 98 | $output .= 'data-step="' . $step . '"'; |
| 99 | 99 | $output .= 'data-rtl="' . esc_attr( is_rtl() ) . '"'; |
| 100 | 100 | $output .= 'data-unit="' . $unit . '"'; |
| 101 | - $output .= 'data-default = "' . esc_attr( $value['filter'][ $filter ]['value'] ) . '" '; |
|
| 102 | - $output .= disabled( filter_var( $value['filter'][ $filter ]['checked'], FILTER_VALIDATE_BOOLEAN ), false, false ); |
|
| 101 | + $output .= 'data-default = "' . esc_attr( $value['filter'][$filter]['value'] ) . '" '; |
|
| 102 | + $output .= disabled( filter_var( $value['filter'][$filter]['checked'], FILTER_VALIDATE_BOOLEAN ), false, false ); |
|
| 103 | 103 | $output .= '>'; |
| 104 | 104 | $output .= '</div>'; |
| 105 | 105 | |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | $output .= 'id="redux-slider-value-' . esc_attr( $field['id'] ) . '-' . $filter . '"'; |
| 113 | 113 | $output .= 'class="' . $mode . '-filter-' . $filter . '"'; |
| 114 | 114 | $output .= 'name="' . esc_attr( $field['name'] . $field['name_suffix'] ) . '[filter][' . $filter . '][value]"'; |
| 115 | - $output .= 'value="' . esc_attr( $value['filter'][ $filter ]['value'] ) . '"'; |
|
| 115 | + $output .= 'value="' . esc_attr( $value['filter'][$filter]['value'] ) . '"'; |
|
| 116 | 116 | $output .= 'data-id="' . esc_attr( $field['id'] ) . '"'; |
| 117 | 117 | $output .= 'data-unit="' . $unit . '"'; |
| 118 | 118 | $output .= '/>'; |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | } |
| 543 | 543 | } |
| 544 | 544 | |
| 545 | - return (bool) $return; |
|
| 545 | + return ( bool ) $return; |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | } |
| 943 | 943 | } |
| 944 | 944 | |
| 945 | - $ret[ $struc['name'] ] = $struc; |
|
| 945 | + $ret[$struc['name']] = $struc; |
|
| 946 | 946 | } |
| 947 | 947 | |
| 948 | 948 | $dir->close(); |
@@ -13,1072 +13,1072 @@ |
||
| 13 | 13 | |
| 14 | 14 | if ( ! class_exists( 'Redux_Filesystem', false ) ) { |
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Class Redux_Filesystem |
|
| 18 | - */ |
|
| 19 | - class Redux_Filesystem { |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * Instance of this class. |
|
| 23 | - * |
|
| 24 | - * @since 1.0.0 |
|
| 25 | - * @var null|Redux_Filesystem |
|
| 26 | - */ |
|
| 27 | - protected static ?Redux_Filesystem $instance = null; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * WP Filesystem object. |
|
| 31 | - * |
|
| 32 | - * @var null|WP_Filesystem_Direct |
|
| 33 | - */ |
|
| 34 | - protected static ?WP_Filesystem_Direct $direct = null; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * File system credentials. |
|
| 38 | - * |
|
| 39 | - * @var array|bool|null |
|
| 40 | - */ |
|
| 41 | - private $creds; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * ReduxFramework object pointer. |
|
| 45 | - * |
|
| 46 | - * @var null|ReduxFramework |
|
| 47 | - */ |
|
| 48 | - public ?ReduxFramework $parent = null; |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * Instance of WP_Filesystem |
|
| 52 | - * |
|
| 53 | - * @var WP_Filesystem_Base|null |
|
| 54 | - */ |
|
| 55 | - private ?WP_Filesystem_Base $wp_filesystem = null; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * If DBI_Filesystem should attempt to use the WP_Filesystem class. |
|
| 59 | - * |
|
| 60 | - * @var bool |
|
| 61 | - */ |
|
| 62 | - private bool $use_filesystem = false; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Default chmod octal value for directories. |
|
| 66 | - * |
|
| 67 | - * @var int |
|
| 68 | - */ |
|
| 69 | - private int $chmod_dir; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Default chmod octal value for files. |
|
| 73 | - * |
|
| 74 | - * @var int |
|
| 75 | - */ |
|
| 76 | - private int $chmod_file; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Default cache folder. |
|
| 80 | - * |
|
| 81 | - * @var string |
|
| 82 | - */ |
|
| 83 | - public string $cache_folder; |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Kill switch. |
|
| 87 | - * |
|
| 88 | - * @var bool |
|
| 89 | - */ |
|
| 90 | - public bool $killswitch = false; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * FTP Form HTML. |
|
| 94 | - * |
|
| 95 | - * @var string |
|
| 96 | - */ |
|
| 97 | - public string $ftp_form; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Pass `true` when instantiating to skip using WP_Filesystem. |
|
| 101 | - * |
|
| 102 | - * @param bool $force_no_fs Force no use of the filesystem. |
|
| 103 | - */ |
|
| 104 | - public function __construct( bool $force_no_fs = false ) { |
|
| 105 | - |
|
| 106 | - // This little number fixes some issues with certain filesystem setups. |
|
| 107 | - |
|
| 108 | - if ( ! function_exists( 'request_filesystem_credentials' ) ) { |
|
| 109 | - require_once ABSPATH . '/wp-admin/includes/template.php'; |
|
| 110 | - require_once ABSPATH . '/wp-includes/pluggable.php'; |
|
| 111 | - require_once ABSPATH . '/wp-admin/includes/file.php'; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - // Set default permissions. |
|
| 115 | - if ( defined( 'FS_CHMOD_DIR' ) ) { |
|
| 116 | - $this->chmod_dir = FS_CHMOD_DIR; |
|
| 117 | - } else { |
|
| 118 | - $this->chmod_dir = ( fileperms( ABSPATH ) & 0777 | 0755 ); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if ( defined( 'FS_CHMOD_FILE' ) ) { |
|
| 122 | - $this->chmod_file = FS_CHMOD_FILE; |
|
| 123 | - } else { |
|
| 124 | - $this->chmod_file = ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - if ( ! $force_no_fs && function_exists( 'request_filesystem_credentials' ) ) { |
|
| 128 | - if ( ( defined( 'WPMDB_WP_FILESYSTEM' ) && WPMDB_WP_FILESYSTEM ) || ! defined( 'WPMDB_WP_FILESYSTEM' ) ) { |
|
| 129 | - $this->maybe_init_wp_filesystem(); |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - $uploads_dir = wp_upload_dir(); |
|
| 134 | - $this->cache_folder = trailingslashit( $uploads_dir['basedir'] ) . 'redux/'; |
|
| 135 | - if ( ! $this->file_exists( $this->cache_folder ) ) { |
|
| 136 | - $this->mkdir( $this->cache_folder ); |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Return an instance of this class. |
|
| 142 | - * |
|
| 143 | - * @param ReduxFramework|null $me ReduxFramework pointer. |
|
| 144 | - * |
|
| 145 | - * @return object A single instance of this class. |
|
| 146 | - * @since 1.0.0 |
|
| 147 | - */ |
|
| 148 | - public static function get_instance( ?ReduxFramework $me = null ): ?object { |
|
| 149 | - |
|
| 150 | - // If the single instance hasn't been set, set it now. |
|
| 151 | - if ( null === self::$instance ) { |
|
| 152 | - self::$instance = new self(); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - if ( null !== $me ) { |
|
| 156 | - self::$instance->parent = $me; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return self::$instance; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Build an FTP form. |
|
| 164 | - */ |
|
| 165 | - public function ftp_form() { |
|
| 166 | - if ( isset( $this->ftp_form ) && ! empty( $this->ftp_form ) ) { |
|
| 167 | - echo '<div class="wrap">'; |
|
| 168 | - echo '<div class="error">'; |
|
| 169 | - echo '<p>'; |
|
| 170 | - // translators: %1$s: Upload URL. %2$s: Codex URL. |
|
| 171 | - echo '<strong>' . esc_html__( 'File Permission Issues', 'redux-framework' ) . '</strong><br/>' . sprintf( esc_html__( 'We were unable to modify required files. Please ensure that %1$s has the proper read-write permissions, or modify your wp-config.php file to contain your FTP login credentials as %2$s.', 'redux-framework' ), '<code>' . esc_url( Redux_Functions_Ex::wp_normalize_path( trailingslashit( WP_CONTENT_DIR ) ) . '/uploads/' ) . '</code>', ' <a href="https://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants" target="_blank">' . esc_html__( 'outlined here', 'redux-framework' ) . '</a>' ); |
|
| 172 | - echo '</p>'; |
|
| 173 | - echo '</div>'; |
|
| 174 | - echo '<h2></h2>'; |
|
| 175 | - echo '</div>'; |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - /** |
|
| 180 | - * Attempt to initiate WP_Filesystem |
|
| 181 | - * If this fails, $use_filesystem is set to false and all methods in this class should use native php fallbacks |
|
| 182 | - * Thwarts `request_filesystem_credentials()` attempt to display a form for obtaining creds from users |
|
| 183 | - * TODO: provide notice and input in wp-admin for users when this fails |
|
| 184 | - */ |
|
| 185 | - public function maybe_init_wp_filesystem() { |
|
| 186 | - // Set up the filesystem with creds. |
|
| 187 | - require_once ABSPATH . '/wp-admin/includes/template.php'; |
|
| 188 | - require_once ABSPATH . '/wp-includes/pluggable.php'; |
|
| 189 | - require_once ABSPATH . '/wp-admin/includes/file.php'; |
|
| 190 | - |
|
| 191 | - ob_start(); |
|
| 192 | - $credentials = request_filesystem_credentials( '', '', false, false ); |
|
| 193 | - $ob_contents = ob_get_contents(); |
|
| 194 | - ob_end_clean(); |
|
| 195 | - |
|
| 196 | - if ( @wp_filesystem( $credentials ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors |
|
| 197 | - global $wp_filesystem; |
|
| 198 | - $this->wp_filesystem = $wp_filesystem; |
|
| 199 | - $this->use_filesystem = true; |
|
| 200 | - $this->generate_default_files(); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Init WO Filesystem. |
|
| 206 | - * |
|
| 207 | - * @param string $form_url Form URL. |
|
| 208 | - * @param string $method Connect method. |
|
| 209 | - * @param bool $context Context. |
|
| 210 | - * |
|
| 211 | - * @return bool |
|
| 212 | - */ |
|
| 213 | - public function advanced_filesystem_init( string $form_url, string $method = '', bool $context = false ): bool { |
|
| 214 | - if ( ! empty( $this->wp_filesystem ) && $this->use_filesystem ) { |
|
| 215 | - return true; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - if ( ! empty( $this->creds ) ) { |
|
| 219 | - return true; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - ob_start(); |
|
| 223 | - |
|
| 224 | - $this->creds = request_filesystem_credentials( $form_url, $method, false, $context ); |
|
| 225 | - |
|
| 226 | - /* first attempt to get credentials */ |
|
| 227 | - if ( false === $this->creds ) { |
|
| 228 | - $this->creds = array(); |
|
| 229 | - $this->ftp_form = ob_get_contents(); |
|
| 230 | - ob_end_clean(); |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * If we come here, we don't have credentials |
|
| 234 | - * so the request for them is displaying |
|
| 235 | - * no need for further processing |
|
| 236 | - * */ |
|
| 237 | - return false; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /* now we got some credentials - try to use them */ |
|
| 241 | - if ( ! @wp_filesystem( $this->creds ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors |
|
| 242 | - $this->creds = array(); |
|
| 243 | - /* incorrect connection data - ask for credentials again, now with an error message */ |
|
| 244 | - request_filesystem_credentials( $form_url, '', true, $context ); |
|
| 245 | - $this->ftp_form = ob_get_contents(); |
|
| 246 | - ob_end_clean(); |
|
| 247 | - |
|
| 248 | - return false; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - global $wp_filesystem; |
|
| 252 | - $this->wp_filesystem = $wp_filesystem; |
|
| 253 | - $this->use_filesystem = true; |
|
| 254 | - $this->generate_default_files(); |
|
| 255 | - |
|
| 256 | - return true; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Load WP filesystem directly. |
|
| 261 | - */ |
|
| 262 | - public static function load_direct() { |
|
| 263 | - if ( null === self::$direct ) { |
|
| 264 | - require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php'; |
|
| 265 | - require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php'; |
|
| 266 | - |
|
| 267 | - self::$direct = new WP_Filesystem_Direct( array() ); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Execute filesystem request. |
|
| 273 | - * |
|
| 274 | - * @param string $action Action to perform. |
|
| 275 | - * @param string $file File to perform upon. |
|
| 276 | - * @param array $params Argument for action. |
|
| 277 | - * |
|
| 278 | - * @return bool|void |
|
| 279 | - */ |
|
| 280 | - public function execute( string $action, string $file = '', array $params = array() ) { |
|
| 281 | - if ( empty( $this->parent->args ) ) { |
|
| 282 | - return; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - if ( ! empty( $params ) ) { |
|
| 286 | - // phpcs:ignore WordPress.PHP.DontExtract |
|
| 287 | - extract( $params ); |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - if ( empty( $this->wp_filesystem ) ) { |
|
| 291 | - if ( 'submenu' === $this->parent->args['menu_type'] ) { |
|
| 292 | - $page_parent = $this->parent->args['page_parent']; |
|
| 293 | - $base = $page_parent . '?page=' . $this->parent->args['page_slug']; |
|
| 294 | - } else { |
|
| 295 | - $base = 'admin.php?page=' . $this->parent->args['page_slug']; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - $url = wp_nonce_url( $base, 'redux-options' ); |
|
| 299 | - $this->advanced_filesystem_init( $url, 'direct', dirname( $file ) ); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - return $this->do_action( $action, $file, $params ); |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Generates the default Redux cache folder. |
|
| 308 | - * |
|
| 309 | - * @return void |
|
| 310 | - */ |
|
| 311 | - private function generate_default_files() { |
|
| 312 | - if ( ! $this->is_dir( Redux_Core::$upload_dir ) ) { |
|
| 313 | - $this->mkdir( Redux_Core::$upload_dir ); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - /** |
|
| 318 | - * Do request filesystem action. |
|
| 319 | - * |
|
| 320 | - * @param string $action Requested action. |
|
| 321 | - * @param string $file File to perform action upon. |
|
| 322 | - * @param array $params Action arguments. |
|
| 323 | - * |
|
| 324 | - * @return bool|void |
|
| 325 | - */ |
|
| 326 | - public function do_action( string $action, string $file = '', array $params = array() ) { |
|
| 327 | - $destination = ''; |
|
| 328 | - $overwrite = ''; |
|
| 329 | - $content = ''; |
|
| 330 | - |
|
| 331 | - if ( ! empty( $params ) ) { |
|
| 332 | - |
|
| 333 | - // phpcs:ignore WordPress.PHP.DontExtract |
|
| 334 | - extract( $params ); |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - global $wp_filesystem; |
|
| 338 | - |
|
| 339 | - if ( defined( 'FS_CHMOD_FILE' ) ) { |
|
| 340 | - $chmod = FS_CHMOD_FILE; |
|
| 341 | - } else { |
|
| 342 | - $chmod = 0644; |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - if ( isset( $params['chmod'] ) && ! empty( $params['chmod'] ) ) { |
|
| 346 | - $chmod = $params['chmod']; |
|
| 347 | - } |
|
| 348 | - $res = false; |
|
| 349 | - if ( ! isset( $recursive ) ) { |
|
| 350 | - $recursive = false; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - // Do unique stuff. |
|
| 354 | - if ( 'mkdir' === $action ) { |
|
| 355 | - $chmod = null; |
|
| 356 | - if ( isset( $params['chmod'] ) && ! empty( $params['chmod'] ) ) { |
|
| 357 | - $chmod = $params['chmod']; |
|
| 358 | - } |
|
| 359 | - $res = $this->mkdir( $file, $chmod ); |
|
| 360 | - } elseif ( 'rmdir' === $action ) { |
|
| 361 | - $res = $this->rmdir( $file, $recursive ); |
|
| 362 | - } elseif ( 'copy' === $action && false === $this->killswitch ) { |
|
| 363 | - $res = $this->copy( $file, $destination, $overwrite, $chmod ); |
|
| 364 | - } elseif ( 'move' === $action && false === $this->killswitch ) { |
|
| 365 | - $res = $this->move( $file, $destination, $overwrite ); |
|
| 366 | - } elseif ( 'delete' === $action ) { |
|
| 367 | - if ( $this->is_dir( $file ) ) { |
|
| 368 | - $res = $this->rmdir( $file, $recursive ); |
|
| 369 | - } else { |
|
| 370 | - $res = $this->unlink( $file ); |
|
| 371 | - } |
|
| 372 | - } elseif ( 'dirlist' === $action ) { |
|
| 373 | - if ( ! isset( $include_hidden ) ) { |
|
| 374 | - $include_hidden = true; |
|
| 375 | - } |
|
| 376 | - $res = $this->scandir( $file, $include_hidden, $recursive ); |
|
| 377 | - } elseif ( 'put_contents' === $action && false === $this->killswitch ) { |
|
| 378 | - // Write a string to a file. |
|
| 379 | - if ( isset( $this->ftp_form ) && ! empty( $this->ftp_form ) ) { |
|
| 380 | - self::load_direct(); |
|
| 381 | - $res = self::$direct->put_contents( $file, $content, $chmod ); |
|
| 382 | - } else { |
|
| 383 | - $res = $this->put_contents( $file, $content, $chmod ); |
|
| 384 | - } |
|
| 385 | - } elseif ( 'chown' === $action ) { |
|
| 386 | - // Changes the file owner. |
|
| 387 | - if ( isset( $owner ) && ! empty( $owner ) ) { |
|
| 388 | - $res = $wp_filesystem->chmod( $file, $chmod, $recursive ); |
|
| 389 | - } |
|
| 390 | - } elseif ( 'owner' === $action ) { |
|
| 391 | - // Gets the file owner. |
|
| 392 | - $res = $this->wp_filesystem->owner( $file ); |
|
| 393 | - } elseif ( 'chmod' === $action ) { |
|
| 394 | - if ( ! isset( $params['chmod'] ) || ( empty( $params['chmod'] ) ) ) { |
|
| 395 | - $chmod = false; |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - $res = $this->chmod( $file, $chmod ); |
|
| 399 | - } elseif ( 'get_contents' === $action ) { |
|
| 400 | - // Reads entire file into a string. |
|
| 401 | - if ( isset( $this->ftp_form ) && ! empty( $this->ftp_form ) ) { |
|
| 402 | - self::load_direct(); |
|
| 403 | - $res = self::$direct->get_contents( $file ); |
|
| 404 | - } else { |
|
| 405 | - $res = $this->get_contents( $file ); |
|
| 406 | - } |
|
| 407 | - } elseif ( 'get_contents_array' === $action ) { |
|
| 408 | - // Reads entire file into an array. |
|
| 409 | - $res = $this->wp_filesystem->get_contents_array( $file ); |
|
| 410 | - } elseif ( 'object' === $action ) { |
|
| 411 | - $res = $this->wp_filesystem; |
|
| 412 | - } elseif ( 'unzip' === $action ) { |
|
| 413 | - $unzipfile = unzip_file( $file, $destination ); |
|
| 414 | - if ( $unzipfile ) { |
|
| 415 | - $res = true; |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - if ( ! $res ) { |
|
| 420 | - if ( 'dirlist' === $action ) { |
|
| 421 | - if ( empty( $res ) ) { |
|
| 422 | - return; |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - if ( ! is_array( $res ) ) { |
|
| 426 | - if ( count( glob( "$file*" ) ) === 0 ) { |
|
| 427 | - return; |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - $this->killswitch = true; |
|
| 433 | - |
|
| 434 | - // translators: %1$s: Upload URL. %2$s: Codex URL. |
|
| 435 | - $msg = '<strong>' . esc_html__( 'File Permission Issues', 'redux-framework' ) . '</strong><br/>' . sprintf( esc_html__( 'We were unable to modify required files. Please ensure that %1$s has the proper read-write permissions, or modify your wp-config.php file to contain your FTP login credentials as %2$s.', 'redux-framework' ), '<code>' . esc_url( Redux_Functions_Ex::wp_normalize_path( trailingslashit( WP_CONTENT_DIR ) ) ) . '/uploads/</code>', '<a href="https://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants" target="_blank">' . esc_html__( 'outlined here', 'redux-framework' ) . '</a>' ); |
|
| 436 | - |
|
| 437 | - $data = array( |
|
| 438 | - 'parent' => self::$instance->parent, |
|
| 439 | - 'type' => 'error', |
|
| 440 | - 'msg' => $msg, |
|
| 441 | - 'id' => 'redux-wp-login', |
|
| 442 | - 'dismiss' => false, |
|
| 443 | - ); |
|
| 444 | - |
|
| 445 | - Redux_Admin_Notices::set_notice( $data ); |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - return $res; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - |
|
| 452 | - /** |
|
| 453 | - * Getter for the instantiated WP_Filesystem. This should be used carefully since $wp_filesystem won't always have a value. |
|
| 454 | - * |
|
| 455 | - * @return WP_Filesystem_Base|false |
|
| 456 | - */ |
|
| 457 | - public function get_wp_filesystem() { |
|
| 458 | - if ( $this->use_filesystem ) { |
|
| 459 | - return $this->wp_filesystem; |
|
| 460 | - } else { |
|
| 461 | - return false; |
|
| 462 | - } |
|
| 463 | - } |
|
| 464 | - |
|
| 465 | - /** |
|
| 466 | - * Check if WP_Filesystem being used. |
|
| 467 | - * |
|
| 468 | - * @return bool |
|
| 469 | - */ |
|
| 470 | - public function using_wp_filesystem(): bool { |
|
| 471 | - return $this->use_filesystem; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * Attempts to use the correct path for the FS method being used. |
|
| 476 | - * |
|
| 477 | - * @param string $abs_path Absolute path. |
|
| 478 | - * |
|
| 479 | - * @return string |
|
| 480 | - */ |
|
| 481 | - public function get_sanitized_path( string $abs_path ): string { |
|
| 482 | - if ( $this->using_wp_filesystem() ) { |
|
| 483 | - return str_replace( ABSPATH, $this->wp_filesystem->abspath(), $abs_path ); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return $abs_path; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * Create file if not exists then set mtime and atime on file |
|
| 491 | - * |
|
| 492 | - * @param string $abs_path Absolute path. |
|
| 493 | - * @param int $time Time. |
|
| 494 | - * @param int $atime Altered time. |
|
| 495 | - * |
|
| 496 | - * @return bool |
|
| 497 | - */ |
|
| 498 | - public function touch( string $abs_path, int $time = 0, int $atime = 0 ): bool { |
|
| 499 | - if ( 0 === $time ) { |
|
| 500 | - $time = time(); |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - if ( 0 === $atime ) { |
|
| 504 | - $atime = time(); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP |
|
| 508 | - $return = @touch( $abs_path, $time, $atime ); |
|
| 509 | - |
|
| 510 | - if ( ! $return && $this->use_filesystem ) { |
|
| 511 | - $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 512 | - $return = $this->wp_filesystem->touch( $abs_path, $time, $atime ); |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - return $return; |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - /** |
|
| 519 | - * Calls file_put_contents with chmod. |
|
| 520 | - * |
|
| 521 | - * @param string $abs_path Absolute path. |
|
| 522 | - * @param string $contents Content to write to the file. |
|
| 523 | - * @param string|null $perms Default permissions value. |
|
| 524 | - * |
|
| 525 | - * @return bool |
|
| 526 | - */ |
|
| 527 | - public function put_contents( string $abs_path, string $contents, ?string $perms = null ): bool { |
|
| 528 | - $return = false; |
|
| 529 | - |
|
| 530 | - if ( ! $this->is_dir( dirname( $abs_path ) ) ) { |
|
| 531 | - $this->mkdir( dirname( $abs_path ) ); |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - if ( $this->is_writable( dirname( $abs_path ) ) ) { |
|
| 535 | - // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 536 | - $return = @file_put_contents( $abs_path, $contents ); |
|
| 537 | - $this->chmod( $abs_path ); |
|
| 538 | - |
|
| 539 | - if ( null === $perms ) { |
|
| 540 | - $perms = $this->chmod_file; |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - if ( ! $return && $this->use_filesystem ) { |
|
| 545 | - $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 546 | - // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_is_writable, WordPress.WP.AlternativeFunctions.file_system_operations_is_writable |
|
| 547 | - if ( $this->is_writable( dirname( $abs_path ) ) ) { |
|
| 548 | - $return = $this->wp_filesystem->put_contents( $abs_path, $contents, $perms ); |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - return (bool) $return; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - /** |
|
| 556 | - * Does the specified file or dir exist? |
|
| 557 | - * |
|
| 558 | - * @param string $abs_path Absolute path. |
|
| 559 | - * @return bool |
|
| 560 | - */ |
|
| 561 | - public function file_exists( string $abs_path ): bool { |
|
| 562 | - $return = file_exists( $abs_path ); |
|
| 563 | - |
|
| 564 | - if ( ! $return && $this->use_filesystem ) { |
|
| 565 | - $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 566 | - $return = $this->wp_filesystem->exists( $abs_path ); |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - return $return; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - /** |
|
| 573 | - * Get a file's size. |
|
| 574 | - * |
|
| 575 | - * @param string $abs_path Absolute path. |
|
| 576 | - * |
|
| 577 | - * @return int |
|
| 578 | - */ |
|
| 579 | - public function filesize( string $abs_path ): int { |
|
| 580 | - $return = filesize( $abs_path ); |
|
| 581 | - |
|
| 582 | - if ( ! $return && $this->use_filesystem ) { |
|
| 583 | - $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 584 | - $return = $this->wp_filesystem->size( $abs_path ); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - return $return; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - /** |
|
| 591 | - * Get the contents of a file as a string. |
|
| 592 | - * |
|
| 593 | - * @param string $abs_path Absolute path. |
|
| 594 | - * |
|
| 595 | - * @return string |
|
| 596 | - */ |
|
| 597 | - public function get_local_file_contents( string $abs_path ): string { |
|
| 598 | - |
|
| 599 | - try { |
|
| 600 | - $contents = ''; |
|
| 601 | - |
|
| 602 | - if ( $this->file_exists( $abs_path ) && is_file( $abs_path ) ) { |
|
| 603 | - if ( $this->is_writable( $abs_path ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions |
|
| 604 | - ob_start(); |
|
| 605 | - |
|
| 606 | - include_once $abs_path; |
|
| 607 | - |
|
| 608 | - $contents = ob_get_clean(); |
|
| 609 | - } |
|
| 610 | - } |
|
| 611 | - } catch ( Exception $e ) { |
|
| 612 | - // This means that ob_start has been disabled on the system. Lets fallback to good old file_get_contents. |
|
| 613 | - $contents = file_get_contents( $abs_path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - return $contents; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - /** |
|
| 620 | - * Get the contents of a file as a string. |
|
| 621 | - * |
|
| 622 | - * @param string $abs_path Absolute path. |
|
| 623 | - * |
|
| 624 | - * @return string |
|
| 625 | - */ |
|
| 626 | - public function get_contents( string $abs_path ): string { |
|
| 627 | - $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 628 | - $return = ''; |
|
| 629 | - if ( $this->use_filesystem ) { |
|
| 630 | - $return = $this->wp_filesystem->get_contents( $abs_path ); |
|
| 631 | - } |
|
| 632 | - if ( empty( $return ) ) { |
|
| 633 | - $return = $this->get_local_file_contents( $abs_path ); |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - return $return; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * Delete a file. |
|
| 641 | - * |
|
| 642 | - * @param string $abs_path Absolute path. |
|
| 643 | - * |
|
| 644 | - * @return bool |
|
| 645 | - */ |
|
| 646 | - public function unlink( string $abs_path ): bool { |
|
| 647 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions |
|
| 648 | - $return = @unlink( $abs_path ); |
|
| 649 | - |
|
| 650 | - if ( ! $return && $this->use_filesystem ) { |
|
| 651 | - $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 652 | - $return = $this->wp_filesystem->delete( $abs_path ); |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - return $return; |
|
| 656 | - } |
|
| 657 | - |
|
| 658 | - /** |
|
| 659 | - * Chmod a file. |
|
| 660 | - * |
|
| 661 | - * @param string $abs_path Absolute path. |
|
| 662 | - * @param int|null $perms Permission value, if not provided, defaults to WP standards. |
|
| 663 | - * |
|
| 664 | - * @return bool |
|
| 665 | - */ |
|
| 666 | - public function chmod( string $abs_path, ?int $perms = null ): bool { |
|
| 667 | - if ( ! $this->file_exists( $abs_path ) ) { |
|
| 668 | - return false; |
|
| 669 | - } |
|
| 670 | - if ( is_null( $perms ) ) { |
|
| 671 | - $perms = $this->is_file( $abs_path ) ? $this->chmod_file : $this->chmod_dir; |
|
| 672 | - } |
|
| 673 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions |
|
| 674 | - $return = @chmod( $abs_path, $perms ); |
|
| 675 | - |
|
| 676 | - if ( ! $return && $this->use_filesystem ) { |
|
| 677 | - $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 678 | - $return = $this->wp_filesystem->chmod( $abs_path, $perms ); |
|
| 679 | - } |
|
| 680 | - |
|
| 681 | - return $return; |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - /** |
|
| 685 | - * Check if this path is a directory. |
|
| 686 | - * |
|
| 687 | - * @param string $abs_path Absolute path. |
|
| 688 | - * |
|
| 689 | - * @return bool |
|
| 690 | - */ |
|
| 691 | - public function is_dir( string $abs_path ): bool { |
|
| 692 | - $return = is_dir( $abs_path ); |
|
| 693 | - |
|
| 694 | - if ( ! $return && $this->use_filesystem ) { |
|
| 695 | - $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 696 | - $return = $this->wp_filesystem->is_dir( $abs_path ); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - return $return; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - /** |
|
| 703 | - * Check if the specified path is a file. |
|
| 704 | - * |
|
| 705 | - * @param string $abs_path Absolute path. |
|
| 706 | - * |
|
| 707 | - * @return bool |
|
| 708 | - */ |
|
| 709 | - public function is_file( string $abs_path ): bool { |
|
| 710 | - $return = is_file( $abs_path ); |
|
| 711 | - |
|
| 712 | - if ( ! $return && $this->use_filesystem ) { |
|
| 713 | - $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 714 | - $return = $this->wp_filesystem->is_file( $abs_path ); |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - return $return; |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - /** |
|
| 721 | - * Is the specified path readable? |
|
| 722 | - * |
|
| 723 | - * @param string $abs_path Absolute path. |
|
| 724 | - * |
|
| 725 | - * @return bool |
|
| 726 | - */ |
|
| 727 | - public function is_readable( string $abs_path ): bool { |
|
| 728 | - $return = is_readable( $abs_path ); |
|
| 729 | - |
|
| 730 | - if ( ! $return && $this->use_filesystem ) { |
|
| 731 | - $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 732 | - $return = $this->wp_filesystem->is_readable( $abs_path ); |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - return $return; |
|
| 736 | - } |
|
| 737 | - |
|
| 738 | - /** |
|
| 739 | - * Is the specified path writable? |
|
| 740 | - * |
|
| 741 | - * @param string $abs_path Absolute path. |
|
| 742 | - * |
|
| 743 | - * @return bool |
|
| 744 | - */ |
|
| 745 | - public function is_writable( string $abs_path ): bool { |
|
| 746 | - $return = is_writable( $abs_path ); // phpcs:ignore WordPress.WP.AlternativeFunctions |
|
| 747 | - |
|
| 748 | - if ( ! $return && $this->use_filesystem ) { |
|
| 749 | - $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 750 | - $return = $this->wp_filesystem->is_writable( $abs_path ); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - return $return; |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - /** |
|
| 757 | - * Create an index file at the given path. |
|
| 758 | - * |
|
| 759 | - * @param string $path Directory to add the index to. |
|
| 760 | - */ |
|
| 761 | - private function create_index( string $path ) { |
|
| 762 | - $index_path = trailingslashit( $path ) . 'index.php'; |
|
| 763 | - if ( ! $this->file_exists( $index_path ) ) { |
|
| 764 | - $this->put_contents( $index_path, "<?php\n//Silence is golden" ); |
|
| 765 | - } |
|
| 766 | - } |
|
| 767 | - |
|
| 768 | - /** |
|
| 769 | - * Recursive mkdir. |
|
| 770 | - * |
|
| 771 | - * @param string $abs_path Absolute path. |
|
| 772 | - * @param int|null $perms Permissions, if default not required. |
|
| 773 | - * |
|
| 774 | - * @return bool |
|
| 775 | - */ |
|
| 776 | - public function mkdir( string $abs_path, ?int $perms = null ): bool { |
|
| 777 | - if ( is_null( $perms ) ) { |
|
| 778 | - $perms = $this->chmod_dir; |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - if ( $this->is_dir( $abs_path ) ) { |
|
| 782 | - $this->chmod( $abs_path, $perms ); |
|
| 783 | - $this->create_index( $abs_path ); |
|
| 784 | - |
|
| 785 | - return true; |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - try { |
|
| 789 | - $mkdirp = wp_mkdir_p( $abs_path ); |
|
| 790 | - } catch ( Exception $e ) { |
|
| 791 | - $mkdirp = false; |
|
| 792 | - } |
|
| 793 | - |
|
| 794 | - if ( $mkdirp ) { |
|
| 795 | - $this->chmod( $abs_path, $perms ); |
|
| 796 | - $this->create_index( $abs_path ); |
|
| 797 | - |
|
| 798 | - return true; |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - $return = false; |
|
| 802 | - |
|
| 803 | - if ( $this->is_writable( dirname( $abs_path ) ) ) { |
|
| 804 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions, WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_is_writable |
|
| 805 | - $return = @mkdir( $abs_path, $perms, true ); |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - if ( ! $return && $this->use_filesystem ) { |
|
| 809 | - $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 810 | - |
|
| 811 | - if ( $this->is_dir( $abs_path ) ) { |
|
| 812 | - $this->create_index( $abs_path ); |
|
| 813 | - |
|
| 814 | - return true; |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - // WP_Filesystem doesn't offer a recursive mkdir(). |
|
| 818 | - $abs_path = str_replace( '//', '/', $abs_path ); |
|
| 819 | - $abs_path = rtrim( $abs_path, '/' ); |
|
| 820 | - if ( empty( $abs_path ) ) { |
|
| 821 | - $abs_path = '/'; |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - $dirs = explode( '/', ltrim( $abs_path, '/' ) ); |
|
| 825 | - $current_dir = ''; |
|
| 826 | - |
|
| 827 | - foreach ( $dirs as $dir ) { |
|
| 828 | - $current_dir .= '/' . $dir; |
|
| 829 | - |
|
| 830 | - // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_is_writable, WordPress.WP.AlternativeFunctions.file_system_operations_is_writable |
|
| 831 | - if ( ! $this->is_dir( $current_dir ) && $this->is_writable( dirname( $current_dir ) ) ) { |
|
| 832 | - $this->wp_filesystem->mkdir( $current_dir, $perms ); |
|
| 833 | - } |
|
| 834 | - } |
|
| 835 | - |
|
| 836 | - $return = $this->is_dir( $abs_path ); |
|
| 837 | - } |
|
| 838 | - |
|
| 839 | - return $return; |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - /** |
|
| 843 | - * Delete a directory. |
|
| 844 | - * |
|
| 845 | - * @param string $abs_path Absolute path. |
|
| 846 | - * @param bool $recursive Set to recursively create. |
|
| 847 | - * |
|
| 848 | - * @return bool |
|
| 849 | - */ |
|
| 850 | - public function rmdir( string $abs_path, bool $recursive = false ): bool { |
|
| 851 | - if ( ! $this->is_dir( $abs_path ) ) { |
|
| 852 | - return false; |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - // Taken from WP_Filesystem_Direct. |
|
| 856 | - if ( ! $recursive ) { |
|
| 857 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions |
|
| 858 | - $return = @rmdir( $abs_path ); |
|
| 859 | - } else { |
|
| 860 | - |
|
| 861 | - // At this point, it's a folder, and we're in recursive mode. |
|
| 862 | - $abs_path = trailingslashit( $abs_path ); |
|
| 863 | - $filelist = $this->scandir( $abs_path ); |
|
| 864 | - |
|
| 865 | - $return = true; |
|
| 866 | - if ( is_array( $filelist ) ) { |
|
| 867 | - foreach ( $filelist as $filename => $fileinfo ) { |
|
| 868 | - |
|
| 869 | - if ( 'd' === $fileinfo['type'] ) { |
|
| 870 | - $return = $this->rmdir( $abs_path . $filename, $recursive ); |
|
| 871 | - } else { |
|
| 872 | - $return = $this->unlink( $abs_path . $filename ); |
|
| 873 | - } |
|
| 874 | - } |
|
| 875 | - } |
|
| 876 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions |
|
| 877 | - if ( file_exists( $abs_path ) && ! @rmdir( $abs_path ) ) { |
|
| 878 | - $return = false; |
|
| 879 | - } |
|
| 880 | - } |
|
| 881 | - |
|
| 882 | - if ( ! $return && $this->use_filesystem ) { |
|
| 883 | - $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 884 | - |
|
| 885 | - return $this->wp_filesystem->rmdir( $abs_path, $recursive ); |
|
| 886 | - } |
|
| 887 | - |
|
| 888 | - return $return; |
|
| 889 | - } |
|
| 890 | - |
|
| 891 | - /** |
|
| 892 | - * Get a list of files/folders under the specified directory. |
|
| 893 | - * |
|
| 894 | - * @param string $abs_path Absolute path. |
|
| 895 | - * @param bool $include_hidden Include hidden files, defaults to true. |
|
| 896 | - * @param bool $recursive Recursive search, defaults to false. |
|
| 897 | - * |
|
| 898 | - * @return array|bool |
|
| 899 | - */ |
|
| 900 | - public function scandir( string $abs_path, bool $include_hidden = true, bool $recursive = false ) { |
|
| 901 | - if ( $this->is_file( $abs_path ) ) { |
|
| 902 | - $limit_file = basename( $abs_path ); |
|
| 903 | - $abs_path = dirname( $abs_path ); |
|
| 904 | - } else { |
|
| 905 | - $limit_file = false; |
|
| 906 | - } |
|
| 907 | - |
|
| 908 | - if ( ! $this->is_dir( $abs_path ) || ! $this->is_readable( $abs_path ) ) { |
|
| 909 | - return false; |
|
| 910 | - } |
|
| 911 | - |
|
| 912 | - $dir = dir( $abs_path ); |
|
| 913 | - |
|
| 914 | - if ( false === $dir ) { |
|
| 915 | - if ( $this->use_filesystem ) { |
|
| 916 | - $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 917 | - |
|
| 918 | - return $this->wp_filesystem->dirlist( $abs_path, $include_hidden, $recursive ); |
|
| 919 | - } |
|
| 920 | - |
|
| 921 | - return false; |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - $ret = array(); |
|
| 925 | - |
|
| 926 | - while ( false !== ( $entry = $dir->read() ) ) { |
|
| 927 | - $struc = array(); |
|
| 928 | - $struc['name'] = $entry; |
|
| 929 | - |
|
| 930 | - if ( '.' === $struc['name'] || '..' === $struc['name'] ) { |
|
| 931 | - continue; |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - if ( ! $include_hidden && '.' === $struc['name'][0] ) { |
|
| 935 | - continue; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - if ( $limit_file && $struc['name'] !== $limit_file ) { |
|
| 939 | - continue; |
|
| 940 | - } |
|
| 941 | - |
|
| 942 | - $struc['type'] = $this->is_dir( $abs_path . '/' . $entry ) ? 'd' : 'f'; |
|
| 943 | - |
|
| 944 | - if ( 'd' === $struc['type'] ) { |
|
| 945 | - if ( $recursive ) { |
|
| 946 | - $struc['files'] = $this->scandir( $abs_path . '/' . $struc['name'], $include_hidden, $recursive ); |
|
| 947 | - } else { |
|
| 948 | - $struc['files'] = array(); |
|
| 949 | - } |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - $ret[ $struc['name'] ] = $struc; |
|
| 953 | - } |
|
| 954 | - |
|
| 955 | - $dir->close(); |
|
| 956 | - |
|
| 957 | - unset( $dir ); |
|
| 958 | - |
|
| 959 | - return $ret; |
|
| 960 | - } |
|
| 961 | - |
|
| 962 | - /** |
|
| 963 | - * Light wrapper for move_uploaded_file with chmod. |
|
| 964 | - * |
|
| 965 | - * @param string $file Source file. |
|
| 966 | - * @param string $destination File destination. |
|
| 967 | - * @param int|null $perms Permission value. |
|
| 968 | - * |
|
| 969 | - * @return bool |
|
| 970 | - */ |
|
| 971 | - public function move_uploaded_file( string $file, string $destination, ?int $perms = null ): bool { |
|
| 972 | - // TODO: look into replicating more functionality from wp_handle_upload(). |
|
| 973 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors |
|
| 974 | - $return = @move_uploaded_file( $file, $destination ); |
|
| 975 | - |
|
| 976 | - if ( $return ) { |
|
| 977 | - $this->chmod( $destination, $perms ); |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - return $return; |
|
| 981 | - } |
|
| 982 | - |
|
| 983 | - /** |
|
| 984 | - * Copy a file. |
|
| 985 | - * |
|
| 986 | - * @param string $source_abs_path Source path. |
|
| 987 | - * @param string $destination_abs_path Destination path. |
|
| 988 | - * @param bool $overwrite Overwrite file. |
|
| 989 | - * @param mixed $perms Permission value. |
|
| 990 | - * @return bool |
|
| 991 | - * Taken from WP_Filesystem_Direct |
|
| 992 | - */ |
|
| 993 | - public function copy( string $source_abs_path, string $destination_abs_path, bool $overwrite = true, $perms = false ): bool { |
|
| 994 | - |
|
| 995 | - // Error if source file doesn't exist. |
|
| 996 | - if ( ! $this->file_exists( $source_abs_path ) ) { |
|
| 997 | - return false; |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - if ( ! $overwrite && $this->file_exists( $destination_abs_path ) ) { |
|
| 1001 | - return false; |
|
| 1002 | - } |
|
| 1003 | - if ( ! $this->is_dir( dirname( $destination_abs_path ) ) ) { |
|
| 1004 | - $this->mkdir( dirname( $destination_abs_path ) ); |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - // phpcs:ignore WordPress.PHP.NoSilencedErrors |
|
| 1008 | - $return = @copy( $source_abs_path, $destination_abs_path ); |
|
| 1009 | - if ( $perms && $return ) { |
|
| 1010 | - $this->chmod( $destination_abs_path, $perms ); |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - if ( ! $return && $this->use_filesystem ) { |
|
| 1014 | - $source_abs_path = $this->get_sanitized_path( $source_abs_path ); |
|
| 1015 | - $destination_abs_path = $this->get_sanitized_path( $destination_abs_path ); |
|
| 1016 | - $return = $this->wp_filesystem->copy( |
|
| 1017 | - $source_abs_path, |
|
| 1018 | - $destination_abs_path, |
|
| 1019 | - $overwrite, |
|
| 1020 | - $perms |
|
| 1021 | - ); |
|
| 1022 | - } |
|
| 1023 | - |
|
| 1024 | - return $return; |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - /** |
|
| 1028 | - * Move a file. |
|
| 1029 | - * |
|
| 1030 | - * @param string $source_abs_path Source absolute path. |
|
| 1031 | - * @param string $destination_abs_path Destination absolute path. |
|
| 1032 | - * @param bool $overwrite Overwrite if file exists. |
|
| 1033 | - * @return bool |
|
| 1034 | - */ |
|
| 1035 | - public function move( string $source_abs_path, string $destination_abs_path, bool $overwrite = true ): bool { |
|
| 1036 | - |
|
| 1037 | - // Error if source file doesn't exist. |
|
| 1038 | - if ( ! $this->file_exists( $source_abs_path ) ) { |
|
| 1039 | - return false; |
|
| 1040 | - } |
|
| 1041 | - |
|
| 1042 | - // Try using rename first. |
|
| 1043 | - // If that fails (for example, the source is read only) try copy. |
|
| 1044 | - // Taken in part from WP_Filesystem_Direct. |
|
| 1045 | - if ( ! $overwrite && $this->file_exists( $destination_abs_path ) ) { |
|
| 1046 | - return false; |
|
| 1047 | - } elseif ( @rename( $source_abs_path, $destination_abs_path ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions |
|
| 1048 | - return true; |
|
| 1049 | - } elseif ( $this->copy( $source_abs_path, $destination_abs_path, $overwrite ) && $this->file_exists( |
|
| 1050 | - $destination_abs_path |
|
| 1051 | - ) ) { |
|
| 1052 | - |
|
| 1053 | - $this->unlink( $source_abs_path ); |
|
| 1054 | - |
|
| 1055 | - return true; |
|
| 1056 | - } else { |
|
| 1057 | - $return = false; |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - if ( $this->use_filesystem ) { |
|
| 1061 | - $source_abs_path = $this->get_sanitized_path( $source_abs_path ); |
|
| 1062 | - $destination_abs_path = $this->get_sanitized_path( $destination_abs_path ); |
|
| 1063 | - |
|
| 1064 | - $return = $this->wp_filesystem->move( $source_abs_path, $destination_abs_path, $overwrite ); |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - return $return; |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - /** |
|
| 1071 | - * Shim: get_template. |
|
| 1072 | - * |
|
| 1073 | - * @param string $file Template name. |
|
| 1074 | - * |
|
| 1075 | - * @return void Path to template file. |
|
| 1076 | - */ |
|
| 1077 | - public function get_template( string $file ) { |
|
| 1078 | - $panel = new Redux_Panel( $this ); |
|
| 1079 | - $panel->get_template( $file ); |
|
| 1080 | - } |
|
| 1081 | - } |
|
| 1082 | - |
|
| 1083 | - Redux_Filesystem::get_instance(); |
|
| 16 | + /** |
|
| 17 | + * Class Redux_Filesystem |
|
| 18 | + */ |
|
| 19 | + class Redux_Filesystem { |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * Instance of this class. |
|
| 23 | + * |
|
| 24 | + * @since 1.0.0 |
|
| 25 | + * @var null|Redux_Filesystem |
|
| 26 | + */ |
|
| 27 | + protected static ?Redux_Filesystem $instance = null; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * WP Filesystem object. |
|
| 31 | + * |
|
| 32 | + * @var null|WP_Filesystem_Direct |
|
| 33 | + */ |
|
| 34 | + protected static ?WP_Filesystem_Direct $direct = null; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * File system credentials. |
|
| 38 | + * |
|
| 39 | + * @var array|bool|null |
|
| 40 | + */ |
|
| 41 | + private $creds; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * ReduxFramework object pointer. |
|
| 45 | + * |
|
| 46 | + * @var null|ReduxFramework |
|
| 47 | + */ |
|
| 48 | + public ?ReduxFramework $parent = null; |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * Instance of WP_Filesystem |
|
| 52 | + * |
|
| 53 | + * @var WP_Filesystem_Base|null |
|
| 54 | + */ |
|
| 55 | + private ?WP_Filesystem_Base $wp_filesystem = null; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * If DBI_Filesystem should attempt to use the WP_Filesystem class. |
|
| 59 | + * |
|
| 60 | + * @var bool |
|
| 61 | + */ |
|
| 62 | + private bool $use_filesystem = false; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Default chmod octal value for directories. |
|
| 66 | + * |
|
| 67 | + * @var int |
|
| 68 | + */ |
|
| 69 | + private int $chmod_dir; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Default chmod octal value for files. |
|
| 73 | + * |
|
| 74 | + * @var int |
|
| 75 | + */ |
|
| 76 | + private int $chmod_file; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Default cache folder. |
|
| 80 | + * |
|
| 81 | + * @var string |
|
| 82 | + */ |
|
| 83 | + public string $cache_folder; |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Kill switch. |
|
| 87 | + * |
|
| 88 | + * @var bool |
|
| 89 | + */ |
|
| 90 | + public bool $killswitch = false; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * FTP Form HTML. |
|
| 94 | + * |
|
| 95 | + * @var string |
|
| 96 | + */ |
|
| 97 | + public string $ftp_form; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Pass `true` when instantiating to skip using WP_Filesystem. |
|
| 101 | + * |
|
| 102 | + * @param bool $force_no_fs Force no use of the filesystem. |
|
| 103 | + */ |
|
| 104 | + public function __construct( bool $force_no_fs = false ) { |
|
| 105 | + |
|
| 106 | + // This little number fixes some issues with certain filesystem setups. |
|
| 107 | + |
|
| 108 | + if ( ! function_exists( 'request_filesystem_credentials' ) ) { |
|
| 109 | + require_once ABSPATH . '/wp-admin/includes/template.php'; |
|
| 110 | + require_once ABSPATH . '/wp-includes/pluggable.php'; |
|
| 111 | + require_once ABSPATH . '/wp-admin/includes/file.php'; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + // Set default permissions. |
|
| 115 | + if ( defined( 'FS_CHMOD_DIR' ) ) { |
|
| 116 | + $this->chmod_dir = FS_CHMOD_DIR; |
|
| 117 | + } else { |
|
| 118 | + $this->chmod_dir = ( fileperms( ABSPATH ) & 0777 | 0755 ); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if ( defined( 'FS_CHMOD_FILE' ) ) { |
|
| 122 | + $this->chmod_file = FS_CHMOD_FILE; |
|
| 123 | + } else { |
|
| 124 | + $this->chmod_file = ( fileperms( ABSPATH . 'index.php' ) & 0777 | 0644 ); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + if ( ! $force_no_fs && function_exists( 'request_filesystem_credentials' ) ) { |
|
| 128 | + if ( ( defined( 'WPMDB_WP_FILESYSTEM' ) && WPMDB_WP_FILESYSTEM ) || ! defined( 'WPMDB_WP_FILESYSTEM' ) ) { |
|
| 129 | + $this->maybe_init_wp_filesystem(); |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + $uploads_dir = wp_upload_dir(); |
|
| 134 | + $this->cache_folder = trailingslashit( $uploads_dir['basedir'] ) . 'redux/'; |
|
| 135 | + if ( ! $this->file_exists( $this->cache_folder ) ) { |
|
| 136 | + $this->mkdir( $this->cache_folder ); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Return an instance of this class. |
|
| 142 | + * |
|
| 143 | + * @param ReduxFramework|null $me ReduxFramework pointer. |
|
| 144 | + * |
|
| 145 | + * @return object A single instance of this class. |
|
| 146 | + * @since 1.0.0 |
|
| 147 | + */ |
|
| 148 | + public static function get_instance( ?ReduxFramework $me = null ): ?object { |
|
| 149 | + |
|
| 150 | + // If the single instance hasn't been set, set it now. |
|
| 151 | + if ( null === self::$instance ) { |
|
| 152 | + self::$instance = new self(); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + if ( null !== $me ) { |
|
| 156 | + self::$instance->parent = $me; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return self::$instance; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Build an FTP form. |
|
| 164 | + */ |
|
| 165 | + public function ftp_form() { |
|
| 166 | + if ( isset( $this->ftp_form ) && ! empty( $this->ftp_form ) ) { |
|
| 167 | + echo '<div class="wrap">'; |
|
| 168 | + echo '<div class="error">'; |
|
| 169 | + echo '<p>'; |
|
| 170 | + // translators: %1$s: Upload URL. %2$s: Codex URL. |
|
| 171 | + echo '<strong>' . esc_html__( 'File Permission Issues', 'redux-framework' ) . '</strong><br/>' . sprintf( esc_html__( 'We were unable to modify required files. Please ensure that %1$s has the proper read-write permissions, or modify your wp-config.php file to contain your FTP login credentials as %2$s.', 'redux-framework' ), '<code>' . esc_url( Redux_Functions_Ex::wp_normalize_path( trailingslashit( WP_CONTENT_DIR ) ) . '/uploads/' ) . '</code>', ' <a href="https://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants" target="_blank">' . esc_html__( 'outlined here', 'redux-framework' ) . '</a>' ); |
|
| 172 | + echo '</p>'; |
|
| 173 | + echo '</div>'; |
|
| 174 | + echo '<h2></h2>'; |
|
| 175 | + echo '</div>'; |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + /** |
|
| 180 | + * Attempt to initiate WP_Filesystem |
|
| 181 | + * If this fails, $use_filesystem is set to false and all methods in this class should use native php fallbacks |
|
| 182 | + * Thwarts `request_filesystem_credentials()` attempt to display a form for obtaining creds from users |
|
| 183 | + * TODO: provide notice and input in wp-admin for users when this fails |
|
| 184 | + */ |
|
| 185 | + public function maybe_init_wp_filesystem() { |
|
| 186 | + // Set up the filesystem with creds. |
|
| 187 | + require_once ABSPATH . '/wp-admin/includes/template.php'; |
|
| 188 | + require_once ABSPATH . '/wp-includes/pluggable.php'; |
|
| 189 | + require_once ABSPATH . '/wp-admin/includes/file.php'; |
|
| 190 | + |
|
| 191 | + ob_start(); |
|
| 192 | + $credentials = request_filesystem_credentials( '', '', false, false ); |
|
| 193 | + $ob_contents = ob_get_contents(); |
|
| 194 | + ob_end_clean(); |
|
| 195 | + |
|
| 196 | + if ( @wp_filesystem( $credentials ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors |
|
| 197 | + global $wp_filesystem; |
|
| 198 | + $this->wp_filesystem = $wp_filesystem; |
|
| 199 | + $this->use_filesystem = true; |
|
| 200 | + $this->generate_default_files(); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Init WO Filesystem. |
|
| 206 | + * |
|
| 207 | + * @param string $form_url Form URL. |
|
| 208 | + * @param string $method Connect method. |
|
| 209 | + * @param bool $context Context. |
|
| 210 | + * |
|
| 211 | + * @return bool |
|
| 212 | + */ |
|
| 213 | + public function advanced_filesystem_init( string $form_url, string $method = '', bool $context = false ): bool { |
|
| 214 | + if ( ! empty( $this->wp_filesystem ) && $this->use_filesystem ) { |
|
| 215 | + return true; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + if ( ! empty( $this->creds ) ) { |
|
| 219 | + return true; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + ob_start(); |
|
| 223 | + |
|
| 224 | + $this->creds = request_filesystem_credentials( $form_url, $method, false, $context ); |
|
| 225 | + |
|
| 226 | + /* first attempt to get credentials */ |
|
| 227 | + if ( false === $this->creds ) { |
|
| 228 | + $this->creds = array(); |
|
| 229 | + $this->ftp_form = ob_get_contents(); |
|
| 230 | + ob_end_clean(); |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * If we come here, we don't have credentials |
|
| 234 | + * so the request for them is displaying |
|
| 235 | + * no need for further processing |
|
| 236 | + * */ |
|
| 237 | + return false; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /* now we got some credentials - try to use them */ |
|
| 241 | + if ( ! @wp_filesystem( $this->creds ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors |
|
| 242 | + $this->creds = array(); |
|
| 243 | + /* incorrect connection data - ask for credentials again, now with an error message */ |
|
| 244 | + request_filesystem_credentials( $form_url, '', true, $context ); |
|
| 245 | + $this->ftp_form = ob_get_contents(); |
|
| 246 | + ob_end_clean(); |
|
| 247 | + |
|
| 248 | + return false; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + global $wp_filesystem; |
|
| 252 | + $this->wp_filesystem = $wp_filesystem; |
|
| 253 | + $this->use_filesystem = true; |
|
| 254 | + $this->generate_default_files(); |
|
| 255 | + |
|
| 256 | + return true; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Load WP filesystem directly. |
|
| 261 | + */ |
|
| 262 | + public static function load_direct() { |
|
| 263 | + if ( null === self::$direct ) { |
|
| 264 | + require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-base.php'; |
|
| 265 | + require_once ABSPATH . '/wp-admin/includes/class-wp-filesystem-direct.php'; |
|
| 266 | + |
|
| 267 | + self::$direct = new WP_Filesystem_Direct( array() ); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Execute filesystem request. |
|
| 273 | + * |
|
| 274 | + * @param string $action Action to perform. |
|
| 275 | + * @param string $file File to perform upon. |
|
| 276 | + * @param array $params Argument for action. |
|
| 277 | + * |
|
| 278 | + * @return bool|void |
|
| 279 | + */ |
|
| 280 | + public function execute( string $action, string $file = '', array $params = array() ) { |
|
| 281 | + if ( empty( $this->parent->args ) ) { |
|
| 282 | + return; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + if ( ! empty( $params ) ) { |
|
| 286 | + // phpcs:ignore WordPress.PHP.DontExtract |
|
| 287 | + extract( $params ); |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + if ( empty( $this->wp_filesystem ) ) { |
|
| 291 | + if ( 'submenu' === $this->parent->args['menu_type'] ) { |
|
| 292 | + $page_parent = $this->parent->args['page_parent']; |
|
| 293 | + $base = $page_parent . '?page=' . $this->parent->args['page_slug']; |
|
| 294 | + } else { |
|
| 295 | + $base = 'admin.php?page=' . $this->parent->args['page_slug']; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + $url = wp_nonce_url( $base, 'redux-options' ); |
|
| 299 | + $this->advanced_filesystem_init( $url, 'direct', dirname( $file ) ); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + return $this->do_action( $action, $file, $params ); |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Generates the default Redux cache folder. |
|
| 308 | + * |
|
| 309 | + * @return void |
|
| 310 | + */ |
|
| 311 | + private function generate_default_files() { |
|
| 312 | + if ( ! $this->is_dir( Redux_Core::$upload_dir ) ) { |
|
| 313 | + $this->mkdir( Redux_Core::$upload_dir ); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + /** |
|
| 318 | + * Do request filesystem action. |
|
| 319 | + * |
|
| 320 | + * @param string $action Requested action. |
|
| 321 | + * @param string $file File to perform action upon. |
|
| 322 | + * @param array $params Action arguments. |
|
| 323 | + * |
|
| 324 | + * @return bool|void |
|
| 325 | + */ |
|
| 326 | + public function do_action( string $action, string $file = '', array $params = array() ) { |
|
| 327 | + $destination = ''; |
|
| 328 | + $overwrite = ''; |
|
| 329 | + $content = ''; |
|
| 330 | + |
|
| 331 | + if ( ! empty( $params ) ) { |
|
| 332 | + |
|
| 333 | + // phpcs:ignore WordPress.PHP.DontExtract |
|
| 334 | + extract( $params ); |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + global $wp_filesystem; |
|
| 338 | + |
|
| 339 | + if ( defined( 'FS_CHMOD_FILE' ) ) { |
|
| 340 | + $chmod = FS_CHMOD_FILE; |
|
| 341 | + } else { |
|
| 342 | + $chmod = 0644; |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + if ( isset( $params['chmod'] ) && ! empty( $params['chmod'] ) ) { |
|
| 346 | + $chmod = $params['chmod']; |
|
| 347 | + } |
|
| 348 | + $res = false; |
|
| 349 | + if ( ! isset( $recursive ) ) { |
|
| 350 | + $recursive = false; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + // Do unique stuff. |
|
| 354 | + if ( 'mkdir' === $action ) { |
|
| 355 | + $chmod = null; |
|
| 356 | + if ( isset( $params['chmod'] ) && ! empty( $params['chmod'] ) ) { |
|
| 357 | + $chmod = $params['chmod']; |
|
| 358 | + } |
|
| 359 | + $res = $this->mkdir( $file, $chmod ); |
|
| 360 | + } elseif ( 'rmdir' === $action ) { |
|
| 361 | + $res = $this->rmdir( $file, $recursive ); |
|
| 362 | + } elseif ( 'copy' === $action && false === $this->killswitch ) { |
|
| 363 | + $res = $this->copy( $file, $destination, $overwrite, $chmod ); |
|
| 364 | + } elseif ( 'move' === $action && false === $this->killswitch ) { |
|
| 365 | + $res = $this->move( $file, $destination, $overwrite ); |
|
| 366 | + } elseif ( 'delete' === $action ) { |
|
| 367 | + if ( $this->is_dir( $file ) ) { |
|
| 368 | + $res = $this->rmdir( $file, $recursive ); |
|
| 369 | + } else { |
|
| 370 | + $res = $this->unlink( $file ); |
|
| 371 | + } |
|
| 372 | + } elseif ( 'dirlist' === $action ) { |
|
| 373 | + if ( ! isset( $include_hidden ) ) { |
|
| 374 | + $include_hidden = true; |
|
| 375 | + } |
|
| 376 | + $res = $this->scandir( $file, $include_hidden, $recursive ); |
|
| 377 | + } elseif ( 'put_contents' === $action && false === $this->killswitch ) { |
|
| 378 | + // Write a string to a file. |
|
| 379 | + if ( isset( $this->ftp_form ) && ! empty( $this->ftp_form ) ) { |
|
| 380 | + self::load_direct(); |
|
| 381 | + $res = self::$direct->put_contents( $file, $content, $chmod ); |
|
| 382 | + } else { |
|
| 383 | + $res = $this->put_contents( $file, $content, $chmod ); |
|
| 384 | + } |
|
| 385 | + } elseif ( 'chown' === $action ) { |
|
| 386 | + // Changes the file owner. |
|
| 387 | + if ( isset( $owner ) && ! empty( $owner ) ) { |
|
| 388 | + $res = $wp_filesystem->chmod( $file, $chmod, $recursive ); |
|
| 389 | + } |
|
| 390 | + } elseif ( 'owner' === $action ) { |
|
| 391 | + // Gets the file owner. |
|
| 392 | + $res = $this->wp_filesystem->owner( $file ); |
|
| 393 | + } elseif ( 'chmod' === $action ) { |
|
| 394 | + if ( ! isset( $params['chmod'] ) || ( empty( $params['chmod'] ) ) ) { |
|
| 395 | + $chmod = false; |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + $res = $this->chmod( $file, $chmod ); |
|
| 399 | + } elseif ( 'get_contents' === $action ) { |
|
| 400 | + // Reads entire file into a string. |
|
| 401 | + if ( isset( $this->ftp_form ) && ! empty( $this->ftp_form ) ) { |
|
| 402 | + self::load_direct(); |
|
| 403 | + $res = self::$direct->get_contents( $file ); |
|
| 404 | + } else { |
|
| 405 | + $res = $this->get_contents( $file ); |
|
| 406 | + } |
|
| 407 | + } elseif ( 'get_contents_array' === $action ) { |
|
| 408 | + // Reads entire file into an array. |
|
| 409 | + $res = $this->wp_filesystem->get_contents_array( $file ); |
|
| 410 | + } elseif ( 'object' === $action ) { |
|
| 411 | + $res = $this->wp_filesystem; |
|
| 412 | + } elseif ( 'unzip' === $action ) { |
|
| 413 | + $unzipfile = unzip_file( $file, $destination ); |
|
| 414 | + if ( $unzipfile ) { |
|
| 415 | + $res = true; |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + if ( ! $res ) { |
|
| 420 | + if ( 'dirlist' === $action ) { |
|
| 421 | + if ( empty( $res ) ) { |
|
| 422 | + return; |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + if ( ! is_array( $res ) ) { |
|
| 426 | + if ( count( glob( "$file*" ) ) === 0 ) { |
|
| 427 | + return; |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + $this->killswitch = true; |
|
| 433 | + |
|
| 434 | + // translators: %1$s: Upload URL. %2$s: Codex URL. |
|
| 435 | + $msg = '<strong>' . esc_html__( 'File Permission Issues', 'redux-framework' ) . '</strong><br/>' . sprintf( esc_html__( 'We were unable to modify required files. Please ensure that %1$s has the proper read-write permissions, or modify your wp-config.php file to contain your FTP login credentials as %2$s.', 'redux-framework' ), '<code>' . esc_url( Redux_Functions_Ex::wp_normalize_path( trailingslashit( WP_CONTENT_DIR ) ) ) . '/uploads/</code>', '<a href="https://codex.wordpress.org/Editing_wp-config.php#WordPress_Upgrade_Constants" target="_blank">' . esc_html__( 'outlined here', 'redux-framework' ) . '</a>' ); |
|
| 436 | + |
|
| 437 | + $data = array( |
|
| 438 | + 'parent' => self::$instance->parent, |
|
| 439 | + 'type' => 'error', |
|
| 440 | + 'msg' => $msg, |
|
| 441 | + 'id' => 'redux-wp-login', |
|
| 442 | + 'dismiss' => false, |
|
| 443 | + ); |
|
| 444 | + |
|
| 445 | + Redux_Admin_Notices::set_notice( $data ); |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + return $res; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + |
|
| 452 | + /** |
|
| 453 | + * Getter for the instantiated WP_Filesystem. This should be used carefully since $wp_filesystem won't always have a value. |
|
| 454 | + * |
|
| 455 | + * @return WP_Filesystem_Base|false |
|
| 456 | + */ |
|
| 457 | + public function get_wp_filesystem() { |
|
| 458 | + if ( $this->use_filesystem ) { |
|
| 459 | + return $this->wp_filesystem; |
|
| 460 | + } else { |
|
| 461 | + return false; |
|
| 462 | + } |
|
| 463 | + } |
|
| 464 | + |
|
| 465 | + /** |
|
| 466 | + * Check if WP_Filesystem being used. |
|
| 467 | + * |
|
| 468 | + * @return bool |
|
| 469 | + */ |
|
| 470 | + public function using_wp_filesystem(): bool { |
|
| 471 | + return $this->use_filesystem; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * Attempts to use the correct path for the FS method being used. |
|
| 476 | + * |
|
| 477 | + * @param string $abs_path Absolute path. |
|
| 478 | + * |
|
| 479 | + * @return string |
|
| 480 | + */ |
|
| 481 | + public function get_sanitized_path( string $abs_path ): string { |
|
| 482 | + if ( $this->using_wp_filesystem() ) { |
|
| 483 | + return str_replace( ABSPATH, $this->wp_filesystem->abspath(), $abs_path ); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return $abs_path; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * Create file if not exists then set mtime and atime on file |
|
| 491 | + * |
|
| 492 | + * @param string $abs_path Absolute path. |
|
| 493 | + * @param int $time Time. |
|
| 494 | + * @param int $atime Altered time. |
|
| 495 | + * |
|
| 496 | + * @return bool |
|
| 497 | + */ |
|
| 498 | + public function touch( string $abs_path, int $time = 0, int $atime = 0 ): bool { |
|
| 499 | + if ( 0 === $time ) { |
|
| 500 | + $time = time(); |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + if ( 0 === $atime ) { |
|
| 504 | + $atime = time(); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP |
|
| 508 | + $return = @touch( $abs_path, $time, $atime ); |
|
| 509 | + |
|
| 510 | + if ( ! $return && $this->use_filesystem ) { |
|
| 511 | + $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 512 | + $return = $this->wp_filesystem->touch( $abs_path, $time, $atime ); |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + return $return; |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + /** |
|
| 519 | + * Calls file_put_contents with chmod. |
|
| 520 | + * |
|
| 521 | + * @param string $abs_path Absolute path. |
|
| 522 | + * @param string $contents Content to write to the file. |
|
| 523 | + * @param string|null $perms Default permissions value. |
|
| 524 | + * |
|
| 525 | + * @return bool |
|
| 526 | + */ |
|
| 527 | + public function put_contents( string $abs_path, string $contents, ?string $perms = null ): bool { |
|
| 528 | + $return = false; |
|
| 529 | + |
|
| 530 | + if ( ! $this->is_dir( dirname( $abs_path ) ) ) { |
|
| 531 | + $this->mkdir( dirname( $abs_path ) ); |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + if ( $this->is_writable( dirname( $abs_path ) ) ) { |
|
| 535 | + // phpcs:ignore WordPress.WP.AlternativeFunctions.file_system_operations_file_put_contents, WordPress.PHP.NoSilencedErrors.Discouraged |
|
| 536 | + $return = @file_put_contents( $abs_path, $contents ); |
|
| 537 | + $this->chmod( $abs_path ); |
|
| 538 | + |
|
| 539 | + if ( null === $perms ) { |
|
| 540 | + $perms = $this->chmod_file; |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + if ( ! $return && $this->use_filesystem ) { |
|
| 545 | + $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 546 | + // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_is_writable, WordPress.WP.AlternativeFunctions.file_system_operations_is_writable |
|
| 547 | + if ( $this->is_writable( dirname( $abs_path ) ) ) { |
|
| 548 | + $return = $this->wp_filesystem->put_contents( $abs_path, $contents, $perms ); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + return (bool) $return; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + /** |
|
| 556 | + * Does the specified file or dir exist? |
|
| 557 | + * |
|
| 558 | + * @param string $abs_path Absolute path. |
|
| 559 | + * @return bool |
|
| 560 | + */ |
|
| 561 | + public function file_exists( string $abs_path ): bool { |
|
| 562 | + $return = file_exists( $abs_path ); |
|
| 563 | + |
|
| 564 | + if ( ! $return && $this->use_filesystem ) { |
|
| 565 | + $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 566 | + $return = $this->wp_filesystem->exists( $abs_path ); |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + return $return; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + /** |
|
| 573 | + * Get a file's size. |
|
| 574 | + * |
|
| 575 | + * @param string $abs_path Absolute path. |
|
| 576 | + * |
|
| 577 | + * @return int |
|
| 578 | + */ |
|
| 579 | + public function filesize( string $abs_path ): int { |
|
| 580 | + $return = filesize( $abs_path ); |
|
| 581 | + |
|
| 582 | + if ( ! $return && $this->use_filesystem ) { |
|
| 583 | + $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 584 | + $return = $this->wp_filesystem->size( $abs_path ); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + return $return; |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + /** |
|
| 591 | + * Get the contents of a file as a string. |
|
| 592 | + * |
|
| 593 | + * @param string $abs_path Absolute path. |
|
| 594 | + * |
|
| 595 | + * @return string |
|
| 596 | + */ |
|
| 597 | + public function get_local_file_contents( string $abs_path ): string { |
|
| 598 | + |
|
| 599 | + try { |
|
| 600 | + $contents = ''; |
|
| 601 | + |
|
| 602 | + if ( $this->file_exists( $abs_path ) && is_file( $abs_path ) ) { |
|
| 603 | + if ( $this->is_writable( $abs_path ) ) { // phpcs:ignore WordPress.WP.AlternativeFunctions |
|
| 604 | + ob_start(); |
|
| 605 | + |
|
| 606 | + include_once $abs_path; |
|
| 607 | + |
|
| 608 | + $contents = ob_get_clean(); |
|
| 609 | + } |
|
| 610 | + } |
|
| 611 | + } catch ( Exception $e ) { |
|
| 612 | + // This means that ob_start has been disabled on the system. Lets fallback to good old file_get_contents. |
|
| 613 | + $contents = file_get_contents( $abs_path ); // phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + return $contents; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + /** |
|
| 620 | + * Get the contents of a file as a string. |
|
| 621 | + * |
|
| 622 | + * @param string $abs_path Absolute path. |
|
| 623 | + * |
|
| 624 | + * @return string |
|
| 625 | + */ |
|
| 626 | + public function get_contents( string $abs_path ): string { |
|
| 627 | + $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 628 | + $return = ''; |
|
| 629 | + if ( $this->use_filesystem ) { |
|
| 630 | + $return = $this->wp_filesystem->get_contents( $abs_path ); |
|
| 631 | + } |
|
| 632 | + if ( empty( $return ) ) { |
|
| 633 | + $return = $this->get_local_file_contents( $abs_path ); |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + return $return; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * Delete a file. |
|
| 641 | + * |
|
| 642 | + * @param string $abs_path Absolute path. |
|
| 643 | + * |
|
| 644 | + * @return bool |
|
| 645 | + */ |
|
| 646 | + public function unlink( string $abs_path ): bool { |
|
| 647 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions |
|
| 648 | + $return = @unlink( $abs_path ); |
|
| 649 | + |
|
| 650 | + if ( ! $return && $this->use_filesystem ) { |
|
| 651 | + $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 652 | + $return = $this->wp_filesystem->delete( $abs_path ); |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + return $return; |
|
| 656 | + } |
|
| 657 | + |
|
| 658 | + /** |
|
| 659 | + * Chmod a file. |
|
| 660 | + * |
|
| 661 | + * @param string $abs_path Absolute path. |
|
| 662 | + * @param int|null $perms Permission value, if not provided, defaults to WP standards. |
|
| 663 | + * |
|
| 664 | + * @return bool |
|
| 665 | + */ |
|
| 666 | + public function chmod( string $abs_path, ?int $perms = null ): bool { |
|
| 667 | + if ( ! $this->file_exists( $abs_path ) ) { |
|
| 668 | + return false; |
|
| 669 | + } |
|
| 670 | + if ( is_null( $perms ) ) { |
|
| 671 | + $perms = $this->is_file( $abs_path ) ? $this->chmod_file : $this->chmod_dir; |
|
| 672 | + } |
|
| 673 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions |
|
| 674 | + $return = @chmod( $abs_path, $perms ); |
|
| 675 | + |
|
| 676 | + if ( ! $return && $this->use_filesystem ) { |
|
| 677 | + $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 678 | + $return = $this->wp_filesystem->chmod( $abs_path, $perms ); |
|
| 679 | + } |
|
| 680 | + |
|
| 681 | + return $return; |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + /** |
|
| 685 | + * Check if this path is a directory. |
|
| 686 | + * |
|
| 687 | + * @param string $abs_path Absolute path. |
|
| 688 | + * |
|
| 689 | + * @return bool |
|
| 690 | + */ |
|
| 691 | + public function is_dir( string $abs_path ): bool { |
|
| 692 | + $return = is_dir( $abs_path ); |
|
| 693 | + |
|
| 694 | + if ( ! $return && $this->use_filesystem ) { |
|
| 695 | + $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 696 | + $return = $this->wp_filesystem->is_dir( $abs_path ); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + return $return; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + /** |
|
| 703 | + * Check if the specified path is a file. |
|
| 704 | + * |
|
| 705 | + * @param string $abs_path Absolute path. |
|
| 706 | + * |
|
| 707 | + * @return bool |
|
| 708 | + */ |
|
| 709 | + public function is_file( string $abs_path ): bool { |
|
| 710 | + $return = is_file( $abs_path ); |
|
| 711 | + |
|
| 712 | + if ( ! $return && $this->use_filesystem ) { |
|
| 713 | + $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 714 | + $return = $this->wp_filesystem->is_file( $abs_path ); |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + return $return; |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + /** |
|
| 721 | + * Is the specified path readable? |
|
| 722 | + * |
|
| 723 | + * @param string $abs_path Absolute path. |
|
| 724 | + * |
|
| 725 | + * @return bool |
|
| 726 | + */ |
|
| 727 | + public function is_readable( string $abs_path ): bool { |
|
| 728 | + $return = is_readable( $abs_path ); |
|
| 729 | + |
|
| 730 | + if ( ! $return && $this->use_filesystem ) { |
|
| 731 | + $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 732 | + $return = $this->wp_filesystem->is_readable( $abs_path ); |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + return $return; |
|
| 736 | + } |
|
| 737 | + |
|
| 738 | + /** |
|
| 739 | + * Is the specified path writable? |
|
| 740 | + * |
|
| 741 | + * @param string $abs_path Absolute path. |
|
| 742 | + * |
|
| 743 | + * @return bool |
|
| 744 | + */ |
|
| 745 | + public function is_writable( string $abs_path ): bool { |
|
| 746 | + $return = is_writable( $abs_path ); // phpcs:ignore WordPress.WP.AlternativeFunctions |
|
| 747 | + |
|
| 748 | + if ( ! $return && $this->use_filesystem ) { |
|
| 749 | + $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 750 | + $return = $this->wp_filesystem->is_writable( $abs_path ); |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + return $return; |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + /** |
|
| 757 | + * Create an index file at the given path. |
|
| 758 | + * |
|
| 759 | + * @param string $path Directory to add the index to. |
|
| 760 | + */ |
|
| 761 | + private function create_index( string $path ) { |
|
| 762 | + $index_path = trailingslashit( $path ) . 'index.php'; |
|
| 763 | + if ( ! $this->file_exists( $index_path ) ) { |
|
| 764 | + $this->put_contents( $index_path, "<?php\n//Silence is golden" ); |
|
| 765 | + } |
|
| 766 | + } |
|
| 767 | + |
|
| 768 | + /** |
|
| 769 | + * Recursive mkdir. |
|
| 770 | + * |
|
| 771 | + * @param string $abs_path Absolute path. |
|
| 772 | + * @param int|null $perms Permissions, if default not required. |
|
| 773 | + * |
|
| 774 | + * @return bool |
|
| 775 | + */ |
|
| 776 | + public function mkdir( string $abs_path, ?int $perms = null ): bool { |
|
| 777 | + if ( is_null( $perms ) ) { |
|
| 778 | + $perms = $this->chmod_dir; |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + if ( $this->is_dir( $abs_path ) ) { |
|
| 782 | + $this->chmod( $abs_path, $perms ); |
|
| 783 | + $this->create_index( $abs_path ); |
|
| 784 | + |
|
| 785 | + return true; |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + try { |
|
| 789 | + $mkdirp = wp_mkdir_p( $abs_path ); |
|
| 790 | + } catch ( Exception $e ) { |
|
| 791 | + $mkdirp = false; |
|
| 792 | + } |
|
| 793 | + |
|
| 794 | + if ( $mkdirp ) { |
|
| 795 | + $this->chmod( $abs_path, $perms ); |
|
| 796 | + $this->create_index( $abs_path ); |
|
| 797 | + |
|
| 798 | + return true; |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + $return = false; |
|
| 802 | + |
|
| 803 | + if ( $this->is_writable( dirname( $abs_path ) ) ) { |
|
| 804 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions, WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_is_writable |
|
| 805 | + $return = @mkdir( $abs_path, $perms, true ); |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + if ( ! $return && $this->use_filesystem ) { |
|
| 809 | + $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 810 | + |
|
| 811 | + if ( $this->is_dir( $abs_path ) ) { |
|
| 812 | + $this->create_index( $abs_path ); |
|
| 813 | + |
|
| 814 | + return true; |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + // WP_Filesystem doesn't offer a recursive mkdir(). |
|
| 818 | + $abs_path = str_replace( '//', '/', $abs_path ); |
|
| 819 | + $abs_path = rtrim( $abs_path, '/' ); |
|
| 820 | + if ( empty( $abs_path ) ) { |
|
| 821 | + $abs_path = '/'; |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + $dirs = explode( '/', ltrim( $abs_path, '/' ) ); |
|
| 825 | + $current_dir = ''; |
|
| 826 | + |
|
| 827 | + foreach ( $dirs as $dir ) { |
|
| 828 | + $current_dir .= '/' . $dir; |
|
| 829 | + |
|
| 830 | + // phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.file_ops_is_writable, WordPress.WP.AlternativeFunctions.file_system_operations_is_writable |
|
| 831 | + if ( ! $this->is_dir( $current_dir ) && $this->is_writable( dirname( $current_dir ) ) ) { |
|
| 832 | + $this->wp_filesystem->mkdir( $current_dir, $perms ); |
|
| 833 | + } |
|
| 834 | + } |
|
| 835 | + |
|
| 836 | + $return = $this->is_dir( $abs_path ); |
|
| 837 | + } |
|
| 838 | + |
|
| 839 | + return $return; |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + /** |
|
| 843 | + * Delete a directory. |
|
| 844 | + * |
|
| 845 | + * @param string $abs_path Absolute path. |
|
| 846 | + * @param bool $recursive Set to recursively create. |
|
| 847 | + * |
|
| 848 | + * @return bool |
|
| 849 | + */ |
|
| 850 | + public function rmdir( string $abs_path, bool $recursive = false ): bool { |
|
| 851 | + if ( ! $this->is_dir( $abs_path ) ) { |
|
| 852 | + return false; |
|
| 853 | + } |
|
| 854 | + |
|
| 855 | + // Taken from WP_Filesystem_Direct. |
|
| 856 | + if ( ! $recursive ) { |
|
| 857 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions |
|
| 858 | + $return = @rmdir( $abs_path ); |
|
| 859 | + } else { |
|
| 860 | + |
|
| 861 | + // At this point, it's a folder, and we're in recursive mode. |
|
| 862 | + $abs_path = trailingslashit( $abs_path ); |
|
| 863 | + $filelist = $this->scandir( $abs_path ); |
|
| 864 | + |
|
| 865 | + $return = true; |
|
| 866 | + if ( is_array( $filelist ) ) { |
|
| 867 | + foreach ( $filelist as $filename => $fileinfo ) { |
|
| 868 | + |
|
| 869 | + if ( 'd' === $fileinfo['type'] ) { |
|
| 870 | + $return = $this->rmdir( $abs_path . $filename, $recursive ); |
|
| 871 | + } else { |
|
| 872 | + $return = $this->unlink( $abs_path . $filename ); |
|
| 873 | + } |
|
| 874 | + } |
|
| 875 | + } |
|
| 876 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions |
|
| 877 | + if ( file_exists( $abs_path ) && ! @rmdir( $abs_path ) ) { |
|
| 878 | + $return = false; |
|
| 879 | + } |
|
| 880 | + } |
|
| 881 | + |
|
| 882 | + if ( ! $return && $this->use_filesystem ) { |
|
| 883 | + $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 884 | + |
|
| 885 | + return $this->wp_filesystem->rmdir( $abs_path, $recursive ); |
|
| 886 | + } |
|
| 887 | + |
|
| 888 | + return $return; |
|
| 889 | + } |
|
| 890 | + |
|
| 891 | + /** |
|
| 892 | + * Get a list of files/folders under the specified directory. |
|
| 893 | + * |
|
| 894 | + * @param string $abs_path Absolute path. |
|
| 895 | + * @param bool $include_hidden Include hidden files, defaults to true. |
|
| 896 | + * @param bool $recursive Recursive search, defaults to false. |
|
| 897 | + * |
|
| 898 | + * @return array|bool |
|
| 899 | + */ |
|
| 900 | + public function scandir( string $abs_path, bool $include_hidden = true, bool $recursive = false ) { |
|
| 901 | + if ( $this->is_file( $abs_path ) ) { |
|
| 902 | + $limit_file = basename( $abs_path ); |
|
| 903 | + $abs_path = dirname( $abs_path ); |
|
| 904 | + } else { |
|
| 905 | + $limit_file = false; |
|
| 906 | + } |
|
| 907 | + |
|
| 908 | + if ( ! $this->is_dir( $abs_path ) || ! $this->is_readable( $abs_path ) ) { |
|
| 909 | + return false; |
|
| 910 | + } |
|
| 911 | + |
|
| 912 | + $dir = dir( $abs_path ); |
|
| 913 | + |
|
| 914 | + if ( false === $dir ) { |
|
| 915 | + if ( $this->use_filesystem ) { |
|
| 916 | + $abs_path = $this->get_sanitized_path( $abs_path ); |
|
| 917 | + |
|
| 918 | + return $this->wp_filesystem->dirlist( $abs_path, $include_hidden, $recursive ); |
|
| 919 | + } |
|
| 920 | + |
|
| 921 | + return false; |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + $ret = array(); |
|
| 925 | + |
|
| 926 | + while ( false !== ( $entry = $dir->read() ) ) { |
|
| 927 | + $struc = array(); |
|
| 928 | + $struc['name'] = $entry; |
|
| 929 | + |
|
| 930 | + if ( '.' === $struc['name'] || '..' === $struc['name'] ) { |
|
| 931 | + continue; |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + if ( ! $include_hidden && '.' === $struc['name'][0] ) { |
|
| 935 | + continue; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + if ( $limit_file && $struc['name'] !== $limit_file ) { |
|
| 939 | + continue; |
|
| 940 | + } |
|
| 941 | + |
|
| 942 | + $struc['type'] = $this->is_dir( $abs_path . '/' . $entry ) ? 'd' : 'f'; |
|
| 943 | + |
|
| 944 | + if ( 'd' === $struc['type'] ) { |
|
| 945 | + if ( $recursive ) { |
|
| 946 | + $struc['files'] = $this->scandir( $abs_path . '/' . $struc['name'], $include_hidden, $recursive ); |
|
| 947 | + } else { |
|
| 948 | + $struc['files'] = array(); |
|
| 949 | + } |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + $ret[ $struc['name'] ] = $struc; |
|
| 953 | + } |
|
| 954 | + |
|
| 955 | + $dir->close(); |
|
| 956 | + |
|
| 957 | + unset( $dir ); |
|
| 958 | + |
|
| 959 | + return $ret; |
|
| 960 | + } |
|
| 961 | + |
|
| 962 | + /** |
|
| 963 | + * Light wrapper for move_uploaded_file with chmod. |
|
| 964 | + * |
|
| 965 | + * @param string $file Source file. |
|
| 966 | + * @param string $destination File destination. |
|
| 967 | + * @param int|null $perms Permission value. |
|
| 968 | + * |
|
| 969 | + * @return bool |
|
| 970 | + */ |
|
| 971 | + public function move_uploaded_file( string $file, string $destination, ?int $perms = null ): bool { |
|
| 972 | + // TODO: look into replicating more functionality from wp_handle_upload(). |
|
| 973 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors |
|
| 974 | + $return = @move_uploaded_file( $file, $destination ); |
|
| 975 | + |
|
| 976 | + if ( $return ) { |
|
| 977 | + $this->chmod( $destination, $perms ); |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + return $return; |
|
| 981 | + } |
|
| 982 | + |
|
| 983 | + /** |
|
| 984 | + * Copy a file. |
|
| 985 | + * |
|
| 986 | + * @param string $source_abs_path Source path. |
|
| 987 | + * @param string $destination_abs_path Destination path. |
|
| 988 | + * @param bool $overwrite Overwrite file. |
|
| 989 | + * @param mixed $perms Permission value. |
|
| 990 | + * @return bool |
|
| 991 | + * Taken from WP_Filesystem_Direct |
|
| 992 | + */ |
|
| 993 | + public function copy( string $source_abs_path, string $destination_abs_path, bool $overwrite = true, $perms = false ): bool { |
|
| 994 | + |
|
| 995 | + // Error if source file doesn't exist. |
|
| 996 | + if ( ! $this->file_exists( $source_abs_path ) ) { |
|
| 997 | + return false; |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + if ( ! $overwrite && $this->file_exists( $destination_abs_path ) ) { |
|
| 1001 | + return false; |
|
| 1002 | + } |
|
| 1003 | + if ( ! $this->is_dir( dirname( $destination_abs_path ) ) ) { |
|
| 1004 | + $this->mkdir( dirname( $destination_abs_path ) ); |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + // phpcs:ignore WordPress.PHP.NoSilencedErrors |
|
| 1008 | + $return = @copy( $source_abs_path, $destination_abs_path ); |
|
| 1009 | + if ( $perms && $return ) { |
|
| 1010 | + $this->chmod( $destination_abs_path, $perms ); |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + if ( ! $return && $this->use_filesystem ) { |
|
| 1014 | + $source_abs_path = $this->get_sanitized_path( $source_abs_path ); |
|
| 1015 | + $destination_abs_path = $this->get_sanitized_path( $destination_abs_path ); |
|
| 1016 | + $return = $this->wp_filesystem->copy( |
|
| 1017 | + $source_abs_path, |
|
| 1018 | + $destination_abs_path, |
|
| 1019 | + $overwrite, |
|
| 1020 | + $perms |
|
| 1021 | + ); |
|
| 1022 | + } |
|
| 1023 | + |
|
| 1024 | + return $return; |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + /** |
|
| 1028 | + * Move a file. |
|
| 1029 | + * |
|
| 1030 | + * @param string $source_abs_path Source absolute path. |
|
| 1031 | + * @param string $destination_abs_path Destination absolute path. |
|
| 1032 | + * @param bool $overwrite Overwrite if file exists. |
|
| 1033 | + * @return bool |
|
| 1034 | + */ |
|
| 1035 | + public function move( string $source_abs_path, string $destination_abs_path, bool $overwrite = true ): bool { |
|
| 1036 | + |
|
| 1037 | + // Error if source file doesn't exist. |
|
| 1038 | + if ( ! $this->file_exists( $source_abs_path ) ) { |
|
| 1039 | + return false; |
|
| 1040 | + } |
|
| 1041 | + |
|
| 1042 | + // Try using rename first. |
|
| 1043 | + // If that fails (for example, the source is read only) try copy. |
|
| 1044 | + // Taken in part from WP_Filesystem_Direct. |
|
| 1045 | + if ( ! $overwrite && $this->file_exists( $destination_abs_path ) ) { |
|
| 1046 | + return false; |
|
| 1047 | + } elseif ( @rename( $source_abs_path, $destination_abs_path ) ) { // phpcs:ignore WordPress.PHP.NoSilencedErrors, WordPress.WP.AlternativeFunctions |
|
| 1048 | + return true; |
|
| 1049 | + } elseif ( $this->copy( $source_abs_path, $destination_abs_path, $overwrite ) && $this->file_exists( |
|
| 1050 | + $destination_abs_path |
|
| 1051 | + ) ) { |
|
| 1052 | + |
|
| 1053 | + $this->unlink( $source_abs_path ); |
|
| 1054 | + |
|
| 1055 | + return true; |
|
| 1056 | + } else { |
|
| 1057 | + $return = false; |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + if ( $this->use_filesystem ) { |
|
| 1061 | + $source_abs_path = $this->get_sanitized_path( $source_abs_path ); |
|
| 1062 | + $destination_abs_path = $this->get_sanitized_path( $destination_abs_path ); |
|
| 1063 | + |
|
| 1064 | + $return = $this->wp_filesystem->move( $source_abs_path, $destination_abs_path, $overwrite ); |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + return $return; |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + /** |
|
| 1071 | + * Shim: get_template. |
|
| 1072 | + * |
|
| 1073 | + * @param string $file Template name. |
|
| 1074 | + * |
|
| 1075 | + * @return void Path to template file. |
|
| 1076 | + */ |
|
| 1077 | + public function get_template( string $file ) { |
|
| 1078 | + $panel = new Redux_Panel( $this ); |
|
| 1079 | + $panel->get_template( $file ); |
|
| 1080 | + } |
|
| 1081 | + } |
|
| 1082 | + |
|
| 1083 | + Redux_Filesystem::get_instance(); |
|
| 1084 | 1084 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $current_data_args_key = md5( maybe_serialize( $current_data_args ) ); |
| 94 | 94 | |
| 95 | 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 ); |
|
| 96 | + $current_data = $this->wp_data[$type . $current_data_args_key] ?? $this->get_data( $type, $current_data_args, $current_value ); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // If ajax is enabled AND $current_data is empty, set a dummy value for the init. |
@@ -112,8 +112,8 @@ discard block |
||
| 112 | 112 | $args_key = md5( maybe_serialize( $args ) ); |
| 113 | 113 | |
| 114 | 114 | // Data caching. |
| 115 | - if ( isset( $this->wp_data[ $type . $args_key ] ) ) { |
|
| 116 | - $data = $this->wp_data[ $type . $args_key ]; |
|
| 115 | + if ( isset( $this->wp_data[$type . $args_key] ) ) { |
|
| 116 | + $data = $this->wp_data[$type . $args_key]; |
|
| 117 | 117 | } else { |
| 118 | 118 | /** |
| 119 | 119 | * Use data from WordPress to populate an option array. |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | if ( ! empty( $data ) ) { |
| 129 | 129 | $data = $this->order_data( $data, $data_sort, $data_order ); |
| 130 | - $this->wp_data[ $type . $args_key ] = $data; |
|
| 130 | + $this->wp_data[$type . $args_key] = $data; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | if ( is_object( $v ) ) { |
| 163 | 163 | $key = $v->$id_key; |
| 164 | 164 | } elseif ( is_array( $v ) ) { |
| 165 | - $key = $v[ $id_key ]; |
|
| 165 | + $key = $v[$id_key]; |
|
| 166 | 166 | } else { |
| 167 | 167 | $key = $k; |
| 168 | 168 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | if ( is_object( $v ) ) { |
| 175 | 175 | $value = $v->$name_key; |
| 176 | 176 | } elseif ( is_array( $v ) ) { |
| 177 | - $value = $v[ $name_key ]; |
|
| 177 | + $value = $v[$name_key]; |
|
| 178 | 178 | } else { |
| 179 | 179 | $value = $v; |
| 180 | 180 | } |
@@ -184,12 +184,12 @@ discard block |
||
| 184 | 184 | |
| 185 | 185 | if ( is_object( $v ) && isset( $v->$secondary_key ) ) { |
| 186 | 186 | $display_key = $v->$secondary_key; |
| 187 | - } elseif ( ! is_object( $v ) && isset( $v[ $secondary_key ] ) ) { |
|
| 188 | - $display_key = $v[ $secondary_key ]; |
|
| 187 | + } elseif ( ! is_object( $v ) && isset( $v[$secondary_key] ) ) { |
|
| 188 | + $display_key = $v[$secondary_key]; |
|
| 189 | 189 | } |
| 190 | - $data[ $key ] = $value; |
|
| 190 | + $data[$key] = $value; |
|
| 191 | 191 | if ( $display_key !== $value && $add_key ) { |
| 192 | - $data[ $key ] = $data[ $key ] . ' [' . $display_key . ']'; |
|
| 192 | + $data[$key] = $data[$key] . ' [' . $display_key . ']'; |
|
| 193 | 193 | } |
| 194 | 194 | } |
| 195 | 195 | } |
@@ -308,14 +308,14 @@ discard block |
||
| 308 | 308 | if ( isset( $sites ) ) { |
| 309 | 309 | $results = array(); |
| 310 | 310 | foreach ( $sites as $site ) { |
| 311 | - $site = (array) $site; |
|
| 311 | + $site = ( array ) $site; |
|
| 312 | 312 | $k = $site['blog_id']; |
| 313 | 313 | $v = $site['domain'] . $site['path']; |
| 314 | 314 | $name = get_blog_option( $k, 'blogname' ); |
| 315 | 315 | if ( ! empty( $name ) ) { |
| 316 | 316 | $v .= ' - [' . $name . ']'; |
| 317 | 317 | } |
| 318 | - $results[ $k ] = $v; |
|
| 318 | + $results[$k] = $v; |
|
| 319 | 319 | } |
| 320 | 320 | $data = $this->process_results( $results, '', '', $display_keys, $secondary_key ); |
| 321 | 321 | } |
@@ -341,10 +341,10 @@ discard block |
||
| 341 | 341 | $post_types = get_post_types( $args, $output, $operator ); |
| 342 | 342 | |
| 343 | 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; |
|
| 344 | + if ( isset( $wp_post_types[$name]->labels->menu_name ) ) { |
|
| 345 | + $data[$name] = $wp_post_types[$name]->labels->menu_name; |
|
| 346 | 346 | } else { |
| 347 | - $data[ $name ] = ucfirst( $name ); |
|
| 347 | + $data[$name] = ucfirst( $name ); |
|
| 348 | 348 | } |
| 349 | 349 | } |
| 350 | 350 | break; |
@@ -353,9 +353,9 @@ discard block |
||
| 353 | 353 | case 'menu_location': |
| 354 | 354 | global $_wp_registered_nav_menus; |
| 355 | 355 | foreach ( $_wp_registered_nav_menus as $k => $v ) { |
| 356 | - $data[ $k ] = $v; |
|
| 356 | + $data[$k] = $v; |
|
| 357 | 357 | if ( ! has_nav_menu( $k ) ) { |
| 358 | - $data[ $k ] .= ' ' . __( '[unassigned]', 'redux-framework' ); |
|
| 358 | + $data[$k] .= ' ' . __( '[unassigned]', 'redux-framework' ); |
|
| 359 | 359 | } |
| 360 | 360 | } |
| 361 | 361 | break; |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | global $_wp_additional_image_sizes; |
| 366 | 366 | $results = array(); |
| 367 | 367 | foreach ( $_wp_additional_image_sizes as $size_name => $size_attrs ) { |
| 368 | - $results[ $size_name ] = $size_name . ' - ' . $size_attrs['width'] . ' x ' . $size_attrs['height']; |
|
| 368 | + $results[$size_name] = $size_name . ' - ' . $size_attrs['width'] . ' x ' . $size_attrs['height']; |
|
| 369 | 369 | } |
| 370 | 370 | $data = $this->process_results( $results, '', '', $display_keys, $secondary_key ); |
| 371 | 371 | |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | if ( 'before' === $item ) { |
| 386 | 386 | continue; |
| 387 | 387 | } |
| 388 | - $data[ 'el el-' . $item ] = $item; |
|
| 388 | + $data['el el-' . $item] = $item; |
|
| 389 | 389 | } |
| 390 | 390 | } |
| 391 | 391 | |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | if ( 'before' === $item ) { |
| 423 | 423 | continue; |
| 424 | 424 | } |
| 425 | - $data[ 'dashicons dashicons-' . $item ] = $item; |
|
| 425 | + $data['dashicons dashicons-' . $item] = $item; |
|
| 426 | 426 | } |
| 427 | 427 | } |
| 428 | 428 | break; |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | $results = array(); |
| 447 | 447 | foreach ( $wp_roles->roles as $role ) { |
| 448 | 448 | foreach ( $role['capabilities'] as $key => $cap ) { |
| 449 | - $results[ $key ] = ucwords( str_replace( '_', ' ', $key ) ); |
|
| 449 | + $results[$key] = ucwords( str_replace( '_', ' ', $key ) ); |
|
| 450 | 450 | } |
| 451 | 451 | } |
| 452 | 452 | $data = $this->process_results( $results, '', '', $display_keys, $secondary_key ); |
@@ -462,10 +462,10 @@ discard block |
||
| 462 | 462 | foreach ( $wp_roles->roles as $role ) { |
| 463 | 463 | $caps = array(); |
| 464 | 464 | foreach ( $role['capabilities'] as $key => $cap ) { |
| 465 | - $caps[ $key ] = ucwords( str_replace( '_', ' ', $key ) ); |
|
| 465 | + $caps[$key] = ucwords( str_replace( '_', ' ', $key ) ); |
|
| 466 | 466 | } |
| 467 | 467 | asort( $caps ); |
| 468 | - $data[ $role['name'] ] = $caps; |
|
| 468 | + $data[$role['name']] = $caps; |
|
| 469 | 469 | } |
| 470 | 470 | |
| 471 | 471 | break; |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | $value = apply_filters( 'wpml_object_id', $value, $post_type, true ); |
| 544 | 544 | } elseif ( is_array( $value ) ) { |
| 545 | 545 | $value = array_map( |
| 546 | - function ( $val ) use ( $post_type ) { |
|
| 546 | + function( $val ) use ( $post_type ) { |
|
| 547 | 547 | return apply_filters( 'wpml_object_id', $val, $post_type, true ); |
| 548 | 548 | }, |
| 549 | 549 | $value |
@@ -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 | } |