Make WordPress Core

Changeset 53674


Ignore:
Timestamp:
07/06/2022 04:18:24 PM (2 years ago)
Author:
SergeyBiryukov
Message:

Block Patterns: Update the value used for keywords.

Patterns on the Pattern Directory can have keywords for better discoverability while searching. The way these are stored was changed from a taxonomy to meta value, but the /wp/v2/pattern-directory/patterns endpoint was still pulling from that old value.

The correct property to use for this field is meta.wpop_keywords, which returns a single string with comma-separated keywords.

Follow-up to [51021].

Props ryelle, TimothyBlynJacobs.
Merges [53665] to the 5.9 branch.
See #56126.

Location:
branches/5.9
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/5.9

  • branches/5.9/src/wp-includes/rest-api/endpoints/class-wp-rest-pattern-directory-controller.php

    r52236 r53674  
    214214            'content'        => wp_kses_post( $raw_pattern->pattern_content ),
    215215            'categories'     => array_map( 'sanitize_title', $raw_pattern->category_slugs ),
    216             'keywords'       => array_map( 'sanitize_title', $raw_pattern->keyword_slugs ),
     216            'keywords'       => array_map( 'sanitize_text_field', explode( ',', $raw_pattern->meta->wpop_keywords ) ),
    217217            'description'    => sanitize_text_field( $raw_pattern->meta->wpop_description ),
    218218            'viewport_width' => absint( $raw_pattern->meta->wpop_viewport_width ),
     
    282282
    283283                'keywords'       => array(
    284                     'description' => __( "The pattern's keyword slugs." ),
     284                    'description' => __( "The pattern's keywords." ),
    285285                    'type'        => 'array',
    286286                    'uniqueItems' => true,
  • branches/5.9/tests/phpunit/data/blocks/pattern-directory/browse-all.json

    r51021 r53674  
    1010            "spay_email": "",
    1111            "wpop_description": "A heading preceded by a chapter number, and followed by a paragraph.",
     12            "wpop_keywords": "blog post",
    1213            "wpop_viewport_width": 1000
    1314        },
     
    2627            "spay_email": "",
    2728            "wpop_description": "A large hero section with an example background image and a heading in the center.",
     29            "wpop_keywords": "header, hero",
    2830            "wpop_viewport_width": 1000
    2931        },
     
    4244            "spay_email": "",
    4345            "wpop_description": "A large hero section with a bright gradient background, a big heading and a filled button.",
     46            "wpop_keywords": "call to action, hero section",
    4447            "wpop_viewport_width": 1000
    4548        },
  • branches/5.9/tests/phpunit/data/blocks/pattern-directory/browse-category-2.json

    r51021 r53674  
    1010            "spay_email": "",
    1111            "wpop_description": "Three filled buttons with rounded corners, side by side.",
     12            "wpop_keywords": "",
    1213            "wpop_viewport_width": 600
    1314        },
     
    2627            "spay_email": "",
    2728            "wpop_description": "Two buttons, one filled and one outlined, side by side.",
     29            "wpop_keywords": "",
    2830            "wpop_viewport_width": 500
    2931        },
  • branches/5.9/tests/phpunit/data/blocks/pattern-directory/browse-keyword-11.json

    r51021 r53674  
    1010            "spay_email": "",
    1111            "wpop_description": "A heading preceded by a chapter number, and followed by a paragraph.",
     12            "wpop_keywords": "",
    1213            "wpop_viewport_width": 1000
    1314        },
     
    2627            "spay_email": "",
    2728            "wpop_description": "A large hero section with an example background image and a heading in the center.",
     29            "wpop_keywords": "",
    2830            "wpop_viewport_width": 1000
    2931        },
     
    4244            "spay_email": "",
    4345            "wpop_description": "A large hero section with a bright gradient background, a big heading and a filled button.",
     46            "wpop_keywords": "",
    4447            "wpop_viewport_width": 1000
    4548        },
  • branches/5.9/tests/phpunit/data/blocks/pattern-directory/search-button.json

    r51021 r53674  
    1010            "spay_email": "",
    1111            "wpop_description": "A large hero section with a bright gradient background, a big heading and a filled button.",
     12            "wpop_keywords": "",
    1213            "wpop_viewport_width": 1000
    1314        },
     
    2627            "spay_email": "",
    2728            "wpop_description": "Three small columns of text, each with an outlined button with rounded corners at the bottom.",
     29            "wpop_keywords": "",
    2830            "wpop_viewport_width": 1000
    2931        },
     
    4244            "spay_email": "",
    4345            "wpop_description": "Three filled buttons with rounded corners, side by side.",
     46            "wpop_keywords": "",
    4447            "wpop_viewport_width": 600
    4548        },
     
    5861            "spay_email": "",
    5962            "wpop_description": "Two buttons, one filled and one outlined, side by side.",
     63            "wpop_keywords": "",
    6064            "wpop_viewport_width": 500
    6165        },
  • branches/5.9/tests/phpunit/tests/rest-api/rest-pattern-directory-controller.php

    r51657 r53674  
    101101
    102102        array_walk( $patterns, array( $this, 'assertPatternMatchesSchema' ) );
     103        $this->assertSame( array( 'blog post' ), $patterns[0]['keywords'] );
     104        $this->assertSame( array( 'header', 'hero' ), $patterns[1]['keywords'] );
     105        $this->assertSame( array( 'call to action', 'hero section' ), $patterns[2]['keywords'] );
    103106    }
    104107
     
    147150
    148151        array_walk( $patterns, array( $this, 'assertPatternMatchesSchema' ) );
    149 
    150         foreach ( $patterns as $pattern ) {
    151             $this->assertContains( 'core', $pattern['keywords'] );
    152         }
    153152    }
    154153
Note: See TracChangeset for help on using the changeset viewer.