WordPress.org

Ready to get started?Download WordPress

Forums

User Photo
How to RETURN photo instead of ECHO photo? (9 posts)

  1. plugins_lexblog
    Member
    Posted 1 year ago #

    Hey guys,

    Great plugin! I love it.

    But the usefulness is very limited because all of your template tags just echo the $img variable. I need to do some things with that value, not just send it to the browser as soon as I grab it!

    What can I do?

    http://wordpress.org/extend/plugins/user-photo/

  2. plugins_lexblog
    Member
    Posted 1 year ago #

    Ugh... This is the best I could come up with:

    $user_photo = userphoto__get_userphoto($author_id, USERPHOTO_THUMBNAIL_SIZE, '', '', array(), '');

    You guys gonna go and change that userphoto__get_userphoto() function in an update and break my theme, or what?

  3. chrishoward
    Member
    Posted 1 year ago #

    Same question here.

    Also notice int he code you've already written the functions to do this, but not made them available.

    Is this likely to be made active soon?

  4. burtatbase
    Member
    Posted 1 year ago #

    plugins_lexblog, if you're worried about future updates breaking your stuff (And so you should be!) a possible solution is to copy that function in it's entirety to your own functions.php for example.

    Rename it, and change every reference to it in your code to your new name.

    The added benefit of this is you can mess with the function to make it return more of what you specifically want, strip out unnecessary bits if you have the knowhow - For example, to make it return just the SRC of the image and go from there.

    Then if they change their function in future, yours should be left unharmed, which is at least a little bit safer.

    Obviously in an ideal world you wouldn't do this, but it might give you a little bit more peace of mind if you're set on going down this route.

  5. Scott Fennell
    Member
    Posted 1 year ago #

    (I am the OP on this topic, just not at my work computer right now).

    burtatbase,

    I see you point but the function returns exactly what I want it to, as is.

    I see they named it with a double underscore after the prefix, which in some circles is a convention to denote that it is intended to be a private function, although not truly private in the OOP sense of the word. That has me worried. I think if they mess with the plugin enough to change the arguments for this function, then I'd rather just take another look at the code and once again grab what I need to return an image.

  6. simalamdeveloper
    Member
    Posted 1 year ago #

    This worked for me:

    For Thumbnail:
    $photoUrl = get_bloginfo('wpurl') . '/wp-content/uploads/userphoto/' . get_user_meta($userID, 'userphoto_thumb_file', true);

    For Full Image:
    $photoUrl = get_bloginfo('wpurl') . '/wp-content/uploads/userphoto/' . get_user_meta($userID, 'userphoto_image_file', true);

    This will just get the full URL to the image.

  7. plugins_lexblog
    Member
    Posted 1 year ago #

    That's really good.

    Caution, some setups balk at your assumption on where wp-conent is, and require:

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

    But it seems REALLY unlikely that the plugin devs on wp-photo will change the user_meta key for the image files. Seems very future-proof. Nice work.

  8. simalamdeveloper
    Member
    Posted 1 year ago #

    Didn't know about the content_url function! Took a quick look but didn't see anything. I'll keep it in mind for future use.

    Thanks! :D

  9. jethin
    Member
    Posted 1 year ago #

    FWIW, I think 'wp_upload_dir' would be somewhat more robust:

    For Thumbnail:
    $upload_dir = wp_upload_dir();
    $photoUrl = $upload_dir['baseurl'] . '/userphoto/' . get_user_meta($userID, 'userphoto_thumb_file', true);

    For Full Image:
    $upload_dir = wp_upload_dir();
    $photoUrl = $upload_dir['baseurl'] . '/userphoto/' . get_user_meta($userID, 'userphoto_image_file', true);

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags

No tags yet.