Update to Kirki 4.0.22

This commit is contained in:
AlxMedia 2022-03-15 14:29:17 +01:00
parent 2b6ac38550
commit 78edeb1b25
492 changed files with 29668 additions and 39884 deletions

View file

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2019 Kirki Framework
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View file

@ -0,0 +1 @@
# data-option

View file

@ -0,0 +1,181 @@
<?php // phpcs:disable PHPCompatibility.FunctionDeclarations.NewClosure
/**
* Option tweaks.
*
* @package kirki-framework/data-option
* @copyright Copyright (c) 2019, Ari Stathopoulos (@aristath)
* @license https://opensource.org/licenses/MIT
* @since 1.0
*/
namespace Kirki\Data;
/**
* Hooks and tweaks to allow Kirki saving Options instead of theme-mods.
*
* @since 1.0
*/
class Option {
/**
* Constructor.
*
* @access public
* @since 1.0
*/
public function __construct() {
add_filter( 'kirki_field_add_setting_args', [ $this, 'add_setting_args' ], 20, 2 );
add_filter( 'kirki_field_add_control_args', [ $this, 'add_control_args' ], 20, 2 );
add_filter( 'kirki_get_value', [ $this, 'kirki_get_value' ], 10, 4 );
}
/**
* Filters the value for an option.
*
* @access public
* @since 4.0
* @param mixed $value The value.
* @param string $option The field-name.
* @param mixed $default The default value.
* @param string $type The option-type (theme_mod, option etc).
* @return mixed Returns the field value.
*/
public function kirki_get_value( $value = '', $option = '', $default = '', $type = 'theme_mod' ) {
if ( 'option' === $type ) {
/**
* If the option doesn't contain a '[', then it's not a sub-item
* of another option. Get the option value and return it.
*/
if ( false === strpos( $option, '[' ) ) {
return get_option( $option, $default );
}
/**
* If we got here then this is part of an option array.
* We need to get the 1st level, and then find the item inside that array.
*/
$parts = \explode( '[', $option );
$value = get_option( $parts[0], [] );
// If there's no value, return the default.
if ( empty( $value ) ) {
return $default;
}
foreach ( $parts as $key => $part ) {
/**
* Skip the 1st item, it's already been dealt with
* when we got the value initially right before this loop.
*/
if ( 0 === $key ) {
continue;
}
$part = str_replace( ']', '', $part );
/**
* If the item exists in the value, then change $value to the item.
* This runs recursively for all parts until we get to the end.
*/
if ( is_array( $value ) && isset( $value[ $part ] ) ) {
$value = $value[ $part ];
continue;
}
/**
* If we got here, the item was not found in the value.
* We need to change the value accordingly depending on whether
* this is the last item in the loop or not.
*/
$value = ( isset( $parts[ $key + 1 ] ) ) ? [] : '';
}
}
return $value;
}
/**
* Allow filtering the arguments.
*
* @since 0.1
* @param array $args The arguments.
* @param WP_Customize_Manager $customizer The customizer instance.
* @return array Return the arguments.
*/
public function add_setting_args( $args, $customizer ) {
// If this is not an option, early exit.
if ( ! isset( $args['option_type'] ) || 'option' !== $args['option_type'] ) {
return $args;
}
// Set "type" argument to option.
$args['type'] = 'option';
return $this->maybe_change_settings( $args );
}
/**
* Allow filtering the arguments.
*
* @since 0.1
* @param array $args The arguments.
* @param WP_Customize_Manager $customizer The customizer instance.
* @return array Return the arguments.
*/
public function add_control_args( $args, $customizer ) {
// If this is not an option, early exit.
if ( ! isset( $args['option_type'] ) || 'option' !== $args['option_type'] ) {
return $args;
}
return $this->maybe_change_settings( $args );
}
/**
* Change the settings argument.
*
* @access private
* @since 1.0
* @param array $args The arguments.
* @return array Returns modified array with tweaks to the [settings] argument if needed.
*/
private function maybe_change_settings( $args ) {
// Check if we have an option-name defined.
if ( isset( $args['option_name'] ) ) {
if ( empty( $args['option_name'] ) ) {
return $args;
}
if ( isset( $args['settings'] ) && $args['settings'] && false !== strpos( $args['settings'], $args['option_name'] . '[' ) ) {
return $args;
}
if ( false === strpos( $args['settings'], '[' ) ) {
// ? Bagus: in line above, it's obvious that '[' is not found in $args['settings']. But why do we explode it using '[' here?
$parts = explode( '[', $args['settings'] );
$final_parts = [ $args['option_name'] ];
foreach ( $parts as $part ) {
$final_parts[] = $part;
}
$args['settings'] = \implode( '][', $final_parts ) . ']';
$args['settings'] = str_replace(
$args['option_name'] . '][',
$args['option_name'] . '[',
$args['settings']
);
}
}
return $args;
}
}