-
-
Notifications
You must be signed in to change notification settings - Fork 24
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
Refactor JS snippet to use WP AJAX #109
Conversation
The custom GET request intercepts normal page generation and might trigger other plugins' actions before Statify is loaded. It also provided an open door for lightweight malicious requests targeting the statistics. Using WP AJAX including Nonce verification reduces both problems.
statify.php
Outdated
@@ -20,6 +20,7 @@ | |||
define( 'STATIFY_FILE', __FILE__ ); | |||
define( 'STATIFY_DIR', dirname( __FILE__ ) ); | |||
define( 'STATIFY_BASE', plugin_basename( __FILE__ ) ); | |||
define( 'STATIFY_VERSION', '1.6.3' ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be 1.7.0?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Absolutely (if we don‘t add this to 1.6.x - and I don‘t think so - or postpone this to 1.8 obviously)
/** | ||
* Track the page view via AJAX. | ||
* | ||
* @return void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my mind there is not helpful. Also the hint on phpdoc - This tag should not be used for constructors or methods defined with a void return type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using this tag in 15 places... Apparently all introduced by myself (default pattern in my IDE because it's mandatory in most of my styleguides - and btw. the PHPdoc ref marks this as "MAY be omitted").
We shouldn't mix it up, so either remove all or none.
Along with some int(eger) and bool(ean) tags probably little out of scope of this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, plugincollektiv need a style guide, simplest way is the WP codex. In this context it is only a hint and the result of different views, works outside of the pluginkollektiv projects. Feel free to leave that or remove all ;)
Hi @stklcode |
d97f297
to
7705dff
Compare
The current JavaScript tracking method issues a GET-request to the home page with two parameters,
statify_referrer
andstatify_target
. As a result the usual WP page is processed, due to the parameters without caching (at least with the most comon caching plugins).As mehtioned in #100 the tracking call might take long time depending on the actual setup (seen times up to 2s). That's because the request is intercepted and completed after Statify has been intialized. And that is typically not the first plugin loaded.
This PR replaces the custom GET tracking method by a POST call to a WP AJAX action. On AJAX calls the overhead is far less than on actual page generation, because many plugins opt-out immediately.
PS: I already tagged some changes in the PHP code with
@since 1.7.0
, because I don't see this change to appear in any 1.6.x release obviously. Doesn't mean anything however, might be rescheduled to any milestone 😃