WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
hide menu (2 posts)

  1. johnjf
    Member
    Posted 1 year ago #

    I was looking around for a way to hide the contact form menu from other users besides the admin and came across a topic with someone posting a function. It worked for me except it would remove it in my admin panel also. I figured out the problem so I thought I would share with those looking for a solution. Here is the code that someone posted

    function remove_contact_menu () {
    global $menu;
    	$restricted = array(__('Contact'));
    	end ($menu);
    	while (prev($menu)){
    		$value = explode(' ',$menu[key($menu)][0]);
    		if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
    	}
    }
    add_action('admin_menu', 'remove_contact_menu');
    if(!current_user_can('level_10')) {
    	add_action('admin_menu', 'remove_contact_menu');
    }

    What you have to do is remove

    add_action('admin_menu', 'remove_contact_menu');

    because there are 2 of the same code. all I did was remove the top code and it's working fine.

    So the final code is

    function remove_contact_menu () {
    global $menu;
    	$restricted = array(__('Contact'));
    	end ($menu);
    	while (prev($menu)){
    		$value = explode(' ',$menu[key($menu)][0]);
    		if(in_array($value[0] != NULL?$value[0]:"" , $restricted)){unset($menu[key($menu)]);}
    	}
    }
    
    if ( ! current_user_can('level_10') ) {
    	add_action('admin_menu', 'remove_contact_menu');
    }

    http://wordpress.org/extend/plugins/contact-form-7/

  2. Takayuki Miyoshi
    Member
    Plugin Author

    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.