PluginProbe
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More / 2.6.3
Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More v2.6.3
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 / QueryMonitor / Collector.php

Collector.php in Content Control – The Ultimate Content Restriction Plugin! Restrict Content, Create Conditional Blocks & More 2.6.3, at classes/QueryMonitor/Collector.php

127 lines 3.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Content Control debug collector.
4 *
5 * @package ContentControl
6 */
7
8 namespace ContentControl\QueryMonitor;
9
10 use ContentControl\QueryMonitor\Data;
11 use QM_DataCollector;
12
13 defined( 'ABSPATH' ) || exit;
14
15
16 /**
17 * Debug data collector.
18 *
19 * @phpstan-template T of \ContentControl\QueryMonitor\Data
20 */
21 class Collector extends QM_DataCollector {
22
23 /**
24 * Collector ID.
25 *
26 * @var string
27 */
28 public $id = 'content-control';
29
30 /**
31 * The data.
32 *
33 * @var Data
34 * @phpstan-var T
35 */
36 protected $data;
37
38 /**
39 * Name of the output class.
40 *
41 * @return string
42 */
43 public function name() {
44 return __( 'Content Control', 'content-control' );
45 }
46
47 /**
48 * Set up.
49 *
50 * @return void
51 */
52 public function set_up() {
53 parent::set_up();
54 add_filter( 'content_control/user_can_view_content', [ $this, 'filter_user_can_view_content' ], 999999, 3 );
55 add_action( 'content_control/restrict_main_query', [ $this, 'action_restrict_main_query' ], 999999 );
56 add_action( 'content_control/restrict_main_query_post', [ $this, 'action_restrict_main_query_post' ], 999999, 2 );
57 }
58
59 /**
60 * Tear down.
61 *
62 * @return void
63 */
64 public function tear_down() {
65 remove_filter( 'content_control/user_can_view_content', [ $this, 'filter_user_can_view_content' ], 999999 );
66 remove_action( 'content_control/restrict_main_query', [ $this, 'action_restrict_main_query' ], 999999 );
67 remove_action( 'content_control/restrict_main_query_post', [ $this, 'action_restrict_main_query_post' ], 999999 );
68 parent::tear_down();
69 }
70
71 /**
72 * Listen for user_can_view_content filter.
73 *
74 * @param bool $user_can_view Whether content is restricted.
75 * @param int|null $post_id Post ID.
76 * @param \ContentControl\Models\Restriction[] $restrictions Restrictions.
77 *
78 * @return bool
79 */
80 public function filter_user_can_view_content( $user_can_view, $post_id, $restrictions ) {
81 $key = isset( $post_id ) ? $post_id : 'main';
82
83 $this->data->user_can_view_content[ $key ] = [
84 'user_can_view' => $user_can_view,
85 'post_id' => $post_id,
86 'restrictions' => $restrictions,
87 'context' => \ContentControl\current_query_context(),
88 ];
89
90 return $user_can_view;
91 }
92
93 /**
94 * Listen for restrict_main_query action.
95 *
96 * @param \ContentControl\Models\Restriction $restriction Restriction.
97 *
98 * @return void
99 */
100 public function action_restrict_main_query( $restriction ) {
101 $this->data->main_query_restriction = $restriction;
102 }
103
104 /**
105 * Listen for restrict_main_query action.
106 *
107 * @param \ContentControl\Models\Restriction $restriction Restriction.
108 * @param int[] $post_ids Post IDs.
109 *
110 * @return void
111 */
112 public function action_restrict_main_query_post( $restriction, $post_ids ) {
113 $this->data->restrict_main_query_posts[] = [
114 'restriction' => $restriction,
115 'post_ids' => $post_ids,
116 ];
117 }
118
119 /**
120 * Data to expose on the Query Monitor debug bar.
121 *
122 * @return void
123 */
124 public function process() {
125 }
126 }
127