PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.40.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.40.0
3.54.0 3.53.0 3.52.0 3.51.0 3.50.0 3.45.0 3.38.0 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.40.0 3.40.1 3.41.0 3.42.0 3.43.0 3.44.0 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 All 178 releases
simple-tags / inc / terms.php

terms.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 3.40.0, at inc/terms.php

356 lines 12.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class SimpleTags_Terms
4 {
5
6 const MENU_SLUG = 'st_options';
7
8 // class instance
9 static $instance;
10
11 // WP_List_Table object
12 public $terms_table;
13
14 /**
15 * Constructor
16 *
17 * @return void
18 * @author Olatechpro
19 */
20 public function __construct()
21 {
22
23 global $hook_suffix; //avoid warning outputs
24 if (!isset($hook_suffix)) {
25 $hook_suffix = '';
26 }
27
28 add_filter('set-screen-option', [__CLASS__, 'set_screen'], 10, 3);
29 // Admin menu
30 add_action('admin_menu', [$this, 'admin_menu']);
31 // Javascript
32 add_action('admin_enqueue_scripts', [__CLASS__, 'admin_enqueue_scripts'], 11);
33 //support post type for terms query
34 add_filter('terms_clauses', [__CLASS__, 'taxopress_terms_clauses'], 10, 3);
35 //inline term edit
36 add_action('wp_ajax_taxopress_terms_inline_save_term', [$this, 'taxopress_terms_inline_save_term_callback']);
37 }
38
39 // Handle the post_type parameter given in get_terms function
40 public static function taxopress_terms_clauses($clauses, $taxonomy, $args)
41 {
42 if (isset($_REQUEST['page']) && $_REQUEST['page'] === 'st_terms' && !empty($args['post_types']) && is_array($args['post_types'])) {
43 global $wpdb;
44
45 $post_types = array();
46
47 foreach ($args['post_types'] as $cpt) {
48 $post_types[] = "'" . $cpt . "'";
49 }
50
51 if (!empty($post_types)) {
52 $clauses['fields'] = 'DISTINCT ' . str_replace('tt.*', 'tt.term_taxonomy_id, tt.term_id, tt.taxonomy, tt.description, tt.parent', $clauses['fields']) . ', COUNT(t.term_id) AS count';
53 $clauses['join'] .= ' INNER JOIN ' . $wpdb->term_relationships . ' AS r ON r.term_taxonomy_id = tt.term_taxonomy_id INNER JOIN ' . $wpdb->posts . ' AS p ON p.ID = r.object_id';
54 $clauses['where'] .= ' AND p.post_type IN (' . implode(',', $post_types) . ')';
55 $clauses['orderby'] = 'GROUP BY t.term_id ' . $clauses['orderby'];
56 }
57 }
58 return $clauses;
59 }
60
61 /**
62 * Init somes JS and CSS need for this feature
63 *
64 * @return void
65 * @author Olatechpro
66 */
67 public static function admin_enqueue_scripts()
68 {
69
70 // add JS for manage click tags
71 if (isset($_GET['page']) && $_GET['page'] == 'st_terms') {
72 wp_enqueue_style('st-taxonomies-css');
73 wp_enqueue_script('admin-tags');
74 wp_enqueue_script('inline-edit-tax');
75 }
76 }
77
78
79 public function taxopress_terms_inline_save_term_callback()
80 {
81 global $wpdb;
82
83 check_ajax_referer('taxinlineeditnonce', '_inline_edit');
84
85 $edit_taxonomy = sanitize_key($_POST['edit_taxonomy']);
86 $taxonomy = sanitize_key($_POST['original_tax']);
87 $tax = get_taxonomy($taxonomy);
88 $edit_tax = get_taxonomy($edit_taxonomy);
89
90 if (!$tax || !$edit_tax) {
91 wp_die(0);
92 }
93
94 if (!isset($_POST['tax_ID']) || !(int) $_POST['tax_ID']) {
95 wp_die(-1);
96 }
97
98 $id = (int) $_POST['tax_ID'];
99
100 if (!current_user_can('edit_term', $id)) {
101 wp_die(-1);
102 }
103
104 $tag = get_term($id, $taxonomy);
105 $_POST['description'] = $tag->description;
106
107 $updated = wp_update_term($id, $taxonomy, $_POST);
108
109 if ($updated && !is_wp_error($updated)) {
110 $tag = get_term($updated['term_id'], $taxonomy);
111 if (!$tag || is_wp_error($tag)) {
112 if (is_wp_error($tag) && $tag->get_error_message()) {
113 wp_die(esc_html($tag->get_error_message()));
114 }
115 wp_die(esc_html__('Item not updated.'));
116 } else {
117 if ($tax !== $edit_tax) {
118 $update_term = $wpdb->update(
119 $wpdb->prefix . 'term_taxonomy',
120 ['taxonomy' => $edit_taxonomy],
121 ['term_taxonomy_id' => $tag->term_taxonomy_id],
122 ['%s'],
123 ['%d']
124 );
125 if ($update_term) {
126 clean_term_cache($tag->term_id);
127 $tag = get_term($tag->term_id, $edit_taxonomy);
128 }
129 }
130 }
131 } else {
132 /*if ( is_wp_error( $updated ) && $updated->get_error_message() ) {
133 wp_die( esc_html($updated->get_error_message()) );
134 }*/
135 wp_die(esc_html__('Error updating term.'));
136 }
137
138 $wp_list_table = new Taxopress_Terms_List();
139
140 $wp_list_table->single_row($tag);
141 wp_die();
142 }
143
144
145 public static function set_screen($status, $option, $value)
146 {
147 return $value;
148 }
149
150 /** Singleton instance */
151 public static function get_instance()
152 {
153 if (!isset(self::$instance)) {
154 self::$instance = new self();
155 }
156
157 return self::$instance;
158 }
159
160 /**
161 * Add WP admin menu for Tags
162 *
163 * @return void
164 * @author Olatechpro
165 */
166 public function admin_menu()
167 {
168 $hook = add_submenu_page(
169 self::MENU_SLUG,
170 esc_html__('Terms', 'simple-tags'),
171 esc_html__('Terms', 'simple-tags'),
172 'simple_tags',
173 'st_terms',
174 [
175 $this,
176 'page_manage_terms',
177 ]
178 );
179
180 if (taxopress_is_screen_main_page() && (!isset($_GET['action']) || $_GET['action'] !== 'new_item')) {
181 add_action("load-$hook", [$this, 'screen_option']);
182 }
183 }
184
185 /**
186 * Screen options
187 */
188 public function screen_option()
189 {
190
191
192 $option = 'per_page';
193 $args = [
194 'label' => esc_html__('Number of items per page', 'simple-tags'),
195 'default' => 20,
196 'option' => 'st_terms_per_page'
197 ];
198
199 add_screen_option($option, $args);
200
201
202 $this->terms_table = new Taxopress_Terms_List();
203 }
204
205 /**
206 * Method for build the page HTML manage tags
207 *
208 * @return void
209 * @author Olatechpro
210 */
211 public function page_manage_terms()
212 {
213 // Default order
214 if (!isset($_GET['order'])) {
215 $_GET['order'] = 'name-asc';
216 }
217
218 settings_errors(__CLASS__);
219
220 ?>
221 <div class="wrap st_wrap st-manage-taxonomies-page manage-taxopress-terms">
222
223 <div id="">
224
225 <?php
226 if (isset($_GET['action']) && $_GET['action'] === 'new_item') {
227 ?>
228 <div class="taxopress-term-wrap">
229 <div class="taxopress-term-main">
230 <h1 class="wp-heading-inline"><?php esc_html_e('Terms', 'simple-tags'); ?></h1>
231 <div class="taxopress-description">
232 <?php esc_html_e('This screen allows you to search and edit all the terms on your site.', 'simple-tags'); ?>
233 </div>
234 <?php
235 do_action('taxopress_terms_copy_with_metadata_promo');
236 ?>
237 </div>
238 <div class="taxopress-right-sidebar">
239 <?php do_action('taxopress_admin_after_sidebar'); ?>
240 </div>
241 </div>
242 <?php
243 } else {
244 ?>
245 <?php
246
247 $taxonomy_heading = '';
248 $show_order_message = false;
249 if (!empty($_REQUEST['taxopress_terms_taxonomy'])) {
250 $taxonomy_obj = get_taxonomy(sanitize_text_field($_REQUEST['taxopress_terms_taxonomy']));
251 if ($taxonomy_obj) {
252 $taxonomy_heading = $taxonomy_obj->labels->name;
253 $show_order_message = true;
254 }
255 }
256 ?>
257 <h1 class="wp-heading-inline">
258 <?php
259 if ($taxonomy_heading) {
260 echo esc_html($taxonomy_heading);
261 } else {
262 esc_html_e('Terms', 'simple-tags');
263 }
264 ?>
265 </h1>
266 <div class="taxopress-description">
267 <?php
268 if ($show_order_message) {
269 esc_html_e('This screen allows you to order terms via drag and drop.', 'simple-tags');
270 } else {
271 esc_html_e('This screen allows you to search and edit all the terms on your site.', 'simple-tags');
272 }
273 ?>
274 </div>
275
276 <?php
277 if (isset($_REQUEST['s']) && $search = esc_attr(sanitize_text_field(wp_unslash($_REQUEST['s'])))) {
278 /* translators: %s: search keywords */
279 printf(' <span class="subtitle">' . esc_html__(
280 'Search results for &#8220;%s&#8221;',
281 'simple-tags'
282 ) . '</span>', esc_html($search));
283 }
284 ?>
285 <?php
286
287 //the terms table instance
288 $this->terms_table->prepare_items();
289 ?>
290
291
292 <hr class="wp-header-end">
293 <div id="ajax-response"></div>
294 <form class="search-form wp-clearfix st-taxonomies-search-form" method="get">
295 <?php
296 // Hide search box if taxopress_show_all=1
297 $this->terms_table->search_box(esc_html__('Search Terms', 'simple-tags'), 'term');
298
299 ?>
300 </form>
301 <div class="clear"></div>
302
303 <div id="col-container" class="wp-clearfix">
304
305 <div class="col-wrap">
306 <form action="<?php echo esc_url(add_query_arg('', '')); ?>" method="post">
307 <?php
308 // Hide pagination if taxopress_show_all=1
309 // if (!empty($_REQUEST['taxopress_show_all']) && $_REQUEST['taxopress_show_all'] == '1') {
310 // // Remove pagination controls via CSS
311 // echo '<style>
312 // .tablenav.top, .tablenav.bottom { display: none !important; }
313 // </style>';
314 // }
315 $this->terms_table->display(); //Display the table
316 ?>
317 </form>
318 <div class="form-wrap edit-term-notes">
319 <p><?php esc_html__('Description here.', 'simple-tags') ?></p>
320 </div>
321 </div>
322
323
324 </div>
325
326
327 </div>
328 <?php $this->terms_table->inline_edit(); ?>
329
330 <script>
331 (function($) {
332 'use strict';
333
334 $(document).ready(function() {
335 // -------------------------------------------------------------
336 // TaxoPress terms quick edit
337 // -------------------------------------------------------------
338 $(document).on('click', 'a.editinline, button.editinline', function(e) {
339 var term_id = $(this).attr('data-term-id');
340 var taxonomy = $(this).attr('data-taxonomy');
341 $('.inline-edit-row#edit-' + term_id).find('select[name="edit_taxonomy"]').val(taxonomy);
342 });
343 });
344
345 })(jQuery);
346 </script>
347 <?php SimpleTags_Admin::printAdminFooter(); ?>
348 </div>
349 <?php
350 }
351 ?>
352 <?php
353 }
354
355 }
356