Skip to content

Instantly share code, notes, and snippets.

@hellofromtonya
Created July 9, 2016 01:38
Show Gist options
  • Save hellofromtonya/5b7e2f0cea4d3d6a78502be4ece6b94b to your computer and use it in GitHub Desktop.
Save hellofromtonya/5b7e2f0cea4d3d6a78502be4ece6b94b to your computer and use it in GitHub Desktop.
Real example of a "return early pattern" opportunity - actually there are two examples of it in here.
function genesis_do_post_image() {
/**
* Return Early Pattern opportunity
* ================================
* Notice that the code wrapped in this conditional block only executes IF the
* conditional expression is true. Hum, that means if the conditional expression
* is false, then the function is done and nothing else is going to happen.
*/
if ( ! is_singular() && genesis_get_option( 'content_archive_thumbnail' ) ) {
$img = genesis_get_image( array(
'format' => 'html',
'size' => genesis_get_option( 'image_size' ),
'context' => 'archive',
'attr' => genesis_parse_attr( 'entry-image', array ( 'alt' => get_the_title() ) ),
) );
/**
* Return Early Pattern opportunity
* ================================
* Here's another one. If no image HTML is returned, then the function is done and nothing
* else is going to happen. That means the code within the IF block will not execute.
*/
if ( ! empty( $img ) ) {
genesis_markup( array(
'html5' => '<a %s>',
'xhtml' => '<a href="' . get_permalink() . '" class="entry-image-link" aria-hidden="true">',
'context' => 'entry-image-link'
));
echo $img . '</a>';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment