From e40bfd714d880c7d39173fd574aa3c2792ce17db Mon Sep 17 00:00:00 2001 From: Erick Hitter <services@ethitter.com> Date: Sun, 20 Mar 2016 21:06:15 -0700 Subject: [PATCH] Introduce utility methods to reduce repetition --- eth-simple-shortlinks.php | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/eth-simple-shortlinks.php b/eth-simple-shortlinks.php index 128b32e..51817c1 100644 --- a/eth-simple-shortlinks.php +++ b/eth-simple-shortlinks.php @@ -134,11 +134,11 @@ class ETH_Simple_Shortlinks { return $shortlink; } - if ( ! in_array( get_post_status( $id ), $this->supported_post_statuses ) ) { + if ( ! $this->is_supported_post_status( get_post_status( $id ) ) ) { return $shortlink; } - if ( ! in_array( get_post_type( $id ), $this->supported_post_types ) ) { + if ( ! $this->is_supported_post_type( get_post_type( $id ) ) ) { return $shortlink; } @@ -150,7 +150,7 @@ class ETH_Simple_Shortlinks { */ public function add_admin_header_assets() { global $typenow; - if ( ! in_array( $typenow, $this->supported_post_types ) ) { + if ( ! $this->is_supported_post_type( $typenow ) ) { return; } @@ -172,7 +172,7 @@ class ETH_Simple_Shortlinks { * Provide the shortlink in row actions for easy access */ public function filter_row_actions( $actions, $post ) { - if ( ! in_array( get_post_type( $post ), $this->supported_post_types ) || ! in_array( get_post_status( $post ), $this->supported_post_statuses ) ) { + if ( ! $this->is_supported_post_type( get_post_type( $post ) ) || ! $this->is_supported_post_status( get_post_status( $post ) ) ) { return $actions; } @@ -181,6 +181,20 @@ class ETH_Simple_Shortlinks { return $actions; } + /** + * Check if given post type is supported + */ + private function is_supported_post_type( $type ) { + return in_array( $type, $this->supported_post_types ); + } + + /** + * Check if given post status is supported + */ + private function is_supported_post_status( $status ) { + return in_array( $status, $this->supported_post_statuses ); + } + /** * Utility method for building permlink */ -- GitLab