WordPress.org

Ready to get started?Download WordPress

Forums

HOWTO: WP-Cache Dynamic Content With Plugins Calls (1 post)

  1. marke1
    Member
    Posted 7 years ago #

    In checking into WP-Cache I noticed that the author said that while it's possible to keep parts of a page dynamic by using a special HTML comment wrapper around the functions, it's not possible to call WordPress plugin functions.

    Turns out this isn't the case. You can in fact call plugin functions in dynamic sections of a cached page. Here's how:

    <!--mfunc-->
    <?php
    // check to see if WP functions are loaded,
    // if not, load the main config file
    // Doing so also lets us call
    // plugin functions
    if (!function_exists('the_post')) {
       require_once(ABSPATH.'/wp-config.php');
    }
    // my dynamic content's plugin function:
    if (function_exists('my_plugin_function')) {
       my_plugin_function('parm1');
    }
    ?>
    <!--/mfunc-->

    The part that checks for 'the_post' does the work of letting us use plugins: If 'the_post' function doesn't exist then the wp-config.php file is loaded, which in turn loads all the required pieces to run any plugin.

    This is tested exactly as you see it there, and it works.

    Granted, it adds overhead because of loading wp-config.php, which in turns loads many other files, but at least it still lets caching work to reduce load where it can.

    FYI: The same should work with Staticize Reload caching plugin too.

    Have fun.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.