WordPress.org

Make WordPress Core

Changeset 36672


Ignore:
Timestamp:
02/24/16 03:55:21 (16 months ago)
Author:
jorbin
Message:

Add Additional filters to Press This

3 new filters that aim to improve the extensibility of Press This:
1) press_this_save_post_content - Applied right after the side_load_images in order to allow potential side loads of other types of media.
Example use case: side load non-image media, such as audio or video.

2) press_this_useful_html_elements
Allows filtering of currently hard coded array of HTML elements allowed in fetch_source_html step for special cases where additional HTML elements need to be kept.
Example use case: HTML5 elements, such as amp-img, that someone wants to pull in.

3) press_this_suggested_content
A filter for the content right before it's passed to the editor and presented to the user.
Example use case is when someone stored posts in a different, non-HTML format, such as Markdown, this is essential.

Fixes #34455.
Props cadeyrn, kraftbj

File:
1 edited

Legend:

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

    r35974 r36672  
    9292        } 
    9393 
    94         // Edxpected slashed 
     94        // Expected slashed 
    9595        return wp_slash( $content ); 
    9696    } 
     
    133133 
    134134        $post['post_content'] = $this->side_load_images( $post_id, $post['post_content'] ); 
     135 
     136        /** 
     137         * Filter the post_content of a Press This post before saving/updating, after 
     138         * side_load_images action had run. 
     139         * 
     140         * @since 4.5.0 
     141         * 
     142         * @param string $content Content after side_load_images process. 
     143         * @param int    $post_id Post ID. 
     144         */ 
     145        $post['post_content'] = apply_filters( 'press_this_save_post_content', $post['post_content'], $post_id ); 
    135146 
    136147        $updated = wp_update_post( $post, true ); 
     
    293304            ) 
    294305        ); 
     306 
     307        /** 
     308         * Filter 'useful' HTML elements list for fetch source step. 
     309         * 
     310         * @since 4.5.0 
     311         * 
     312         * @param array $elements Default list of useful elements. 
     313         */ 
     314        $useful_html_elements = apply_filter( 'press_this_useful_html_elements', $useful_html_elements ); 
    295315 
    296316        $source_content = wp_remote_retrieve_body( $remote_url ); 
     
    11931213            } 
    11941214        } 
     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 ); 
    11951224 
    11961225        return $content; 
Note: See TracChangeset for help on using the changeset viewer.