From 6165ea0b980e01e78618caa63fd4dd84a965c1a9 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Wed, 24 Feb 2016 03:55:21 +0000 Subject: [PATCH] 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 git-svn-id: https://develop.svn.wordpress.org/trunk@36672 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/class-wp-press-this.php | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/wp-admin/includes/class-wp-press-this.php b/src/wp-admin/includes/class-wp-press-this.php index f65df283c0..0ccb9d7799 100644 --- a/src/wp-admin/includes/class-wp-press-this.php +++ b/src/wp-admin/includes/class-wp-press-this.php @@ -91,7 +91,7 @@ class WP_Press_This { } } - // Edxpected slashed + // Expected slashed return wp_slash( $content ); } @@ -133,6 +133,17 @@ class WP_Press_This { $post['post_content'] = $this->side_load_images( $post_id, $post['post_content'] ); + /** + * Filter the post_content of a Press This post before saving/updating, after + * side_load_images action had run. + * + * @since 4.5.0 + * + * @param string $content Content after side_load_images process. + * @param int $post_id Post ID. + */ + $post['post_content'] = apply_filters( 'press_this_save_post_content', $post['post_content'], $post_id ); + $updated = wp_update_post( $post, true ); if ( is_wp_error( $updated ) ) { @@ -293,6 +304,15 @@ class WP_Press_This { ) ); + /** + * Filter 'useful' HTML elements list for fetch source step. + * + * @since 4.5.0 + * + * @param array $elements Default list of useful elements. + */ + $useful_html_elements = apply_filter( 'press_this_useful_html_elements', $useful_html_elements ); + $source_content = wp_remote_retrieve_body( $remote_url ); $source_content = wp_kses( $source_content, $useful_html_elements ); @@ -1193,6 +1213,15 @@ class WP_Press_This { } } + /** + * Filter the assembled HTML for the Press This editor. + * + * @since 4.5.0 + * + * @param string $content Assembled end output of suggested content for the Press This editor. + */ + $content = apply_filters( 'press_this_suggested_content', $content ); + return $content; }