Make WordPress Core

Changeset 6349


Ignore:
Timestamp:
11/29/2007 05:51:09 AM (17 years ago)
Author:
ryan
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-mail.php

    r6281 r6349  
    2828    $boundary = '';
    2929    $bodysignal = 0;
     30    $post_author = 1;
     31    $author_found = false;
    3032    $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    3133    foreach ($message as $line) :
     
    7173                if ( is_email($author) ) {
    7274                    echo "Author = {$author} <p>";
    73                     $author = $wpdb->escape($author);
    74                     $result = $wpdb->get_row("SELECT ID FROM $wpdb->users WHERE user_email='$author' LIMIT 1");
    75                     if (!$result)
     75                    $userdata = get_user_by_email($author);
     76                    if (!$userdata) {
    7677                        $post_author = 1;
    77                     else
    78                         $post_author = $result->ID;
    79                 } else
     78                        $author_found = false;
     79                    } else {
     80                        $post_author = $userdata->ID;
     81                        $author_found = true;
     82                    }
     83                } else {
    8084                    $post_author = 1;
     85                    $author_found = false;
     86                }
    8187            }
    8288
     
    111117        }
    112118    endforeach;
     119
     120    // Set $post_status based on $author_found and on author's publish_posts capability
     121    if ($author_found) {
     122        $user = new WP_User($post_author);
     123        if ($user->has_cap('publish_posts'))
     124            $post_status = 'publish';
     125        else
     126            $post_status = 'pending';
     127    } else {
     128        // Author not found in DB, set status to pending.  Author already set to admin.
     129        $post_status = 'pending';
     130    }
    113131
    114132    $subject = trim($subject);
     
    145163    $post_category = $post_categories;
    146164
    147     // or maybe we should leave the choice to email drafts? propose a way
    148     $post_status = 'publish';
    149 
    150165    $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status');
    151166    $post_data = add_magic_quotes($post_data);
Note: See TracChangeset for help on using the changeset viewer.