Repository navigation
Expand file tree
/
Copy pathblocks.php
More file actions
141 lines (120 loc) · 4.21 KB
/
Copy pathblocks.php
File metadata and controls
141 lines (120 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
/**
* File: blocks.php
*
* @package Pitchfork
*
*/
/**
* Unregisters a few of the WordPress native blocks that
* we will not be supporting in this theme.
*
* It fires after other plugins and the above block init function add their blocks
* to the WP registry. Using those entries, it filters the list, removing the unsupported
* blocks and returning a smaller array.
*
* Overwritable by a child theme.
*/
if ( ! function_exists( 'pitchfork_unregister_native_blocks' ) ) {
/**
* Gather the list of registered blocks, remove elements from the returned array.
*/
function pitchfork_unregister_native_blocks() {
// Get the list of registered blocks including those added by plugins.
$registered_blocks = WP_Block_Type_Registry::get_instance()->get_all_registered();
// Removing native blocks from the "text" category.
unset( $registered_blocks['core/pullquote'] );
unset( $registered_blocks['core/quote'] );
unset( $registered_blocks['core/preformatted'] );
unset( $registered_blocks['core/verse'] );
unset( $registered_blocks['core/accordion'] );
// Strip the array down to just the keys.
$registered_blocks = array_keys( $registered_blocks );
return $registered_blocks;
}
add_filter( 'allowed_block_types_all', 'pitchfork_unregister_native_blocks' );
}
// Deregister the core WordPress block patterns.
if ( ! function_exists( 'pitchfork_remove_core_patterns' ) ) {
/**
* Removes theme support for 'core-block-patterns', which removes
* ALL core block patterns from the editor.
*/
function pitchfork_remove_core_patterns() {
remove_theme_support( 'core-block-patterns' );
}
add_action( 'after_setup_theme', 'pitchfork_remove_core_patterns' );
}
// Register pattern categories at the correct time.
add_action( 'init', function () {
if ( ! function_exists( 'register_block_pattern_category' ) ) {
return; // Older WP; nothing to do.
}
register_block_pattern_category(
'pitchfork-card',
[ 'label' => __( 'Pitchfork: Cards', 'pitchfork' ) ]
);
register_block_pattern_category(
'pitchfork-card-layouts',
[ 'label' => __( 'Pitchfork: Card Layouts', 'pitchfork' ) ]
);
register_block_pattern_category(
'pitchfork-content',
[ 'label' => __( 'Pitchfork: Content', 'pitchfork' ) ]
);
register_block_pattern_category(
'pitchfork-section',
[ 'label' => __( 'Pitchfork: Section', 'pitchfork' ) ]
);
register_block_pattern_category(
'pitchfork-loops',
[ 'label' => __( 'Pitchfork: Query Loops', 'pitchfork' ) ]
);
register_block_pattern_category(
'pitchfork-fullpage',
[ 'label' => __( 'Pitchfork: Page templates', 'pitchfork' ) ]
);
register_block_pattern_category(
'pitchfork-search',
[ 'label' => __( 'Pitchfork: Search', 'pitchfork' ) ]
);
}, 10 );
if ( ! function_exists( 'pitchfork_gutenberg_css' ) ) {
/**
* Load CSS styles in editor area.
*/
function pitchfork_gutenberg_css() {
add_theme_support( 'editor-styles' );
add_editor_style( 'dist/css/theme.css' );
}
}
add_action( 'after_setup_theme', 'pitchfork_gutenberg_css' );
/**
* Opt in/out features for the theme and the block editor.
* From: https://developer.wordpress.org/block-editor/developers/themes/theme-support/
*
* @return void
*/
function pitchfork_theme_support_block_editor_opt_in() {
// This is still in expirimental-theme.json, but not an actual theme.json
add_theme_support( 'responsive-embeds' );
// Reminder: Lots of other theme options moved to theme.json.
}
add_action( 'after_setup_theme', 'pitchfork_theme_support_block_editor_opt_in' );
/**
* With the use of the separate core assets filter, we can easily deregister
* block styles from individual core blocks with the deregister_style hook.
* Ref: https://github.com/WordPress/gutenberg/issues/32051#issuecomment-1058964416
*
* Affects front end only, not block editor screens.
* Ref: https://developer.wordpress.org/reference/functions/wp_should_load_separate_core_block_assets/
*
* @return void
*/
function pitchfork_remove_core_wp_block_styles() {
wp_deregister_style( 'wp-block-button' );
wp_deregister_style( 'wp-block-image' );
wp_deregister_style( 'wp-block-separator' );
}
add_filter( 'should_load_separate_core_block_assets', '__return_true' );
add_action( 'wp_enqueue_scripts', 'pitchfork_remove_core_wp_block_styles', 100 );