<?php
/**
 * It helper of global helper for both version.
 *
 * @package  vitepos
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

if ( ! defined( 'APPSBD_ISPOSTBACK' ) ) {
	define( 'APPSBD_ISPOSTBACK', strtoupper( $_SERVER['REQUEST_METHOD'] ) == 'POST' );
}

if ( ! function_exists( 'APBD_PostValue' ) ) {
	/**
	 * The APBD PostValue is generated by appsbd
	 *
	 * @param mixed $index It is index.
	 * @param null  $default It is default.
	 *
	 * @return mixed|string|null
	 */
	function APBD_PostValue( $index, $default = null ) {
		if ( ! isset( $_POST[ $index ] ) ) {
			return $default;
		} else {
			return sanitize_text_field( $_POST[ $index ] );
		}
	}
}
if ( ! function_exists( 'vitepos_is_api_request' ) ) {
	/**
	 * Checks if the current request is a WP REST API and vitepos api call or not.
	 *
	 * @param string $base_route Its the base route to check.
	 *
	 * @return bool
	 */
	function vitepos_is_api_request( $base_route = 'vitepos/v1/' ) {
		if ( vitepos_is_rest() ) {
			$current_url = wp_parse_url( add_query_arg( array() ) );
			$is_exists   = strpos( $current_url['path'], $base_route );
			return false !== $is_exists && ! is_null( $is_exists );
		}

		return false;
	}
}
