PluginProbe
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More / 2.6.2
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More v2.6.2
trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.10 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.1.8 2.0.0 2.0.1 2.0.10 2.0.11 2.0.12 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 47 releases
content-control / classes / Controllers / Compatibility / BetterDocs.php

BetterDocs.php in Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More 2.6.2, at classes/Controllers/Compatibility/BetterDocs.php

80 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * BetterDocs controller class.
4 *
5 * @package ContentControl
6 */
7
8 namespace ContentControl\Controllers\Compatibility;
9
10 use ContentControl\Base\Controller;
11
12 /**
13 * BetterDocs controller class.
14 */
15 class BetterDocs extends Controller {
16
17 /**
18 * Initiate hooks & filter.
19 *
20 * @return void
21 */
22 public function init() {
23 add_filter( 'content_control/get_rest_api_intent', [ $this, 'get_rest_api_intent' ], 10 );
24 }
25
26 /**
27 * Check if controller is enabled.
28 *
29 * @return bool
30 */
31 public function controller_enabled() {
32 return defined( 'BETTERDOCS_PLUGIN_FILE' );
33 }
34
35 /**
36 * Get intent for BetterDocs.
37 *
38 * @param array<string,mixed> $intent Intent.
39 *
40 * @return array<string,mixed>
41 */
42 public function get_rest_api_intent( $intent ) {
43 global $wp;
44
45 $rest_route = $wp->query_vars['rest_route'];
46 $endpoint_parts = explode( '/', str_replace( '/wp/v2/', '', $rest_route ) );
47
48 // Set the custom search intent.
49 if ( isset( $wp->query_vars['search'] ) ) {
50 $intent['search'] = sanitize_title( $wp->query_vars['search'] );
51 }
52
53 if ( 'unknown' === $intent['type'] && 'docs' === $intent['name'] ) {
54 // If we have a post type or taxonomy, the name is the first part (posts, categories).
55 $post_type = sanitize_key( $endpoint_parts[0] );
56
57 if ( 'docs' === $post_type ) {
58 $intent['type'] = 'post_type';
59 }
60 }
61
62 // phpcs:disable WordPress.Security.NonceVerification.Recommended
63 if ( isset( $_REQUEST['post_type'] ) ) {
64 $post_type = sanitize_text_field( wp_unslash( $_REQUEST['post_type'] ) );
65
66 // Check if any ct_forced_* request aregs are set. If so we should use the post type intent.
67 if ( strpos( $post_type, 'ct_forced_' ) !== false ) {
68 $intent['type'] = 'post_type';
69
70 $post_type = str_replace( 'ct_forced_', '', $post_type );
71
72 $intent['name'] = explode( ':', $post_type );
73 }
74 }
75 // phpcs:enable WordPress.Security.NonceVerification.Recommended
76
77 return $intent;
78 }
79 }
80