• I posted this request in BBpress forum but for some reason it did not show up so I hope someone here can help as it is more a wordpress issue and my understanding of PHP code!
    WP 4.6 BBpress plugin 2.5.10
    I am using some of the super BBpress code suggestions at https://codex.bbpress.org/layout-and-functionality-examples-you-can-use/ and most work just fine ‘out of the box’ but I am not sure what I should be putting in place of ‘ my_nav_menu_profile_link’ in this one. If I put in the code as is….

    // Filter wp_nav_menu() to add profile link
    add_filter( 'wp_nav_menu_items', 'my_nav_menu_profile_link' );
    function my_nav_menu_profile_link($menu) {
    ????if (!is_user_logged_in())
    ????????return $menu;
    ????else
    ????????$current_user = wp_get_current_user();
    ????????$user=$current_user->user_nicename ;
    ????????$profilelink = '<li><a href="/forums/users/' . $user . '/edit">Edit Profile</a></li>';
    ????????$menu = $menu . $profilelink;
    ????????return $menu;
    ??
    }

    I get this when trying the menu link……
    Object not found!
    The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
    If you think this is a server error, please contact the webmaster.
    Error 404
    localhost
    Apache/2.4.23 (Win32) OpenSSL/1.0.2h PHP/5.6.24

    If I replace the ‘ my_nav_menu_profile_link’ with the actual link like this…..

    /* Profile link in menu....................*/
    // Filter wp_nav_menu() to add profile link
    add_filter( 'wp_nav_menu_items', 'https://localhost/wordpress/wp-admin/profile.php' );
    function https://localhost/wordpress/wp-admin/profile.php($menu) {
        if (!is_user_logged_in())
            return $menu;
        else
            $current_user = wp_get_current_user();
            $user=$current_user->user_nicename ;
            $profilelink = '<li><a href="/forums/users/' . $user . '/edit">Edit Profile</a></li>';
            $menu = $menu . $profilelink;
            return $menu;
      
    }

    I get this as soon as I go to the site…

    Parse error: syntax error, unexpected ‘:’, expecting ‘(‘ in C:\xampp\htdocs\wordpress\wp-content\themes\twentytenchild\functions.php on line 49
    What should I be entering and when I move to a live site will it need to be further changed?

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator Stephen Edgar

    (@netweb)

    I’ve just approved the bbPress post, it got picked up by our filters:

    https://bbpress.org/forums/topic/profile-in-menu-php/

    Thread Starter Don46

    (@don46)

    Thanks Stephen
    I dont know what is going on with the BBpress forum but I just received a notification of another user (having similar problems) who posted a reply to this thread (in the BBpress forum) and upon clicking on the link provided the post did NOT show his reply either? We both would appreciate a solution to what is, I am sure, just due to our ignorance of PHP code be it within BBpres or WordPress child themes!
    Perhaps in the meanwhile there is an ongoing problem with posting over there?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘PHP code re profile in menu’ is closed to new replies.