PluginProbe
Filter Everything — WordPress & WooCommerce Filters / trunk
Filter Everything — WordPress & WooCommerce Filters vtrunk
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 1.6.3 All 51 releases
filter-everything / src / Admin / AdminHooks.php

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

338 lines 14.1 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 .'/pricing/?utm_source=free_plugin&utm_medium=internal&utm_campaign=free_plugin_upgrade&utm_content=plugin_actions_lnk') . '" 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 $limit = null;
198 if ($messageNum === '92' && !empty($get['post'])) {
199 $filterSet = Container::instance()->getFilterSetService();
200 $post_type_field = $filterSet->getPostTypeField((int) $get['post']);
201 $post_type = !empty($post_type_field['post_type']['value']) ? $post_type_field['post_type']['value'] : '';
202 $limit = $filterSet->getFreeLimitForPostType($post_type);
203 }
204 $errors = FilterFields::getErrorsList($limit);
205
206 ?>
207 <?php foreach ( $errors as $id => $message ) : ?>
208 <?php if( isset( $errors[$messageNum] ) ): // no need to escape ?>
209 <div class="wpc-error is-dismissible">
210 <p><?php echo $errors[$messageNum]; ?></p>
211 <button type="button" class="notice-dismiss">
212 <span class="screen-reader-text"><?php esc_html_e('Dismiss this notice.'); ?></span>
213 </button>
214 </div>
215 <?php break; endif; ?>
216 <?php endforeach; ?>
217 <?php
218 }
219
220 public function filterSetOrderby( $query ) {
221 if( ! is_admin() )
222 return;
223
224 if( $query->get('post_type') !== FLRT_FILTERS_SET_POST_TYPE ){
225 return;
226 }
227
228 $orderby = $query->get( 'orderby' );
229
230 if( $orderby === 'menu_order title' ){
231 $query->set( 'orderby', 'date' );
232 $query->set( 'order', 'DESC' );
233 }
234
235 if( 'set_post_type' == $orderby ) {
236 $query->set( 'meta_key', 'wpc_filter_set_post_type' );
237 $query->set( 'orderby', 'meta_value' );
238 }
239
240 }
241
242 public function filterSetSortableColumn( $columns )
243 {
244 $columns['set_post_type'] = 'set_post_type';
245 return $columns;
246 }
247
248 public function filterSetPostTypeCol( $columns )
249 {
250 $newColumns = [];
251
252 foreach ( $columns as $columnId => $columnName ) {
253
254 if( $columnId === 'date' ){
255 continue;
256 }
257
258 $newColumns[$columnId] = $columnName;
259 if( $columnId === 'title' ){
260 $newColumns['set_post_type'] = esc_html__( 'Post type', 'filter-everything' );
261 }
262 }
263
264 return $newColumns;
265 }
266
267 public function filterSetWhereFilterCol( $columns )
268 {
269 $newColumns = [];
270
271 foreach ( $columns as $columnId => $columnName ) {
272
273 if( $columnId === 'date' ){
274 continue;
275 }
276
277 $newColumns[$columnId] = $columnName;
278 if( $columnId === 'title' ){
279 $newColumns['where_filter'] = "<div>" . esc_html__( 'Open', 'filter-everything' ) . flrt_open_in_new_tab_icon() . '</div>';
280 }
281 }
282
283 return $newColumns;
284 }
285
286 public function filterSetPostTypeColContent( $column_name, $post_id )
287 {
288 if( 'set_post_type' == $column_name ){
289 $fss = Container::instance()->getFilterSetService();
290 $theSet = $fss->getSet( $post_id );
291
292 $postTypeSelected = isset( $theSet['post_type']['value'] ) ? $theSet['post_type']['value'] : '';
293 $postTypes = isset( $theSet['post_type']['options'] ) ? $theSet['post_type']['options'] : '';
294 $postType = isset( $postTypes[ $postTypeSelected ] ) ? $postTypes[ $postTypeSelected ] : '';
295
296 echo esc_html( $postType );
297 }
298 }
299
300 public function filterSetWhereFilterColContent( $column_name, $post_id )
301 {
302 $fss = Container::instance()->getFilterSetService();
303 $theSet = $fss->getSet( $post_id );
304 $filterSet = Container::instance()->getFilterSetService();
305 $under_limit_filter_set = $filterSet->under_limit_filter_set($post_id);
306 $link = '';
307 $html = '';
308
309 if ('where_filter' == $column_name) {
310 $link = flrt_filter_set_front_link($post_id);
311
312 if ($under_limit_filter_set) {
313 $post_type_field = $filterSet->getPostTypeField($post_id);
314 $post_type = !empty($post_type_field['post_type']['value']) ? $post_type_field['post_type']['value'] : '';
315 $limit = $filterSet->getFreeLimitForPostType($post_type);
316 $tip_text = wp_kses(
317 sprintf(
318 /* translators: %d: maximum number of free filter sets per post type */
319 __('This Filter Set is inactive.<br>The Free version allows up to %d Filter Sets per post type.<br>Upgrade to PRO to activate unlimited Filter Sets.', 'filter-everything'),
320 $limit
321 ),
322 array('br' => array())
323 );
324 $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>';
325 } else {
326 if (!empty($link)) {
327 $html = '<a class="wpc-location-preview" target="_blank" href="' . esc_url($link) . '"><span class="dashicons dashicons-visibility"></span></a>';
328 } else {
329 $html = '';
330 }
331 }
332
333 echo $html;
334 }
335 }
336 }
337
338 new AdminHooks();