WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] Admin bar linking problem

[Resolved] Admin bar linking problem

  • barrypress

    @barrypress

    I added a custom menu to my admin bar, but when I try to add dynamic links to let’s say user inbox or activity page with bp_loggedin_user_domain function page just refreshes.
    Same links work when I try linking from headher.php but I need it in admin bar.

    this is the code I aded to my functions.php

    function add_sumtips_admin_bar_link() {
    	global $wp_admin_bar;
    	if ( !is_super_admin() || !is_admin_bar_showing() )
    		return;
    	$wp_admin_bar->add_menu( array(
    	'id' => 'sumtips_link',
    	'title' => __( 'Osobno'),
    	'href' => __('< ?php echo bp_loggedin_user_domain()  ?>/messages/sentbox'),
    	));
    
    	// Add sub menu link "View All Posts"
    	$wp_admin_bar->add_menu( array(
    		'parent' => 'sumtips_link',
    		'id'     => 'sumtips_all',
    		'title' => __( 'View All Posts'),
    		'href' => __('http://sumtips.com/all'),
    	));
    
    	// Add sub menu link "Downloads"
    	$wp_admin_bar->add_menu( array(
    		'parent' => 'sumtips_link',
    		'id'     => 'sumtips_downloads',
    		'title' => __( 'Downloads'),
    		'href' => __('<?php echo bp_loggedin_user_domain() ?>activity'),
    		'meta'   => array(
    			'class' => 'st_menu_download',),
    	));
    		$wp_admin_bar->add_menu( array(
    			'parent' => 'sumtips_downloads',
    			'id'     => 'sumtips_browsers',
    			'title' => __( 'Browsers'),
    			'href' => __('http://sumtips.com/downloads?category=3'),
    		));
    }
    add_action('admin_bar_menu', 'add_sumtips_admin_bar_link',25);

Viewing 7 replies - 1 through 7 (of 7 total)
  • barrypress

    @barrypress

    Is that problem caused by the fact that admin bar is defined in wordpress files and doesn’t uderstand bp_XXX functions?
    I really can’t undersand what is causing this problem, it’s posible that this is a bug.

    Moderator keesiemeijer

    @keesiemeijer

    Not sure if those functions will work but try changing it like so [untested]:

    'href' => bp_loggedin_user_domain().'/messages/sentbox',

    barrypress

    @barrypress

    It isn’t working, I tried all the variations I coud find on the net like:
    <?php echo bp_loggedin_user_domain() . BP_MESSAGES_SLUG ?>
    and bunch of others but I can’t get it to work.

    Moderator keesiemeijer

    @keesiemeijer

    The function bp_loggedin_user_domain exists if your code doesn’t throw an error.
    Try it with this for testing:

    add_action( 'admin_bar_menu', 'add_sumtips_admin_bar_link', 999 );
    
    function add_sumtips_admin_bar_link( $wp_admin_bar ) {
      global $wp_admin_bar;
    
      if (!is_super_admin() ||  !is_admin_bar_showing() )
    		return;
    
      $args = array(
        'id' => 'sumtips_link',
        'title' => 'Osobno',
        'href' => bp_loggedin_user_domain() . 'messages/sentbox',
      );  
    
      $wp_admin_bar->add_node($args);
    }

    http://codex.wordpress.org/Function_Reference/add_node

    barrypress

    @barrypress

    This is working!! Thanks for your reply.
    I’am still not shure that I understand the problem.

    Moderator keesiemeijer

    @keesiemeijer

    I think the problem was you put the ‘href’ in translation functions (__())
    http://codex.wordpress.org/Function_Reference/_2
    And this is just a string (not a valid url):

    '<?php echo bp_loggedin_user_domain() ?>activity'

    I’m glad you got it resolved.

    barrypress

    @barrypress

    thank you for your explanation.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘[Resolved] Admin bar linking problem’ is closed to new replies.
Skip to toolbar