Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ETK Block patterns: Adding extra checks for array values before we use them to avoid PHP #53066

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,10 @@ private function reregister_core_patterns() {
// Gutenberg registers patterns with varying prefixes, but categorizes them using `core/*` in a blockTypes array.
// This will ensure we remove `query/*` blocks for example.
// TODO: We need to revisit our usage or $pattern['blockTypes']: they are currently an experimental feature and not guaranteed to reference `core/*` blocks.
$pattern_block_type_or_name = ! empty( $pattern['blockTypes'][0] ) ? $pattern['blockTypes'][0] : $pattern['name'];
$pattern_block_type_or_name =
isset( $pattern['blockTypes'] ) && ! empty( $pattern['blockTypes'][0] )
? $pattern['blockTypes'][0]
: $pattern['name'];
if ( 'core/' === substr( $pattern_block_type_or_name, 0, 5 ) ) {
unregister_block_pattern( $pattern['name'] );
}
Expand All @@ -275,8 +278,11 @@ private function reregister_core_patterns() {
private function update_core_patterns_with_wpcom_categories() {
if ( class_exists( 'WP_Block_Patterns_Registry' ) ) {
foreach ( \WP_Block_Patterns_Registry::get_instance()->get_all_registered() as $pattern ) {
$wpcom_categories = $this->core_to_wpcom_categories_dictionary[ $pattern['name'] ];
if ( isset( $wpcom_categories ) ) {
$wpcom_categories =
$pattern['name'] && isset( $this->core_to_wpcom_categories_dictionary[ $pattern['name'] ] )
? $this->core_to_wpcom_categories_dictionary[ $pattern['name'] ]
: null;
if ( $wpcom_categories ) {
unregister_block_pattern( $pattern['name'] );
$pattern_properties = array_merge(
$pattern,
Expand Down