Make WordPress Core

Changeset 2900


Ignore:
Timestamp:
09/21/2005 05:13:49 AM (19 years ago)
Author:
ryan
Message:

Partial migration to roles.

Location:
trunk/wp-admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/admin-db.php

    r2702 r2900  
    1313    $user = get_userdata( $user_id );
    1414    $level_key = $wpdb->prefix . 'user_level';
    15     if ( 1 < $user->user_level ) {
    16         $editable = get_editable_user_ids( $user_id );
     15
     16    $editable = get_editable_user_ids( $user_id );
    1717   
    18         if( !$editable ) {
    19                 $other_drafts = '';
    20         } else {
    21             $editable = join(',', $editable);
    22             $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' ");
    23         }
     18    if( !$editable ) {
     19        $other_drafts = '';
    2420    } else {
    25         $other_drafts = false;
     21        $editable = join(',', $editable);
     22        $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' ");
    2623    }
     24
    2725    return apply_filters('get_others_drafts', $other_drafts);
    2826}
     
    3028function get_editable_authors( $user_id ) {
    3129    global $wpdb;
    32     $user = get_userdata( $user_id );
    33     $level_key = $wpdb->prefix . 'user_level';
    34 
    35     if ( 7 > $user->user_level ) // TODO: ROLE SYSTEM
    36         return false;
    3730
    3831    $editable = get_editable_user_ids( $user_id );
    3932
    40     if( !$editable )
    41             return false;
    42     else {
     33    if( !$editable ) {
     34        return false;
     35    } else {
    4336        $editable = join(',', $editable);
    4437        $authors = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($editable)" );
     
    5043function get_editable_user_ids( $user_id, $exclude_zeros = true ) {
    5144    global $wpdb;
    52     $user = get_userdata( $user_id );
     45   
     46    $user = new WP_User( $user_id );
     47   
     48    if ( ! $user->has_cap('edit_others_posts') ) {
     49            echo "no cap<br/>";
     50        if ( $user->has_cap('edit_posts') || $exclude_zeros == false )
     51            return array($user->id);
     52        else
     53            return false;
     54    }
     55
    5356    $level_key = $wpdb->prefix . 'user_level';
    5457
    55     $query = "SELECT * FROM $wpdb->usermeta WHERE meta_key = '$level_key'";
     58    $query = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key'";
    5659    if ( $exclude_zeros )
    5760        $query .= " AND meta_value != '0'";
    58     $possible = $wpdb->get_results( $query );
    59 
    60     if ( !$possible )
    61         return false;   
    62 
    63     $user_ids = array();
    64     foreach ( $possible as $mark )
    65         if ( intval($mark->meta_value) <= $user->user_level )
    66             $user_ids[] = $mark->user_id;
    67     if ( empty( $user_ids ) )
    68         return false;
    69     return $user_ids;
     61       
     62    return $wpdb->get_col( $query );
    7063}
    7164
  • trunk/wp-admin/edit-form-advanced.php

    r2804 r2900  
    103103<?php endif; ?>
    104104
    105 <?php if ( $authors = get_editable_authors( $current_user->ID ) ) : // TODO: ROLE SYSTEM ?>
     105<?php if ( $authors = get_editable_authors( $current_user->id ) ) : // TODO: ROLE SYSTEM ?>
    106106<fieldset id="authordiv" class="dbx-box">
    107107<h3 class="dbx-handle"><?php _e('Post author'); ?>:</h3>
  • trunk/wp-admin/edit-page-form.php

    r2826 r2900  
    8484</fieldset>
    8585
    86 <?php if ( $authors = get_editable_authors( $current_user->ID ) ) : // TODO: ROLE SYSTEM ?>
     86<?php if ( $authors = get_editable_authors( $current_user->id ) ) : // TODO: ROLE SYSTEM ?>
    8787<fieldset id="authordiv" class="dbx-box">
    8888<h3 class="dbx-handle"><?php _e('Post author'); ?>:</h3>
Note: See TracChangeset for help on using the changeset viewer.