0

I am redesigning a template. So I am trying to show a holding page till the redesign process is done.

I ever used following function for the purpose on many other projects and it's redirected to the holding.php if the user is not an Admin

add_action( 'template_redirect', function() { if( !current_user_can( 'manage_options' ) ) { include( get_template_directory() . '/holding.php' ); exit; } });

But when I try to put this code on my current redesigning project it's shows a blank page if I go to the home page or any other page. if I remove the above code from function.php the site works fine.

And I've noted that this current projects' all php file has /** * @package WordPress * @subpackage Starkers */

my theme folder contains WordPress, Starkers too I thought it's commented out. so it does nothing.

Those lines are included every files such as index.php, function.php, etc

Why it's showing a blank page if I add the redirection function as I mentioned below.?? Any help will be appreciated.

[UPDATE] when I enable the debug i got the following lines.

Notice: load_plugin_textdomain was called with an argument that is deprecated since version 2.7 with no alternative available. in /home/supgower/public_html/wp-includes/functions.php on line 3008

Notice: date_default_timezone_set() [function.date-default-timezone-set]: Timezone ID 'UTC-1' is invalid in /home/supgower/public_html/wp-content/plugins/event-calendar/tz.php on line 27

Notice: date_default_timezone_set() [function.date-default-timezone-set]: Timezone ID 'UTC-1' is invalid in /home/supgower/public_html/wp-content/plugins/event-calendar/tz.php on line 27

Notice: wp_enqueue_script was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in /home/supgower/public_html/wp-includes/functions.php on line 3049

Notice: wp_enqueue_style was called incorrectly. Scripts and styles should not be registered or enqueued until the wp_enqueue_scripts, admin_enqueue_scripts, or login_enqueue_scripts hooks. Please see Debugging in WordPress for more information. (This message was added in version 3.3.) in /home/supgower/public_html/wp-includes/functions.php on line 3049

2
  • 2
    Please add debug information to your question to make answers possible.
    – fuxia
    Commented Mar 18, 2014 at 7:32
  • @toscho I've updated the question with the debug message Commented Mar 18, 2014 at 7:39

1 Answer 1

0

Have you tried this:

<?php
add_action( 'template_redirect', 'wp138320_template_redirect' );

function wp138320_template_redirect()
{
    if ( ! current_user_can( 'manage_options' ) )
    {
        include( get_template_directory() . '/holding.php' );
        exit;
    }
}
?>

I'm currently working on a site that has issues with hooking into actions/filters like that too, changing it to something like the code above did the trick in that install.

---- edit: Using the hook @Pieter mentions:

<?php
add_filter( 'template_include', 'wp138320_template_include' );

function wp138320_template_include( $template )
{
    if ( ! current_user_can( 'manage_options' ) )
    {
        if ( '' != locate_template( 'holding.php' ) )
            return 'holding.php'; // holding.php should be in the root of your theme's folder
    }

    return $template;
}
?>
4
  • don't use template_redirect to call a template, rather use template_include. See this post wordpress.stackexchange.com/questions/137247/… Commented Mar 18, 2014 at 9:43
  • @Hiranthi Thanks a lots.. it's working like a charm.. but how.?? I do not understand.. function is same.. is not it? Commented Mar 18, 2014 at 10:08
  • @PieterGoosen thanks for that! I really need to dive into core more often.. :)
    – Hiranthi
    Commented Mar 18, 2014 at 12:57
  • @RiffazStarr yes, the function is the same, but the way the function is being called (the way we're hooking into the action) is different.
    – Hiranthi
    Commented Mar 18, 2014 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.