@dccharron – Darn, beta tested for several weeks and didn’t catch that. Will put out a patch shortly.
That error first indicates your on an older version of PHP. I added that function for PHP 5.2 compatibility but seems something is awry. Can you post the contents of System Info from Popup Maker -> Tools here. I need to figure out why it may be occuring.
Will look for a quick solution, can you make changes to the PHP files manually to see if the fix I find works without pushing an update?
@dccharron – I think I found a better alternate function if you can test it that would be great.
In that file misc-functions.php is a function named get_called_class().
If you can replace it with this and test again I would be greatful. I need to get this part worked out ASAP as v1.4 builds on the features that use this heavily.
function get_called_class () {
foreach ( debug_backtrace() as $trace ) {
if ( isset( $trace['object'] ) ) {
if ( $trace['object'] instanceof $trace['class'] ) {
return get_class( $trace['object'] );
}
}
}
return false;
}
Made the change to get_called_class () in misc-functions.php as you suggested/provided then tried updating one popup. Got a fatal error:
Parse error: syntax error, unexpected '&', expecting ']' in /home/content/06/7129406/html/wp-content/plugins/popup-maker/includes/misc-functions.php on line 21
This disabled my access to admin page completely so reverted to original code and all ok now. Of course it now generates the 4 errors I mentioned earlier.
I must confess changing PHP in situ is not my strong suit so perhaps I fouled things up. Happy to take advice and try it again if that’s useful to you.
Weird. I just checked that the code that I used was correct. When I compared the code I got from the email to the code in your post, they were different! I had used the one from the email so I decided to copy and paste the code from the post and try it again. Failed again but different error this time:
Fatal error: Class name must be a valid object or a string in /home/content/06/7129406/html/wp-content/plugins/popup-maker/includes/class-popmake-fields.php on line 23
Weird.
@dccharron – Testing a different solution. There are several functions that are available, I need to find the most efficient one that works.
Bear with me and I’m gonna post 2 more for you to try now.
#1
function get_called_class($level = 1, $trace = false) {
if (!$trace) $trace = debug_backtrace();
if (!isset($trace[$level])) throw new Exception(
'Cannot find called class: stack level too deep');
if (!isset($trace[$level]['type'])) throw new Exception (
'Cannot find called class: type not set');
switch ($trace[$level]['type']) {
case '::':
$lines = file($trace[$level]['file']);
$i = 0;
$callerLine = '';
while (stripos($callerLine, $trace[$level]['function']) === false) {
$i++;
$callerLine = $lines[$trace[$level]['line'] - $i] . $callerLine;
}
$pattern = '/([a-zA-Z0-9\_]+)::' . $trace[$level]['function'] . '/';
preg_match($pattern, $callerLine, $matches);
if (!isset($matches[1])) {
throw new Exception(
'Cannot find called class: originating method call is obscured');
}
switch ($matches[1]) {
case 'self':
case 'parent':
return get_called_class($level + 1, $trace);
default:
return $matches[1];
}
case '->':
switch ($trace[$level]['function']) {
case '__get':
if (!is_object($trace[$level]['object'])) {
throw new Exception('Edge case fail. __get called on non object');
}
return get_class($trace[$level]['object']);
default: return $trace[$level]['class'];
}
default:
throw new Exception ("Unknown backtrace method type");
}
}
#2
function get_called_class()
{
$bt = debug_backtrace();
$lines = file($bt[1]['file']);
preg_match('/([a-zA-Z0-9\_]+)::'.$bt[1]['function'].'/',
$lines[$bt[1]['line']-1],
$matches);
return $matches[1];
}
#3
function get_called_class() {
$bt = debug_backtrace();
$l = 0;
do {
$l++;
$lines = file($bt[$l]['file']);
$callerLine = $lines[$bt[$l]['line']-1];
preg_match('/([a-zA-Z0-9\_]+)::'.$bt[$l]['function'].'/',
$callerLine,
$matches);
if ($matches[1] == 'self') {
$line = $bt[$l]['line']-1;
while ($line > 0 && strpos($lines[$line], 'class') === false) {
$line--;
}
preg_match('/class[\s]+(.+?)[\s]+/si', $lines[$line], $matches);
}
}
while ($matches[1] == 'parent' && $matches[1]);
return $matches[1];
}
Try them in order. Let me know which works for you. Thanks for testing.
Solution #1 worked perfectly. No errors. Updated perfectly. Tested perfectly. Will try the other two solutions now.
Solution #2 worked perfectly too. No errors. Updated perfectly. Tested perfectly. Will try #3 now.
Solution #3 worked perfectly too. No errors. Updated perfectly. Tested perfectly. Back to you now.
@dccharron – Awesome, thanks for the confirmation. Gonna include those in a patch in just a bit. I am working out one other issue and then can put out a patch.
@dccharron – Patch is live.
Please take a moment to rate and review the plugin and or support.
I’ve updated to 1.3.1 and tested again. All working perfectly. How good is that! Thanks again.
@dccharron – Awesome! Happy I could help you out. Btw, when you have a moment, I would very much appreciate if you could quickly rate the plugin, just to help us spread the word.