<?php

/**
 * Publish/unpublish the client area
 *
 * This function will, depending on the website package, publish or unpublish
 * the client area. This is to prevent the wrong packages being able to access 
 * the client area. For whatever reason, likely the order or events on the 
 * WordPress query, this function wouldn't work using has_newsletter() function 
 * so the website package has to be coded here too.
 *
 * @function update_client_area_status()
 *
 * @uses wp_update_post()
 *
 * @param (string) $status the website package title
 *
 * @return N/A
 *
 * @since 1.0.0 
 *
 */
function update_client_area_status( $status ) {
	
	if ( ! mtd_enabled() ) {

		wp_update_post( array( 'ID' => 197, 'post_status' => 'draft' ) );
		wp_update_post( array( 'ID' => 199, 'post_status' => 'draft' ) );
		wp_update_post( array( 'ID' => 201, 'post_status' => 'draft' ) );
	} else {

		wp_update_post( array( 'ID' => 197, 'post_status' => 'publish' ) );
		wp_update_post( array( 'ID' => 199, 'post_status' => 'publish' ) );
		wp_update_post( array( 'ID' => 201, 'post_status' => 'publish' ) );
	}
}



/**
 * Removes the client area pages from WP admin
 *
 * This function removes the client area pages from WordPress admin if the
 * website package doesn't include them.
 *
 * @function exclude_client_area_from_admin()
 *
 * @uses mtd_enabled()
 *
 * @param (object) $query the WordPress query object
 *
 * @return (object) the altered object
 *
 * @since 1.0.12 
 *
 */
function exclude_client_area_from_admin( $query ) {
	
    if ( ! mtd_enabled() ) {
		
        $query->query_vars['post__not_in'] = array( 197, 199, 201 ); // client area, kashflow, openspace
		return $query;
    }
}
add_filter( 'parse_query', 'exclude_client_area_from_admin' );



/**
 * Returns the IRIS OpenSpace login portal
 *
 * This function returns the IRIS OpenSpace login portal from the template part 
 * in the WordPress theme.
 *
 * @function add_openspace_portal()
 *
 * @uses get_template_part()
 *
 * @param N/A
 *
 * @return (string) the IRIS OpenSpace login portal
 *
 * @since 1.0.0 
 *
 */
function add_openspace_portal() {
	
	if ( mtd_enabled() ) {
		
		ob_start();
		
		get_template_part( 'templates/login', 'openspace' );
		
		return ob_get_clean();
	}
	return false;
}
add_shortcode( 'openspace', 'add_openspace_portal' );



/**
 * Returns the IRIS KashFlow login portal
 *
 * This function returns the IRIS KashFlow login portal from the template part 
 * in the WordPress theme.
 *
 * @function add_kashflow_portal()
 *
 * @uses get_template_part()
 *
 * @param N/A
 *
 * @return (string) the IRIS KashFlow login portal
 *
 * @since 1.0.0 
 *
 */

function add_kashflow_portal() {
	
	if ( mtd_enabled() ) {
		
		ob_start();
		
		get_template_part( 'templates/login', 'kashflow' );
		
		return ob_get_clean();
	}
	return false;
}
add_shortcode( 'kashflow', 'add_kashflow_portal' );