Make WordPress Core

Changeset 50163


Ignore:
Timestamp:
02/02/2021 08:32:42 PM (6 years ago)
Author:
whyisjake
Message:

Administration: New filter ahead of the months drop-down.

As this can cause large, long running queries on sites with many posts, this filter allows the query to be modified, bypassing entirely if needed.

Fixes #51660.

Props geoffguillain, SergeyBiryukov, hareesh-pillai, hellofromTonya, TimothyBlynJacobs, whyisjake.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/package-lock.json

    r50137 r50163  
    39223922                                                "unbzip2-stream": "^1.3.3",
    39233923                                                "ws": "^7.2.3"
    3924                                         },
    3925                                         "dependencies": {
    3926                                                 "devtools-protocol": {
    3927                                                         "version": "0.0.818844",
    3928                                                         "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.818844.tgz",
    3929                                                         "integrity": "sha512-AD1hi7iVJ8OD0aMLQU5VK0XH9LDlA1+BcPIgrAxPfaibx2DbWucuyOhc4oyQCbnvDDO68nN6/LcKfqTP343Jjg==",
    3930                                                         "dev": true
    3931                                                 }
    39323924                                        }
    39333925                                },
     
    71977189                "create-hash": {
    71987190                        "version": "1.2.0",
    7199                         "resolved": "https://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz",
     7191                        "resolved": "http://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz",
    72007192                        "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==",
    72017193                        "dev": true,
     
    72107202                "create-hmac": {
    72117203                        "version": "1.1.7",
    7212                         "resolved": "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz",
     7204                        "resolved": "http://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz",
    72137205                        "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==",
    72147206                        "dev": true,
     
    72957287                "css-color-names": {
    72967288                        "version": "0.0.4",
    7297                         "resolved": "https://registry.npmjs.org/css-color-names/-/css-color-names-0.0.4.tgz",
     7289                        "resolved": "http://registry.npmjs.org/css-color-names/-/css-color-names-0.0.4.tgz",
    72987290                        "integrity": "sha1-gIrcLnnPhHOAabZGyyDsJ762KeA=",
    72997291                        "dev": true
     
    80578049                        "dev": true
    80588050                },
     8051                "devtools-protocol": {
     8052                        "version": "0.0.818844",
     8053                        "resolved": "https://registry.npmjs.org/devtools-protocol/-/devtools-protocol-0.0.818844.tgz",
     8054                        "integrity": "sha512-AD1hi7iVJ8OD0aMLQU5VK0XH9LDlA1+BcPIgrAxPfaibx2DbWucuyOhc4oyQCbnvDDO68nN6/LcKfqTP343Jjg==",
     8055                        "dev": true
     8056                },
    80598057                "diff": {
    80608058                        "version": "4.0.2",
     
    80708068                "diffie-hellman": {
    80718069                        "version": "5.0.3",
    8072                         "resolved": "https://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz",
     8070                        "resolved": "http://registry.npmjs.org/diffie-hellman/-/diffie-hellman-5.0.3.tgz",
    80738071                        "integrity": "sha512-kqag/Nl+f3GwyK25fhUMYj81BUOrZ9IuJsjIcDE5icNM9FJHAVm3VcUDxdLPoQtTuUylWm6ZIknYJwwaPxsUzg==",
    80748072                        "dev": true,
     
    2037420372                "sha.js": {
    2037520373                        "version": "2.4.11",
    20376                         "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz",
     20374                        "resolved": "http://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz",
    2037720375                        "integrity": "sha512-QMEp5B7cftE7APOjk5Y6xgrbWu+WkLVQwk8JNjZ8nKRciZaByEW6MubieAiToS7+dwvrjGhH8jRXz3MVd0AYqQ==",
    2037820376                        "dev": true,
  • trunk/src/wp-admin/includes/class-wp-list-table.php

    r50120 r50163  
    596596                }
    597597
    598                 $extra_checks = "AND post_status != 'auto-draft'";
    599                 if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) {
    600                         $extra_checks .= " AND post_status != 'trash'";
    601                 } elseif ( isset( $_GET['post_status'] ) ) {
    602                         $extra_checks = $wpdb->prepare( ' AND post_status = %s', $_GET['post_status'] );
    603                 }
    604 
    605                 $months = $wpdb->get_results(
    606                         $wpdb->prepare(
    607                                 "
    608                         SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
    609                         FROM $wpdb->posts
    610                         WHERE post_type = %s
    611                         $extra_checks
    612                         ORDER BY post_date DESC
    613                 ",
    614                                 $post_type
    615                         )
    616                 );
    617 
    618598                /**
    619                  * Filters the 'Months' drop-down results.
     599                 * Filters to short-circuit performing the months dropdown query.
    620600                 *
    621                  * @since 3.7.0
     601                 * @since 5.7.0
    622602                 *
    623                  * @param object[] $months    Array of the months drop-down query results.
    624                  * @param string   $post_type The post type.
     603                 * @param object[]|false $months   'Months' drop-down results. Default false.
     604                 * @param string         $post_type The post type.
    625605                 */
    626                 $months = apply_filters( 'months_dropdown_results', $months, $post_type );
     606                $months = apply_filters( 'pre_months_dropdown_query', false, $post_type );
     607
     608                if ( ! is_array( $months ) ) {
     609                        $extra_checks = "AND post_status != 'auto-draft'";
     610                        if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) {
     611                                $extra_checks .= " AND post_status != 'trash'";
     612                        } elseif ( isset( $_GET['post_status'] ) ) {
     613                                $extra_checks = $wpdb->prepare( ' AND post_status = %s', $_GET['post_status'] );
     614                        }
     615
     616                        $months = $wpdb->get_results(
     617                                $wpdb->prepare(
     618                                        "
     619                                SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
     620                                FROM $wpdb->posts
     621                                WHERE post_type = %s
     622                                $extra_checks
     623                                ORDER BY post_date DESC
     624                        ",
     625                                        $post_type
     626                                )
     627                        );
     628
     629                        /**
     630                         * Filters the 'Months' drop-down results.
     631                         *
     632                         * @since 3.7.0
     633                         *
     634                         * @param object[] $months    Array of the months drop-down query results.
     635                         * @param string   $post_type The post type.
     636                         */
     637                        $months = apply_filters( 'months_dropdown_results', $months, $post_type );
     638                }
    627639
    628640                $month_count = count( $months );
Note: See TracChangeset for help on using the changeset viewer.