1
0
Fork 1

Update simple-glitchtip.php

This commit is contained in:
colin 2024-07-18 20:25:20 +00:00
parent 8f541c7e79
commit de5b12f1cf
2 changed files with 66 additions and 16 deletions

66
simple-glitchtip.php Normal file
View File

@ -0,0 +1,66 @@
<?php
/*
Plugin Name: Simple Glitchtip
Description: A simple plugin to handle Sentry/Glitchtip DSNs and report errors.
Version: 1.0
Author: Colin
Plugin URI: https://git.nixc.us/colin/simple-glitchtip
*/
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly.
}
// Register settings
function sg_register_settings() {
register_setting('sg-settings-group', 'sg_dsn');
}
// Settings page
function sg_settings_page() {
?>
<div class="wrap">
<h1>Simple Glitchtip Settings</h1>
<form method="post" action="options.php">
<?php settings_fields('sg-settings-group'); ?>
<?php do_settings_sections('sg-settings-group'); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">DSN</th>
<td><input type="text" name="sg_dsn" value="<?php echo esc_attr(get_option('sg_dsn')); ?>" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
// Add settings menu
function sg_add_settings_menu() {
add_options_page('Simple Glitchtip Settings', 'Glitchtip', 'manage_options', 'sg-settings', 'sg_settings_page');
}
add_action('admin_menu', 'sg_add_settings_menu');
add_action('admin_init', 'sg_register_settings');
// Initialize error handler
function sg_initialize_error_handler($dsn) {
if (!class_exists('Raven_Client')) {
require_once plugin_dir_path(__FILE__) . 'raven-client.phar';
}
$client = new Raven_Client($dsn);
$error_handler = new Raven_ErrorHandler($client);
$error_handler->registerExceptionHandler();
$error_handler->registerErrorHandler();
$error_handler->registerShutdownFunction();
}
// Initialize the plugin
function sg_initialize_plugin() {
$dsn = getenv('SENTRY_DSN') ?: getenv('GLITCHTIP_DSN') ?: get_option('sg_dsn');
if ($dsn) {
sg_initialize_error_handler($dsn);
}
}
add_action('plugins_loaded', 'sg_initialize_plugin');

View File

@ -1,16 +0,0 @@
<?php
/*
Plugin Name: Simple Tracking
Description: Embeds tracking code into your WordPress site.
Version: 1.0
Author: Colin
Author URI: https://git.nixc.us/colin/SimpleTracking.git
*/
function add_simple_tracking_code() {
$tracking_code_path = plugin_dir_path(__FILE__) . 'tracking-code.php';
if (file_exists($tracking_code_path)) {
include $tracking_code_path;
}
}
add_action('wp_head', 'add_simple_tracking_code');