Change default child theme directory for form templates
This topic contains 7 replies, has 2 voices, and was last updated by Stiofan O’Connor 7 years, 1 month ago.
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket-
AuthorPosts
-
October 17, 2017 at 1:29 pm #791
Issue carried forward from this WordPress forum –
Thank you, Stiofan!
This is what I understood and tried. (Does not work!) Can someone advise on the code please?
add_filter('uwp_templates_register','_my_uwp_template_change'); add_filter('uwp_templates_login','_my_uwp_template_change'); add_filter('uwp_templates_account','_my_uwp_template_change'); add_filter('uwp_templates_change','_my_uwp_template_change'); add_filter('uwp_templates_forgot','_my_uwp_template_change'); add_filter('uwp_templates_profile','_my_uwp_template_change'); function _my_uwp_template_change($template){ if (strpos($template, 'register') !== false) { $template = get_stylesheet_directory_uri() . '/newpath/userswp/register.php'; }elseif(strpos($template, 'login') !== false){ $template = get_stylesheet_directory_uri() . '/newpath/userswp/login.php'; }elseif(strpos($template, 'account') !== false){ $template = get_stylesheet_directory_uri() . '/newpath/account.php'; }elseif(strpos($template, 'change') !== false){ $template = get_stylesheet_directory_uri() . '/newpath/userswp/change.php'; }elseif(strpos($template, 'forgot') !== false){ $template = get_stylesheet_directory_uri() . '/newpath/userswp/forgot.php'; }elseif(strpos($template, 'profile') !== false){ $template = get_stylesheet_directory_uri() . '/newpath/userswp/profile.php'; } return $template; }
Kind regards
Abhijeet
October 17, 2017 at 6:35 pm #794Actually you were pretty close, just change
uwp_templates_
to (no s)
uwp_template_Stiofan 🙂
October 18, 2017 at 3:45 am #802Thank you Stiofan 🙂
I guess this time, it works till the point of picking up the new path. But after that, breaks down with something like this (message shown on browser when accessing login.php):
Fatal error: Uncaught Error: Call to undefined function do_action() in /home/directory/themes/child/newpath/userswp/login.php:1 Stack trace: #0 {main} thrown in /home/directory/themes/child/newpath/userswp/login.php on line 1
Not sure what went wrong. Do I need to change anything in the form itself?
Kind regards
Abhijeet
October 18, 2017 at 8:37 am #804Hi Abhijeet,
That is strange, its working for me, and do_action should always be defined unless you are calling the file direct.
If you can provide wp-admin details in a private reply i will take a look, also let me know where your code is located.
Thanks,
Stiofan
October 18, 2017 at 10:28 am #806Hi Stiofan,
Thank you. It is a staging area and I cannot share the admin details. I really appreciate the inputs and advise here. About your query, I am adding this code to a site-specific plugin.
I use a do_action () at the end of the code pasted above. I am not sure whether I have the correct hooks here (tried a few 🙂 ) after looking in the forms.
do_action('uwp_template_', $template);
Kind regards
AbhijeetOctober 18, 2017 at 11:14 am #808Yes you do not need a do_action in the snippet. Below is the exact code i tested with on my test site:
add_filter('uwp_template_register','_my_uwp_template_change'); add_filter('uwp_template_login','_my_uwp_template_change'); add_filter('uwp_template_account','_my_uwp_template_change'); add_filter('uwp_template_change','_my_uwp_template_change'); add_filter('uwp_template_forgot','_my_uwp_template_change'); add_filter('uwp_template_profile','_my_uwp_template_change'); function _my_uwp_template_change($template){ if (strpos($template, 'register') !== false) { $template = get_stylesheet_directory() . '/newpath/userswp/register.php'; }elseif(strpos($template, 'login') !== false){ $template = get_stylesheet_directory() . '/newpath/userswp/login.php'; }elseif(strpos($template, 'account') !== false){ $template = get_stylesheet_directory() . '/newpath/account.php'; }elseif(strpos($template, 'change') !== false){ $template = get_stylesheet_directory() . '/newpath/userswp/change.php'; }elseif(strpos($template, 'forgot') !== false){ $template = get_stylesheet_directory() . '/newpath/userswp/forgot.php'; }elseif(strpos($template, 'profile') !== false){ $template = get_stylesheet_directory() . '/newpath/userswp/profile.php'; } return $template; }
Stiofan
October 18, 2017 at 12:01 pm #809Thank you Stiofan!
I am building a site-plugin. I have two snippets that work and this is the third one. I do not know what went wrong the previous attempts when I tried coding it in [with and without the do_action()]. But this time, it worked! I do not know how to explain. Perhaps cache? Though I usually test incognito.
As I wrote in my 5-star review of UsersWP, I can not thank you enough! 🙂
Cheers
AbhijeetOctober 18, 2017 at 12:47 pm #810Great! 🙂
I’m glad you got it working and thank you very much for your review again 🙂Stiofan
-
AuthorPosts
We have moved to a support ticketing system and our forums are now closed.
Open Support Ticket