WordPress.org

Support

Support » Plugins and Hacks » [Resolved] Using filter hook: symposium_toolbar_add_user_action

[Resolved] Using filter hook: symposium_toolbar_add_user_action

  • I’m trying to use the filter hook “symposium_toolbar_add_user_action” to add custom actions/URLs to the user menu. I’m able to add a single action but I can’t work out how to structure the return value of the filter (e.g. $added_info in the example code within the documentation provided with the plugin). Can you please provide a code snippet of how I could build $added_info in order to produce e.g. 3 menu items? Thanks.

    P.S. Awesome plugin and excellently documented.

    http://wordpress.org/plugins/wp-symposium-toolbar/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Guillaume Assire

    @alphagolf_fr

    Hi Maurta,

    You may want to use the following snippet:

    function symposium_toolbar_add_user_action_hook ( $user_id ) {
    
    	$ret = array();
    
    	$added_info['title'] = "A Title for User ID #".$user_id;
    	$added_info['url'] = site_url();
    	$ret[] = $added_info;
    
    	$added_info['title'] = "Another Title";
    	$added_info['url'] = admin_url();
    	$ret[] = $added_info;
    
    	$added_info['title'] = "A Third Row";
    	$added_info['url'] = home_url();
    	$ret[] = $added_info;
    
    	return $ret;
    }
    add_filter ( 'symposium_toolbar_add_user_action', 'symposium_toolbar_add_user_action_hook', 10, 1 );

    Note that using this hook, the added rows will go at the bottom of the User Action section, that is: after the Log Out link. If you prefer them to go between the User Info and the Edit Profile, you should use the other hook symposium_toolbar_custom_user_info, which uses HTML spans.

    There is also a bug with symposium_toolbar_add_user_action, in that you need at least one of the default items of this section, otherwise it’ll be removed in whole, and the added rows won’t be displayed! Please confirm that the above solves your issue and you are not removing all the default items from the User Action section. I will fix this with next release anyway.

    Thanks for your nice words ; documenting software is an ongoing task, it also helps with clarifying use cases.

    Thanks for your prompt response. Your snippet works as you say and solves my issue. I’m not removing all the default items from the User Action List. Thanks.

    On an unrelated matter, I was getting a PHP Notice message whenever saving the plugin’s settings:
    Notice: Undefined variable: wps_is_active in wp-symposium-toolbar_functions.php on line 854

    I noticed that $wps_is_active is a global variable but not declared as such in the function symposium_toolbar_save_before_render(). I simply declared it as a global and the Notice is not displayed.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] Using filter hook: symposium_toolbar_add_user_action’ is closed to new replies.