Does Jetpack conflicts with load_template()?

admin2025-06-04  2

EDIT the title of this question was "Does anyone know if Jetpack is caching pages/content" but has been changed following the thread.

I just updated a plugin I made. Among others, it does filter the content of a page using the_content hook.

But I noticed that it does not behaves like it should once I pushed the changes online (some parts of my content are missing).

Once I do disable Jetpack, it works as expected.

Does anyone know if Jetpack is caching pages/content and how to clear that cache ?

I didn't find anything about it online.

Thanks !

EDIT the title of this question was "Does anyone know if Jetpack is caching pages/content" but has been changed following the thread.

I just updated a plugin I made. Among others, it does filter the content of a page using the_content hook.

But I noticed that it does not behaves like it should once I pushed the changes online (some parts of my content are missing).

Once I do disable Jetpack, it works as expected.

Does anyone know if Jetpack is caching pages/content and how to clear that cache ?

I didn't find anything about it online.

Thanks !

Share Improve this question edited Jan 24, 2019 at 22:00 gordie asked Jan 17, 2019 at 10:18 gordiegordie 4925 silver badges19 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 1

Does anyone know if Jetpack is caching pages/content

Jetpack does not cache the contents of your posts and pages.

Once I do disable Jetpack, it works as expected.

This seems like a conflict between how your code filters the_content, and the way one of the Jetpack features uses the same filter. I would recommend that you deactivate each Jetpack feature, one at a time, until you find the exact source of the conflict. You can then contact the Jetpack support team via this contact form to let them know about the conflict between the 2 plugins.

I found out that the bug occurs when Publicize connections is enabled in Jetpack, thanks to the advices of @jeherve.

Indeed, I have a function hooked on the_content and which appends content to a specific page :

add_filter( 'the_content','wpsstm_frontend_wizard_content');

function wpsstm_frontend_wizard_content($content){
    if ( !is_page(MYPAGEID) ) return $content;

    ob_start();
    wpsstm_locate_template( 'frontend-wizard.php', true);
    $wizard = ob_get_clean();
    return $content . $wizard;
}

The template is loaded through wpsstm_locate_template(); which calls the core function load_template():

/*
Locate a template & fallback in plugin's folder
*/
function wpsstm_locate_template( $template_name, $load = false, $require_once = true ) {

    if ( !$located = locate_template( 'wpsstm/' . $template_name ) ) {
        // Template not found in theme's folder, use plugin's template as a fallback
        $located = wpsstm()->plugin_dir . 'templates/' . $template_name;
    }

    if ( $load && ('' != $located) ){
        load_template( $located, $require_once );
    }

    return $located;
}

I fixed my problem by setting $require_once = false when I call wpsstm_locate_template() - and thus load_template():

wpsstm_locate_template( 'frontend-wizard.php', true, false);

I guess that Jetpacks 'runs' my filter before it is really displayed. Thus the file already has been loaded once and won't load again until $require_once is set to false.

I found out how to fix it but anyway, that seems to be a bug within Jetpack; or maybe I should handle this in another way. I'll write them.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748976613a315317.html

最新回复(0)