Make WordPress Core

Changeset 36848


Ignore:
Timestamp:
03/04/2016 06:55:23 PM (9 years ago)
Author:
azaozz
Message:

Pres This:

  • Change the newly added press_this_save_post_content filter to press_this_save_post and pass the $post_data array to it.
  • Remove the newly added press_this_useful_html_elements. It only runs in compatibility mode when a URL is typed by the user.
  • Remove the press_this_suggested_content filter. It is redundant as the suggested HTML for the editor is already filtered by press_this_suggested_html.
  • Add some more inline docs and rename couple of vars to make the code more readable.

Fixes #34455.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-press-this.php

    r36819 r36848  
    113113        }
    114114
    115         $post = array(
     115        $post_data = array(
    116116            'ID'            => $post_id,
    117117            'post_title'    => ( ! empty( $_POST['post_title'] ) ) ? sanitize_text_field( trim( $_POST['post_title'] ) ) : '',
     
    126126        if ( ! empty( $_POST['post_status'] ) && 'publish' === $_POST['post_status'] ) {
    127127            if ( current_user_can( 'publish_posts' ) ) {
    128                 $post['post_status'] = 'publish';
     128                $post_data['post_status'] = 'publish';
    129129            } else {
    130                 $post['post_status'] = 'pending';
    131             }
    132         }
    133 
    134         $post['post_content'] = $this->side_load_images( $post_id, $post['post_content'] );
     130                $post_data['post_status'] = 'pending';
     131            }
     132        }
     133
     134        $post_data['post_content'] = $this->side_load_images( $post_id, $post_data['post_content'] );
    135135
    136136        /**
    137          * Filter the post_content of a Press This post before saving/updating, after
     137         * Filter the post data of a Press This post before saving/updating, after
    138138         * side_load_images action had run.
    139139         *
    140140         * @since 4.5.0
    141141         *
    142          * @param string $content Content after side_load_images process.
    143          * @param int    $post_id Post ID.
     142         * @param array $post_data The post data.
    144143         */
    145         $post['post_content'] = apply_filters( 'press_this_save_post_content', $post['post_content'], $post_id );
    146 
    147         $updated = wp_update_post( $post, true );
     144        $post_data = apply_filters( 'press_this_save_post', $post_data );
     145
     146        $updated = wp_update_post( $post_data, true );
    148147
    149148        if ( is_wp_error( $updated ) ) {
    150149            wp_send_json_error( array( 'errorMessage' => $updated->get_error_message() ) );
    151150        } else {
    152             if ( isset( $post['post_format'] ) ) {
    153                 if ( current_theme_supports( 'post-formats', $post['post_format'] ) ) {
    154                     set_post_format( $post_id, $post['post_format'] );
    155                 } elseif ( $post['post_format'] ) {
     151            if ( isset( $post_data['post_format'] ) ) {
     152                if ( current_theme_supports( 'post-formats', $post_data['post_format'] ) ) {
     153                    set_post_format( $post_id, $post_data['post_format'] );
     154                } elseif ( $post_data['post_format'] ) {
    156155                    set_post_format( $post_id, false );
    157156                }
     
    179178             * @param string $status  Post status.
    180179             */
    181             $redirect = apply_filters( 'press_this_save_redirect', $redirect, $post_id, $post['post_status'] );
     180            $redirect = apply_filters( 'press_this_save_redirect', $redirect, $post_id, $post_data['post_status'] );
    182181
    183182            if ( $redirect ) {
     
    284283        }
    285284
    286         $useful_html_elements = array(
     285        $allowed_elements = array(
    287286            'img' => array(
    288287                'src'      => true,
     
    305304        );
    306305
    307         /**
    308          * Filter 'useful' HTML elements list for fetch source step.
    309          *
    310          * @since 4.5.0
    311          *
    312          * @param array $useful_html_elements Default list of useful elements.
    313          */
    314         $useful_html_elements = apply_filter( 'press_this_useful_html_elements', $useful_html_elements );
    315 
    316306        $source_content = wp_remote_retrieve_body( $remote_url );
    317         $source_content = wp_kses( $source_content, $useful_html_elements );
     307        $source_content = wp_kses( $source_content, $allowed_elements );
    318308
    319309        return $source_content;
     
    11821172
    11831173        /**
    1184          * Filter the default HTML for the Press This editor.
     1174         * Filter the default HTML tags used in the suggested content for the editor.
     1175         *
     1176         * The HTML strings use printf format. After filtering the content is added at the specified places with `sprintf()`.
    11851177         *
    11861178         * @since 4.2.0
    11871179         *
    1188          * @param array $default_html Associative array with two keys: 'quote' where %1$s is replaced with the site description
    1189          *                            or the selected content, and 'link' there %1$s is link href, %2$s is link text.
     1180         * @param array $default_html Associative array with three possible keys:
     1181         *                                - 'quote' where %1$s is replaced with the site description or the selected content.
     1182         *                                - 'link' where %1$s is link href, %2$s is link text, usually the source page title.
     1183         *                                - 'embed' which contains an [embed] shortcode when the source page offers embeddable content.
     1184         * @param array $data         Associative array containing the data from the source page.
    11901185         */
    11911186        $default_html = apply_filters( 'press_this_suggested_html', $default_html, $data );
     
    12131208            }
    12141209        }
    1215 
    1216         /**
    1217          * Filter the assembled HTML for the Press This editor.
    1218          *
    1219          * @since 4.5.0
    1220          *
    1221          * @param string $content Assembled end output of suggested content for the Press This editor.
    1222          */
    1223         $content = apply_filters( 'press_this_suggested_content', $content );
    12241210
    12251211        return $content;
Note: See TracChangeset for help on using the changeset viewer.