Skip to:
Content
Pages
Categories
Search
Top
Bottom

How do I refer to current user’s name?

  • I am trying to write a plugin … how do I refer to the currently logged in user’s name? I tried

    get_user_name( $user->ID )

    but I get “get_user requires a numerical ID” or something like that.

Viewing 9 replies - 1 through 9 (of 9 total)
  • change $user to $bb_current_user

    If you’re in a function, be sure to add that to the globals. If you’re in just a template file, no need to.

    so:

    Function BlahBlah () {

    global $bb_current_user;

    $myName = get_user_name( $bb_current_user->ID );

    echo "Hello, my name is ".$myName;

    }

    Like that?

    Where can I find a list of all these variables and functions? Like how did the author of that plugin know there was such a thing as get_user_name()?

    Check out /bb-includes/template-functions.php for the list of things you can use for calls.

    Trent

    How about a list of hooks?

    I am not really the best one to answer on this particular issue, so I appologize in advance, but if I understand what you are asking based on previous information in post, /bb-includes/function.php has all the different bbPress functions to call and template-functions.php have specific template related calls.

    If that is useless information because I am not quite understanding, I would imagine Ardentfrost or someone else should be along with a better answer.

    Trent

    There is no instructions on how to write plugins as far as I know. You just gotta do it like the rest of us: look through the code and figure out how it’s written. It’s not too hard and it’s written logically. You need to be able to either grep or search inside the files (there’s a way to search inside php files using windows search). If you want to look for hooks, look for add_action or add_filter and see where they all are. If you want to see how to use them, look through other plugins.

    And if you have specific questions, these forums are here and there are plenty of people who try to help :)

    This is frustrating. Tell me why this simplest of all plugins does not work.

    <?php

    /*

    Plugin Name: Add something to the header

    Plugin URI: http://davidbessler.com

    Description: My first plugin

    Author: David Bessler

    Author URI: http://davidbessler.com

    Version: 1.0

    */

    function add_something_to_the_header (){

    echo "<!--Something I added-->n";

    }

    add_action ('bb_head' , 'add_something_to_the_header');

    ?>

    davidbessler,

    Your theme needs to have a call to bb_head() in its header.php.

    If you’re using a version of the default header, make sure bb_head() is actually being executed on every page load. There was a bug in early versions of bbPress that prevented bb_head() from being called on anything but topic pages.

    As an aside, if you’re adding javascript, you should definitely use bb_enqueue_script().

    bb_enqueue_script( 'give-it-some-name', '/soruce/file.js');

    OK. Thanks. It turned out bb_head() was only called (as part of an if () statement) when the page is a topic. So I see that my above plugin works on a topic page. Awesome.

    My long-term project is a forum-access plugin where you can grant or restrict access to individual users. Not roles-based.

    Does anyone know a hook to use for intercepting an individual forum listing in front-page.php? You’d think get_forum would work, but for some reason … anyway.

    I’ll keep you posted on my adventures of learning to write plugins.

Viewing 9 replies - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.
Skip to toolbar