Change default child theme directory for form templates

This topic contains 7 replies, has 2 voices, and was last updated by  Stiofan O’Connor 6 years, 6 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #791

    Backpacking Series
    Buyer
    Post count: 104

    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

    #794

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Actually you were pretty close, just change
    uwp_templates_
    to (no s)
    uwp_template_

    Stiofan 🙂

    #802

    Backpacking Series
    Buyer
    Post count: 104

    Thank 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

    #804

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Hi 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

    #806

    Backpacking Series
    Buyer
    Post count: 104

    Hi 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
    Abhijeet

    #808

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Yes 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

    #809

    Backpacking Series
    Buyer
    Post count: 104

    Thank 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
    Abhijeet

    #810

    Stiofan O’Connor
    Site Admin
    Post count: 22956

    Great! 🙂
    I’m glad you got it working and thank you very much for your review again 🙂

    Stiofan

Viewing 8 posts - 1 through 8 (of 8 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket