Replacement for register_trigger
-
Hi, in the changelog, you mention register_trigger is renamed to notification_register_trigger.
Is there any other changes I need to make to the code?
Because calling notification_register_trigger() results in a fatal error “call to undefined function”.
-
Yes, all the changes are in the changelog.
You are getting this error because probably you are calling this function too early. I’d suggest hooking into one of these actions.
Thanks. My code used to work in v5, but doesn’t behave the same in v6.
I tried to do this, but still the same issue?
add_action( 'init', function() { notification_register_trigger( new my_function() ); }, 1100);
What’s the undefined function?
notification_register_trigger
ormy_function
?notification_register_trigger
is undefined.Quite weird. Is the plugin active for sure? Where do you execute this code? Your plugin or theme?
I’m executing the code in my plugin.
The Notification plugin is definitely active, but something very strange is going on.
To find out why, I setup a localhost environment to test.
When upgrading from v5 to v6, I see the following error:
G'day!Since WordPress 5.2 there is a built-in feature that detects when a plugin or theme causes a fatal error on your site, and notifies you with this automated email.In this case, WordPress caught an error with one of your plugins, Notification.First, visit your website (https://localhost/testsite/) and check for any visible issues. Next, visit the page where the error was caught (https://localhost/testsite/wp-admin/admin-ajax.php?_fs_blog_admin=true) and check for any visible issues.Please contact your host for assistance with investigating this issue further.If your site appears broken and you can't access your dashboard normally, WordPress now has a special "recovery mode". This lets you safely login to your dashboard and investigate further.https://localhost/testsite/wp-login.php?action=enter_recovery_mode&rm_token=nPL2zUI9ZTBAsL3TmC13t2&rm_key=GBwPEdAOaZ7FbU4nEMvZLOTo keep your site safe, this link will expire in 1 day. Don't worry about that, though: a new link will be emailed to you if the error occurs again after it expires.Error Details=============An error of type E_ERROR was caused in line 329 of the file D:\User\Programs\Xampp7.2\htdocs\testsite\wp-content\plugins\notification\class\Abstracts\Trigger.php. Error message: Uncaught Error: Class 'BracketSpace\Notification\Admin\FieldsResolver' not found in D:\User\Programs\Xampp7.2\htdocs\testsite\wp-content\plugins\notification\class\Abstracts\Trigger.php:329Stack trace:#0 D:\User\Programs\Xampp7.2\htdocs\testsite\wp-content\plugins\notification\class\Abstracts\Trigger.php(429): BracketSpace\Notification\Abstracts\Trigger->resolve_fields()#1 D:\User\Programs\Xampp7.2\htdocs\testsite\wp-includes\class-wp-hook.php(286): BracketSpace\Notification\Abstracts\Trigger->_action(Object(Plugin_Upgrader), Array)#2 D:\User\Programs\Xampp7.2\htdocs\testsite\wp-includes\class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array)#3 D:\User\Programs\Xampp7.2\htdocs\testsite\wp-includes\plugin.php(465): WP_Hook->do_action(Array)#4 D:\User\Programs\Xampp7.2\htdocs\testsite\wp-admin\includes\class-plugin-upgrader.php(316): do_action('upgrader_proces...', Object(Plugin_Upgrader), Array)#5 D:\User\Programs\Xampp7.2\htdocs\testsite\wp-admin\includes\ajax-actions.php(4191)
After reloading the admin page, I no longer have the error message, but things don’t seem to be working.
If I try to disable a notification and come back to the notification page, it shows it’s still enabled.
To further test, I try to simulate a plugin update notification. I also enable logging, but it seems that is also broken.
Fatal error: Uncaught Error: Call to a member function get_title() on null in D:\User\Programs\Xampp7.2\htdocs\testsite\wp-content\plugins\notification\class\Core\Debugging.php:201 Stack trace: #0 D:\User\Programs\Xampp7.2\htdocs\testsite\wp-includes\class-wp-hook.php(288): BracketSpace\Notification\Core\Debugging->catch_notification(Object(BracketSpace\Notification\Defaults\Carrier\Email), Object(BracketSpace\Notification\Defaults\Trigger\Plugin\Updated)) #1 D:\User\Programs\Xampp7.2\htdocs\testsite\wp-includes\class-wp-hook.php(310): WP_Hook->apply_filters('', Array) #2 D:\User\Programs\Xampp7.2\htdocs\testsite\wp-includes\plugin.php(465): WP_Hook->do_action(Array) #3 D:\User\Programs\Xampp7.2\htdocs\testsite\wp-content\plugins\notification\class\Abstracts\Trigger.php(239): do_action('notification/ca...', Object(BracketSpace\Notification\Defaults\Carrier\Email), Object(BracketSpace\Notification\Defaults\Trigger\Plugin\Updated), Object(BracketSpace\Notification\Core\Notification)) #4 D:\User\Programs\Xampp in D:\User\Programs\Xampp7.2\htdocs\testsite\wp-content\plugins\notification\class\Core\Debugging.php on line 201
This behaviour is consistent with both my development and production site.
Let me know if there’s anything I can do to assist the debug.
Thanks a lot for the detailed info! I can see you are running PHP 7.2 and latest WP, that’s great.
Do you have some old paid extensions installed? Or custom code extending the plugin? Because the
Admin\FieldsResolver
class is not used anymore and the old plugins are not compatible.No paid extensions installed.
I was only running a custom trigger, but it has been disabled.
I see it uses the “resolver” field. What do I replace it with then?
class webhook_failed extends \BracketSpace\Notification\Abstracts\Trigger { public function __construct() { // Add slug and the title. parent::__construct( 'customplugin_webhook_failed', __( 'Custom Webhook Failed', 'customplugin' ) ); // Hook to the action. $this->add_action( 'customplugin_webhook_failed', 10, 3 ); } public function action($error_description, $error_code, $error_data) { $this->error_description = $error_description; $this->error_code = $error_code; $this->error_data = $error_data; } public function merge_tags() { $this->add_merge_tag( new \BracketSpace\Notification\Defaults\MergeTag\StringTag( array( 'slug' => 'error_description', 'name' => __( 'Error Description', 'customplugin' ), 'resolver' => function( $trigger ) { return $trigger->error_description; }, ) ) ); $this->add_merge_tag( new \BracketSpace\Notification\Defaults\MergeTag\StringTag( array( 'slug' => 'error_code', 'name' => __( 'Error Code/Reason', 'customplugin' ), 'resolver' => function( $trigger ) { return $trigger->error_code; }, ) ) ); $this->add_merge_tag( new \BracketSpace\Notification\Defaults\MergeTag\StringTag( array( 'slug' => 'error_data', 'name' => __( 'Error Data', 'customplugin' ), 'resolver' => function( $trigger ) { return $trigger->error_data; }, ) ) ); } }
Custom trigger looks good, but it looks like you’ve been still using old version of the plugin.
This error:
Error message: Uncaught Error: Class 'BracketSpace\Notification\Admin\FieldsResolver' not found in D:\User\Programs\Xampp7.2\htdocs\testsite\wp-content\plugins\notification\class\Abstracts\Trigger.php:329
Is not related to version 6, see this line.
Please make sure you’ve updated the plugin and it update went successfully.
The error message was shown in WP Admin when doing the upgrade from v5 to v6.
I think the upgrade process doesn’t work in all cases for some reason.
I uninstalled and reinstalled the plugin and it looks to be working now, so I’m going to mark this as resolved.
BTW, the uninstalled process didn’t completely remove the existing notifications even if was selected in the settings. Perhaps my setup had some weird issue (both dev and production environments).
Thanks a lot for confirming!
I’m putting the uninstall process check on our to-do list.
- The topic ‘Replacement for register_trigger’ is closed to new replies.