~canonical-sysadmins/wordpress/5.1

« back to all changes in this revision

Viewing changes to wp-admin/includes/class-wp-terms-list-table.php

  • Committer: Barry Price
  • Date: 2019-02-22 03:51:26 UTC
  • mfrom: (1.2.12 upstream)
  • Revision ID: barry.price@canonical.com-20190222035126-o28k38qs8jfyjsxt
Merge WP5.1 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
        public function __construct( $args = array() ) {
39
39
                global $post_type, $taxonomy, $action, $tax;
40
40
 
41
 
                parent::__construct( array(
42
 
                        'plural' => 'tags',
43
 
                        'singular' => 'tag',
44
 
                        'screen' => isset( $args['screen'] ) ? $args['screen'] : null,
45
 
                ) );
 
41
                parent::__construct(
 
42
                        array(
 
43
                                'plural'   => 'tags',
 
44
                                'singular' => 'tag',
 
45
                                'screen'   => isset( $args['screen'] ) ? $args['screen'] : null,
 
46
                        )
 
47
                );
46
48
 
47
49
                $action    = $this->screen->action;
48
50
                $post_type = $this->screen->post_type;
49
51
                $taxonomy  = $this->screen->taxonomy;
50
52
 
51
 
                if ( empty( $taxonomy ) )
 
53
                if ( empty( $taxonomy ) ) {
52
54
                        $taxonomy = 'post_tag';
 
55
                }
53
56
 
54
 
                if ( ! taxonomy_exists( $taxonomy ) )
 
57
                if ( ! taxonomy_exists( $taxonomy ) ) {
55
58
                        wp_die( __( 'Invalid taxonomy.' ) );
 
59
                }
56
60
 
57
61
                $tax = get_taxonomy( $taxonomy );
58
62
 
59
63
                // @todo Still needed? Maybe just the show_ui part.
60
 
                if ( empty( $post_type ) || !in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) )
 
64
                if ( empty( $post_type ) || ! in_array( $post_type, get_post_types( array( 'show_ui' => true ) ) ) ) {
61
65
                        $post_type = 'post';
 
66
                }
62
67
 
63
68
        }
64
69
 
65
70
        /**
66
 
         *
67
71
         * @return bool
68
72
         */
69
73
        public function ajax_user_can() {
105
109
                        $tags_per_page = apply_filters( 'edit_categories_per_page', $tags_per_page );
106
110
                }
107
111
 
108
 
                $search = !empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : '';
 
112
                $search = ! empty( $_REQUEST['s'] ) ? trim( wp_unslash( $_REQUEST['s'] ) ) : '';
109
113
 
110
114
                $args = array(
111
115
                        'search' => $search,
112
 
                        'page' => $this->get_pagenum(),
 
116
                        'page'   => $this->get_pagenum(),
113
117
                        'number' => $tags_per_page,
114
118
                );
115
119
 
116
 
                if ( !empty( $_REQUEST['orderby'] ) )
 
120
                if ( ! empty( $_REQUEST['orderby'] ) ) {
117
121
                        $args['orderby'] = trim( wp_unslash( $_REQUEST['orderby'] ) );
 
122
                }
118
123
 
119
 
                if ( !empty( $_REQUEST['order'] ) )
 
124
                if ( ! empty( $_REQUEST['order'] ) ) {
120
125
                        $args['order'] = trim( wp_unslash( $_REQUEST['order'] ) );
 
126
                }
121
127
 
122
128
                $this->callback_args = $args;
123
129
 
124
 
                $this->set_pagination_args( array(
125
 
                        'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ),
126
 
                        'per_page' => $tags_per_page,
127
 
                ) );
 
130
                $this->set_pagination_args(
 
131
                        array(
 
132
                                'total_items' => wp_count_terms( $this->screen->taxonomy, compact( 'search' ) ),
 
133
                                'per_page'    => $tags_per_page,
 
134
                        )
 
135
                );
128
136
        }
129
137
 
130
138
        /**
131
 
         *
132
139
         * @return bool
133
140
         */
134
141
        public function has_items() {
143
150
        }
144
151
 
145
152
        /**
146
 
         *
147
153
         * @return array
148
154
         */
149
155
        protected function get_bulk_actions() {
157
163
        }
158
164
 
159
165
        /**
160
 
         *
161
166
         * @return string
162
167
         */
