diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php index 64b4ce28f1..b0ba186a02 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php @@ -206,7 +206,7 @@ class WP_REST_Pattern_Directory_Controller extends WP_REST_Controller { 'title' => sanitize_text_field( $raw_pattern->title->rendered ), 'content' => wp_kses_post( $raw_pattern->pattern_content ), 'categories' => array_map( 'sanitize_title', $raw_pattern->category_slugs ), - 'keywords' => array_map( 'sanitize_title', $raw_pattern->keyword_slugs ), + 'keywords' => array_map( 'sanitize_text_field', explode( ',', $raw_pattern->meta->wpop_keywords ) ), 'description' => sanitize_text_field( $raw_pattern->meta->wpop_description ), 'viewport_width' => absint( $raw_pattern->meta->wpop_viewport_width ), ); @@ -274,7 +274,7 @@ class WP_REST_Pattern_Directory_Controller extends WP_REST_Controller { ), 'keywords' => array( - 'description' => __( "The pattern's keyword slugs." ), + 'description' => __( "The pattern's keywords." ), 'type' => 'array', 'uniqueItems' => true, 'items' => array( 'type' => 'string' ), diff --git a/tests/phpunit/data/blocks/pattern-directory/browse-all.json b/tests/phpunit/data/blocks/pattern-directory/browse-all.json index 26131e33bb..8d0d2d4ba3 100644 --- a/tests/phpunit/data/blocks/pattern-directory/browse-all.json +++ b/tests/phpunit/data/blocks/pattern-directory/browse-all.json @@ -9,6 +9,7 @@ "meta": { "spay_email": "", "wpop_description": "A heading preceded by a chapter number, and followed by a paragraph.", + "wpop_keywords": "blog post", "wpop_viewport_width": 1000 }, "category_slugs": [ "text" ], @@ -25,6 +26,7 @@ "meta": { "spay_email": "", "wpop_description": "A large hero section with an example background image and a heading in the center.", + "wpop_keywords": "header, hero", "wpop_viewport_width": 1000 }, "category_slugs": [ "header" ], @@ -41,6 +43,7 @@ "meta": { "spay_email": "", "wpop_description": "A large hero section with a bright gradient background, a big heading and a filled button.", + "wpop_keywords": "call to action, hero section", "wpop_viewport_width": 1000 }, "category_slugs": [ "header" ], diff --git a/tests/phpunit/data/blocks/pattern-directory/browse-category-2.json b/tests/phpunit/data/blocks/pattern-directory/browse-category-2.json index 947da16bfd..1fce1a0f80 100644 --- a/tests/phpunit/data/blocks/pattern-directory/browse-category-2.json +++ b/tests/phpunit/data/blocks/pattern-directory/browse-category-2.json @@ -9,6 +9,7 @@ "meta": { "spay_email": "", "wpop_description": "Three filled buttons with rounded corners, side by side.", + "wpop_keywords": "", "wpop_viewport_width": 600 }, "category_slugs": [ "buttons" ], @@ -25,6 +26,7 @@ "meta": { "spay_email": "", "wpop_description": "Two buttons, one filled and one outlined, side by side.", + "wpop_keywords": "", "wpop_viewport_width": 500 }, "category_slugs": [ "buttons" ], diff --git a/tests/phpunit/data/blocks/pattern-directory/browse-keyword-11.json b/tests/phpunit/data/blocks/pattern-directory/browse-keyword-11.json index 26131e33bb..383d7eff61 100644 --- a/tests/phpunit/data/blocks/pattern-directory/browse-keyword-11.json +++ b/tests/phpunit/data/blocks/pattern-directory/browse-keyword-11.json @@ -9,6 +9,7 @@ "meta": { "spay_email": "", "wpop_description": "A heading preceded by a chapter number, and followed by a paragraph.", + "wpop_keywords": "", "wpop_viewport_width": 1000 }, "category_slugs": [ "text" ], @@ -25,6 +26,7 @@ "meta": { "spay_email": "", "wpop_description": "A large hero section with an example background image and a heading in the center.", + "wpop_keywords": "", "wpop_viewport_width": 1000 }, "category_slugs": [ "header" ], @@ -41,6 +43,7 @@ "meta": { "spay_email": "", "wpop_description": "A large hero section with a bright gradient background, a big heading and a filled button.", + "wpop_keywords": "", "wpop_viewport_width": 1000 }, "category_slugs": [ "header" ], diff --git a/tests/phpunit/data/blocks/pattern-directory/search-button.json b/tests/phpunit/data/blocks/pattern-directory/search-button.json index b135e0ac5a..10e5c6036f 100644 --- a/tests/phpunit/data/blocks/pattern-directory/search-button.json +++ b/tests/phpunit/data/blocks/pattern-directory/search-button.json @@ -9,6 +9,7 @@ "meta": { "spay_email": "", "wpop_description": "A large hero section with a bright gradient background, a big heading and a filled button.", + "wpop_keywords": "", "wpop_viewport_width": 1000 }, "category_slugs": [ "header" ], @@ -25,6 +26,7 @@ "meta": { "spay_email": "", "wpop_description": "Three small columns of text, each with an outlined button with rounded corners at the bottom.", + "wpop_keywords": "", "wpop_viewport_width": 1000 }, "category_slugs": [ "columns" ], @@ -41,6 +43,7 @@ "meta": { "spay_email": "", "wpop_description": "Three filled buttons with rounded corners, side by side.", + "wpop_keywords": "", "wpop_viewport_width": 600 }, "category_slugs": [ "buttons" ], @@ -57,6 +60,7 @@ "meta": { "spay_email": "", "wpop_description": "Two buttons, one filled and one outlined, side by side.", + "wpop_keywords": "", "wpop_viewport_width": 500 }, "category_slugs": [ "buttons" ], diff --git a/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php b/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php index 43ca497edb..8c6e79f7a8 100644 --- a/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php +++ b/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php @@ -111,6 +111,9 @@ class WP_REST_Pattern_Directory_Controller_Test extends WP_Test_REST_Controller_ $this->assertGreaterThan( 0, count( $patterns ) ); array_walk( $patterns, array( $this, 'assertPatternMatchesSchema' ) ); + $this->assertSame( array( 'blog post' ), $patterns[0]['keywords'] ); + $this->assertSame( array( 'header', 'hero' ), $patterns[1]['keywords'] ); + $this->assertSame( array( 'call to action', 'hero section' ), $patterns[2]['keywords'] ); } /** @@ -157,10 +160,6 @@ class WP_REST_Pattern_Directory_Controller_Test extends WP_Test_REST_Controller_ $this->assertGreaterThan( 0, count( $patterns ) ); array_walk( $patterns, array( $this, 'assertPatternMatchesSchema' ) ); - - foreach ( $patterns as $pattern ) { - $this->assertContains( 'core', $pattern['keywords'] ); - } } /**