Partial migration to roles.
git-svn-id: http://svn.automattic.com/wordpress/trunk@2900 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
1d16b58059
commit
14eb9ebc01
|
@ -12,34 +12,27 @@ function get_others_drafts( $user_id ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$user = get_userdata( $user_id );
|
$user = get_userdata( $user_id );
|
||||||
$level_key = $wpdb->prefix . 'user_level';
|
$level_key = $wpdb->prefix . 'user_level';
|
||||||
if ( 1 < $user->user_level ) {
|
|
||||||
$editable = get_editable_user_ids( $user_id );
|
|
||||||
|
|
||||||
if( !$editable ) {
|
$editable = get_editable_user_ids( $user_id );
|
||||||
$other_drafts = '';
|
|
||||||
} else {
|
if( !$editable ) {
|
||||||
$editable = join(',', $editable);
|
$other_drafts = '';
|
||||||
$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 {
|
} else {
|
||||||
$other_drafts = false;
|
$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' ");
|
||||||
}
|
}
|
||||||
|
|
||||||
return apply_filters('get_others_drafts', $other_drafts);
|
return apply_filters('get_others_drafts', $other_drafts);
|
||||||
}
|
}
|
||||||
|
|
||||||
function get_editable_authors( $user_id ) {
|
function get_editable_authors( $user_id ) {
|
||||||
global $wpdb;
|
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 );
|
$editable = get_editable_user_ids( $user_id );
|
||||||
|
|
||||||
if( !$editable )
|
if( !$editable ) {
|
||||||
return false;
|
return false;
|
||||||
else {
|
} else {
|
||||||
$editable = join(',', $editable);
|
$editable = join(',', $editable);
|
||||||
$authors = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($editable)" );
|
$authors = $wpdb->get_results( "SELECT * FROM $wpdb->users WHERE ID IN ($editable)" );
|
||||||
}
|
}
|
||||||
|
@ -49,24 +42,24 @@ function get_editable_authors( $user_id ) {
|
||||||
|
|
||||||
function get_editable_user_ids( $user_id, $exclude_zeros = true ) {
|
function get_editable_user_ids( $user_id, $exclude_zeros = true ) {
|
||||||
global $wpdb;
|
global $wpdb;
|
||||||
$user = get_userdata( $user_id );
|
|
||||||
|
$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;
|
||||||
|
}
|
||||||
|
|
||||||
$level_key = $wpdb->prefix . 'user_level';
|
$level_key = $wpdb->prefix . 'user_level';
|
||||||
|
|
||||||
$query = "SELECT * FROM $wpdb->usermeta WHERE meta_key = '$level_key'";
|
$query = "SELECT user_id FROM $wpdb->usermeta WHERE meta_key = '$level_key'";
|
||||||
if ( $exclude_zeros )
|
if ( $exclude_zeros )
|
||||||
$query .= " AND meta_value != '0'";
|
$query .= " AND meta_value != '0'";
|
||||||
$possible = $wpdb->get_results( $query );
|
|
||||||
|
|
||||||
if ( !$possible )
|
return $wpdb->get_col( $query );
|
||||||
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() {
|
function get_author_user_ids() {
|
||||||
|
|
|
@ -102,7 +102,7 @@ addLoadEvent(focusit);
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if ( $authors = get_editable_authors( $current_user->ID ) ) : // TODO: ROLE SYSTEM ?>
|
<?php if ( $authors = get_editable_authors( $current_user->id ) ) : // TODO: ROLE SYSTEM ?>
|
||||||
<fieldset id="authordiv" class="dbx-box">
|
<fieldset id="authordiv" class="dbx-box">
|
||||||
<h3 class="dbx-handle"><?php _e('Post author'); ?>:</h3>
|
<h3 class="dbx-handle"><?php _e('Post author'); ?>:</h3>
|
||||||
<div class="dbx-content">
|
<div class="dbx-content">
|
||||||
|
|
|
@ -83,7 +83,7 @@ addLoadEvent(focusit);
|
||||||
<div class="dbx-content"><input name="post_name" type="text" size="13" id="post_name" value="<?php echo $post->post_name ?>" /></div>
|
<div class="dbx-content"><input name="post_name" type="text" size="13" id="post_name" value="<?php echo $post->post_name ?>" /></div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
|
|
||||||
<?php if ( $authors = get_editable_authors( $current_user->ID ) ) : // TODO: ROLE SYSTEM ?>
|
<?php if ( $authors = get_editable_authors( $current_user->id ) ) : // TODO: ROLE SYSTEM ?>
|
||||||
<fieldset id="authordiv" class="dbx-box">
|
<fieldset id="authordiv" class="dbx-box">
|
||||||
<h3 class="dbx-handle"><?php _e('Post author'); ?>:</h3>
|
<h3 class="dbx-handle"><?php _e('Post author'); ?>:</h3>
|
||||||
<div class="dbx-content">
|
<div class="dbx-content">
|
||||||
|
|
Loading…
Reference in New Issue