163
168
        public function current_action() {
164
 
                if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' === $_REQUEST['action'] || 'delete' === $_REQUEST['action2'] ) )
 
169
                if ( isset( $_REQUEST['action'] ) && isset( $_REQUEST['delete_tags'] ) && ( 'delete' === $_REQUEST['action'] || 'delete' === $_REQUEST['action2'] ) ) {
165
170
                        return 'bulk-delete';
 
171
                }
166
172
 
167
173
                return parent::current_action();
168
174
        }
169
175
 
170
176
        /**
171
 
         *
172
177
         * @return array
173
178
         */
174
179
        public function get_columns() {
189
194
        }
190
195
 
191
196
        /**
192
 
         *
193
197
         * @return array
194
198
         */
195
199
        protected function get_sortable_columns() {
198
202
                        'description' => 'description',
199
203
                        'slug'        => 'slug',
200
204
                        'posts'       => 'count',
201
 
                        'links'       => 'count'
 
205
                        'links'       => 'count',
202
206
                );
203
207
        }
204
208
 
207
211
        public function display_rows_or_placeholder() {
208
212
                $taxonomy = $this->screen->taxonomy;
209
213
 
210
 
                $args = wp_parse_args( $this->callback_args, array(
211
 
                        'page' => 1,
212
 
                        'number' => 20,
213
 
                        'search' => '',
214
 
                        'hide_empty' => 0
215
 
                ) );
 
214
                $args = wp_parse_args(
 
215
                        $this->callback_args,
 
216
                        array(
 
217
                                'page'       => 1,
 
218
                                'number'     => 20,
 
219
                                'search'     => '',
 
220
                                'hide_empty' => 0,
 
221
                        )
 
222
                );
216
223
 
217
224
                $page = $args['page'];
218
225
 
268
275
 
269
276
                foreach ( $terms as $key => $term ) {
270
277
 
271
 
                        if ( $count >= $end )
 
278
                        if ( $count >= $end ) {
272
279
                                break;
 
280
                        }
273
281
 
274
 
                        if ( $term->parent != $parent && empty( $_REQUEST['s'] ) )
 
282
                        if ( $term->parent != $parent && empty( $_REQUEST['s'] ) ) {
275
283
                                continue;
 
284
                        }
276
285
 
277
286
                        // If the page starts in a subtree, print the parents.
278
287
                        if ( $count == $start && $term->parent > 0 && empty( $_REQUEST['s'] ) ) {
279
288
                                $my_parents = $parent_ids = array();
280
 
                                $p = $term->parent;
 
289
                                $p          = $term->parent;
281
290
                                while ( $p ) {
282
 
                                        $my_parent = get_term( $p, $taxonomy );
 
291
                                        $my_parent    = get_term( $p, $taxonomy );
283
292
                                        $my_parents[] = $my_parent;
284
 
                                        $p = $my_parent->parent;
285
 
                                        if ( in_array( $p, $parent_ids ) ) // Prevent parent loops.
 
293
                                        $p            = $my_parent->parent;
 
294
                                        if ( in_array( $p, $parent_ids ) ) { // Prevent parent loops.
286
295
                                                break;
 
296
                                        }
287
297
                                        $parent_ids[] = $p;
288
298
                                }
289
299
                                unset( $parent_ids );
303
313
 
304
314
                        ++$count;
305
315
 
306
 
                        unset( $terms[$key] );
 
316
                        unset( $terms[ $key ] );
307
317
 
308
 
                        if ( isset( $children[$term->term_id] ) && empty( $_REQUEST['s'] ) )
 
318
                        if ( isset( $children[ $term->term_id ] ) && empty( $_REQUEST['s'] ) ) {
309
319
                                $this->_rows( $taxonomy, $terms, $children, $start, $per_page, $count, $term->term_id, $level + 1 );
 
320
                        }
310
321
                }
311
322
        }
312
323
 
317
328
         */
318
329
        public function single_row( $tag, $level = 0 ) {
319
330
                global $taxonomy;
320
 
                $tag = sanitize_term( $tag, $taxonomy );
 
331
                $tag = sanitize_term( $tag, $taxonomy );
321
332
 
322
333
                $this->level = $level;
323
334
 
367
378
 
368
379
                $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
369
380
 
370
 
                $edit_link = add_query_arg(
371
 
                        'wp_http_referer',
372
 
                        urlencode( wp_unslash( $uri ) ),
373
 
                        get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type )
374
 
                );
 
381
                $edit_link = get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type );
 
