Warning: This function has been deprecated. Use get_users() instead.

get_editable_user_ids() WordPress Function

The get_editable_user_ids() function is used to retrieve a list of user IDs that are allowed to be edited. This function is useful for restricting access to certain users.

get_editable_user_ids( int $user_id, bool $exclude_zeros = true,  $post_type = 'post' ) #

Gets the IDs of any users who can edit posts.


Parameters

$user_id

(int)(Required)User ID.

$exclude_zeros

(bool)(Optional) Whether to exclude zeroes.

Default value: true


Top ↑

Return

(array) Array of editable user IDs, empty array otherwise.


Top ↑

Source

File: wp-admin/includes/deprecated.php

function get_editable_user_ids( $user_id, $exclude_zeros = true, $post_type = 'post' ) {
	_deprecated_function( __FUNCTION__, '3.1.0', 'get_users()' );

	global $wpdb;

	if ( ! $user = get_userdata( $user_id ) )
		return array();
	$post_type_obj = get_post_type_object($post_type);

	if ( ! $user->has_cap($post_type_obj->cap->edit_others_posts) ) {
		if ( $user->has_cap($post_type_obj->cap->edit_posts) || ! $exclude_zeros )
			return array($user->ID);
		else
			return array();
	}

	if ( !is_multisite() )
		$level_key = $wpdb->get_blog_prefix() . 'user_level';
	else
		$level_key = $wpdb->get_blog_prefix() . 'capabilities'; // WPMU site admins don't have user_levels.

	$query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s", $level_key);
	if ( $exclude_zeros )
		$query .= " AND meta_value != '0'";

	return $wpdb->get_col( $query );
}


Top ↑

Changelog

Changelog
VersionDescription
3.1.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.

Show More