PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.38.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.38.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 / class.admin.mass.php

class.admin.mass.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 3.38.0, at inc/class.admin.mass.php

404 lines 13.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class SimpleTags_Admin_Mass {
4
5 const MENU_SLUG = 'st_options';
6
7 /**
8 * SimpleTags_Admin_Mass constructor.
9 */
10 public function __construct() {
11 // Ajax action, JS Helper and admin action
12 add_action( 'admin_init', array( __CLASS__, 'admin_init' ) );
13
14 // Admin menu
15 add_action( 'admin_menu', array( __CLASS__, 'admin_menu' ) );
16
17 // Register taxo, parent method...
18 SimpleTags_Admin::register_taxonomy();
19 }
20
21 /**
22 * Add WP admin menu for Tags
23 *
24 * @return void
25 * @author WebFactory Ltd
26 */
27 public static function admin_menu() {
28 add_submenu_page(
29 self::MENU_SLUG,
30 esc_html__( 'Mass Edit Terms', 'simple-tags' ),
31 esc_html__( 'Mass Edit Terms', 'simple-tags' ),
32 'simple_tags',
33 'st_mass_terms',
34 array(
35 __CLASS__,
36 'pageMassEditTags',
37 )
38 );
39 }
40
41 /**
42 * Control POST data for mass edit tags
43 *
44 */
45 public static function admin_init() {
46 if ( ! current_user_can( 'simple_tags' ) ) {
47 return false;
48 }
49
50 // Get GET data
51 if ( isset( $_GET['post_type'] ) ) {
52 $type = stripslashes( sanitize_text_field($_GET['post_type']) );
53 }
54
55 if ( isset( $_POST['update_mass'] ) ) {
56 // origination and intention
57 if ( ! ( wp_verify_nonce( sanitize_text_field($_POST['secure_mass']), 'st_mass_terms' ) ) ) {
58 add_settings_error( __CLASS__, __CLASS__, esc_html__( 'Security problem. Try again.', 'simple-tags' ), 'error taxopress-notice' );
59
60 return false;
61 }
62
63 if ( isset( $_POST['tags'] ) ) {
64 $counter = 0;
65 foreach ( (array) array_map('sanitize_text_field', $_POST['tags']) as $object_id => $tag_list ) {
66 // Trim data
67 $tag_list = trim( stripslashes( $tag_list ) );
68
69 // String to array
70 $tags = explode( ',', $tag_list );
71
72 // Remove empty and trim tag
73 $tags = array_filter( $tags, '_delete_empty_element' );
74
75 // Add new tag (no append ! replace !)
76 wp_set_object_terms( $object_id, $tags, SimpleTags_Admin::$taxonomy );
77 $counter ++;
78
79 // Clean cache
80 clean_post_cache( $object_id );
81 }
82
83 add_settings_error( __CLASS__, __CLASS__, sprintf( esc_html__( '%1$s %2$s(s) terms updated with success !', 'simple-tags' ), (int) $counter, strtolower( SimpleTags_Admin::$post_type_name ) ), 'updated taxopress-notice' );
84
85 return true;
86 }
87 }
88
89 return false;
90 }
91
92 /**
93 * WP Page - Mass edit tags
94 *
95 */
96 public static function pageMassEditTags() {
97 global $wpdb, $wp_locale, $wp_query;
98 list( $post_stati, $avail_post_stati ) = self::edit_data_query();
99
100 if ( ! isset( $_GET['paged'] ) ) {
101 $_GET['paged'] = 1;
102 }
103
104 // Display message
105 settings_errors( __CLASS__ );
106 ?>
107 <div class="taxopress-block-wrap">
108 <div class="wrap st_wrap tagcloudui st_mass_terms-page admin-settings">
109 <form id="posts-filter" action="" method="get">
110 <input type="hidden" name="page" value="st_mass_terms"/>
111 <input type="hidden" name="taxo" value="<?php echo esc_attr( SimpleTags_Admin::$taxonomy ); ?>"/>
112 <input type="hidden" name="cpt" value="<?php echo esc_attr( SimpleTags_Admin::$post_type ); ?>"/>
113
114 <h1><?php _e( 'Mass edit terms', 'simple-tags' ); ?></h1>
115 <br>
116 <div class="taxopress-description"><?php esc_html_e('This feature allows users to mass edit terms while creating and editing content.', 'simple-tags'); ?></div>
117 <br>
118
119 <ul class="subsubsub">
120 <?php
121 $status_links = array();
122 $num_posts = wp_count_posts( SimpleTags_Admin::$post_type, 'readable' );
123 $class = ( empty( $_GET['post_status'] ) && empty( $_GET['post_type'] ) ) ? ' class="current"' : '';
124 $status_links[] = '<li><a href="' . admin_url( 'admin.php' ) . '?page=st_mass_terms&amp;cpt=' . SimpleTags_Admin::$post_type . '&amp;taxo=' . SimpleTags_Admin::$taxonomy . '"' . $class . '>' . esc_html__( 'All', 'simple-tags' ) . '</a>';
125 foreach ( $post_stati as $status => $label ) {
126 $class = '';
127
128 if ( ! in_array( $status, $avail_post_stati ) ) {
129 continue;
130 }
131
132 if ( empty( $num_posts->$status ) ) {
133 continue;
134 }
135 if ( isset( $_GET['post_status'] ) && $status == $_GET['post_status'] ) {
136 $class = ' class="current"';
137 }
138
139 $status_links[] = '<li><a href="' . admin_url( 'admin.php' ) . '?page=st_mass_terms&amp;cpt=' . SimpleTags_Admin::$post_type . '&amp;taxo=' . SimpleTags_Admin::$taxonomy . '&amp;post_status=' . $status . '"' . $class . '>' . sprintf( _n( $label[2][0], $label[2][1], (int) $num_posts->$status ), number_format_i18n( $num_posts->$status ) ) . '</a>';
140 }
141 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
142 echo implode( ' |</li>', $status_links ) . '</li>';
143 unset( $status_links );
144
145 $class = ( ! empty( $_GET['post_type'] ) ) ? ' class="current"' : '';
146 ?>
147 </ul>
148
149 <?php if ( isset( $_GET['post_status'] ) ) : ?>
150 <input type="hidden" name="post_status" value="<?php echo esc_attr( sanitize_text_field($_GET['post_status']) ) ?>"/>
151 <?php endif; ?>
152
153
154 <p class="search-box">
155 <input type="text" id="post-search-input" name="s" value="<?php the_search_query(); ?>"/>
156 <input type="submit" value="<?php _e( 'Search', 'simple-tags' ); ?>" class="button"/>
157 </p>
158
159 <div class="tablenav custom-nav">
160 <?php
161 $posts_per_page = ( isset( $_GET['posts_per_page'] ) ) ? (int) $_GET['posts_per_page'] : 0;
162 if ( (int) $posts_per_page == 0 ) {
163 $posts_per_page = 15;
164 }
165
166 $page_links = paginate_links( array(
167 'base' => add_query_arg( 'paged', '%#%' ),
168 'format' => '',
169 'total' => ceil( $wp_query->found_posts / $posts_per_page ),
170 'current' => ( (int) $_GET['paged'] )
171 ) );
172
173 if ( $page_links ) {
174 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
175 echo "<div class='tablenav-pages'>". $page_links ."</div>";
176 }
177 ?>
178
179 <div style="float: left">
180 <?php
181 if ( ! is_singular() ) {
182 $arc_result = $wpdb->get_results( $wpdb->prepare( "SELECT DISTINCT YEAR(post_date) AS yyear, MONTH(post_date) AS mmonth FROM $wpdb->posts WHERE post_type = %s ORDER BY post_date DESC", SimpleTags_Admin::$post_type ) );
183
184 $month_count = count( $arc_result );
185
186 if ( ! isset( $_GET['m'] ) ) {
187 $_GET['m'] = '';
188 }
189
190 if ( $month_count && ! ( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) {
191 ?>
192 <select name='m'>
193 <option <?php selected( @sanitize_text_field($_GET['m']), 0 ); ?>
194 value='0'><?php _e( 'Show all dates', 'simple-tags' ); ?></option>
195 <?php
196 foreach ( $arc_result as $arc_row ) {
197 if ( $arc_row->yyear == 0 ) {
198 continue;
199 }
200 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
201
202 if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] ) {
203 $default = ' selected="selected"';
204 } else {
205 $default = '';
206 }
207 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
208 echo "<option$default value='$arc_row->yyear$arc_row->mmonth'>";
209 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
210 echo esc_html($wp_locale->get_month( $arc_row->mmonth )) . " ".esc_html($arc_row->yyear)."";
211 echo "</option>\n";
212 }
213 ?>
214 </select>
215 <?php
216 }
217 ?>
218
219 <select name="posts_per_page" id="posts_per_page">
220 <option <?php if ( ! isset( $_GET['posts_per_page'] ) ) {
221 echo 'selected="selected"';
222 } ?> value=""><?php _e( 'Quantity&hellip;', 'simple-tags' ); ?></option>
223 <option <?php selected( $posts_per_page, 10 ); ?> value="10">10</option>
224 <option <?php selected( $posts_per_page, 20 ); ?> value="20">20</option>
225 <option <?php selected( $posts_per_page, 30 ); ?> value="30">30</option>
226 <option <?php selected( $posts_per_page, 40 ); ?> value="40">40</option>
227 <option <?php selected( $posts_per_page, 50 ); ?> value="50">50</option>
228 <option <?php selected( $posts_per_page, 100 ); ?> value="100">100</option>
229 <option <?php selected( $posts_per_page, 200 ); ?> value="200">200</option>
230 </select>
231
232 <input type="submit" id="post-query-submit" value="<?php _e( 'Filter', 'simple-tags' ); ?>"
233 class="button-secondary"/>
234 <?php } ?>
235 <?php SimpleTags_Admin::boxSelectorTaxonomy( 'st_mass_terms' ); ?>
236 </div>
237 <br style="clear:both;"/>
238 </div>
239 </form>
240
241 <div style="clear:both;margin-bottom: 6px;"></div>
242
243 <?php if ( have_posts() ) :
244 add_filter( 'the_title', 'esc_html' );
245 ?>
246 <form name="post" id="post" method="post" class="st-mass-edit">
247 <table class="widefat post fixed">
248 <thead>
249 <tr>
250 <th class="manage-column"><?php esc_html_e( 'Post title', 'simple-tags' ); ?></th>
251 <th class="manage-column"><?php printf( esc_html__( 'Terms : %s', 'simple-tags' ), esc_html( SimpleTags_Admin::$taxo_name ) ); ?></th>
252 </tr>
253 </thead>
254 <tbody>
255 <?php
256 $class = 'alternate';
257 while ( have_posts() ) {
258 the_post();
259 $class = ( $class == 'alternate' ) ? '' : 'alternate';
260 ?>
261 <tr valign="top" class="<?php echo esc_attr($class); ?>">
262 <th scope="row"><a
263 href="<?php echo esc_url(admin_url( 'post.php?action=edit&amp;post=' . get_the_ID() )); ?>"
264 title="<?php esc_attr_e( 'Edit', 'simple-tags' ); ?>"><?php echo ( esc_html(get_the_title()) == '' ) ? (int)get_the_ID() : esc_html(get_the_title()); ?></a>
265 </th>
266 <td><input id="tags-input<?php the_ID(); ?>" class="autocomplete-input tags_input"
267 type="text" size="100" name="tags[<?php echo (int)get_the_ID(); ?>]"
268 value="<?php echo esc_attr(SimpleTags_Admin::getTermsToEdit( SimpleTags_Admin::$taxonomy, get_the_ID() )); ?>"/>
269 </td>
270 </tr>
271 <?php
272 }
273 ?>
274 </tbody>
275 </table>
276
277 <p class="submit">
278 <input type="hidden" name="secure_mass"
279 value="<?php echo esc_attr(wp_create_nonce( 'st_mass_terms' )); ?>"/>
280 <input class="button-primary" type="submit" name="update_mass"
281 value="<?php esc_attr_e( 'Update all &raquo;', 'simple-tags' ); ?>"/>
282 </p>
283 </form>
284
285 <?php else: ?>
286
287 <p><?php _e( 'No content to edit.', 'simple-tags' ); ?>
288
289 <?php endif; ?>
290
291 <?php SimpleTags_Admin::printAdminFooter(); ?>
292 </div>
293
294 <div class="taxopress-right-sidebar admin-settings-sidebar">
295 <?php do_action('taxopress_admin_after_sidebar'); ?>
296 </div>
297
298 </div>
299
300 <?php
301 do_action( 'simpletags-mass_terms', SimpleTags_Admin::$taxonomy );
302 }
303
304 /**
305 * Clone the core WP function, add the possibility to manage the post type
306 *
307 * @param bool $q
308 *
309 * @return array
310 * @author WebFactory Ltd
311 */
312 public static function edit_data_query( $q = false ) {
313 if ( false === $q ) {
314 $q = $_GET;
315 }
316
317 // Date
318 if ( isset( $q['m'] ) ) {
319 $q['m'] = (int) $q['m'];
320 }
321
322 // Category
323 if ( isset( $q['cat'] ) ) {
324 $q['cat'] = (int) $q['cat'];
325 }
326
327 // Quantity
328 $q['posts_per_page'] = ( isset( $q['posts_per_page'] ) ) ? (int) $q['posts_per_page'] : 0;
329 if ( $q['posts_per_page'] == 0 ) {
330 $q['posts_per_page'] = 15;
331 }
332
333 // Content type
334 $q['post_type'] = SimpleTags_Admin::$post_type;
335
336 // Post status
337 $post_stati = array( // array( adj, noun )
338 'publish' => array(
339 _x( 'Published', 'post' ),
340 __( 'Published posts' ),
341 _n_noop( 'Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>' )
342 ),
343 'future' => array(
344 _x( 'Scheduled', 'post' ),
345 __( 'Scheduled posts' ),
346 _n_noop( 'Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>' )
347 ),
348 'pending' => array(
349 _x( 'Pending Review', 'post' ),
350 __( 'Pending posts' ),
351 _n_noop( 'Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>' )
352 ),
353 'draft' => array(
354 _x( 'Draft', 'post' ),
355 _x( 'Drafts', 'manage posts header' ),
356 _n_noop( 'Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>' )
357 ),
358 'private' => array(
359 _x( 'Private', 'post' ),
360 __( 'Private posts' ),
361 _n_noop( 'Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>' )
362 ),
363 'inherit' => array(
364 _x( 'Inherit', 'post' ),
365 __( 'Inherit posts' ),
366 _n_noop( 'Inherit <span class="count">(%s)</span>', 'Inherit <span class="count">(%s)</span>' )
367 ),
368 );
369
370 $post_stati = apply_filters( 'post_stati', $post_stati );
371 $avail_post_stati = get_available_post_statuses( SimpleTags_Admin::$post_type );
372
373
374 if($q['post_type'] === 'attachment'){
375 $q['post_status'] = 'inherit';
376 }
377
378 $post_status_q = '';
379 if ( isset( $q['post_status'] ) && in_array( $q['post_status'], array_keys( $post_stati ) ) ) {
380 $post_status_q = '&post_status=' . $q['post_status'];
381 $post_status_q .= '&perm=readable';
382 } elseif ( ! isset( $q['post_status'] ) ) {
383 $q['post_status'] = '';
384 }
385
386
387 if ( 'pending' === $q['post_status'] ) {
388 $order = 'ASC';
389 $orderby = 'modified';
390 } elseif ( 'draft' === $q['post_status'] ) {
391 $order = 'DESC';
392 $orderby = 'modified';
393 } else {
394 $order = 'DESC';
395 $orderby = 'date';
396 }
397
398 wp( "post_type={$q['post_type']}&what_to_show=posts$post_status_q&posts_per_page={$q['posts_per_page']}&order=$order&orderby=$orderby" );
399
400 return array( $post_stati, $avail_post_stati );
401 }
402
403 }
404