本文整理汇总了PHP中Kirki::get_instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Kirki::get_instance方法的具体用法?PHP Kirki::get_instance怎么用?PHP Kirki::get_instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Kirki
的用法示例。
在下文中一共展示了Kirki::get_instance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: kirki_get_option
/**
* Get the value of a field.
*/
function kirki_get_option($option = '')
{
// Make sure the class is instanciated
Kirki::get_instance();
// Get the array of all the fields.
$fields = Kirki::fields()->get_all();
// Get the config.
$config = Kirki::config()->get_all();
/**
* If no setting has been defined then return all.
*/
if ('' == $option) {
if ('option' == $config['options_type']) {
$values = array();
foreach ($fields as $field) {
$values[] = get_option($field['settings'], $field['default']);
}
} else {
$values = get_theme_mods();
}
return $values;
}
// If a value has been defined then we proceed.
// Early exit if this option does not exist
if (!isset($fields[$option])) {
return;
}
$option_name = $fields[$option]['settings'];
$default = $fields[$option]['default'];
if ('option' == $config['options_type']) {
$value = get_option($option_name, $default);
} else {
$value = get_theme_mod($option_name, $default);
}
return $value;
}
示例2: define
if (!defined('KIRKI_URL')) {
define('KIRKI_URL', get_template_directory_uri() . '/modules/kirki');
}
// Include the main plugin class
include_once KIRKI_PATH . '/includes/class-kirki.php';
/**
* The Kirki class autoloader.
* Finds the path to a class that we're requiring and includes the file.
*/
function kirki_autoload_classes($class_name)
{
if (0 === stripos($class_name, 'Kirki')) {
$foldername = 0 === stripos($class_name, 'Kirki_Controls_') ? 'controls' : '';
$foldername = 0 === stripos($class_name, 'Kirki_Scripts') ? 'scripts' : $foldername;
$foldername = 0 === stripos($class_name, 'Kirki_Styles') ? 'styles' : $foldername;
$foldername = '' != $foldername ? $foldername . DIRECTORY_SEPARATOR : '';
$class_path = KIRKI_PATH . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . $foldername . 'class-' . strtolower(str_replace('_', '-', $class_name)) . '.php';
if (file_exists($class_path)) {
include $class_path;
}
}
}
// Run the autoloader
spl_autoload_register('kirki_autoload_classes');
// Include helper files
include_once KIRKI_PATH . '/includes/deprecated.php';
include_once KIRKI_PATH . '/includes/sanitize.php';
include_once KIRKI_PATH . '/includes/helpers.php';
// Make sure the class is instanciated
Kirki::get_instance();
示例3: kirki_get_option
/**
* Get the value of a field.
*/
function kirki_get_option($option = '')
{
// Make sure the class is instanciated
Kirki::get_instance();
// Get the array of all the fields.
$fields = Kirki::fields()->get_all();
// Get the config.
$config = Kirki::config()->get_all();
// If we're using options instead of theme_mods,
// then first we'll have to get the array of all options.
if ('option' == $config['options_type']) {
$values = array();
if ('' == $config['option_name']) {
// No option name is defined.
// Each options is saved separately in the db, so we'll manually build the array here.
foreach ($fields as $field) {
$values[$field['settings']] = get_option($field['settings'], $field['default']);
}
} else {
// An option_name has been defined so our options are all saved in an array there.
$values = get_option($config['option_name']);
foreach ($fields as $field) {
if (!isset($values[$field['settings_raw']])) {
$values[$field['settings_raw']] = maybe_unserialize($field['default']);
}
}
}
}
if ('' == $option) {
// No option has been defined so we'll get all options and return an array
// If we're using options then we already have the $values set above.
// All we need here is a fallback for theme_mods
if ('option' != $config['options_type']) {
// We're using theme_mods
$values = get_theme_mods();
}
// Early exit and return the array of all values
return $values;
}
// If a value has been defined then we proceed.
// Early exit if this option does not exist
$field_id = 'option' == $config['options_type'] && '' != $config['option_name'] ? $config['option_name'] . '[' . $option . ']' : $option;
if (!isset($fields[$field_id])) {
return;
}
if ('option' == $config['options_type']) {
// We're using options instead of theme_mods.
// We already have the array of values set from above so we'll use that.
$value = isset($values[$option]) ? $values[$option] : $fields[$option]['default'];
} else {
// We're using theme_mods
$value = get_theme_mod($option, $fields[$option]['default']);
}
// Combine background options to a single array
if ('background' == $fields[$field_id]['type']) {
if ('option' == $config['options_type']) {
$value = array('background-color' => isset($values[$option . '_color']) ? $values[$option . '_color'] : null, 'background-repeat' => isset($values[$option . '_repeat']) ? $values[$option . '_repeat'] : null, 'background-attachment' => isset($values[$option . '_attach']) ? $values[$option . '_attach'] : null, 'background-image' => isset($values[$option . '_image']) ? $values[$option . '_image'] : null, 'background-position' => isset($values[$option . '_position']) ? $values[$option . '_position'] : null, 'background-clip' => isset($values[$option . '_clip']) ? $values[$option . '_clip'] : null, 'background-size' => isset($values[$option . '_size']) ? $values[$option . '_size'] : null);
} else {
$value = array('background-color' => isset($fields[$field_id]['default']['color']) ? get_theme_mod($option . '_color', $fields[$field_id]['default']['color']) : null, 'background-repeat' => isset($fields[$field_id]['default']['repeat']) ? get_theme_mod($option . '_repeat', $fields[$field_id]['default']['repeat']) : null, 'background-attachment' => isset($fields[$field_id]['default']['attach']) ? get_theme_mod($option . '_attach', $fields[$field_id]['default']['attach']) : null, 'background-image' => isset($fields[$field_id]['default']['image']) ? get_theme_mod($option . '_image', $fields[$field_id]['default']['image']) : null, 'background-position' => isset($fields[$field_id]['default']['position']) ? get_theme_mod($option . '_position', $fields[$field_id]['default']['position']) : null, 'background-clip' => isset($fields[$field_id]['default']['clip']) ? get_theme_mod($option . '_clip', $fields[$field_id]['default']['clip']) : null, 'background-size' => isset($fields[$field_id]['default']['size']) ? get_theme_mod($option . '_size', $fields[$field_id]['default']['size']) : null);
}
}
// Return the single value.
// Pass it through maybe_unserialize so we're sure we get a proper value.
return maybe_unserialize($value);
}