返回介绍

delete_option()

发布于 2017-09-10 22:06:20 字数 5180 浏览 1058 评论 0 收藏 0

delete_option( string $option )

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


description


参数

$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;
}

更新日志

Versiondescription
1.2.0Introduced.

相关函数

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

  1. 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.

    
    <?php delete_option( 'my_option' ); ?>
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文