More PHPcs complain passification

This commit is contained in:
Jay Wood
2015-08-28 19:19:25 -04:00
parent 896b70b100
commit b3848809c0

View File

@ -12,22 +12,22 @@ class CWV3 {
* *
* @return string|int String if special page like homepage, or post_id otherwise. * @return string|int String if special page like homepage, or post_id otherwise.
*/ */
public function get_cookie_name(){ public function get_cookie_name() {
global $post; global $post;
$sitewide = get_option( 'cwv3_sitewide' ); $sitewide = get_option( 'cwv3_sitewide' );
$homepage = get_option( 'cwv3_homepage' ); $homepage = get_option( 'cwv3_homepage' );
$misc = get_option( 'cwv3_misc' ); $misc = get_option( 'cwv3_misc' );
if ( 'enabled' == ! empty( $sitewide ) ){ if ( 'enabled' == ! empty( $sitewide ) ) {
return 'sitewide'; return 'sitewide';
} }
if ( 'enabled' == ! empty( $homepage ) && is_front_page() ){ if ( 'enabled' == ! empty( $homepage ) && is_front_page() ) {
return 'homepage'; return 'homepage';
} }
if ( 'enabled' == ! empty( $misc ) && ( is_search() || is_archive() ) ){ if ( 'enabled' == ! empty( $misc ) && ( is_search() || is_archive() ) ) {
return 'misc'; return 'misc';
} }
@ -35,20 +35,20 @@ class CWV3 {
// Special consideration needs to be taken to check if the post parent is in-fact // Special consideration needs to be taken to check if the post parent is in-fact
// gated in any way. // gated in any way.
$cat_gated = $this->is_cat_gated( $post->post_parent ); $cat_gated = $this->is_cat_gated( $post->post_parent );
if ( ! empty( $cat_gated ) ){ if ( ! empty( $cat_gated ) ) {
// Return the category cookie name like _cat_### // Return the category cookie name like _cat_###
return '_cat_' . $cat_gated; return '_cat_' . $cat_gated;
} else if ( $this->is_gated( $post->post_parent ) ){ } else if ( $this->is_gated( $post->post_parent ) ) {
return $post->post_parent; return $post->post_parent;
} }
} }
if ( is_singular() && isset( $post->ID ) ){ if ( is_singular() && isset( $post->ID ) ) {
$cat_gated = $this->is_cat_gated( $post->ID ); $cat_gated = $this->is_cat_gated( $post->ID );
if ( ! empty( $cat_gated ) ){ if ( ! empty( $cat_gated ) ) {
// Return the category cookie name like _cat_### // Return the category cookie name like _cat_###
return '_cat_' . $cat_gated; return '_cat_' . $cat_gated;
} else if ( $this->is_gated( $post->ID ) ){ } else if ( $this->is_gated( $post->ID ) ) {
return $post->ID; return $post->ID;
} }
} }
@ -64,9 +64,10 @@ class CWV3 {
* regular category taxonomy. * regular category taxonomy.
* *
* @param int $post_id Post ID * @param int $post_id Post ID
*
* @return bool TRUE | FALSE * @return bool TRUE | FALSE
*/ */
public function is_gated( $post_id ){ public function is_gated( $post_id ) {
$meta = get_post_meta( $post_id, 'cwv3_auth', true ); $meta = get_post_meta( $post_id, 'cwv3_auth', true );
@ -82,15 +83,19 @@ class CWV3 {
* *
* Determines if a post is within a gated category, if so, will * Determines if a post is within a gated category, if so, will
* return the category id for use in cookie names like so '_cat_###' * return the category id for use in cookie names like so '_cat_###'
*
* @param int $post_id Post ID * @param int $post_id Post ID
*
* @return boolean|string False on failure, cookie string otherwise * @return boolean|string False on failure, cookie string otherwise
*/ */
public function is_cat_gated( $post_id ){ public function is_cat_gated( $post_id ) {
$cat_settings = get_option( 'cwv3_cat_list', array() ); $cat_settings = get_option( 'cwv3_cat_list', array() );
if ( ! empty( $cat_settings ) ){ if ( ! empty( $cat_settings ) ) {
$post_categories = get_the_category( $post_id ); $post_categories = get_the_category( $post_id );
return $this->in_cat( $cat_settings, $post_categories ); return $this->in_cat( $cat_settings, $post_categories );
} }
return false; return false;
} }
@ -103,6 +108,7 @@ class CWV3 {
* *
* @param array $cat_settings Array of categories from settings page * @param array $cat_settings Array of categories from settings page
* @param array $post_categories Array of categories from get_the_category() * @param array $post_categories Array of categories from get_the_category()
*
* @return boolean|int False on failure, category ID on success * @return boolean|int False on failure, category ID on success
*/ */
public function in_cat( $cat_settings, $post_categories ) { public function in_cat( $cat_settings, $post_categories ) {
@ -117,6 +123,7 @@ class CWV3 {
continue; continue;
} }
} }
return false; return false;
} }
@ -127,7 +134,7 @@ class CWV3 {
* *
* @return null * @return null
*/ */
public function hooks(){ public function hooks() {
add_action( 'init', array( $this, 'register_frontend_data' ) ); add_action( 'init', array( $this, 'register_frontend_data' ) );
add_action( 'wp_enqueue_scripts', array( $this, 'load_dependancies' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'load_dependancies' ) );
@ -143,7 +150,9 @@ class CWV3 {
public function load_dependancies() { public function load_dependancies() {
global $post; global $post;
if ( current_user_can( 'manage_options' ) ) { return; } if ( current_user_can( 'manage_options' ) ) {
return;
}
wp_enqueue_style( 'cwv3_css' ); wp_enqueue_style( 'cwv3_css' );
wp_enqueue_script( 'cwv3_js' ); wp_enqueue_script( 'cwv3_js' );
@ -153,7 +162,8 @@ class CWV3 {
'opacity' => get_option( 'cwv3_bg_opacity', 0.85 ), 'opacity' => get_option( 'cwv3_bg_opacity', 0.85 ),
'cookie_path' => SITECOOKIEPATH, 'cookie_path' => SITECOOKIEPATH,
'cookie_name' => $this->get_cookie_name(), 'cookie_name' => $this->get_cookie_name(),
'cookie_time' => intval( $cookie_death ) > 365 ? 365 : intval( $cookie_death ), // Max at one year if it's over 365 days. 'cookie_time' => intval( $cookie_death ) > 365 ? 365 : intval( $cookie_death ),
// Max at one year if it's over 365 days.
'denial_enabled' => get_option( 'cwv3_denial', 'enabled' ), 'denial_enabled' => get_option( 'cwv3_denial', 'enabled' ),
'denial_method' => get_option( 'cwv3_method', 'redirect' ), 'denial_method' => get_option( 'cwv3_method', 'redirect' ),
'redirect_url' => esc_js( get_option( 'cwv3_exit_link', '#' ) ), 'redirect_url' => esc_js( get_option( 'cwv3_exit_link', '#' ) ),