add_action('after_setup_theme', function() {
if (class_exists('ErrorExplorer\WordPressErrorReporter\ErrorReporter')) {
$webhook_url = get_option('error_explorer_webhook_url');
if ($webhook_url && get_option('error_explorer_enabled')) {
$errorReporter = new \ErrorExplorer\WordPressErrorReporter\ErrorReporter($webhook_url, [
'environment' => wp_get_environment_type(),
'project_name' => get_bloginfo('name'),
]);
$errorReporter->register();
}
}
});
class MyPlugin {
private $errorReporter;
public function __construct() {
add_action('plugins_loaded', [$this, 'init_error_reporting']);
}
public function init_error_reporting() {
if (class_exists('ErrorExplorer\WordPressErrorReporter\ErrorReporter')) {
$this->errorReporter = new \ErrorExplorer\WordPressErrorReporter\ErrorReporter(
'YOUR_WEBHOOK_URL',
['project_name' => 'My Plugin']
);
$this->errorReporter->register();
}
}
public function some_method() {
try {
// Plugin logic here
} catch (Exception $e) {
if ($this->errorReporter) {
$this->errorReporter->addBreadcrumb('Plugin method failed', 'plugin');
$this->errorReporter->reportError($e);
}
throw $e; // Re-throw if needed
}
}
}
// Track order failures
add_action('woocommerce_order_status_failed', function($order_id) {
global $errorReporter;
if ($errorReporter) {
$errorReporter->addBreadcrumb('Order failed', 'woocommerce', 'error', [
'order_id' => $order_id
]);
$errorReporter->reportMessage(
'WooCommerce order failed',
wp_get_environment_type(),
null,
'warning',
['order_id' => $order_id]
);
}
});
// Track payment errors
add_action('woocommerce_payment_failure', function() {
global $errorReporter;
if ($errorReporter) {
$errorReporter->addBreadcrumb('Payment failed', 'woocommerce', 'error');
}
});
// Test exception
try {
throw new Exception('Test error from Error Explorer WordPress SDK');
} catch (Exception $e) {
$errorReporter->reportError($e);
}
// Test PHP error
$undefined_variable->someProperty; // Will be caught by error handler