PluginProbe ʕ •ᴥ•ʔ
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid / 5.0.3
The Post Grid – Shortcode, Gutenberg Blocks and Elementor Addon for Post Grid v5.0.3
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 3 years ago FilterHooks.php 3 years ago
FilterHooks.php
179 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( 'admin_body_class', [ __CLASS__, 'admin_body_class' ] );
41 add_filter( 'wp_kses_allowed_html', [ __CLASS__, 'tpg_custom_wpkses_post_tags' ], 10, 2 );
42 }
43
44 public static function tpg_custom_wpkses_post_tags( $tags, $context ) {
45
46 if ( 'post' === $context ) {
47 $tags['iframe'] = [
48 'src' => true,
49 'height' => true,
50 'width' => true,
51 'frameborder' => true,
52 'allowfullscreen' => true,
53 ];
54 $tags['input'] = [
55 'type' => true,
56 'class' => true,
57 'placeholder' => true,
58 ];
59 $tags['style'] = [
60 'src' => true,
61 ];
62 }
63
64 return $tags;
65 }
66
67 /**
68 * Admin body class
69 *
70 * @param string $classes Classes.
71 *
72 * @return string
73 */
74
75 public static function admin_body_class( $classes ) {
76 $settings = get_option( 'rt_the_post_grid_settings' );
77 global $pagenow;
78
79 if ( isset( $settings['tpg_block_type'] ) && in_array( $settings['tpg_block_type'], [
80 'elementor',
81 'shortcode'
82 ] ) ) {
83 $classes .= ' tpg-block-type-elementor-or-shortcode';
84 }
85
86 //check if the current page is post.php and if the post parameteris set
87 if ( $pagenow === 'post.php' && isset( $_GET['post'] ) ) {
88
89 if ( rtTPG()->hasPro() ) {
90 $classes .= ' the-post-grid the-post-grid-pro';
91 } else {
92 $classes .= ' the-post-grid';
93 }
94 }
95
96 return $classes;
97 }
98
99 /**
100 * Set view count
101 *
102 * @param string $content Content.
103 *
104 * @return string
105 */
106 public static function set_post_view_count( $content ) {
107 if ( is_single() ) {
108 $pId = get_the_ID();
109 Fns::update_post_views_count( $pId );
110 }
111
112 return $content;
113 }
114
115 /**
116 * Filter author args.
117 *
118 * @param array $args Args.
119 *
120 * @return array
121 */
122 public static function filter_author_args( $args ) {
123 $defaults = [ 'role__in' => [ 'administrator', 'editor', 'author' ] ];
124
125 return wp_parse_args( $args, $defaults );
126 }
127
128 /**
129 * Add plugin row meta
130 *
131 * @param array $links Links.
132 * @param string $file File.
133 *
134 * @return array
135 */
136 public static function plugin_row_meta( $links, $file ) {
137 if ( $file == RT_THE_POST_GRID_PLUGIN_ACTIVE_FILE_NAME ) {
138 $report_url = 'https://www.radiustheme.com/contact/';
139 $row_meta['issues'] = sprintf(
140 '%2$s <a target="_blank" href="%1$s">%3$s</a>',
141 esc_url( $report_url ),
142 esc_html__( 'Facing issue?', 'the-post-grid' ),
143 '<span style="color: red">' . esc_html__( 'Please open a support ticket.', 'the-post-grid' ) . '</span>'
144 );
145
146 return array_merge( $links, $row_meta );
147 }
148
149 return (array) $links;
150 }
151
152 /**
153 * ACF content filter
154 *
155 * @param string $content Content.
156 *
157 * @return string
158 */
159 public static function tpg_acf_content_filter( $content ) {
160 // Check if we're inside the main loop in a post or page.
161 if ( is_single() && in_the_loop() && is_main_query() && rtTPG()->hasPro() ) {
162 $settings = get_option( rtTPG()->options['settings'] );
163
164 $data = [
165 'show_acf' => isset( $settings['show_acf_details'] ) && $settings['show_acf_details'] ? 'show' : false,
166 'cf_group' => isset( $settings['cf_group_details'] ) ? $settings['cf_group_details'] : [],
167 'cf_hide_empty_value' => isset( $settings['cf_hide_empty_value_details'] ) ? $settings['cf_hide_empty_value_details'] : false,
168 'cf_show_only_value' => isset( $settings['cf_show_only_value_details'] ) ? $settings['cf_show_only_value_details'] : false,
169 'cf_hide_group_title' => isset( $settings['cf_hide_group_title_details'] ) ? $settings['cf_hide_group_title_details'] : false,
170 ];
171
172 return $content . Fns::tpg_get_acf_data_elementor( $data, null, false );
173 }
174
175 return $content;
176 }
177
178 }
179