• Resolved janosklak

    (@janosklak)


    I think your plugin is great and uncomplicated because I can use an existing page as a coming soon page. Could I ask you to eliminate this error?

    Warning: Undefined array key 0 in /home/httpd/vhosts/badundraum.ch/boffi-sg.ch/wp-content/plugins/bw-coming-soon-page/includes/plugin-settings.php on line 11

    Please update your Plugin “Coming soon Page”. ??

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter janosklak

    (@janosklak)

    if ( ! function_exists('bwcs_redirection_process') ) {

    function bwcs_redirection_process()
    {
    // get options
    $is_enabled = ( ! empty( get_option( 'bwcs_enable_plugin' ) ) ) ? get_option( 'bwcs_enable_plugin' ) : 'enabled';
    $roles = ( ! empty( get_option( 'bwcs_roles' ) ) ) ? get_option( 'bwcs_roles' ) : array();
    $pages = ( ! empty( get_option( 'bwcs_other_pages' ) ) ) ? get_option( 'bwcs_other_pages' ) : array();
    $current_user = wp_get_current_user();
    $current_user_role = isset($current_user->roles[0]) ? $current_user->roles[0] : '';

    $current_page_id = get_queried_object_id();
    $coming_soon_page_id = get_option( 'bwcs_coming_soon_page' );
    $shop_page_id = get_option( 'woocommerce_shop_page_id' );

    // If options are not updated yet
    if ( empty( $coming_soon_page_id ) ) {

    $coming_soon_page_id = get_page_by_path( 'coming-soon' )->ID;

    }

    // Condition for shop page
    if ( empty( $shop_page_id ) ){

    $shop_page = false;

    }else{

    if ( ! function_exists('is_shop') ) {

    // nothing to do

    }elseif (is_shop() && in_array( $shop_page_id, $pages ) ) {

    $shop_page = true;

    }

    }

    if ( $is_enabled != 'disabled' ) {

    if ( in_array( $current_page_id, $pages ) ) {

    // no redirection

    }elseif ( in_array( $current_user_role, $roles ) || current_user_can( 'manage_options' ) ) {

    // no redirection

    }elseif ( $shop_page ) {

    // no redirection if shop page is selected

    }elseif( $current_page_id != $coming_soon_page_id ) {

    wp_redirect( get_permalink( $coming_soon_page_id ) );
    exit;
    }


    }
    }

    add_action( 'template_redirect', 'bwcs_redirection_process', 1 );
    }


    Thread Starter janosklak

    (@janosklak)

    To fix this bug, you should make sure that the array is not empty before accessing its elements. You can do this as follows:

    $current_user = wp_get_current_user();
    $current_user_role = isset($current_user->roles[0]) ? $current_user->roles[0] : '';

    This change first checks whether the array roles even has an element at position 0 before it is accessed. If the array is empty, an empty character string (”) is assigned.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Warning: Undefined array key 0 in’ is closed to new replies.