get_editable_user_ids

Gets the IDs of any users who can edit posts.

Description

(array) get_editable_user_ids( (int) $user_id, (constant) $exclude_zeros = true, (string) $post_type = 'post' ); 

Returns (array)

Array of editable user IDs, empty array otherwise.

Parameters (3)

0. $user_id (int)
The user id.
1. $exclude_zeros — Optional. (constant) => true
Whether to exclude zeroes. Default true.
2. $post_type — Optional. (string) => 'post'
The post type.

Usage

  1. if ( !function_exists( 'get_editable_user_ids' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/deprecated.php'; 
  3.  
  4. // The user id. 
  5. $user_id = -1; 
  6.  
  7. // Optional. Whether to exclude zeroes. Default true. 
  8. $exclude_zeros = true; 
  9.  
  10. // The post type. 
  11. $post_type = 'post'; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = get_editable_user_ids($user_id, $exclude_zeros, $post_type); 
  15.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/deprecated.php  
  1. function get_editable_user_ids( $user_id, $exclude_zeros = true, $post_type = 'post' ) { 
  2. _deprecated_function( __FUNCTION__, '3.1.0', 'get_users()' ); 
  3.  
  4. global $wpdb; 
  5.  
  6. if ( ! $user = get_userdata( $user_id ) ) 
  7. return array(); 
  8. $post_type_obj = get_post_type_object($post_type); 
  9.  
  10. if ( ! $user->has_cap($post_type_obj->cap->edit_others_posts) ) { 
  11. if ( $user->has_cap($post_type_obj->cap->edit_posts) || ! $exclude_zeros ) 
  12. return array($user->ID); 
  13. else 
  14. return array(); 
  15.  
  16. if ( !is_multisite() ) 
  17. $level_key = $wpdb->get_blog_prefix() . 'user_level'; 
  18. else 
  19. $level_key = $wpdb->get_blog_prefix() . 'capabilities'; // wpmu site admins don't have user_levels 
  20.  
  21. $query = $wpdb->prepare("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = %s", $level_key); 
  22. if ( $exclude_zeros ) 
  23. $query .= " AND meta_value != '0'"; 
  24.  
  25. return $wpdb->get_col( $query );