Skip to content

Conversation

@xknown
Copy link
Member

@xknown xknown commented Nov 9, 2020

Updates wp_update_link to handle invalid link ids, it also adds a couple
of unit tests.

Trac ticket: https://core.trac.wordpress.org/ticket/51423


This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@hellofromtonya
Copy link
Contributor

Status: Blocked

The solution for this PR is currently blocked until we figure out the best way to handle wp_get_object_terms. The discussion is happening in #736. Once we land on an implementation, I can update this PR.

Comment on lines 129 to 132
if ( is_wp_error( $cats ) ) {
return array();
}
return array_unique( $cats );
Copy link
Contributor

Choose a reason for hiding this comment

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

Code review discussion with @jrfnl:

  • Use the same strategy as in PR 736 by flipping this around to check that wp_get_object_terms does return an array and then pass that into array_unique(); else, return an empty array().
  • We do not need to return the WP_Error. Why? This function expects to return only an array.
if ( is_array( $cats ) {
	return array_unique( $cats );
}

return array();

Updates `wp_update_link` to handle invalid link ids, it also adds a couple
of unit tests.
Comment on lines 308 to 310
if ( null === $link ) {
return new WP_Error( 'invalid_link', __( 'Invalid link ID.' ) );
}
Copy link
Contributor

@hellofromtonya hellofromtonya Feb 5, 2021

Choose a reason for hiding this comment

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

Code discussion with @jrfnl:

The code assumes it $links will be an array. However, get_bookmark() could also return null which is problematic:

$link_cats = $link['link_category'];

and

$linkdata = array_merge( $link, $linkdata );

https://3v4l.org/KPmBt
https://3v4l.org/4vURI

We need to wrangle this. It does not need WP_Error.

@hellofromtonya
Copy link
Contributor

@hellofromtonya hellofromtonya self-assigned this Mar 11, 2021
@xknown xknown closed this by deleting the head repository Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants