render // which is unused since the introduction of WP_Block class. // // See: // - https://core.trac.wordpress.org/ticket/49927 // - commit 910de8f6890c87f93359c6f2edc6c27b9a3f3292 at wordpress-develop. if ( null === $block ) { return $block_render_callback( $attributes, $content ); } $registry = WP_Block_Type_Registry::get_instance(); $block_type = $registry->get_registered( $block->name ); // For WordPress versions that don't support the context API. if ( ! $block->context ) { $block->context = array(); } // Inject the post context if not done by Core. $needs_post_id = ! empty( $block_type->uses_context ) && in_array( 'postId', $block_type->uses_context, true ); if ( $post instanceof WP_Post && $needs_post_id && ! isset( $block->context['postId'] ) && 'wp_template' !== $post->post_type && 'wp_template_part' !== $post->post_type ) { $block->context['postId'] = $post->ID; } $needs_post_type = ! empty( $block_type->uses_context ) && in_array( 'postType', $block_type->uses_context, true ); if ( $post instanceof WP_Post && $needs_post_type && ! isset( $block->context['postType'] ) && 'wp_template' !== $post->post_type && 'wp_template_part' !== $post->post_type ) { /* * The `postType` context is largely unnecessary server-side, since the * ID is usually sufficient on its own. That being said, since a block's * manifest is expected to be shared between the server and the client, * it should be included to consistently fulfill the expectation. */ $block->context['postType'] = $post->post_type; } return $block_render_callback( $attributes, $content, $block ); }; } return $args; } add_filter( 'register_block_type_args', 'gutenberg_inject_default_block_context' ); /** * Override post type labels for Reusable Block custom post type. * The labels are different from the ones in Core. * * Remove this when Core receives the new labels (minimum supported version WordPress 5.8) * * @return array Array of new labels for Reusable Block post type. */ function gutenberg_override_reusable_block_post_type_labels() { return array( 'name' => _x( 'Reusable blocks', 'post type general name', 'gutenberg' ), 'singular_name' => _x( 'Reusable block', 'post type singular name', 'gutenberg' ), 'menu_name' => _x( 'Reusable blocks', 'admin menu', 'gutenberg' ), 'name_admin_bar' => _x( 'Reusable block', 'add new on admin bar', 'gutenberg' ), 'add_new' => _x( 'Add New', 'Reusable block', 'gutenberg' ), 'add_new_item' => __( 'Add new Reusable block', 'gutenberg' ), 'new_item' => __( 'New Reusable block', 'gutenberg' ), 'edit_item' => __( 'Edit Reusable block', 'gutenberg' ), 'view_item' => __( 'View Reusable block', 'gutenberg' ), 'all_items' => __( 'All Reusable blocks', 'gutenberg' ), 'search_items' => __( 'Search Reusable blocks', 'gutenberg' ), 'not_found' => __( 'No reusable blocks found.', 'gutenberg' ), 'not_found_in_trash' => __( 'No reusable blocks found in Trash.', 'gutenberg' ), 'filter_items_list' => __( 'Filter reusable blocks list', 'gutenberg' ), 'items_list_navigation' => __( 'Reusable blocks list navigation', 'gutenberg' ), 'items_list' => __( 'Reusable blocks list', 'gutenberg' ), 'item_published' => __( 'Reusable block published.', 'gutenberg' ), 'item_published_privately' => __( 'Reusable block published privately.', 'gutenberg' ), 'item_reverted_to_draft' => __( 'Reusable block reverted to draft.', 'gutenberg' ), 'item_scheduled' => __( 'Reusable block scheduled.', 'gutenberg' ), 'item_updated' => __( 'Reusable block updated.', 'gutenberg' ), ); } add_filter( 'post_type_labels_wp_block', 'gutenberg_override_reusable_block_post_type_labels', 10, 0 ); /** * Update allowed inline style attributes list. * * Note: This should be removed when the minimum required WP version is >= 5.8. * * @param string[] $attrs Array of allowed CSS attributes. * @return string[] CSS attributes. */ function gutenberg_safe_style_attrs( $attrs ) { $attrs[] = 'object-position'; $attrs[] = 'border-top-left-radius'; $attrs[] = 'border-top-right-radius'; $attrs[] = 'border-bottom-right-radius'; $attrs[] = 'border-bottom-left-radius'; $attrs[] = 'filter'; return $attrs; } add_filter( 'safe_style_css', 'gutenberg_safe_style_attrs' );