• Resolved sqhendr

    (@sqhendr)


    Hey,

    So, I had been having trouble getting photos to show up using get_cupp_meta. I had worked around it by using get_the_author_meta and doing a lot of twisty manipulations to get the size of photo I wanted, but was difficult, and seemed fragile. So, I looked deeper into the plugin code, particularly the get_cupp_meta function. It wasn’t returning anything, because the get_attachment_image_by_url function was using the guid value to find the id. It was also trying to parse the url using WP_CONTENT_URL, which wasn’t in the downloads path, anyway. Thus, it was failing in multiple ways to return an id.

    After a little searching around, I found that there is a function since WordPress 4.0 called attachment_url_to_postid that takes a path and returns an id, using the _wp_attached_file meta_value to match against. I replaced the get_attachment_image_by_url function call in get_cupp_meta with attachment_url_to_postid and my images are showing up just fine, with the proper sizes and all.

    I wonder if you might consider making that change in your plugin. As it stands, I’ve had to hack the plugin, and next time there’s an update, I’ll have to merge your new changes with mine, to maintain consistency. I really like the plugin, because it makes it easy for us to set up our user photos the way we want them.

    https://www.ads-software.com/plugins/custom-user-profile-photo/

Viewing 7 replies - 1 through 7 (of 7 total)
  • Basically there’s not a hope in hell for any of us who don’t know code to use this plug-in…..Bummer.
    Anybody who wants to give us non-coders a concrete example of what to put where so the photo will show up where it’s supposed to will be much appreciated.

    https://www.macaleaveyaviation.com/wp

    Thread Starter sqhendr

    (@sqhendr)

    Hey,

    Sorry, I would have responded earlier, but apparently WordPress’ email notifications aren’t working as I expected. I’m not sure what the etiquette is here. I’d be glad to send anyone a copy of the main plugin file that I changed. You’d just need to replace the 3five_cupp.php file with that one.

    The main thing to remember is that if the plugin is ever updated, that file will get overwritten. I’ve also not run a ton of tests on this change, so your mileage may vary, but it seems to be working well for me.

    Hello sqhendr,
    I think you’ve got a great idea there. We’d love to see the code changes you made regarding the GUID. Could you paste the code here so we can consider it for our next update. If the code change is too long, let me know and we’ll set up another way to connect.

    Much appreciated,
    3five

    Thread Starter sqhendr

    (@sqhendr)

    Hey,

    Glad to do so. All I changed was the get_cupp_meta function:

    /**
     * Retrieve the appropriate image size
     *
     * @param $user_id    Default: $post->post_author. Will accept any valid user ID passed into this parameter.
     * @param $size       Default: 'thumbnail'. Accepts all default WordPress sizes and any custom sizes made by the add_image_size() function.
     * @return {url}      Use this inside the src attribute of an image tag or where you need to call the image url.
     */
    function get_cupp_meta( $user_id, $size ) {
        //allow the user to specify the image size
        if (!$size){
            $size = 'thumbnail'; // Default image size if not specified.
        }
        if(!$user_id){
            $user_id = $post->post_author;
        }
    
        // get the custom uploaded image
        $attachment_upload_url = esc_url( get_the_author_meta( 'cupp_upload_meta', $user_id ) );
        // get the external image
        $attachment_ext_url = esc_url( get_the_author_meta( 'cupp_meta', $user_id ) );
        $attachment_url = '';
        $image_url = '';
        if($attachment_upload_url){
            $attachment_url = $attachment_upload_url;
            // grabs the id from the URL a WordPress function instead of the one originally proposed
            $attachment_id = attachment_url_to_postid( $attachment_url );
            // retrieve the thumbnail size of our image
            $image_thumb = wp_get_attachment_image_src( $attachment_id, $size );
            $image_url = $image_thumb[0];
    
        } elseif($attachment_ext_url) {
            $image_url = $attachment_ext_url;
        }
    
        if ( empty($image_url) )
            return;
    
        // return the image thumbnail
        return $image_url;
    }

    Essentially, I just changed the original call to get_attachment_image_by_url to attachment_url_to_postid. It seems like a pretty obscure WordPress function, so I hope it’s got good staying power.

    Hello Tom MacAleavey,
    You are correct in that the plugin is intended for the theme coders. However, we are working on an option to allow non-coders the ability to override the Gravatar within WordPress. This can be very tricky though because it could potentially break a theme.

    We’ll let you know when that update is released.

    Regards,
    3five

    Just pushed v0.3. Thanks sqhendr for the info on the WP core function.

    Thread Starter sqhendr

    (@sqhendr)

    Seems to work quite well. Thanks for the update!

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Searching by GUID not reliable’ is closed to new replies.