WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Admin bar linking problem (8 posts)

  1. barrypress
    Member
    Posted 1 year ago #

    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);
  2. barrypress
    Member
    Posted 1 year ago #

    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.

  3. keesiemeijer
    moderator
    Posted 1 year ago #

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

    'href' => bp_loggedin_user_domain().'/messages/sentbox',
  4. barrypress
    Member
    Posted 1 year ago #

    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.

  5. keesiemeijer
    moderator
    Posted 1 year ago #

    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

  6. barrypress
    Member
    Posted 1 year ago #

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

  7. keesiemeijer
    moderator
    Posted 1 year ago #

    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.

  8. barrypress
    Member
    Posted 1 year ago #

    thank you for your explanation.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags