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

Use new core functions in menu items REST API #35648

Open
wants to merge 2 commits into
base: trunk
Choose a base branch
from

Conversation

@spacedmonkey
Copy link
Member

@spacedmonkey spacedmonkey commented Oct 14, 2021

Description

In the menu item controller, use the new functions rest_get_route_for_term and rest_get_route_for_post. These functions are not part of core at time of writing on the REST API menu item endpoints and were added in WP 5.5.

How has this been tested?

Screenshots

Types of changes

Checklist:

  • My code is tested.
  • My code follows the WordPress code style.
  • My code follows the accessibility standards.
  • I've tested my changes with keyboard and screen readers.
  • My code has proper inline documentation.
  • I've included developer documentation if appropriate.
  • I've updated all React Native files affected by any refactorings/renamings in this PR (please manually search all *.native.js files for terms that need renaming or removal).
if ( ! empty( $menu_item->object_id ) ) {
if ( 'post_type' === $menu_item->type ) {
$path = rest_get_route_for_post( $menu_item->object_id );
if ( $path ) {
$links['https://api.w.org/object'][] = array(
'href' => rest_url( $path ),
'post_type' => $menu_item->type,
'embeddable' => true,
);
}
} elseif ( 'taxonomy' === $menu_item->type ) {
$path = rest_get_route_for_term( $menu_item->object_id );
if ( $path ) {
$links['https://api.w.org/object'][] = array(
'href' => rest_url( $path ),
'taxonomy' => $menu_item->type,
'embeddable' => true,
);
}
Copy link
Member

@Mamaduka Mamaduka Oct 15, 2021

Maybe we could return early here, and I think we can also split type checks into two if statements.

It's just a personal nitpick. I find nested if statements hard to ready. Feel free to ignore.

Something like this:

if ( empty( $menu_item->object_id ) ) {
	return $links;
}

if ( 'post_type' === $menu_item->type ) {
	$path = rest_get_route_for_post( $menu_item->object_id );
	if ( $path ) {
		$links['https://api.w.org/object'][] = array(
			'href'       => rest_url( $path ),
			'post_type'  => $menu_item->type,
			'embeddable' => true,
		);
	}
}

if ( 'taxonomy' === $menu_item->type ) {
	$path = rest_get_route_for_term( $menu_item->object_id );
	if ( $path ) {
		$links['https://api.w.org/object'][] = array(
			'href'       => rest_url( $path ),
			'taxonomy'   => $menu_item->type,
			'embeddable' => true,
		);
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants