• Resolved markussss

    (@markussss)


    In your examples you show the following snippet to only show Simple History to specific users.

    I wonder if you can address also the Simple History menu item in the admin toolbar? https://cln.sh/W2z8pR8t

    something like simle_history/show_adminbar_menu maybe?

    // Allow only the users specified in $allowed_users to show the history page, the history widget on the dashboard, or the history settings page
    add_filter( 'simple_history/show_dashboard_page', 'function_show_history_dashboard_or_page' );
    add_filter( 'simple_history/show_dashboard_widget', 'function_show_history_dashboard_or_page' );
    add_filter( 'simple_history/show_settings_page', 'function_show_history_dashboard_or_page' );
    function function_show_history_dashboard_or_page( $show ) {
    
    ...
    }

    https://github.com/bonny/WordPress-Simple-History/blob/main/examples/examples.php

    best regards
    Markus

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author eskapism

    (@eskapism)

    You can remove the items from the admin bar using these filters:

    • simple_history/add_admin_bar_menu_item
    • simple_history/add_admin_bar_network_menu_item

    Just return false from them and the menu bar item should be gone.

    Thread Starter markussss

    (@markussss)

    I confirm it works – here the code if someone else needs it. Just added those two lines. Thanks a lot!

    add_filter( 'simple_history/add_admin_bar_menu_item', '__return_false' );
    add_filter( 'simple_history/add_admin_bar_network_menu_item', '__return_false' );

    And got the final code

    <?php 
    
    // Allow only the users specified in $allowed_users to show the history page, the history widget on the dashboard, or the history settings page
    add_filter( 'simple_history/show_dashboard_page', 'function_show_history_dashboard_or_page' );
    add_filter( 'simple_history/show_dashboard_widget', 'function_show_history_dashboard_or_page' );
    add_filter( 'simple_history/show_settings_page', 'function_show_history_dashboard_or_page' );
    add_filter( 'simple_history/add_admin_bar_menu_item', 'function_show_history_dashboard_or_page' );
    add_filter( 'simple_history/add_admin_bar_network_menu_item', 'function_show_history_dashboard_or_page' );
    
    
    function function_show_history_dashboard_or_page( $show ) {
    
    	$allowed_users = array(
    		'[email protected]',
    		'[email protected]',
    	);
    
    	$user = wp_get_current_user();
    
    	if ( ! in_array( $user->user_email, $allowed_users ) ) {
    		$show = false;
    	}
    
    	return $show;
    }
    Plugin Author eskapism

    (@eskapism)

    Great! Thanks for the follow up with code examples!??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Filter simple_history/show_adminbar_menu to hide it from the toolbar dropdown?’ is closed to new replies.