<?php 
//CARD OPT FUNCTIONS

function has_card() {

	if ( is_package_1() || is_package_2()) {
		
		return false;
	}
	if( opt_card() ){
		return false;
	}
	return true;
	
}

function check_card_status() {
    
    // This is a WP Super Cache constant to prevent the newsletter page being cached.
    define( 'DONOTCACHEPAGE', true );
	// This is a Litespeed Cache constant to prevent the newsletter page being cached.
	define( 'LSCACHE_NO_CACHE', true );
	
	if( ! has_card() ) {
		
		wp_redirect( home_url( '404' ) );
		exit;
	}
}

//THIS BELOW FUNCTION IS REMOVED DUE TO WORDPRESS 6.1 UPDATE CONFLICT WITH THIS PARSE QUERY - ON 11-NOV-22
//function exclude_card_from_admin( $query ) {
//	$pageTitle = "Card";
//	$pageObject = get_page_by_title($pageTitle);
//	$pageobjID = $pageObject->ID;
//	
//    if ( ! has_card() ) {
//		
//        $query->query_vars['post__not_in'] = array($pageobjID); // card
//		return $query;
//    }
//}
//add_filter( 'parse_query', 'exclude_card_from_admin' );

function draft_card_status() {
	$pageTitle = "Card";
	$pageObject = get_page_by_title($pageTitle);
	$pageobjID = $pageObject->ID;
	
	if ( ! has_card() ) {
		
		wp_update_post( array( 'ID' => $pageobjID, 'post_status' => 'draft' ) );
		
	} else if ( has_card() ){

		wp_update_post( array( 'ID' => $pageobjID, 'post_status' => 'publish' ) );
	}
}

?>