make custom ajax callbacks survive to plugin updates: RESOLVED – UserPro Forums https://forum.userproplugin.com/forums/topic/make-custom-ajax-callbacks-survive-to-plugin-updates-resolved/feed/ Sun, 05 May 2024 07:15:08 +0000 https://bbpress.org/?v=2.6.2 en-US https://forum.userproplugin.com/forums/topic/make-custom-ajax-callbacks-survive-to-plugin-updates-resolved/#post-44896 <![CDATA[make custom ajax callbacks survive to plugin updates: RESOLVED]]> https://forum.userproplugin.com/forums/topic/make-custom-ajax-callbacks-survive-to-plugin-updates-resolved/#post-44896 Thu, 11 Dec 2014 09:47:13 +0000 Mad Max Customizable ajax callback on fields is great: you can add custom fields, so it’s great you can add custom validation on them. Modify plugin core files to add custom validation instead, is a great no-no from my point of view. Modifications don’t survive plugin updates and keep track of this sort of problems when you are a developer with tens of WP site to mantain, is a real nightmare.
So here I’m trying to give my contribution, posting a simple solution that seems to work perfectly in my tests; I hope userpro developers will consider to add this little, little code modification to the next release of the plugin.

Modify the function userpro_side_validate() (line 606 of the famous ajax.php file), and just add this few lines of code at the end of the function, before the $output is json_encoded, i.e. on line 662:

here is the gist with the whole function:
https://gist.github.com/w3b-beweb/9afcbaf70a45773b548e

Now you can add filters in your functions.php with custom validation code, and it will survive the updates.

For example, let say I need to validate a new username as an italian cell number. So I have to check that the username is not already taken and has the form of a cell number. I can add a custom ajax callback check on the username field of my registgration form, for example username_exists_as_cell_phone and then add this code to my functions.php:

You can find the code on the same gist as above, in the comments
https://gist.github.com/w3b-beweb/9afcbaf70a45773b548e

Just remember to return $output at the end!

Hope this addition can make its way through the plugin code asap.

]]>
https://forum.userproplugin.com/forums/topic/make-custom-ajax-callbacks-survive-to-plugin-updates-resolved/#post-44971 <![CDATA[Reply To: make custom ajax callbacks survive to plugin updates: RESOLVED]]> https://forum.userproplugin.com/forums/topic/make-custom-ajax-callbacks-survive-to-plugin-updates-resolved/#post-44971 Sun, 14 Dec 2014 01:25:05 +0000 Steve Kim Hi!

I love the tutorial and definitely going to use it.

I have a quick question tho.

So, you know how there are two tabs in the profile? (Following and Follower).

When it is clicked, an user is redirected to “Following” or “Follower” page?

Well, I find it very inconvenient just to see these information.

I want to make it so that when it is clicked, it simply switches over to the tab instead of redirecting.

Would you happen to know how to do it?

Thanks!

]]>
https://forum.userproplugin.com/forums/topic/make-custom-ajax-callbacks-survive-to-plugin-updates-resolved/#post-45672 <![CDATA[Reply To: make custom ajax callbacks survive to plugin updates: RESOLVED]]> https://forum.userproplugin.com/forums/topic/make-custom-ajax-callbacks-survive-to-plugin-updates-resolved/#post-45672 Thu, 22 Jan 2015 13:06:33 +0000 XMSchulte Nice,
what about the ID 039? Can I use any number? Does each field have its own ID? How do I know which number to choose?
Thanks
Dirk

]]>