Skip to content

Commit

Permalink
Use a filter instead of modifying each block.json file.
Browse files Browse the repository at this point in the history
  • Loading branch information
aristath committed Jun 7, 2021
1 parent c015795 commit 3a39cea
Show file tree
Hide file tree
Showing 40 changed files with 56 additions and 89 deletions.
23 changes: 22 additions & 1 deletion lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,5 +470,26 @@ function gutenberg_migrate_old_typography_shape( $metadata ) {
return $metadata;
}


add_filter( 'block_type_metadata', 'gutenberg_migrate_old_typography_shape' );

/**
* Filters the content of a single block.
*
* @param array $metadata Metadata for registering a block type.
*
* @return array Returns the $metadata with any missing `style` and `editorStyle` added.
*/
function gutenberg_add_missing_styles_to_core_block_json( $metadata ) {
if ( ! empty( $metadata['name'] ) && 0 === strpos( $metadata['name'], 'core/' ) ) {
$block_name = str_replace( 'core/', '', $metadata['name'] );

if ( ! isset( $metadata['style'] ) ) {
$metadata['style'] = "wp-block-$block_name";
}
if ( ! isset( $metadata['editorStyle'] ) ) {
$metadata['editorStyle'] = "wp-block-$block_name-editor";
}
}
return $metadata;
}
add_filter( 'block_type_metadata', 'gutenberg_add_missing_styles_to_core_block_json' );
3 changes: 1 addition & 2 deletions packages/block-library/src/archives/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@
"align": true,
"html": false
},
"editorStyle": "wp-block-archives-editor",
"style": "wp-block-archives"
"editorStyle": "wp-block-archives-editor"
}
3 changes: 1 addition & 2 deletions packages/block-library/src/block/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,5 @@
"html": false,
"inserter": false
},
"editorStyle": "wp-block-editor",
"style": "wp-block"
"editorStyle": "wp-block-editor"
}
1 change: 0 additions & 1 deletion packages/block-library/src/calendar/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
"supports": {
"align": true
},
"editorStyle": "wp-block-calendar-editor",
"style": "wp-block-calendar"
}
1 change: 0 additions & 1 deletion packages/block-library/src/code/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@
"fontSize": true
}
},
"editorStyle": "wp-block-code-editor",
"style": "wp-block-code"
}
4 changes: 1 addition & 3 deletions packages/block-library/src/column/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,5 @@
"spacing": {
"padding": true
}
},
"editorStyle": "wp-block-column-editor",
"style": "wp-block-column"
}
}
3 changes: 1 addition & 2 deletions packages/block-library/src/freeform/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
"customClassName": false,
"reusable": false
},
"editorStyle": "wp-block-freeform-editor",
"style": "wp-block-freeform"
"editorStyle": "wp-block-freeform-editor"
}
3 changes: 1 addition & 2 deletions packages/block-library/src/html/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
"className": false,
"html": false
},
"editorStyle": "wp-block-html-editor",
"style": "wp-block-html"
"editorStyle": "wp-block-html-editor"
}
3 changes: 1 addition & 2 deletions packages/block-library/src/legacy-widget/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@
"customClassName": false,
"reusable": false
},
"editorStyle": "wp-block-legacy-widget-editor",
"style": "wp-block-legacy-widget"
"editorStyle": "wp-block-legacy-widget-editor"
}
4 changes: 1 addition & 3 deletions packages/block-library/src/loginout/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@
"typography": {
"fontSize": false
}
},
"editorStyle": "wp-block-loginout-editor",
"style": "wp-block-loginout"
}
}
3 changes: 1 addition & 2 deletions packages/block-library/src/more/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
"html": false,
"multiple": false
},
"editorStyle": "wp-block-more-editor",
"style": "wp-block-more"
"editorStyle": "wp-block-more-editor"
}
3 changes: 1 addition & 2 deletions packages/block-library/src/nextpage/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,5 @@
"className": false,
"html": false
},
"editorStyle": "wp-block-nextpage-editor",
"style": "wp-block-nextpage"
"editorStyle": "wp-block-nextpage-editor"
}
4 changes: 1 addition & 3 deletions packages/block-library/src/post-comment-author/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@
"usesContext": [ "commentId" ],
"supports": {
"html": false
},
"editorStyle": "wp-block-post-comment-author-editor",
"style": "wp-block-post-comment-author"
}
}
4 changes: 1 addition & 3 deletions packages/block-library/src/post-comment-content/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,5 @@
"usesContext": [ "commentId" ],
"supports": {
"html": false
},
"editorStyle": "wp-block-post-comment-content-editor",
"style": "wp-block-post-comment-content"
}
}
4 changes: 1 addition & 3 deletions packages/block-library/src/post-comment-date/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,5 @@
"usesContext": [ "commentId" ],
"supports": {
"html": false
},
"editorStyle": "wp-block-post-comment-date-editor",
"style": "wp-block-post-comment-date"
}
}
4 changes: 1 addition & 3 deletions packages/block-library/src/post-comment/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@
},
"supports": {
"html": false
},
"editorStyle": "wp-block-post-comment-editor",
"style": "wp-block-post-comment"
}
}
4 changes: 1 addition & 3 deletions packages/block-library/src/post-comments-count/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@
"fontSize": true,
"lineHeight": true
}
},
"editorStyle": "wp-block-post-comments-count-editor",
"style": "wp-block-post-comments-count"
}
}
1 change: 0 additions & 1 deletion packages/block-library/src/post-comments-form/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,5 @@
"lineHeight": true
}
},
"editorStyle": "wp-block-post-comments-form-editor",
"style": "wp-block-post-comments-form"
}
4 changes: 1 addition & 3 deletions packages/block-library/src/post-comments-link/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,5 @@
"fontSize": true,
"lineHeight": true
}
},
"editorStyle": "wp-block-post-comments-link-editor",
"style": "wp-block-post-comments-link"
}
}
1 change: 0 additions & 1 deletion packages/block-library/src/post-comments/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,5 @@
"link": true
}
},
"editorStyle": "wp-block-post-comments-editor",
"style": "wp-block-post-comments"
}
3 changes: 1 addition & 2 deletions packages/block-library/src/post-content/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
"html": false,
"__experimentalLayout": true
},
"editorStyle": "wp-block-post-content-editor",
"style": "wp-block-post-content"
"editorStyle": "wp-block-post-content-editor"
}
4 changes: 1 addition & 3 deletions packages/block-library/src/post-date/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,5 @@
"fontSize": true,
"lineHeight": true
}
},
"editorStyle": "wp-block-post-date-editor",
"style": "wp-block-post-date"
}
}
4 changes: 1 addition & 3 deletions packages/block-library/src/post-navigation-link/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,5 @@
"supports": {
"reusable": false,
"html": false
},
"editorStyle": "wp-block-post-navigation-link-editor",
"style": "wp-block-post-navigation-link"
}
}
4 changes: 1 addition & 3 deletions packages/block-library/src/post-terms/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,5 @@
"lineHeight": true,
"fontSize": true
}
},
"editorStyle": "wp-block-post-terms-editor",
"style": "wp-block-post-terms"
}
}
1 change: 0 additions & 1 deletion packages/block-library/src/post-title/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,5 @@
"__experimentalFontFamily": true
}
},
"editorStyle": "wp-block-post-title-editor",
"style": "wp-block-post-title"
}
1 change: 0 additions & 1 deletion packages/block-library/src/preformatted/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@
"fontSize": true
}
},
"editorStyle": "wp-block-preformatted-editor",
"style": "wp-block-preformatted"
}
4 changes: 1 addition & 3 deletions packages/block-library/src/query-pagination-next/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@
"fontSize": true,
"lineHeight": true
}
},
"editorStyle": "wp-block-query-pagination-next-editor",
"style": "wp-block-query-pagination-next"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,5 @@
"reusable": false,
"html": false
},
"editorStyle": "wp-block-query-pagination-numbers-editor",
"style": "wp-block-query-pagination-numbers"
"editorStyle": "query-pagination-numbers-editor"
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,5 @@
"fontSize": true,
"lineHeight": true
}
},
"editorStyle": "wp-block-query-pagination-previous-editor",
"style": "wp-block-query-pagination-previous"
}
}
3 changes: 1 addition & 2 deletions packages/block-library/src/query-title/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,5 @@
"__experimentalFontFamily": true
}
},
"editorStyle": "wp-block-query-title-editor",
"style": "wp-block-query-title"
"editorStyle": "wp-block-query-title-editor"
}
3 changes: 1 addition & 2 deletions packages/block-library/src/query/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,5 @@
},
"__experimentalLayout": true
},
"editorStyle": "wp-block-query-editor",
"style": "wp-block-query"
"editorStyle": "wp-block-query-editor"
}
3 changes: 1 addition & 2 deletions packages/block-library/src/shortcode/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
"customClassName": false,
"html": false
},
"editorStyle": "wp-block-shortcode-editor",
"style": "wp-block-shortcode"
"editorStyle": "wp-block-shortcode-editor"
}
4 changes: 1 addition & 3 deletions packages/block-library/src/site-tagline/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,5 @@
"__experimentalTextTransform": true,
"__experimentalLetterSpacing": true
}
},
"editorStyle": "wp-block-site-tagline-editor",
"style": "wp-block-site-tagline"
}
}
4 changes: 1 addition & 3 deletions packages/block-library/src/site-title/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,5 @@
"__experimentalFontWeight": true,
"__experimentalLetterSpacing": true
}
},
"editorStyle": "wp-block-site-title-editor",
"style": "wp-block-site-title"
}
}
3 changes: 1 addition & 2 deletions packages/block-library/src/social-link/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,5 @@
"reusable": false,
"html": false
},
"editorStyle": "wp-block-social-link-editor",
"style": "wp-block-social-link"
"editorStyle": "wp-block-social-link-editor"
}
4 changes: 1 addition & 3 deletions packages/block-library/src/table-of-contents/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,5 @@
"usesContext": [ "postId" ],
"supports": {
"html": false
},
"editorStyle": "wp-block-table-of-contents-editor",
"style": "wp-block-table-of-contents"
}
}
3 changes: 1 addition & 2 deletions packages/block-library/src/tag-cloud/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,5 @@
"html": false,
"align": true
},
"editorStyle": "wp-block-tag-cloud-editor",
"style": "wp-block-tag-cloud"
"editorStyle": "wp-block-tag-cloud-editor"
}
3 changes: 1 addition & 2 deletions packages/block-library/src/template-part/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,5 @@
},
"__experimentalLayout": true
},
"editorStyle": "wp-block-template-part-editor",
"style": "wp-block-template-part"
"editorStyle": "wp-block-template-part-editor"
}
3 changes: 1 addition & 2 deletions packages/block-library/src/term-description/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,5 @@
"lineHeight": true
}
},
"editorStyle": "wp-block-term-description-editor",
"style": "wp-block-term-description"
"editorStyle": "wp-block-term-description-editor"
}
4 changes: 2 additions & 2 deletions packages/block-library/src/verse/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"padding": true
}
},
"editorStyle": "wp-block-verse-editor",
"style": "wp-block-verse"
"style": "wp-block-verse",
"editorStyle": "wp-block-verse-editor"
}

0 comments on commit 3a39cea

Please sign in to comment.