Since precaching may take a very long time, it's done through a background CLI process in order not to run out of max execution time of PHP. Please enable one of the following functions if you whish to use precaching: " , $this->plugin_constant ) ?>shell_possibilities ); ?>
+
+
network ) {
+ /* list all blogs */
$blog_list = get_blog_list( 0, 'all' );
foreach ($blog_list as $blog) {
+ /* get permalinks for this blog */
$this->precache_list_permalinks ( $links, $blog['blog_id'] );
}
}
else {
+ /* no network, better */
$this->precache_list_permalinks ( $links, false );
}
+ /* temporary php file, will destroy itself after finish in order to clean up */
$tmpfile = tempnam(sys_get_temp_dir(), 'wp-ffpc');
+ /* double check if we do have any links to pre-cache */
if ( !empty ( $links ) ) :
+ /* this is the precacher php worker file: logs the links, their generation time and the generated content size
+ * writes the logfile and destroys itself afterwards
+ */
$out .= '';
file_put_contents ( $tmpfile, $out );
+ /* call the precache worker file in the background */
$shellfunction = $this->shell_function;
$shellfunction( 'php '. $tmpfile .' >'. $this->precache_logfile .' 2>&1 &' );
@@ -827,25 +873,29 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
*
*/
private function precache_list_permalinks ( &$links, $site = false ) {
+ /* $post will be populated when running throught the posts */
global $post;
include_once ( ABSPATH . "wp-load.php" );
+ /* if a site id was provided, save current blog and change to the other site */
if ( $site !== false ) {
$current_blog = get_current_blog_id();
switch_to_blog( $site );
}
+ /* get all published posts */
$args = array (
'post_type' => 'any',
'posts_per_page' => -1,
'post_status' => 'publish',
);
-
$posts = new WP_Query( $args );
+ /* get all the posts, one by one */
while ( $posts->have_posts() ) {
$posts->the_post();
+ /* get the permalink for currently selected post */
switch ($post->post_type) {
case 'revision':
case 'nav_menu_item':
@@ -864,12 +914,15 @@ if ( ! class_exists( 'WP_FFPC' ) ) {
break;
}
+ /* collect permalinks */
$links[] = $permalink;
}
+ /* just in case, reset $post */
wp_reset_postdata();
+ /* switch back to original site if we navigated away */
if ( $site !== false ) {
switch_to_blog( $current_blog );
}