Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Akismet comment nonce is not automatically disabled #642

Closed
Kalfer opened this issue Dec 25, 2015 · 10 comments
Closed

Bug: Akismet comment nonce is not automatically disabled #642

Kalfer opened this issue Dec 25, 2015 · 10 comments
Labels
bug
Milestone

Comments

@Kalfer
Copy link

@Kalfer Kalfer commented Dec 25, 2015

Hey there

I upgraded to Pro v151220 ZenCache, and I found that the Akismet (3.1.6) plugin also causes the issue #601.

Thank you

@raamdev
Copy link
Contributor

@raamdev raamdev commented Dec 26, 2015

@Kalfer ZenCache Pro v151220 automatically detects when the HTML contains _wpnonce or akismet_comment_nonce and prevents that page from being cached. When this happens, you should see a note at the very bottom of the source code (when you View Source on the page) that indicates as much (assuming you have ZenCache HTML Notes enabled in ZenCache → Plugin Options → Enable/Disable).

Is that not happening? Can you explain the problem you're having with the Akismet plugin and ZenCache?

@Kalfer
Copy link
Author

@Kalfer Kalfer commented Dec 26, 2015

Yes, I saw that message at the end of my web source code.

Now I have Akismet disabled. Is there any alternative to Akismet?

Thanks

El 26 dic 2015, a las 14:30, Raam Dev notifications@github.com escribió:

@Kalfer https://github.com/Kalfer ZenCache Pro v151220 automatically detects when the HTML contains _wpnonce or akismet_comment_nonce and prevents that page from being cached. When this happens, you should see a note at the very bottom of the source code (when you View Source on the page) that indicates as much (assuming you have ZenCache HTML Notes enabled in ZenCache → Plugin Options → Enable/Disable).

Is that not happening? Can you explain the problem you're having with the Akismet plugin and ZenCache?


Reply to this email directly or view it on GitHub #642 (comment).

@raamdev
Copy link
Contributor

@raamdev raamdev commented Dec 26, 2015

@Kalfer ZenCache is supposed to disable the Akismet nonce when it detects that Akismet is active (see this line), but for some reason that's not working as expected. I just confirmed this on my own site and I'm still researching.

You should definitely be able to use Akismet and ZenCache together.

@raamdev raamdev added this to the Next Release (Pro) milestone Dec 26, 2015
@raamdev
Copy link
Contributor

@raamdev raamdev commented Dec 26, 2015

Problem Found: Akismet Bug

This is actually a bug in the way Akismet checks the value of $akismet_comment_nonce_option on this line.

Akismet is using == (simple equality operator) instead of === (strict type comparison operator) when checking if $akismet_comment_nonce_option == '', so when a filter sets the value of $akismet_comment_nonce_option to boolean FALSE, the conditional still evaluates to true because == '' is the same as == FALSE.

If that line in Akismet is changed to $akismet_comment_nonce_option === '', then filtering $akismet_comment_nonce_option to return boolean FALSE works as expected, disabling that option.

Akismet Bug Report Opened

I've opened an Akismet bug report here: https://plugins.trac.wordpress.org/ticket/2467

@raamdev
Copy link
Contributor

@raamdev raamdev commented Dec 26, 2015

Temporary Fix for Site Owners

You can use an MU-Plugin to tell Akismet to disable the Akismet Nonce, which will allow ZenCache to continue caching pages even while Akismet is enabled. (This was the intended behavior all along, but due to the bug described above, it's not working as expected in the latest ZenCache release. This MU-Plugin returns a value to Akismet that works around the bug.)

Create this file and directory:
wp-content/mu-plugins/zc-disable-akismet-nonce.php

<?php
/*
Plugin Name: Disable Akismet Comment Nonce
Description: Disables the Akismet comment nonce; required for ZenCache
Author: WebSharks, Inc.
Version: 1.0
Author URI: http://zencache.com/
*/
add_filter('akismet_comment_nonce', function() {
    return 'not-true'; // MUST return a string literal; must not be 'true'. See http://bit.ly/1YItpdE
}, PHP_INT_MAX);
@raamdev
Copy link
Contributor

@raamdev raamdev commented Dec 26, 2015

How ZenCache can resolve this in the next release

If Akismet does not fix this issue by the next ZenCache release, we can temporarily work around this issue by returning something like 'not-true' (or '0'--as a string literal--, but that might be confusing and get refactored to return 0 which would introduce this issue again) instead of boolean FALSE.

The nice thing about returning something like 'not-true' is that it would continue to work as expected even after Akismet fixes the above issue.

@raamdev raamdev changed the title Akismet plugin also causes the issue #601 Bug: Akismet comment nonce is not automatically disabled Dec 26, 2015
@raamdev
Copy link
Contributor

@raamdev raamdev commented Dec 26, 2015

EDIT: Added PHP_INT_MAX to add_filter() in Temporary Workaround above.

@raamdev
Copy link
Contributor

@raamdev raamdev commented Dec 27, 2015

Note that this is not be changed/fixed in Akismet for backwards compatibility reasons; see this comment:

This is mostly a case of missing documentation meeting backwards compatibility.
In the interest of not breaking any implementations that have been written in the last five years, I've left the code as is but added explanatory documentation in r1316691. To disable the Akismet comment nonce, return any string value that is not 'true' or '' for the 'akismet_comment_nonce' filter. A good option would be the reason why the filter is disabled, like 'disabled-by-zencache'.

The reason that Akismet will still include the comment nonce even if the filter returns false is because originally, the nonce was controlled solely by the akismet_comment_nonce option, which could be set to (string) 'true' or (string) 'false'. If the get_option() call returned (boolean) false, that meant that no value had been set, so Akismet should just choose whatever the default behavior was, which meant including the nonce. The check for $akismet_comment_nonce_option == '' was meant to cover this case (but should have originally been $akismet_comment_nonce_option === false).


All that remains to close this issue is to change ZenCache so that it returns (string) 'disabled-by-zencache' instead of (boolean) false.

@raamdev
Copy link
Contributor

@raamdev raamdev commented Dec 31, 2015

Next Pro Release Changelog:

  • Akismet Compatibility: Fixed a bug with Akismet compatibility where ZenCache was not properly disabling the Akismet Comment Nonce, which resulted in pages being unnecessarily excluded from the cache due to the presence of the akismet_comment_nonce in the markup. Props @Kalfer. See Issue #642.
@raamdev raamdev closed this Dec 31, 2015
@raamdev raamdev removed the ready for work label Dec 31, 2015
@wpsharks wpsharks locked and limited conversation to collaborators Jan 3, 2016
@raamdev
Copy link
Contributor

@raamdev raamdev commented Jan 3, 2016

ZenCache Pro v160103 has been released and includes changes from this GitHub Issue. See the v160103 announcement for further details.


This issue will now be locked to further updates. If you have something to add related to this GitHub Issue, please open a new GitHub Issue and reference this one (#642).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants