Strange behavior of debug_backtrace() detected, seems that it was changed in PHP 7 >, so that add_action() will not work in the same way. The counter $shift is now one level less. An example to reproduce it:
<?php
register_plugin(
'add_action_test',
'add_action_test',
'0.1',
'J. Ehret',
'http://ehret-studio.com',
'Testing strange behavior of add_action()',
'',
''
);
add_action('index-post-dataindex', 'add_action_test');
function add_action_test() {
include __DIR__.'/A.php';
$a = new A;
$a->fireFoo();
}
A.php looks as follows:
<?php
class A {
function fireFoo() {
add_action('theme-header', function() { echo 'here in foo() ...'; });
}
}
Adding version_compare() into add_action() could solve that issue:
...
$shift=count($bt) - 4;
if(version_compare(PHP_VERSION, '7.0.0', '>=')) {
$shift--;
}
...
Strange behavior of
debug_backtrace()detected, seems that it was changed inPHP 7 >, so thatadd_action()will not work in the same way. The counter$shiftis now one level less. An example to reproduce it:A.php looks as follows:
Adding
version_compare()intoadd_action()could solve that issue: