Skip to content

Commit

Permalink
Convert to Traits: Remove $_this and use ($_this)
Browse files Browse the repository at this point in the history
  • Loading branch information
raamdev committed Feb 28, 2016
1 parent 726609a commit c2d3c41
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
14 changes: 6 additions & 8 deletions src/includes/classes/CdnFilters.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,14 +243,13 @@ protected function maybeSetupFilters()
if (!$this->cdn_when_logged_in && $this->plugin->isLikeUserLoggedIn()) {
return; // Disable in this case.
}
$_this = $this; // Needed for closures below.

add_action('wp_head', function () use ($_this) {
$_this->completed_wp_head_action_hook = true;
add_action('wp_head', function () {
$this->completed_wp_head_action_hook = true;
}, PHP_INT_MAX); // The very last hook, ideally.

add_action('wp_footer', function () use ($_this) {
$_this->started_wp_footer_action_hook = true;
add_action('wp_footer', function () {
$this->started_wp_footer_action_hook = true;
}, -PHP_INT_MAX); // The very first hook, ideally.

add_filter('home_url', array($this, 'urlFilter'), PHP_INT_MAX - 10, 4);
Expand Down Expand Up @@ -340,7 +339,6 @@ public function contentFilter($string)
if (strpos($string, '<') === false) {
return $string; // Nothing to do.
}
$_this = $this; // Reference needed by closures below.

$regex_url_attrs = '/'.// HTML attributes containing a URL.

Expand All @@ -361,9 +359,9 @@ public function contentFilter($string)
'/i'; // End regex pattern; case insensitive.

$orig_string = $string; // In case of regex errors.
$string = preg_replace_callback($regex_url_attrs, function ($m) use ($_this) {
$string = preg_replace_callback($regex_url_attrs, function ($m) {
unset($m[0]); // Discard full match.
$m[6] = $_this->filterUrl($m[6], null, true, null);
$m[6] = $this->filterUrl($m[6], null, true, null);
return implode('', $m); // Concatenate all parts.
}, $string); // End content filter.

Expand Down
10 changes: 4 additions & 6 deletions src/includes/traits/Ac/PostloadUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,12 @@ public function maybeFilterStatusHeaderPostload()
if (empty($this->postload['filter_status_header'])) {
return; // Nothing to do in this case.
}
$_this = $this; // Reference needed below.

add_filter(
'status_header',
function ($status_header, $status_code) use ($_this) {
function ($status_header, $status_code) {
if ($status_code > 0) {
$_this->http_status = (integer) $status_code;
$this->http_status = (integer) $status_code;
}
return $status_header;
},
Expand Down Expand Up @@ -282,12 +281,11 @@ public function wpMainQueryPostload()
$this->is_user_logged_in = is_user_logged_in();
$this->content_url = rtrim(content_url(), '/');
$this->is_maintenance = $this->functionIsPossible('is_maintenance') && is_maintenance();
$_this = $this; // Reference for the closure below.

add_action(
'template_redirect',
function () use ($_this) {
$_this->is_a_wp_content_type = $_this->is_404 || $_this->is_maintenance
function () {
$this->is_a_wp_content_type = $this->is_404 || $this->is_maintenance
|| is_front_page() // See <https://core.trac.wordpress.org/ticket/21602#comment:7>
|| is_home() || is_singular() || is_archive() || is_post_type_archive() || is_tax() || is_search() || is_feed();
},
Expand Down
3 changes: 1 addition & 2 deletions src/includes/traits/Shared/CachePathUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ public function buildHostCachePathRegexFragsFromWcUris($uris, $regex_suffix_frag
$uris = trim((string) $uris);
$regex_suffix_frag = $this->cachePathRegexSuffixFrag($regex_suffix_frag);

$_this = $this; // Reference for the closure below.
$flags = $this::CACHE_PATH_ALLOW_WILDCARDS | $this::CACHE_PATH_NO_SCHEME | $this::CACHE_PATH_NO_HOST
| $this::CACHE_PATH_NO_PATH_INDEX | $this::CACHE_PATH_NO_QUV | $this::CACHE_PATH_NO_EXT;

Expand All @@ -324,7 +323,7 @@ public function buildHostCachePathRegexFragsFromWcUris($uris, $regex_suffix_frag

foreach ($uri_patterns as $_key => &$_uri_pattern) {
if (($_uri_pattern = trim($_uri_pattern, '^$'))) {
$_cache_path = $_this->buildCachePath($host_url.'/'.trim($_uri_pattern, '/'), '', '', $flags);
$_cache_path = $this->buildCachePath($host_url.'/'.trim($_uri_pattern, '/'), '', '', $flags);
$_relative_cache_path = preg_replace('/^'.preg_quote($host_cache_path, '/').'(?:\/|$)/i', '', $_cache_path);
$_uri_pattern = $this->wdRegexToActualRegexFrag($_relative_cache_path);
}
Expand Down

0 comments on commit c2d3c41

Please sign in to comment.