382
 
 
383
                if ( $edit_link ) {
 
384
                        $edit_link = add_query_arg(
 
385
                                'wp_http_referer',
 
386
                                urlencode( wp_unslash( $uri ) ),
 
387
                                $edit_link
 
388
                        );
 
389
                        $name      = sprintf(
 
390
                                '<a class="row-title" href="%s" aria-label="%s">%s</a>',
 
391
                                esc_url( $edit_link ),
 
392
                                /* translators: %s: taxonomy term name */
 
393
                                esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $tag->name ) ),
 
394
                                $name
 
395
                        );
 
396
                }
375
397
 
376
398
                $out = sprintf(
377
 
                        '<strong><a class="row-title" href="%s" aria-label="%s">%s</a></strong><br />',
378
 
                        esc_url( $edit_link ),
379
 
                        /* translators: %s: taxonomy term name */
380
 
                        esc_attr( sprintf( __( '&#8220;%s&#8221; (Edit)' ), $tag->name ) ),
 
399
                        '<strong>%s</strong><br />',
381
400
                        $name
382
401
                );
383
402
 
418
437
                }
419
438
 
420
439
                $taxonomy = $this->screen->taxonomy;
421
 
                $tax = get_taxonomy( $taxonomy );
422
 
                $uri = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
 
440
                $tax      = get_taxonomy( $taxonomy );
 
441
                $uri      = wp_doing_ajax() ? wp_get_referer() : $_SERVER['REQUEST_URI'];
423
442
 
424
443
                $edit_link = add_query_arg(
425
444
                        'wp_http_referer',
437
456
                                __( 'Edit' )
438
457
                        );
439
458
                        $actions['inline hide-if-no-js'] = sprintf(
440
 
                                '<a href="#" class="editinline aria-button-if-js" aria-label="%s">%s</a>',
 
459
                                '<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>',
441
460
                                /* translators: %s: taxonomy term name */
442
461
                                esc_attr( sprintf( __( 'Quick edit &#8220;%s&#8221; inline' ), $tag->name ) ),
443
462
                                __( 'Quick&nbsp;Edit' )
452
471
                                __( 'Delete' )
453
472
                        );
454
473
                }
