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

Blocks: remove gutenberg refs in PHP files #51978

Merged
merged 3 commits into from
Jun 27, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion packages/block-library/src/latest-posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ function render_block_core_latest_posts( $attributes ) {
$filter_latest_posts_excerpt_more = static function( $more ) use ( $attributes ) {
$use_excerpt = 'excerpt' === $attributes['displayPostContentRadio'];
/* translators: %1$s is a URL to a post, excerpt truncation character, default … */
return $use_excerpt ? sprintf( __( ' … <a href="%1$s" rel="noopener noreferrer">Read more</a>', 'gutenberg' ), esc_url( get_permalink() ) ) : $more;
return $use_excerpt ? sprintf( __( ' … <a href="%1$s" rel="noopener noreferrer">Read more</a>' ), esc_url( get_permalink() ) ) : $more;
};

add_filter( 'excerpt_more', $filter_latest_posts_excerpt_more );
Expand Down
34 changes: 24 additions & 10 deletions packages/block-library/src/navigation/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function block_core_navigation_sort_menu_items_by_parent_id( $menu_items ) {
*
* @return string Submenu markup with the directives injected.
*/
function gutenberg_block_core_navigation_add_directives_to_submenu( $w, $block_attributes ) {
function block_core_navigation_add_directives_to_submenu( $w, $block_attributes ) {
while ( $w->next_tag(
array(
'tag_name' => 'LI',
Expand Down Expand Up @@ -124,7 +124,7 @@ function gutenberg_block_core_navigation_add_directives_to_submenu( $w, $block_a
};

// Iterate through subitems if exist.
gutenberg_block_core_navigation_add_directives_to_submenu( $w, $block_attributes );
block_core_navigation_add_directives_to_submenu( $w, $block_attributes );
}
return $w->get_updated_html();
};
Expand Down Expand Up @@ -341,7 +341,11 @@ function block_core_navigation_get_fallback_blocks() {
// If `core/page-list` is not registered then return empty blocks.
$fallback_blocks = $registry->is_registered( 'core/page-list' ) ? $page_list_fallback : array();

$navigation_post = Gutenberg_Navigation_Fallback::get_fallback();
if ( class_exists( 'WP_Navigation_Fallback' ) ) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I this should be

if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN ) {

Same effect, just convention?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd go with the class_exists check, since the compat layer changes over time (and is thus not directly equivalent to the presence of the plugin).

$navigation_post = WP_Navigation_Fallback::get_fallback();
} else {
$navigation_post = Gutenberg_Navigation_Fallback::get_fallback();
}

// Use the first non-empty Navigation as fallback if available.
if ( $navigation_post ) {
Expand Down Expand Up @@ -673,7 +677,7 @@ function render_block_core_navigation( $attributes, $content, $block ) {
// Add directives to the submenu if needed.
if ( defined( 'IS_GUTENBERG_PLUGIN' ) && IS_GUTENBERG_PLUGIN && $has_submenus && $should_load_view_script ) {
$w = new WP_HTML_Tag_Processor( $inner_blocks_html );
$inner_blocks_html = gutenberg_block_core_navigation_add_directives_to_submenu( $w, $attributes );
$inner_blocks_html = block_core_navigation_add_directives_to_submenu( $w, $attributes );
}

$modal_unique_id = wp_unique_id( 'modal-' );
Expand Down Expand Up @@ -836,6 +840,8 @@ function block_core_navigation_typographic_presets_backcompatibility( $parsed_bl
/**
* Turns menu item data into a nested array of parsed blocks
*
* @deprecated 6.3.0 Use WP_Navigation_Fallback::parse_blocks_from_menu_items() instead.
*
* @param array $menu_items An array of menu items that represent
* an individual level of a menu.
* @param array $menu_items_by_parent_id An array keyed by the id of the
Expand All @@ -846,7 +852,7 @@ function block_core_navigation_typographic_presets_backcompatibility( $parsed_bl
*/
function block_core_navigation_parse_blocks_from_menu_items( $menu_items, $menu_items_by_parent_id ) {

_deprecated_function( __FUNCTION__, '6.3.0', 'Gutenberg_Navigation_Fallback::parse_blocks_from_menu_items' );
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback::parse_blocks_from_menu_items' );

if ( empty( $menu_items ) ) {
return array();
Expand Down Expand Up @@ -891,11 +897,13 @@ function block_core_navigation_parse_blocks_from_menu_items( $menu_items, $menu_
/**
* Get the classic navigation menu to use as a fallback.
*
* @deprecated 6.3.0 Use WP_Navigation_Fallback::get_classic_menu_fallback() instead.
*
* @return object WP_Term The classic navigation.
*/
function block_core_navigation_get_classic_menu_fallback() {

_deprecated_function( __FUNCTION__, '6.3.0', 'Gutenberg_Navigation_Fallback::get_classic_menu_fallback' );
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback::get_classic_menu_fallback' );

$classic_nav_menus = wp_get_nav_menus();

Expand Down Expand Up @@ -933,12 +941,14 @@ static function( $a, $b ) {
/**
* Converts a classic navigation to blocks.
*
* @deprecated 6.3.0 Use WP_Navigation_Fallback::get_classic_menu_fallback_blocks() instead.
*
* @param object $classic_nav_menu WP_Term The classic navigation object to convert.
* @return array the normalized parsed blocks.
*/
function block_core_navigation_get_classic_menu_fallback_blocks( $classic_nav_menu ) {

_deprecated_function( __FUNCTION__, '6.3.0', 'Gutenberg_Navigation_Fallback::get_classic_menu_fallback_blocks' );
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback::get_classic_menu_fallback_blocks' );

// BEGIN: Code that already exists in wp_nav_menu().
$menu_items = wp_get_nav_menu_items( $classic_nav_menu->term_id, array( 'update_post_term_cache' => false ) );
Expand Down Expand Up @@ -971,13 +981,15 @@ function block_core_navigation_get_classic_menu_fallback_blocks( $classic_nav_me
}

/**
* If there's a the classic menu then use it as a fallback.
* If there's a classic menu then use it as a fallback.
*
* @deprecated 6.3.0 Use WP_Navigation_Fallback::create_classic_menu_fallback() instead.
*
* @return array the normalized parsed blocks.
*/
function block_core_navigation_maybe_use_classic_menu_fallback() {

_deprecated_function( __FUNCTION__, '6.3.0', 'Gutenberg_Navigation_Fallback::create_classic_menu_fallback' );
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback::create_classic_menu_fallback' );

// See if we have a classic menu.
$classic_nav_menu = block_core_navigation_get_classic_menu_fallback();
Expand Down Expand Up @@ -1016,11 +1028,13 @@ function block_core_navigation_maybe_use_classic_menu_fallback() {
/**
* Finds the most recently published `wp_navigation` Post.
*
* @deprecated 6.3.0 Use WP_Navigation_Fallback::get_most_recently_published_navigation() instead.
*
* @return WP_Post|null the first non-empty Navigation or null.
*/
function block_core_navigation_get_most_recently_published_navigation() {

_deprecated_function( __FUNCTION__, '6.3.0', 'Gutenberg_Navigation_Fallback::get_most_recently_published_navigation' );
_deprecated_function( __FUNCTION__, '6.3.0', 'WP_Navigation_Fallback::get_most_recently_published_navigation' );

// Default to the most recently created menu.
$parsed_args = array(
Expand Down
Loading