Make WordPress Core

Ticket #25787: 25787.diff

File 25787.diff, 16.1 KB (added by MisdaX, 10 years ago)

first attempt without breaking existing functionality

  • wp-includes/post-template.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    999999 * @param array|string $args {
    10001000 *     Array or string of arguments. Optional.
    10011001 *
    1002  *     @type int    $child_of     Display only the sub-pages of a single page by ID. Default 0 (all pages).
    1003  *     @type string $authors      Comma-separated list of author IDs. Default empty (all authors).
    1004  *     @type string $date_format  PHP date format to use for the listed pages. Relies on the 'show_date' parameter.
    1005  *                                Default is the value of 'date_format' option.
    1006  *     @type int    $depth        Number of levels in the hierarchy of pages to include in the generated list.
    1007  *                                Accepts -1 (any depth), 0 (all pages), 1 (top-level pages only), and n (pages to
    1008  *                                the given n depth). Default 0.
    1009  *     @type bool   $echo         Whether or not to echo the list of pages. Default true.
    1010  *     @type string $exclude      Comma-separated list of page IDs to exclude. Default empty.
    1011  *     @type array  $include      Comma-separated list of page IDs to include. Default empty.
    1012  *     @type string $link_after   Text or HTML to follow the page link label. Default null.
    1013  *     @type string $link_before  Text or HTML to precede the page link label. Default null.
    1014  *     @type string $post_type    Post type to query for. Default 'page'.
    1015  *     @type string $post_status  Comma-separated list of post statuses to include. Default 'publish'.
    1016  *     @type string $show_date    Whether to display the page publish or modified date for each page. Accepts
    1017  *                                'modified' or any other value. An empty value hides the date. Default empty.
    1018  *     @type string $sort_column  Comma-separated list of column names to sort the pages by. Accepts 'post_author',
    1019  *                                'post_date', 'post_title', 'post_name', 'post_modified', 'post_modified_gmt',
    1020  *                                'menu_order', 'post_parent', 'ID', 'rand', or 'comment_count'. Default 'post_title'.
    1021  *     @type string $title_li     List heading. Passing a null or empty value will result in no heading, and the list
    1022  *                                will not be wrapped with unordered list `<ul>` tags. Default 'Pages'.
    1023  *     @type Walker $walker       Walker instance to use for listing pages. Default empty (Walker_Page).
     1002 *     @type int    $child_of       Display only the sub-pages of a single page by ID. Default 0 (all pages).
     1003 *     @type string $authors        Comma-separated list of author IDs. Default empty (all authors).
     1004 *     @type string $date_format    PHP date format to use for the listed pages. Relies on the 'show_date' parameter.
     1005 *                                  Default is the value of 'date_format' option.
     1006 *     @type int    $depth          Number of levels in the hierarchy of pages to include in the generated list.
     1007 *                                  Accepts -1 (any depth), 0 (all pages), 1 (top-level pages only), and n (pages to
     1008 *                                  the given n depth). Default 0.
     1009 *     @type bool   $echo           Whether or not to echo the list of pages. Default true.
     1010 *     @type string $exclude        Comma-separated list of page IDs to exclude. Default empty.
     1011 *     @type array  $include        Comma-separated list of page IDs to include. Default empty.
     1012 *     @type string $link_after     Text or HTML to follow the page link label. Default null.
     1013 *     @type string $link_before    Text or HTML to precede the page link label. Default null.
     1014 *     @type string $post_type      Post type to query for. Default 'page'.
     1015 *     @type string $post_status    Comma-separated list of post statuses to include. Default 'publish'.
     1016 *     @type string $show_date      Whether to display the page publish or modified date for each page. Accepts
     1017 *                                  'modified' or any other value. An empty value hides the date. Default empty.
     1018 *     @type string $sort_column    Comma-separated list of column names to sort the pages by. Accepts 'post_author',
     1019 *                                  'post_date', 'post_title', 'post_name', 'post_modified', 'post_modified_gmt',
     1020 *                                  'menu_order', 'post_parent', 'ID', 'rand', or 'comment_count'. Default 'post_title'.
     1021 *     @type string $title_li       List heading. Passing a null or empty value will result in no heading, and the list
     1022 *                                  will not be wrapped with unordered list `<ul>` tags. Default 'Pages'.
     1023 *     @type Walker $walker         Walker instance to use for listing pages. Default empty (Walker_Page).
     1024 *     @type bool   $optimize_query If set to true all page attributes are fetched from database. If set to false only
     1025 *                                  the minimal necessary page attributes are fetched from the database to serve the
     1026 *                                  function. Default false.
    10241027 * }
    10251028 * @return string HTML list of pages.
    10261029 */
     
    10321035                'title_li' => __( 'Pages' ), 'echo' => 1,
    10331036                'authors' => '', 'sort_column' => 'menu_order, post_title',
    10341037                'link_before' => '', 'link_after' => '', 'walker' => '',
     1038                'optimize_query' => 0
    10351039        );
    10361040
    10371041        $r = wp_parse_args( $args, $defaults );
    10381042
     1043        $optimize_query = $r['optimize_query'];
     1044
    10391045        $output = '';
    10401046        $current_page = 0;
    10411047
     
    10561062
    10571063        // Query pages.
    10581064        $r['hierarchical'] = 0;
     1065
     1066        if ($optimize_query) {
     1067
     1068                // The whole functionality needs only this page columns/attributes
     1069                $r['restrict_columns'] = array('ID', 'post_date', 'post_title', 'post_modified', 'post_parent');
     1070        }
     1071
    10591072        $pages = get_pages( $r );
    10601073
    10611074        if ( ! empty( $pages ) ) {
     
    11111124 *     Optional. Arguments to generate a page menu. {@see wp_list_pages()}
    11121125 *     for additional arguments.
    11131126 *
    1114  * @type string     $sort_column How to short the list of pages. Accepts post column names.
    1115  *                               Default 'menu_order, post_title'.
    1116  * @type string     $menu_class  Class to use for the div ID containing the page list. Default 'menu'.
    1117  * @type bool       $echo        Whether to echo the list or return it. Accepts true (echo) or false (return).
    1118  *                               Default true.
    1119  * @type string     $link_before The HTML or text to prepend to $show_home text. Default empty.
    1120  * @type string     $link_after  The HTML or text to append to $show_home text. Default empty.
    1121  * @type int|string $show_home   Whether to display the link to the home page. Can just enter the text
    1122  *                               you'd like shown for the home link. 1|true defaults to 'Home'.
     1127 * @type string     $sort_column    How to short the list of pages. Accepts post column names.
     1128 *                                  Default 'menu_order, post_title'.
     1129 * @type string     $menu_class     Class to use for the div ID containing the page list. Default 'menu'.
     1130 * @type bool       $echo           Whether to echo the list or return it. Accepts true (echo) or false (return).
     1131 *                                  Default true.
     1132 * @type string     $link_before    The HTML or text to prepend to $show_home text. Default empty.
     1133 * @type string     $link_after     The HTML or text to append to $show_home text. Default empty.
     1134 * @type int|string $show_home      Whether to display the link to the home page. Can just enter the text
     1135 *                                  you'd like shown for the home link. 1|true defaults to 'Home'.
     1136 * @type bool       $optimize_query If set to true all page attributes are fetched from database. If set to false only
     1137 *                                  the minimal necessary page attributes are fetched from the database to serve the
     1138 *                                  function. Default false.
    11231139 * }
    11241140 * @return string html menu
    11251141 */
    11261142function wp_page_menu( $args = array() ) {
    1127         $defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true, 'link_before' => '', 'link_after' => '');
     1143        $defaults = array('sort_column' => 'menu_order, post_title', 'menu_class' => 'menu', 'echo' => true,
     1144                'link_before' => '', 'link_after' => '', 'optimize_query' => 0);
    11281145        $args = wp_parse_args( $args, $defaults );
    11291146
    11301147        /**
  • wp-includes/post.php

    IDEA additional info:
    Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
    <+>UTF-8
     
    43824382 * @param array|string $args {
    43834383 *     Optional. Array or string of arguments to retrieve pages.
    43844384 *
    4385  *     @type int          $child_of     Page ID to return child and grandchild pages of.
    4386  *                                      Default 0, or no restriction.
    4387  *     @type string       $sort_order   How to sort retrieved pages. Accepts 'ASC', 'DESC'. Default 'ASC'.
    4388  *     @type string       $sort_column  What columns to sort pages by, comma-separated. Accepts 'post_author',
    4389  *                                      'post_date', 'post_title', 'post_name', 'post_modified', 'menu_order',
    4390  *                                      'post_modified_gmt', 'post_parent', 'ID', 'rand', 'comment_count'.
    4391  *                                      'post_' can be omitted for any values that start with it.
    4392  *                                      Default 'post_title'.
    4393  *     @type bool         $hierarchical Whether to return pages hierarchically. Default true.
    4394  *     @type array        $exclude      Array of page IDs to exclude. Default empty array.
    4395  *     @type array        $include      Array of page IDs to include. Cannot be used with `$child_of`,
    4396  *                                      `$parent`, `$exclude`, `$meta_key`, `$meta_value`, or `$hierarchical`.
    4397  *                                      Default empty array.
    4398  *     @type string       $meta_key     Only include pages with this meta key. Default empty.
    4399  *     @type string       $meta_value   Only include pages with this meta value. Requires `$meta_key`.
    4400  *                                      Default empty.
    4401  *     @type string       $authors      A comma-separated list of author IDs. Default empty.
    4402  *     @type int          $parent       Page ID to return direct children of. `$hierarchical` must be false.
    4403  *                                      Default -1, or no restriction.
    4404  *     @type string|array $exclude_tree Comma-separated string or array of page IDs to exclude.
    4405  *                                      Default empty array.
    4406  *     @type int          $number       The number of pages to return. Default 0, or all pages.
    4407  *     @type int          $offset       The number of pages to skip before returning. Requires `$number`.
    4408  *                                      Default 0.
    4409  *     @type string       $post_type    The post type to query. Default 'page'.
    4410  *     @type string       $post_status  A comma-separated list of post status types to include.
    4411  *                                      Default 'publish'.
     4385 *     @type int          $child_of         Page ID to return child and grandchild pages of.
     4386 *                                          Default 0, or no restriction.
     4387 *     @type string       $sort_order       How to sort retrieved pages. Accepts 'ASC', 'DESC'. Default 'ASC'.
     4388 *     @type string       $sort_column      What columns to sort pages by, comma-separated. Accepts 'post_author',
     4389 *                                          'post_date', 'post_title', 'post_name', 'post_modified', 'menu_order',
     4390 *                                          'post_modified_gmt', 'post_parent', 'ID', 'rand', 'comment_count'.
     4391 *                                          'post_' can be omitted for any values that start with it.
     4392 *                                          Default 'post_title'.
     4393 *     @type bool         $hierarchical     Whether to return pages hierarchically. Default true.
     4394 *     @type array        $exclude          Array of page IDs to exclude. Default empty array.
     4395 *     @type array        $include          Array of page IDs to include. Cannot be used with `$child_of`,
     4396 *                                          `$parent`, `$exclude`, `$meta_key`, `$meta_value`, or `$hierarchical`.
     4397 *                                          Default empty array.
     4398 *     @type string       $meta_key         Only include pages with this meta key. Default empty.
     4399 *     @type string       $meta_value       Only include pages with this meta value. Requires `$meta_key`.
     4400 *                                          Default empty.
     4401 *     @type string       $authors          A comma-separated list of author IDs. Default empty.
     4402 *     @type int          $parent           Page ID to return direct children of. `$hierarchical` must be false.
     4403 *                                          Default -1, or no restriction.
     4404 *     @type string|array $exclude_tree     Comma-separated string or array of page IDs to exclude.
     4405 *                                          Default empty array.
     4406 *     @type int          $number           The number of pages to return. Default 0, or all pages.
     4407 *     @type int          $offset           The number of pages to skip before returning. Requires `$number`.
     4408 *                                          Default 0.
     4409 *     @type string       $post_type        The post type to query. Default 'page'.
     4410 *     @type string       $post_status      A comma-separated list of post status types to include.
     4411 *                                          Default 'publish'.
     4412 *     @type array        $restrict_columns Array of column names from wp_posts. Only these columns will be fetched
     4413 *                                          from the database if the array is not empty. That means that the fields
     4414 *                                          in the returning "page" objects will be empty too. Default empty array.
    44124415 * }
    44134416 * @return array List of pages matching defaults or `$args`.
    44144417 */
     
    44234426                'authors' => '', 'parent' => -1, 'exclude_tree' => array(),
    44244427                'number' => '', 'offset' => 0,
    44254428                'post_type' => 'page', 'post_status' => 'publish',
     4429                'restrict_columns' => array()
    44264430        );
    44274431
    44284432        $r = wp_parse_args( $args, $defaults );
     
    44364440        $meta_value = $r['meta_value'];
    44374441        $parent = $r['parent'];
    44384442        $post_status = $r['post_status'];
     4443        $restrict_columns = $r['restrict_columns'];
    44394444
    44404445        // Make sure the post type is hierarchical.
    44414446        $hierarchical_post_types = get_post_types( array( 'hierarchical' => true ) );
     
    45984603                $sort_order = 'ASC';
    45994604        }
    46004605
    4601         $query = "SELECT * FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
     4606        // select all columns by default
     4607        $columns_to_select = '*';
     4608
     4609        // all existing columns from wp_posts
     4610        $existing_columns = array('ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title',
     4611                'post_excerpt', 'post_status', 'comment_status', 'ping_status', 'post_password', 'post_name', 'to_ping',
     4612                'pinged', 'post_modified', 'post_modified_gmt', 'post_content_filtered', 'post_parent', 'guid', 'menu_order',
     4613                'post_type', 'post_mime_type', 'comment_count');
     4614
     4615        // is the argument set?
     4616        if (is_array($restrict_columns) && count($restrict_columns) > 0) {
     4617
     4618                // validate the columns (filter the argument)
     4619                $restrict_columns_filtered = array_intersect($existing_columns, $restrict_columns);
     4620
     4621                // items left after filtering? -> replace the default select
     4622                if (count($restrict_columns_filtered) > 0) {
     4623                        $columns_to_select = implode(',', $restrict_columns_filtered);
     4624                }
     4625        }
     4626
     4627        // build the query
     4628        $query = "SELECT $columns_to_select FROM $wpdb->posts $join WHERE ($where_post_type) $where ";
    46024629        $query .= $author_query;
    4603         $query .= " ORDER BY " . $sort_column . " " . $sort_order ;
     4630        $query .= " ORDER BY " . $sort_column . " " . $sort_order;
    46044631
    4605         if ( ! empty( $number ) ) {
     4632        if (!empty($number)) {
    46064633                $query .= ' LIMIT ' . $offset . ',' . $number;
    46074634        }
    46084635