From 8c9af98160ce1a13d2f6cfcdf0407c8f0f59847f Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 17 Apr 2022 17:24:27 +0000 Subject: [PATCH] Coding Standards: Simplify long conditions in `xfn_check()`. Add some comments for clarity. Follow-up to [2051], [4990], [53198]. See #54728. git-svn-id: https://develop.svn.wordpress.org/trunk@53199 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/meta-boxes.php | 35 +++++++++++++--------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/src/wp-admin/includes/meta-boxes.php b/src/wp-admin/includes/meta-boxes.php index 09a60229bd..35d6c62bc7 100644 --- a/src/wp-admin/includes/meta-boxes.php +++ b/src/wp-admin/includes/meta-boxes.php @@ -1188,7 +1188,7 @@ function link_target_meta_box( $link ) { * * @param string $xfn_relationship * @param string $xfn_value - * @param mixed $deprecated Never used. + * @param mixed $deprecated Never used. */ function xfn_check( $xfn_relationship, $xfn_value = '', $deprecated = '' ) { global $link; @@ -1197,40 +1197,37 @@ function xfn_check( $xfn_relationship, $xfn_value = '', $deprecated = '' ) { _deprecated_argument( __FUNCTION__, '2.5.0' ); // Never implemented. } - $link_rel = isset( $link->link_rel ) ? $link->link_rel : ''; // In PHP 5.3: $link_rel = $link->link_rel ?: ''; - $rels = preg_split( '/\s+/', $link_rel ); + $link_rel = isset( $link->link_rel ) ? $link->link_rel : ''; // In PHP 5.3: $link_rel = $link->link_rel ?: ''; + $link_rels = preg_split( '/\s+/', $link_rel ); - if ( '' !== $xfn_value && in_array( $xfn_value, $rels, true ) ) { + // Mark the specified value as checked if it matches the link relationship. + if ( '' !== $xfn_value && in_array( $xfn_value, $link_rels, true ) ) { echo ' checked="checked"'; } if ( '' === $xfn_value ) { + // Mark the 'none' value as checked if the link does not match the specified relationship. if ( 'family' === $xfn_relationship - && strpos( $link_rel, 'child' ) === false - && strpos( $link_rel, 'parent' ) === false - && strpos( $link_rel, 'sibling' ) === false - && strpos( $link_rel, 'spouse' ) === false - && strpos( $link_rel, 'kin' ) === false + && ! array_intersect( $link_rels, array( 'child', 'parent', 'sibling', 'spouse', 'kin' ) ) ) { echo ' checked="checked"'; } if ( 'friendship' === $xfn_relationship - && strpos( $link_rel, 'friend' ) === false - && strpos( $link_rel, 'acquaintance' ) === false - && strpos( $link_rel, 'contact' ) === false ) { - echo ' checked="checked"'; - } - - if ( 'geographical' === $xfn_relationship - && strpos( $link_rel, 'co-resident' ) === false - && strpos( $link_rel, 'neighbor' ) === false + && ! array_intersect( $link_rels, array( 'friend', 'acquaintance', 'contact' ) ) ) { echo ' checked="checked"'; } + if ( 'geographical' === $xfn_relationship + && ! array_intersect( $link_rels, array( 'co-resident', 'neighbor' ) ) + ) { + echo ' checked="checked"'; + } + + // Mark the 'me' value as checked if it matches the link relationship. if ( 'identity' === $xfn_relationship - && in_array( 'me', $rels, true ) + && in_array( 'me', $link_rels, true ) ) { echo ' checked="checked"'; }