PluginProbe
Filter Everything — WordPress & WooCommerce Filters / 1.9.2.1
Filter Everything — WordPress & WooCommerce Filters v1.9.2.1
1.9.7 1.9.6 1.9.5 1.9.4 1.9.3 1.9.2.2 1.9.2.1 trunk 1.2.1 1.2.3 1.2.4 1.2.5 1.3.0 1.3.1 1.3.2 1.4.1 1.4.4 1.4.5 1.4.8 1.4.9 1.5.0 1.5.1 1.6.0 1.6.1 1.6.2 All 52 releases
filter-everything / src / Admin / AdminHooks.php

AdminHooks.php in Filter Everything — WordPress & WooCommerce Filters 1.9.2.1, at src/Admin/AdminHooks.php

334 lines 13.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 namespace FilterEverything\Filter;
5
6 if ( ! defined('ABSPATH') ) {
7 exit;
8 }
9
10 class AdminHooks
11 {
12
13 public function __construct()
14 {
15 add_filter( 'manage_edit-'.FLRT_FILTERS_SET_POST_TYPE.'_columns', array( $this, 'filterSetPostTypeCol' ) );
16 add_action( 'manage_'.FLRT_FILTERS_SET_POST_TYPE.'_posts_custom_column', array( $this, 'filterSetPostTypeColContent'), 10, 2 );
17
18 add_filter( 'manage_edit-'.FLRT_FILTERS_SET_POST_TYPE.'_columns', array( $this, 'filterSetWhereFilterCol' ), 1 );
19 add_action( 'manage_'.FLRT_FILTERS_SET_POST_TYPE.'_posts_custom_column', array( $this, 'filterSetWhereFilterColContent'), 10, 2 );
20
21 add_filter( 'manage_edit-'.FLRT_FILTERS_SET_POST_TYPE.'_sortable_columns', array( $this, 'filterSetSortableColumn') );
22 add_action( 'pre_get_posts', array( $this, 'filterSetOrderby' ) );
23
24 add_action('admin_notices', [$this, 'adminNotices'] );
25 add_action('admin_notices', [$this, 'checkForbiddenPrefixes'] );
26
27 add_filter( 'plugin_action_links_' . FLRT_PLUGIN_BASENAME, [$this,'actionsLink'] );
28
29 add_action( 'current_screen', [$this, 'currentScreen' ] );
30 add_action( 'wpc_admin_toolbar_right', [$this, 'aboutPro' ] );
31 }
32
33 public function aboutPro()
34 {
35 if ( ! defined('FLRT_FILTERS_PRO') ) {
36 echo '<a class="wpc-tab wpc-get-pro" href="'.admin_url( 'edit.php?post_type=filter-set&page=filters-settings&tab=aboutpro' ).'"><span>'.esc_html__( 'PRO benefits', 'filter-everything' ).'</span>' . flrt_diamond_icon() . "</a>\r\n";;
37 echo '<a class="wpc-tab wpc-get-pro wpc-get-pro-background button button-primary" href="'. esc_url(flrt_unlock_pro_link( 'hero_upgrade_btn' )).'" target="_blank">'.esc_html__( 'Upgrade to PRO', 'filter-everything' ).' '. flrt_crown_icon() .'</a>'."\r\n";
38 }
39 $this->addHelpTab();
40 }
41
42
43 public function addHelpTab() {
44 $screen = get_current_screen();
45
46 if( is_null( $screen ) ){
47 return false;
48 }
49
50 // Overview tab.
51 $screen->add_help_tab(
52 array(
53 'id' => 'overview',
54 'title' => esc_html__( 'Overview', 'filter-everything' ),
55 'content' =>
56 '<p><strong>' . esc_html__( 'Overview', 'filter-everything' ) . '</strong></p>' .
57 '<p>' . esc_html__( 'Filter Everything — WordPress & WooCommerce product filter plugin that allows you to design a flexible filtering system.', 'filter-everything' ) . '</p>'.
58 '<p>' . esc_html__( 'It is fast, convenient, intuitive, and contains unique SEO features (in the PRO version).', 'filter-everything' ) . '</p>'
59 )
60 );
61
62 // Help tab.
63 $screen->add_help_tab(
64 array(
65 'id' => 'help',
66 'title' => esc_html__( 'Help & Support', 'filter-everything' ),
67 'content' =>
68 '<p><strong>' . esc_html__( 'Help & Support', 'filter-everything' ) . '</strong></p>' .
69 '<ul>' .
70 '<li>' . wp_kses( sprintf(
71 __( '<a href="%s" target="_blank">Documentation</a>. Common information on how to work with the plugin can be found in our documentation.', 'filter-everything' ),
72 'https://filtereverything.pro/resources/'
73 ),
74 array(
75 'a' => array( 'href' => true, 'target' => true )
76 )
77 ). '</li>' .
78 '<li>' . wp_kses(
79 sprintf(
80 __( '<a href="%s" target="_blank">Support</a>. Create a technical support request if you are unable to resolve the issue yourself.', 'filter-everything' ),
81 'https://filtereverything.pro/support/'
82 ),
83 array(
84 'a' => array( 'href' => false, 'target' => true )
85 )
86 ). '</li>' .
87 '</ul>'
88 )
89 );
90
91 // Sidebar.
92 $screen->set_help_sidebar(
93 '<p><strong>' . esc_html__( 'Information', 'filter-everything' ) . '</strong></p>' .
94 '<p><span class="dashicons dashicons-admin-plugins"></span> ' . sprintf( esc_html__( 'Version %s', 'filter-everything' ), FLRT_PLUGIN_VER ) . '</p>' .
95 '<p><span class="dashicons dashicons-wordpress"></span> <a href="https://wordpress.org/plugins/filter-everything/" target="_blank">' . esc_html__( 'View details', 'filter-everything' ) . '</a></p>' .
96 '<p><span class="dashicons dashicons-admin-home"></span> <a href="https://filtereverything.pro/" target="_blank" target="_blank">' . esc_html__( 'Visit website', 'filter-everything' ) . '</a></p>' .
97 ''
98 );
99 }
100
101 public function currentScreen( $screen )
102 {
103 $screenList = [FLRT_FILTERS_SET_POST_TYPE];
104
105 if( defined( 'FLRT_SEO_RULES_POST_TYPE' ) ){
106 $screenList[] = FLRT_SEO_RULES_POST_TYPE;
107 }
108
109 if( isset( $screen->post_type ) && in_array( $screen->post_type, $screenList ) ){
110 add_action( 'in_admin_header', [ $this, 'inAdminHeader' ] );
111 }
112 }
113
114 public function inAdminHeader()
115 {
116 $templateManager = Container::instance()->getTemplateManager();
117 $templateManager->includeAdminView( 'header-navigation' );
118 }
119
120 public function actionsLink( $actions ) {
121 $actionsLink = array(
122 '<a href="' . admin_url( 'post-new.php?post_type=filter-set' ) . '">'.esc_html__('Add Filters', 'filter-everything').'</a>',
123 '<a href="' . admin_url( 'edit.php?post_type=filter-set&page=filters-settings' ) . '">'.esc_html__('Settings', 'filter-everything').'</a>'
124 );
125
126 $actions = array_merge( $actionsLink, $actions );
127
128 if( ! defined( 'FLRT_FILTERS_PRO' ) ){
129 $actions[] = '<a href="' . esc_url(FLRT_PLUGIN_URL .'/?get_pro=true') . '" class="wpc-go-pro" target="_blank">'.esc_html__('Get PRO', 'filter-everything').'</a>';
130 }
131
132 return $actions;
133 }
134
135 public function checkForbiddenPrefixes()
136 {
137 $forbiddenPrefixes = flrt_get_forbidden_prefixes();
138 $savedPrefixes = get_option( 'wpc_filter_permalinks', [] );
139
140 if ( ! is_array( $savedPrefixes ) ) {
141 $savedPrefixes = maybe_unserialize( $savedPrefixes );
142 }
143 if ( ! is_array( $savedPrefixes ) ) {
144 $savedPrefixes = []; // If still not an array, default to an empty array
145 }
146
147 $warningPrefixes = [];
148
149 foreach( $forbiddenPrefixes as $prefix ){
150 if( in_array( $prefix, $savedPrefixes ) ){
151 $warningPrefixes[] = $prefix;
152 }
153 }
154
155 $permalinkOptionsUrl = admin_url( 'edit.php?post_type=filter-set&page=filters-settings&tab=prefixes' );
156 $permalinksTab = new PermalinksTab();
157 $permalinksTabLabel = strtolower( $permalinksTab->getLabel() );
158
159 if( ! empty( $warningPrefixes ) ){
160
161 $message = wp_kses(
162 sprintf(
163 _n(
164 'Error: <strong>%s</strong> filter prefix is not allowed and must be changed on the Filter %s settings <a href="%s" target="_blank">page</a>. Otherwise this site will not work properly.',
165 'Error: following filter prefixes <strong>%s</strong> are not allowed and must be changed on the Filter %s settings <a href="%s" target="_blank">page</a>. Otherwise this site will not work properly.',
166 count($warningPrefixes),
167 'filter-everything'
168 ), implode( ', ', $warningPrefixes ), $permalinksTabLabel, $permalinkOptionsUrl
169 ),
170 array(
171 'strong' => array(),
172 'a' => array('href' => true, 'target' => true)
173 )
174 );
175
176 ?>
177 <div class="notice wpc-error is-dismissible">
178 <p><?php echo $message; // Already escaped ?></p>
179 </div>
180 <?php
181
182 }
183
184 }
185
186 public function adminNotices()
187 {
188 $get = Container::instance()->getTheGet();
189 /**
190 * string
191 */
192 if( ! isset( $get['message'] ) ){
193 return false;
194 }
195
196 $messageNum = sanitize_key($get['message']); // no need to escape
197 $errors = FilterFields::getErrorsList();
198
199 ?>
200 <?php foreach ( $errors as $id => $message ) : ?>
201 <?php if( isset( $errors[$messageNum] ) ): // no need to escape ?>
202 <div class="wpc-error is-dismissible">
203 <p><?php echo $errors[$messageNum]; ?></p>
204 <button type="button" class="notice-dismiss">
205 <span class="screen-reader-text"><?php esc_html_e('Dismiss this notice.'); ?></span>
206 </button>
207 </div>
208 <?php break; endif; ?>
209 <?php endforeach; ?>
210 <?php
211 }
212
213 public function filterSetOrderby( $query ) {
214 if( ! is_admin() )
215 return;
216
217 if( $query->get('post_type') !== FLRT_FILTERS_SET_POST_TYPE ){
218 return;
219 }
220
221 $orderby = $query->get( 'orderby' );
222
223 if( $orderby === 'menu_order title' ){
224 $query->set( 'orderby', 'date' );
225 $query->set( 'order', 'DESC' );
226 }
227
228 if( 'set_post_type' == $orderby ) {
229 $query->set( 'meta_key', 'wpc_filter_set_post_type' );
230 $query->set( 'orderby', 'meta_value' );
231 }
232
233 }
234
235 public function filterSetSortableColumn( $columns )
236 {
237 $columns['set_post_type'] = 'set_post_type';
238 return $columns;
239 }
240
241 public function filterSetPostTypeCol( $columns )
242 {
243 $newColumns = [];
244
245 foreach ( $columns as $columnId => $columnName ) {
246
247 if( $columnId === 'date' ){
248 continue;
249 }
250
251 $newColumns[$columnId] = $columnName;
252 if( $columnId === 'title' ){
253 $newColumns['set_post_type'] = esc_html__( 'Post type', 'filter-everything' );
254 }
255 }
256
257 return $newColumns;
258 }
259
260 public function filterSetWhereFilterCol( $columns )
261 {
262 $newColumns = [];
263
264 foreach ( $columns as $columnId => $columnName ) {
265
266 if( $columnId === 'date' ){
267 continue;
268 }
269
270 $newColumns[$columnId] = $columnName;
271 if( $columnId === 'title' ){
272 $newColumns['where_filter'] = "<div>" . esc_html__( 'Open', 'filter-everything' ) . flrt_open_in_new_tab_icon() . '</div>';
273 }
274 }
275
276 return $newColumns;
277 }
278
279 public function filterSetPostTypeColContent( $column_name, $post_id )
280 {
281 if( 'set_post_type' == $column_name ){
282 $fss = Container::instance()->getFilterSetService();
283 $theSet = $fss->getSet( $post_id );
284
285 $postTypeSelected = isset( $theSet['post_type']['value'] ) ? $theSet['post_type']['value'] : '';
286 $postTypes = isset( $theSet['post_type']['options'] ) ? $theSet['post_type']['options'] : '';
287 $postType = isset( $postTypes[ $postTypeSelected ] ) ? $postTypes[ $postTypeSelected ] : '';
288
289 echo esc_html( $postType );
290 }
291 }
292
293 public function filterSetWhereFilterColContent( $column_name, $post_id )
294 {
295 $fss = Container::instance()->getFilterSetService();
296 $theSet = $fss->getSet( $post_id );
297 $filterSet = Container::instance()->getFilterSetService();
298 $under_limit_filter_set = $filterSet->under_limit_filter_set($post_id);
299 $link = '';
300 $html = '';
301
302 if ('where_filter' == $column_name) {
303 $set_settings_fields = $fss->getSettingsLocationTypeFields($post_id);
304
305 foreach ($set_settings_fields as $key => $attributes) {
306 if ($attributes['id'] == $fss->generateFieldId('post_name')) {
307 $current_index = isset($attributes['value']) ? $attributes['value'] : '';
308 $options = !empty($attributes['options']) ? $attributes['options'] : [];
309 if (isset($options[$current_index]['data-link'])) {
310 $link = esc_attr($options[$current_index]['data-link']);
311 }
312 }
313 }
314
315 if ($under_limit_filter_set) {
316 $tip_text = wp_kses(
317 __('This Filter Set is inactive.<br>The Free version allows up to 3 Filter Sets per post type.<br>Upgrade to PRO to activate unlimited Filter Sets.', 'filter-everything'),
318 array('br' => array())
319 );
320 $html = '<div class="wpc-pro-filter-set-badge"><span class="wpc-alert-emoji wpc-icon-help-tip" data-tip="' . esc_attr($tip_text) . '">' . flrt_unlock_icon('20px', '20px', '#3858E9') . '</span><a class="wpc-pro-badge-text" href="' . esc_url(flrt_vailable_in_pro_attr_link()) . '">' . esc_html__('Unlock with PRO', 'filter-everything') . '</a></div>';
321 } else {
322 if (!empty($link)) {
323 $html = '<a class="wpc-location-preview" target="_blank" href="' . esc_url($link) . '"><span class="dashicons dashicons-visibility"></span></a>';
324 } else {
325 $html = '';
326 }
327 }
328
329 echo $html;
330 }
331 }
332 }
333
334 new AdminHooks();