Make WordPress Core

Ticket #22942: 22942_updated_for_3.8.26148.diff

File 22942_updated_for_3.8.26148.diff, 16.4 KB (added by codebykat, 11 years ago)

Updated to fix merge conflicts with inline documentation added to wp-mail.php.

  • wp-admin/includes/schema.php

    diff --git wp-admin/includes/schema.php wp-admin/includes/schema.php
    index 90ab600..97a9330 100644
    function populate_options() { 
    377377        'comments_notify' => 1,
    378378        'posts_per_rss' => 10,
    379379        'rss_use_excerpt' => 0,
    380         'mailserver_url' => 'mail.example.com',
    381         'mailserver_login' => 'login@example.com',
    382         'mailserver_pass' => 'password',
    383         'mailserver_port' => 110,
    384380        'default_category' => 1,
    385381        'default_comment_status' => 'open',
    386382        'default_ping_status' => 'open',
    function populate_options() { 
    484480
    485481        // 3.5
    486482        'link_manager_enabled' => 0,
     483
     484        // 3.8
     485        'post_by_email_enabled' => 0,
    487486        );
    488487
    489488        // 3.3
  • wp-admin/includes/upgrade.php

    diff --git wp-admin/includes/upgrade.php wp-admin/includes/upgrade.php
    index bd250ae..623bb5a 100644
    function upgrade_all() { 
    408408        if ( $wp_current_db_version < 26148 )
    409409                upgrade_372();
    410410
     411        if ( $wp_current_db_version < 26148 )
     412                upgrade_380();
     413
    411414        maybe_disable_link_manager();
    412415
    413416        maybe_disable_automattic_widgets();
    414417
     418        maybe_disable_post_by_email();
     419
    415420        update_option( 'db_version', $wp_db_version );
    416421        update_option( 'db_upgraded', true );
    417422}
    function upgrade_372() { 
    12381243}
    12391244
    12401245/**
     1246 * Execute changes made in WordPress 3.8.
     1247 *
     1248 * @since 3.8.0
     1249 */
     1250function upgrade_380() {
     1251        global $wp_current_db_version;
     1252
     1253        if ( $wp_current_db_version < 26148 && 'mail.example.com' != get_option( 'mailserver_url' ) )
     1254                update_option( 'post_by_email_enabled', 1 ); // Previously set to 0 by populate_options()
     1255}
     1256
     1257/**
    12411258 * Execute network level changes
    12421259 *
    12431260 * @since 3.0.0
    function maybe_disable_link_manager() { 
    20022019}
    20032020
    20042021/**
     2022 * Disables Post by Email options if, at the time of upgrade, the settings have not been changed from original defaults.
     2023 *
     2024 * @since 3.8.0
     2025 */
     2026function maybe_disable_post_by_email() {
     2027        global $wp_current_db_version;
     2028
     2029        if ( $wp_current_db_version >= 26148 && get_option( 'post_by_email_enabled' ) && 'mail.example.com' == get_option( 'mailserver_url' ) )
     2030                update_option( 'post_by_email_enabled', 0 );
     2031}
     2032
     2033/**
    20052034 * Runs before the schema is upgraded.
    20062035 *
    20072036 * @since 2.9.0
  • wp-admin/options-writing.php

    diff --git wp-admin/options-writing.php wp-admin/options-writing.php
    index b3f9f68..a04edb2 100644
    get_current_screen()->add_help_tab( array( 
    2828        'content' => '<p>' . __('Press This is a bookmarklet that makes it easy to blog about something you come across on the web. You can use it to just grab a link, or to post an excerpt. Press This will even allow you to choose from images included on the page and use them in your post. Just drag the Press This link on this screen to your bookmarks bar in your browser, and you&#8217;ll be on your way to easier content creation. Clicking on it while on another website opens a popup window with all these options.') . '</p>',
    2929) );
    3030
    31 /** This filter is documented in wp-admin/options.php */
    32 if ( apply_filters( 'enable_post_by_email_configuration', true ) ) {
    33         get_current_screen()->add_help_tab( array(
    34                 'id'      => 'options-postemail',
    35                 'title'   => __( 'Post Via Email' ),
    36                 'content' => '<p>' . __( 'Post via email settings allow you to send your WordPress install an email with the content of your post. You must set up a secret e-mail account with POP3 access to use this, and any mail received at this address will be posted, so it&#8217;s a good idea to keep this address very secret.' ) . '</p>',
    37         ) );
    38 }
    39 
    4031/**
    4132 * Toggle site update services configuration functionality.
    4233 *
    do_settings_fields('writing', 'remote_publishing'); // A deprecated section. 
    132123
    133124<?php
    134125/** This filter is documented in wp-admin/options.php */
    135 if ( apply_filters( 'enable_post_by_email_configuration', true ) ) {
    136 ?>
    137 <h3 class="title"><?php _e('Post via e-mail') ?></h3>
    138 <p><?php printf(__('To post to WordPress by e-mail you must set up a secret e-mail account with POP3 access. Any mail received at this address will be posted, so it&#8217;s a good idea to keep this address very secret. Here are three random strings you could use: <kbd>%s</kbd>, <kbd>%s</kbd>, <kbd>%s</kbd>.'), wp_generate_password(8, false), wp_generate_password(8, false), wp_generate_password(8, false)) ?></p>
    139 
    140 <table class="form-table">
    141 <tr valign="top">
    142 <th scope="row"><label for="mailserver_url"><?php _e('Mail Server') ?></label></th>
    143 <td><input name="mailserver_url" type="text" id="mailserver_url" value="<?php form_option('mailserver_url'); ?>" class="regular-text code" />
    144 <label for="mailserver_port"><?php _e('Port') ?></label>
    145 <input name="mailserver_port" type="text" id="mailserver_port" value="<?php form_option('mailserver_port'); ?>" class="small-text" />
    146 </td>
    147 </tr>
    148 <tr valign="top">
    149 <th scope="row"><label for="mailserver_login"><?php _e('Login Name') ?></label></th>
    150 <td><input name="mailserver_login" type="text" id="mailserver_login" value="<?php form_option('mailserver_login'); ?>" class="regular-text ltr" /></td>
    151 </tr>
    152 <tr valign="top">
    153 <th scope="row"><label for="mailserver_pass"><?php _e('Password') ?></label></th>
    154 <td>
    155 <input name="mailserver_pass" type="text" id="mailserver_pass" value="<?php form_option('mailserver_pass'); ?>" class="regular-text ltr" />
    156 </td>
    157 </tr>
    158 <tr valign="top">
    159 <th scope="row"><label for="default_email_category"><?php _e('Default Mail Category') ?></label></th>
    160 <td>
    161 <?php
    162 wp_dropdown_categories(array('hide_empty' => 0, 'name' => 'default_email_category', 'orderby' => 'name', 'selected' => get_option('default_email_category'), 'hierarchical' => true));
    163 ?>
    164 </td>
    165 </tr>
    166 <?php do_settings_fields('writing', 'post_via_email'); ?>
    167 </table>
     126if ( get_option( 'post_by_email_enabled' ) && apply_filters( 'enable_post_by_email_configuration', true ) ) { ?>
     127<h3 class="title"><?php _e( 'Post via e-mail' ) ?></h3>
     128<p><?php _e( 'This functionality is no longer packaged with WordPress.  To continue using it, please install the <a href="http://wordpress.org/plugins/post-by-email">Post By Email plugin</a>.' ); ?></p>
    168129<?php } ?>
    169130
    170131<?php
  • wp-includes/default-filters.php

    diff --git wp-includes/default-filters.php wp-includes/default-filters.php
    index b6c7527..f70458c 100644
    add_filter( 'heartbeat_nopriv_received', 'wp_auth_check', 10, 2 ); 
    301301add_filter( 'authenticate', 'wp_authenticate_username_password',  20, 3 );
    302302add_filter( 'authenticate', 'wp_authenticate_spam_check',         99    );
    303303
     304// If the upgrade hasn't run yet, assume the post by mail options are set.
     305add_filter( 'default_option_post_by_email_enabled', '__return_true' );
     306
    304307unset($filter, $action);
  • wp-includes/formatting.php

    diff --git wp-includes/formatting.php wp-includes/formatting.php
    index 56aac4c..116703d 100644
    function sanitize_option($option, $value) { 
    28492849                case 'medium_size_h':
    28502850                case 'large_size_w':
    28512851                case 'large_size_h':
    2852                 case 'mailserver_port':
    28532852                case 'comment_max_links':
    28542853                case 'page_on_front':
    28552854                case 'page_for_posts':
    function sanitize_option($option, $value) { 
    29012900
    29022901                case 'date_format':
    29032902                case 'time_format':
    2904                 case 'mailserver_url':
    2905                 case 'mailserver_login':
    2906                 case 'mailserver_pass':
    29072903                case 'upload_path':
    29082904                        $value = strip_tags( $value );
    29092905                        $value = wp_kses_data( $value );
  • wp-mail.php

    diff --git wp-mail.php wp-mail.php
    index 550c28c..15d37be 100644
     
    11<?php
    22/**
    3  * Gets the email message from the user's mailbox to add as
    4  * a WordPress post. Mailbox connection information must be
    5  * configured under Settings > Writing
     3 * This file is deprecated and has been replaced by the
     4 * plugin Post By Email.  Instead of loading wp-mail.php to
     5 * trigger the "wp-mail.php" action, you should trigger it
     6 * yourself, either in a plugin/theme hook or via wp_cron.
     7 *
     8 * For more information:
     9 * http://wordpress.org/plugins/post-by-email/
     10 * http://codex.wordpress.org/Category:WP-Cron_Functions
    611 *
    712 * @package WordPress
    813 */
     
    1015/** Make sure that the WordPress bootstrap has run before continuing. */
    1116require(dirname(__FILE__) . '/wp-load.php');
    1217
    13 /** This filter is documented in wp-admin/options.php */
    14 if ( ! apply_filters( 'enable_post_by_email_configuration', true ) )
    15         wp_die( __( 'This action has been disabled by the administrator.' ) );
    16 
    17 /**
     18/** Show an error in debug mode if this file is loaded directly.  **/
     19_doing_it_wrong( 'wp-mail.php', __( "This file is deprecated and should not be called directly.  Schedule the action 'wp-mail.php' instead." ), '3.8' );
     20 
     21 /**
    1822 * Fires to allow a plugin to do a complete takeover of Post by Email.
    1923 *
    2024 * @since 2.9.0
    2125 */
    22 do_action( 'wp-mail.php' );
    23 
    24 /** Get the POP3 class with which to access the mailbox. */
    25 require_once( ABSPATH . WPINC . '/class-pop3.php' );
    26 
    27 /** Only check at this interval for new messages. */
    28 if ( !defined('WP_MAIL_INTERVAL') )
    29         define('WP_MAIL_INTERVAL', 300); // 5 minutes
    30 
    31 $last_checked = get_transient('mailserver_last_checked');
    32 
    33 if ( $last_checked )
    34         wp_die(__('Slow down cowboy, no need to check for new mails so often!'));
    35 
    36 set_transient('mailserver_last_checked', true, WP_MAIL_INTERVAL);
    37 
    38 $time_difference = get_option('gmt_offset') * HOUR_IN_SECONDS;
    39 
    40 $phone_delim = '::';
    41 
    42 $pop3 = new POP3();
    43 
    44 if ( !$pop3->connect( get_option('mailserver_url'), get_option('mailserver_port') ) || !$pop3->user( get_option('mailserver_login') ) )
    45         wp_die( esc_html( $pop3->ERROR ) );
    46 
    47 $count = $pop3->pass( get_option('mailserver_pass') );
    48 
    49 if( false === $count )
    50         wp_die( esc_html( $pop3->ERROR ) );
    51 
    52 if( 0 === $count ) {
    53         $pop3->quit();
    54         wp_die( __('There doesn&#8217;t seem to be any new mail.') );
    55 }
    56 
    57 for ( $i = 1; $i <= $count; $i++ ) {
    58 
    59         $message = $pop3->get($i);
    60 
    61         $bodysignal = false;
    62         $boundary = '';
    63         $charset = '';
    64         $content = '';
    65         $content_type = '';
    66         $content_transfer_encoding = '';
    67         $post_author = 1;
    68         $author_found = false;
    69         $dmonths = array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
    70         foreach ($message as $line) {
    71                 // body signal
    72                 if ( strlen($line) < 3 )
    73                         $bodysignal = true;
    74                 if ( $bodysignal ) {
    75                         $content .= $line;
    76                 } else {
    77                         if ( preg_match('/Content-Type: /i', $line) ) {
    78                                 $content_type = trim($line);
    79                                 $content_type = substr($content_type, 14, strlen($content_type) - 14);
    80                                 $content_type = explode(';', $content_type);
    81                                 if ( ! empty( $content_type[1] ) ) {
    82                                         $charset = explode('=', $content_type[1]);
    83                                         $charset = ( ! empty( $charset[1] ) ) ? trim($charset[1]) : '';
    84                                 }
    85                                 $content_type = $content_type[0];
    86                         }
    87                         if ( preg_match('/Content-Transfer-Encoding: /i', $line) ) {
    88                                 $content_transfer_encoding = trim($line);
    89                                 $content_transfer_encoding = substr($content_transfer_encoding, 27, strlen($content_transfer_encoding) - 27);
    90                                 $content_transfer_encoding = explode(';', $content_transfer_encoding);
    91                                 $content_transfer_encoding = $content_transfer_encoding[0];
    92                         }
    93                         if ( ( $content_type == 'multipart/alternative' ) && ( false !== strpos($line, 'boundary="') ) && ( '' == $boundary ) ) {
    94                                 $boundary = trim($line);
    95                                 $boundary = explode('"', $boundary);
    96                                 $boundary = $boundary[1];
    97                         }
    98                         if (preg_match('/Subject: /i', $line)) {
    99                                 $subject = trim($line);
    100                                 $subject = substr($subject, 9, strlen($subject) - 9);
    101                                 // Captures any text in the subject before $phone_delim as the subject
    102                                 if ( function_exists('iconv_mime_decode') ) {
    103                                         $subject = iconv_mime_decode($subject, 2, get_option('blog_charset'));
    104                                 } else {
    105                                         $subject = wp_iso_descrambler($subject);
    106                                 }
    107                                 $subject = explode($phone_delim, $subject);
    108                                 $subject = $subject[0];
    109                         }
    110 
    111                         // Set the author using the email address (From or Reply-To, the last used)
    112                         // otherwise use the site admin
    113                         if ( ! $author_found && preg_match( '/^(From|Reply-To): /', $line ) ) {
    114                                 if ( preg_match('|[a-z0-9_.-]+@[a-z0-9_.-]+(?!.*<)|i', $line, $matches) )
    115                                         $author = $matches[0];
    116                                 else
    117                                         $author = trim($line);
    118                                 $author = sanitize_email($author);
    119                                 if ( is_email($author) ) {
    120                                         echo '<p>' . sprintf(__('Author is %s'), $author) . '</p>';
    121                                         $userdata = get_user_by('email', $author);
    122                                         if ( ! empty( $userdata ) ) {
    123                                                 $post_author = $userdata->ID;
    124                                                 $author_found = true;
    125                                         }
    126                                 }
    127                         }
    128 
    129                         if (preg_match('/Date: /i', $line)) { // of the form '20 Mar 2002 20:32:37'
    130                                 $ddate = trim($line);
    131                                 $ddate = str_replace('Date: ', '', $ddate);
    132                                 if (strpos($ddate, ',')) {
    133                                         $ddate = trim(substr($ddate, strpos($ddate, ',') + 1, strlen($ddate)));
    134                                 }
    135                                 $date_arr = explode(' ', $ddate);
    136                                 $date_time = explode(':', $date_arr[3]);
    137 
    138                                 $ddate_H = $date_time[0];
    139                                 $ddate_i = $date_time[1];
    140                                 $ddate_s = $date_time[2];
    141 
    142                                 $ddate_m = $date_arr[1];
    143                                 $ddate_d = $date_arr[0];
    144                                 $ddate_Y = $date_arr[2];
    145                                 for ( $j = 0; $j < 12; $j++ ) {
    146                                         if ( $ddate_m == $dmonths[$j] ) {
    147                                                 $ddate_m = $j+1;
    148                                         }
    149                                 }
    150 
    151                                 $time_zn = intval($date_arr[4]) * 36;
    152                                 $ddate_U = gmmktime($ddate_H, $ddate_i, $ddate_s, $ddate_m, $ddate_d, $ddate_Y);
    153                                 $ddate_U = $ddate_U - $time_zn;
    154                                 $post_date = gmdate('Y-m-d H:i:s', $ddate_U + $time_difference);
    155                                 $post_date_gmt = gmdate('Y-m-d H:i:s', $ddate_U);
    156                         }
    157                 }
    158         }
    159 
    160         // Set $post_status based on $author_found and on author's publish_posts capability
    161         if ( $author_found ) {
    162                 $user = new WP_User($post_author);
    163                 $post_status = ( $user->has_cap('publish_posts') ) ? 'publish' : 'pending';
    164         } else {
    165                 // Author not found in DB, set status to pending. Author already set to admin.
    166                 $post_status = 'pending';
    167         }
    168 
    169         $subject = trim($subject);
    170 
    171         if ( $content_type == 'multipart/alternative' ) {
    172                 $content = explode('--'.$boundary, $content);
    173                 $content = $content[2];
    174                 // match case-insensitive content-transfer-encoding
    175                 if ( preg_match( '/Content-Transfer-Encoding: quoted-printable/i', $content, $delim) ) {
    176                         $content = explode($delim[0], $content);
    177                         $content = $content[1];
    178                 }
    179                 $content = strip_tags($content, '<img><p><br><i><b><u><em><strong><strike><font><span><div>');
    180         }
    181         $content = trim($content);
    182 
    183         /**
    184          * Filter the original content of the email.
    185          *
    186          * Give Post-By-Email extending plugins full access to the content, either
    187          * the raw content, or the content of the last quoted-printable section.
    188          *
    189          * @since 2.8.0
    190          *
    191          * @param string $content The original email content.
    192          */
    193         $content = apply_filters( 'wp_mail_original_content', $content );
    194 
    195         if ( false !== stripos($content_transfer_encoding, "quoted-printable") ) {
    196                 $content = quoted_printable_decode($content);
    197         }
    198 
    199         if ( function_exists('iconv') && ! empty( $charset ) ) {
    200                 $content = iconv($charset, get_option('blog_charset'), $content);
    201         }
    202 
    203         // Captures any text in the body after $phone_delim as the body
    204         $content = explode($phone_delim, $content);
    205         $content = empty( $content[1] ) ? $content[0] : $content[1];
    206 
    207         $content = trim($content);
    208 
    209         /**
    210          * Filter the content of the post submitted by email before saving.
    211          *
    212          * @since 1.2.0
    213          *
    214          * @param string $content The email content.
    215          */
    216         $post_content = apply_filters( 'phone_content', $content );
    217 
    218         $post_title = xmlrpc_getposttitle($content);
    219 
    220         if ($post_title == '') $post_title = $subject;
    221 
    222         $post_category = array(get_option('default_email_category'));
    223 
    224         $post_data = compact('post_content','post_title','post_date','post_date_gmt','post_author','post_category', 'post_status');
    225         $post_data = wp_slash($post_data);
    226 
    227         $post_ID = wp_insert_post($post_data);
    228         if ( is_wp_error( $post_ID ) )
    229                 echo "\n" . $post_ID->get_error_message();
    230 
    231         // We couldn't post, for whatever reason. Better move forward to the next email.
    232         if ( empty( $post_ID ) )
    233                 continue;
    234 
    235         /**
    236          * Fires after a post submitted by email is published.
    237          *
    238          * @since 1.2.0
    239          *
    240          * @param int $post_ID The post ID.
    241          */
    242         do_action( 'publish_phone', $post_ID );
    243 
    244         echo "\n<p>" . sprintf(__('<strong>Author:</strong> %s'), esc_html($post_author)) . '</p>';
    245         echo "\n<p>" . sprintf(__('<strong>Posted title:</strong> %s'), esc_html($post_title)) . '</p>';
    246 
    247         if(!$pop3->delete($i)) {
    248                 echo '<p>' . sprintf(__('Oops: %s'), esc_html($pop3->ERROR)) . '</p>';
    249                 $pop3->reset();
    250                 exit;
    251         } else {
    252                 echo '<p>' . sprintf(__('Mission complete. Message <strong>%s</strong> deleted.'), $i) . '</p>';
    253         }
    254 
    255 }
    256 
    257 $pop3->quit();
     26do_action( 'wp-mail.php' );
     27 No newline at end of file