WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#17279 closed defect (bug) (fixed)

No need to run twentyeleven_url_grabber twice

Reported by: duck_ Owned by: lancewillett
Milestone: 3.2 Priority: normal
Severity: normal Version: 3.2
Component: Themes Keywords: has-patch
Focuses: Cc:

Description

Just run it once to get the result and if that's false then replace it with the permalink.

Related: #17267

Attachments (1)

17279.diff (1.1 KB) - added by duck_ 4 years ago.

Download all attachments as: .zip

Change History (5)

@duck_4 years ago

comment:1 @Otto424 years ago

Always best to be explicit about it. I'd suggest this style instead:

if ( false == ( $link_url = twentyeleven_url_grabber() ) ) {
  $link_url = get_permalink();
}

comment:2 @duck_4 years ago

I initially did that but personally found it a bit harder to read, but achieves the same result.

comment:3 @lancewillett4 years ago

Even better is to run it once and use get_permalink() only as a fallback. empty() catches the false and an empty string.

$link_url = twentyeleven_url_grabber();
if ( empty( $link_url ) )
   $link_url = get_permalink();

comment:4 @lancewillett4 years ago

  • Owner set to lancewillett
  • Resolution set to fixed
  • Status changed from new to closed

In [17917]:

Twenty Eleven: run twentyeleven_url_grabber once in widgets.php, props duck_ -- closes #17279

Note: See TracTickets for help on using tickets.