Make WordPress Core


Ignore:
Timestamp:
07/02/2019 11:41:16 PM (7 years ago)
Author:
pento
Message:

Coding Standards: Fix the Squiz.PHP.DisallowMultipleAssignments violations in wp-includes.

See #47632.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/post.php

    r45424 r45590  
    454454
    455455        // If the file is relative, prepend upload dir.
    456         if ( $file && 0 !== strpos( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) && ( ( $uploads = wp_get_upload_dir() ) && false === $uploads['error'] ) ) {
    457                 $file = $uploads['basedir'] . "/$file";
     456        if ( $file && 0 !== strpos( $file, '/' ) && ! preg_match( '|^.:\\\|', $file ) ) {
     457                $uploads = wp_get_upload_dir();
     458                if ( false === $uploads['error'] ) {
     459                        $file = $uploads['basedir'] . "/$file";
     460                }
    458461        }
    459462
     
    500503        $file = apply_filters( 'update_attached_file', $file, $attachment_id );
    501504
    502         if ( $file = _wp_relative_upload_path( $file ) ) {
     505        $file = _wp_relative_upload_path( $file );
     506        if ( $file ) {
    503507                return update_post_meta( $attachment_id, '_wp_attached_file', $file );
    504508        } else {
     
    756760        $ancestors = array();
    757761
    758         $id = $ancestors[] = $post->post_parent;
     762        $id          = $post->post_parent;
     763        $ancestors[] = $id;
    759764
    760765        while ( $ancestor = get_post( $id ) ) {
     
    764769                }
    765770
    766                 $id = $ancestors[] = $ancestor->post_parent;
     771                $id          = $ancestor->post_parent;
     772                $ancestors[] = $id;
    767773        }
    768774
     
    11491155 */
    11501156function get_post_type( $post = null ) {
    1151         if ( $post = get_post( $post ) ) {
     1157        $post = get_post( $post );
     1158        if ( $post ) {
    11521159                return $post->post_type;
    11531160        }
     
    21552162        }
    21562163
    2157         if ( $keys = array_keys( $custom ) ) {
     2164        $keys = array_keys( $custom );
     2165        if ( $keys ) {
    21582166                return $keys;
    21592167        }
     
    40524060        global $wpdb;
    40534061
    4054         if ( ! $post = get_post( $post ) ) {
     4062        $post = get_post( $post );
     4063        if ( ! $post ) {
    40554064                return;
    40564065        }
     
    42284237                $post                        = get_post( $post_ID );
    42294238                $conflicts_with_date_archive = false;
    4230                 if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) && $slug_num = intval( $slug ) ) {
    4231                         $permastructs   = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) );
    4232                         $postname_index = array_search( '%postname%', $permastructs );
    4233 
    4234                         /*
    4235                          * Potential date clashes are as follows:
    4236                          *
    4237                          * - Any integer in the first permastruct position could be a year.
    4238                          * - An integer between 1 and 12 that follows 'year' conflicts with 'monthnum'.
    4239                          * - An integer between 1 and 31 that follows 'monthnum' conflicts with 'day'.
    4240                          */
    4241                         if ( 0 === $postname_index ||
    4242                                 ( $postname_index && '%year%' === $permastructs[ $postname_index - 1 ] && 13 > $slug_num ) ||
    4243                                 ( $postname_index && '%monthnum%' === $permastructs[ $postname_index - 1 ] && 32 > $slug_num )
    4244                         ) {
    4245                                 $conflicts_with_date_archive = true;
     4239                if ( 'post' === $post_type && ( ! $post || $post->post_name !== $slug ) && preg_match( '/^[0-9]+$/', $slug ) ) {
     4240                        $slug_num = intval( $slug );
     4241
     4242                        if ( $slug_num ) {
     4243                                $permastructs   = array_values( array_filter( explode( '/', get_option( 'permalink_structure' ) ) ) );
     4244                                $postname_index = array_search( '%postname%', $permastructs );
     4245
     4246                                /*
     4247                                * Potential date clashes are as follows:
     4248                                *
     4249                                * - Any integer in the first permastruct position could be a year.
     4250                                * - An integer between 1 and 12 that follows 'year' conflicts with 'monthnum'.
     4251                                * - An integer between 1 and 31 that follows 'monthnum' conflicts with 'day'.
     4252                                */
     4253                                if ( 0 === $postname_index ||
     4254                                        ( $postname_index && '%year%' === $permastructs[ $postname_index - 1 ] && 13 > $slug_num ) ||
     4255                                        ( $postname_index && '%monthnum%' === $permastructs[ $postname_index - 1 ] && 32 > $slug_num )
     4256                                ) {
     4257                                        $conflicts_with_date_archive = true;
     4258                                }
    42464259                        }
    42474260                }
     
    53215334                return true;
    53225335        }
    5323         if ( $id = url_to_postid( $url ) ) {
     5336
     5337        $id = url_to_postid( $url );
     5338        if ( $id ) {
    53245339                $post = get_post( $id );
    53255340                if ( 'attachment' == $post->post_type ) {
     
    55455560function wp_get_attachment_metadata( $attachment_id = 0, $unfiltered = false ) {
    55465561        $attachment_id = (int) $attachment_id;
    5547         if ( ! $post = get_post( $attachment_id ) ) {
     5562        $post          = get_post( $attachment_id );
     5563        if ( ! $post ) {
    55485564                return false;
    55495565        }
     
    55785594function wp_update_attachment_metadata( $attachment_id, $data ) {
    55795595        $attachment_id = (int) $attachment_id;
    5580         if ( ! $post = get_post( $attachment_id ) ) {
     5596        $post          = get_post( $attachment_id );
     5597        if ( ! $post ) {
    55815598                return false;
    55825599        }
     
    55905607         * @param int   $attachment_id Attachment post ID.
    55915608         */
    5592         if ( $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID ) ) {
     5609        $data = apply_filters( 'wp_update_attachment_metadata', $data, $post->ID );
     5610        if ( $data ) {
    55935611                return update_post_meta( $post->ID, '_wp_attachment_metadata', $data );
    55945612        } else {
     
    56095627function wp_get_attachment_url( $attachment_id = 0 ) {
    56105628        $attachment_id = (int) $attachment_id;
    5611         if ( ! $post = get_post( $attachment_id ) ) {
     5629        $post          = get_post( $attachment_id );
     5630        if ( ! $post ) {
    56125631                return false;
    56135632        }
     
    56195638        $url = '';
    56205639        // Get attached file.
    5621         if ( $file = get_post_meta( $post->ID, '_wp_attached_file', true ) ) {
     5640        $file = get_post_meta( $post->ID, '_wp_attached_file', true );
     5641        if ( $file ) {
    56225642                // Get upload directory.
    5623                 if ( ( $uploads = wp_get_upload_dir() ) && false === $uploads['error'] ) {
     5643                $uploads = wp_get_upload_dir();
     5644                if ( $uploads && false === $uploads['error'] ) {
    56245645                        // Check that the upload base exists in the file location.
    56255646                        if ( 0 === strpos( $file, $uploads['basedir'] ) ) {
     
    56765697function wp_get_attachment_caption( $post_id = 0 ) {
    56775698        $post_id = (int) $post_id;
    5678         if ( ! $post = get_post( $post_id ) ) {
     5699        $post    = get_post( $post_id );
     5700        if ( ! $post ) {
    56795701                return false;
    56805702        }
     
    57075729function wp_get_attachment_thumb_file( $post_id = 0 ) {
    57085730        $post_id = (int) $post_id;
    5709         if ( ! $post = get_post( $post_id ) ) {
     5731        $post    = get_post( $post_id );
     5732        if ( ! $post ) {
    57105733                return false;
    57115734        }
    5712         if ( ! is_array( $imagedata = wp_get_attachment_metadata( $post->ID ) ) ) {
     5735
     5736        $imagedata = wp_get_attachment_metadata( $post->ID );
     5737        if ( ! is_array( $imagedata ) ) {
    57135738                return false;
    57145739        }
     
    57165741        $file = get_attached_file( $post->ID );
    57175742
    5718         if ( ! empty( $imagedata['thumb'] ) && ( $thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file ) ) && file_exists( $thumbfile ) ) {
    5719                 /**
    5720                  * Filters the attachment thumbnail file path.
    5721                  *
    5722                  * @since 2.1.0
    5723                  *
    5724                  * @param string $thumbfile File path to the attachment thumbnail.
    5725                  * @param int    $post_id   Attachment ID.
    5726                  */
    5727                 return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
     5743        if ( ! empty( $imagedata['thumb'] ) ) {
     5744                $thumbfile = str_replace( wp_basename( $file ), $imagedata['thumb'], $file );
     5745                if ( file_exists( $thumbfile ) ) {
     5746                        /**
     5747                         * Filters the attachment thumbnail file path.
     5748                         *
     5749                         * @since 2.1.0
     5750                         *
     5751                         * @param string $thumbfile File path to the attachment thumbnail.
     5752                         * @param int    $post_id   Attachment ID.
     5753                         */
     5754                        return apply_filters( 'wp_get_attachment_thumb_file', $thumbfile, $post->ID );
     5755                }
    57285756        }
    57295757        return false;
     
    57405768function wp_get_attachment_thumb_url( $post_id = 0 ) {
    57415769        $post_id = (int) $post_id;
    5742         if ( ! $post = get_post( $post_id ) ) {
     5770        $post    = get_post( $post_id );
     5771        if ( ! $post ) {
    57435772                return false;
    57445773        }
    5745         if ( ! $url = wp_get_attachment_url( $post->ID ) ) {
     5774
     5775        $url = wp_get_attachment_url( $post->ID );
     5776        if ( ! $url ) {
    57465777                return false;
    57475778        }
     
    57525783        }
    57535784
    5754         if ( ! $thumb = wp_get_attachment_thumb_file( $post->ID ) ) {
     5785        $thumb = wp_get_attachment_thumb_file( $post->ID );
     5786        if ( ! $thumb ) {
    57555787                return false;
    57565788        }
     
    57795811 */
    57805812function wp_attachment_is( $type, $post = null ) {
    5781         if ( ! $post = get_post( $post ) ) {
     5813        $post = get_post( $post );
     5814        if ( ! $post ) {
    57825815                return false;
    57835816        }
    57845817
    5785         if ( ! $file = get_attached_file( $post->ID ) ) {
     5818        $file = get_attached_file( $post->ID );
     5819        if ( ! $file ) {
    57865820                return false;
    57875821        }
     
    58545888                if ( is_numeric( $mime ) ) {
    58555889                        $mime = (int) $mime;
    5856                         if ( $post = get_post( $mime ) ) {
     5890                        $post = get_post( $mime );
     5891                        if ( $post ) {
    58575892                                $post_id = (int) $post->ID;
    58585893                                $file    = get_attached_file( $post_id );
     
    58605895                                if ( ! empty( $ext ) ) {
    58615896                                        $post_mimes[] = $ext;
    5862                                         if ( $ext_type = wp_ext2type( $ext ) ) {
     5897                                        $ext_type     = wp_ext2type( $ext );
     5898                                        if ( $ext_type ) {
    58635899                                                $post_mimes[] = $ext_type;
    58645900                                        }
     
    59065942                                $dir  = array_shift( $keys );
    59075943                                $uri  = array_shift( $dirs );
    5908                                 if ( $dh = opendir( $dir ) ) {
     5944                                $dh   = opendir( $dir );
     5945                                if ( $dh ) {
    59095946                                        while ( false !== $file = readdir( $dh ) ) {
    59105947                                                $file = wp_basename( $file );
     
    61136150                 * @param string $cap Capability.
    61146151                 */
    6115                 if ( ! $cap = apply_filters( 'pub_priv_sql_capability', '' ) ) {
     6152                $cap = apply_filters( 'pub_priv_sql_capability', '' );
     6153                if ( ! $cap ) {
    61166154                        $cap = current_user_can( $post_type_obj->cap->read_private_posts );
    61176155                }
     
    66436681
    66446682        // Now look for larger loops.
    6645         if ( ! $loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent ) ) {
     6683        $loop = wp_find_hierarchy_loop( 'wp_get_post_parent_id', $post_ID, $post_parent );
     6684        if ( ! $loop ) {
    66466685                return $post_parent; // No loop
    66476686        }
     
    67296768 */
    67306769function wp_queue_posts_for_term_meta_lazyload( $posts ) {
    6731         $post_type_taxonomies = $term_ids = array();
     6770        $post_type_taxonomies = array();
     6771        $term_ids             = array();
    67326772        foreach ( $posts as $post ) {
    67336773                if ( ! ( $post instanceof WP_Post ) ) {
Note: See TracChangeset for help on using the changeset viewer.