From 5c9d92b7f86e006942dc8a7e9bdad993d7e27e62 Mon Sep 17 00:00:00 2001 From: Aaron Jorbin Date: Wed, 24 Feb 2016 03:56:24 +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 Built from https://develop.svn.wordpress.org/trunk@36672 git-svn-id: http://core.svn.wordpress.org/trunk@36639 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-admin/includes/class-wp-press-this.php | 31 ++++++++++++++++++++++- wp-includes/version.php | 2 +- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/wp-admin/includes/class-wp-press-this.php b/wp-admin/includes/class-wp-press-this.php index f65df283c0..0ccb9d7799 100644 --- a/wp-admin/includes/class-wp-press-this.php +++ b/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; } diff --git a/wp-includes/version.php b/wp-includes/version.php index 707e537cf0..6fa23c75c9 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -4,7 +4,7 @@ * * @global string $wp_version */ -$wp_version = '4.5-alpha-36671'; +$wp_version = '4.5-alpha-36672'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.