PluginProbe
Filter Everything — WordPress & WooCommerce Filters / 1.9.7
Filter Everything — WordPress & WooCommerce Filters v1.9.7
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 / Admin.php

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

211 lines 7.5 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 Admin
11 {
12 public $tabRenderer;
13
14 public function __construct()
15 {
16 add_action( 'admin_menu', array($this, 'adminMenu'), 9);
17 $this->tabRenderer = Container::instance()->getTabRenderer();
18 $filterSet = Container::instance()->getFilterSetService();
19
20 add_action( 'pre_post_update', [$filterSet, 'preSaveSet'], 10, 2 );
21 add_action( 'save_post', array( $filterSet, 'saveSet' ), 10, 2 );
22
23 add_action( 'init', array( $this, 'initTabs' ), 11 );
24
25 add_action( 'admin_init', array( $this, 'init' ) );
26
27 add_filter( 'wpc_general_filters_settings', [$this, 'generalFilterSettings'] );
28
29 add_action('admin_head', array($this, 'addAdminStyles'));
30
31 }
32
33 public function init()
34 {
35 $filterFields = Container::instance()->getFilterFieldsService();
36 $filterFields->registerHooks();
37
38 // Check permissions before to show these screens
39 add_action( 'load-post.php', [ $this, 'checkPermissions' ] );
40 add_action( 'load-edit.php', [ $this, 'checkPermissions' ] );
41 add_action( 'load-post-new.php', [ $this, 'checkPermissions' ] );
42
43 }
44
45 public function adminMenu()
46 {
47 global $submenu;
48 $page = 'edit.php?post_type=' . FLRT_FILTERS_SET_POST_TYPE;
49
50 add_menu_page( esc_html__('Filters', 'filter-everything'), esc_html__('Filters', 'filter-everything'), 'manage_options', $page, false, 'none', '85');
51
52 add_submenu_page( $page, esc_html__('Filter Sets', 'filter-everything'), esc_html__('Filter Sets', 'filter-everything'), 'manage_options', $page);
53 add_submenu_page( $page, esc_html__('Add New', 'filter-everything'), esc_html__('Add New', 'filter-everything'), 'manage_options', 'post-new.php?post_type=' . FLRT_FILTERS_SET_POST_TYPE);
54
55 if (!defined('FLRT_FILTERS_PRO')) {
56 $settings = flrt_vailable_in_pro_attr_link();
57
58 // Two PRO-only destinations in the menu, each with the PRO badge. They
59 // were dropped in 1.9.6 to keep the menu short and are back since 1.9.7:
60 // the owner saw fewer free → PRO visits without them — two PRO-badged
61 // entries in the menu and the toolbar are a visible reminder of what
62 // PRO adds.
63 add_submenu_page($page, esc_html__('SEO Rules', 'filter-everything'), esc_html__('SEO Rules', 'filter-everything'), 'manage_options', $settings);
64 add_submenu_page($page, esc_html__('Import/Export', 'filter-everything'), esc_html__('Import/Export', 'filter-everything'), 'manage_options', $settings);
65
66 if (isset($submenu[$page])) {
67 foreach ($submenu[$page] as $key => $details) {
68 if ($details[2] === $settings) {
69 $submenu[$page][$key][0] .= flrt_pro_promo_label(true);
70 }
71 }
72 }
73 }
74
75 do_action('wpc_add_submenu_pages');
76
77 add_submenu_page( $page, esc_html__('Settings', 'filter-everything'), esc_html__('Settings', 'filter-everything'), 'manage_options', 'filters-settings', array($this, 'filterSettingsPage'));
78
79 // «What's new» is a Settings tab since 1.9.7 (WhatsNew), not a menu entry
80 do_action('wpc_after_add_submenu_pages');
81
82 }
83
84 public function filterSettingsPage()
85 {
86 $this->tabRenderer->render();
87 }
88
89 public function initTabs()
90 {
91 $this->tabRenderer->register(new SettingsTab());
92 $this->tabRenderer->register(new PermalinksTab());
93
94 do_action( 'wpc_setttings_tabs_register', $this->tabRenderer );
95
96 $this->tabRenderer->register(new ExperimentalTab());
97
98 if( ! defined('FLRT_FILTERS_PRO') ) {
99 // Free: What's new goes BEFORE «PRO benefits», so the tab that sells
100 // stays last and most visible (owner, 2026-09-22)
101 do_action( 'wpc_settings_tabs_registered', $this->tabRenderer );
102 $this->tabRenderer->register( new AboutProTab() );
103
104 }else{
105 $show_license_tab = false;
106
107 if ( is_multisite() ) {
108 if ( is_main_site() ) {
109 $show_license_tab = true;
110 }
111 } else {
112 $show_license_tab = true;
113 }
114
115 if ( $show_license_tab ) {
116 $this->tabRenderer->register(new LicenseTab( FLRT_LICENSE_KEY ));
117 }
118 }
119
120 // PRO: What's new is the last tab, after License
121 if ( defined('FLRT_FILTERS_PRO') ) {
122 do_action( 'wpc_settings_tabs_registered', $this->tabRenderer );
123 }
124
125 $this->tabRenderer->init();
126 }
127
128 public function addAdminStyles()
129 {
130 if(defined('FLRT_FILTERS_PRO') && FLRT_FILTERS_PRO) {
131 return;
132 }
133
134 if (!is_admin()) {
135 return;
136 }
137 ?>
138 <style type="text/css">
139 .wpc-pro-badge {
140 background: #3858E9;
141 color: #fff;
142 padding: 2px 6px;
143 border-radius: 14px;
144 margin-left: 6px;
145 font-size: 10px;
146 border: 1px solid #3858E9;
147 position: absolute;
148 }
149 </style>
150 <?php
151 }
152
153 public function checkPermissions()
154 {
155 $screen = get_current_screen();
156 $post_types = [ FLRT_FILTERS_SET_POST_TYPE, FLRT_FILTERS_POST_TYPE ];
157
158 if( defined('FLRT_FILTERS_PRO') && FLRT_FILTERS_PRO ){
159 $post_types[] = FLRT_SEO_RULES_POST_TYPE;
160 }
161
162 if( ! is_null( $screen ) && property_exists( $screen, 'post_type' ) && in_array( $screen->post_type, $post_types, true ) ){
163 if( ! current_user_can( flrt_plugin_user_caps() ) ) {
164 wp_die( esc_html__( 'Sorry, you are not allowed to access this page.' ) );
165 }
166 }
167 }
168
169 public function generalFilterSettings( $settings )
170 {
171 $result_terms = [];
172
173 // Chips hooks
174 $maybe_saved_terms = flrt_get_option('show_terms_in_content', []);
175 $theme_dependencies = flrt_get_theme_dependencies();
176
177 $current_terms = $settings['common_settings']['fields']['show_terms_in_content']['options'];
178
179 if( flrt_is_woocommerce() ){
180 $woocommerce_terms = array(
181 'woocommerce_archive_description' => esc_html__('WooCommerce archive description', 'filter-everything' ),
182 'woocommerce_no_products_found' => esc_html__('WooCommerce no products found', 'filter-everything' ),
183 'woocommerce_before_shop_loop' => esc_html__('WooCommerce before Shop loop', 'filter-everything' ),
184 'woocommerce_before_main_content' => esc_html__('WooCommerce before main content', 'filter-everything' )
185 );
186
187 $result_terms = array_merge( $current_terms, $woocommerce_terms );
188 }
189
190 if( $maybe_saved_terms && is_array( $maybe_saved_terms )){
191 foreach ($maybe_saved_terms as $hook ){
192 if( ! in_array( $hook, array_keys( $result_terms ) ) ){
193 $result_terms[$hook] = $hook;
194 }
195 }
196 }
197
198 if( isset( $theme_dependencies['chips_hook'] ) && ! empty( $theme_dependencies['chips_hook'] )){
199 foreach ($theme_dependencies['chips_hook'] as $hook ){
200 if( ! in_array( $hook, array_keys( $result_terms ) ) ){
201 $result_terms[$hook] = $hook;
202 }
203 }
204 }
205
206 $settings['common_settings']['fields']['show_terms_in_content']['options'] = $result_terms;
207
208 return $settings;
209 }
210
211 }