diff --git a/wp-admin/admin-db.php b/wp-admin/admin-db.php index 78e803c864..b657edd701 100644 --- a/wp-admin/admin-db.php +++ b/wp-admin/admin-db.php @@ -13,12 +13,13 @@ function get_others_drafts( $user_id ) { $user = get_userdata( $user_id ); $level_key = $wpdb->prefix . 'user_level'; if ( 1 < $user->user_level ) { - $editable = $wpdb->get_col("SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key' AND meta_value <= '$user->user_level' AND user_id != $user_id"); - if( is_array( $editable ) == false ) + $editable = get_editable_user_ids( $user_id ); + + if( !$editable ) { $other_drafts = ''; - else { + } else { $editable = join(',', $editable); - $other_drafts = $wpdb->get_results("SELECT ID, post_title FROM $wpdb->posts WHERE post_status = 'draft' AND post_author IN ($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' "); } } else { $other_drafts = false; @@ -26,4 +27,64 @@ function get_others_drafts( $user_id ) { return apply_filters('get_others_drafts', $other_drafts); } +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 ); +} + ?> \ No newline at end of file diff --git a/wp-admin/admin-functions.php b/wp-admin/admin-functions.php index 47c49b2fb1..cb3fcff3e2 100644 --- a/wp-admin/admin-functions.php +++ b/wp-admin/admin-functions.php @@ -437,8 +437,11 @@ function dropdown_categories($default = 0) { // Dandy new recursive multiple category stuff. function cat_rows($parent = 0, $level = 0, $categories = 0) { - global $wpdb, $class, $user_level; - if (!$categories) + global $wpdb, $class, $current_user; + + $user_level = $current_user->user_level; + + if ( !$categories ) $categories = $wpdb->get_results("SELECT * FROM $wpdb->categories ORDER BY cat_name"); if ($categories) { diff --git a/wp-admin/edit-form-advanced.php b/wp-admin/edit-form-advanced.php index a7970a6355..577cf776e7 100644 --- a/wp-admin/edit-form-advanced.php +++ b/wp-admin/edit-form-advanced.php @@ -104,13 +104,13 @@ window.onload = focusit; - 7 && $users = $wpdb->get_results("SELECT ID, user_login FROM $wpdb->users WHERE user_level <= $user_level AND user_level > 0") ) : ?> +ID ) ) : // TODO: ROLE SYSTEM ?>