MVT:CALL to WP Page Content
<?php
/*******
THIS PAGE LIVES IN :
htdocs/mwp/mivapage/
********/
$directory = dirname(__FILE__);
preg_match('/(.*)mwp\//i' , $directory , $matches);
$wpLoadFilePath = $matches[0] . 'wp-load.php';
$pageFile = $directory . '/pages/' .$_GET['pg']. '.php';
if(isset($_GET['pg']) && !isset($_GET['update']) && file_exists($pageFile)){
include $pageFile;
//we get the local version 'cached'
die();
}
elseif(isset($_GET['pg']) && isset($_GET['update'])){
if(file_exists($wpLoadFilePath)){
require_once $wpLoadFilePath;
if(isset($_GET['pg']) && !empty($_GET['pg'])){
$mypage = get_post($_GET['pg']);
if(!empty($mypage)){
ob_start();
?>
<style>
img.alignleft,
img.alignright,
img.aligncenter,
img.alignnone{
max-width: 100%;
height: auto;
margin:0 auto 1em;
display: block;
}
@media screen and (min-width: 767px){
.alignleft{
float:left;
}
img.alignleft{
margin:0 1em 1em 0;
}
img.aligright{
margin:0 0px 1em 1em;
}
}
</style>
<?
echo apply_filters('the_content', $mypage->post_content );
$content = ob_get_contents();
ob_end_clean();
$myfile = fopen($pageFile, "w");
fwrite($myfile, $content);
fclose($myfile);
// we don't echo anything, we just write to file
die();
}
}
}
}
else{
if(file_exists($wpLoadFilePath) && !isset($_GET['update'])){
require_once $wpLoadFilePath;
if(isset($_GET['pg']) && !empty($_GET['pg'])){
$mypage = get_post($_GET['pg']);
if(!empty($mypage)){
ob_start();
?>
<style>
img.alignleft,
img.alignright,
img.aligncenter,
img.alignnone{
max-width: 100%;
height: auto;
margin:0 auto 1em;
display: block;
}
@media screen and (min-width: 767px){
.alignleft{
float:left;
}
img.alignleft{
margin:0 1em 1em 0;
}
img.aligright{
margin:0 0px 1em 1em;
}
}
</style>
<?
echo apply_filters('the_content', $mypage->post_content );
$content = ob_get_contents();
ob_end_clean();
$myfile = fopen($pageFile, "w");
fwrite($myfile, $content);
fclose($myfile);
// we write to file and then echo
echo $content;
die();
}
}
}
}
<?php
//the cached file is refreshed when the page is updated
add_action('save_post_page', function($post_ID, $post, $update){
$remotePageUpdate = home_url().'/mivapage/?pg='.$post_ID.'&update=1';
wp_remote_get($remotePageUpdate , array());
},10000,3);