stayallive / wp-sentry

A (unofficial) WordPress plugin reporting PHP and JavaScript errors to Sentry.
https://wordpress.org/plugins/wp-sentry-integration/
MIT License
305 stars 48 forks source link

Support loading wp-sentry.php as part of wp-config.php #103

Closed ocean90 closed 2 years ago

ocean90 commented 2 years ago

The readme already mentions that you can load the plugin file with a must-use plugin to catch more errors. I'd like to go a step further and load the plugin file as part of wp-config.php to also catch errors during the WordPress bootstrap process.

Loading the plugin that early means that some WordPress functions may not exist yet. Luckily, the plugin doesn't depend on so many functions and each used function can be adjusted to make it work.

The simplified code for wp-config.php may look like this:

// Load the WordPress plugin API early so hooks can be used.
require_once ABSPATH . '/wp-includes/plugin.php';

// Load WP Sentry plugin
require_once ABSPATH . '/wp-content/plugins/wp-sentry-integration/wp-sentry.php';
define( 'WP_SENTRY_MU_LOADED', true );

We first have to require the WordPress plugin API to make functions like add_action() available. That's not a big deal and fully supported by WordPress, see here and here).

For the plugin itself we only have to make sure that two functions exist: is_admin() and get_bloginfo().

I'm aware that this is some advanced usage but since the changes are minimal I thought I submit this PR anyway. Let me know what you think!

ocean90 commented 2 years ago

@stayallive Do you have any thoughts on this idea? Is there something I can help to move this forward?

stayallive commented 2 years ago

@ocean90, I have been thinking about this one and slightly modified this PR into #106.

WDYT?

stayallive commented 2 years ago

Implemented in #106, thanks for kicking this off and doing the research!