PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.5.3
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.5.3
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 3.6.2 All 177 releases
simple-tags / inc / class.admin.mass.php

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

401 lines 13.0 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__( 'TaxoPress: 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' );
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' );
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="wrap st_wrap tagcloudui st_mass_terms-page admin-settings">
108 <?php SimpleTags_Admin::boxSelectorTaxonomy( 'st_mass_terms' ); ?>
109
110 <form id="posts-filter" action="" method="get">
111 <input type="hidden" name="page" value="st_mass_terms"/>
112 <input type="hidden" name="taxo" value="<?php echo esc_attr( SimpleTags_Admin::$taxonomy ); ?>"/>
113 <input type="hidden" name="cpt" value="<?php echo esc_attr( SimpleTags_Admin::$post_type ); ?>"/>
114
115 <h2><?php _e( 'Mass edit terms', 'simple-tags' ); ?></h2>
116 <br>
117
118 <ul class="subsubsub">
119 <?php
120 $status_links = array();
121 $num_posts = wp_count_posts( SimpleTags_Admin::$post_type, 'readable' );
122 $class = ( empty( $_GET['post_status'] ) && empty( $_GET['post_type'] ) ) ? ' class="current"' : '';
123 $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>';
124 foreach ( $post_stati as $status => $label ) {
125 $class = '';
126
127 if ( ! in_array( $status, $avail_post_stati ) ) {
128 continue;
129 }
130
131 if ( empty( $num_posts->$status ) ) {
132 continue;
133 }
134 if ( isset( $_GET['post_status'] ) && $status == $_GET['post_status'] ) {
135 $class = ' class="current"';
136 }
137
138 $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>';
139 }
140 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
141 echo implode( ' |</li>', $status_links ) . '</li>';
142 unset( $status_links );
143
144 $class = ( ! empty( $_GET['post_type'] ) ) ? ' class="current"' : '';
145 ?>
146 </ul>
147
148 <?php if ( isset( $_GET['post_status'] ) ) : ?>
149 <input type="hidden" name="post_status" value="<?php echo esc_attr( sanitize_text_field($_GET['post_status']) ) ?>"/>
150 <?php endif; ?>
151
152 <div class="tablenav">
153 <?php
154 $posts_per_page = ( isset( $_GET['posts_per_page'] ) ) ? (int) $_GET['posts_per_page'] : 0;
155 if ( (int) $posts_per_page == 0 ) {
156 $posts_per_page = 15;
157 }
158
159 $page_links = paginate_links( array(
160 'base' => add_query_arg( 'paged', '%#%' ),
161 'format' => '',
162 'total' => ceil( $wp_query->found_posts / $posts_per_page ),
163 'current' => ( (int) $_GET['paged'] )
164 ) );
165
166 if ( $page_links ) {
167 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
168 echo "<div class='tablenav-pages'>". $page_links ."</div>";
169 }
170 ?>
171
172 <div style="float: left">
173 <?php
174 if ( ! is_singular() ) {
175 $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 ) );
176
177 $month_count = count( $arc_result );
178
179 if ( ! isset( $_GET['m'] ) ) {
180 $_GET['m'] = '';
181 }
182
183 if ( $month_count && ! ( 1 == $month_count && 0 == $arc_result[0]->mmonth ) ) {
184 ?>
185 <select name='m'>
186 <option <?php selected( @sanitize_text_field($_GET['m']), 0 ); ?>
187 value='0'><?php _e( 'Show all dates', 'simple-tags' ); ?></option>
188 <?php
189 foreach ( $arc_result as $arc_row ) {
190 if ( $arc_row->yyear == 0 ) {
191 continue;
192 }
193 $arc_row->mmonth = zeroise( $arc_row->mmonth, 2 );
194
195 if ( $arc_row->yyear . $arc_row->mmonth == $_GET['m'] ) {
196 $default = ' selected="selected"';
197 } else {
198 $default = '';
199 }
200 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
201 echo "<option$default value='$arc_row->yyear$arc_row->mmonth'>";
202 // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
203 echo esc_html($wp_locale->get_month( $arc_row->mmonth )) . " ".esc_html($arc_row->yyear)."";
204 echo "</option>\n";
205 }
206 ?>
207 </select>
208 <?php
209 }
210 ?>
211
212 <select name="posts_per_page" id="posts_per_page">
213 <option <?php if ( ! isset( $_GET['posts_per_page'] ) ) {
214 echo 'selected="selected"';
215 } ?> value=""><?php _e( 'Quantity&hellip;', 'simple-tags' ); ?></option>
216 <option <?php selected( $posts_per_page, 10 ); ?> value="10">10</option>
217 <option <?php selected( $posts_per_page, 20 ); ?> value="20">20</option>
218 <option <?php selected( $posts_per_page, 30 ); ?> value="30">30</option>
219 <option <?php selected( $posts_per_page, 40 ); ?> value="40">40</option>
220 <option <?php selected( $posts_per_page, 50 ); ?> value="50">50</option>
221 <option <?php selected( $posts_per_page, 100 ); ?> value="100">100</option>
222 <option <?php selected( $posts_per_page, 200 ); ?> value="200">200</option>
223 </select>
224
225 <input type="submit" id="post-query-submit" value="<?php _e( 'Filter', 'simple-tags' ); ?>"
226 class="button-secondary"/>
227 <?php } ?>
228 </div>
229
230
231 <p class="search-box">
232 <input type="text" id="post-search-input" name="s" value="<?php the_search_query(); ?>"/>
233 <input type="submit" value="<?php _e( 'Search', 'simple-tags' ); ?>" class="button"/>
234 </p>
235
236 <br style="clear:both;"/>
237 </div>
238 </form>
239
240 <br style="clear:both;"/>
241
242 <?php if ( have_posts() ) :
243 add_filter( 'the_title', 'esc_html' );
244 ?>
245 <form name="post" id="post" method="post" class="st-mass-edit">
246 <table class="widefat post fixed">
247 <thead>
248 <tr>
249 <th class="manage-column"><?php esc_html_e( 'Post title', 'simple-tags' ); ?></th>
250 <th class="manage-column"><?php printf( esc_html__( 'Terms : %s', 'simple-tags' ), esc_html( SimpleTags_Admin::$taxo_name ) ); ?></th>
251 </tr>
252 </thead>
253 <tbody>
254 <?php
255 $class = 'alternate';
256 while ( have_posts() ) {
257 the_post();
258 $class = ( $class == 'alternate' ) ? '' : 'alternate';
259 ?>
260 <tr valign="top" class="<?php echo esc_attr($class); ?>">
261 <th scope="row"><a
262 href="<?php echo esc_url(admin_url( 'post.php?action=edit&amp;post=' . get_the_ID() )); ?>"
263 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>
264 </th>
265 <td><input id="tags-input<?php the_ID(); ?>" class="autocomplete-input tags_input"
266 type="text" size="100" name="tags[<?php echo (int)get_the_ID(); ?>]"
267 value="<?php echo esc_attr(SimpleTags_Admin::getTermsToEdit( SimpleTags_Admin::$taxonomy, get_the_ID() )); ?>"/>
268 </td>
269 </tr>
270 <?php
271 }
272 ?>
273 </tbody>
274 </table>
275
276 <p class="submit">
277 <input type="hidden" name="secure_mass"
278 value="<?php echo esc_attr(wp_create_nonce( 'st_mass_terms' )); ?>"/>
279 <input class="button-primary" type="submit" name="update_mass"
280 value="<?php esc_attr_e( 'Update all &raquo;', 'simple-tags' ); ?>"/>
281 </p>
282 </form>
283
284 <?php else: ?>
285
286 <p><?php _e( 'No content to edit.', 'simple-tags' ); ?>
287
288 <?php endif; ?>
289
290 <?php SimpleTags_Admin::printAdminFooter(); ?>
291 </div>
292
293 <div class="taxopress-right-sidebar admin-settings-sidebar">
294 <?php do_action('taxopress_admin_after_sidebar'); ?>
295 </div>
296
297 <?php
298 do_action( 'simpletags-mass_terms', SimpleTags_Admin::$taxonomy );
299 }
300
301 /**
302 * Clone the core WP function, add the possibility to manage the post type
303 *
304 * @param bool $q
305 *
306 * @return array
307 * @author WebFactory Ltd
308 */
309 public static function edit_data_query( $q = false ) {
310 if ( false === $q ) {
311 $q = $_GET;
312 }
313
314 // Date
315 if ( isset( $q['m'] ) ) {
316 $q['m'] = (int) $q['m'];
317 }
318
319 // Category
320 if ( isset( $q['cat'] ) ) {
321 $q['cat'] = (int) $q['cat'];
322 }
323
324 // Quantity
325 $q['posts_per_page'] = ( isset( $q['posts_per_page'] ) ) ? (int) $q['posts_per_page'] : 0;
326 if ( $q['posts_per_page'] == 0 ) {
327 $q['posts_per_page'] = 15;
328 }
329
330 // Content type
331 $q['post_type'] = SimpleTags_Admin::$post_type;
332
333 // Post status
334 $post_stati = array( // array( adj, noun )
335 'publish' => array(
336 _x( 'Published', 'post' ),
337 __( 'Published posts' ),
338 _n_noop( 'Published <span class="count">(%s)</span>', 'Published <span class="count">(%s)</span>' )
339 ),
340 'future' => array(
341 _x( 'Scheduled', 'post' ),
342 __( 'Scheduled posts' ),
343 _n_noop( 'Scheduled <span class="count">(%s)</span>', 'Scheduled <span class="count">(%s)</span>' )
344 ),
345 'pending' => array(
346 _x( 'Pending Review', 'post' ),
347 __( 'Pending posts' ),
348 _n_noop( 'Pending Review <span class="count">(%s)</span>', 'Pending Review <span class="count">(%s)</span>' )
349 ),
350 'draft' => array(
351 _x( 'Draft', 'post' ),
352 _x( 'Drafts', 'manage posts header' ),
353 _n_noop( 'Draft <span class="count">(%s)</span>', 'Drafts <span class="count">(%s)</span>' )
354 ),
355 'private' => array(
356 _x( 'Private', 'post' ),
357 __( 'Private posts' ),
358 _n_noop( 'Private <span class="count">(%s)</span>', 'Private <span class="count">(%s)</span>' )
359 ),
360 'inherit' => array(
361 _x( 'Inherit', 'post' ),
362 __( 'Inherit posts' ),
363 _n_noop( 'Inherit <span class="count">(%s)</span>', 'Inherit <span class="count">(%s)</span>' )
364 ),
365 );
366
367 $post_stati = apply_filters( 'post_stati', $post_stati );
368 $avail_post_stati = get_available_post_statuses( SimpleTags_Admin::$post_type );
369
370
371 if($q['post_type'] === 'attachment'){
372 $q['post_status'] = 'inherit';
373 }
374
375 $post_status_q = '';
376 if ( isset( $q['post_status'] ) && in_array( $q['post_status'], array_keys( $post_stati ) ) ) {
377 $post_status_q = '&post_status=' . $q['post_status'];
378 $post_status_q .= '&perm=readable';
379 } elseif ( ! isset( $q['post_status'] ) ) {
380 $q['post_status'] = '';
381 }
382
383
384 if ( 'pending' === $q['post_status'] ) {
385 $order = 'ASC';
386 $orderby = 'modified';
387 } elseif ( 'draft' === $q['post_status'] ) {
388 $order = 'DESC';
389 $orderby = 'modified';
390 } else {
391 $order = 'DESC';
392 $orderby = 'date';
393 }
394
395 wp( "post_type={$q['post_type']}&what_to_show=posts$post_status_q&posts_per_page={$q['posts_per_page']}&order=$order&orderby=$orderby" );
396
397 return array( $post_stati, $avail_post_stati );
398 }
399
400 }
401