Skip Navigation

[Resuelto] Notification when custom image field is changed

Este hilo está resuelto. Aquí tiene una descripción del problema y la solución.

Problem:

The issue here is that the user wanted to send a notification using CRED when their user edits an image field on the form.

Solution:

The solution can be seen below.
https://toolset.com/forums/topic/notification-when-custom-image-field-is-changed/#post-1244707

This support ticket is created hace 5 años, 6 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 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

Este tema contiene 30 respuestas, tiene 2 mensajes.

Última actualización por FelipeP5703 hace 5 años, 5 meses.

Asistido por: Shane.

Autor
Mensajes
#1244753

Ok, I created two radio buttons (Trocar Perfil and Trocar Fotos). I already added them to the Edit Form. Now you can do your magic.

#1244820

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Felipe,

I've modified the code and sent out a test mail.

Please let me know as soon as you get this mail.

Thanks,
Shane

#1244824

I got the email but my question is this, you only changed the field name to when the user deletes the profile picture. Do I have to duplicate your JQuery code in order to do the other pictures?

Also, once the user changes the pictures the first time, the radio changes to YES, but let's say he wants to change the pictures tomorrow again, will the radio be back to default as NO, or will keep YES because of the first time he changed the pictures?

#1245140

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Felipe,

Right now the code is targeting when the user clicks the x button to delete the image. This will trigger the js to set the code to yes.

If you set the default answer to NO in the types field setting then each time the page is loaded it will default to NO. It will only change to YES once the user makes the change on the photo.

However when the user changes it to YES we will need to default it to NO because that YES value will be saved to the post itself.

jQuery( document ).ready(function() {
  jQuery('input:radio[name=wpcf-trocar-perfil]').filter('[value=2]').prop('checked', true);
});

Add this code to the forms js as well and it will default the field to NO on page load.

Thanks,
Shane

#1245145

Got it!

When you say:
Right now the code is targeting when the user clicks the x button to delete the image.
Do you mean any X, either be single image or multiple images?

#1245150

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Felipe,

I made the code general because it would be difficult to actually tell. So I hooked it up so once the use clicks to remove any of the images it will trigger the code.

Being able to distinguish between the single image or the multiple images will take a little bit more code and will make it somewhat more complex.

Thanks,
Shane

#1245154

No that's fine, as long as the code captures one or another, it's ok. I just need to be informed if any image was changed or not.

I'll test it out, and let you know. Thanks

#1245157

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Felipe,

Awesome let me know as soon as your tests are done then we can wrap up here.

Thanks,
Shane

#1245165

I tested but the notification is not sending the email. The user gets his/her notification fine, but the one I set up for Admin is not sending, although the test email works fine.

Look: enlace oculto

#1245233

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Felipe,

Thanks for the detailed explanation.

Could you try this scenario for me. What happens if you manually set the field to yes. Just edit the post and manually set the field to yes and then submit.

Let me know if the email is sent then.

Thanks,
Shane

#1245248
WP_Error.jpg

No, it did not work. I followed your instruction and nothing was sent to admin.

Also, now it seems there is an error in the My Account. What could it be?

Notice: Trying to get property 'ID' of non-object in /home/b16f1985/public_html/felipepenna.com/destackterapiastest/wp-content/plugins/types/vendor/toolset/types/embedded/includes/fields/image.php on line 1273
#1246020

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Felipe,

I'm checking on this for you now.

#1246611

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Felipe,

This should be working now.

The issue was that you had the field after the submit button. Please check if you got the emails because I did in my testing.

Thanks,
Shane

#1246640

So I tested on a couple of custom post and most of them worked fine, except for Tamy's. I'm not sure why I'm not getting an email when she changes her pictures.

Two things:
1) The Notice is still in place and it's coming from Toolset. "Notice: Trying to get property 'ID' of non-object in /home/b16f1985/public_html/felipepenna.com/destackterapiastest/wp-content/plugins/types/vendor/toolset/types/embedded/includes/fields/image.php on line 1273"
This showed up after I gave you access to do the changes. It's showing on the home page and on Minha Conta.

2) The other thing that got me thinking is this. I'm allowing a total of 6 pictures for the custom multiple images. If the user puts up 3 right now and tomorrow adds the other images, admin will not receive an email about that. It's a bit important to know when the client adds pictures or changes them. How can we notify the admin of such things?

#1246720

Shane
Supporter

Idiomas: Inglés (English )

Zona horaria: America/Jamaica (GMT-05:00)

Hi Felipe,

I've added this code as well for when the user clicks the add new button.

jQuery( ".js-wpt-repadd " ).click(function() {
  jQuery('input:radio[name=wpcf-trocar-perfil]').filter('[value=1]').prop('checked', true);
});

Thanks,
Shane