PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 7.7.0
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v7.7.0
7.9.3 7.9.2 trunk 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.0.5 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.2.0 4.2.1 4.2.2 4.2.3 5.0.0 5.0.1 5.0.2 5.0.3 5.0.4 5.0.5 6.0.0 7.0.0 7.0.1 7.0.2 7.1.0 7.2.0 7.2.1 7.2.10 7.2.11 7.2.2 7.2.3 7.2.4 7.2.5 7.2.6 7.2.7 7.2.8 7.2.9 7.3.0 7.3.1 7.4.0 7.4.1 7.4.2 7.4.3 7.5.0 7.6.0 7.6.1 7.7.0 7.7.1 7.7.10 7.7.11 7.7.12 7.7.13 7.7.14 7.7.15 7.7.16 7.7.17 7.7.18 7.7.19 7.7.2 7.7.20 7.7.21 7.7.22 7.7.3 7.7.4 7.7.5 7.7.6 7.7.7 7.7.8 7.7.9 7.8.0 7.8.1 7.8.2 7.8.3 7.8.4 7.8.5 7.8.6 7.8.7 7.8.8 7.8.9 7.9.0 7.9.1
the-post-grid / app / Controllers / Hooks / FilterHooks.php
the-post-grid / app / Controllers / Hooks Last commit date
ActionHooks.php 2 years ago FilterHooks.php 2 years ago
FilterHooks.php
264 lines
1 <?php
2 /**
3 * Filter Hooks class.
4 *
5 * @package RT_TPG
6 */
7
8 namespace RT\ThePostGrid\Controllers\Hooks;
9
10 use Cassandra\Varint;
11 use RT\ThePostGrid\Helpers\Fns;
12
13 // Do not allow directly accessing this file.
14 if ( ! defined( 'ABSPATH' ) ) {
15 exit( 'This script cannot be accessed directly.' );
16 }
17
18 /**
19 * Filter Hooks class.
20 *
21 * @package RT_TPG
22 */
23 class FilterHooks {
24 /**
25 * Class init
26 *
27 * @return void
28 */
29 public static function init() {
30 add_filter( 'tpg_author_arg', [ __CLASS__, 'filter_author_args' ], 10 );
31 add_filter( 'plugin_row_meta', [ __CLASS__, 'plugin_row_meta' ], 10, 2 );
32
33 $settings = get_option( 'rt_the_post_grid_settings' );
34
35 if ( isset( $settings['show_acf_details'] ) && $settings['show_acf_details'] ) {
36 add_filter( 'the_content', [ __CLASS__, 'tpg_acf_content_filter' ] );
37 }
38
39 add_filter( 'wp_head', [ __CLASS__, 'set_post_view_count' ], 9999 );
40 add_filter( 'body_class', [ __CLASS__, 'body_classes' ] );
41 add_filter( 'admin_body_class', [ __CLASS__, 'admin_body_class' ] );
42 add_filter( 'wp_kses_allowed_html', [ __CLASS__, 'tpg_custom_wpkses_post_tags' ], 10, 2 );
43 add_filter( 'wp_kses_allowed_html', [ __CLASS__, 'custom_wpkses_post_tags' ], 10, 2 );
44 }
45
46 /**
47 * Add body classes
48 *
49 * @param $classes
50 *
51 * @return mixed
52 */
53 public static function body_classes( $classes ) {
54 global $post;
55
56 if ( isset( $post->post_content ) && has_shortcode( $post->post_content, 'tpg_my_account' ) ) {
57 $classes[] = 'tpg-myaccount-page';
58 }
59
60 $icon_font = Fns::tpg_option( 'tpg_icon_font' );
61 $classes[] = 'rttpg';
62 $classes[] = 'rttpg-' . RT_THE_POST_GRID_VERSION;
63 $classes[] = 'radius-frontend rttpg-body-wrap';
64 if ( 'fontawesome' !== $icon_font ) {
65 $classes[] = 'rttpg-flaticon';
66 }
67
68 return $classes;
69 }
70
71 /**
72 * Admin body class
73 *
74 * @param string $classes Classes.
75 *
76 * @return string
77 */
78 public static function admin_body_class( $classes ) {
79 $settings = get_option( 'rt_the_post_grid_settings' );
80 global $pagenow;
81
82 if ( isset( $settings['tpg_block_type'] ) && in_array(
83 $settings['tpg_block_type'],
84 [
85 'elementor',
86 'shortcode',
87 ]
88 ) ) {
89 $classes .= ' tpg-block-type-elementor-or-shortcode';
90 }
91
92 // Check if the current page is post.php and if the post parameteris set.
93 //phpcs:ignore WordPress.Security.NonceVerification.Recommended
94 if ( 'post.php' === $pagenow && isset( $_GET['post'] ) ) {
95
96 if ( rtTPG()->hasPro() ) {
97 $classes .= ' the-post-grid the-post-grid-pro';
98 } else {
99 $classes .= ' the-post-grid';
100 }
101
102 $classes .= ' radius-editor rttpg-body-wrap';
103 }
104
105 return $classes;
106 }
107
108 /**
109 * @param $tags
110 * @param $context
111 *
112 * @return mixed
113 */
114 public static function tpg_custom_wpkses_post_tags( $tags, $context ) {
115
116 if ( 'post' === $context ) {
117 $tags['iframe'] = [
118 'src' => true,
119 'height' => true,
120 'width' => true,
121 'frameborder' => true,
122 'allowfullscreen' => true,
123 ];
124 $tags['input'] = [
125 'type' => true,
126 'class' => true,
127 'placeholder' => true,
128 ];
129 $tags['style'] = [
130 'src' => true,
131 ];
132 }
133
134 return $tags;
135 }
136
137 /**
138 * Set view count
139 *
140 * @param string $content Content.
141 *
142 * @return string
143 */
144 public static function set_post_view_count( $content ) {
145 if ( is_single() ) {
146 $pId = get_the_ID();
147 Fns::update_post_views_count( $pId );
148 }
149
150 return $content;
151 }
152
153 /**
154 * Filter author args.
155 *
156 * @param array $args Args.
157 *
158 * @return array
159 */
160 public static function filter_author_args( $args ) {
161 $defaults = [ 'role__in' => [ 'administrator', 'editor', 'author' ] ];
162
163 return wp_parse_args( $args, $defaults );
164 }
165
166 /**
167 * Add plugin row meta
168 *
169 * @param array $links Links.
170 * @param string $file File.
171 *
172 * @return array
173 */
174 public static function plugin_row_meta( $links, $file ) {
175 if ( $file == RT_THE_POST_GRID_PLUGIN_ACTIVE_FILE_NAME ) {
176 $report_url = 'https://www.radiustheme.com/contact/';
177 $row_meta['issues'] = sprintf(
178 '%2$s <a target="_blank" href="%1$s">%3$s</a>',
179 esc_url( $report_url ),
180 esc_html__( 'Facing issue?', 'the-post-grid' ),
181 '<span style="color: red">' . esc_html__( 'Please open a support ticket.', 'the-post-grid' ) . '</span>'
182 );
183
184 return array_merge( $links, $row_meta );
185 }
186
187 return (array) $links;
188 }
189
190 /**
191 * ACF content filter
192 *
193 * @param string $content Content.
194 *
195 * @return string
196 */
197 public static function tpg_acf_content_filter( $content ) {
198 // Check if we're inside the main loop in a post or page.
199 if ( is_single() && in_the_loop() && is_main_query() && rtTPG()->hasPro() ) {
200 $settings = get_option( rtTPG()->options['settings'] );
201
202 $data = [
203 'show_acf' => isset( $settings['show_acf_details'] ) && $settings['show_acf_details'] ? 'show' : false,
204 'cf_group' => isset( $settings['cf_group_details'] ) ? $settings['cf_group_details'] : [],
205 'cf_hide_empty_value' => isset( $settings['cf_hide_empty_value_details'] ) ? $settings['cf_hide_empty_value_details'] : false,
206 'cf_show_only_value' => isset( $settings['cf_show_only_value_details'] ) ? $settings['cf_show_only_value_details'] : false,
207 'cf_hide_group_title' => isset( $settings['cf_hide_group_title_details'] ) ? $settings['cf_hide_group_title_details'] : false,
208 ];
209
210 return $content . Fns::tpg_get_acf_data_elementor( $data, null, false );
211 }
212
213 return $content;
214 }
215
216 /**
217 * Add exceptions in wp_kses_post tags.
218 *
219 * @param array $tags Allowed tags, attributes, and/or entities.
220 * @param string $context Context to judge allowed tags by. Allowed values are 'post'.
221 *
222 * @return array
223 */
224 public static function custom_wpkses_post_tags( $tags, $context ) {
225 if ( 'post' === $context ) {
226 $tags['iframe'] = [
227 'src' => true,
228 'height' => true,
229 'width' => true,
230 'frameborder' => true,
231 'allowfullscreen' => true,
232 ];
233
234 $tags['svg'] = [
235 'class' => true,
236 'aria-hidden' => true,
237 'aria-labelledby' => true,
238 'role' => true,
239 'xmlns' => true,
240 'width' => true,
241 'height' => true,
242 'viewbox' => true,
243 'stroke' => true,
244 'fill' => true,
245 ];
246
247 $tags['g'] = [ 'fill' => true ];
248 $tags['title'] = [ 'title' => true ];
249 $tags['path'] = [
250 'd' => true,
251 'fill' => true,
252 'stroke-width' => true,
253 'stroke-linecap' => true,
254 'stroke-linejoin' => true,
255 'fill-rule' => true,
256 'clip-rule' => true,
257 'stroke' => true,
258 ];
259 }
260
261 return $tags;
262 }
263 }
264