From 6b6138ad70499c511467505ff5ceafdcdf817c41 Mon Sep 17 00:00:00 2001 From: Robin Cornett Date: Mon, 20 Apr 2015 13:14:08 -0400 Subject: [PATCH] refactor (early returns) --- ...lass-displayfeaturedimagegenesis-admin.php | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/includes/class-displayfeaturedimagegenesis-admin.php b/includes/class-displayfeaturedimagegenesis-admin.php index a679700..ba13c6b 100644 --- a/includes/class-displayfeaturedimagegenesis-admin.php +++ b/includes/class-displayfeaturedimagegenesis-admin.php @@ -52,10 +52,11 @@ class Display_Featured_Image_Genesis_Admin { $post_types['post'] = 'post'; $post_types['page'] = 'page'; foreach ( $post_types as $post_type ) { - if ( post_type_supports( $post_type, 'thumbnail' ) ) { - add_filter( "manage_edit-{$post_type}_columns", array( $this, 'add_column' ) ); - add_action( "manage_{$post_type}_posts_custom_column", array( $this, 'custom_post_columns' ), 10, 2 ); + if ( ! post_type_supports( $post_type, 'thumbnail' ) ) { + return; } + add_filter( "manage_edit-{$post_type}_columns", array( $this, 'add_column' ) ); + add_action( "manage_{$post_type}_posts_custom_column", array( $this, 'custom_post_columns' ), 10, 2 ); } } @@ -126,14 +127,22 @@ class Display_Featured_Image_Genesis_Admin { */ public function custom_post_columns( $column, $post_id ) { - if ( 'featured_image' === $column ) { - $id = get_post_thumbnail_id( $post_id ); - $preview = apply_filters( 'display_featured_image_genesis_admin_post_thumbnail', wp_get_attachment_image_src( $id, 'thumbnail' ), $id ); - if ( $id ) { - echo '' . esc_attr( the_title_attribute( 'echo=0' ) ) . ''; - } + if ( 'featured_image' !== $column ) { + return; } + $id = get_post_thumbnail_id( $post_id ); + if ( ! $id ) { + return; + } + + $preview = apply_filters( + 'display_featured_image_genesis_admin_post_thumbnail', + wp_get_attachment_image_src( $id, 'thumbnail' ), + $id + ); + echo '' . esc_attr( the_title_attribute( 'echo=0' ) ) . ''; + } /**