返回介绍

delete_metadata_by_mid()

发布于 2017-09-10 22:05:51 字数 4539 浏览 1212 评论 0 收藏 0

delete_metadata_by_mid( string $meta_type,  int $meta_id )

Delete meta data by meta ID


description


参数

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

更新日志

Versiondescription
3.3.0Introduced.

相关函数

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

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

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

发布评论

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