Make WordPress Core

Changeset 53199


Ignore:
Timestamp:
04/17/2022 05:24:27 PM (4 years ago)
Author:
SergeyBiryukov
Message:

Coding Standards: Simplify long conditions in xfn_check().

Add some comments for clarity.

Follow-up to [2051], [4990], [53198].

See #54728.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/meta-boxes.php

    r53198 r53199  
    11891189 * @param string $xfn_relationship
    11901190 * @param string $xfn_value
    1191  * @param mixed  $deprecated Never used.
     1191 * @param mixed  $deprecated       Never used.
    11921192 */
    11931193function xfn_check( $xfn_relationship, $xfn_value = '', $deprecated = '' ) {
    … …  
    11981198        }
    11991199
    1200         $link_rel = isset( $link->link_rel ) ? $link->link_rel : ''; // In PHP 5.3: $link_rel = $link->link_rel ?: '';
    1201         $rels     = preg_split( '/\s+/', $link_rel );
    1202 
    1203         if ( '' !== $xfn_value && in_array( $xfn_value, $rels, true ) ) {
     1200        $link_rel  = isset( $link->link_rel ) ? $link->link_rel : ''; // In PHP 5.3: $link_rel = $link->link_rel ?: '';
     1201        $link_rels = preg_split( '/\s+/', $link_rel );
     1202
     1203        // Mark the specified value as checked if it matches the link relationship.
     1204        if ( '' !== $xfn_value && in_array( $xfn_value, $link_rels, true ) ) {
    12041205                echo ' checked="checked"';
    12051206        }
    12061207
    12071208        if ( '' === $xfn_value ) {
     1209                // Mark the 'none' value as checked if the link does not match the specified relationship.
    12081210                if ( 'family' === $xfn_relationship
    1209                         && strpos( $link_rel, 'child' ) === false
    1210                         && strpos( $link_rel, 'parent' ) === false
    1211                         && strpos( $link_rel, 'sibling' ) === false
    1212                         && strpos( $link_rel, 'spouse' ) === false
    1213                         && strpos( $link_rel, 'kin' ) === false
     1211                        && ! array_intersect( $link_rels, array( 'child', 'parent', 'sibling', 'spouse', 'kin' ) )
    12141212                ) {
    12151213                        echo ' checked="checked"';
    … …  
    12171215
    12181216                if ( 'friendship' === $xfn_relationship
    1219                         && strpos( $link_rel, 'friend' ) === false
    1220                         && strpos( $link_rel, 'acquaintance' ) === false
    1221                         && strpos( $link_rel, 'contact' ) === false ) {
    1222                         echo ' checked="checked"';
    1223                 }
    1224 
    1225                 if ( 'geographical' === $xfn_relationship
    1226                         && strpos( $link_rel, 'co-resident' ) === false
    1227                         && strpos( $link_rel, 'neighbor' ) === false
     1217                        && ! array_intersect( $link_rels, array( 'friend', 'acquaintance', 'contact' ) )
    12281218                ) {
    12291219                        echo ' checked="checked"';
    12301220                }
    12311221
     1222                if ( 'geographical' === $xfn_relationship
     1223                        && ! array_intersect( $link_rels, array( 'co-resident', 'neighbor' ) )
     1224                ) {
     1225                        echo ' checked="checked"';
     1226                }
     1227
     1228                // Mark the 'me' value as checked if it matches the link relationship.
    12321229                if ( 'identity' === $xfn_relationship
    1233                         && in_array( 'me', $rels, true )
     1230                        && in_array( 'me', $link_rels, true )
    12341231                ) {
    12351232                        echo ' checked="checked"';
Note: See TracChangeset for help on using the changeset viewer.