How can you disable the post search field "Search posts" - for non-admin roles in WP dashboard?
Image attached:
In my case, the non-admin role is a customer. The customer cannot and must not edit or delete any further posts which belong to other parties. Those posts the customer can view on pages as a common viewer. It's a customer. So I am asking why to show up that search field. I want to disable it.
(Example: if you advertise a flower vase, do you would then want to search for flower vases from others? Maybe some want it - but I don't want to offer that feature)
(Incidental things not relevant to answering the question: BTW, in case someone is asking: I cannot assign the common WP customer role because it does not meet the requirements. BTW, The customer is eligible to delete and view his post. Editing the own posts is possible with Elementor but not with the common WP link)
Attempts:
I tried 4 code snippets from the plugin "Code Snippets" by WPCode, but the search field "Search posts" in WP dashboard (posts) for non-admin roles stays!
// Prevent search queries
add_action(
'parse_query',
function ( $query, $error = true ) {
if ( is_search() && ! is_admin() ) {
$query->is_search = false;
$query->query_vars['s'] = false;
$query->query['s'] = false;
if ( true === $error ) {
$query->is_404 = true;
}
}
},
15,
2
);
// Remove the Search Widget
add_action(
'widgets_init',
function () {
unregister_widget( 'WP_Widget_Search' );
});
// Remove the search form
add_filter( 'get_search_form', '__return_empty_string', 999 );
// Remove the core search block
add_action(
'init',
function () {
if ( ! function_exists( 'unregister_block_type' ) || ! class_exists( 'WP_Block_Type_Registry' ) ) {
return;
}
$block = 'core/search';
if ( WP_Block_Type_Registry::get_instance()->is_registered( $block ) ) {
unregister_block_type( $block );
}
});
example.com/wp-admin/edit.php?s=SEARCH_TERM
to actually do the search.