wordpress option.php,wordpress函数delete_option()用法示例

delete_option( string $option )

Removes option by name. Prevents removal of protected WordPress options.

描述

参数

$option

(string)

(Required)

Name of option to remove. Expected to not be SQL-escaped.

返回值

(bool) True, if option is successfully deleted. False on failure.

源代码

File: wp-includes/option.php

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;

/**

* Fires immediately before an option is deleted.

*

* @since 2.9.0

*

* @param string $option Name of the option to delete.

*/

do_action( 'delete_option', $option );

$result = $wpdb->delete( $wpdb->options, array( 'option_name' => $option ) );

if ( ! 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 ) {

/**

* Fires after a specific option has been deleted.

*

* The dynamic portion of the hook name, `$option`, refers to the option name.

*

* @since 3.0.0

*

* @param string $option Name of the deleted option.

*/

do_action( "delete_option_{$option}", $option );

/**

* Fires after an option has been deleted.

*

* @since 2.9.0

*

* @param string $option Name of the deleted option.

*/

do_action( 'deleted_option', $option );

return true;

}

return false;

}

更新日志

Version

描述

1.2.0

Introduced.

相关函数

Uses

wp-includes/load.php:

wp_installing()

wp-includes/cache.php:

wp_cache_set()

wp-includes/cache.php:

wp_cache_delete()

wp-includes/plugin.php:

do_action()

wp-includes/option.php:

wp_load_alloptions()

wp-includes/option.php:

delete_option

wp-includes/option.php:

delete_option_{$option}

wp-includes/option.php:

deleted_option

wp-includes/option.php:

wp_protect_special_option()

wp-includes/wp-db.php:

wpdb::get_row()

wp-includes/wp-db.php:

wpdb::delete()

wp-includes/wp-db.php:

wpdb::prepare()

Show 7 more uses

Hide more uses

Used By

wp-includes/rest-api/endpoints/class-wp-rest-settings-controller.php:

WP_REST_Settings_Controller::update_item()

wp-admin/includes/class-wp-upgrader.php:

WP_Upgrader::release_lock()

wp-includes/option.php:

delete_network_option()

wp-includes/taxonomy.php:

_wp_batch_split_terms()

wp-admin/includes/class-wp-site-icon.php:

WP_Site_Icon::delete_attachment_data()

wp-admin/includes/misc.php:

update_home_siteurl()

wp-admin/includes/schema.php:

populate_options()

wp-admin/includes/update-core.php:

update_core()

wp-includes/theme.php:

remove_theme_mods()

wp-includes/theme.php:

switch_theme()

wp-includes/theme.php:

get_theme_mods()

wp-includes/class-wp-theme.php:

WP_Theme::get_allowed_on_site()

wp-includes/taxonomy.php:

clean_term_cache()

wp-includes/option.php:

get_transient()

wp-includes/option.php:

set_transient()

wp-includes/option.php:

delete_transient()

wp-includes/post.php:

_reset_front_page_settings_for_post()

wp-includes/revision.php:

_wp_upgrade_revisions_of_post()

wp-includes/ms-functions.php:

maybe_add_existing_user_to_blog()

wp-includes/ms-blogs.php:

delete_blog_option()

Show 15 more used by

Hide more used by

User Contributed Notes

Skip to note content

You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note

Contributed by Codex

Delete a single option

This will delete ‘my_option’ from the options table within your MySQL database.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值