mirror of
https://ghproxy.net/https://github.com/AlxMedia/magaziner.git
synced 2025-08-28 09:43:30 +08:00
Update to Kirki 4.0.22
This commit is contained in:
parent
2b6ac38550
commit
78edeb1b25
492 changed files with 29668 additions and 39884 deletions
21
functions/kirki/packages/kirki-framework/util/LICENSE
Normal file
21
functions/kirki/packages/kirki-framework/util/LICENSE
Normal 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.
|
2
functions/kirki/packages/kirki-framework/util/README.md
Normal file
2
functions/kirki/packages/kirki-framework/util/README.md
Normal file
|
@ -0,0 +1,2 @@
|
|||
# core
|
||||
Kirki Core
|
412
functions/kirki/packages/kirki-framework/util/src/Helper.php
Normal file
412
functions/kirki/packages/kirki-framework/util/src/Helper.php
Normal file
|
@ -0,0 +1,412 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper methods
|
||||
*
|
||||
* @package Kirki
|
||||
* @category Core
|
||||
* @author Ari Stathopoulos (@aristath)
|
||||
* @copyright Copyright (c) 2019, Ari Stathopoulos (@aristath)
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
namespace Kirki\Util;
|
||||
|
||||
// Exit if accessed directly.
|
||||
if ( ! defined( 'ABSPATH' ) ) {
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* A simple object containing static methods.
|
||||
*/
|
||||
class Helper {
|
||||
|
||||
/**
|
||||
* Recursive replace in arrays.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param array $array The first array.
|
||||
* @param array $array1 The second array.
|
||||
* @return mixed
|
||||
*/
|
||||
public static function array_replace_recursive( $array, $array1 ) {
|
||||
if ( function_exists( 'array_replace_recursive' ) ) {
|
||||
return array_replace_recursive( $array, $array1 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the arguments, merge one by one.
|
||||
*
|
||||
* In PHP 7 func_get_args() changed the way it behaves but this doesn't mean anything in this case
|
||||
* since this method is only used when the array_replace_recursive() function doesn't exist
|
||||
* and that was introduced in PHP v5.3.
|
||||
*
|
||||
* Once WordPress-Core raises its minimum requirements we'll be able to remove this fallback completely.
|
||||
*/
|
||||
$args = func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue
|
||||
$array = $args[0];
|
||||
if ( ! is_array( $array ) ) {
|
||||
return $array;
|
||||
}
|
||||
$count = count( $args );
|
||||
for ( $i = 1; $i < $count; $i++ ) {
|
||||
if ( is_array( $args[ $i ] ) ) {
|
||||
$array = self::recurse( $array, $args[ $i ] );
|
||||
}
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method to be used from the array_replace_recursive method.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param array $array The first array.
|
||||
* @param array $array1 The second array.
|
||||
* @return array
|
||||
*/
|
||||
public static function recurse( $array, $array1 ) {
|
||||
foreach ( $array1 as $key => $value ) {
|
||||
|
||||
// Create new key in $array, if it is empty or not an array.
|
||||
if ( ! isset( $array[ $key ] ) || ( isset( $array[ $key ] ) && ! is_array( $array[ $key ] ) ) ) {
|
||||
$array[ $key ] = [];
|
||||
}
|
||||
|
||||
// Overwrite the value in the base array.
|
||||
if ( is_array( $value ) ) {
|
||||
$value = self::recurse( $array[ $key ], $value );
|
||||
}
|
||||
$array[ $key ] = $value;
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the WP_Filesystem.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return object WP_Filesystem
|
||||
*/
|
||||
public static function init_filesystem() {
|
||||
$credentials = [];
|
||||
|
||||
if ( ! defined( 'FS_METHOD' ) ) {
|
||||
define( 'FS_METHOD', 'direct' );
|
||||
}
|
||||
|
||||
$method = defined( 'FS_METHOD' ) ? FS_METHOD : false;
|
||||
|
||||
if ( 'ftpext' === $method ) {
|
||||
// If defined, set it to that, Else, set to NULL.
|
||||
$credentials['hostname'] = defined( 'FTP_HOST' ) ? preg_replace( '|\w+://|', '', FTP_HOST ) : null;
|
||||
$credentials['username'] = defined( 'FTP_USER' ) ? FTP_USER : null;
|
||||
$credentials['password'] = defined( 'FTP_PASS' ) ? FTP_PASS : null;
|
||||
|
||||
// Set FTP port.
|
||||
if ( strpos( $credentials['hostname'], ':' ) && null !== $credentials['hostname'] ) {
|
||||
list( $credentials['hostname'], $credentials['port'] ) = explode( ':', $credentials['hostname'], 2 );
|
||||
if ( ! is_numeric( $credentials['port'] ) ) {
|
||||
unset( $credentials['port'] );
|
||||
}
|
||||
} else {
|
||||
unset( $credentials['port'] );
|
||||
}
|
||||
|
||||
// Set connection type.
|
||||
if ( ( defined( 'FTP_SSL' ) && FTP_SSL ) && 'ftpext' === $method ) {
|
||||
$credentials['connection_type'] = 'ftps';
|
||||
} elseif ( ! array_filter( $credentials ) ) {
|
||||
$credentials['connection_type'] = null;
|
||||
} else {
|
||||
$credentials['connection_type'] = 'ftp';
|
||||
}
|
||||
}
|
||||
|
||||
// The WordPress filesystem.
|
||||
global $wp_filesystem;
|
||||
|
||||
if ( empty( $wp_filesystem ) ) {
|
||||
require_once wp_normalize_path( ABSPATH . '/wp-admin/includes/file.php' ); // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude
|
||||
WP_Filesystem( $credentials );
|
||||
}
|
||||
|
||||
return $wp_filesystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the attachment object.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @see https://pippinsplugins.com/retrieve-attachment-id-from-image-url/
|
||||
* @param string $url URL to the image.
|
||||
* @return int|string Numeric ID of the attachement.
|
||||
*/
|
||||
public static function get_image_id( $url ) {
|
||||
global $wpdb;
|
||||
if ( empty( $url ) ) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$attachment = wp_cache_get( 'kirki_image_id_' . md5( $url ), null );
|
||||
if ( false === $attachment ) {
|
||||
$attachment = $wpdb->get_col( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE guid = %s;", $url ) ); // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery
|
||||
wp_cache_add( 'kirki_image_id_' . md5( $url ), $attachment, null );
|
||||
}
|
||||
|
||||
if ( ! empty( $attachment ) ) {
|
||||
return $attachment[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of the attachment's properties.
|
||||
*
|
||||
* @param string $url URL to the image.
|
||||
* @return array
|
||||
*/
|
||||
public static function get_image_from_url( $url ) {
|
||||
$image_id = self::get_image_id( $url );
|
||||
$image = wp_get_attachment_image_src( $image_id, 'full' );
|
||||
|
||||
return [
|
||||
'url' => $image[0],
|
||||
'width' => $image[1],
|
||||
'height' => $image[2],
|
||||
'thumbnail' => $image[3],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of posts.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param array $args Define arguments for the get_posts function.
|
||||
* @return array
|
||||
*/
|
||||
public static function get_posts( $args ) {
|
||||
if ( is_string( $args ) ) {
|
||||
$args = add_query_arg(
|
||||
[
|
||||
'suppress_filters' => false,
|
||||
]
|
||||
);
|
||||
} elseif ( is_array( $args ) && ! isset( $args['suppress_filters'] ) ) {
|
||||
$args['suppress_filters'] = false;
|
||||
}
|
||||
|
||||
// Get the posts.
|
||||
// TODO: WordPress.VIP.RestrictedFunctions.get_posts_get_posts.
|
||||
$posts = get_posts( $args );
|
||||
|
||||
// Properly format the array.
|
||||
$items = [];
|
||||
foreach ( $posts as $post ) {
|
||||
$items[ $post->ID ] = $post->post_title;
|
||||
}
|
||||
wp_reset_postdata();
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of publicly-querable taxonomies.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public static function get_taxonomies() {
|
||||
$items = [];
|
||||
|
||||
// Get the taxonomies.
|
||||
$taxonomies = get_taxonomies(
|
||||
[
|
||||
'public' => true,
|
||||
]
|
||||
);
|
||||
|
||||
// Build the array.
|
||||
foreach ( $taxonomies as $taxonomy ) {
|
||||
$id = $taxonomy;
|
||||
$taxonomy = get_taxonomy( $taxonomy );
|
||||
$items[ $id ] = $taxonomy->labels->name;
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of publicly-querable post-types.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public static function get_post_types() {
|
||||
$items = [];
|
||||
|
||||
// Get the post types.
|
||||
$post_types = get_post_types(
|
||||
[
|
||||
'public' => true,
|
||||
],
|
||||
'objects'
|
||||
);
|
||||
|
||||
// Build the array.
|
||||
foreach ( $post_types as $post_type ) {
|
||||
$items[ $post_type->name ] = $post_type->labels->name;
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of terms from a taxonomy.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param string|array $taxonomies See https://developer.wordpress.org/reference/functions/get_terms/ for details.
|
||||
* @return array
|
||||
*/
|
||||
public static function get_terms( $taxonomies ) {
|
||||
$items = [];
|
||||
|
||||
// Get the post types.
|
||||
$terms = get_terms( $taxonomies );
|
||||
|
||||
// Build the array.
|
||||
foreach ( $terms as $term ) {
|
||||
$items[ $term->term_id ] = $term->name;
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an array of navigation menus.
|
||||
*
|
||||
* @access public
|
||||
* @param string $value_field The value to be stored in options. Accepted values: id|slug.
|
||||
* @return array
|
||||
*/
|
||||
public static function get_nav_menus( $value_field = 'id' ) {
|
||||
$choices = [];
|
||||
$nav_menus = wp_get_nav_menus();
|
||||
|
||||
foreach ( $nav_menus as $term ) {
|
||||
$choices[ 'slug' === $value_field ? $term->slug : $term->term_id ] = $term->name;
|
||||
}
|
||||
|
||||
return $choices;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets an array of material-design colors.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @param string $context Allows us to get subsets of the palette.
|
||||
* @return array
|
||||
*/
|
||||
public static function get_material_design_colors( $context = 'primary' ) {
|
||||
return \Kirki\Util\MaterialColors::get_colors( $context );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array of all available dashicons.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @return array
|
||||
*/
|
||||
public static function get_dashicons() {
|
||||
if ( class_exists( '\Kirki\Util\Dashicons' ) ) {
|
||||
return \Kirki\Util\Dashicons::get_icons();
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Compares the 2 values given the condition
|
||||
*
|
||||
* @param mixed $value1 The 1st value in the comparison.
|
||||
* @param mixed $value2 The 2nd value in the comparison.
|
||||
* @param string $operator The operator we'll use for the comparison.
|
||||
* @return boolean whether The comparison has succeded (true) or failed (false).
|
||||
*/
|
||||
public static function compare_values( $value1, $value2, $operator ) {
|
||||
if ( '===' === $operator ) {
|
||||
return $value1 === $value2;
|
||||
}
|
||||
if ( '!==' === $operator ) {
|
||||
return $value1 !== $value2;
|
||||
}
|
||||
if ( ( '!=' === $operator || 'not equal' === $operator ) ) {
|
||||
return $value1 != $value2; // phpcs:ignore WordPress.PHP.StrictComparisons
|
||||
}
|
||||
if ( ( '>=' === $operator || 'greater or equal' === $operator || 'equal or greater' === $operator ) ) {
|
||||
return $value2 >= $value1;
|
||||
}
|
||||
if ( ( '<=' === $operator || 'smaller or equal' === $operator || 'equal or smaller' === $operator ) ) {
|
||||
return $value2 <= $value1;
|
||||
}
|
||||
if ( ( '>' === $operator || 'greater' === $operator ) ) {
|
||||
return $value2 > $value1;
|
||||
}
|
||||
if ( ( '<' === $operator || 'smaller' === $operator ) ) {
|
||||
return $value2 < $value1;
|
||||
}
|
||||
if ( 'contains' === $operator || 'in' === $operator ) {
|
||||
if ( is_array( $value1 ) && is_array( $value2 ) ) {
|
||||
foreach ( $value2 as $val ) {
|
||||
if ( in_array( $val, $value1 ) ) { // phpcs:ignore WordPress.PHP.StrictInArray
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if ( is_array( $value1 ) && ! is_array( $value2 ) ) {
|
||||
return in_array( $value2, $value1 ); // phpcs:ignore WordPress.PHP.StrictInArray
|
||||
}
|
||||
if ( is_array( $value2 ) && ! is_array( $value1 ) ) {
|
||||
return in_array( $value1, $value2 ); // phpcs:ignore WordPress.PHP.StrictInArray
|
||||
}
|
||||
return ( false !== strrpos( $value1, $value2 ) || false !== strpos( $value2, $value1 ) );
|
||||
}
|
||||
if ( 'does not contain' === $operator || 'not in' === $operator ) {
|
||||
return ! self::compare_values( $value1, $value2, $operator );
|
||||
}
|
||||
return $value1 == $value2; // phpcs:ignore WordPress.PHP.StrictComparisons
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepare PHP array to be used as JS object.
|
||||
*
|
||||
* @see See https://developer.wordpress.org/reference/classes/wp_scripts/localize/
|
||||
*
|
||||
* @param array $values The data which can be either a single or multi-dimensional array.
|
||||
* @return array
|
||||
*/
|
||||
public static function prepare_php_array_for_js( $values ) {
|
||||
|
||||
foreach ( $values as $key => $value ) {
|
||||
if ( ! is_scalar( $value ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$values[ $key ] = html_entity_decode( (string) $value, ENT_QUOTES, 'UTF-8' );
|
||||
}
|
||||
|
||||
return $values;
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,109 @@
|
|||
<?php
|
||||
/**
|
||||
* Helper methods for material-design colors.
|
||||
*
|
||||
* @package kirki-framework/control-palette
|
||||
* @author Ari Stathopoulos (@aristath)
|
||||
* @copyright Copyright (c) 2019, Ari Stathopoulos (@aristath)
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
* @since 1.0
|
||||
*/
|
||||
|
||||
namespace Kirki\Util;
|
||||
|
||||
/**
|
||||
* A simple object containing static methods.
|
||||
*
|
||||
* @since 1.0
|
||||
*/
|
||||
class MaterialColors {
|
||||
|
||||
/**
|
||||
* Gets an array of material-design colors.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @since 1.0
|
||||
* @param string $context Allows us to get subsets of the palette.
|
||||
* @return array
|
||||
*/
|
||||
public static function get_colors( $context = 'primary' ) {
|
||||
$colors = [
|
||||
'primary' => [ '#ffffff', '#000000', '#f44336', '#e91e63', '#9c27b0', '#673ab7', '#3f51b5', '#2196f3', '#03a9f4', '#00bcd4', '#009688', '#4caf50', '#8bc34a', '#cddc39', '#ffeb3b', '#ffc107', '#ff9800', '#ff5722', '#795548', '#9e9e9e', '#607d8b' ],
|
||||
'red' => [ '#ffebee', '#ffcdd2', '#ef9a9a', '#e57373', '#ef5350', '#f44336', '#e53935', '#d32f2f', '#c62828', '#b71c1c', '#ff8a80', '#ff5252', '#ff1744', '#d50000' ],
|
||||
'pink' => [ '#fce4ec', '#f8bbd0', '#f48fb1', '#f06292', '#ec407a', '#e91e63', '#d81b60', '#c2185b', '#ad1457', '#880e4f', '#ff80ab', '#ff4081', '#f50057', '#c51162' ],
|
||||
'purple' => [ '#f3e5f5', '#e1bee7', '#ce93d8', '#ba68c8', '#ab47bc', '#9c27b0', '#8e24aa', '#7b1fa2', '#6a1b9a', '#4a148c', '#ea80fc', '#e040fb', '#d500f9', '#aa00ff' ],
|
||||
'deep-purple' => [ '#ede7f6', '#d1c4e9', '#b39ddb', '#9575cd', '#7e57c2', '#673ab7', '#5e35b1', '#512da8', '#4527a0', '#311b92', '#b388ff', '#7c4dff', '#651fff', '#6200ea' ],
|
||||
'indigo' => [ '#e8eaf6', '#c5cae9', '#9fa8da', '#7986cb', '#5c6bc0', '#3f51b5', '#3949ab', '#303f9f', '#283593', '#1a237e', '#8c9eff', '#536dfe', '#3d5afe', '#304ffe' ],
|
||||
'blue' => [ '#e3f2fd', '#bbdefb', '#90caf9', '#64b5f6', '#42a5f5', '#2196f3', '#1e88e5', '#1976d2', '#1565c0', '#0d47a1', '#82b1ff', '#448aff', '#2979ff', '#2962ff' ],
|
||||
'light-blue' => [ '#e1f5fe', '#b3e5fc', '#81d4fa', '#4fc3f7', '#29b6fc', '#03a9f4', '#039be5', '#0288d1', '#0277bd', '#01579b', '#80d8ff', '#40c4ff', '#00b0ff', '#0091ea' ],
|
||||
'cyan' => [ '#e0f7fa', '#b2ebf2', '#80deea', '#4dd0e1', '#26c6da', '#00bcd4', '#00acc1', '#0097a7', '#00838f', '#006064', '#84ffff', '#18ffff', '#00e5ff', '#00b8d4' ],
|
||||
'teal' => [ '#e0f2f1', '#b2dfdb', '#80cbc4', '#4db6ac', '#26a69a', '#009688', '#00897b', '#00796b', '#00695c', '#004d40', '#a7ffeb', '#64ffda', '#1de9b6', '#00bfa5' ],
|
||||
'green' => [ '#e8f5e9', '#c8e6c9', '#a5d6a7', '#81c784', '#66bb6a', '#4caf50', '#43a047', '#388e3c', '#2e7d32', '#1b5e20', '#b9f6ca', '#69f0ae', '#00e676', '#00c853' ],
|
||||
'light-green' => [ '#f1f8e9', '#dcedc8', '#c5e1a5', '#aed581', '#9ccc65', '#8bc34a', '#7cb342', '#689f38', '#558b2f', '#33691e', '#ccff90', '#b2ff59', '#76ff03', '#64dd17' ],
|
||||
'lime' => [ '#f9fbe7', '#f0f4c3', '#e6ee9c', '#dce775', '#d4e157', '#cddc39', '#c0ca33', '#a4b42b', '#9e9d24', '#827717', '#f4ff81', '#eeff41', '#c6ff00', '#aeea00' ],
|
||||
'yellow' => [ '#fffde7', '#fff9c4', '#fff590', '#fff176', '#ffee58', '#ffeb3b', '#fdd835', '#fbc02d', '#f9a825', '#f57f17', '#ffff82', '#ffff00', '#ffea00', '#ffd600' ],
|
||||
'amber' => [ '#fff8e1', '#ffecb3', '#ffe082', '#ffd54f', '#ffca28', '#ffc107', '#ffb300', '#ffa000', '#ff8f00', '#ff6f00', '#ffe57f', '#ffd740', '#ffc400', '#ffab00' ],
|
||||
'orange' => [ '#fff3e0', '#ffe0b2', '#ffcc80', '#ffb74d', '#ffa726', '#ff9800', '#fb8c00', '#f57c00', '#ef6c00', '#e65100', '#ffd180', '#ffab40', '#ff9100', '#ff6d00' ],
|
||||
'deep-orange' => [ '#fbe9a7', '#ffccbc', '#ffab91', '#ff8a65', '#ff7043', '#ff5722', '#f4511e', '#e64a19', '#d84315', '#bf360c', '#ff9e80', '#ff6e40', '#ff3d00', '#dd2600' ],
|
||||
'brown' => [ '#efebe9', '#d7ccc8', '#bcaaa4', '#a1887f', '#8d6e63', '#795548', '#6d4c41', '#5d4037', '#4e342e', '#3e2723' ],
|
||||
'grey' => [ '#fafafa', '#f5f5f5', '#eeeeee', '#e0e0e0', '#bdbdbd', '#9e9e9e', '#757575', '#616161', '#424242', '#212121', '#000000', '#ffffff' ],
|
||||
'blue-grey' => [ '#eceff1', '#cfd8dc', '#b0bbc5', '#90a4ae', '#78909c', '#607d8b', '#546e7a', '#455a64', '#37474f', '#263238' ],
|
||||
];
|
||||
|
||||
switch ( $context ) {
|
||||
case '50':
|
||||
case '100':
|
||||
case '200':
|
||||
case '300':
|
||||
case '400':
|
||||
case '500':
|
||||
case '600':
|
||||
case '700':
|
||||
case '800':
|
||||
case '900':
|
||||
case 'A100':
|
||||
case 'A200':
|
||||
case 'A400':
|
||||
case 'A700':
|
||||
$key = absint( $context ) / 100;
|
||||
if ( 'A100' === $context ) {
|
||||
$key = 10;
|
||||
unset( $colors['grey'] );
|
||||
} elseif ( 'A200' === $context ) {
|
||||
$key = 11;
|
||||
unset( $colors['grey'] );
|
||||
} elseif ( 'A400' === $context ) {
|
||||
$key = 12;
|
||||
unset( $colors['grey'] );
|
||||
} elseif ( 'A700' === $context ) {
|
||||
$key = 13;
|
||||
unset( $colors['grey'] );
|
||||
}
|
||||
unset( $colors['primary'] );
|
||||
$position_colors = [];
|
||||
foreach ( $colors as $color_family ) {
|
||||
if ( isset( $color_family[ $key ] ) ) {
|
||||
$position_colors[] = $color_family[ $key ];
|
||||
}
|
||||
}
|
||||
return $position_colors;
|
||||
case 'all':
|
||||
unset( $colors['primary'] );
|
||||
$all_colors = [];
|
||||
foreach ( $colors as $color_family ) {
|
||||
foreach ( $color_family as $color ) {
|
||||
$all_colors[] = $color;
|
||||
}
|
||||
}
|
||||
return $all_colors;
|
||||
case 'primary':
|
||||
return $colors['primary'];
|
||||
default:
|
||||
if ( isset( $colors[ $context ] ) ) {
|
||||
return $colors[ $context ];
|
||||
}
|
||||
return $colors['primary'];
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
<?php
|
||||
/**
|
||||
* WordPress Customize Setting classes
|
||||
*
|
||||
* @package Kirki
|
||||
* @subpackage Modules
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
namespace Kirki\Util\Setting;
|
||||
|
||||
/**
|
||||
* Handles saving and sanitizing of user-meta.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @see WP_Customize_Setting
|
||||
*/
|
||||
class Site_Option extends \WP_Customize_Setting {
|
||||
|
||||
/**
|
||||
* Type of customize settings.
|
||||
*
|
||||
* @access public
|
||||
* @since 3.0.0
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'site_option';
|
||||
|
||||
/**
|
||||
* Get the root value for a setting, especially for multidimensional ones.
|
||||
*
|
||||
* @access protected
|
||||
* @since 3.0.0
|
||||
* @param mixed $default Value to return if root does not exist.
|
||||
* @return mixed
|
||||
*/
|
||||
protected function get_root_value( $default = null ) {
|
||||
return get_site_option( $this->id_data['base'], $default );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the root value for a setting, especially for multidimensional ones.
|
||||
*
|
||||
* @access protected
|
||||
* @since 3.0.0
|
||||
* @param mixed $value Value to set as root of multidimensional setting.
|
||||
* @return bool Whether the multidimensional root was updated successfully.
|
||||
*/
|
||||
protected function set_root_value( $value ) {
|
||||
return update_site_option( $this->id_data['base'], $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the value of the setting, using the related API.
|
||||
*
|
||||
* @access protected
|
||||
* @since 3.0.0
|
||||
* @param mixed $value The value to update.
|
||||
* @return bool The result of saving the value.
|
||||
*/
|
||||
protected function update( $value ) {
|
||||
return $this->set_root_value( $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the value of the setting.
|
||||
*
|
||||
* @access protected
|
||||
* @since 3.0.0
|
||||
* @return mixed The value.
|
||||
*/
|
||||
public function value() {
|
||||
return $this->get_root_value( $this->default );
|
||||
}
|
||||
}
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* WordPress Customize Setting classes
|
||||
*
|
||||
* @package Kirki
|
||||
* @subpackage Modules
|
||||
* @since 3.0.0
|
||||
*/
|
||||
|
||||
namespace Kirki\Util\Setting;
|
||||
|
||||
/**
|
||||
* Handles saving and sanitizing of user-meta.
|
||||
*
|
||||
* @since 3.0.0
|
||||
* @see WP_Customize_Setting
|
||||
*/
|
||||
class User_Meta extends \WP_Customize_Setting {
|
||||
|
||||
/**
|
||||
* Type of customize settings.
|
||||
*
|
||||
* @access public
|
||||
* @since 3.0.0
|
||||
* @var string
|
||||
*/
|
||||
public $type = 'user_meta';
|
||||
|
||||
/**
|
||||
* Get the root value for a setting, especially for multidimensional ones.
|
||||
*
|
||||
* @access protected
|
||||
* @since 3.0.0
|
||||
* @param mixed $default Value to return if root does not exist.
|
||||
* @return mixed
|
||||
*/
|
||||
protected function get_root_value( $default = null ) {
|
||||
$id_base = $this->id_data['base'];
|
||||
|
||||
// Get all user-meta.
|
||||
// We'll use this to check if the value is set or not,
|
||||
// in order to figure out if we need to return the default value.
|
||||
$user_meta = get_user_meta( get_current_user_id() );
|
||||
|
||||
// Get the single meta.
|
||||
$single_meta = get_user_meta( get_current_user_id(), $id_base, true );
|
||||
|
||||
if ( isset( $user_meta[ $id_base ] ) ) {
|
||||
return $single_meta;
|
||||
}
|
||||
return $default;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the root value for a setting, especially for multidimensional ones.
|
||||
*
|
||||
* @access protected
|
||||
* @since 3.0.0
|
||||
* @param mixed $value Value to set as root of multidimensional setting.
|
||||
* @return bool Whether the multidimensional root was updated successfully.
|
||||
*/
|
||||
protected function set_root_value( $value ) {
|
||||
$id_base = $this->id_data['base'];
|
||||
|
||||
// First delete the current user-meta.
|
||||
// We're doing this to avoid duplicate entries.
|
||||
delete_user_meta( get_current_user_id(), $id_base );
|
||||
|
||||
// Update the user-meta.
|
||||
return update_user_meta( get_current_user_id(), $id_base, $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the value of the setting, using the related API.
|
||||
*
|
||||
* @access protected
|
||||
* @since 3.0.0
|
||||
* @param mixed $value The value to update.
|
||||
* @return bool The result of saving the value.
|
||||
*/
|
||||
protected function update( $value ) {
|
||||
return $this->set_root_value( $value );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the value of the setting.
|
||||
*
|
||||
* @access protected
|
||||
* @since 3.0.0
|
||||
* @return mixed The value.
|
||||
*/
|
||||
public function value() {
|
||||
return $this->get_root_value( $this->default );
|
||||
}
|
||||
}
|
220
functions/kirki/packages/kirki-framework/util/src/Util.php
Normal file
220
functions/kirki/packages/kirki-framework/util/src/Util.php
Normal file
|
@ -0,0 +1,220 @@
|
|||
<?php
|
||||
/**
|
||||
* A utility class for Kirki.
|
||||
*
|
||||
* @package Kirki
|
||||
* @category Core
|
||||
* @author Ari Stathopoulos (@aristath)
|
||||
* @copyright Copyright (c) 2019, Ari Stathopoulos (@aristath)
|
||||
* @license https://opensource.org/licenses/MIT
|
||||
* @since 3.0.9
|
||||
*/
|
||||
|
||||
namespace Kirki\Util;
|
||||
|
||||
/**
|
||||
* Utility class.
|
||||
*/
|
||||
class Util {
|
||||
|
||||
/**
|
||||
* Fields containing variables.
|
||||
*
|
||||
* @static
|
||||
* @access private
|
||||
* @since 4.0
|
||||
* @var array
|
||||
*/
|
||||
private $variables_fields = [];
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @since 3.0.9
|
||||
* @access public
|
||||
*/
|
||||
public function __construct() {
|
||||
add_filter( 'http_request_args', [ $this, 'http_request' ], 10, 2 );
|
||||
add_action( 'kirki_field_init', [ $this, 'field_init_variables' ], 10, 2 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if Kirki is installed as a plugin.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @since 3.0.0
|
||||
* @return bool
|
||||
*/
|
||||
public static function is_plugin() {
|
||||
$is_plugin = false;
|
||||
if ( ! function_exists( 'get_plugins' ) ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude
|
||||
}
|
||||
|
||||
// Get all plugins.
|
||||
$plugins = get_plugins();
|
||||
$_plugin = '';
|
||||
foreach ( $plugins as $plugin => $args ) {
|
||||
if ( ! $is_plugin && isset( $args['Name'] ) && ( 'Kirki' === $args['Name'] || 'Kirki Toolkit' === $args['Name'] ) ) {
|
||||
$is_plugin = true;
|
||||
$_plugin = $plugin;
|
||||
}
|
||||
}
|
||||
|
||||
// No need to proceed any further if Kirki wasn't found in the list of plugins.
|
||||
if ( ! $is_plugin ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Make sure the is_plugins_loaded function is loaded.
|
||||
include_once ABSPATH . 'wp-admin/includes/plugin.php'; // phpcs:ignore WPThemeReview.CoreFunctionality.FileInclude
|
||||
|
||||
// Extra logic in case the plugin is installed but not activated.
|
||||
if ( $_plugin && is_plugin_inactive( $_plugin ) ) {
|
||||
return false;
|
||||
}
|
||||
return $is_plugin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add fields with variables to self::$variables_fields.
|
||||
*
|
||||
* @access public
|
||||
* @since 4.0
|
||||
* @param array $args The field args.
|
||||
* @param Object $object The field object.
|
||||
* @return void
|
||||
*/
|
||||
public function field_init_variables( $args, $object ) {
|
||||
if ( isset( $args['variables'] ) ) {
|
||||
self::$variables_fields[] = $args;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Build the variables.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @since 3.0.9
|
||||
* @return array Formatted as array( 'variable-name' => value ).
|
||||
*/
|
||||
public static function get_variables() {
|
||||
|
||||
$variables = [];
|
||||
$fields = self::$variables_fields;
|
||||
|
||||
/**
|
||||
* Compatibility with Kirki v3.x API.
|
||||
* If the Kirki class exists, check for fields inside it
|
||||
* and add them to our fields array.
|
||||
*/
|
||||
if ( class_exists( '\Kirki\Compatibility\Kirki' ) ) {
|
||||
$fields = array_merge( \Kirki\Compatibility\Kirki::$fields, $fields );
|
||||
}
|
||||
|
||||
// Loop through all fields.
|
||||
foreach ( $fields as $field ) {
|
||||
|
||||
// Skip if this field doesn't have variables.
|
||||
if ( ! isset( $field['variables'] ) || ! $field['variables'] || empty( $field['variables'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$option_type = ( isset( $field['option_type'] ) ) ? $field['option_type'] : 'theme_mod';
|
||||
$default = ( isset( $field['default'] ) ) ? $field['default'] : '';
|
||||
$value = apply_filters( 'kirki_get_value', get_theme_mod( $field['settings'], $default ), $field['settings'], $default, $option_type );
|
||||
|
||||
// Loop through the array of variables.
|
||||
foreach ( $field['variables'] as $field_variable ) {
|
||||
|
||||
// Is the variable ['name'] defined? If yes, then we can proceed.
|
||||
if ( isset( $field_variable['name'] ) ) {
|
||||
|
||||
// Do we have a callback function defined? If not then set $variable_callback to false.
|
||||
$variable_callback = ( isset( $field_variable['callback'] ) && is_callable( $field_variable['callback'] ) ) ? $field_variable['callback'] : false;
|
||||
|
||||
/**
|
||||
* If we have a variable_callback defined then get the value of the option
|
||||
* and run it through the callback function.
|
||||
* If no callback is defined (false) then just get the value.
|
||||
*/
|
||||
$variables[ $field_variable['name'] ] = $value;
|
||||
if ( $variable_callback ) {
|
||||
$variables[ $field_variable['name'] ] = call_user_func( $field_variable['callback'], $value );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pass the variables through a filter ('kirki_variable') and return the array of variables.
|
||||
return apply_filters( 'kirki_variable', $variables );
|
||||
}
|
||||
|
||||
/**
|
||||
* HTTP Request injection.
|
||||
*
|
||||
* @access public
|
||||
* @since 3.0.0
|
||||
* @param array $request The request params.
|
||||
* @param string $url The request URL.
|
||||
* @return array
|
||||
*/
|
||||
public function http_request( $request = [], $url = '' ) {
|
||||
|
||||
// Early exit if installed as a plugin or not a request to wordpress.org,
|
||||
// or finally if we don't have everything we need.
|
||||
if (
|
||||
self::is_plugin() ||
|
||||
false === strpos( $url, 'wordpress.org' ) || (
|
||||
! isset( $request['body'] ) ||
|
||||
! isset( $request['body']['plugins'] ) ||
|
||||
! isset( $request['body']['translations'] ) ||
|
||||
! isset( $request['body']['locale'] ) ||
|
||||
! isset( $request['body']['all'] )
|
||||
)
|
||||
) {
|
||||
return $request;
|
||||
}
|
||||
|
||||
$plugins = json_decode( $request['body']['plugins'], true );
|
||||
if ( ! isset( $plugins['plugins'] ) ) {
|
||||
return $request;
|
||||
}
|
||||
$exists = false;
|
||||
foreach ( $plugins['plugins'] as $plugin ) {
|
||||
if ( isset( $plugin['Name'] ) && 'Kirki Toolkit' === $plugin['Name'] ) {
|
||||
$exists = true;
|
||||
}
|
||||
}
|
||||
// Inject data.
|
||||
if ( ! $exists && defined( 'KIRKI_PLUGIN_FILE' ) ) {
|
||||
$plugins['plugins']['kirki/kirki.php'] = get_plugin_data( KIRKI_PLUGIN_FILE );
|
||||
}
|
||||
$request['body']['plugins'] = wp_json_encode( $plugins );
|
||||
return $request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the $wp_version.
|
||||
*
|
||||
* @static
|
||||
* @access public
|
||||
* @since 3.0.12
|
||||
* @param string $context Use 'minor' or 'major'.
|
||||
* @return int|string Returns integer when getting the 'major' version.
|
||||
* Returns string when getting the 'minor' version.
|
||||
*/
|
||||
public static function get_wp_version( $context = 'minor' ) {
|
||||
global $wp_version;
|
||||
|
||||
// We only need the major version.
|
||||
if ( 'major' === $context ) {
|
||||
$version_parts = explode( '.', $wp_version );
|
||||
return $version_parts[0];
|
||||
}
|
||||
|
||||
return $wp_version;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue