functions.php 1.16 KB
Newer Older
1
2
<?php

3
namespace Automattic\WP\Cron_Control;
4

5
6
7
8
9
10
/**
 * Check if an event is an internal one that the plugin will always run
 */
function is_internal_event( $action ) {
	return Internal_Events::instance()->is_internal_event( $action );
}
11

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
 * Check if the current request is to one of the plugin's REST endpoints
 *
 * @param string $type list|run
 *
 * @return bool
 */
function is_rest_endpoint_request( $type = 'list' ) {
	// Which endpoint are we checking
	$endpoint = null;
	switch ( $type ) {
		case 'list' :
			$endpoint = REST_API::ENDPOINT_LIST;
			break;

		case 'run' :
			$endpoint = REST_API::ENDPOINT_RUN;
			break;
	}

	// No endpoint to check
	if ( is_null( $endpoint ) ) {
		return false;
	}

	// Build the full endpoint and check against the current request
	$run_endpoint = sprintf( '%s/%s/%s', rest_get_url_prefix(), REST_API::API_NAMESPACE, $endpoint );

	return in_array( $run_endpoint, parse_request() );
}

43
44
/**
 * Flush plugin's internal caches
45
46
 *
 * FOR INTERNAL USE ONLY - see WP-CLI; all other cache clearance should happen through the `Cron_Options_CPT` class
47
 */
48
function _flush_internal_caches() {
49
50
	return wp_cache_delete( Cron_Options_CPT::CACHE_KEY );
}