user_can_edit_post

Whether user can edit a post.

Description

user_can_edit_post( (int) $user_id, (int) $post_id, (int) $blog_id = 1 ); 

Parameters (3)

0. $user_id (int)
The user id.
1. $post_id (int)
The post id.
2. $blog_id — Optional. (int) => 1
The blog id.

Usage

  1. if ( !function_exists( 'user_can_edit_post' ) ) { 
  2. require_once ABSPATH . WPINC . '/deprecated.php'; 
  3.  
  4. // The user id. 
  5. $user_id = -1; 
  6.  
  7. // The post id. 
  8. $post_id = -1; 
  9.  
  10. // The blog id. 
  11. $blog_id = 1; 
  12.  
  13. // NOTICE! Understand what this does before running. 
  14. $result = user_can_edit_post($user_id, $post_id, $blog_id); 
  15.  

Defined (1)

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

/wp-includes/deprecated.php  
  1. function user_can_edit_post($user_id, $post_id, $blog_id = 1) { 
  2. _deprecated_function( __FUNCTION__, '2.0.0', 'current_user_can()' ); 
  3.  
  4. $author_data = get_userdata($user_id); 
  5. $post = get_post($post_id); 
  6. $post_author_data = get_userdata($post->post_author); 
  7.  
  8. if ( (($user_id == $post_author_data->ID) && !($post->post_status == 'publish' && $author_data->user_level < 2)) 
  9. || ($author_data->user_level > $post_author_data->user_level) 
  10. || ($author_data->user_level >= 10) ) { 
  11. return true; 
  12. } else { 
  13. return false;