<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 31/01/2019
 * Time: 4:07 CH
 */

namespace WACVP\Inc;

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

class Server_Cron {

	protected static $instance = null;

	private function __construct() {
		add_action( 'init', array( $this, 'receive_cron_request' ) );
	}


	public static function get_instance() {

		// If the single instance hasn't been set, set it now.
		if ( null == self::$instance ) {
			self::$instance = new self;
		}

		return self::$instance;
	}

	public function receive_cron_request() {
		$data   = Data::get_params();
		$enable = $data['enable_cron_server'];
		if ( $enable ) {
			if ( isset( $_REQUEST['_wacv_admin_nonce'] ) && ! wp_verify_nonce( wc_clean( wp_unslash( $_REQUEST['_wacv_admin_nonce'] ) ), 'wacv_admin_nonce' ) ) {
				return;
			}
			if ( isset( $_GET['crtk'] ) && $_GET['crtk'] == get_option( 'wacv_cron_key' ) ) {
				file_get_contents( site_url() . '/wp-cron.php' );// phpcs:ignore WordPress.WP.AlternativeFunctions.file_get_contents_file_get_contents
				exit;
			}
		}
	}
}
