From 1b5fc476f82c752c5cc21d9182e73c4753edb9dc Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Mon, 18 Sep 2023 13:19:19 +0000 Subject: [PATCH] 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. Built from https://develop.svn.wordpress.org/trunk@56611 git-svn-id: http://core.svn.wordpress.org/trunk@56123 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- .../includes/class-wp-posts-list-table.php | 19 ++++++++- .../includes/class-wp-terms-list-table.php | 40 ++++++++++++++----- wp-includes/version.php | 2 +- 3 files changed, 47 insertions(+), 14 deletions(-) diff --git a/wp-admin/includes/class-wp-posts-list-table.php b/wp-admin/includes/class-wp-posts-list-table.php index 5f11ecb9bb..55456333c8 100644 --- a/wp-admin/includes/class-wp-posts-list-table.php +++ b/wp-admin/includes/class-wp-posts-list-table.php @@ -1168,7 +1168,12 @@ class WP_Posts_List_Table extends WP_List_Table { } } - 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 ); + } } /** @@ -1475,7 +1480,17 @@ class WP_Posts_List_Table extends WP_List_Table { __( '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( '', /* translators: %s: Post title. */ diff --git a/wp-admin/includes/class-wp-terms-list-table.php b/wp-admin/includes/class-wp-terms-list-table.php index 69c6da0d85..efbf68a9f4 100644 --- a/wp-admin/includes/class-wp-terms-list-table.php +++ b/wp-admin/includes/class-wp-terms-list-table.php @@ -425,12 +425,17 @@ class WP_Terms_List_Table extends WP_List_Table { $name ); - $output .= ''; + if ( $quick_edit_enabled ) { + $output .= ''; + } return $output; } @@ -485,12 +490,25 @@ class WP_Terms_List_Table extends WP_List_Table { esc_attr( sprintf( __( 'Edit “%s”' ), $tag->name ) ), __( 'Edit' ) ); - $actions['inline hide-if-no-js'] = sprintf( - '', - /* translators: %s: Taxonomy term name. */ - esc_attr( sprintf( __( 'Quick edit “%s” inline' ), $tag->name ) ), - __( 'Quick 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( + '', + /* translators: %s: Taxonomy term name. */ + esc_attr( sprintf( __( 'Quick edit “%s” inline' ), $tag->name ) ), + __( 'Quick Edit' ) + ); + } } if ( current_user_can( 'delete_term', $tag->term_id ) ) { diff --git a/wp-includes/version.php b/wp-includes/version.php index 4c710c849b..6ed36dee57 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '6.4-alpha-56610'; +$wp_version = '6.4-alpha-56611'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.