WP_Privacy_Requests_Table::get_request_counts() WordPress Method

The WP_Privacy_Requests_Table::get_request_counts() method is used to get the number of privacy requests for each request type. The types of requests are: - Export personal data - Erase personal data The request counts are returned as an associative array, with the request types as the keys, and the request counts as the values.

WP_Privacy_Requests_Table::get_request_counts() #

Count number of requests for each status.


Return

(object) Number of posts for each status.


Top ↑

Source

File: wp-admin/includes/class-wp-privacy-requests-table.php

	protected function get_request_counts() {
		global $wpdb;

		$cache_key = $this->post_type . '-' . $this->request_type;
		$counts    = wp_cache_get( $cache_key, 'counts' );

		if ( false !== $counts ) {
			return $counts;
		}

		$query = "
			SELECT post_status, COUNT( * ) AS num_posts
			FROM {$wpdb->posts}
			WHERE post_type = %s
			AND post_name = %s
			GROUP BY post_status";

		$results = (array) $wpdb->get_results( $wpdb->prepare( $query, $this->post_type, $this->request_type ), ARRAY_A );
		$counts  = array_fill_keys( get_post_stati(), 0 );

		foreach ( $results as $row ) {
			$counts[ $row['post_status'] ] = $row['num_posts'];
		}

		$counts = (object) $counts;
		wp_cache_set( $cache_key, $counts, 'counts' );

		return $counts;
	}


Top ↑

Changelog

Changelog
VersionDescription
4.9.6Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.