• Hello,

    I uploaded the plugin successfully and have added my profile picture to the user page (I am the administrator). Now I can’t figure out which code to enter and where to enter it. I’ve tried going into the theme as well as the simple custom css plugin. Would it be possible to provide a step-by-step on how to get my photo to appear? (Do I need to add code and take out code, just add code, etc.). Thanks in advance for your help.

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

Viewing 3 replies - 1 through 3 (of 3 total)
  • To enable local system avatars in a template that uses avatars, you need to replace whenever the avatar is requested. This works for Customizr, but the concept is similar for others that use an avatar. The alternative is to change every template where you want to display an avatar and add it in using the “echo” command.

    This describes the process to override the ‘get_avatar’ function used in many themes, including customizr.

    To do this, you need to create a child template (so your changes don’t get overridden every time you update your template) and implement the runkit extension in php. I know this is complicated, but I couldn’t find anything less.

    Also NOTE the recommended statement by the authors of this plugin will only give you YOUR icon:

    $imgURL = get_cupp_meta($user_id, $size); // wrong

    You need to use the following:

    $imgURL = get_the_author_meta(‘cupp_upload_meta’, $id, $size); // correct

    Step-by-step guide (For Customizr on Ubuntu/Apache)

    1. Install ‘Childify Me’ plugin to enable modifications to the template that will not be lost and create a child template
    2. Install ‘Custom User Profile Photo’ to enable custom photo uploads and associate with user profiles
    3. Install https://github.com/zenovich/runkit for php (note: had to use master, the current release had build errors)
    1. wget https://github.com/zenovich/runkit/archive/master.zip
    2. unzip master.zip
    3. mv master runkit-1.0.4
    4. tar -zcvf runkit-1.0.4.tgz runkit-1.0.4
    5. pecl install runkit-1.0.4.tgz
    6. Create a /etc/php5/apache2/ mods-available/runkit.ini with extension=runkit.ini
    7. Create a 20-runkit.ini -> ../../mods-available/runkit.ini simlink (ln –s)
    8. Restart the apache server
    1. Add the following using the Appearance->editor->Theme Functions to override the Customizr display avatar code:


    <?php
    // Your amazing code here (post parent load)
    if ( function_exists( 'get_avatar' ) ) :
    runkit_function_remove ( 'get_avatar' );
    endif;
    /**
    * These functions can be replaced via plugins. If plugins do not redefine these
    * functions, then these will be used instead.
    *
    * @package WordPress
    */
    if ( !function_exists( 'get_avatar' ) ) :
    /**
    * Retrieve the avatar for a user who provided a user ID or email address.
    *
    * @since 2.5.0
    *
    * @param int|string|object $id_or_email A user ID, email address, or comment object
    * @param int $size Size of the avatar image
    * @param string $default URL to a default image to use if no avatar is available
    * @param string $alt Alternative text to use in image tag. Defaults to blank
    * @return false|string
    <img> tag for the user’s avatar.
    */
    function get_avatar( $id_or_email, $size = ’96’, $default = ”, $alt = false ) {
    if ( ! get_option(‘show_avatars’) )
    return false;
    if ( false === $alt)
    $safe_alt = ”;
    else
    $safe_alt = esc_attr( $alt );
    if ( !is_numeric($size) )
    $size = ’96’;
    $email = ”;
    if ( is_numeric($id_or_email) ) {
    $id = (int) $id_or_email;
    $user = get_userdata($id);
    if ( $user )
    $email = $user->user_email;
    } elseif ( is_object($id_or_email) ) {
    // No avatar for pingbacks or trackbacks
    /**
    * Filter the list of allowed comment types for retrieving avatars.
    *
    * @since 3.0.0
    *
    * @param array $types An array of content types. Default only contains ‘comment’.
    */
    $allowed_comment_types = apply_filters( ‘get_avatar_comment_types’, array( ‘comment’ ) );
    if ( ! empty( $id_or_email->comment_type ) && ! in_array( $id_or_email->comment_type, (array) $allowed_comment_types ) )
    return false;
    if ( ! empty( $id_or_email->user_id ) ) {
    $id = (int) $id_or_email->user_id;
    $user = get_userdata($id);
    if ( $user )
    $email = $user->user_email;
    }
    if ( ! $email && ! empty( $id_or_email->comment_author_email ) )
    $email = $id_or_email->comment_author_email;
    } else {
    $email = $id_or_email;
    }
    $imgURL = get_the_author_meta(‘cupp_upload_meta’, $id, $size);
    // Print the image on the page
    return(‘<img src=”‘. $imgURL .'” alt=””>’);
    }
    endif;

    Oops, should have said the above code goes into the child “Theme Functions” (functions.php). To modify the theme and override get_avatar.

    Hello Chayre,
    Sorry for the delayed response here.

    Please disregard jdponds responses. We cannot verify nor guarantee the code he is pasting above. This plugin does not need the runkit repo he references.

    The code provided in the examples work perfectly fine and should be used as shown in the example in most cases. The issue you might be having is the user ID. You have to properly fetch the user ID of the person you’re trying to display. The other key is how you’re trying to attach that user to a post or comment, etc.

    Can you provide us with more info on how you intend to use this photo. Is it strictly on posts that you make in your blog or custom post type?

    Regards,
    3five

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Photo won't show up’ is closed to new replies.