delete_usermeta

函数
delete_usermeta ( $user_id, $meta_key, $meta_value = '' )
参数
  • (int) $user_id User ID.
    Required:
  • (string) $meta_key Metadata key.
    Required:
  • (mixed) $meta_value Optional. Metadata value. Default empty.
    Required:
    Default: (empty)
返回值
  • (bool) True deletion completed and false if user_id is not a number.
相关
  • delete_user_meta()
定义位置
相关方法
delete_user_metadelete_metadelete_site_metadelete_term_metaget_usermeta
引入
2.0.0
弃用
3.0.0

delete_usermeta: 这个函数删除用户元数据。应将用户ID和元数据键作为参数指定。

删除用户元数据。

function delete_usermeta( $user_id, $meta_key, $meta_value = '' ) {
	_deprecated_function( __FUNCTION__, '3.0.0', 'delete_user_meta()' );
	global $wpdb;
	if ( !is_numeric( $user_id ) )
		return false;
	$meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);

	if ( is_array($meta_value) || is_object($meta_value) )
		$meta_value = serialize($meta_value);
	$meta_value = trim( $meta_value );

	$cur = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) );

	if ( $cur && $cur->umeta_id )
		do_action( 'delete_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value );

	if ( ! empty($meta_value) )
		$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s AND meta_value = %s", $user_id, $meta_key, $meta_value) );
	else
		$wpdb->query( $wpdb->prepare("DELETE FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) );

	clean_user_cache( $user_id );
	wp_cache_delete( $user_id, 'user_meta' );

	if ( $cur && $cur->umeta_id )
		do_action( 'deleted_usermeta', $cur->umeta_id, $user_id, $meta_key, $meta_value );

	return true;
}

常见问题

FAQs
查看更多 >