Skip to content
Snippets Groups Projects
Commit e40bfd71 authored by Erick Hitter's avatar Erick Hitter
Browse files

Introduce utility methods to reduce repetition

parent 35ddcd25
Branches
Tags
1 merge request!2Utility methods for supported post types and statuses
...@@ -134,11 +134,11 @@ class ETH_Simple_Shortlinks { ...@@ -134,11 +134,11 @@ class ETH_Simple_Shortlinks {
return $shortlink; 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; 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; return $shortlink;
} }
...@@ -150,7 +150,7 @@ class ETH_Simple_Shortlinks { ...@@ -150,7 +150,7 @@ class ETH_Simple_Shortlinks {
*/ */
public function add_admin_header_assets() { public function add_admin_header_assets() {
global $typenow; global $typenow;
if ( ! in_array( $typenow, $this->supported_post_types ) ) { if ( ! $this->is_supported_post_type( $typenow ) ) {
return; return;
} }
...@@ -172,7 +172,7 @@ class ETH_Simple_Shortlinks { ...@@ -172,7 +172,7 @@ class ETH_Simple_Shortlinks {
* Provide the shortlink in row actions for easy access * Provide the shortlink in row actions for easy access
*/ */
public function filter_row_actions( $actions, $post ) { 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; return $actions;
} }
...@@ -181,6 +181,20 @@ class ETH_Simple_Shortlinks { ...@@ -181,6 +181,20 @@ class ETH_Simple_Shortlinks {
return $actions; 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 * Utility method for building permlink
*/ */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment