steveosoule
3/17/2017 - 11:37 PM

Miva WordPress Integrations Optimized

Miva WordPress Integrations Optimized

<?php
/**
 * Load In Miva's WP-HEADER Page
 */
$wp_header = get_transient( 'wp_header' );
$hostname = $_SERVER['SERVER_NAME'];

if( $wp_header === FALSE || isset($_REQUEST['update_miva_hdft']) )
{
	echo '<!-- !@! Updating WP-HEADER -->';
	// $wp_header = file_get_contents("http://" . $hostname . "/mm5/merchant.mvc?Screen=WP-HEADER");
	$wp_header_url = 'https://'.$hostname.'/mm5/merchant.mvc?Screen=WP-HEADER';

	// create a new cURL resource
	$ch = curl_init();

	// set URL and other appropriate options
	curl_setopt_array($ch, array(
		CURLOPT_URL => $wp_header_url,
		CURLOPT_USERPWD => 'super:secret',
		CURLOPT_RETURNTRANSFER => TRUE,
		CURLOPT_SSL_VERIFYHOST => 0,
		CURLOPT_SSL_VERIFYPEER => 0
	));

	// grab URL and return the content from the URL
	$wp_header = curl_exec($ch);

	// close cURL resource, and free up system resources
	curl_close($ch);

	// Save the URL's response in a WordPress Transient to speed-up future page-views
	set_transient( 'wp_header', $wp_header, 12*HOUR_IN_SECONDS );
} else {
	echo '<!-- !@! Transiented WP-HEADER -->';
}

?>
<?php

	/**
	 * Load In Miva's WP-FOOTER Page
	 */
	$wp_footer = get_transient( 'wp_footer' );
	$hostname = $_SERVER['SERVER_NAME'];

	if( $wp_footer === FALSE || isset($_REQUEST['update_miva_hdft']) )
	{
		echo '<!-- !@! Updating WP-FOOTER -->';
		// $wp_footer = file_get_contents("http://" . $hostname . "/mm5/merchant.mvc?Screen=WP-FOOTER");
		$wp_footer_url = 'https://'.$hostname.'/mm5/merchant.mvc?Screen=WP-FOOTER';

		// create a new cURL resource
		$ch = curl_init();

		// set URL and other appropriate options
		curl_setopt_array($ch, array(
			CURLOPT_URL => $wp_footer_url,
			CURLOPT_USERPWD => 'super:secret',
			CURLOPT_RETURNTRANSFER => TRUE,
			CURLOPT_SSL_VERIFYHOST => 0,
			CURLOPT_SSL_VERIFYPEER => 0
		));

		// grab URL and return the content from the URL
		$wp_footer = curl_exec($ch);

		// close cURL resource, and free up system resources
		curl_close($ch);

		// Save the URL's response in a WordPress Transient to speed-up future page-views
		set_transient( 'wp_footer', $wp_footer, 12*HOUR_IN_SECONDS );
	} else {
		echo '<!-- !@! Transiented WP-FOOTER -->';
	}

	// Output the Transiented or Newly cURL'd URL
	echo $wp_footer;

?>