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

[PR] Refactor codebase to remove unnecessary applyWpFilters() and doWpAction() #317

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitchange
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
1491589996
2ea258a033ce686450ef6bccbc0f66efdba74ac1:58ffb9673670b6.69941207
d0e05c36184f81b133761b71ca6ee0136be67409:5929bfd91e18f9.45059581
4 changes: 2 additions & 2 deletions src/includes/classes/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ protected function saveOptions($args)
if ($this->plugin->isApache() && !($add_wp_htaccess = $this->plugin->addWpHtaccess())) {
$query_args[GLOBAL_NS.'_wp_htaccess_add_failure'] = '1';
}
if ($this->plugin->isNginx() && $this->plugin->applyWpFilters(GLOBAL_NS.'_wp_htaccess_nginx_notice', true)
if ($this->plugin->isNginx() && apply_filters(GLOBAL_NS.'_wp_htaccess_nginx_notice', true)
&& (!isset($_SERVER['WP_NGINX_CONFIG']) || $_SERVER['WP_NGINX_CONFIG'] !== 'done')) {
$query_args[GLOBAL_NS.'_wp_htaccess_nginx_notice'] = '1';
}
Expand Down Expand Up @@ -669,7 +669,7 @@ protected function restoreDefaultOptions($args)
if ($this->plugin->isApache() && !($add_wp_htaccess = $this->plugin->addWpHtaccess())) {
$query_args[GLOBAL_NS.'_wp_htaccess_add_failure'] = '1';
}
if ($this->plugin->isNginx() && $this->plugin->applyWpFilters(GLOBAL_NS.'_wp_htaccess_nginx_notice', true)
if ($this->plugin->isNginx() && apply_filters(GLOBAL_NS.'_wp_htaccess_nginx_notice', true)
&& (!isset($_SERVER['WP_NGINX_CONFIG']) || $_SERVER['WP_NGINX_CONFIG'] !== 'done')) {
$query_args[GLOBAL_NS.'_wp_htaccess_nginx_notice'] = '1';
}
Expand Down
4 changes: 2 additions & 2 deletions src/includes/classes/AutoCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ protected function getSitemapUrlsDeep($sitemap, $___recursive = false)
if (!$this->plugin->autoCacheCheckXmlSitemap($sitemap, $___recursive, $this->is_child_blog)) {
goto finale; // Nothing we can do.
}
if (!$allow_url_fopen || $this->plugin->applyWpFilters(GLOBAL_NS.'_auto_cache_sitemap_force_wp_http_api', false)) { // Try the WP HTTP API instead.
if (!$allow_url_fopen || apply_filters(GLOBAL_NS.'_auto_cache_sitemap_force_wp_http_api', false)) { // Try the WP HTTP API instead.
$sitemap = $this->plugin->autoCacheWpRemoteGetXmlSitemap($sitemap);
}

Expand All @@ -289,7 +289,7 @@ protected function getSitemapUrlsDeep($sitemap, $___recursive = false)
unset($_sitemapindex_urls, $_urlset_urls);
}

if (!$allow_url_fopen || $this->plugin->applyWpFilters(GLOBAL_NS.'_auto_cache_sitemap_force_wp_http_api', false)) {
if (!$allow_url_fopen || apply_filters(GLOBAL_NS.'_auto_cache_sitemap_force_wp_http_api', false)) {
unlink($sitemap); // Delete temp file downloaded by cURL
}

Expand Down
2 changes: 1 addition & 1 deletion src/includes/classes/MenuPage/Options/HostExclusions.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct()
$exclude_hosts_option_enable = is_multisite() &&
((defined('SUBDOMAIN_INSTALL') && SUBDOMAIN_INSTALL) || $this->plugin->canConsiderDomainMapping());

if ($this->plugin->applyWpFilters(GLOBAL_NS.'_exclude_hosts_option_enable', $exclude_hosts_option_enable)) {
if (apply_filters(GLOBAL_NS.'_exclude_hosts_option_enable', $exclude_hosts_option_enable)) {
echo '<div class="plugin-menu-page-panel">'."\n";

echo ' <a href="#" class="plugin-menu-page-panel-heading">'."\n";
Expand Down
2 changes: 1 addition & 1 deletion src/includes/classes/MenuPage/Options/StaticCdnFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct()
echo ' <h3>'.__('Enable Static CDN Filters (e.g., MaxCDN/CloudFront)?', SLUG_TD).'</h3>'."\n";
echo ' <p>'.sprintf(__('This feature allows you to serve some and/or ALL static files on your site from a CDN of your choosing. This is made possible through content/URL filters exposed by WordPress and implemented by %1$s. All it requires is that you setup a CDN hostname sourced by your WordPress installation domain. You enter that CDN hostname below and %1$s will do the rest! Super easy, and it doesn\'t require any DNS changes either. :-) Please <a href="http://cometcache.com/r/static-cdn-filters-general-instructions/" target="_blank">click here</a> for a general set of instructions.', SLUG_TD), esc_html(NAME)).'</p>'."\n";
echo ' <p>'.__('<strong>What\'s a CDN?</strong> It\'s a Content Delivery Network (i.e., a network of optimized servers) designed to cache static resources served from your site (e.g., JS/CSS/images and other static files) onto it\'s own servers, which are located strategically in various geographic areas around the world. Integrating a CDN for static files can dramatically improve the speed and performance of your site, lower the burden on your own server, and reduce latency associated with visitors attempting to access your site from geographic areas of the world that might be very far away from the primary location of your own web servers.', SLUG_TD).'</p>'."\n";
if ($this->plugin->isNginx() && $this->plugin->applyWpFilters(GLOBAL_NS.'_wp_htaccess_nginx_notice', true) && (!isset($_SERVER['WP_NGINX_CONFIG']) || $_SERVER['WP_NGINX_CONFIG'] !== 'done')) {
if ($this->plugin->isNginx() && apply_filters(GLOBAL_NS.'_wp_htaccess_nginx_notice', true) && (!isset($_SERVER['WP_NGINX_CONFIG']) || $_SERVER['WP_NGINX_CONFIG'] !== 'done')) {
echo '<div class="plugin-menu-page-notice error">'."\n";
echo ' <i class="si si-thumbs-down"></i> '.__('It appears that your server is running NGINX and does not support <code>.htaccess</code> rules. Please <a href="http://cometcache.com/r/kb-article-recommended-nginx-server-configuration/" target="_new">update your server configuration manually</a>. Note that updating your NGINX server configuration <em>before</em> enabling Static CDN Filters is recommended to prevent any <a href="http://cometcache.com/r/kb-article-what-are-cross-origin-request-blocked-cors-errors/" target="_new">CORS errors</a> with your CDN. If you\'ve already updated your NGINX configuration, you can safely <a href="http://cometcache.com/r/kb-article-how-do-i-disable-the-nginx-htaccess-notice/" target="_new">ignore this message</a>.', SLUG_TD)."\n";
echo '</div>'."\n";
Expand Down
2 changes: 1 addition & 1 deletion src/includes/classes/MenuPage/Options/UserRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct()
echo ' <option value="1"'.selected($this->plugin->options['when_logged_in'], '1', false).'>'.__('Yes, but DON\'T maintain a separate cache for each user (I know what I\'m doing).', SLUG_TD).'</option>'."\n";
}
echo ' </select></p>'."\n";
if ($this->plugin->options['when_logged_in'] === '1' && $this->plugin->applyWpFilters(GLOBAL_NS.'_when_logged_in_no_admin_bar', true)) {
if ($this->plugin->options['when_logged_in'] === '1' && apply_filters(GLOBAL_NS.'_when_logged_in_no_admin_bar', true)) {
echo '<p class="warning">'.sprintf(__('<strong>Warning:</strong> Whenever you enable caching for logged-in users (without a separate cache for each user), the WordPress Admin Bar <em>must</em> be disabled to prevent one user from seeing another user\'s details in the Admin Bar. <strong>Given your current configuration, %1$s will automatically hide the WordPress Admin Bar on the front-end of your site.</strong>', SLUG_TD), esc_html(NAME)).'</p>'."\n";
}
echo ' <p class="info">'.sprintf(__('<strong>Note:</strong> %1$s includes comment authors as part of it\'s logged-in user check. This way comment authors will be able to see updates to comment threads immediately. And, so that any dynamically-generated messages displayed by your theme will work as intended. In short, %1$s thinks of a comment author as a logged-in user, even though technically they are not. Users who gain access to password-protected Posts/Pages are also considered by the logged-in user check.', SLUG_TD), esc_html(NAME)).'</p>'."\n";
Expand Down
22 changes: 11 additions & 11 deletions src/includes/classes/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public function setup()
$setup = -1; // Flag as having been setup.

if ($this->enable_hooks) {
$this->doWpAction('before_'.GLOBAL_NS.'_'.__FUNCTION__, get_defined_vars());
do_action('before_'.GLOBAL_NS.'_'.__FUNCTION__, get_defined_vars());
}
/* -------------------------------------------------------------- */

Expand Down Expand Up @@ -523,16 +523,16 @@ public function setup()

'uninstall_on_deletion' => '0', // `0|1`.
];
$this->default_options = $this->applyWpFilters(GLOBAL_NS.'_default_options', $this->default_options);
$this->default_options = apply_filters(GLOBAL_NS.'_default_options', $this->default_options);
$this->options = $this->getOptions(); // Filters, validates, and returns plugin options.

$this->cap = $this->applyWpFilters(GLOBAL_NS.'_cap', $this->cap);
$this->update_cap = $this->applyWpFilters(GLOBAL_NS.'_update_cap', $this->update_cap);
$this->network_cap = $this->applyWpFilters(GLOBAL_NS.'_network_cap', $this->network_cap);
$this->uninstall_cap = $this->applyWpFilters(GLOBAL_NS.'_uninstall_cap', $this->uninstall_cap);
$this->cap = apply_filters(GLOBAL_NS.'_cap', $this->cap);
$this->update_cap = apply_filters(GLOBAL_NS.'_update_cap', $this->update_cap);
$this->network_cap = apply_filters(GLOBAL_NS.'_network_cap', $this->network_cap);
$this->uninstall_cap = apply_filters(GLOBAL_NS.'_uninstall_cap', $this->uninstall_cap);
/*[pro strip-from="lite"]*/
$this->clear_min_cap = $this->applyWpFilters(GLOBAL_NS.'_clear_min_cap', $this->clear_min_cap);
$this->stats_min_cap = $this->applyWpFilters(GLOBAL_NS.'_stats_min_cap', $this->stats_min_cap);
$this->clear_min_cap = apply_filters(GLOBAL_NS.'_clear_min_cap', $this->clear_min_cap);
$this->stats_min_cap = apply_filters(GLOBAL_NS.'_stats_min_cap', $this->stats_min_cap);
/*[/pro]*/
/* -------------------------------------------------------------- */

Expand Down Expand Up @@ -641,7 +641,7 @@ public function setup()
add_action('delete_user', [$this, 'autoClearAuthorPageCacheOnUserDeletion'], 10, 2);
add_action('remove_user_from_blog', [$this, 'autoClearAuthorPageCacheOnUserDeletion'], 10, 1);

if ($this->options['enable'] && $this->applyWpFilters(GLOBAL_NS.'_disable_akismet_comment_nonce', true)) {
if ($this->options['enable'] && apply_filters(GLOBAL_NS.'_disable_akismet_comment_nonce', true)) {
add_filter('akismet_comment_nonce', function () {
return 'disabled-by-'.SLUG_TD; // MUST return a string literal that is not 'true' or '' (an empty string). See <http://bit.ly/1YItpdE>
}); // See also why the Akismet nonce should be disabled: <http://jas.xyz/1R23f5c>
Expand Down Expand Up @@ -677,7 +677,7 @@ public function setup()
}
/* -------------------------------------------------------------- */

$this->doWpAction('after_'.GLOBAL_NS.'_'.__FUNCTION__, get_defined_vars());
$this->doWpAction(GLOBAL_NS.'_'.__FUNCTION__.'_complete', get_defined_vars());
do_action('after_'.GLOBAL_NS.'_'.__FUNCTION__, get_defined_vars());
do_action(GLOBAL_NS.'_'.__FUNCTION__.'_complete', get_defined_vars());
}
}
6 changes: 3 additions & 3 deletions src/includes/functions/wp-cache-postload.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function wp_cache_postload()
if (!$advanced_cache->is_running) {
return; // Not applicable.
}
$advanced_cache->doWpAction('before_'.$GLOBAL_NS.'_'.__FUNCTION__, get_defined_vars());
do_action('before_'.$GLOBAL_NS.'_'.__FUNCTION__, get_defined_vars());

/*[pro strip-from="lite"]*/
if (!empty($advanced_cache->postload['invalidate_when_logged_in'])) {
Expand All @@ -34,6 +34,6 @@ function wp_cache_postload()
if (!empty($advanced_cache->postload['wp_main_query'])) {
add_action('wp', [$advanced_cache, 'wpMainQueryPostload'], PHP_INT_MAX);
}
$advanced_cache->doWpAction('after_'.$GLOBAL_NS.'_'.__FUNCTION__, get_defined_vars());
$advanced_cache->doWpAction($GLOBAL_NS.'_'.__FUNCTION__.'_complete', get_defined_vars());
do_action('after_'.$GLOBAL_NS.'_'.__FUNCTION__, get_defined_vars());
do_action($GLOBAL_NS.'_'.__FUNCTION__.'_complete', get_defined_vars());
}
2 changes: 1 addition & 1 deletion src/includes/traits/Ac/PostloadUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ public function maybeInvalidateWhenLoggedInPostload()
if (!($this->user_token = $this->userToken())) {
return; // Nothing to do in this case.
}
if ($this->applyWpFilters(GLOBAL_NS.'_invalidate_when_logged_in_postload', true) === false) {
if (apply_filters(GLOBAL_NS.'_invalidate_when_logged_in_postload', true) === false) {
return; // Nothing to do in this case (disabled via filter).
}
$regex = $this->assembleCachePathRegex('', '.*?\.u\/'.preg_quote($this->user_token, '/').'[.\/]');
Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Plugin/InstallUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ public function addAdvancedCache()
'ac_file_version' => VERSION, // Version when AC file was built.
]
);
if ($this->applyWpFilters(GLOBAL_NS.'_exclude_uris_client_side_too', true)) {
if (apply_filters(GLOBAL_NS.'_exclude_uris_client_side_too', true)) {
$possible_advanced_cache_constant_key_values['exclude_client_side_uris'] .= "\n".$this->options['exclude_uris'];
}
foreach ($possible_advanced_cache_constant_key_values as $_option => $_value) {
Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Plugin/OptionUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getOptions($intersect = true, $refresh = false)
} // End the collection of all plugin options.

$this->options = array_merge($this->default_options, $options);
$this->options = $this->applyWpFilters(GLOBAL_NS.'_options', $this->options);
$this->options = apply_filters(GLOBAL_NS.'_options', $this->options);
$this->options = $intersect ? array_intersect_key($this->options, $this->default_options) : $this->options;
$this->options = array_map('trim', array_map('strval', $this->options));

Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Plugin/StatsUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ trait StatsUtils
*/
public function statsLogPinger()
{
if (!$this->applyWpFilters(GLOBAL_NS.'_statsLogPinger_enable', IS_PRO)) {
if (!apply_filters(GLOBAL_NS.'_statsLogPinger_enable', IS_PRO)) {
return; // Stats collection disabled by site.
} elseif ($this->options['last_pro_stats_log'] >= strtotime('-1 week')) {
return; // No reason to keep pinging.
Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Plugin/WcpFeedUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function autoClearXmlFeedsCache($type, $post_id = 0)
if (!($variation_regex_frags = $utils->convertVariationsToHostCachePathRegexFrags($variations))) {
return $counter; // Nothing to do here.
}
$in_sets_of = $this->applyWpFilters(GLOBAL_NS.'_autoClearXmlFeedsCache_in_sets_of', 10, get_defined_vars());
$in_sets_of = apply_filters(GLOBAL_NS.'_autoClearXmlFeedsCache_in_sets_of', 10, get_defined_vars());

for ($_i = 0; $_i < count($variation_regex_frags); $_i = $_i + $in_sets_of) {
$_variation_regex_frags = array_slice($variation_regex_frags, $_i, $in_sets_of);
Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Plugin/WcpPluginUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait WcpPluginUtils
*/
public function autoClearOnPluginActivationDeactivation($plugin, $network_wide = false)
{
if (!$this->applyWpFilters(GLOBAL_NS.'_auto_clear_on_plugin_activation_deactivation', true)) {
if (!apply_filters(GLOBAL_NS.'_auto_clear_on_plugin_activation_deactivation', true)) {
return 0; // Nothing to do here.
}

Expand Down
2 changes: 1 addition & 1 deletion src/includes/traits/Plugin/WcpUserUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function autoClearUserCache($user_id)
if ($this->options['when_logged_in'] !== 'postload') {
return $counter; // Nothing to do.
}
if ($this->applyWpFilters(GLOBAL_NS.'_invalidate_when_logged_in_postload', true) === false) {
if (apply_filters(GLOBAL_NS.'_invalidate_when_logged_in_postload', true) === false) {
return $counter; // Nothing to do in this case (disabled via filter).
}
$regex = $this->assembleCachePathRegex('', '.*?\.u\/'.preg_quote($user_id, '/').'[.\/]');
Expand Down
6 changes: 3 additions & 3 deletions src/includes/traits/Plugin/WcpUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ public function autoWurgeCache()
*/
public function disableAutoWipeCacheRoutines()
{
$is_disabled = (boolean) $this->applyWpFilters(GLOBAL_NS.'_disable_auto_wipe_cache_routines', false);
$is_disabled = (boolean) apply_filters(GLOBAL_NS.'_disable_auto_wipe_cache_routines', false);

if ($is_disabled && is_admin() && (!IS_PRO || $this->options['change_notifications_enable'])) {
$this->enqueueMainNotice(
Expand All @@ -383,7 +383,7 @@ public function disableAutoWipeCacheRoutines()
*/
public function disableAutoClearCacheRoutines()
{
$is_disabled = (boolean) $this->applyWpFilters(GLOBAL_NS.'_disable_auto_clear_cache_routines', false);
$is_disabled = (boolean) apply_filters(GLOBAL_NS.'_disable_auto_clear_cache_routines', false);

if ($is_disabled && is_admin() && (!IS_PRO || $this->options['change_notifications_enable'])) {
$this->enqueueMainNotice(
Expand All @@ -406,7 +406,7 @@ public function disableAutoClearCacheRoutines()
*/
public function disableAutoPurgeCacheRoutines()
{
$is_disabled = (boolean) $this->applyWpFilters(GLOBAL_NS.'_disable_auto_purge_cache_routines', false);
$is_disabled = (boolean) apply_filters(GLOBAL_NS.'_disable_auto_purge_cache_routines', false);

if ($is_disabled && is_admin() && (!IS_PRO || $this->options['change_notifications_enable'])) {
$this->enqueueMainNotice(
Expand Down
8 changes: 4 additions & 4 deletions src/includes/traits/Shared/CacheLockUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ trait CacheLockUtils
*/
public function cacheLock()
{
if ($this->applyWpFilters(GLOBAL_NS.'\\share::disable_cache_locking', false)
|| $this->applyWpFilters(GLOBAL_NS.'_disable_cache_locking', false)
if (apply_filters(GLOBAL_NS.'\\share::disable_cache_locking', false)
|| apply_filters(GLOBAL_NS.'_disable_cache_locking', false)
) {
return false; // Disabled cache locking.
}
if (!($wp_config_file = $this->findWpConfigFile())) {
throw new \Exception(__('Unable to find the wp-config.php file.', SLUG_TD));
}
$lock_type = 'flock'; // Default lock type.
$lock_type = $this->applyWpFilters(GLOBAL_NS.'\\share::cache_lock_lock_type', $lock_type);
$lock_type = $this->applyWpFilters(GLOBAL_NS.'_cache_lock_type', $lock_type);
$lock_type = apply_filters(GLOBAL_NS.'\\share::cache_lock_lock_type', $lock_type);
$lock_type = apply_filters(GLOBAL_NS.'_cache_lock_type', $lock_type);

if (!in_array($lock_type, ['flock', 'sem'], true)) {
$lock_type = 'flock'; // Default lock type.
Expand Down
46 changes: 0 additions & 46 deletions src/includes/traits/Shared/HookUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,50 +232,4 @@ public function applyFilters($hook, $value)

return $value; // With applied filters.
}

/**
* Does an action w/ back compat. for ZenCache.
*
* @since 150422 Rewrite.
*
* @param string $hook The hook to apply.
*/
public function doWpAction($hook)
{
$hook = (string) $hook;
$args = func_get_args();
call_user_func_array('do_action', $args);

if (mb_stripos($hook, GLOBAL_NS) === 0) {
$zencache_filter = 'zencache'.mb_substr($hook, mb_strlen(GLOBAL_NS));
$zencache_args = $args; // Use a copy of the args.
$zencache_args[0] = $zencache_filter;
call_user_func_array('do_action', $zencache_args);
}
}

/**
* Applies filters w/ back compat. for ZenCache.
*
* @since 150422 Rewrite.
*
* @param string $hook The hook to apply.
*
* @return mixed The filtered value.
*/
public function applyWpFilters($hook)
{
$hook = (string) $hook;
$args = func_get_args();
$value = call_user_func_array('apply_filters', $args);

if (mb_stripos($hook, GLOBAL_NS) === 0) {
$zencache_hook = 'zencache'.mb_substr($hook, mb_strlen(GLOBAL_NS));
$zencache_args = $args; // Use a copy of the args.
$zencache_args[0] = $zencache_hook;
$zencache_args[1] = $value; // Filtered value.
$value = call_user_func_array('apply_filters', $zencache_args);
}
return $value; // Filtered value.
}
}