delete_metadata_by_mid() - WordPress 函数参考中文文档

返回介绍

delete_metadata_by_mid()

发布于 2017-09-10 字数4541 浏览 1041 评论 0

delete_metadata_by_mid( string $meta_type,  int $meta_id )

Delete meta data by meta ID


描述


参数

$meta_type

(string)
(Required)
Type of object metadata is for (e.g., comment, post, term, or user).

$meta_id

(int)
(Required)
ID for a specific meta row


返回值

(bool) True on successful delete, false on failure.


源代码

File: wp-includes/meta.php

function delete_metadata_by_mid( $meta_type, $meta_id ) {
	global $wpdb;

	// Make sure everything is valid.
	if ( ! $meta_type || ! is_numeric( $meta_id ) || floor( $meta_id ) != $meta_id ) {
		return false;
	}

	$meta_id = intval( $meta_id );
	if ( $meta_id <= 0 ) {
		return false;
	}

	$table = _get_meta_table( $meta_type );
	if ( ! $table ) {
		return false;
	}

	// object and id columns
	$column = sanitize_key($meta_type . '_id');
	$id_column = 'user' == $meta_type ? 'umeta_id' : 'meta_id';

	// Fetch the meta and go on if it's found.
	if ( $meta = get_metadata_by_mid( $meta_type, $meta_id ) ) {
		$object_id = $meta->{$column};

		/** This action is documented in wp-includes/meta.php */
		do_action( "delete_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );

		// Old-style action.
		if ( 'post' == $meta_type || 'comment' == $meta_type ) {
			/**
			 * Fires immediately before deleting post or comment metadata of a specific type.
			 *
			 * The dynamic portion of the hook, `$meta_type`, refers to the meta
			 * object type (post or comment).
			 *
			 * @since 3.4.0
			 *
			 * @param int $meta_id ID of the metadata entry to delete.
			 */
			do_action( "delete_{$meta_type}meta", $meta_id );
		}

		// Run the query, will return true if deleted, false otherwise
		$result = (bool) $wpdb->delete( $table, array( $id_column => $meta_id ) );

		// Clear the caches.
		wp_cache_delete($object_id, $meta_type . '_meta');

		/** This action is documented in wp-includes/meta.php */
		do_action( "deleted_{$meta_type}_meta", (array) $meta_id, $object_id, $meta->meta_key, $meta->meta_value );

		// Old-style action.
		if ( 'post' == $meta_type || 'comment' == $meta_type ) {
			/**
			 * Fires immediately after deleting post or comment metadata of a specific type.
			 *
			 * The dynamic portion of the hook, `$meta_type`, refers to the meta
			 * object type (post or comment).
			 *
			 * @since 3.4.0
			 *
			 * @param int $meta_ids Deleted metadata entry ID.
			 */
			do_action( "deleted_{$meta_type}meta", $meta_id );
		}

		return $result;

	}

	// Meta id was not found.
	return false;
}

更新日志

Version 描述
3.3.0 Introduced.

相关函数

Uses

  • wp-includes/cache.php:
    wp_cache_delete()
  • wp-includes/formatting.php:
    sanitize_key()
  • wp-includes/plugin.php:
    do_action()
  • wp-includes/wp-db.php:
    wpdb::delete()
  • wp-includes/meta.php:
    _get_meta_table()
  • wp-includes/meta.php:
    get_metadata_by_mid()
  • wp-includes/meta.php:
    delete_{$meta_type}_meta
  • wp-includes/meta.php:
    delete_{$meta_type}meta
  • wp-includes/meta.php:
    deleted_{$meta_type}_meta
  • wp-includes/meta.php:
    deleted_{$meta_type}meta
  • Show 5 more uses
    Hide more uses


Used By

  • wp-admin/includes/ms.php:
    wpmu_delete_user()
  • wp-admin/includes/user.php:
    wp_delete_user()
  • wp-admin/includes/post.php:
    delete_meta()
  • wp-includes/functions.php:
    do_enclose()
  • wp-includes/taxonomy.php:
    wp_delete_term()
  • wp-includes/post.php:
    wp_delete_attachment()
  • wp-includes/post.php:
    wp_delete_post()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::set_custom_fields()
  • wp-includes/comment.php:
    do_all_pings()
  • wp-includes/comment.php:
    wp_delete_comment()
  • Show 5 more used by
    Hide more used by


User Contributed Notes

上一篇:delete_metadata()

下一篇:delete_network_option()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!