From 1c80badf1e16f629d24324da4f4b4a7ff201ae68 Mon Sep 17 00:00:00 2001 From: David Shanske Date: Sun, 1 Oct 2023 04:34:57 +0000 Subject: [PATCH] More phpcs fixes --- includes/class-kind-config.php | 2 +- includes/class-kind-media-metadata.php | 2 +- includes/class-kind-metabox.php | 8 ++++---- includes/class-kind-post-widget.php | 2 +- includes/class-kind-post.php | 3 --- includes/class-kind-taxonomy.php | 13 ++++++------- includes/class-mf2-post.php | 9 +-------- includes/compat.php | 2 +- includes/kind-functions.php | 26 +++++++++++++------------- includes/register-kinds.php | 1 - 10 files changed, 28 insertions(+), 40 deletions(-) diff --git a/includes/class-kind-config.php b/includes/class-kind-config.php index 0233e89..c45a979 100644 --- a/includes/class-kind-config.php +++ b/includes/class-kind-config.php @@ -278,7 +278,7 @@ public static function options_callback() { */ public static function checkbox_callback( array $args ) { $option = get_option( $args['name'] ); - $checked = intval($option ?? 0); + $checked = intval( $option ?? 0 ); printf( '', esc_attr( $args['name'] ) ); // phpcs:ignore printf( '', esc_attr( $args['name'] ), checked( 1, $checked, false) ); // phpcs:ignore } diff --git a/includes/class-kind-media-metadata.php b/includes/class-kind-media-metadata.php index 9af05ef..3325935 100644 --- a/includes/class-kind-media-metadata.php +++ b/includes/class-kind-media-metadata.php @@ -263,7 +263,7 @@ public static function wp_sanitize_media_metadata( $metadata ) { $value = wp_sanitize_media_metadata( $value ); } elseif ( is_string( $value ) && preg_match( '~[^\x20-\x7E\t\r\n]~', $value ) > 0 ) { $encoding = mb_detect_encoding( $value, 'ISO-8859-1, UCS-2' ); - $value = $encoding ? mb_convert_encoding( $value, 'UTF-8', $encoding ) : utf8_encode( $value ); + $value = $encoding ? mb_convert_encoding( $value, 'UTF-8', $encoding ) $value; } $metadata[ $name ] = $value; } diff --git a/includes/class-kind-metabox.php b/includes/class-kind-metabox.php index ef788cd..3f9996d 100755 --- a/includes/class-kind-metabox.php +++ b/includes/class-kind-metabox.php @@ -213,8 +213,8 @@ public static function kind_the_time( $prefix, $label, $datetime, $class ) { $offset = $time['offset']; } $string = ''; return $string; @@ -397,9 +397,9 @@ public static function save_post( $post_id, $post ) { } $durations = array( - 'Y' => intval( $_POST['duration_years'] ?? '' ), + 'Y' => intval( $_POST['duration_years'] ?? '' ), 'M' => intval( $_POST['duration_months'] ?? '' ), - 'D' => intval( $_POST['duration_days'] ?? '' ), + 'D' => intval( $_POST['duration_days'] ?? '' ), 'H' => intval( $_POST['duration_hours'] ?? '' ), 'I' => intval( $_POST['duration_minutes'] ?? '' ), 'S' => intval( $_POST['duration_seconds'] ?? '' ), diff --git a/includes/class-kind-post-widget.php b/includes/class-kind-post-widget.php index 41bb68b..61abb82 100755 --- a/includes/class-kind-post-widget.php +++ b/includes/class-kind-post-widget.php @@ -43,7 +43,7 @@ public function widget( $args, $instance ) { 'terms' => $kind, ), ), - 'numberposts' => $instance['number'] ?? 5 , + 'numberposts' => $instance['number'] ?? 5, ); $posts = get_posts( $query ); } diff --git a/includes/class-kind-post.php b/includes/class-kind-post.php index d373da7..8a362ad 100644 --- a/includes/class-kind-post.php +++ b/includes/class-kind-post.php @@ -27,9 +27,6 @@ public function __construct( $post ) { } $post = get_post( $post ); - if ( ! $post ) { - return false; - } } /* diff --git a/includes/class-kind-taxonomy.php b/includes/class-kind-taxonomy.php index bd1d603..2bbe2d5 100755 --- a/includes/class-kind-taxonomy.php +++ b/includes/class-kind-taxonomy.php @@ -959,17 +959,16 @@ public static function select_metabox( $post ) { } if ( isset( $_GET['kind'] ) ) { $default = get_term_by( 'slug', $_GET['kind'], 'kind' ); - } else { + } elseif ( 'publish' === get_post_status( $post ) ) { // On existing published posts without a kind fall back on article which most closely mimics the behavior of an unclassified post - if ( 'publish' === get_post_status( $post ) ) { - $default = get_term_by( 'slug', 'article', 'kind' ); - } else { - $default = get_term_by( 'slug', get_option( 'kind_default' ), 'kind' ); - } + $default = get_term_by( 'slug', 'article', 'kind' ); + } else { + $default = get_term_by( 'slug', get_option( 'kind_default' ), 'kind' ); } + $terms = get_terms( - 'kind', array( + 'taxonomy' => 'kind', 'hide_empty' => 0, ) ); diff --git a/includes/class-mf2-post.php b/includes/class-mf2-post.php index 75a6940..4458336 100644 --- a/includes/class-mf2-post.php +++ b/includes/class-mf2-post.php @@ -41,7 +41,7 @@ public function __construct( $post ) { } $post = get_post( $post ); if ( ! $post ) { - return false; + return; } $this->mf2 = $this->get_mf2meta(); $this->post_author = $post->post_author; @@ -759,10 +759,3 @@ public function get_attachments_from_urls( $urls ) { return array_filter( array_unique( $att_ids ) ); } } - -function get_mf2_post( $post_id ) { - if ( $post_id instanceof MF2_Post ) { - return $post_id; - } - return new MF2_Post( $post_id ); -} diff --git a/includes/compat.php b/includes/compat.php index 78f09e3..9696257 100644 --- a/includes/compat.php +++ b/includes/compat.php @@ -48,6 +48,6 @@ function ( $time ) use ( $format ) { // Backcompat for wp_filter_content_tags introduced in 5.5. if ( ! function_exists( 'wp_filter_content_tags' ) ) { function wp_filter_content_tags( $content ) { - return wp_make_content_images_responsive( $content ); + return wp_make_content_images_responsive( $content ); // phpcs:ignore } } diff --git a/includes/kind-functions.php b/includes/kind-functions.php index 225fee3..2307b6f 100755 --- a/includes/kind-functions.php +++ b/includes/kind-functions.php @@ -108,16 +108,16 @@ function kind_display( $post_id = null ) { echo Kind_View::get_display( $post_id ); // phpcs:ignore } -function kind_flatten_array( $array ) { - if ( ! is_array( $array ) ) { - return $array; +function kind_flatten_array( $a ) { + if ( ! is_array( $a ) ) { + return $a; } - if ( wp_is_numeric_array( $array ) ) { - $array = array_map( 'kind_flatten_array', $array ); + if ( wp_is_numeric_array( $a ) ) { + $array = array_map( 'kind_flatten_array', $a ); } - $array = array_filter( $array ); - if ( 1 === count( $array ) ) { - return $array[0]; + $array = array_filter( $a ); + if ( 1 === count( $a ) ) { + return $a[0]; } } @@ -139,18 +139,18 @@ function kind_src_url_in_content( $content ) { * @return string Marked up link to a post. **/ -function kind_get_the_link( $post = null, $class = null ) { +function kind_get_the_link( $post = null, $cls = null ) { $post = get_post( $post ); $kind = get_post_kind_slug( $post ); - if ( is_array( $class ) ) { - $class = implode( ' ', $class ); + if ( is_array( $cls ) ) { + $cls = implode( ' ', $cls ); } - $class = 'class=' . $class; + $cls = 'class=' . $class; $time_string = ''; $time_string = sprintf( $time_string, - esc_attr( $class ), + esc_attr( $cls ), esc_attr( get_the_date( DATE_W3C, $post ) ), get_the_date( '', $post ) ); diff --git a/includes/register-kinds.php b/includes/register-kinds.php index af00ed6..666c1b4 100755 --- a/includes/register-kinds.php +++ b/includes/register-kinds.php @@ -181,7 +181,6 @@ 'name' => __( 'Likes', 'indieweb-post-kinds' ), // General name for the kind plural 'verb' => __( 'Liked', 'indieweb-post-kinds' ), // The string for the verb or action (liked this) 'property' => 'like-of', // microformats 2 property - 'properties' => array(), 'properties' => array( 'like-of' => array( 'type' => 'cite',