What's wrong with this code?
Gives an error when i try and add it as a plugin.
Also, any way of optimising it?
Thanks.
<?php
/*
Plugin Name: Site Block
Plugin URI:
Description: Block all for for logged-out users except for register pages
Version:
Author:
Author URI:
License:
License URI:
*/
function redirect_to_specific_page() {
if ( !is_user_logged_in() ) {
if ( !is_page ( array ( '916', '940', '1015', '1017', '1044', '1046', '1048', '1051', '1388' ) ) {
wp_redirect( 'http://www.example.com/login/', 302 );
exit;
}
}
if ( is_user_logged_in() && rcp_is_expired() ) {
if ( (rcp_get_subscription_id( $GLOBALS['user_ID'] ) == 1) || (rcp_get_subscription_id( $GLOBALS['user_ID'] ) == 2) || (rcp_get_subscription_id( $GLOBALS['user_ID'] ) == 3) || (rcp_get_subscription_id( $GLOBALS['user_ID'] ) == 7) || (rcp_get_subscription_id( $GLOBALS['user_ID'] ) == 8) ) {
if ( !is_page ( array ( '916', '940', '1015', '1017', '1044', '1046', '1048', '1289', '1291', '1322', '1051', '1388' ) ) {
wp_redirect ( 'http://www.example.com/expired1/', 302 );
exit;
}
}
if ( (rcp_get_subscription_id( $GLOBALS['user_ID'] ) == 4) || (rcp_get_subscription_id( $GLOBALS['user_ID'] ) == 5) || (rcp_get_subscription_id( $GLOBALS['user_ID'] ) == 6) ) {
if ( !is_page ( array ( '916', '940', '1015', '1017', '1044', '1046', '1048', '1289', '1291', '1217', '1051', '1388' ) ) {
wp_redirect ( 'http://www.example.com/expired2/', 302 );
exit;
}
}
}
}
add_action( 'template_redirect', 'redirect_to_specific_page' );
Kyle answers:
if ( !is_page ( array ( '916', '940', '1015', '1017', '1044', '1046', '1048', '1051', '1388' ) ) {
Should be
if ( !is_page ( array ( '916', '940', '1015', '1017', '1044', '1046', '1048', '1051', '1388' ) ) ) {
That needs to apply to all threee of the page checks
Kyle comments:
Also, replace the $GLOBALS['user_id'] stuff with
$user_id = get_current_user_id();