countryCode ) ) { $country_code = sanitize_text_field( $body->countryCode ); } } } $redirect_url = esc_url( get_option( 'aa_block_redirect_url', site_url() ) ); // Per-post or custom post type logic if ( is_singular() ) { $post_id = get_queried_object_id(); $enabled = get_post_meta( $post_id, '_aa_block_enable', true ); $custom_blocked = get_post_meta( $post_id, '_aa_block_countries', true ); $custom_blocked = array_filter( array_map( 'trim', explode( ',', $custom_blocked ) ) ); if ( $enabled === '1' && in_array( $country_code, $custom_blocked, true ) ) { wp_redirect( $redirect_url ); exit; } } // Global fallback if ( get_option( 'aa_block_enabled', '1' ) === '1' ) { $global_blocked = array_map( 'trim', explode( ',', get_option( 'aa_block_countries', '' ) ) ); if ( in_array( $country_code, $global_blocked, true ) ) { wp_redirect( $redirect_url ); exit; } } } add_action( 'template_redirect', 'aa_block_country_check_and_redirect' ); // 3. META BOX FOR POSTS, PAGES, CUSTOM POST TYPES function aa_block_country_add_meta_box() { $post_types = get_post_types( [ 'public' => true ], 'names' ); foreach ( $post_types as $post_type ) { add_meta_box( 'aa_block_country_meta', 'AA Country Block Options', 'aa_block_country_meta_callback', $post_type, 'side' ); } } add_action( 'add_meta_boxes', 'aa_block_country_add_meta_box' ); function aa_block_country_meta_callback( $post ) { $enabled = get_post_meta( $post->ID, '_aa_block_enable', true ); $countries = get_post_meta( $post->ID, '_aa_block_countries', true ); wp_nonce_field( 'aa_block_country_meta_box', 'aa_block_country_meta_box_nonce' ); ?>

Comma-separated country codes (e.g., US,IN,FR)