Permalink Manager Lite - Version 0.3.4

Version Description

  • Hotfix for not working custom taxonomies tags.
  • Now the rewrite rules for custom post types are stored in different way.
Download this release

Release Info

Developer mbis
Plugin Icon 128x128 Permalink Manager Lite
Version 0.3.4
Comparing to
See all releases

Code changes from version 0.3.3 to 0.3.4

README.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: mbis
3
  Tags: urls, permalinks, slugs
4
  Requires at least: 4.0
5
  Tested up to: 4.5.2
6
- Stable tag: 0.3.3
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
@@ -72,8 +72,17 @@ After the plugin is installed you can access its dashboard from this page: `Tool
72
  3. Regenerate section.
73
  4. Custom permastructures.
74
 
 
 
 
 
 
75
  == Changelog ==
76
 
 
 
 
 
77
  = 0.3.3 =
78
  * Hotfix for bug with dynamic function names in PHP7.
79
 
3
  Tags: urls, permalinks, slugs
4
  Requires at least: 4.0
5
  Tested up to: 4.5.2
6
+ Stable tag: 0.3.4
7
  License: GPLv2 or later
8
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
 
72
  3. Regenerate section.
73
  4. Custom permastructures.
74
 
75
+ == Frequently Asked Questions ==
76
+
77
+ = Q. The permalinks did not work any longer after the plugin was removed. =
78
+ A. You need to flush the original rewrite rules. Go to "Settings -> Permalinks" `/wp-admin/options-permalink.php` and click on "Save Changes".
79
+
80
  == Changelog ==
81
 
82
+ = 0.3.4 =
83
+ * Hotfix for not working custom taxonomies tags.
84
+ * Now the rewrite rules for custom post types are stored in different way.
85
+
86
  = 0.3.3 =
87
  * Hotfix for bug with dynamic function names in PHP7.
88
 
inc/permalink-manager-class-wp-list-table.php DELETED
@@ -1,1371 +0,0 @@
1
- <?php
2
- /**
3
- * Base class for displaying a list of items in an ajaxified HTML table.
4
- *
5
- * This class is copied from /wp-admin/includes/class-wp-list-table.php to fix strict standard issues
6
- *
7
- * @since 3.1.0
8
- * @access private
9
- */
10
- class Permalink_WP_List_Table {
11
-
12
- /**
13
- * The current list of items.
14
- *
15
- * @since 3.1.0
16
- * @access public
17
- * @var array
18
- */
19
- public $items;
20
-
21
- /**
22
- * Various information about the current table.
23
- *
24
- * @since 3.1.0
25
- * @access protected
26
- * @var array
27
- */
28
- protected $_args;
29
-
30
- /**
31
- * Various information needed for displaying the pagination.
32
- *
33
- * @since 3.1.0
34
- * @access protected
35
- * @var array
36
- */
37
- protected $_pagination_args = array();
38
-
39
- /**
40
- * The current screen.
41
- *
42
- * @since 3.1.0
43
- * @access protected
44
- * @var object
45
- */
46
- protected $screen;
47
-
48
- /**
49
- * Cached bulk actions.
50
- *
51
- * @since 3.1.0
52
- * @access private
53
- * @var array
54
- */
55
- private $_actions;
56
-
57
- /**
58
- * Cached pagination output.
59
- *
60
- * @since 3.1.0
61
- * @access private
62
- * @var string
63
- */
64
- private $_pagination;
65
-
66
- /**
67
- * The view switcher modes.
68
- *
69
- * @since 4.1.0
70
- * @access protected
71
- * @var array
72
- */
73
- protected $modes = array();
74
-
75
- /**
76
- * Stores the value returned by ->get_column_info().
77
- *
78
- * @since 4.1.0
79
- * @access protected
80
- * @var array
81
- */
82
- protected $_column_headers;
83
-
84
- /**
85
- * {@internal Missing Summary}
86
- *
87
- * @access protected
88
- * @var array
89
- */
90
- protected $compat_fields = array( '_args', '_pagination_args', 'screen', '_actions', '_pagination' );
91
-
92
- /**
93
- * {@internal Missing Summary}
94
- *
95
- * @access protected
96
- * @var array
97
- */
98
- protected $compat_methods = array( 'set_pagination_args', 'get_views', 'get_bulk_actions', 'bulk_actions',
99
- 'row_actions', 'months_dropdown', 'view_switcher', 'comments_bubble', 'get_items_per_page', 'pagination',
100
- 'get_sortable_columns', 'get_column_info', 'get_table_classes', 'display_tablenav', 'extra_tablenav',
101
- 'single_row_columns' );
102
-
103
- /**
104
- * Constructor.
105
- *
106
- * The child class should call this constructor from its own constructor to override
107
- * the default $args.
108
- *
109
- * @since 3.1.0
110
- * @access public
111
- *
112
- * @param array|string $args {
113
- * Array or string of arguments.
114
- *
115
- * @type string $plural Plural value used for labels and the objects being listed.
116
- * This affects things such as CSS class-names and nonces used
117
- * in the list table, e.g. 'posts'. Default empty.
118
- * @type string $singular Singular label for an object being listed, e.g. 'post'.
119
- * Default empty
120
- * @type bool $ajax Whether the list table supports AJAX. This includes loading
121
- * and sorting data, for example. If true, the class will call
122
- * the _js_vars() method in the footer to provide variables
123
- * to any scripts handling AJAX events. Default false.
124
- * @type string $screen String containing the hook name used to determine the current
125
- * screen. If left null, the current screen will be automatically set.
126
- * Default null.
127
- * }
128
- */
129
- public function __construct( $args = array() ) {
130
- $args = wp_parse_args( $args, array(
131
- 'plural' => '',
132
- 'singular' => '',
133
- 'ajax' => false,
134
- 'screen' => null,
135
- ) );
136
-
137
- $this->screen = convert_to_screen( $args['screen'] );
138
-
139
- add_filter( "manage_{$this->screen->id}_columns", array( $this, 'get_columns' ), 0 );
140
-
141
- if ( !$args['plural'] )
142
- $args['plural'] = $this->screen->base;
143
-
144
- $args['plural'] = sanitize_key( $args['plural'] );
145
- $args['singular'] = sanitize_key( $args['singular'] );
146
-
147
- $this->_args = $args;
148
-
149
- if ( $args['ajax'] ) {
150
- // wp_enqueue_script( 'list-table' );
151
- add_action( 'admin_footer', array( $this, '_js_vars' ) );
152
- }
153
-
154
- if ( empty( $this->modes ) ) {
155
- $this->modes = array(
156
- 'list' => __( 'List View' ),
157
- 'excerpt' => __( 'Excerpt View' )
158
- );
159
- }
160
- }
161
-
162
- /**
163
- * Make private properties readable for backward compatibility.
164
- *
165
- * @since 4.0.0
166
- * @access public
167
- *
168
- * @param string $name Property to get.
169
- * @return mixed Property.
170
- */
171
- public function __get( $name ) {
172
- if ( in_array( $name, $this->compat_fields ) ) {
173
- return $this->$name;
174
- }
175
- }
176
-
177
- /**
178
- * Make private properties settable for backward compatibility.
179
- *
180
- * @since 4.0.0
181
- * @access public
182
- *
183
- * @param string $name Property to check if set.
184
- * @param mixed $value Property value.
185
- * @return mixed Newly-set property.
186
- */
187
- public function __set( $name, $value ) {
188
- if ( in_array( $name, $this->compat_fields ) ) {
189
- return $this->$name = $value;
190
- }
191
- }
192
-
193
- /**
194
- * Make private properties checkable for backward compatibility.
195
- *
196
- * @since 4.0.0
197
- * @access public
198
- *
199
- * @param string $name Property to check if set.
200
- * @return bool Whether the property is set.
201
- */
202
- public function __isset( $name ) {
203
- if ( in_array( $name, $this->compat_fields ) ) {
204
- return isset( $this->$name );
205
- }
206
- }
207
-
208
- /**
209
- * Make private properties un-settable for backward compatibility.
210
- *
211
- * @since 4.0.0
212
- * @access public
213
- *
214
- * @param string $name Property to unset.
215
- */
216
- public function __unset( $name ) {
217
- if ( in_array( $name, $this->compat_fields ) ) {
218
- unset( $this->$name );
219
- }
220
- }
221
-
222
- /**
223
- * Make private/protected methods readable for backward compatibility.
224
- *
225
- * @since 4.0.0
226
- * @access public
227
- *
228
- * @param callable $name Method to call.
229
- * @param array $arguments Arguments to pass when calling.
230
- * @return mixed|bool Return value of the callback, false otherwise.
231
- */
232
- public function __call( $name, $arguments ) {
233
- if ( in_array( $name, $this->compat_methods ) ) {
234
- return call_user_func_array( array( $this, $name ), $arguments );
235
- }
236
- return false;
237
- }
238
-
239
- /**
240
- * Checks the current user's permissions
241
- *
242
- * @since 3.1.0
243
- * @access public
244
- * @abstract
245
- */
246
- public function ajax_user_can() {
247
- die( 'function WP_List_Table::ajax_user_can() must be over-ridden in a sub-class.' );
248
- }
249
-
250
- /**
251
- * Prepares the list of items for displaying.
252
- * @uses WP_List_Table::set_pagination_args()
253
- *
254
- * @since 3.1.0
255
- * @access public
256
- * @abstract
257
- */
258
- public function prepare_items() {
259
- die( 'function WP_List_Table::prepare_items() must be over-ridden in a sub-class.' );
260
- }
261
-
262
- /**
263
- * An internal method that sets all the necessary pagination arguments
264
- *
265
- * @since 3.1.0
266
- * @access protected
267
- *
268
- * @param array|string $args Array or string of arguments with information about the pagination.
269
- */
270
- protected function set_pagination_args( $args ) {
271
- $args = wp_parse_args( $args, array(
272
- 'total_items' => 0,
273
- 'total_pages' => 0,
274
- 'per_page' => 0,
275
- ) );
276
-
277
- if ( !$args['total_pages'] && $args['per_page'] > 0 )
278
- $args['total_pages'] = ceil( $args['total_items'] / $args['per_page'] );
279
-
280
- // Redirect if page number is invalid and headers are not already sent.
281
- if ( ! headers_sent() && ( ! defined( 'DOING_AJAX' ) || ! DOING_AJAX ) && $args['total_pages'] > 0 && $this->get_pagenum() > $args['total_pages'] ) {
282
- wp_redirect( add_query_arg( 'paged', $args['total_pages'] ) );
283
- exit;
284
- }
285
-
286
- $this->_pagination_args = $args;
287
- }
288
-
289
- /**
290
- * Access the pagination args.
291
- *
292
- * @since 3.1.0
293
- * @access public
294
- *
295
- * @param string $key Pagination argument to retrieve. Common values include 'total_items',
296
- * 'total_pages', 'per_page', or 'infinite_scroll'.
297
- * @return int Number of items that correspond to the given pagination argument.
298
- */
299
- public function get_pagination_arg( $key ) {
300
- if ( 'page' === $key ) {
301
- return $this->get_pagenum();
302
- }
303
-
304
- if ( isset( $this->_pagination_args[$key] ) ) {
305
- return $this->_pagination_args[$key];
306
- }
307
- }
308
-
309
- /**
310
- * Whether the table has items to display or not
311
- *
312
- * @since 3.1.0
313
- * @access public
314
- *
315
- * @return bool
316
- */
317
- public function has_items() {
318
- return !empty( $this->items );
319
- }
320
-
321
- /**
322
- * Message to be displayed when there are no items
323
- *
324
- * @since 3.1.0
325
- * @access public
326
- */
327
- public function no_items() {
328
- _e( 'No items found.' );
329
- }
330
-
331
- /**
332
- * Display the search box.
333
- *
334
- * @since 3.1.0
335
- * @access public
336
- *
337
- * @param string $text The search button text
338
- * @param string $input_id The search input id
339
- */
340
- public function search_box( $text, $input_id ) {
341
- if ( empty( $_REQUEST['s'] ) && !$this->has_items() )
342
- return;
343
-
344
- $input_id = $input_id . '-search-input';
345
-
346
- if ( ! empty( $_REQUEST['orderby'] ) )
347
- echo '<input type="hidden" name="orderby" value="' . esc_attr( $_REQUEST['orderby'] ) . '" />';
348
- if ( ! empty( $_REQUEST['order'] ) )
349
- echo '<input type="hidden" name="order" value="' . esc_attr( $_REQUEST['order'] ) . '" />';
350
- if ( ! empty( $_REQUEST['post_mime_type'] ) )
351
- echo '<input type="hidden" name="post_mime_type" value="' . esc_attr( $_REQUEST['post_mime_type'] ) . '" />';
352
- if ( ! empty( $_REQUEST['detached'] ) )
353
- echo '<input type="hidden" name="detached" value="' . esc_attr( $_REQUEST['detached'] ) . '" />';
354
- ?>
355
- <p class="search-box">
356
- <label class="screen-reader-text" for="<?php echo $input_id ?>"><?php echo $text; ?>:</label>
357
- <input type="search" id="<?php echo $input_id ?>" name="s" value="<?php _admin_search_query(); ?>" />
358
- <?php submit_button( $text, 'button', '', false, array('id' => 'search-submit') ); ?>
359
- </p>
360
- <?php
361
- }
362
-
363
- /**
364
- * Get an associative array ( id => link ) with the list
365
- * of views available on this table.
366
- *
367
- * @since 3.1.0
368
- * @access protected
369
- *
370
- * @return array
371
- */
372
- protected function get_views() {
373
- return array();
374
- }
375
-
376
- /**
377
- * Display the list of views available on this table.
378
- *
379
- * @since 3.1.0
380
- * @access public
381
- */
382
- public function views() {
383
- $views = $this->get_views();
384
- /**
385
- * Filters the list of available list table views.
386
- *
387
- * The dynamic portion of the hook name, `$this->screen->id`, refers
388
- * to the ID of the current screen, usually a string.
389
- *
390
- * @since 3.5.0
391
- *
392
- * @param array $views An array of available list table views.
393
- */
394
- $views = apply_filters( "views_{$this->screen->id}", $views );
395
-
396
- if ( empty( $views ) )
397
- return;
398
-
399
- $this->screen->render_screen_reader_content( 'heading_views' );
400
-
401
- echo "<ul class='subsubsub'>\n";
402
- foreach ( $views as $class => $view ) {
403
- $views[ $class ] = "\t<li class='$class'>$view";
404
- }
405
- echo implode( " |</li>\n", $views ) . "</li>\n";
406
- echo "</ul>";
407
- }
408
-
409
- /**
410
- * Get an associative array ( option_name => option_title ) with the list
411
- * of bulk actions available on this table.
412
- *
413
- * @since 3.1.0
414
- * @access protected
415
- *
416
- * @return array
417
- */
418
- protected function get_bulk_actions() {
419
- return array();
420
- }
421
-
422
- /**
423
- * Display the bulk actions dropdown.
424
- *
425
- * @since 3.1.0
426
- * @access protected
427
- *
428
- * @param string $which The location of the bulk actions: 'top' or 'bottom'.
429
- * This is designated as optional for backward compatibility.
430
- */
431
- protected function bulk_actions( $which = '' ) {
432
- if ( is_null( $this->_actions ) ) {
433
- $no_new_actions = $this->_actions = $this->get_bulk_actions();
434
- /**
435
- * Filters the list table Bulk Actions drop-down.
436
- *
437
- * The dynamic portion of the hook name, `$this->screen->id`, refers
438
- * to the ID of the current screen, usually a string.
439
- *
440
- * This filter can currently only be used to remove bulk actions.
441
- *
442
- * @since 3.5.0
443
- *
444
- * @param array $actions An array of the available bulk actions.
445
- */
446
- $this->_actions = apply_filters( "bulk_actions-{$this->screen->id}", $this->_actions );
447
- $this->_actions = array_intersect_assoc( $this->_actions, $no_new_actions );
448
- $two = '';
449
- } else {
450
- $two = '2';
451
- }
452
-
453
- if ( empty( $this->_actions ) )
454
- return;
455
-
456
- echo '<label for="bulk-action-selector-' . esc_attr( $which ) . '" class="screen-reader-text">' . __( 'Select bulk action' ) . '</label>';
457
- echo '<select name="action' . $two . '" id="bulk-action-selector-' . esc_attr( $which ) . "\">\n";
458
- echo '<option value="-1">' . __( 'Bulk Actions' ) . "</option>\n";
459
-
460
- foreach ( $this->_actions as $name => $title ) {
461
- $class = 'edit' === $name ? ' class="hide-if-no-js"' : '';
462
-
463
- echo "\t" . '<option value="' . $name . '"' . $class . '>' . $title . "</option>\n";
464
- }
465
-
466
- echo "</select>\n";
467
-
468
- submit_button( __( 'Apply' ), 'action', '', false, array( 'id' => "doaction$two" ) );
469
- echo "\n";
470
- }
471
-
472
- /**
473
- * Get the current action selected from the bulk actions dropdown.
474
- *
475
- * @since 3.1.0
476
- * @access public
477
- *
478
- * @return string|false The action name or False if no action was selected
479
- */
480
- public function current_action() {
481
- if ( isset( $_REQUEST['filter_action'] ) && ! empty( $_REQUEST['filter_action'] ) )
482
- return false;
483
-
484
- if ( isset( $_REQUEST['action'] ) && -1 != $_REQUEST['action'] )
485
- return $_REQUEST['action'];
486
-
487
- if ( isset( $_REQUEST['action2'] ) && -1 != $_REQUEST['action2'] )
488
- return $_REQUEST['action2'];
489
-
490
- return false;
491
- }
492
-
493
- /**
494
- * Generate row actions div
495
- *
496
- * @since 3.1.0
497
- * @access protected
498
- *
499
- * @param array $actions The list of actions
500
- * @param bool $always_visible Whether the actions should be always visible
501
- * @return string
502
- */
503
- protected function row_actions( $actions, $always_visible = false ) {
504
- $action_count = count( $actions );
505
- $i = 0;
506
-
507
- if ( !$action_count )
508
- return '';
509
-
510
- $out = '<div class="' . ( $always_visible ? 'row-actions visible' : 'row-actions' ) . '">';
511
- foreach ( $actions as $action => $link ) {
512
- ++$i;
513
- ( $i == $action_count ) ? $sep = '' : $sep = ' | ';
514
- $out .= "<span class='$action'>$link$sep</span>";
515
- }
516
- $out .= '</div>';
517
-
518
- $out .= '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>';
519
-
520
- return $out;
521
- }
522
-
523
- /**
524
- * Display a monthly dropdown for filtering items
525
- *
526
- * @since 3.1.0
527
- * @access protected
528
- *
529
- * @global wpdb $wpdb
530
- * @global WP_Locale $wp_locale
531
- *
532
- * @param string $post_type
533
- */
534
- protected function months_dropdown( $post_type ) {
535
- global $wpdb, $wp_locale;
536
-
537
- /**
538
- * Filters whether to remove the 'Months' drop-down from the post list table.
539
- *
540
- * @since 4.2.0
541
- *
542
- * @param bool $disable Whether to disable the drop-down. Default false.
543
- * @param string $post_type The post type.
544
- */
545
- if ( apply_filters( 'disable_months_dropdown', false, $post_type ) ) {
546
- return;
547
- }
548
-
549
- $extra_checks = "AND post_status != 'auto-draft'";
550
- if ( ! isset( $_GET['post_status'] ) || 'trash' !== $_GET['post_status'] ) {
551
- $extra_checks .= " AND post_status != 'trash'";
552
- } elseif ( isset( $_GET['post_status'] ) ) {
553
- $extra_checks = $wpdb->prepare( ' AND post_status = %s', $_GET['post_status'] );
554
- }
555
-
556
- $months = $wpdb->get_results( $wpdb->prepare( "
557
- SELECT DISTINCT YEAR( post_date ) AS year, MONTH( post_date ) AS month
558
- FROM $wpdb->posts
559
- WHERE post_type = %s
560
- $extra_checks
561
- ORDER BY post_date DESC
562
- ", $post_type ) );
563
-
564
- /**
565
- * Filters the 'Months' drop-down results.
566
- *
567
- * @since 3.7.0
568
- *
569
- * @param object $months The months drop-down query results.
570
- * @param string $post_type The post type.
571
- */
572
- $months = apply_filters( 'months_dropdown_results', $months, $post_type );
573
-
574
- $month_count = count( $months );
575
-
576
- if ( !$month_count || ( 1 == $month_count && 0 == $months[0]->month ) )
577
- return;
578
-
579
- $m = isset( $_GET['m'] ) ? (int) $_GET['m'] : 0;
580
- ?>
581
- <label for="filter-by-date" class="screen-reader-text"><?php _e( 'Filter by date' ); ?></label>
582
- <select name="m" id="filter-by-date">
583
- <option<?php selected( $m, 0 ); ?> value="0"><?php _e( 'All dates' ); ?></option>
584
- <?php
585
- foreach ( $months as $arc_row ) {
586
- if ( 0 == $arc_row->year )
587
- continue;
588
-
589
- $month = zeroise( $arc_row->month, 2 );
590
- $year = $arc_row->year;
591
-
592
- printf( "<option %s value='%s'>%s</option>\n",
593
- selected( $m, $year . $month, false ),
594
- esc_attr( $arc_row->year . $month ),
595
- /* translators: 1: month name, 2: 4-digit year */
596
- sprintf( __( '%1$s %2$d' ), $wp_locale->get_month( $month ), $year )
597
- );
598
- }
599
- ?>
600
- </select>
601
- <?php
602
- }
603
-
604
- /**
605
- * Display a view switcher
606
- *
607
- * @since 3.1.0
608
- * @access protected
609
- *
610
- * @param string $current_mode
611
- */
612
- protected function view_switcher( $current_mode ) {
613
- ?>
614
- <input type="hidden" name="mode" value="<?php echo esc_attr( $current_mode ); ?>" />
615
- <div class="view-switch">
616
- <?php
617
- foreach ( $this->modes as $mode => $title ) {
618
- $classes = array( 'view-' . $mode );
619
- if ( $current_mode === $mode )
620
- $classes[] = 'current';
621
- printf(
622
- "<a href='%s' class='%s' id='view-switch-$mode'><span class='screen-reader-text'>%s</span></a>\n",
623
- esc_url( add_query_arg( 'mode', $mode ) ),
624
- implode( ' ', $classes ),
625
- $title
626
- );
627
- }
628
- ?>
629
- </div>
630
- <?php
631
- }
632
-
633
- /**
634
- * Display a comment count bubble
635
- *
636
- * @since 3.1.0
637
- * @access protected
638
- *
639
- * @param int $post_id The post ID.
640
- * @param int $pending_comments Number of pending comments.
641
- */
642
- protected function comments_bubble( $post_id, $pending_comments ) {
643
- $approved_comments = get_comments_number();
644
-
645
- $approved_comments_number = number_format_i18n( $approved_comments );
646
- $pending_comments_number = number_format_i18n( $pending_comments );
647
-
648
- $approved_only_phrase = sprintf( _n( '%s comment', '%s comments', $approved_comments ), $approved_comments_number );
649
- $approved_phrase = sprintf( _n( '%s approved comment', '%s approved comments', $approved_comments ), $approved_comments_number );
650
- $pending_phrase = sprintf( _n( '%s pending comment', '%s pending comments', $pending_comments ), $pending_comments_number );
651
-
652
- // No comments at all.
653
- if ( ! $approved_comments && ! $pending_comments ) {
654
- printf( '<span aria-hidden="true">—</span><span class="screen-reader-text">%s</span>',
655
- __( 'No comments' )
656
- );
657
- // Approved comments have different display depending on some conditions.
658
- } elseif ( $approved_comments ) {
659
- printf( '<a href="%s" class="post-com-count post-com-count-approved"><span class="comment-count-approved" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
660
- esc_url( add_query_arg( array( 'p' => $post_id, 'comment_status' => 'approved' ), admin_url( 'edit-comments.php' ) ) ),
661
- $approved_comments_number,
662
- $pending_comments ? $approved_phrase : $approved_only_phrase
663
- );
664
- } else {
665
- printf( '<span class="post-com-count post-com-count-no-comments"><span class="comment-count comment-count-no-comments" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
666
- $approved_comments_number,
667
- $pending_comments ? __( 'No approved comments' ) : __( 'No comments' )
668
- );
669
- }
670
-
671
- if ( $pending_comments ) {
672
- printf( '<a href="%s" class="post-com-count post-com-count-pending"><span class="comment-count-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></a>',
673
- esc_url( add_query_arg( array( 'p' => $post_id, 'comment_status' => 'moderated' ), admin_url( 'edit-comments.php' ) ) ),
674
- $pending_comments_number,
675
- $pending_phrase
676
- );
677
- } else {
678
- printf( '<span class="post-com-count post-com-count-pending post-com-count-no-pending"><span class="comment-count comment-count-no-pending" aria-hidden="true">%s</span><span class="screen-reader-text">%s</span></span>',
679
- $pending_comments_number,
680
- $approved_comments ? __( 'No pending comments' ) : __( 'No comments' )
681
- );
682
- }
683
- }
684
-
685
- /**
686
- * Get the current page number
687
- *
688
- * @since 3.1.0
689
- * @access public
690
- *
691
- * @return int
692
- */
693
- public function get_pagenum() {
694
- $pagenum = isset( $_REQUEST['paged'] ) ? absint( $_REQUEST['paged'] ) : 0;
695
-
696
- if ( isset( $this->_pagination_args['total_pages'] ) && $pagenum > $this->_pagination_args['total_pages'] )
697
- $pagenum = $this->_pagination_args['total_pages'];
698
-
699
- return max( 1, $pagenum );
700
- }
701
-
702
- /**
703
- * Get number of items to display on a single page
704
- *
705
- * @since 3.1.0
706
- * @access protected
707
- *
708
- * @param string $option
709
- * @param int $default
710
- * @return int
711
- */
712
- protected function get_items_per_page( $option, $default = 20 ) {
713
- $per_page = (int) get_user_option( $option );
714
- if ( empty( $per_page ) || $per_page < 1 )
715
- $per_page = $default;
716
-
717
- /**
718
- * Filters the number of items to be displayed on each page of the list table.
719
- *
720
- * The dynamic hook name, $option, refers to the `per_page` option depending
721
- * on the type of list table in use. Possible values include: 'edit_comments_per_page',
722
- * 'sites_network_per_page', 'site_themes_network_per_page', 'themes_network_per_page',
723
- * 'users_network_per_page', 'edit_post_per_page', 'edit_page_per_page',
724
- * 'edit_{$post_type}_per_page', etc.
725
- *
726
- * @since 2.9.0
727
- *
728
- * @param int $per_page Number of items to be displayed. Default 20.
729
- */
730
- return (int) apply_filters( $option, $per_page );
731
- }
732
-
733
- /**
734
- * Display the pagination.
735
- *
736
- * @since 3.1.0
737
- * @access protected
738
- *
739
- * @param string $which
740
- */
741
- protected function pagination( $which ) {
742
- if ( empty( $this->_pagination_args ) ) {
743
- return;
744
- }
745
-
746
- $total_items = $this->_pagination_args['total_items'];
747
- $total_pages = $this->_pagination_args['total_pages'];
748
- $infinite_scroll = false;
749
- if ( isset( $this->_pagination_args['infinite_scroll'] ) ) {
750
- $infinite_scroll = $this->_pagination_args['infinite_scroll'];
751
- }
752
-
753
- if ( 'top' === $which && $total_pages > 1 ) {
754
- $this->screen->render_screen_reader_content( 'heading_pagination' );
755
- }
756
-
757
- $output = '<span class="displaying-num">' . sprintf( _n( '%s item', '%s items', $total_items ), number_format_i18n( $total_items ) ) . '</span>';
758
-
759
- $current = $this->get_pagenum();
760
-
761
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
762
-
763
- $current_url = remove_query_arg( array( 'hotkeys_highlight_last', 'hotkeys_highlight_first' ), $current_url );
764
-
765
- $page_links = array();
766
-
767
- $total_pages_before = '<span class="paging-input">';
768
- $total_pages_after = '</span>';
769
-
770
- $disable_first = $disable_last = $disable_prev = $disable_next = false;
771
-
772
- if ( $current == 1 ) {
773
- $disable_first = true;
774
- $disable_prev = true;
775
- }
776
- if ( $current == 2 ) {
777
- $disable_first = true;
778
- }
779
- if ( $current == $total_pages ) {
780
- $disable_last = true;
781
- $disable_next = true;
782
- }
783
- if ( $current == $total_pages - 1 ) {
784
- $disable_last = true;
785
- }
786
-
787
- if ( $disable_first ) {
788
- $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&laquo;</span>';
789
- } else {
790
- $page_links[] = sprintf( "<a class='first-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
791
- esc_url( remove_query_arg( 'paged', $current_url ) ),
792
- __( 'First page' ),
793
- '&laquo;'
794
- );
795
- }
796
-
797
- if ( $disable_prev ) {
798
- $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&lsaquo;</span>';
799
- } else {
800
- $page_links[] = sprintf( "<a class='prev-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
801
- esc_url( add_query_arg( 'paged', max( 1, $current-1 ), $current_url ) ),
802
- __( 'Previous page' ),
803
- '&lsaquo;'
804
- );
805
- }
806
-
807
- if ( 'bottom' === $which ) {
808
- $html_current_page = $current;
809
- $total_pages_before = '<span class="screen-reader-text">' . __( 'Current Page' ) . '</span><span id="table-paging" class="paging-input">';
810
- } else {
811
- $html_current_page = sprintf( "%s<input class='current-page' id='current-page-selector' type='text' name='paged' value='%s' size='%d' aria-describedby='table-paging' />",
812
- '<label for="current-page-selector" class="screen-reader-text">' . __( 'Current Page' ) . '</label>',
813
- $current,
814
- strlen( $total_pages )
815
- );
816
- }
817
- $html_total_pages = sprintf( "<span class='total-pages'>%s</span>", number_format_i18n( $total_pages ) );
818
- $page_links[] = $total_pages_before . sprintf( _x( '%1$s of %2$s', 'paging' ), $html_current_page, $html_total_pages ) . $total_pages_after;
819
-
820
- if ( $disable_next ) {
821
- $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&rsaquo;</span>';
822
- } else {
823
- $page_links[] = sprintf( "<a class='next-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
824
- esc_url( add_query_arg( 'paged', min( $total_pages, $current+1 ), $current_url ) ),
825
- __( 'Next page' ),
826
- '&rsaquo;'
827
- );
828
- }
829
-
830
- if ( $disable_last ) {
831
- $page_links[] = '<span class="tablenav-pages-navspan" aria-hidden="true">&raquo;</span>';
832
- } else {
833
- $page_links[] = sprintf( "<a class='last-page' href='%s'><span class='screen-reader-text'>%s</span><span aria-hidden='true'>%s</span></a>",
834
- esc_url( add_query_arg( 'paged', $total_pages, $current_url ) ),
835
- __( 'Last page' ),
836
- '&raquo;'
837
- );
838
- }
839
-
840
- $pagination_links_class = 'pagination-links';
841
- if ( ! empty( $infinite_scroll ) ) {
842
- $pagination_links_class = ' hide-if-js';
843
- }
844
- $output .= "\n<span class='$pagination_links_class'>" . join( "\n", $page_links ) . '</span>';
845
-
846
- if ( $total_pages ) {
847
- $page_class = $total_pages < 2 ? ' one-page' : '';
848
- } else {
849
- $page_class = ' no-pages';
850
- }
851
- $this->_pagination = "<div class='tablenav-pages{$page_class}'>$output</div>";
852
-
853
- echo $this->_pagination;
854
- }
855
-
856
- /**
857
- * Get a list of columns. The format is:
858
- * 'internal-name' => 'Title'
859
- *
860
- * @since 3.1.0
861
- * @access public
862
- * @abstract
863
- *
864
- * @return array
865
- */
866
- public function get_columns() {
867
- die( 'function WP_List_Table::get_columns() must be over-ridden in a sub-class.' );
868
- }
869
-
870
- /**
871
- * Get a list of sortable columns. The format is:
872
- * 'internal-name' => 'orderby'
873
- * or
874
- * 'internal-name' => array( 'orderby', true )
875
- *
876
- * The second format will make the initial sorting order be descending
877
- *
878
- * @since 3.1.0
879
- * @access protected
880
- *
881
- * @return array
882
- */
883
- protected function get_sortable_columns() {
884
- return array();
885
- }
886
-
887
- /**
888
- * Gets the name of the default primary column.
889
- *
890
- * @since 4.3.0
891
- * @access protected
892
- *
893
- * @return string Name of the default primary column, in this case, an empty string.
894
- */
895
- protected function get_default_primary_column_name() {
896
- $columns = $this->get_columns();
897
- $column = '';
898
-
899
- if ( empty( $columns ) ) {
900
- return $column;
901
- }
902
-
903
- // We need a primary defined so responsive views show something,
904
- // so let's fall back to the first non-checkbox column.
905
- foreach ( $columns as $col => $column_name ) {
906
- if ( 'cb' === $col ) {
907
- continue;
908
- }
909
-
910
- $column = $col;
911
- break;
912
- }
913
-
914
- return $column;
915
- }
916
-
917
- /**
918
- * Public wrapper for WP_List_Table::get_default_primary_column_name().
919
- *
920
- * @since 4.4.0
921
- * @access public
922
- *
923
- * @return string Name of the default primary column.
924
- */
925
- public function get_primary_column() {
926
- return $this->get_primary_column_name();
927
- }
928
-
929
- /**
930
- * Gets the name of the primary column.
931
- *
932
- * @since 4.3.0
933
- * @access protected
934
- *
935
- * @return string The name of the primary column.
936
- */
937
- protected function get_primary_column_name() {
938
- $columns = get_column_headers( $this->screen );
939
- $default = $this->get_default_primary_column_name();
940
-
941
- // If the primary column doesn't exist fall back to the
942
- // first non-checkbox column.
943
- if ( ! isset( $columns[ $default ] ) ) {
944
- $default = WP_List_Table::get_default_primary_column_name();
945
- }
946
-
947
- /**
948
- * Filters the name of the primary column for the current list table.
949
- *
950
- * @since 4.3.0
951
- *
952
- * @param string $default Column name default for the specific list table, e.g. 'name'.
953
- * @param string $context Screen ID for specific list table, e.g. 'plugins'.
954
- */
955
- $column = apply_filters( 'list_table_primary_column', $default, $this->screen->id );
956
-
957
- if ( empty( $column ) || ! isset( $columns[ $column ] ) ) {
958
- $column = $default;
959
- }
960
-
961
- return $column;
962
- }
963
-
964
- /**
965
- * Get a list of all, hidden and sortable columns, with filter applied
966
- *
967
- * @since 3.1.0
968
- * @access protected
969
- *
970
- * @return array
971
- */
972
- protected function get_column_info() {
973
- // $_column_headers is already set / cached
974
- if ( isset( $this->_column_headers ) && is_array( $this->_column_headers ) ) {
975
- // Back-compat for list tables that have been manually setting $_column_headers for horse reasons.
976
- // In 4.3, we added a fourth argument for primary column.
977
- $column_headers = array( array(), array(), array(), $this->get_primary_column_name() );
978
- foreach ( $this->_column_headers as $key => $value ) {
979
- $column_headers[ $key ] = $value;
980
- }
981
-
982
- return $column_headers;
983
- }
984
-
985
- $columns = get_column_headers( $this->screen );
986
- $hidden = get_hidden_columns( $this->screen );
987
-
988
- $sortable_columns = $this->get_sortable_columns();
989
- /**
990
- * Filters the list table sortable columns for a specific screen.
991
- *
992
- * The dynamic portion of the hook name, `$this->screen->id`, refers
993
- * to the ID of the current screen, usually a string.
994
- *
995
- * @since 3.5.0
996
- *
997
- * @param array $sortable_columns An array of sortable columns.
998
- */
999
- $_sortable = apply_filters( "manage_{$this->screen->id}_sortable_columns", $sortable_columns );
1000
-
1001
- $sortable = array();
1002
- foreach ( $_sortable as $id => $data ) {
1003
- if ( empty( $data ) )
1004
- continue;
1005
-
1006
- $data = (array) $data;
1007
- if ( !isset( $data[1] ) )
1008
- $data[1] = false;
1009
-
1010
- $sortable[$id] = $data;
1011
- }
1012
-
1013
- $primary = $this->get_primary_column_name();
1014
- $this->_column_headers = array( $columns, $hidden, $sortable, $primary );
1015
-
1016
- return $this->_column_headers;
1017
- }
1018
-
1019
- /**
1020
- * Return number of visible columns
1021
- *
1022
- * @since 3.1.0
1023
- * @access public
1024
- *
1025
- * @return int
1026
- */
1027
- public function get_column_count() {
1028
- list ( $columns, $hidden ) = $this->get_column_info();
1029
- $hidden = array_intersect( array_keys( $columns ), array_filter( $hidden ) );
1030
- return count( $columns ) - count( $hidden );
1031
- }
1032
-
1033
- /**
1034
- * Print column headers, accounting for hidden and sortable columns.
1035
- *
1036
- * @since 3.1.0
1037
- * @access public
1038
- *
1039
- * @staticvar int $cb_counter
1040
- *
1041
- * @param bool $with_id Whether to set the id attribute or not
1042
- */
1043
- public function print_column_headers( $with_id = true ) {
1044
- list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
1045
-
1046
- $current_url = set_url_scheme( 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] );
1047
- $current_url = remove_query_arg( 'paged', $current_url );
1048
-
1049
- if ( isset( $_GET['orderby'] ) ) {
1050
- $current_orderby = $_GET['orderby'];
1051
- } else {
1052
- $current_orderby = '';
1053
- }
1054
-
1055
- if ( isset( $_GET['order'] ) && 'desc' === $_GET['order'] ) {
1056
- $current_order = 'desc';
1057
- } else {
1058
- $current_order = 'asc';
1059
- }
1060
-
1061
- if ( ! empty( $columns['cb'] ) ) {
1062
- static $cb_counter = 1;
1063
- $columns['cb'] = '<label class="screen-reader-text" for="cb-select-all-' . $cb_counter . '">' . __( 'Select All' ) . '</label>'
1064
- . '<input id="cb-select-all-' . $cb_counter . '" type="checkbox" />';
1065
- $cb_counter++;
1066
- }
1067
-
1068
- foreach ( $columns as $column_key => $column_display_name ) {
1069
- $class = array( 'manage-column', "column-$column_key" );
1070
-
1071
- if ( in_array( $column_key, $hidden ) ) {
1072
- $class[] = 'hidden';
1073
- }
1074
-
1075
- if ( 'cb' === $column_key )
1076
- $class[] = 'check-column';
1077
- elseif ( in_array( $column_key, array( 'posts', 'comments', 'links' ) ) )
1078
- $class[] = 'num';
1079
-
1080
- if ( $column_key === $primary ) {
1081
- $class[] = 'column-primary';
1082
- }
1083
-
1084
- if ( isset( $sortable[$column_key] ) ) {
1085
- list( $orderby, $desc_first ) = $sortable[$column_key];
1086
-
1087
- if ( $current_orderby === $orderby ) {
1088
- $order = 'asc' === $current_order ? 'desc' : 'asc';
1089
- $class[] = 'sorted';
1090
- $class[] = $current_order;
1091
- } else {
1092
- $order = $desc_first ? 'desc' : 'asc';
1093
- $class[] = 'sortable';
1094
- $class[] = $desc_first ? 'asc' : 'desc';
1095
- }
1096
-
1097
- $column_display_name = '<a href="' . esc_url( add_query_arg( compact( 'orderby', 'order' ), $current_url ) ) . '"><span>' . $column_display_name . '</span><span class="sorting-indicator"></span></a>';
1098
- }
1099
-
1100
- $tag = ( 'cb' === $column_key ) ? 'td' : 'th';
1101
- $scope = ( 'th' === $tag ) ? 'scope="col"' : '';
1102
- $id = $with_id ? "id='$column_key'" : '';
1103
-
1104
- if ( !empty( $class ) )
1105
- $class = "class='" . join( ' ', $class ) . "'";
1106
-
1107
- echo "<$tag $scope $id $class>$column_display_name</$tag>";
1108
- }
1109
- }
1110
-
1111
- /**
1112
- * Display the table
1113
- *
1114
- * @since 3.1.0
1115
- * @access public
1116
- */
1117
- public function display() {
1118
- $singular = $this->_args['singular'];
1119
-
1120
- $this->display_tablenav( 'top' );
1121
-
1122
- $this->screen->render_screen_reader_content( 'heading_list' );
1123
- ?>
1124
- <table class="wp-list-table <?php echo implode( ' ', $this->get_table_classes() ); ?>">
1125
- <thead>
1126
- <tr>
1127
- <?php $this->print_column_headers(); ?>
1128
- </tr>
1129
- </thead>
1130
-
1131
- <tbody id="the-list"<?php
1132
- if ( $singular ) {
1133
- echo " data-wp-lists='list:$singular'";
1134
- } ?>>
1135
- <?php $this->display_rows_or_placeholder(); ?>
1136
- </tbody>
1137
-
1138
- <tfoot>
1139
- <tr>
1140
- <?php $this->print_column_headers( false ); ?>
1141
- </tr>
1142
- </tfoot>
1143
-
1144
- </table>
1145
- <?php
1146
- $this->display_tablenav( 'bottom' );
1147
- }
1148
-
1149
- /**
1150
- * Get a list of CSS classes for the WP_List_Table table tag.
1151
- *
1152
- * @since 3.1.0
1153
- * @access protected
1154
- *
1155
- * @return array List of CSS classes for the table tag.
1156
- */
1157
- protected function get_table_classes() {
1158
- return array( 'widefat', 'fixed', 'striped', $this->_args['plural'] );
1159
- }
1160
-
1161
- /**
1162
- * Generate the table navigation above or below the table
1163
- *
1164
- * @since 3.1.0
1165
- * @access protected
1166
- * @param string $which
1167
- */
1168
- protected function display_tablenav( $which ) {
1169
- if ( 'top' === $which ) {
1170
- wp_nonce_field( 'bulk-' . $this->_args['plural'] );
1171
- }
1172
- ?>
1173
- <div class="tablenav <?php echo esc_attr( $which ); ?>">
1174
-
1175
- <?php if ( $this->has_items() ): ?>
1176
- <div class="alignleft actions bulkactions">
1177
- <?php $this->bulk_actions( $which ); ?>
1178
- </div>
1179
- <?php endif;
1180
- $this->extra_tablenav( $which );
1181
- $this->pagination( $which );
1182
- ?>
1183
-
1184
- <br class="clear" />
1185
- </div>
1186
- <?php
1187
- }
1188
-
1189
- /**
1190
- * Extra controls to be displayed between bulk actions and pagination
1191
- *
1192
- * @since 3.1.0
1193
- * @access protected
1194
- *
1195
- * @param string $which
1196
- */
1197
- protected function extra_tablenav( $which ) {}
1198
-
1199
- /**
1200
- * Generate the tbody element for the list table.
1201
- *
1202
- * @since 3.1.0
1203
- * @access public
1204
- */
1205
- public function display_rows_or_placeholder() {
1206
- if ( $this->has_items() ) {
1207
- $this->display_rows();
1208
- } else {
1209
- echo '<tr class="no-items"><td class="colspanchange" colspan="' . $this->get_column_count() . '">';
1210
- $this->no_items();
1211
- echo '</td></tr>';
1212
- }
1213
- }
1214
-
1215
- /**
1216
- * Generate the table rows
1217
- *
1218
- * @since 3.1.0
1219
- * @access public
1220
- */
1221
- public function display_rows() {
1222
- foreach ( $this->items as $item )
1223
- $this->single_row( $item );
1224
- }
1225
-
1226
- /**
1227
- * Generates content for a single row of the table
1228
- *
1229
- * @since 3.1.0
1230
- * @access public
1231
- *
1232
- * @param object $item The current item
1233
- */
1234
- public function single_row( $item ) {
1235
- echo '<tr>';
1236
- $this->single_row_columns( $item );
1237
- echo '</tr>';
1238
- }
1239
-
1240
- /**
1241
- *
1242
- * @param object $item
1243
- * @param string $column_name
1244
- */
1245
- protected function column_default( $item, $column_name ) {}
1246
-
1247
- /**
1248
- *
1249
- * @param object $item
1250
- */
1251
- protected function column_cb( $item ) {}
1252
-
1253
- /**
1254
- * Generates the columns for a single row of the table
1255
- *
1256
- * @since 3.1.0
1257
- * @access protected
1258
- *
1259
- * @param object $item The current item
1260
- */
1261
- protected function single_row_columns( $item ) {
1262
- list( $columns, $hidden, $sortable, $primary ) = $this->get_column_info();
1263
-
1264
- foreach ( $columns as $column_name => $column_display_name ) {
1265
- $classes = "$column_name column-$column_name";
1266
- if ( $primary === $column_name ) {
1267
- $classes .= ' has-row-actions column-primary';
1268
- }
1269
-
1270
- if ( in_array( $column_name, $hidden ) ) {
1271
- $classes .= ' hidden';
1272
- }
1273
-
1274
- // Comments column uses HTML in the display name with screen reader text.
1275
- // Instead of using esc_attr(), we strip tags to get closer to a user-friendly string.
1276
- $data = 'data-colname="' . wp_strip_all_tags( $column_display_name ) . '"';
1277
-
1278
- $attributes = "class='$classes' $data";
1279
-
1280
- if ( 'cb' === $column_name ) {
1281
- echo '<th scope="row" class="check-column">';
1282
- echo $this->column_cb( $item );
1283
- echo '</th>';
1284
- } elseif ( method_exists( $this, '_column_' . $column_name ) ) {
1285
- echo call_user_func(
1286
- array( $this, '_column_' . $column_name ),
1287
- $item,
1288
- $classes,
1289
- $data,
1290
- $primary
1291
- );
1292
- } elseif ( method_exists( $this, 'column_' . $column_name ) ) {
1293
- echo "<td $attributes>";
1294
- echo call_user_func( array( $this, 'column_' . $column_name ), $item );
1295
- echo $this->handle_row_actions( $item, $column_name, $primary );
1296
- echo "</td>";
1297
- } else {
1298
- echo "<td $attributes>";
1299
- echo $this->column_default( $item, $column_name );
1300
- echo $this->handle_row_actions( $item, $column_name, $primary );
1301
- echo "</td>";
1302
- }
1303
- }
1304
- }
1305
-
1306
- /**
1307
- * Generates and display row actions links for the list table.
1308
- *
1309
- * @since 4.3.0
1310
- * @access protected
1311
- *
1312
- * @param object $item The item being acted upon.
1313
- * @param string $column_name Current column name.
1314
- * @param string $primary Primary column name.
1315
- * @return string The row actions HTML, or an empty string if the current column is the primary column.
1316
- */
1317
- protected function handle_row_actions( $item, $column_name, $primary ) {
1318
- return $column_name === $primary ? '<button type="button" class="toggle-row"><span class="screen-reader-text">' . __( 'Show more details' ) . '</span></button>' : '';
1319
- }
1320
-
1321
- /**
1322
- * Handle an incoming ajax request (called from admin-ajax.php)
1323
- *
1324
- * @since 3.1.0
1325
- * @access public
1326
- */
1327
- public function ajax_response() {
1328
- $this->prepare_items();
1329
-
1330
- ob_start();
1331
- if ( ! empty( $_REQUEST['no_placeholder'] ) ) {
1332
- $this->display_rows();
1333
- } else {
1334
- $this->display_rows_or_placeholder();
1335
- }
1336
-
1337
- $rows = ob_get_clean();
1338
-
1339
- $response = array( 'rows' => $rows );
1340
-
1341
- if ( isset( $this->_pagination_args['total_items'] ) ) {
1342
- $response['total_items_i18n'] = sprintf(
1343
- _n( '%s item', '%s items', $this->_pagination_args['total_items'] ),
1344
- number_format_i18n( $this->_pagination_args['total_items'] )
1345
- );
1346
- }
1347
- if ( isset( $this->_pagination_args['total_pages'] ) ) {
1348
- $response['total_pages'] = $this->_pagination_args['total_pages'];
1349
- $response['total_pages_i18n'] = number_format_i18n( $this->_pagination_args['total_pages'] );
1350
- }
1351
-
1352
- die( wp_json_encode( $response ) );
1353
- }
1354
-
1355
- /**
1356
- * Send required variables to JavaScript land
1357
- *
1358
- * @access public
1359
- */
1360
- public function _js_vars() {
1361
- $args = array(
1362
- 'class' => get_class( $this ),
1363
- 'screen' => array(
1364
- 'id' => $this->screen->id,
1365
- 'base' => $this->screen->base,
1366
- )
1367
- );
1368
-
1369
- printf( "<script type='text/javascript'>list_args = %s;</script>\n", wp_json_encode( $args ) );
1370
- }
1371
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inc/permalink-manager-helper-functions.php CHANGED
@@ -143,8 +143,6 @@ class Permalink_Manager_Helper_Functions extends Permalink_Manager_Class {
143
  // The snippet belows prevent duplicates in permastructures
144
  if($field == 'base-editor') {
145
 
146
- //print_r($value);
147
-
148
  // Algorithm below works like array_count_values(), but we also need to make the permastructs unique
149
  $unique_permastructures = array();
150
  foreach($value as $key => $permastruct) {
143
  // The snippet belows prevent duplicates in permastructures
144
  if($field == 'base-editor') {
145
 
 
 
146
  // Algorithm below works like array_count_values(), but we also need to make the permastructs unique
147
  $unique_permastructures = array();
148
  foreach($value as $key => $permastruct) {
permalink-manager.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Permalink Manager
5
  * Plugin URI: http://maciejbis.net/
6
  * Description: A simple tool that allows to mass update of slugs that are used to build permalinks for Posts, Pages and Custom Post Types.
7
- * Version: 0.3.3
8
  * Author: Maciej Bis
9
  * Author URI: http://maciejbis.net/
10
  * License: GPL-2.0+
@@ -20,7 +20,7 @@ if ( ! defined( 'WPINC' ) ) {
20
 
21
  // Define the directories used to load plugin files.
22
  define( 'PERMALINK_MANAGER_PLUGIN_NAME', 'permalink-manager' );
23
- define( 'PERMALINK_MANAGER_VERSION', '0.3.3' );
24
  define( 'PERMALINK_MANAGER_DIR', untrailingslashit( dirname( __FILE__ ) ) );
25
  define( 'PERMALINK_MANAGER_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) );
26
  define( 'PERMALINK_MANAGER_WEBSITE', 'http://maciejbis.net' );
@@ -141,11 +141,6 @@ class Permalink_Manager_Class {
141
  $Permalink_Manager_Base_Editor = new Permalink_Manager_Base_Editor();
142
  $Permalink_Manager_Base_Editor->set_screen_option_fields($this->fields_arrays('screen_options'));
143
  $Permalink_Manager_Base_Editor->prepare_items($wpdb->posts);
144
-
145
- //echo '<pre>';
146
- //print_r($wp_rewrite);
147
- //echo '</pre>';
148
-
149
  ?>
150
 
151
  <form id="permalinks-base-table" method="post">
@@ -531,6 +526,8 @@ class Permalink_Manager_Class {
531
  * Change permalinks for posts, pages & custom post types
532
  */
533
  function custom_permalinks($permalink, $post) {
 
 
534
  $post = (is_integer($post)) ? get_post($post) : $post;
535
  $post_type = $post->post_type;
536
  $permastruct = isset($this->permalink_manager_options['base-editor'][$post_type]) ? $this->permalink_manager_options['base-editor'][$post_type] : '';
@@ -583,8 +580,22 @@ class Permalink_Manager_Class {
583
  // Do the replacement (post tag is removed now to enable support for hierarchical CPT)
584
  $tags = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', '%post_id%', '%category%', '%author%', $post_type_tag);
585
  $replacements = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->ID, $category, $author, '');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
586
 
587
- return str_replace($tags, $replacements, "{$permalink}{$full_slug}");
588
  }
589
 
590
  /**
@@ -604,8 +615,34 @@ class Permalink_Manager_Class {
604
  // Ignore empty permastructures (do not add them)
605
  if(empty($permastruct)) continue;
606
 
607
- $new_rule = $wp_rewrite->generate_rewrite_rules($wp_rewrite->root . $permastruct, EP_PERMALINK);
608
- $rules = array_merge($new_rule, $rules);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
609
  }
610
  return $rules;
611
  }
4
  * Plugin Name: Permalink Manager
5
  * Plugin URI: http://maciejbis.net/
6
  * Description: A simple tool that allows to mass update of slugs that are used to build permalinks for Posts, Pages and Custom Post Types.
7
+ * Version: 0.3.4
8
  * Author: Maciej Bis
9
  * Author URI: http://maciejbis.net/
10
  * License: GPL-2.0+
20
 
21
  // Define the directories used to load plugin files.
22
  define( 'PERMALINK_MANAGER_PLUGIN_NAME', 'permalink-manager' );
23
+ define( 'PERMALINK_MANAGER_VERSION', '0.3.4' );
24
  define( 'PERMALINK_MANAGER_DIR', untrailingslashit( dirname( __FILE__ ) ) );
25
  define( 'PERMALINK_MANAGER_URL', untrailingslashit( plugins_url( '', __FILE__ ) ) );
26
  define( 'PERMALINK_MANAGER_WEBSITE', 'http://maciejbis.net' );
141
  $Permalink_Manager_Base_Editor = new Permalink_Manager_Base_Editor();
142
  $Permalink_Manager_Base_Editor->set_screen_option_fields($this->fields_arrays('screen_options'));
143
  $Permalink_Manager_Base_Editor->prepare_items($wpdb->posts);
 
 
 
 
 
144
  ?>
145
 
146
  <form id="permalinks-base-table" method="post">
526
  * Change permalinks for posts, pages & custom post types
527
  */
528
  function custom_permalinks($permalink, $post) {
529
+ global $wp_rewrite;
530
+
531
  $post = (is_integer($post)) ? get_post($post) : $post;
532
  $post_type = $post->post_type;
533
  $permastruct = isset($this->permalink_manager_options['base-editor'][$post_type]) ? $this->permalink_manager_options['base-editor'][$post_type] : '';
580
  // Do the replacement (post tag is removed now to enable support for hierarchical CPT)
581
  $tags = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', '%post_id%', '%category%', '%author%', $post_type_tag);
582
  $replacements = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->ID, $category, $author, '');
583
+ $permalink = str_replace($tags, $replacements, "{$permalink}{$full_slug}");
584
+
585
+ // Replace custom taxonomies
586
+ $taxonomies = get_taxonomies( array('public' => true, '_builtin' => false), 'names', 'and' );
587
+ if ( $taxonomies ) {
588
+ foreach($taxonomies as $taxonomy) {
589
+ $tag = "%{$taxonomy}%";
590
+ $terms = wp_get_object_terms($post->ID, $taxonomy);
591
+ if (!is_wp_error($terms) && !empty($terms) && is_object($terms[0])) {
592
+ $replacement = $terms[0]->slug;
593
+ $permalink = str_replace($tag, $replacement, $permalink);
594
+ }
595
+ }
596
+ }
597
 
598
+ return $permalink;
599
  }
600
 
601
  /**
615
  // Ignore empty permastructures (do not add them)
616
  if(empty($permastruct)) continue;
617
 
618
+ $new_rules = $wp_rewrite->generate_rewrite_rules($wp_rewrite->root . $permastruct, EP_PERMALINK);
619
+
620
+ // Replace old rewrite rules with new ones
621
+ $cpt = get_post_type_object( $post_type );
622
+ if(isset($cpt->rewrite['slug'])) {
623
+ $rules_to_be_replaced = $wp_rewrite->generate_rewrite_rules($wp_rewrite->root . $cpt->rewrite['slug'] . "/%{$post_type}%", EP_NONE);
624
+ $rules_to_be_replaced_keys = array_keys($rules_to_be_replaced);
625
+
626
+ $split_before = reset($rules_to_be_replaced_keys);
627
+ $split_after = end($rules_to_be_replaced_keys);
628
+
629
+ $split_before_pos = array_search($split_before, array_keys($rules));
630
+ $split_after_pos = array_search($split_after, array_keys($rules)) + 1;
631
+
632
+ $rules_before = array_slice($rules, 0, $split_before_pos, true);
633
+ $rules_inside = array_slice($rules, $split_before_pos, ($split_after_pos - $split_before_pos), true);
634
+ $rules_after = array_slice($rules, $split_after_pos, null, true);
635
+
636
+ // $rules = $rules_before + $new_rules + $rules_inside + $rules_after;
637
+ /**
638
+ * Uncomment above if you would like to keep all original rewrite rules
639
+ */
640
+ $rules = $rules_before + $new_rules + $rules_after;
641
+
642
+ } else {
643
+ $rules = array_merge($rules, $new_rules);
644
+ }
645
+
646
  }
647
  return $rules;
648
  }