本文整理汇总了PHP中wp_protect_special_option函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_protect_special_option函数的具体用法?PHP wp_protect_special_option怎么用?PHP wp_protect_special_option使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_protect_special_option函数的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: update_site_option
/**
* Update the value of a site option that was already added.
*
* @see update_option()
* @since 2.8.0
* @package WordPress
* @subpackage Option
*
* @uses apply_filters() Calls 'pre_update_site_option_$option' hook to allow overwriting the
* option value to be stored.
* @uses do_action() Calls 'update_site_option_$option' and 'update_site_option' hooks on success.
*
* @param string $option Name of option. Expected to not be SQL-escaped.
* @param mixed $value Option value. Expected to not be SQL-escaped.
* @return bool False if value was not updated and true if value was updated.
*/
function update_site_option($option, $value)
{
global $wpdb;
wp_protect_special_option($option);
$old_value = get_site_option($option);
$value = apply_filters('pre_update_site_option_' . $option, $value, $old_value);
if ($value === $old_value) {
return false;
}
if (false === $old_value) {
return add_site_option($option, $value);
}
$notoptions = wp_cache_get('notoptions', 'site-options');
if (is_array($notoptions) && isset($notoptions[$option])) {
unset($notoptions[$option]);
wp_cache_set('notoptions', $notoptions, 'site-options');
}
if (!is_multisite()) {
$result = update_option($option, $value);
} else {
$value = sanitize_option($option, $value);
$serialized_value = maybe_serialize($value);
$result = $wpdb->update($wpdb->sitemeta, array('meta_value' => $serialized_value), array('site_id' => $wpdb->siteid, 'meta_key' => $option));
if ($result) {
$cache_key = "{$wpdb->siteid}:{$option}";
wp_cache_set($cache_key, $value, 'site-options');
}
}
if ($result) {
do_action("update_site_option_{$option}", $option, $value, $old_value);
do_action("update_site_option", $option, $value, $old_value);
return true;
}
return false;
}
示例2: delete_option
/**
* Removes option by name and prevents removal of protected WordPress options.
*
* @package WordPress
* @subpackage Option
* @since 1.2.0
*
* @param string $name Option name to remove.
* @return bool True, if succeed. False, if failure.
*/
function delete_option($name)
{
global $wpdb;
wp_protect_special_option($name);
_delete_option_cache($name);
// Get the ID, if no ID then return
// expected_slashed ($name)
$option = $wpdb->get_row("SELECT option_id, autoload FROM {$wpdb->options} WHERE option_name = '{$name}'");
if (is_null($option) || !$option->option_id) {
return false;
}
// expected_slashed ($name)
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name = '{$name}'");
return true;
}
示例3: update_network_option
/**
* Update the value of a network option that was already added.
*
* @since 4.4.0
*
* @see update_option()
*
* @global wpdb $wpdb
* @global object $current_site
*
* @param string $option Name of option. Expected to not be SQL-escaped.
* @param mixed $value Option value. Expected to not be SQL-escaped.
* @param int|bool $network_id Optional. ID of the network. Defaults to current network ID.
* @return bool False if value was not updated and true if value was updated.
*/
function update_network_option($option, $value, $network_id = false)
{
global $wpdb, $current_site;
$network_id = (int) $network_id;
// Fallback to the current network if a network ID is not specified.
if (!$network_id && is_multisite()) {
$network_id = $current_site->id;
}
wp_protect_special_option($option);
$old_value = get_network_option($option, false, $network_id);
/**
* Filter a specific network option before its value is updated.
*
* The dynamic portion of the hook name, `$option`, refers to the option name.
*
* @since 2.9.0 As 'pre_update_site_option_' . $key
* @since 3.0.0
* @since 4.4.0 The `$option` parameter was added
*
* @param mixed $value New value of the network option.
* @param mixed $old_value Old value of the network option.
* @param string $option Option name.
*/
$value = apply_filters('pre_update_site_option_' . $option, $value, $old_value, $option);
if ($value === $old_value) {
return false;
}
if (false === $old_value) {
return add_network_option($option, $value, $network_id);
}
$notoptions_key = "{$network_id}:notoptions";
$notoptions = wp_cache_get($notoptions_key, 'site-options');
if (is_array($notoptions) && isset($notoptions[$option])) {
unset($notoptions[$option]);
wp_cache_set($notoptions_key, $notoptions, 'site-options');
}
if (!is_multisite()) {
$result = update_option($option, $value);
} else {
$value = sanitize_option($option, $value);
$serialized_value = maybe_serialize($value);
$result = $wpdb->update($wpdb->sitemeta, array('meta_value' => $serialized_value), array('site_id' => $network_id, 'meta_key' => $option));
if ($result) {
$cache_key = "{$network_id}:{$option}";
wp_cache_set($cache_key, $value, 'site-options');
}
}
if ($result) {
/**
* Fires after the value of a specific network option has been successfully updated.
*
* The dynamic portion of the hook name, `$option`, refers to the option name.
*
* @since 2.9.0 As "update_site_option_{$key}"
* @since 3.0.0
*
* @param string $option Name of the network option.
* @param mixed $value Current value of the network option.
* @param mixed $old_value Old value of the network option.
*/
do_action('update_site_option_' . $option, $option, $value, $old_value);
/**
* Fires after the value of a network option has been successfully updated.
*
* @since 3.0.0
*
* @param string $option Name of the network option.
* @param mixed $value Current value of the network option.
* @param mixed $old_value Old value of the network option.
*/
do_action('update_site_option', $option, $value, $old_value);
return true;
}
return false;
}
示例4: delete_option
/**
* Removes option by name. Prevents removal of protected WordPress options.
*
* @package WordPress
* @subpackage Option
* @since 1.2.0
*
* @uses do_action() Calls 'delete_option' hook before option is deleted.
* @uses do_action() Calls 'deleted_option' and 'delete_option_$option' hooks on success.
*
* @param string $option Name of option to remove. Expected to not be SQL-escaped.
* @return bool True, if option is successfully deleted. False on failure.
*/
function delete_option($option)
{
global $wpdb;
$option = trim($option);
if (empty($option)) {
return false;
}
wp_protect_special_option($option);
// Get the ID, if no ID then return
$row = $wpdb->get_row($wpdb->prepare("SELECT autoload FROM {$wpdb->options} WHERE option_name = %s", $option));
if (is_null($row)) {
return false;
}
do_action('delete_option', $option);
$result = $wpdb->delete($wpdb->options, array('option_name' => $option));
if (!defined('WP_INSTALLING')) {
if ('yes' == $row->autoload) {
$alloptions = wp_load_alloptions();
if (is_array($alloptions) && isset($alloptions[$option])) {
unset($alloptions[$option]);
wp_cache_set('alloptions', $alloptions, 'options');
}
} else {
wp_cache_delete($option, 'options');
}
}
if ($result) {
do_action("delete_option_{$option}", $option);
do_action('deleted_option', $option);
return true;
}
return false;
}
示例5: delete_option
function delete_option($name)
{
global $wpdb;
wp_protect_special_option($name);
// Get the ID, if no ID then return
// expected_slashed ($name)
$option = $wpdb->get_row("SELECT option_id, autoload FROM {$wpdb->options} WHERE option_name = '{$name}'");
if (is_null($option) || !$option->option_id) {
return false;
}
// expected_slashed ($name)
$wpdb->query("DELETE FROM {$wpdb->options} WHERE option_name = '{$name}'");
if ('yes' == $option->autoload) {
$alloptions = wp_load_alloptions();
if (isset($alloptions[$name])) {
unset($alloptions[$name]);
wp_cache_set('alloptions', $alloptions, 'options');
}
} else {
wp_cache_delete($name, 'options');
}
return true;
}
示例6: update_site_option
/**
* Update the value of a site option that was already added.
*
* @since 2.8.0
*
* @see update_option()
*
* @global wpdb $wpdb
*
* @param string $option Name of option. Expected to not be SQL-escaped.
* @param mixed $value Option value. Expected to not be SQL-escaped.
* @return bool False if value was not updated and true if value was updated.
*/
function update_site_option($option, $value)
{
global $wpdb;
wp_protect_special_option($option);
$old_value = get_site_option($option);
/**
* Filter a specific site option before its value is updated.
*
* The dynamic portion of the hook name, `$option`, refers to the option name.
*
* @since 2.9.0 As 'pre_update_site_option_' . $key
* @since 3.0.0
*
* @param mixed $value New value of site option.
* @param mixed $old_value Old value of site option.
*/
$value = apply_filters('pre_update_site_option_' . $option, $value, $old_value);
if ($value === $old_value) {
return false;
}
if (false === $old_value) {
return add_site_option($option, $value);
}
$notoptions_key = "{$wpdb->siteid}:notoptions";
$notoptions = wp_cache_get($notoptions_key, 'site-options');
if (is_array($notoptions) && isset($notoptions[$option])) {
unset($notoptions[$option]);
wp_cache_set($notoptions_key, $notoptions, 'site-options');
}
if (!is_multisite()) {
$result = update_option($option, $value);
} else {
$value = sanitize_option($option, $value);
$serialized_value = maybe_serialize($value);
$result = $wpdb->update($wpdb->sitemeta, array('meta_value' => $serialized_value), array('site_id' => $wpdb->siteid, 'meta_key' => $option));
if ($result) {
$cache_key = "{$wpdb->siteid}:{$option}";
wp_cache_set($cache_key, $value, 'site-options');
}
}
if ($result) {
/**
* Fires after the value of a specific site option has been successfully updated.
*
* The dynamic portion of the hook name, `$option`, refers to the option name.
*
* @since 2.9.0 As "update_site_option_{$key}"
* @since 3.0.0
*
* @param string $option Name of site option.
* @param mixed $value Current value of site option.
* @param mixed $old_value Old value of site option.
*/
do_action("update_site_option_{$option}", $option, $value, $old_value);
/**
* Fires after the value of a site option has been successfully updated.
*
* @since 3.0.0
*
* @param string $option Name of site option.
* @param mixed $value Current value of site option.
* @param mixed $old_value Old value of site option.
*/
do_action("update_site_option", $option, $value, $old_value);
return true;
}
return false;
}
示例7: delete_option
function delete_option($name) {
global $wpdb;
wp_protect_special_option($name);
// Get the ID, if no ID then return
$option = $wpdb->get_row("SELECT option_id, autoload FROM $wpdb->options WHERE option_name = '$name'");
if ( !$option->option_id ) return false;
$wpdb->query("DELETE FROM $wpdb->options WHERE option_name = '$name'");
if ( 'yes' == $option->autoload ) {
$alloptions = wp_load_alloptions();
if ( isset($alloptions[$name]) ) {
unset($alloptions[$name]);
wp_cache_set('alloptions', $alloptions, 'options');
}
} else {
wp_cache_delete($name, 'options');
}
return true;
}
示例8: delete_global_option
function delete_global_option($option)
{
global $wpdb;
$option = trim($option);
if (empty($option)) {
return false;
}
wp_protect_special_option($option);
// Get the ID, if no ID then return
$row = $wpdb->get_row($wpdb->prepare("SELECT autoload FROM {$wpdb->global_options} WHERE option_name = %s", $option));
if (is_null($row)) {
return false;
}
/**
* Fires immediately before a global option is deleted.
*
* The dynamic portion of the hook name, `$option`, refers to the option name.
*
* @since 1.0.0
*
* @param string $option Name of the option to delete.
*/
do_action('pre_delete_global_option_' . $option, $option);
if (!is_multinetwork()) {
$result = delete_network_option(null, $option);
} else {
$result = $wpdb->delete($wpdb->global_options, array('option_name' => $option));
if (!wp_installing()) {
if ('yes' == $row->autoload) {
$alloptions = wp_load_global_alloptions();
if (is_array($alloptions) && isset($alloptions[$option])) {
unset($alloptions[$option]);
wp_cache_set('alloptions', $alloptions, 'global-options');
}
} else {
wp_cache_delete($option, 'global-options');
}
}
}
if ($result) {
/**
* Fires after a specific global option has been deleted.
*
* The dynamic portion of the hook name, `$option`, refers to the option name.
*
* @since 1.0.0
*
* @param string $option Name of the deleted option.
*/
do_action("delete_global_option_{$option}", $option);
/**
* Fires after a global option has been deleted.
*
* @since 1.0.0
*
* @param string $option Name of the deleted option.
*/
do_action('deleted_global_option', $option);
return true;
}
return false;
}
示例9: update_network_option
/**
* Update the value of a network option that was already added.
*
* @since 4.4.0
*
* @see update_option()
*
* @global wpdb $wpdb
* @global object $current_site
*
* @param int $network_id ID of the network. Can be null to default to the current network ID.
* @param string $option Name of option. Expected to not be SQL-escaped.
* @param mixed $value Option value. Expected to not be SQL-escaped.
* @return bool False if value was not updated and true if value was updated.
*/
function update_network_option($network_id, $option, $value)
{
global $wpdb, $current_site;
if ($network_id && !is_numeric($network_id)) {
return false;
}
$network_id = (int) $network_id;
wp_protect_special_option($option);
$old_value = get_network_option($network_id, $option, false);
/**
* Filter a specific network option before its value is updated.
*
* The dynamic portion of the hook name, `$option`, refers to the option name.
*
* @since 2.9.0 As 'pre_update_site_option_' . $key
* @since 3.0.0
* @since 4.4.0 The `$option` parameter was added
*
* @param mixed $value New value of the network option.
* @param mixed $old_value Old value of the network option.
* @param string $option Option name.
*/
$value = apply_filters('pre_update_site_option_' . $option, $value, $old_value, $option);
if ($value === $old_value) {
return false;
}
if (false === $old_value) {
return add_network_option($network_id, $option, $value);
}
$notoptions_key = "{$network_id}:notoptions";
$notoptions = wp_cache_get($notoptions_key, 'site-options');
if (is_array($notoptions) && isset($notoptions[$option])) {
unset($notoptions[$option]);
wp_cache_set($notoptions_key, $notoptions, 'site-options');
}
$result = update_option($option, $value);
if ($result) {
/**
* Fires after the value of a specific network option has been successfully updated.
*
* The dynamic portion of the hook name, `$option`, refers to the option name.
*
* @since 2.9.0 As "update_site_option_{$key}"
* @since 3.0.0
*
* @param string $option Name of the network option.
* @param mixed $value Current value of the network option.
* @param mixed $old_value Old value of the network option.
*/
do_action('update_site_option_' . $option, $option, $value, $old_value);
/**
* Fires after the value of a network option has been successfully updated.
*
* @since 3.0.0
*
* @param string $option Name of the network option.
* @param mixed $value Current value of the network option.
* @param mixed $old_value Old value of the network option.
*/
do_action('update_site_option', $option, $value, $old_value);
return true;
}
return false;
}