Make WordPress Core

Ticket #4642: 4642.2.diff

File 4642.2.diff, 1.9 KB (added by Bobcat, 17 years ago)

wp-mail.php patch to set post_status based on the author's capabilities

  • wp-mail.php

     
    2727        $content_transfer_encoding = '';
    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) :
    3234                if (strlen($line) < 3) $bodysignal = 1;
     
    7274                                        echo "Author = {$author} <p>";
    7375                                        $author = $wpdb->escape($author);
    7476                                        $result = $wpdb->get_row("SELECT ID FROM $wpdb->users WHERE user_email='$author' LIMIT 1");
    75                                         if (!$result)
     77                                        if (!$result) {
    7678                                                $post_author = 1;
    77                                         else
     79                                                $author_found = false;
     80                                        } else {
    7881                                                $post_author = $result->ID;
    79                                 } else
     82                                                $author_found = true;
     83                                        }
     84                                } else {
    8085                                        $post_author = 1;
     86                                        $author_found = false;
     87                                }
    8188                        }
    8289
    8390                        if (preg_match('/Date: /i', $line)) { // of the form '20 Mar 2002 20:32:37'
     
    111118                }
    112119        endforeach;
    113120
     121        // Set $post_status based on $author_found and on author's publish_posts capability
     122        if ($author_found) {
     123                $user = new WP_User($post_author);
     124                if ($user->has_cap('publish_posts'))
     125                        $post_status = 'publish';
     126                else
     127                        $post_status = 'pending';
     128        } else {
     129                // Author not found in DB, set status to pending.  Author already set to admin.
     130                $post_status = 'pending';
     131        }
     132
    114133        $subject = trim($subject);
    115134
    116135        if ($content_type == 'multipart/alternative') {
     
    144163
    145164        $post_category = $post_categories;
    146165
    147         // or maybe we should leave the choice to email drafts? propose a way
    148         $post_status = 'publish';
    149 
    150166        $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status');
    151167        $post_data = add_magic_quotes($post_data);
    152168