Make WordPress Core


Ignore:
Timestamp:
01/29/2020 12:43:23 AM (6 years ago)
Author:
SergeyBiryukov
Message:

Docs: Improve inline comments per the documentation standards.

Includes minor code layout fixes for better readability.

See #48303.

File:
1 edited

Legend:

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

    r47052 r47122  
    772772        $qv['m']        = is_scalar( $qv['m'] ) ? preg_replace( '|[^0-9]|', '', $qv['m'] ) : '';
    773773        $qv['paged']    = absint( $qv['paged'] );
    774         $qv['cat']      = preg_replace( '|[^0-9,-]|', '', $qv['cat'] ); // comma separated list of positive or negative integers
    775         $qv['author']   = preg_replace( '|[^0-9,-]|', '', $qv['author'] ); // comma separated list of positive or negative integers
     774        $qv['cat']      = preg_replace( '|[^0-9,-]|', '', $qv['cat'] );    // Comma-separated list of positive or negative integers.
     775        $qv['author']   = preg_replace( '|[^0-9,-]|', '', $qv['author'] ); // Comma-separated list of positive or negative integers.
    776776        $qv['pagename'] = trim( $qv['pagename'] );
    777777        $qv['name']     = trim( $qv['name'] );
     
    813813            $this->is_single = true;
    814814        } elseif ( ( '' !== $qv['hour'] ) && ( '' !== $qv['minute'] ) && ( '' !== $qv['second'] ) && ( '' != $qv['year'] ) && ( '' != $qv['monthnum'] ) && ( '' != $qv['day'] ) ) {
    815             // If year, month, day, hour, minute, and second are set, a single
    816             // post is being queried.
     815            // If year, month, day, hour, minute, and second are set,
     816            // a single post is being queried.
    817817            $this->is_single = true;
    818818        } elseif ( '' != $qv['pagename'] || ! empty( $qv['page_id'] ) ) {
     
    949949        }
    950950
    951         // if we're previewing inside the write screen
     951        // If we're previewing inside the write screen.
    952952        if ( '' != $qv['preview'] ) {
    953953            $this->is_preview = true;
     
    975975        }
    976976
    977         // Correct is_* for page_on_front and page_for_posts
     977        // Correct `is_*` for 'page_on_front' and 'page_for_posts'.
    978978        if ( $this->is_home && 'page' == get_option( 'show_on_front' ) && get_option( 'page_on_front' ) ) {
    979979            $_query = wp_parse_args( $this->query );
    980             // pagename can be set and empty depending on matched rewrite rules. Ignore an empty pagename.
     980            // 'pagename' can be set and empty depending on matched rewrite rules. Ignore an empty 'pagename'.
    981981            if ( isset( $_query['pagename'] ) && '' == $_query['pagename'] ) {
    982982                unset( $_query['pagename'] );
     
    989989                $this->is_home = false;
    990990                $qv['page_id'] = get_option( 'page_on_front' );
    991                 // Correct <!--nextpage--> for page_on_front
     991                // Correct <!--nextpage--> for 'page_on_front'.
    992992                if ( ! empty( $qv['paged'] ) ) {
    993993                    $qv['page'] = $qv['paged'];
     
    10021002            if ( $this->queried_object && 'attachment' == $this->queried_object->post_type ) {
    10031003                if ( preg_match( '/^[^%]*%(?:postname)%/', get_option( 'permalink_structure' ) ) ) {
    1004                     // See if we also have a post with the same slug
     1004                    // See if we also have a post with the same slug.
    10051005                    $post = get_page_by_path( $qv['pagename'], OBJECT, 'post' );
    10061006                    if ( $post ) {
     
    10621062
    10631063        $this->is_singular = $this->is_single || $this->is_page || $this->is_attachment;
    1064         // Done correcting is_* for page_on_front and page_for_posts
     1064        // Done correcting `is_*` for 'page_on_front' and 'page_for_posts'.
    10651065
    10661066        if ( '404' == $qv['error'] ) {
     
    11091109        foreach ( get_taxonomies( array(), 'objects' ) as $taxonomy => $t ) {
    11101110            if ( 'post_tag' == $taxonomy ) {
    1111                 continue;   // Handled further down in the $q['tag'] block
     1111                continue; // Handled further down in the $q['tag'] block.
    11121112            }
    11131113
     
    11491149        }
    11501150
    1151         // If querystring 'cat' is an array, implode it.
     1151        // If query string 'cat' is an array, implode it.
    11521152        if ( is_array( $q['cat'] ) ) {
    11531153            $q['cat'] = implode( ',', $q['cat'] );
    11541154        }
    11551155
    1156         // Category stuff
     1156        // Category stuff.
     1157
    11571158        if ( ! empty( $q['cat'] ) && ! $this->is_singular ) {
    11581159            $cat_in     = array();
     
    12321233        }
    12331234
    1234         // If querystring 'tag' is array, implode it.
     1235        // If query string 'tag' is array, implode it.
    12351236        if ( is_array( $q['tag'] ) ) {
    12361237            $q['tag'] = implode( ',', $q['tag'] );
    12371238        }
    12381239
    1239         // Tag stuff
     1240        // Tag stuff.
     1241
    12401242        if ( '' != $q['tag'] && ! $this->is_singular && $this->query_vars_changed ) {
    12411243            if ( strpos( $q['tag'], ',' ) !== false ) {
     
    13371339        $search = '';
    13381340
    1339         // added slashes screw with quote grouping when done early, so done later
     1341        // Added slashes screw with quote grouping when done early, so done later.
    13401342        $q['s'] = stripslashes( $q['s'] );
    13411343        if ( empty( $_GET['s'] ) && $this->is_main_query() ) {
    13421344            $q['s'] = urldecode( $q['s'] );
    13431345        }
    1344         // there are no line breaks in <input /> fields
     1346        // There are no line breaks in <input /> fields.
    13451347        $q['s']                  = str_replace( array( "\r", "\n" ), '', $q['s'] );
    13461348        $q['search_terms_count'] = 1;
     
    13511353                $q['search_terms_count'] = count( $matches[0] );
    13521354                $q['search_terms']       = $this->parse_search_terms( $matches[0] );
    1353                 // if the search string has only short terms or stopwords, or is 10+ terms long, match it as sentence
     1355                // If the search string has only short terms or stopwords, or is 10+ terms long, match it as sentence.
    13541356                if ( empty( $q['search_terms'] ) || count( $q['search_terms'] ) > 9 ) {
    13551357                    $q['search_terms'] = array( $q['s'] );
     
    14251427
    14261428        foreach ( $terms as $term ) {
    1427             // keep before/after spaces when term is for exact match
     1429            // Keep before/after spaces when term is for exact match.
    14281430            if ( preg_match( '/^".+"$/', $term ) ) {
    14291431                $term = trim( $term, "\"'" );
     
    15151517            $search_orderby = '';
    15161518
    1517             // sentence match in 'post_title'
     1519            // Sentence match in 'post_title'.
    15181520            if ( $like ) {
    15191521                $search_orderby .= $wpdb->prepare( "WHEN {$wpdb->posts}.post_title LIKE %s THEN 1 ", $like );
    15201522            }
    15211523
    1522             // sanity limit, sort as sentence when more than 6 terms
    1523             // (few searches are longer than 6 terms and most titles are not)
     1524            // Sanity limit, sort as sentence when more than 6 terms
     1525            // (few searches are longer than 6 terms and most titles are not).
    15241526            if ( $num_terms < 7 ) {
    1525                 // all words in title
     1527                // All words in title.
    15261528                $search_orderby .= 'WHEN ' . implode( ' AND ', $q['search_orderby_title'] ) . ' THEN 2 ';
    1527                 // any word in title, not needed when $num_terms == 1
     1529                // Any word in title, not needed when $num_terms == 1.
    15281530                if ( $num_terms > 1 ) {
    15291531                    $search_orderby .= 'WHEN ' . implode( ' OR ', $q['search_orderby_title'] ) . ' THEN 3 ';
     
    15411543            }
    15421544        } else {
    1543             // single word or sentence search
     1545            // Single word or sentence search.
    15441546            $search_orderby = reset( $q['search_orderby_title'] ) . ' DESC';
    15451547        }
     
    17731775        $q = &$this->query_vars;
    17741776
    1775         // Fill again in case pre_get_posts unset some vars.
     1777        // Fill again in case 'pre_get_posts' unset some vars.
    17761778        $q = $this->fill_query_vars( $q );
    17771779
    1778         // Parse meta query
     1780        // Parse meta query.
    17791781        $this->meta_query = new WP_Meta_Query();
    17801782        $this->meta_query->parse_query_vars( $q );
    17811783
    1782         // Set a flag if a pre_get_posts hook changed the query vars.
     1784        // Set a flag if a 'pre_get_posts' hook changed the query vars.
    17831785        $hash = md5( serialize( $this->query_vars ) );
    17841786        if ( $hash != $this->query_vars_hash ) {
     
    17881790        unset( $hash );
    17891791
    1790         // First let's clear some variables
     1792        // First let's clear some variables.
    17911793        $distinct         = '';
    17921794        $whichauthor      = '';
     
    18721874
    18731875        if ( $this->is_feed ) {
    1874             // This overrides posts_per_page.
     1876            // This overrides 'posts_per_page'.
    18751877            if ( ! empty( $q['posts_per_rss'] ) ) {
    18761878                $q['posts_per_page'] = $q['posts_per_rss'];
     
    19231925            $where .= " AND {$wpdb->posts}.menu_order = " . $q['menu_order'];
    19241926        }
    1925         // The "m" parameter is meant for months but accepts datetimes of varying specificity
     1927        // The "m" parameter is meant for months but accepts datetimes of varying specificity.
    19261928        if ( $q['m'] ) {
    19271929            $where .= " AND YEAR({$wpdb->posts}.post_date)=" . substr( $q['m'], 0, 4 );
     
    19431945        }
    19441946
    1945         // Handle the other individual date parameters
     1947        // Handle the other individual date parameters.
    19461948        $date_parameters = array();
    19471949
     
    19801982        unset( $date_parameters, $date_query );
    19811983
    1982         // Handle complex date queries
     1984        // Handle complex date queries.
    19831985        if ( ! empty( $q['date_query'] ) ) {
    19841986            $this->date_query = new WP_Date_Query( $q['date_query'] );
     
    20052007                // Only one request for a slug is possible, this is why name & pagename are overwritten above.
    20062008                break;
    2007             } //end foreach
     2009            } // End foreach.
    20082010            unset( $ptype_obj );
    20092011        }
     
    20732075        }
    20742076
    2075         // If a post number is specified, load that post
     2077        // If a post number is specified, load that post.
    20762078        if ( $q['p'] ) {
    20772079            $where .= " AND {$wpdb->posts}.ID = " . $q['p'];
     
    21182120        }
    21192121
    2120         // Taxonomies
     2122        // Taxonomies.
    21212123        if ( ! $this->is_singular ) {
    21222124            $this->parse_tax_query( $q );
     
    21302132        if ( $this->is_tax ) {
    21312133            if ( empty( $post_type ) ) {
    2132                 // Do a fully inclusive search for currently registered post types of queried taxonomies
     2134                // Do a fully inclusive search for currently registered post types of queried taxonomies.
    21332135                $post_type  = array();
    21342136                $taxonomies = array_keys( $this->tax_query->queried_terms );
     
    21822184            }
    21832185
    2184             // 'cat', 'category_name', 'tag_id'
     2186            // 'cat', 'category_name', 'tag_id'.
    21852187            foreach ( $this->tax_query->queried_terms as $queried_taxonomy => $queried_items ) {
    21862188                if ( empty( $queried_items['terms'][0] ) ) {
     
    22112213        }
    22122214
    2213         // Author/user stuff
     2215        // Author/user stuff.
    22142216
    22152217        if ( ! empty( $q['author'] ) && $q['author'] != '0' ) {
     
    22312233        }
    22322234
    2233         // Author stuff for nice URLs
     2235        // Author stuff for nice URLs.
    22342236
    22352237        if ( '' != $q['author_name'] ) {
     
    22372239                $q['author_name'] = explode( '/', $q['author_name'] );
    22382240                if ( $q['author_name'][ count( $q['author_name'] ) - 1 ] ) {
    2239                     $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 1 ]; // no trailing slash
     2241                    $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 1 ]; // No trailing slash.
    22402242                } else {
    2241                     $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 2 ]; // there was a trailing slash
     2243                    $q['author_name'] = $q['author_name'][ count( $q['author_name'] ) - 2 ]; // There was a trailing slash.
    22422244                }
    22432245            }
     
    22772279        }
    22782280
    2279         // MIME-Type stuff for attachment browsing
     2281        // MIME-Type stuff for attachment browsing.
    22802282
    22812283        if ( isset( $q['post_mime_type'] ) && '' != $q['post_mime_type'] ) {
     
    25652567        }
    25662568
    2567         // Paging
     2569        // Paging.
    25682570        if ( empty( $q['nopaging'] ) && ! $this->is_singular ) {
    25692571            $page = absint( $q['paged'] );
     
    25822584        }
    25832585
    2584         // Comments feeds
     2586        // Comments feeds.
    25852587        if ( $this->is_comment_feed && ! $this->is_singular ) {
    25862588            if ( $this->is_archive || $this->is_search ) {
     
    25882590                $cwhere   = "WHERE comment_approved = '1' $where";
    25892591                $cgroupby = "{$wpdb->comments}.comment_id";
    2590             } else { // Other non singular e.g. front
     2592            } else { // Other non-singular, e.g. front.
    25912593                $cjoin    = "JOIN {$wpdb->posts} ON ( {$wpdb->comments}.comment_post_ID = {$wpdb->posts}.ID )";
    25922594                $cwhere   = "WHERE ( post_status = 'publish' OR ( post_status = 'inherit' AND post_type = 'attachment' ) ) AND comment_approved = '1'";
     
    26512653
    26522654            $comments = (array) $wpdb->get_results( "SELECT $distinct {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits" );
    2653             // Convert to WP_Comment
     2655            // Convert to WP_Comment.
    26542656            $this->comments      = array_map( 'get_comment', $comments );
    26552657            $this->comment_count = count( $this->comments );
     
    29912993
    29922994            if ( $split_the_query ) {
    2993                 // First get the IDs and then fill in the objects
     2995                // First get the IDs and then fill in the objects.
    29942996
    29952997                $this->request = "SELECT $found_rows $distinct {$wpdb->posts}.ID FROM {$wpdb->posts} $join WHERE 1=1 $where $groupby $orderby $limits";
     
    30573059            $comments_request = "SELECT {$wpdb->comments}.* FROM {$wpdb->comments} $cjoin $cwhere $cgroupby $corderby $climits";
    30583060            $comments         = $wpdb->get_results( $comments_request );
    3059             // Convert to WP_Comment
     3061            // Convert to WP_Comment.
    30603062            $this->comments      = array_map( 'get_comment', $comments );
    30613063            $this->comment_count = count( $this->comments );
     
    31123114        }
    31133115
    3114         // Put sticky posts at the top of the posts array
     3116        // Put sticky posts at the top of the posts array.
    31153117        $sticky_posts = get_option( 'sticky_posts' );
    31163118        if ( $this->is_home && $page <= 1 && is_array( $sticky_posts ) && ! empty( $sticky_posts ) && ! $q['ignore_sticky_posts'] ) {
     
    31213123                if ( in_array( $this->posts[ $i ]->ID, $sticky_posts ) ) {
    31223124                    $sticky_post = $this->posts[ $i ];
    3123                     // Remove sticky from current position
     3125                    // Remove sticky from current position.
    31243126                    array_splice( $this->posts, $i, 1 );
    3125                     // Move to front, after other stickies
     3127                    // Move to front, after other stickies.
    31263128                    array_splice( $this->posts, $sticky_offset, 0, array( $sticky_post ) );
    31273129                    // Increment the sticky offset. The next sticky will be placed at this offset.
    31283130                    $sticky_offset++;
    3129                     // Remove post from sticky posts array
     3131                    // Remove post from sticky posts array.
    31303132                    $offset = array_search( $sticky_post->ID, $sticky_posts );
    31313133                    unset( $sticky_posts[ $offset ] );
     
    31383140            }
    31393141
    3140             // Fetch sticky posts that weren't in the query results
     3142            // Fetch sticky posts that weren't in the query results.
    31413143            if ( ! empty( $sticky_posts ) ) {
    31423144                $stickies = get_posts(
     
    32813283        $this->in_the_loop = true;
    32823284
    3283         if ( $this->current_post == -1 ) { // loop has just started
     3285        if ( $this->current_post == -1 ) { // Loop has just started.
    32843286            /**
    32853287             * Fires once the loop is started.
     
    33173319             */
    33183320            do_action_ref_array( 'loop_end', array( &$this ) );
    3319             // Do some cleaning up after the loop
     3321            // Do some cleaning up after the loop.
    33203322            $this->rewind_posts();
    33213323        } elseif ( 0 === $this->post_count ) {
     
    37903792        }
    37913793
    3792         // Only a Taxonomy provided.
     3794        // Only a taxonomy provided.
    37933795        if ( empty( $term ) ) {
    37943796            return true;
     
    38873889     */
    38883890    public function is_front_page() {
    3889         // most likely case
     3891        // Most likely case.
    38903892        if ( 'posts' == get_option( 'show_on_front' ) && $this->is_home() ) {
    38913893            return true;
Note: See TracChangeset for help on using the changeset viewer.