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' ;
if ( 1 < $user -> user_level ) {
2005-07-08 21:27:46 -04:00
$editable = get_editable_user_ids ( $user_id );
if ( ! $editable ) {
2005-07-08 18:59:15 -04:00
$other_drafts = '' ;
2005-07-08 21:27:46 -04:00
} else {
2005-07-08 18:59:15 -04:00
$editable = join ( ',' , $editable );
2005-07-08 21:27:46 -04:00
$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
}
} else {
$other_drafts = false ;
}
return apply_filters ( 'get_others_drafts' , $other_drafts );
}
2005-07-08 21:27:46 -04:00
function get_editable_authors ( $user_id ) {
global $wpdb ;
$user = get_userdata ( $user_id );
$level_key = $wpdb -> prefix . 'user_level' ;
if ( 7 > $user -> user_level ) // TODO: ROLE SYSTEM
return false ;
$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 ) " );
}
return apply_filters ( 'get_editable_authors' , $authors );
}
function get_editable_user_ids ( $user_id , $exclude_zeros = true ) {
global $wpdb ;
$user = get_userdata ( $user_id );
$level_key = $wpdb -> prefix . 'user_level' ;
$query = " SELECT * FROM $wpdb->usermeta WHERE meta_key = ' $level_key ' " ;
if ( $exclude_zeros )
$query .= " AND meta_value != '0' " ;
$possible = $wpdb -> get_results ( $query );
if ( ! $possible )
return false ;
$user_ids = array ();
foreach ( $possible as $mark )
if ( intval ( $mark -> meta_value ) <= $user -> user_level )
$user_ids [] = $mark -> user_id ;
if ( empty ( $user_ids ) )
return false ;
return $user_ids ;
}
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
?>