Skip to content

Commit 6a264d2

Browse files
Quick Edit: Allow Quick Edit to be disabled for custom post types or 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
1 parent 6340624 commit 6a264d2

2 files changed

Lines changed: 46 additions & 13 deletions

File tree

src/wp-admin/includes/class-wp-posts-list-table.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,7 +1168,12 @@ public function column_title( $post ) {
11681168
}
11691169
}
11701170

1171-
get_inline_data( $post );
1171+
/** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */
1172+
$quick_edit_enabled = apply_filters( 'quick_edit_enabled_for_post_type', true, $post->post_type );
1173+
1174+
if ( $quick_edit_enabled ) {
1175+
get_inline_data( $post );
1176+
}
11721177
}
11731178

11741179
/**
@@ -1475,7 +1480,17 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
14751480
__( 'Edit' )
14761481
);
14771482

1478-
if ( 'wp_block' !== $post->post_type ) {
1483+
/**
1484+
* Filters whether Quick Edit should be enabled for the given post type.
1485+
*
1486+
* @since 6.4.0
1487+
*
1488+
* @param bool $enable Whether to enable the Quick Edit functionality. Default true.
1489+
* @param string $post_type Post type name.
1490+
*/
1491+
$quick_edit_enabled = apply_filters( 'quick_edit_enabled_for_post_type', true, $post->post_type );
1492+
1493+
if ( $quick_edit_enabled && 'wp_block' !== $post->post_type ) {
14791494
$actions['inline hide-if-no-js'] = sprintf(
14801495
'<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>',
14811496
/* translators: %s: Post title. */

src/wp-admin/includes/class-wp-terms-list-table.php

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,17 @@ public function column_name( $tag ) {
425425
$name
426426
);
427427

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

431-
/** This filter is documented in wp-admin/edit-tag-form.php */
432-
$output .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug, $qe_data ) . '</div>';
433-
$output .= '<div class="parent">' . $qe_data->parent . '</div></div>';
431+
if ( $quick_edit_enabled ) {
432+
$output .= '<div class="hidden" id="inline_' . $qe_data->term_id . '">';
433+
$output .= '<div class="name">' . $qe_data->name . '</div>';
434+
435+
/** This filter is documented in wp-admin/edit-tag-form.php */
436+
$output .= '<div class="slug">' . apply_filters( 'editable_slug', $qe_data->slug, $qe_data ) . '</div>';
437+
$output .= '<div class="parent">' . $qe_data->parent . '</div></div>';
438+
}
434439

435440
return $output;
436441
}
@@ -485,12 +490,25 @@ protected function handle_row_actions( $item, $column_name, $primary ) {
485490
esc_attr( sprintf( __( 'Edit &#8220;%s&#8221;' ), $tag->name ) ),
486491
__( 'Edit' )
487492
);
488-
$actions['inline hide-if-no-js'] = sprintf(
489-
'<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>',
490-
/* translators: %s: Taxonomy term name. */
491-
esc_attr( sprintf( __( 'Quick edit &#8220;%s&#8221; inline' ), $tag->name ) ),
492-
__( 'Quick&nbsp;Edit' )
493-
);
493+
494+
/**
495+
* Filters whether Quick Edit should be enabled for the given taxonomy.
496+
*
497+
* @since 6.4.0
498+
*
499+
* @param bool $enable Whether to enable the Quick Edit functionality. Default true.
500+
* @param string $taxonomy Taxonomy name.
501+
*/
502+
$quick_edit_enabled = apply_filters( 'quick_edit_enabled_for_taxonomy', true, $taxonomy );
503+
504+
if ( $quick_edit_enabled ) {
505+
$actions['inline hide-if-no-js'] = sprintf(
506+
'<button type="button" class="button-link editinline" aria-label="%s" aria-expanded="false">%s</button>',
507+
/* translators: %s: Taxonomy term name. */
508+
esc_attr( sprintf( __( 'Quick edit &#8220;%s&#8221; inline' ), $tag->name ) ),
509+
__( 'Quick&nbsp;Edit' )
510+
);
511+
}
494512
}
495513

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

0 commit comments

Comments
 (0)