• One of the options in UnderConstruction is:
    “Display the under construction page that is part of the active theme — ‘Only available for themes with an under-construction.php file'”

    This option is dimmed even when an under-construction.php file exists in an active child theme.

    Here’s how I patched it:

    In line 149 of ucOptions.php, change ‘get_template_directory()’ to ‘get_stylesheet_directory()’. This will cause UnderConstruction to look for the under-construction.php template in the active theme even if its a child theme.

    Cheers,

    https://ww.wp.xz.cn/plugins/underconstruction/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Nicely done. I was just looking for this solution myself. The full solution is this:

    To have it look in the child theme:
    line 149 of ucOptions, change to $current_theme_has_uc_page = file_exists(get_stylesheet_directory() . '/under-construction.php');

    and have it display the under-construction.php file on the child theme:
    line 125 of underConstruction, change to
    require_once(get_stylesheet_directory() . '/under-construction.php');

    A better solution (which can be implemented in a future update) is to check to see if the currently active theme is a child theme and contains the under-construction.php file like this:

    if (is_child_theme() && file_exists(get_stylesheet_directory() . '/under-construction.php')) {
    		$current_theme_has_uc_page = file_exists(get_stylesheet_directory() . '/under-construction.php');
    	} else {
    		$current_theme_has_uc_page = file_exists(get_stylesheet_directory() . '/under-construction.php');
    	}

    That would replace line 149 $current_theme_has_uc_page = file_exists(get_template_directory() . '/under-construction.php');

    And then for underConstruction.php, replace the following:

    if($this->displayStatusCodeIs(3)){
    						require_once(get_template_directory() . '/under-construction.php');
    						die();
    					}

    With this:

    if($this->displayStatusCodeIs(3)){
    	if ( is_child_theme() && file_exists(get_stylesheet_directory() . '/under-construction.php') ) {
    		require_once(get_stylesheet_directory() . '/under-construction.php');
    
    	} else {
    
    		require_once(get_template_directory() . '/under-construction.php');
    
    	}
    
    	die();
    }

    This will allow for the under-construction.php to live in either the parent or child and pull from the correct place. And if it’s a child theme without the underconstruction.php, it will look to see if it exists in the parent and use it instead.

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Using UnderConstruction in a child theme’ is closed to new replies.