Skip Navigation

[Resuelto] Cred Conditional codes

This support ticket is created hace 6 años, 2 meses. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Hoy no hay técnicos de soporte disponibles en el foro Juego de herramientas. Siéntase libre de enviar sus tiques y les daremos trámite tan pronto como estemos disponibles en línea. Gracias por su comprensión.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

Etiquetado: 

Este tema contiene 7 respuestas, tiene 2 mensajes.

Última actualización por Akhil hace 6 años, 2 meses.

Asistido por: Waqar.

Autor
Mensajes
#1116075

Hi . how does conditional for cred user form is different from normal field ?
i have this :

[cred_field field="profile-image" force_type="field" class="form-control text-center center-block file-upload" output="bootstrap"]

How do i code to display default image if the profile image is empty ?

I read the documents , and its just get more confusing..

Thanks

#1116683

seriosuly ? 18 hrs the ticket still no one pickup ??

#1117067

Hi there,

Thank you for contacting us and we apologize for the delay.

If your goal is to show the default WordPress "Profile Picture" (from Gravatar), when a custom user field "profile-image", is not set, you'll need to a custom shortcode for this.

Here is an example of shortcode that you can add at the bottom of your active child theme's "functions.php" file:


// custom shortcode to check if user image is set
add_shortcode('check_user_image', 'check_user_image_fn');
function check_user_image_fn() {
    
	if (!empty($_GET['user_id'])){

        // get the ID of user, whose form is is being edited
		$user_id = $_GET['user_id'];
		
		// get the image from user's meta
		$profile_image = do_shortcode( '[types usermeta="profile-image" user_id="'.$user_id.'"][/types]' );
		
		if ($profile_image){
			// show the custom image if it is set
			echo $profile_image;
		}
		else{
			$user_email = get_the_author_meta( 'user_email', $user_id );
  			$avatar = get_avatar( $user_email, $size = '48', $default = 'mystery');

  			// show the default Gravatar image if no profile image is set
			echo $avatar;
		}
	}
}

To add this shortcode in your user edit form, you can place it as:


[check_user_image]

I hope this helps and please let us know if there's anything else we can help you with.

Thanks,
Waqar

#1117104

Hi. Thanks but I am not using gravatar. User Custom field is" image profile."'

#1118126

Hi there,

Thanks for writing back and for sharing further details.

The suggested custom shortcode will first check for a custom user field, and if it is empty will show WordPress’ default profile picture (from Gravatar).

If you’d only like to show a default and fixed fallback image when an image is not set for the custom user field (‘profile-image’), you can use the updated code:


// custom shortcode to check if user image is set
add_shortcode('check_user_image', 'check_user_image_fn');
function check_user_image_fn() {
     
    if (!empty($_GET['user_id'])){
 
        // get the ID of user, whose form is is being edited
        $user_id = $_GET['user_id'];
         
        // get the image from user's meta
        $profile_image = do_shortcode( '[types usermeta="profile-image" user_id="'.$user_id.'"][/types]' );
         
        if ($profile_image){
            // show the custom image if it is set
            echo $profile_image;
        }
        else{
           // show default fallback image
            $fallback_image_URL = "image URL";
            echo '<img alt="some alt text" src="'.$fallback_image_URL.'">';
        }
    }
}

Feel free to replace “image URL” and “some alt text” values as needed.

If we can be of any further assistance, please let us know.

Regards,
Waqar Ali

#1118170

My issue is resolved now. Thank you!

not related but to highlight that your profile info is different from the rest of the forum supporters .

#1118171

not related but to highlight that your profile info is different from the rest of the forum supporters .

#1118173

My issue is resolved now. Thank you!