From 40a99fc9a1adb0da4f20d4f2e7d4e3a201d89144 Mon Sep 17 00:00:00 2001 From: ryan Date: Fri, 15 Jul 2005 01:27:01 +0000 Subject: [PATCH] Move user_can_*() functions to capabilities.php. git-svn-id: http://svn.automattic.com/wordpress/trunk@2713 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/capabilities.php | 70 +++++++++++++++++++++++++++++++++ wp-includes/functions-post.php | 71 ---------------------------------- 2 files changed, 70 insertions(+), 71 deletions(-) diff --git a/wp-includes/capabilities.php b/wp-includes/capabilities.php index b4e8df0cc..96564afaa 100644 --- a/wp-includes/capabilities.php +++ b/wp-includes/capabilities.php @@ -270,4 +270,74 @@ function current_user_can($capability) { return call_user_func_array(array(&$current_user, 'has_cap'), $args); } +// +// These are deprecated. Use current_user_can(). +// + +/* returns true if $user_id can create a new post */ +function user_can_create_post($user_id, $blog_id = 1, $category_id = 'None') { + $author_data = get_userdata($user_id); + return ($author_data->user_level > 1); +} + +/* returns true if $user_id can create a new post */ +function user_can_create_draft($user_id, $blog_id = 1, $category_id = 'None') { + $author_data = get_userdata($user_id); + return ($author_data->user_level >= 1); +} + +/* returns true if $user_id can edit $post_id */ +function user_can_edit_post($user_id, $post_id, $blog_id = 1) { + $author_data = get_userdata($user_id); + $post = get_post($post_id); + $post_author_data = get_userdata($post->post_author); + + if ( (($user_id == $post_author_data->ID) && !($post->post_status == 'publish' && $author_data->user_level < 2)) + || ($author_data->user_level > $post_author_data->user_level) + || ($author_data->user_level >= 10) ) { + return true; + } else { + return false; + } +} + +/* returns true if $user_id can delete $post_id */ +function user_can_delete_post($user_id, $post_id, $blog_id = 1) { + // right now if one can edit, one can delete + return user_can_edit_post($user_id, $post_id, $blog_id); +} + +/* returns true if $user_id can set new posts' dates on $blog_id */ +function user_can_set_post_date($user_id, $blog_id = 1, $category_id = 'None') { + $author_data = get_userdata($user_id); + return (($author_data->user_level > 4) && user_can_create_post($user_id, $blog_id, $category_id)); +} + +/* returns true if $user_id can edit $post_id's date */ +function user_can_edit_post_date($user_id, $post_id, $blog_id = 1) { + $author_data = get_userdata($user_id); + return (($author_data->user_level > 4) && user_can_edit_post($user_id, $post_id, $blog_id)); +} + +/* returns true if $user_id can edit $post_id's comments */ +function user_can_edit_post_comments($user_id, $post_id, $blog_id = 1) { + // right now if one can edit a post, one can edit comments made on it + return user_can_edit_post($user_id, $post_id, $blog_id); +} + +/* returns true if $user_id can delete $post_id's comments */ +function user_can_delete_post_comments($user_id, $post_id, $blog_id = 1) { + // right now if one can edit comments, one can delete comments + return user_can_edit_post_comments($user_id, $post_id, $blog_id); +} + +function user_can_edit_user($user_id, $other_user) { + $user = get_userdata($user_id); + $other = get_userdata($other_user); + if ( $user->user_level > $other->user_level || $user->user_level > 8 || $user->ID == $other->ID ) + return true; + else + return false; +} + ?> diff --git a/wp-includes/functions-post.php b/wp-includes/functions-post.php index 2ed81e4b8..4912d24ae 100644 --- a/wp-includes/functions-post.php +++ b/wp-includes/functions-post.php @@ -381,77 +381,6 @@ function trackback_url_list($tb_list, $post_id) { } } - -// query user capabilities -// rather simplistic. shall evolve with future permission system overhaul -// $blog_id and $category_id are there for future usage - -/* returns true if $user_id can create a new post */ -function user_can_create_post($user_id, $blog_id = 1, $category_id = 'None') { - $author_data = get_userdata($user_id); - return ($author_data->user_level > 1); -} - -/* returns true if $user_id can create a new post */ -function user_can_create_draft($user_id, $blog_id = 1, $category_id = 'None') { - $author_data = get_userdata($user_id); - return ($author_data->user_level >= 1); -} - -/* returns true if $user_id can edit $post_id */ -function user_can_edit_post($user_id, $post_id, $blog_id = 1) { - $author_data = get_userdata($user_id); - $post = get_post($post_id); - $post_author_data = get_userdata($post->post_author); - - if ( (($user_id == $post_author_data->ID) && !($post->post_status == 'publish' && $author_data->user_level < 2)) - || ($author_data->user_level > $post_author_data->user_level) - || ($author_data->user_level >= 10) ) { - return true; - } else { - return false; - } -} - -/* returns true if $user_id can delete $post_id */ -function user_can_delete_post($user_id, $post_id, $blog_id = 1) { - // right now if one can edit, one can delete - return user_can_edit_post($user_id, $post_id, $blog_id); -} - -/* returns true if $user_id can set new posts' dates on $blog_id */ -function user_can_set_post_date($user_id, $blog_id = 1, $category_id = 'None') { - $author_data = get_userdata($user_id); - return (($author_data->user_level > 4) && user_can_create_post($user_id, $blog_id, $category_id)); -} - -/* returns true if $user_id can edit $post_id's date */ -function user_can_edit_post_date($user_id, $post_id, $blog_id = 1) { - $author_data = get_userdata($user_id); - return (($author_data->user_level > 4) && user_can_edit_post($user_id, $post_id, $blog_id)); -} - -/* returns true if $user_id can edit $post_id's comments */ -function user_can_edit_post_comments($user_id, $post_id, $blog_id = 1) { - // right now if one can edit a post, one can edit comments made on it - return user_can_edit_post($user_id, $post_id, $blog_id); -} - -/* returns true if $user_id can delete $post_id's comments */ -function user_can_delete_post_comments($user_id, $post_id, $blog_id = 1) { - // right now if one can edit comments, one can delete comments - return user_can_edit_post_comments($user_id, $post_id, $blog_id); -} - -function user_can_edit_user($user_id, $other_user) { - $user = get_userdata($user_id); - $other = get_userdata($other_user); - if ( $user->user_level > $other->user_level || $user->user_level > 8 || $user->ID == $other->ID ) - return true; - else - return false; -} - function wp_blacklist_check($author, $email, $url, $comment, $user_ip, $user_agent) { global $wpdb;