WordPress.org

Ready to get started?Download WordPress

Forums

W3 Total Cache
MFUNC still not working (42 posts)

  1. azn137
    Member
    Posted 1 year ago #

    So I did it like in the FAQ says, first I inserted this line

    define('W3TC_DYNAMIC_SECURITY', 'my_string');

    into my wp-config.php. Then, I modified my single.php to having this:

    <!-- mfunc {my_string} -->
    <?php get_sidebar(); ?>
    <!--/ mfunc {my_string} -->

    No dice. So I tried the other way

    <!-- mfunc {my_string} get_sidebar(); -->
    <!--/ mfunc {my_string} -->

    No luck either. Am I doing something wrong?

    http://wordpress.org/extend/plugins/w3-total-cache/

  2. senator94
    Member
    Posted 1 year ago #

    Same here...

    I tried different combinations but it is not working.

  3. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

    Please try like this: <!-- mfunc my_string -->

    Will improve the description in the next update.

  4. senator94
    Member
    Posted 1 year ago #

    Awesome...

    It is working thanks

  5. azn137
    Member
    Posted 1 year ago #

    Nope. That blew it up badly. http://i.imgur.com/epTsCVp.png

  6. senator94
    Member
    Posted 1 year ago #

    Actually...it is not working....

    I ran different test in different browsers. The my_string was exposed in my HTML code. The mfunc did not work.

  7. Sean Donovan
    Member
    Posted 1 year ago #

    It has worked for me. If you are seeing my_string exposed, then it means W3_total_cache is not seeing your code and replacing it. Are you sure you have the plugin enabled, preview mode disabled and page caching enabled?

  8. Sean Donovan
    Member
    Posted 1 year ago #

    (oops, a duplicate because of a 503 error with the WP.org server)

  9. Nic Windley
    Member
    Posted 1 year ago #

    From test I've done it may depend if you're using it with Cloudflare or not;

    This is the correct syntax when you are not using Cloudflare.

    <!-- mfunc THE CODE WITHOUT PHP TAGS -->
    <?php THE CODE ?>
    <!-- /mfunc -->

    Cloudflare will cause the page to fail to render when it hits the php code so you wouold be better off using mclude.

  10. azn137
    Member
    Posted 1 year ago #

    @Nic Windley: good debugging. That snippet seems to work.

    <!-- mfunc THE CODE WITHOUT PHP TAGS -->
    <?php THE CODE ?>
    <!-- /mfunc -->

    So, the bottom line is that the added security didn't take effect?

  11. kokoschka
    Member
    Posted 1 year ago #

    I just tried mfunc snippet as posted above, but it still does not seem to work. I have googled for hours but can't find any definite answer on how to get page fragment caching to work.

    This does not work for me:

    <!-- mfunc echo date('h:i:s'); -->
    <?php echo date('h:i:s'); ?>
    <!-- /mfunc -->

    I tried lots of different mfunc snippets but did't get it to work. Defining 'W3TC_DYNAMIC_SECURITY' in my wp-config.php does not help either.

    I use page cache (disk enhanced), database cache (APC) and object cache (APC), and I've already tried switching page cache to disk:basic or APC, but nothing seems to work.

  12. azn137
    Member
    Posted 1 year ago #

    *sigh* I can confirm that it still doesn't work either. My Jetpack Twitter feed doesn't seem to update.

    My current workaround is set the page cache to be 43200, which is 12 hours, which is nowhere near perfect :(

  13. senator94
    Member
    Posted 1 year ago #

    I tried a lot of combinations but none seem to take when I start testing. I tested it on different browsers logged out. The mfunc snippet is all exposed.

  14. mbrinson
    Member
    Posted 1 year ago #

    Hallelujah! That worked for me!
    @kokoschka - It looks like you're still leaving out the security_string part of the <!-- mfunc --> deal.

    Here's what worked for me:

    Added this line of code to the wp-config.php file in the root of the wordpress installation:
    define('W3TC_DYNAMIC_SECURITY', 'mysecretcode');

    Then used this code where I wanted the PHP to be run un-cached:

    <!-- mfunc mysecretcode -->
      echo 'testing php execution';
      x = 10;
      echo x;
      whatever php code you want
    <!-- /mfunc mysecretcode -->

    Remember, the <!-- mfunc --> comments actually REPLACE the <?php ?> tags. Kokoschka appears to be including the <?php ?> tags within the <!-- mfunc --> tags which is not how it works.

  15. geerthoekzema
    Member
    Posted 1 year ago #

    It's not working for me.
    The mfunc function never seems to work correct with me... and i've tried every combination possible.

    What i've done so far:

    1.
    <!-- mfunc mysecret mother_off_all_forms(); --><!-- /mfunc mysecret -->
    
    2.
    <!-- mfunc mysecret echo mother_off_all_forms(); --><!-- /mfunc mysecret -->
    
    3.
    <!-- mfunc mysecret -->mother_off_all_forms();<!-- /mfunc mysecret -->
    
    4.
    <!-- mfunc mysecret --><?php mother_off_all_forms();?><!-- /mfunc mysecret -->
    
    5.
    <!-- mfunc mysecret mother_off_all_forms --><?php mother_off_all_forms(); ?><!-- /mfunc mysecret -->
    
    6.
    <!-- mfunc mysecret  function1() --><?php function2() ?><!-- /mfunc mysecret -->

    #4 and #5 are returning the function, but it is not excluded from the cache.

    #1 and #2 are only returning the function when im logged in, when i'm logged out there is no result

    #3 is just showing the text.

    I'm kind a frustrated. The whole mfunc function seems to be buggy, because it never works as described in de FAQ.

    Update with #6
    When i'm logged in (= page cache off), function 1 is being executed. When I'm logged of (= page cache on), function 2 is executed (and is cached).

  16. senator94
    Member
    Posted 1 year ago #

    Same here...I tried a lot of different combinations and can never get it to work when I log out of WordPress.

  17. nattila
    Member
    Posted 1 year ago #

    It's so strange, the following code works, but my function returns with an empty page on the second pageload (when the content is coming from cache). Do you have any idea what is the difference?

    <!-- mfunc mystring echo date('h:i:s'); -->
    <?php echo date('h:i:s'); ?>
    <!-- /mfunc mystring -->

    the following code doesn't work

    <!-- mfunc mystring setPostViews(get_the_ID()); -->
    <?php setPostViews(get_the_ID()); ?>
    <!-- /mfunc mystring -->
  18. mbrinson
    Member
    Posted 1 year ago #

    I've been running into the same behavior. Unfortunately I don't have a solution to post, just confirming that you're not alone.
    However, now it's working. I swear I didn't change anything, but maybe I did and forgot. Who knows.
    It seems to be sporadic and I'm afraid it will crop up again as an issue for me.

  19. mbrinson
    Member
    Posted 1 year ago #

    I just checked on the site I was having this issue with and sure enough it's a problem again. Darn it.
    I'm just going to have to forget about fragment caching this for now until this gets resolved (if it ever does).

    If Frederick Townes is interested (or anyone else who is smart enough to be able to contribute to the W3TC plugin) I can make the site I'm experiencing this on available as a case study. Just let me know.

    One thing I have just noticed is that it only seems to happen with the home page. So the behavior is:
    Visit the home page for the first time - loads fine. Refresh that page and you get the white screen of death. Continuous attempts and ctrl+f5 - still get white screen.
    Visit any other pages of the site (that use the same fragment caching coding) and they all load fine. Refresh - no problem.

  20. geerthoekzema
    Member
    Posted 1 year ago #

    Hi Frederick,

    Is there any news on this issue? Are we doing anything wrong? I do have two sites with this issue now. Please response.

  21. abecoffman
    Member
    Posted 1 year ago #

    I tried this on my localhost and it worked:

    -- wp-config.php
    define('W3TC_DYNAMIC_SECURITY', 'FRAGMENT_CACHING');

    -- theme files

    <!-- mfunc FRAGMENT_CACHING -->
        echo "Not being cached"
    <!-- /mfunc FRAGMENT_CACHING -->

    When it's in production, it doesn't work. The cached pages get built without the dynamic content but the content of the comment doesn't show up in the html source code.

  22. abecoffman
    Member
    Posted 1 year ago #

    So I got it working by switching Page Caching to Disk:Basic and checking the Use Late "Init" checkbox. I guess I probably should have read the line "Adds support for use of WordPress functionality in fragment caching calls" sooner.

  23. squrler
    Member
    Posted 1 year ago #

    Hey there,

    Haven't tried abecoffman's workaround yet so I can't comment on that, but I would very very much like a good, stable fix for this functionality. It is absolutely essential functionality.

    Thanks to Frederick for your work!

  24. Frederick Townes
    Member
    Plugin Author

    Posted 1 year ago #

    If you use Disc:Enhanced have you tried deleting the cache/page_enhanced/yoursite folder manually through FTP? the cache engine stores .old files so it can load old pages when rebuilding new ones. However it takes some time before those are removed so can create conflict with fragment cache. This is because the old cache files are loaded instead of the new ones.

    Also if you use fragment cache on all pages its not recommended to use Disc:Enhanced since fragment cache with Disc:Enhanced prevents caching of pages.

  25. abecoffman
    Member
    Posted 1 year ago #

    For those of you who are interested, you can go look at the regex that's being used to extract the code out of the html comment. The issue I was having was determining when this code executes, which Frederick seems to have cleared up.

  26. Airic
    Member
    Posted 1 year ago #

    Hi,

    Has someone found a way to use mfunc ? I tried different possibilities to get my ads rotate but always not working...
    My ads code in page is: <?php wpads('article'); ?>

    If someone have an idea...

  27. geerthoekzema
    Member
    Posted 1 year ago #

    Hi Frederick,

    Thnx for your reply.

    Unfortunately it didn't work out. There are no .old files, so no need to delete those. I've tried basic and enhanced cache. The first one with and without the late init option one.

    What am I missing?

  28. geerthoekzema
    Member
    Posted 1 year ago #

    I'm getting a bit frustrated...

    I really appreciate this plugin, but when the fragment caching is not working, some of my sites are not working correctly.

    If there is anyway to get more support, i'd like to know.

  29. donwilson
    Member
    Posted 1 year ago #

    We just updated to 0.9.2.11 and our mclude calls are still being ignored (they show up as HTML comments in the minified HTML).

    Something isn't looping over the HTML content after it's pulled from cache and processing the fragmented code blocks before sending it to the browser.

  30. glinch
    Member
    Posted 1 year ago #

    I would also like to chip in that I'm also struggling to get this to work, which is quite a problem for me on a few sites. Still a great plugin I just need to get this functionality working.

    Im using WP 3.5.1 and version 0.9.2.11, Using Disc:Basic & also Use late "init".

    Have tried different combinations of mfunc code, as I'm sure everybody else has, but the output still gets cached.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic