函数文档

get_editable_authors()

💡 云策文档标注

概述

get_editable_authors() 是一个已弃用的 WordPress 函数,用于获取可编辑文章的作者用户列表。它基于用户 ID 查询数据库,返回用户对象数组或 false。

关键要点

  • 函数已弃用:自 WordPress 3.1.0 起,推荐使用 get_users() 替代。
  • 参数:接受一个必需的 $user_id 整数参数,表示用户 ID。
  • 返回值:返回可编辑作者的用户对象数组,若无则返回 false。
  • 内部实现:调用 get_editable_user_ids() 获取可编辑用户 ID,然后通过 wpdb::get_results() 查询数据库。
  • 过滤器:应用 get_editable_authors 过滤器,允许修改返回结果。

代码示例

function get_editable_authors( $user_id ) {
    _deprecated_function( __FUNCTION__, '3.1.0', 'get_users()' );

    global $wpdb;

    $editable = get_editable_user_ids( $user_id );

    if ( !$editable ) {
        return false;
    } else {
        $editable = join(',', $editable);
        $authors = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($editable) ORDER BY display_name" );
    }

    return apply_filters('get_editable_authors', $authors);
}

注意事项

  • 此函数已弃用,新代码应避免使用,改用 get_users() 实现类似功能。
  • 函数依赖于 get_editable_user_ids() 来获取可编辑用户 ID,后者也已弃用。
  • 使用 wpdb::get_results() 直接查询数据库,需注意 SQL 注入风险,但在此上下文中已通过 join 处理。

📄 原文内容

Gets author users who can edit posts.

Parameters

$user_idintrequired
User ID.

Return

array|false List of editable authors. False if no editable users.

Source

function get_editable_authors( $user_id ) {
	_deprecated_function( __FUNCTION__, '3.1.0', 'get_users()' );

	global $wpdb;

	$editable = get_editable_user_ids( $user_id );

	if ( !$editable ) {
		return false;
	} else {
		$editable = join(',', $editable);
		$authors = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($editable) ORDER BY display_name" );
	}

	return apply_filters('get_editable_authors', $authors);
}

Changelog

Version Description
3.1.0 Introduced.