455
 
                if ( $tax->public ) {
 
474
                if ( is_taxonomy_viewable( $tax ) ) {
456
475
                        $actions['view'] = sprintf(
457
476
                                '<a href="%s" aria-label="%s">%s</a>',
458
477
                                get_term_link( $tag ),
468
487
                 * @since 2.8.0
469
488
                 * @deprecated 3.0.0 Use {$taxonomy}_row_actions instead.
470
489
                 *
471
 
                 * @param array  $actions An array of action links to be displayed. Default
472
 
                 *                        'Edit', 'Quick Edit', 'Delete', and 'View'.
473
 
                 * @param WP_Term $tag    Term object.
 
490
                 * @param string[] $actions An array of action links to be displayed. Default
 
491
                 *                          'Edit', 'Quick Edit', 'Delete', and 'View'.
 
492
                 * @param WP_Term  $tag     Term object.
474
493
                 */
475
494
                $actions = apply_filters( 'tag_row_actions', $actions, $tag );
476
495
 
481
500
                 *
482
501
                 * @since 3.0.0
483
502
                 *
484
 
                 * @param array  $actions An array of action links to be displayed. Default
485
 
                 *                        'Edit', 'Quick Edit', 'Delete', and 'View'.
486
 
                 * @param WP_Term $tag    Term object.
 
503
                 * @param string[] $actions An array of action links to be displayed. Default
 
504
                 *                          'Edit', 'Quick Edit', 'Delete', and 'View'.
 
505
                 * @param WP_Term  $tag     Term object.
487
506
                 */
488
507
                $actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag );
489
508
 
521
540
                $tax = get_taxonomy( $this->screen->taxonomy );
522
541
 
523
542
                $ptype_object = get_post_type_object( $this->screen->post_type );
524
 
                if ( ! $ptype_object->show_ui )
 
543
                if ( ! $ptype_object->show_ui ) {
525
544
                        return $count;
 
545
                }
526
546
 
527
547
                if ( $tax->query_var ) {
528
548
                        $args = array( $tax->query_var => $tag->slug );
529
549
                } else {
530
 
                        $args = array( 'taxonomy' => $tax->name, 'term' => $tag->slug );
 
550
                        $args = array(
 
551
                                'taxonomy' => $tax->name,
 
552
                                'term'     => $tag->slug,
 
553
                        );
531
554
                }
532
555
 
533
 
                if ( 'post' != $this->screen->post_type )
 
556
                if ( 'post' != $this->screen->post_type ) {
534
557
                        $args['post_type'] = $this->screen->post_type;
535
 
 
536
 
                if ( 'attachment' === $this->screen->post_type )
537
 
                        return "<a href='" . esc_url ( add_query_arg( $args, 'upload.php' ) ) . "'>$count</a>";
538
 
 
539
 
                return "<a href='" . esc_url ( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>";
 
558
                }
 
559
 
 
560
                if ( 'attachment' === $this->screen->post_type ) {
 
561
                        return "<a href='" . esc_url( add_query_arg( $args, 'upload.php' ) ) . "'>$count</a>";
 
562
                }
 
563
 
 
564
                return "<a href='" . esc_url( add_query_arg( $args, 'edit.php' ) ) . "'>$count</a>";
540
565
        }
541
566
 
542
567
        /**
545
570
         */
546
571
        public function column_links( $tag ) {
547
572
                $count = number_format_i18n( $tag->count );
548
 
                if ( $count )
 
573
                if ( $count ) {
549
574
                        $count = "<a href='link-manager.php?cat_id=$tag->term_id'>$count</a>";
 
575
                }
550
576
                return $count;
551
577
        }
552
578
 
579
605
        public function inline_edit() {
580
606
                $tax = get_taxonomy( $this->screen->taxonomy );
581
607
 
582
 
                if ( ! current_user_can( $tax->cap->edit_terms ) )
 
608
                if ( ! current_user_can( $tax->cap->edit_terms ) ) {
583
609
                        return;
584
 
?>
 
610
                }
 
611
                ?>
585
612
 
586
613
        <form method="get"><table style="display: none"><tbody id="inlineedit">
587
614
                <tr id="inline-edit" class="inline-edit-row" style="display: none"><td colspan="<?php echo $this->get_column_count(); ?>" class="colspanchange">
593
620
                                        <span class="title"><?php _ex( 'Name', 'term name' ); ?></span>
594
621
                                        <span class="input-text-wrap"><input type="text" name="name" class="ptitle" value="" /></span>
595
622
                                </label>
596
 
        <?php if ( !global_terms_enabled() ) { ?>
 
623
                <?php if ( ! global_terms_enabled() ) { ?>
597
624
                                <label>
598
625
                                        <span class="title"><?php _e( 'Slug' ); ?></span>
599
626
                                        <span class="input-text-wrap"><input type="text" name="slug" class="ptitle" value="" /></span>
600
627
                                </label>
601
628
        <?php } ?>
602
629
                        </div></fieldset>
603
 
        <?php
 
630
                <?php
604
631
 
605
 
                $core_columns = array( 'cb' => true, 'description' => true, 'name' => true, 'slug' => true, 'posts' => true );
 
632
                $core_columns = array(
 
633
                        'cb'          => true,
 
634
                        'description' => true,
 
635
                        'name'        => true,
 
636
                        'slug'        => true,
 
637
                        'posts'       => true,
 
638
                );
606
639
 
607
640
                list( $columns ) = $this->get_column_info();
608
641
 
609
642
                foreach ( $columns as $column_name => $column_display_name ) {
610
 
                        if ( isset( $core_columns[$column_name] ) )
 
643
                        if ( isset( $core_columns[ $column_name ] ) ) {
611
644
                                continue;
 
645
                        }
612
646
 
613
647
                        /** This action is documented in wp-admin/includes/class-wp-posts-list-table.php */
614
648
                        do_action( 'quick_edit_custom_box', $column_name, 'edit-tags', $this->screen->taxonomy );
615
649
                }
616
650
 
617
 
        ?>
 
651
                ?>
618
652
 
619
653
                <div class="inline-edit-save submit">
620
654
                        <button type="button" class="cancel button alignleft"><?php _e( 'Cancel' ); ?></button>
630
664
                </div>
631
665
                </td></tr>
632
666
                </tbody></table></form>
633
 
        <?php
 
667
                <?php
634
668
        }
635
669
}