Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -398,16 +398,19 @@ function validate_block_directives( $prepared_post, $request ) {
return $prepared_post;
}

if ( ! isset( $prepared_post->post_content ) ) {
return $prepared_post;
}
// Every field the directory renders, not just the one the pattern editor writes.
foreach ( array( 'post_content', 'post_title', 'post_excerpt' ) as $field ) {
if ( ! isset( $prepared_post->$field ) ) {
continue;
}

if ( content_has_block_directives( $prepared_post->post_content ) ) {
return new \WP_Error(
'rest_pattern_interactivity_directive',
__( 'Pattern content contains interactivity directives, which are not allowed.', 'wporg-patterns' ),
array( 'status' => 400 )
);
if ( content_has_block_directives( $prepared_post->$field ) ) {
return new \WP_Error(
'rest_pattern_interactivity_directive',
__( 'Patterns cannot contain interactivity directives.', 'wporg-patterns' ),
array( 'status' => 400 )
Comment thread
obenland marked this conversation as resolved.
);
}
}

return $prepared_post;
Expand Down Expand Up @@ -841,6 +844,14 @@ function check_for_spam( $post ) {
* @return boolean
*/
function is_title_valid( $title ) {
if ( strip_shortcodes( $title ) !== $title || wp_strip_all_tags( $title ) !== $title ) {
return false;
}

if ( content_has_block_directives( $title ) ) {
return false;
}
Comment thread
obenland marked this conversation as resolved.

// Check title against a list of disallowed words.
// Note the space after `test ` to avoid matching "testimonial".
$disallow_list = array( 'test ', 'testing', 'my pattern', 'wordpress', 'example' );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ public function data_invalid_title() {
'rest_pattern_invalid_title',
array_merge( $defaults, array( 'title' => 'Test' ) ),
),
array(
'rest_pattern_invalid_title',
array_merge( $defaults, array( 'title' => 'Quote [caption width="1" caption="x"]y[/caption]' ) ),
),
array(
'rest_pattern_invalid_title',
array_merge( $defaults, array( 'title' => 'Quote <span>markup</span>' ) ),
),
array(
'rest_pattern_interactivity_directive',
array_merge( $defaults, array( 'title' => 'Quote <span data-wp-interactive="x">y</span>' ) ),
),
Comment thread
obenland marked this conversation as resolved.
);
}

Expand Down