When posting by email, publish only if user has publish caps, otherwise set status to pending. Props Bobcat. fixes #4642

git-svn-id: https://develop.svn.wordpress.org/trunk@6349 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Ryan Boren 2007-11-29 05:51:09 +00:00
parent 376e2d98af
commit 1715c0f74e

View File

@ -27,6 +27,8 @@ for ($i=1; $i <= $count; $i++) :
$content_transfer_encoding = ''; $content_transfer_encoding = '';
$boundary = ''; $boundary = '';
$bodysignal = 0; $bodysignal = 0;
$post_author = 1;
$author_found = false;
$dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
foreach ($message as $line) : foreach ($message as $line) :
if (strlen($line) < 3) $bodysignal = 1; if (strlen($line) < 3) $bodysignal = 1;
@ -70,14 +72,18 @@ for ($i=1; $i <= $count; $i++) :
$author = sanitize_email($author); $author = sanitize_email($author);
if ( is_email($author) ) { if ( is_email($author) ) {
echo "Author = {$author} <p>"; echo "Author = {$author} <p>";
$author = $wpdb->escape($author); $userdata = get_user_by_email($author);
$result = $wpdb->get_row("SELECT ID FROM $wpdb->users WHERE user_email='$author' LIMIT 1"); if (!$userdata) {
if (!$result)
$post_author = 1; $post_author = 1;
else $author_found = false;
$post_author = $result->ID; } else {
} else $post_author = $userdata->ID;
$author_found = true;
}
} else {
$post_author = 1; $post_author = 1;
$author_found = false;
}
} }
if (preg_match('/Date: /i', $line)) { // of the form '20 Mar 2002 20:32:37' if (preg_match('/Date: /i', $line)) { // of the form '20 Mar 2002 20:32:37'
@ -111,6 +117,18 @@ for ($i=1; $i <= $count; $i++) :
} }
endforeach; endforeach;
// Set $post_status based on $author_found and on author's publish_posts capability
if ($author_found) {
$user = new WP_User($post_author);
if ($user->has_cap('publish_posts'))
$post_status = 'publish';
else
$post_status = 'pending';
} else {
// Author not found in DB, set status to pending. Author already set to admin.
$post_status = 'pending';
}
$subject = trim($subject); $subject = trim($subject);
if ($content_type == 'multipart/alternative') { if ($content_type == 'multipart/alternative') {
@ -144,9 +162,6 @@ for ($i=1; $i <= $count; $i++) :
$post_category = $post_categories; $post_category = $post_categories;
// or maybe we should leave the choice to email drafts? propose a way
$post_status = 'publish';
$post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status'); $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status');
$post_data = add_magic_quotes($post_data); $post_data = add_magic_quotes($post_data);