WordPress.org

Make WordPress Core

Ticket #44034: 44034.diff

File 44034.diff, 2.0 KB (added by birgire, 2 years ago)
  • src/wp-admin/includes/user.php

    diff --git src/wp-admin/includes/user.php src/wp-admin/includes/user.php
    index 7694889..69ba6dc 100644
    function _wp_privacy_hook_requests_page() { 
    995995        add_submenu_page( 'tools.php', __( 'Erase Personal Data' ), __( 'Erase Personal Data' ), 'erase_others_personal_data', 'remove_personal_data', '_wp_personal_data_removal_page' );
    996996}
    997997
     998/**
     999 * Count user requests of a given type.
     1000 *
     1001 * @since 4.9.7
     1002 *
     1003 * @param  string $type   Request type. Supported types are
     1004 *                        'remove_personal_data' and 'export_personal_data'.
     1005 * @return object $counts Number of request types for each status.
     1006 */
     1007function wp_count_user_requests( $type = '' ) {
     1008        global $wpdb;
     1009
     1010        $types = array( 'remove_personal_data', 'export_personal_data' );
     1011
     1012        if ( ! in_array( $type, $types, true ) ) {
     1013                return new stdClass;
     1014        }
     1015               
     1016        $cache_key = 'user-request-' . $type;
     1017        $counts    = wp_cache_get( $cache_key, 'counts' );
     1018
     1019        if ( false !== $counts ) {
     1020                return $counts;
     1021        }
     1022
     1023        $query = "
     1024                SELECT post_status, COUNT( * ) AS num_posts
     1025                FROM {$wpdb->posts}
     1026                WHERE post_type = %s
     1027                AND post_name = %s
     1028                GROUP BY post_status";
     1029       
     1030        $results = (array) $wpdb->get_results( $wpdb->prepare( $query, 'user_request', $type ), ARRAY_A );
     1031        $counts  = array_fill_keys( get_post_stati(), 0 );
     1032
     1033        foreach ( $results as $row ) {
     1034                $counts[ $row['post_status'] ] = $row['num_posts'];
     1035        }
     1036
     1037        $counts = (object) $counts;
     1038        wp_cache_set( $cache_key, $counts, 'counts' );
     1039
     1040        /**
     1041         * Modify returned user request counts, of a given type, by status.
     1042         *
     1043         * @since 4.9.7
     1044         *
     1045         * @param object $counts Number of request types for each status.
     1046         * @param string $type   Request type.
     1047         */
     1048        return apply_filters( 'wp_count_user_requests', $counts, $type );
     1049}
     1050
    9981051// TODO: move the following classes in new files.
    9991052if ( ! class_exists( 'WP_List_Table' ) ) {
    10001053        require_once( ABSPATH . 'wp-admin/includes/class-wp-list-table.php' );