Skip to content

Commit

Permalink
Editor: Cast the result of the default_content, default_title, an…
Browse files Browse the repository at this point in the history
…d `default_excerpt` filters.

If a plugin returns a non-string value (or returns `null`) on these filters, it can cause errors in the block editor. Casting them as a string prevents these errors.

Merges [43858] from the 5.0 branch to trunk.

Props dd32.
See #45236.


git-svn-id: https://develop.svn.wordpress.org/trunk@44224 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
jeremyfelt committed Dec 16, 2018
1 parent 3261d68 commit 7f2a7a3
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/wp-admin/includes/post.php
Expand Up @@ -683,7 +683,7 @@ function get_default_post_to_edit( $post_type = 'post', $create_in_db = false )
* @param string $post_content Default post content.
* @param WP_Post $post Post object.
*/
$post->post_content = apply_filters( 'default_content', $post_content, $post );
$post->post_content = (string) apply_filters( 'default_content', $post_content, $post );

/**
* Filters the default post title initially used in the "Write Post" form.
Expand All @@ -693,7 +693,7 @@ function get_default_post_to_edit( $post_type = 'post', $create_in_db = false )
* @param string $post_title Default post title.
* @param WP_Post $post Post object.
*/
$post->post_title = apply_filters( 'default_title', $post_title, $post );
$post->post_title = (string) apply_filters( 'default_title', $post_title, $post );

/**
* Filters the default post excerpt initially used in the "Write Post" form.
Expand All @@ -703,7 +703,7 @@ function get_default_post_to_edit( $post_type = 'post', $create_in_db = false )
* @param string $post_excerpt Default post excerpt.
* @param WP_Post $post Post object.
*/
$post->post_excerpt = apply_filters( 'default_excerpt', $post_excerpt, $post );
$post->post_excerpt = (string) apply_filters( 'default_excerpt', $post_excerpt, $post );

return $post;
}
Expand Down

0 comments on commit 7f2a7a3

Please sign in to comment.