Skip to content

Instantly share code, notes, and snippets.

@soderlind
Last active July 9, 2024 08:55
Show Gist options
  • Save soderlind/9b95fa498a4ba1c563cc3d30b03260ab to your computer and use it in GitHub Desktop.
Save soderlind/9b95fa498a4ba1c563cc3d30b03260ab to your computer and use it in GitHub Desktop.
Buggregator for local WordPress development

Buggregator for local WordPress development

Buggregator

  1. (You need docker)
  2. Save the docker-compose.yml file.
  3. Run docker-compose up in the same folder as the docker-compose.yml file.
    • Update buggregator by running docker-compose pull
  4. Buggregator is at http://127.0.0.1:8000/#/

Learn more at https://docs.buggregator.dev/

WordPress

Make sure WP_ENVIRONMENT_TYPEis set to local. Local (by WPEngine) does that by default.

Log errors using WP Sentry

  1. Install WP Sentry. You don't have to activate it. We will load it early, to catch errors early.
  2. In wp-config.php add:
// NOTE: WP_ENVIRONMENT_TYPE must be defined and set to 'local'. Uncomment the line below if it's not set by the server
// define( 'WP_ENVIRONMENT_TYPE', 'local' );

if ( defined( 'WP_ENVIRONMENT_TYPE' ) && 'local' === WP_ENVIRONMENT_TYPE ) {
	define( 'WP_SENTRY_PHP_DSN', 'http://[email protected]:8000/1' );
	define( 'WP_SENTRY_ERROR_TYPES', E_ALL & ~E_NOTICE & ~E_USER_NOTICE );
	require_once __DIR__ . '/wp-content/plugins/wp-sentry-integration/wp-sentry.php';
}

Learn more at https://github.com/stayallive/wp-sentry/tree/v7.13.0?tab=readme-ov-file#usage

Example: Exeception sentry

Dump stuff using ray

  1. Install ray in your project using composer: composer --dev require spatie/ray
  2. Copy ray.php to the root of your WordPress site
  3. Now you can dump to buggregator, from your project, using \ray( $var );
Example: Variable dump ray

Send emails to Buggregator

Save mu-buggregator-smtp.php in your mu-plugins folder

Example: Email mail
services:
buggregator:
image: ghcr.io/buggregator/server:latest
depends_on:
buggregator-database:
condition: service_healthy
ports:
- 127.0.0.1:8000:8000 # Sentry, Ray
- 127.0.0.1:1025:1025 # SMTP
environment:
PERSISTENCE_DRIVER: database
DB_DRIVER: pgsql
DB_DATABASE: buggregator
DB_HOST: buggregator-database
DB_PORT: 5432
DB_USERNAME: buggregator
DB_PASSWORD: buggregator
buggregator-database:
image: postgres:latest
healthcheck:
test: [ "CMD-SHELL", "pg_isready --username=buggregator --dbname=buggregator" ]
interval: 3s
timeout: 3s
retries: 1
environment:
POSTGRES_DB: buggregator
POSTGRES_USER: buggregator
POSTGRES_PASSWORD: buggregator
<?php
/**
* Plugin Name: MU Buggregator SMTP
* Description: Send email to Buggregator. Will only log errors if WP_ENVIRONMENT_TYPE is set to 'local'.
* Version: 1.0.0
* Author: PerS
* Author URI: https://www.soderlind.no/
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
*/
if (! defined('WP_ENVIRONMENT_TYPE') || 'local' !== WP_ENVIRONMENT_TYPE) {
return;
}
/**
* Send emails to Buggregator
*
* @param \PHPMailer $phpmailer The PHPMailer instance (passed by reference).
*/
add_action( 'phpmailer_init', function( $phpmailer ) : void {
$phpmailer->isSMTP();
$phpmailer->Host = '127.0.0.1';
$phpmailer->Port = 1025;
} );
<?php
if ( ! defined( 'WP_ENVIRONMENT_TYPE' ) || 'local' !== WP_ENVIRONMENT_TYPE ) {
return;
}
return [
/*
* This settings controls whether data should be sent to Ray.
*/
'enable' => true,
/*
* The host used to communicate with the Ray app.
*/
'host' => '[email protected]',
/*
* The port number used to communicate with the Ray app.
*/
'port' => 8000,
/*
* Absolute base path for your sites or projects in Homestead, Vagrant, Docker, or another remote development server.
*/
'remote_path' => null,
/*
* Absolute base path for your sites or projects on your local computer where your IDE or code editor is running on.
*/
'local_path' => null,
/*
* When this setting is enabled, the package will not try to format values sent to Ray.
*/
'always_send_raw_values' => false,
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment