Completed
Branch develop (6e04c9)
by
unknown
02:44
created

core-integration.php ➔ wp_parse_slug_list()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 3
eloc 6
nc 4
nop 1
dl 0
loc 11
rs 9.4285
1
<?php
2
/**
3
 * Integration points with WordPress core that won't ever be committed
4
 */
5
6
/**
7
 * Inject `parent__in` and `parent__not_in` vars to avoid bad cache
8
 *
9
 * @see https://core.trac.wordpress.org/ticket/35677
10
 */
11
function wp_api_comment_query_vars( $query ) {
12
	$query->query_var_defaults['parent__in'] = array();
13
	$query->query_var_defaults['parent__not_in'] = array();
14
}
15
add_action( 'pre_get_comments', 'wp_api_comment_query_vars' );
16
17
if ( ! function_exists( 'wp_parse_slug_list' ) ) {
18
	/**
19
	 * Clean up an array, comma- or space-separated list of slugs.
20
	 *
21
	 * @since
22
	 *
23
	 * @param  array|string $list List of slugs.
24
	 * @return array Sanitized array of slugs.
25
	 */
26
	function wp_parse_slug_list( $list ) {
27
		if ( ! is_array( $list ) ) {
28
			$list = preg_split( '/[\s,]+/', $list );
29
		}
30
31
		foreach ( $list as $key => $value ) {
32
			$list[ $key ] = sanitize_title( $value );
33
		}
34
35
		return array_unique( $list );
36
	}
37
}
38
39
if ( ! function_exists( 'rest_get_server' ) ) {
40
	/**
41
	 * Retrieves the current REST server instance.
42
	 *
43
	 * Instantiates a new instance if none exists already.
44
	 *
45
	 * @since 4.5.0
46
	 *
47
	 * @global WP_REST_Server $wp_rest_server REST server instance.
48
	 *
49
	 * @return WP_REST_Server REST server instance.
50
	 */
51
	function rest_get_server() {
52
		/* @var WP_REST_Server $wp_rest_server */
53
		global $wp_rest_server;
54
55
		if ( empty( $wp_rest_server ) ) {
56
			/**
57
			 * Filter the REST Server Class.
58
			 *
59
			 * This filter allows you to adjust the server class used by the API, using a
60
			 * different class to handle requests.
61
			 *
62
			 * @since 4.4.0
63
			 *
64
			 * @param string $class_name The name of the server class. Default 'WP_REST_Server'.
65
			 */
66
			$wp_rest_server_class = apply_filters( 'wp_rest_server_class', 'WP_REST_Server' );
67
			$wp_rest_server = new $wp_rest_server_class;
68
69
			/**
70
			 * Fires when preparing to serve an API request.
71
			 *
72
			 * Endpoint objects should be created and register their hooks on this action rather
73
			 * than another action to ensure they're only loaded when needed.
74
			 *
75
			 * @since 4.4.0
76
			 *
77
			 * @param WP_REST_Server $wp_rest_server Server object.
78
			 */
79
			do_action( 'rest_api_init', $wp_rest_server );
80
		}
81
82
		return $wp_rest_server;
83
	}
84
}
85