2005-07-08 18:59:15 -04:00
< ? php
function get_users_drafts ( $user_id ) {
global $wpdb ;
$user_id = ( int ) $user_id ;
$query = " SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'draft' AND post_author = $user_id ORDER BY ID DESC " ;
$query = apply_filters ( 'get_users_drafts' , $query );
return $wpdb -> get_results ( $query );
}
function get_others_drafts ( $user_id ) {
global $wpdb ;
$user = get_userdata ( $user_id );
$level_key = $wpdb -> prefix . 'user_level' ;
2005-09-21 01:13:49 -04:00
$editable = get_editable_user_ids ( $user_id );
2005-07-08 21:27:46 -04:00
2005-09-21 01:13:49 -04:00
if ( ! $editable ) {
$other_drafts = '' ;
2005-07-08 18:59:15 -04:00
} else {
2005-09-21 01:13:49 -04:00
$editable = join ( ',' , $editable );
$other_drafts = $wpdb -> get_results ( " SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'draft' AND post_author IN ( $editable ) AND post_author != ' $user_id ' " );
2005-07-08 18:59:15 -04:00
}
2005-09-21 01:13:49 -04:00
2005-07-08 18:59:15 -04:00
return apply_filters ( 'get_others_drafts' , $other_drafts );
}
2005-07-08 21:27:46 -04:00
function get_editable_authors ( $user_id ) {
global $wpdb ;
$editable = get_editable_user_ids ( $user_id );
2005-09-21 01:13:49 -04:00
if ( ! $editable ) {
return false ;
} else {
2005-07-08 21:27:46 -04:00
$editable = join ( ',' , $editable );
$authors = $wpdb -> get_results ( " SELECT * FROM $wpdb->users WHERE ID IN ( $editable ) " );
}
return apply_filters ( 'get_editable_authors' , $authors );
}
function get_editable_user_ids ( $user_id , $exclude_zeros = true ) {
global $wpdb ;
2005-09-21 01:13:49 -04:00
$user = new WP_User ( $user_id );
if ( ! $user -> has_cap ( 'edit_others_posts' ) ) {
echo " no cap<br/> " ;
if ( $user -> has_cap ( 'edit_posts' ) || $exclude_zeros == false )
return array ( $user -> id );
else
return false ;
}
2005-07-08 21:27:46 -04:00
$level_key = $wpdb -> prefix . 'user_level' ;
2005-09-21 01:13:49 -04:00
$query = " SELECT user_id FROM $wpdb->usermeta WHERE meta_key = ' $level_key ' " ;
2005-07-08 21:27:46 -04:00
if ( $exclude_zeros )
$query .= " AND meta_value != '0' " ;
2005-09-21 01:13:49 -04:00
return $wpdb -> get_col ( $query );
2005-07-08 21:27:46 -04:00
}
function get_author_user_ids () {
global $wpdb ;
$level_key = $wpdb -> prefix . 'user_level' ;
$query = " SELECT user_id FROM $wpdb->usermeta WHERE meta_key = ' $level_key ' AND meta_value != '0' " ;
return $wpdb -> get_col ( $query );
}
function get_nonauthor_user_ids () {
global $wpdb ;
$level_key = $wpdb -> prefix . 'user_level' ;
$query = " SELECT user_id FROM $wpdb->usermeta WHERE meta_key = ' $level_key ' AND meta_value = '0' " ;
return $wpdb -> get_col ( $query );
}
2005-07-08 18:59:15 -04:00
?>