@@ -1976,6 +1976,8 @@ public function block( $args, $assoc_args ) {
1976
1976
? $ assoc_args ['slug ' ]
1977
1977
: sanitize_title ( $ title );
1978
1978
1979
+ $ next_version = "\x24\x24next-version$$ " ; // Escapes to hide the string from tools/replace-next-version-tag.sh
1980
+
1979
1981
$ variation_options = array ( 'production ' , 'experimental ' , 'beta ' );
1980
1982
$ variation = ( isset ( $ assoc_args ['variation ' ] ) && in_array ( $ assoc_args ['variation ' ], $ variation_options , true ) )
1981
1983
? $ assoc_args ['variation ' ]
@@ -2004,56 +2006,51 @@ public function block( $args, $assoc_args ) {
2004
2006
2005
2007
$ wp_filesystem ->mkdir ( $ path );
2006
2008
2007
- $ has_keywords = isset ( $ assoc_args ['keywords ' ] );
2009
+ $ keywords = isset ( $ assoc_args ['keywords ' ] )
2010
+ ? array_map (
2011
+ function ( $ keyword ) {
2012
+ return trim ( $ keyword );
2013
+ },
2014
+ array_slice ( explode ( ', ' , $ assoc_args ['keywords ' ] ), 0 , 3 )
2015
+ )
2016
+ : array ();
2008
2017
2009
2018
$ files = array (
2010
- "$ path/ $ slug .php " => self ::render_block_file (
2011
- 'block-register-php ' ,
2019
+ "$ path/block.json " => self ::render_block_file (
2020
+ 'block-block-json ' ,
2012
2021
array (
2013
- 'nextVersion ' => "\x24\x24next-version$$ " , // Escapes to hide the string from tools/replace-next-version-tag.sh
2014
- 'slug ' => $ slug ,
2015
- 'title ' => $ title ,
2016
- 'underscoredSlug ' => str_replace ( '- ' , '_ ' , $ slug ),
2017
- 'underscoredTitle ' => str_replace ( ' ' , '_ ' , $ title ),
2022
+ 'slug ' => $ slug ,
2023
+ 'title ' => wp_json_encode ( $ title , JSON_UNESCAPED_UNICODE ),
2024
+ 'description ' => isset ( $ assoc_args ['description ' ] )
2025
+ ? wp_json_encode ( $ assoc_args ['description ' ], JSON_UNESCAPED_UNICODE )
2026
+ : wp_json_encode ( $ title , JSON_UNESCAPED_UNICODE ),
2027
+ 'nextVersion ' => $ next_version ,
2028
+ 'keywords ' => wp_json_encode ( $ keywords , JSON_UNESCAPED_UNICODE ),
2018
2029
)
2019
2030
),
2020
- "$ path/index.js " => self ::render_block_file (
2021
- 'block-index-js ' ,
2031
+ "$ path/ $ slug .php " => self ::render_block_file (
2032
+ 'block-register-php ' ,
2022
2033
array (
2023
- 'slug ' => $ slug ,
2024
- 'title ' => $ title ,
2025
- 'description ' => isset ( $ assoc_args ['description ' ] )
2026
- ? $ assoc_args ['description ' ]
2027
- : $ title ,
2028
- 'keywords ' => $ has_keywords
2029
- ? array_map (
2030
- function ( $ keyword ) {
2031
- // Construction necessary for Mustache lists.
2032
- return array ( 'keyword ' => trim ( $ keyword ) );
2033
- },
2034
- explode ( ', ' , $ assoc_args ['keywords ' ], 3 )
2035
- )
2036
- : '' ,
2037
- 'hasKeywords ' => $ has_keywords ,
2034
+ 'nextVersion ' => $ next_version ,
2035
+ 'title ' => $ title ,
2036
+ 'underscoredTitle ' => str_replace ( ' ' , '_ ' , $ title ),
2038
2037
)
2039
2038
),
2040
- "$ path/editor.js " => self ::render_block_file ( 'block-editor-js ' ),
2041
- "$ path/editor.scss " => self ::render_block_file (
2039
+ "$ path/editor.js " => self ::render_block_file ( 'block-editor-js ' ),
2040
+ "$ path/editor.scss " => self ::render_block_file (
2042
2041
'block-editor-scss ' ,
2043
2042
array (
2044
2043
'slug ' => $ slug ,
2045
2044
'title ' => $ title ,
2046
2045
)
2047
2046
),
2048
- "$ path/edit.js " => self ::render_block_file (
2047
+ "$ path/edit.js " => self ::render_block_file (
2049
2048
'block-edit-js ' ,
2050
2049
array (
2051
2050
'title ' => $ title ,
2052
2051
'className ' => str_replace ( ' ' , '' , ucwords ( str_replace ( '- ' , ' ' , $ slug ) ) ),
2053
2052
)
2054
2053
),
2055
- "$ path/icon.js " => self ::render_block_file ( 'block-icon-js ' ),
2056
- "$ path/attributes.js " => self ::render_block_file ( 'block-attributes-js ' ),
2057
2054
);
2058
2055
2059
2056
$ files_written = array ();
0 commit comments