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

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

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