The MU forums have moved to WordPress.org

Calling All MU+PHP freaks (20 posts)

  1. suleiman
    Member
    Posted 17 years ago #

    I'll make this short and sweet. I have two problems.

    1) Trying to get the user_ID not of the active user but of the blog owner. I've tried using the variable "$user_ID" in my plugin but if I sign out and log in with a different user then the $user_ID variable gets swapped. I was using $blog_id for a bit, but then realized that $blog_id and $user_ID were not tied to each other.

    2) My php file checking function is broken:

    function filechecking() {
    global $user_ID;
    $filename = '/wp-content/avatars/' . $user_ID . '.jpg';
    if (file_exists($filename)) {
    printf($filename);
    }
    else {
    echo "wp-content/avatars/default.jpg"
    }

    Running this function does not work for me. All I'm looking to do is have the function check whether a user has uploaded a photo, and if they have then display that, but if not display the default avatar.

  2. lunabyte
    Member
    Posted 17 years ago #

    :|

    I did it for my avatar script.

  3. drmike
    Member
    Posted 17 years ago #

    You and your avatar script... :)

  4. lunabyte
    Member
    Posted 17 years ago #

    I like my avatar script. :D

    I put quite a bit of time into it. ;)

    I know, I'm a tease with some of my scripts. :D

    Funny how the users on my new portal project say the same thing when our site is running a version or two ahead of what's available for download. lol

  5. suleiman
    Member
    Posted 17 years ago #

    Any insights into what I'm dong wrong luna?

    I tried throwing in $user_id = (int) $user_id; when initializing the $user_id variable in the function, and that got me closer (the script echoed "wp-content/avatars/0.jpg" where before there was nothing showing up before the ".jpg"

    But I don't need a 0, I need the right user_id of the blog owner.

  6. gumdrop
    Member
    Posted 17 years ago #

    OK, where's that avatar script luna anyways??

  7. suleiman
    Member
    Posted 17 years ago #

    it's his own custom script gumdrop, not a public distro.

  8. WDuluoz
    Member
    Posted 17 years ago #

    I assume you are not doing this within the loop because the_author_ID(); gets the author id in the loop.

    Make sure you have the absolute path added to the file before you check it.

    WDuluoz

  9. suleiman
    Member
    Posted 17 years ago #

    Thanks WDuluoz, I'm now at least getting the right number. But now a new problem has happened.

    where the code:

    global $blog_id;
    $filename = '/wp-content/avatars/' . $blog_id . '.jpg';

    returned the value of /wp-content/avatars/33.jpg

    the new code:

    $userpicture = the_author_ID();
    $filename = '/wp-content/avatars/' . $userpicture . '.jpg';

    is returning the value 33/wp-content/avatars/.jpg.

    How can I get that 33 to appear where it's supposed to, immediately before the .jpg part of the url?

  10. suleiman
    Member
    Posted 17 years ago #

    Nevermind, the url is now working correctly.

    On to the second problem: the php file checking function is not working correctly.

    I have it set to:

    if (file_exists($filename)) {
    printf($filename);
    }
    else {
    echo "wp-content/avatars/default.jpg";
    }

    but even when a user has uploaded their avatar, the default.jpg file displays.

    Any ideas folks?

  11. suleiman
    Member
    Posted 17 years ago #

    Fixed this problem too. Will be posting on my blog the updated package soon!

  12. suleiman
    Member
    Posted 17 years ago #

    EDIT: I've found as WDulouz has pointed out that the_author_ID(); only works within the loop.

    What could i use that would work both inside and outside of the loop?

  13. zappoman
    Member
    Posted 17 years ago #

    By the way, you did figure out that get_the_author_ID() and the_author_ID() have slightly different behavior... as is the case with all of these template functions the "the_xxxx" version will do an echo, and the "get_the_xxxx" version will return a string. That explains why...


    $userpicture = the_author_ID();
    $filename = '/wp-content/avatars/' . $userpicture . '.jpg';
    echo $filename;

    Will return output...

    33/wp-content/avatars/.jpg.

    Because what actually happens is the equivalent of...


    echo '33';
    $filename = '/wp-content/avatars/' . NULL . '.jpg';
    echo $filename;

    Anyway... this is a nuance I figured out the hard way as I was seeing text output in weird places and I was scratching my head trying to figure out why... then I looked at the code and realized how obvious it was.

  14. zappoman
    Member
    Posted 17 years ago #

    As for why "the_author_ID()" and "get_the_author_ID()" only seem to work inside of the loop, it has to do with the fact that these two functions assume that the global variable $authordata has been setup. See author-template.php for details on all of the author related template tags... you'll see they all pretty much depend on this.

    As with all of the templates tag functions, you can get the globals for them setup properly if you call...


    // Setup global post data.
    function setup_postdata($post) {
    ...

    This of course assumes you have a post object already to work with. So for example if you've done something outside of the standard loop to get a list of posts then you can call this function so that the standard template tags will work.

    There is some good documentation of this in the Wordpress Codex... look for details on "The Loop" and Custom Queries.

    Here's one example that sort of explains this function and how you might use it.

    Also, if you already know the author_id, and you want to get the other template tags to work, you could go ahead and set $authordata yourself by calling...


    global $authordata;
    $authordata = get_userdata( $auth_id );

    Good luck!

  15. suleiman
    Member
    Posted 17 years ago #

    what about creating a mini loop?
    Only for the sidebar, only for that widget?

  16. zappoman
    Member
    Posted 17 years ago #

    There is some really good documentation on the Wordpress Codex about the idea of running multiple loops. It's really straight forward. Check it out.

  17. lunabyte
    Member
    Posted 17 years ago #

    Why use multiple loops? I don't get it. It isn't needed. ;)

  18. suleiman
    Member
    Posted 17 years ago #

    Why can't I run this line in the widget:

    $blogownerid = $wpdb->get_results("SELECT post_author FROM wp_98_posts");

    ??

    Everytime I try it throws back this error:

    Fatal error: Call to a member function on a non-object in...

    EDIT: forgot to initialize global $wpdb, nevermind.

  19. findtj
    Member
    Posted 17 years ago #

    Suleiman,
    Once you get an update on this let us know, I am currently working with a 'bandaged together' version of your widget it works pretty well. One other thing I noticed is on the management side of the tool, there is no way that I have noticed to delete an image (say if you do not want to use one). Thanks again!

  20. suleiman
    Member
    Posted 17 years ago #

    findtj, please take a look at this thread:

    http://mu.wordpress.org/forums/topic.php?id=3858

    The new WPMU Avatar Pack has been released. It is bundled with a new Author Profile Enhanced widget. Let me know if it works for you.

About this Topic

  • Started 17 years ago by suleiman
  • Latest reply from suleiman