Last active
October 20, 2017 19:26
-
-
Save steveosoule/96ed597523f8285513cad95df0e94bef to your computer and use it in GitHub Desktop.
Miva WordPress Integrations Optimized
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* ------------------------ | |
* Basic Example | |
* ------------------------ | |
* No transients, no password-protection curl methods | |
*/ | |
echo file_get_contents("http://" . $hostname . "/mm5/merchant.mvc?Screen=WP-HEADER"); | |
/** | |
* ------------------------ | |
* Transient Example | |
* ------------------------ | |
*/ | |
/* | |
// Use WP Transients to cache the Miva WP-HEADER page | |
if ( false === ( $miva_wp_header = get_transient( 'miva_wp_header' ) ) ) { | |
$miva_wp_header = file_get_contents("http://" . $hostname . "/mm5/merchant.mvc?Screen=WP-HEADER"); | |
set_transient( 'miva_wp_header', $miva_wp_header, 6 * HOUR_IN_SECONDS ); | |
} | |
echo $miva_wp_header; | |
*/ | |
/** | |
* ------------------------ | |
* Password Protection CURL & Transient Example | |
* ------------------------ | |
*/ | |
/* | |
// 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_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 -->'; | |
} | |
// Output the Transiented or Newly cURL'd URL | |
echo $wp_header; | |
*/ | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment