generated from alleyinteractive/create-wordpress-plugin
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclass-wp-curate.php
65 lines (57 loc) · 1.77 KB
/
class-wp-curate.php
1
2
3
4
5
6
7
8
9
10
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<?php
/**
* WP_Curate class file
*
* @package wp-curate
*/
namespace Alley\WP\WP_Curate;
/**
* WP_Curate class.
*/
class WP_Curate {
/**
* Set things up.
*/
public function __construct() {
add_filter( 'rest_post_query', [ $this, 'add_type_param' ], 10, 2 );
}
/**
* Add post_type to rest post query if the type param is set.
*
* @param array<array<int, string>|string> $query_args The existing query args.
* @param \WP_REST_Request $request The REST request.
* @return array<array<int, string>|string>
*/
public function add_type_param( $query_args, $request ): array { // @phpstan-ignore-line
if ( ! empty( $request->get_param( 'type' ) ) && is_string( $request->get_param( 'type' ) ) ) {
$types = explode( ',', $request->get_param( 'type' ) );
$types = array_filter( $types, 'post_type_exists' );
$query_args['post_type'] = $types;
}
return $query_args;
}
/**
* Get the query heading based on the curation settings.
*
* @param array<mixed> $curation Curation settings.
* @return string Query heading.
*/
public static function get_query_heading( array $curation ): string {
$heading = '';
$provider = $curation[ 'provider' ];
if ( taxonomy_exists( $provider ) && isset( $curation[ $provider ] ) && is_numeric( $curation[ $provider ] ) ) { // @phpstan-ignore-line
$term = get_term( $curation[ $provider ], $provider ); // @phpstan-ignore-line
if ( $term instanceof \WP_Term ) {
$heading = html_entity_decode( $term->name );
}
}
/**
* Filters the query heading.
*
* @param string $heading Default heading.
* @param array $curation Curation settings.
*/
$heading = apply_filters( 'wp_curate_query_heading', $heading, $curation );
return $heading;
}
}