The easiest way:
只需将以下内容作为代码的包装,以避免人们看到您所做的事情:
// Add Template comment here and assign your test template to a \'private\' page.
/*
Template Name: TESTTEMPLATE
*/
// Here we start with the template part that only admins can see:
if ( current_use_can( \'administrator\' )
{
// DO STUFF HERE
// after the following line everything is public again.
}
else
{
// ADDITIONAL: redirect to home
// http://codex.wordpress.org/Function_Reference/wp_redirect
wp_redirect( home_url() );
// could also be the last page
// $redirectURL = trim ($_SERVER[\'REQUEST_URI\']);
// wp_redirect( $redirectULR );
exit;
}