Skip to content

Instantly share code, notes, and snippets.

@TemporaryJam
Last active June 3, 2019 03:41
Show Gist options
  • Save TemporaryJam/8ba9eb0767ead2456af093c751ec9ab5 to your computer and use it in GitHub Desktop.
Save TemporaryJam/8ba9eb0767ead2456af093c751ec9ab5 to your computer and use it in GitHub Desktop.
Stop ExpressionEngine nested hook calls from failing when using the end_script flag in a nested call.
From 2c06ccd60184aeb56e13692b42559247c552265a Mon Sep 17 00:00:00 2001
Date: Fri, 4 May 2018 16:19:02 +1000
Subject: [PATCH] Patching EE extension bug where a nested call to extensions
and use of end_script will exit all currently running hooks instead of just
the current one
---
public/system/ee/legacy/libraries/Extensions.php | 33 +++++++++++++++++++++---
1 file changed, 29 insertions(+), 4 deletions(-)
diff --git a/public/system/ee/legacy/libraries/Extensions.php b/public/system/ee/legacy/libraries/Extensions.php
index b1410004..113181b0 100644
--- a/public/system/ee/legacy/libraries/Extensions.php
+++ b/public/system/ee/legacy/libraries/Extensions.php
@@ -13,7 +13,7 @@
class EE_Extensions {
var $extensions = array();
- var $end_script = FALSE; // To return or not to return
+ var $current_end_script = FALSE; // To return or not to return
var $last_call = FALSE; // The data returned from the last called method for this hook
var $in_progress = ''; // Last hook called. Prevents loops.
var $s_cache = array(); // Array of previously unserialized settings
@@ -60,6 +60,31 @@ class EE_Extensions {
}
}
+ /**
+ * Magic set for legacy end_script
+ * @param $key
+ * @param $value
+ */
+ public function __set($key, $value) {
+ if ($key == 'end_script') {
+ $this->current_end_script = $value;
+ }
+ }
+
+ /**
+ * Magic get for legacy end_script
+ * @param $key
+ * @return bool
+ */
+ public function __get($key)
+ {
+ if ($key == 'end_script') {
+ $return = $this->current_end_script;
+ $this->current_end_script = false;
+ return $return;
+ }
+ }
+
/**
* Universal caller, was used for php 4 compatibility
*
@@ -87,7 +112,7 @@ class EE_Extensions {
function call($which)
{
// Reset Our Variables
- $this->end_script = FALSE;
+ $this->current_end_script = FALSE;
$this->last_call = FALSE;
// Anything to Do Here?
@@ -127,7 +152,7 @@ class EE_Extensions {
// one for the hook we still stop the script now because
// extensions with a higher priority call the shots and thus
// override any extensions with a lower priority.
- if ($this->end_script === TRUE)
+ if ($this->current_end_script === TRUE)
{
break;
}
@@ -135,7 +160,7 @@ class EE_Extensions {
// Have to keep breaking since break only accepts parameters as of
// PHP 5.4.0
- if ($this->end_script === TRUE)
+ if ($this->current_end_script === TRUE)
{
break;
}
--
2.15.1 (Apple Git-101)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment