Make WordPress Core


Ignore:
Timestamp:
05/29/2015 02:40:52 AM (11 years ago)
Author:
helen
Message:

List tables: introduce the concept of a "primary" column.

This becomes the column that contains the row actions, and allows for a more flexibility, particularly with custom post types and list tables. To (re)define the primary column, use the list_table_primary_column filter, which receives the column name and the screen ID as arguments.

props stephdau, DaveAl, jesin.
see #25408.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/includes/class-wp-terms-list-table.php

    r32642 r32644  
    308308    public function column_name( $tag ) {
    309309        $taxonomy = $this->screen->taxonomy;
    310         $tax = get_taxonomy( $taxonomy );
    311 
    312         $default_term = get_option( 'default_' . $taxonomy );
    313310
    314311        $pad = str_repeat( '— ', max( 0, $this->level ) );
     
    334331        $out = '<strong><a class="row-title" href="' . $edit_link . '" title="' . esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $name ) ) . '">' . $name . '</a></strong><br />';
    335332
    336         $actions = array();
    337         if ( current_user_can( $tax->cap->edit_terms ) ) {
    338             $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
    339             $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __( 'Quick&nbsp;Edit' ) . '</a>';
    340         }
    341         if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term )
    342             $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url( "edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ) . "'>" . __( 'Delete' ) . "</a>";
    343         if ( $tax->public )
    344             $actions['view'] = '<a href="' . get_term_link( $tag ) . '">' . __( 'View' ) . '</a>';
    345 
    346         /**
    347          * Filter the action links displayed for each term in the Tags list table.
    348          *
    349          * @since 2.8.0
    350          * @deprecated 3.0.0 Use {$taxonomy}_row_actions instead.
    351          *
    352          * @param array  $actions An array of action links to be displayed. Default
    353          *                        'Edit', 'Quick Edit', 'Delete', and 'View'.
    354          * @param object $tag     Term object.
    355          */
    356         $actions = apply_filters( 'tag_row_actions', $actions, $tag );
    357 
    358         /**
    359          * Filter the action links displayed for each term in the terms list table.
    360          *
    361          * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
    362          *
    363          * @since 3.0.0
    364          *
    365          * @param array  $actions An array of action links to be displayed. Default
    366          *                        'Edit', 'Quick Edit', 'Delete', and 'View'.
    367          * @param object $tag     Term object.
    368          */
    369         $actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag );
    370 
    371         $out .= $this->row_actions( $actions );
    372333        $out .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
    373334        $out .= '<div class="name">' . $qe_data->name . '</div>';
     
    378339
    379340        return $out;
     341    }
     342
     343    /**
     344     * Get name of default primary column
     345     *
     346     * @since 4.3.0
     347     * @access protected
     348     *
     349     * @return string
     350     */
     351    protected function get_default_primary_column_name() {
     352        return 'name';
     353    }
     354
     355    /**
     356     * Generate and display row actions links
     357     *
     358     * @since 4.3.0
     359     * @access protected
     360     *
     361     * @param object $tag Tag being acted upon
     362     * @param string $column_name Current column name
     363     * @param string $primary Primary column name
     364     *
     365     * @return string
     366     */
     367    protected function handle_row_actions( $tag, $column_name, $primary ) {
     368        $taxonomy = $this->screen->taxonomy;
     369        $tax = get_taxonomy( $taxonomy );
     370        $default_term = get_option( 'default_' . $taxonomy );
     371
     372        $edit_link = esc_url( get_edit_term_link( $tag->term_id, $taxonomy, $this->screen->post_type ) );
     373
     374        if ( $primary === $column_name ) {
     375            $actions = array();
     376            if ( current_user_can( $tax->cap->edit_terms ) ) {
     377                $actions['edit'] = '<a href="' . $edit_link . '">' . __( 'Edit' ) . '</a>';
     378                $actions['inline hide-if-no-js'] = '<a href="#" class="editinline">' . __( 'Quick&nbsp;Edit' ) . '</a>';
     379            }
     380            if ( current_user_can( $tax->cap->delete_terms ) && $tag->term_id != $default_term )
     381                $actions['delete'] = "<a class='delete-tag' href='" . wp_nonce_url( "edit-tags.php?action=delete&amp;taxonomy=$taxonomy&amp;tag_ID=$tag->term_id", 'delete-tag_' . $tag->term_id ) . "'>" . __( 'Delete' ) . "</a>";
     382            if ( $tax->public )
     383                $actions['view'] = '<a href="' . get_term_link( $tag ) . '">' . __( 'View' ) . '</a>';
     384
     385            /**
     386             * Filter the action links displayed for each term in the Tags list table.
     387             *
     388             * @since 2.8.0
     389             * @deprecated 3.0.0 Use {$taxonomy}_row_actions instead.
     390             *
     391             * @param array  $actions An array of action links to be displayed. Default
     392             *                        'Edit', 'Quick Edit', 'Delete', and 'View'.
     393             * @param object $tag     Term object.
     394             */
     395            $actions = apply_filters( 'tag_row_actions', $actions, $tag );
     396
     397            /**
     398             * Filter the action links displayed for each term in the terms list table.
     399             *
     400             * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
     401             *
     402             * @since 3.0.0
     403             *
     404             * @param array  $actions An array of action links to be displayed. Default
     405             *                        'Edit', 'Quick Edit', 'Delete', and 'View'.
     406             * @param object $tag     Term object.
     407             */
     408            $actions = apply_filters( "{$taxonomy}_row_actions", $actions, $tag );
     409
     410            return $this->row_actions( $actions );
     411        }
    380412    }
    381413
Note: See TracChangeset for help on using the changeset viewer.