Skip to content

Commit e04c89c

Browse files
Sanitize pattern titles and categories (#817)
* sanitized pattern and template variables * use sanitized string for pattern slug * escape the comment instead
1 parent 7549ecb commit e04c89c

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

includes/create-theme/theme-patterns.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
class CBT_Theme_Patterns {
44
public static function pattern_from_template( $template, $new_slug = null ) {
55
$theme_slug = $new_slug ? $new_slug : wp_get_theme()->get( 'TextDomain' );
6-
$pattern_slug = $theme_slug . '/' . $template->slug;
6+
$template_slug = str_replace( '*/', '*/', $template->slug );
7+
$pattern_slug = $theme_slug . '/' . $template_slug;
78
$pattern_content = <<<PHP
89
<?php
910
/**
10-
* Title: {$template->slug}
11+
* Title: {$template_slug}
1112
* Slug: {$pattern_slug}
1213
* Inserter: no
1314
*/
@@ -29,12 +30,14 @@ public static function pattern_from_wp_block( $pattern_post ) {
2930
$pattern->slug = wp_get_theme()->get( 'TextDomain' ) . '/' . $pattern->name;
3031
$pattern_category_list = get_the_terms( $pattern->id, 'wp_pattern_category' );
3132
$pattern->categories = ! empty( $pattern_category_list ) ? join( ', ', wp_list_pluck( $pattern_category_list, 'name' ) ) : '';
33+
$pattern_title = str_replace( '*/', '*&#47;', $pattern->title );
34+
$pattern_categories = str_replace( '*/', '*&#47;', $pattern->categories );
3235
$pattern->content = <<<PHP
3336
<?php
3437
/**
35-
* Title: {$pattern->title}
38+
* Title: {$pattern_title}
3639
* Slug: {$pattern->slug}
37-
* Categories: {$pattern->categories}
40+
* Categories: {$pattern_categories}
3841
*/
3942
?>
4043
{$pattern_post->post_content}

0 commit comments

Comments
 (0)