Skip to content

Commit

Permalink
Quick Edit: Allow Quick Edit to be disabled for custom post types or …
Browse files Browse the repository at this point in the history
…taxonomies.

Some custom post types or taxonomies may not need the Quick Edit functionality, in which case adding hidden fields and rendering the form with the data to edit would be redundant.

This commit introduces two filters for more granular control:

* `quick_edit_enabled_for_post_type`
* `quick_edit_enabled_for_taxonomy`

Follow-up to [8857], [9083], [9098].

Props garyc40, sabernhardt, mukesh27, costdev, oglekler, wyrfel, peterwilsoncc, faguni22, robinwpdeveloper, webcommsat, johnbillion, azaozz, hellofromTonya, GunGeekATX, Jick, mikeschinkel, jane, nacin, helen, wonderboymusic, DrewAPicture, SergeyBiryukov.
Fixes #16502, #19343, #57596.

git-svn-id: https://develop.svn.wordpress.org/trunk@56611 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Sep 18, 2023
1 parent 6340624 commit 6a264d2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 13 deletions.
19 changes: 17 additions & 2 deletions src/wp-admin/includes/class-wp-posts-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -1168,7 +1168,12 @@ public function column_title( $post ) {
}
}

get_inline_data( $post );
/** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
$quick_edit_enabled = apply_filters( 'quick_edit_enabled_for_post_type', true, $post->post_type );

if ( $quick_edit_enabled ) {
get_inline_data( $post );
}
}

/**
Expand Down Expand Up @@ -1475,7 +1480,17 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
__( 'Edit' )
);

if ( 'wp_block' !== $post->post_type ) {
/**
* Filters whether Quick Edit should be enabled for the given post type.
*
* @since 6.4.0
*
* @param bool $enable Whether to enable the Quick Edit functionality. Default true.
* @param string $post_type Post type name.
*/
$quick_edit_enabled = apply_filters( 'quick_edit_enabled_for_post_type', true, $post->post_type );

if ( $quick_edit_enabled && 'wp_block' !== $post->post_type ) {
$actions['inline hide-if-no-js'] = sprintf(
'<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>',
/* translators: %s: Post title. */
Expand Down
40 changes: 29 additions & 11 deletions src/wp-admin/includes/class-wp-terms-list-table.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,17 @@ public function column_name( $tag ) {
$name
);

$output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
$output .= '<div class="name">' . $qe_data->name . '</div>';
/** This filter is documented in wp-admin/includes/class-wp-terms-list-table.php */
$quick_edit_enabled = apply_filters( 'quick_edit_enabled_for_taxonomy', true, $taxonomy );

/** This filter is documented in wp-admin/edit-tag-form.php */
$output .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug, $qe_data ) . '</div>';
$output .= '<div class="parent">' . $qe_data->parent . '</div></div>';
if ( $quick_edit_enabled ) {
$output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
$output .= '<div class="name">' . $qe_data->name . '</div>';

/** This filter is documented in wp-admin/edit-tag-form.php */
$output .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug, $qe_data ) . '</div>';
$output .= '<div class="parent">' . $qe_data->parent . '</div></div>';
}

return $output;
}
Expand Down Expand Up @@ -485,12 +490,25 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $tag->name ) ),
__( 'Edit' )
);
$actions['inline hide-if-no-js'] = sprintf(
'<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>',
/* translators: %s: Taxonomy term name. */
esc_attr( sprintf( __( 'Quick edit &#8220;%s&#8221; inline' ), $tag->name ) ),
__( 'Quick&nbsp;Edit' )
);

/**
* Filters whether Quick Edit should be enabled for the given taxonomy.
*
* @since 6.4.0
*
* @param bool $enable Whether to enable the Quick Edit functionality. Default true.
* @param string $taxonomy Taxonomy name.
*/
$quick_edit_enabled = apply_filters( 'quick_edit_enabled_for_taxonomy', true, $taxonomy );

if ( $quick_edit_enabled ) {
$actions['inline hide-if-no-js'] = sprintf(
'<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>',
/* translators: %s: Taxonomy term name. */
esc_attr( sprintf( __( 'Quick edit &#8220;%s&#8221; inline' ), $tag->name ) ),
__( 'Quick&nbsp;Edit' )
);
}
}

if ( current_user_can( 'delete_term', $tag->term_id ) ) {
Expand Down

0 comments on commit 6a264d2

Please sign in to comment.