littlebizzy / slickstack

Lightning-fast WordPress on Nginx
https://slickstack.io
GNU General Public License v3.0
642 stars 112 forks source link

Support for global PHP constants not overwritten by SlickStack #168

Closed skilver-io closed 1 year ago

skilver-io commented 2 years ago

Hi @jessuppi,

Have you every considered to support sentry.io as an additional error tracking system?

What is sentry.io? Sentry.io is an open-source full-stack error tracking system which allows to track errors and performance issues on WordPress in PHP and Javascript and helps developers to monitor and fix crashes in real time. Client side error and performance tracking is possible.

Why we need to integrate We are running multiple slickstack instances across almost all regions and we are having issues to track client side errors as well as performance issues on our custom product pages, cart and checkout. Sentry.io would allow us to track errors across all instances in a single system.

Slickstack integration The integration would be fairly simple via global variables in the wp-config file + a lightweight plugin by Alex Bouma to get started right out of the box:

Plugin: https://wordpress.org/plugins/wp-sentry-integration/#description Git: https://github.com/stayallive/wp-sentry/blob/v5.1.0/README.md

Necessary global variables

WP_SENTRY_PHP_DSN // Track PHP (must have for sentry.io)
WP_SENTRY_BROWSER_DSN // Track Javascript (must have for sentry.io)
WP_SENTRY_VERSION // Website version for release tracking
WP_SENTRY_ENV // Environment: production, staging; default: unspecified

If no support possible In case a support for sentry.io is not possible: Is it possible to define the global variables in the wp-config file on our own?

I am not sure if slickstack will override the wp-config file on ss-install or on updates, etc.. Can you please give some details if there could be any issues coming up when integrating and changing the global variables on our own. Thanks you for your help.

Looking forward to hearing from you.

Best, Dennis

DeZa90 commented 2 years ago

Solution

We solved the issue by defining the global variables in a mu-plugin, so that the variables are available once the regular plugins load.

closed

jessuppi commented 2 years ago

Thanks for the feedback @skilver-io

Since the underlying issue here is about global PHP constants, and not really about Sentry, I changed the title. By the way, Sentry looks really cool, we definitely want to support plugins like this, although it's probably not something we would want to bundle with SlickStack by default.

This issue has been discussed several times in our Discord chat room during the past few years, and it's been difficult for me to get much feedback from developers on how to solve it.

A few years ago, SlickStack included a file at /wp-content/functions.php that was include_once by our wp-config.php boilerplate so that teams could define any PHP constants they wanted in that file, and it would load early on in the WordPress loading sequence as per this chart:

Ref: https://wordpress.stackexchange.com/questions/71406/is-there-a-flowchart-for-wordpress-loading-sequence

However, recently we removed that file due to:

Of course, LittleBizzy has always been a fan of hardcoding with PHP constants instead of MySQL queries whenever possible, so I understand if developers don't want to use a theme or plugin for every case.

My concerns are as follows:

  1. we must keep wp-config.php hardcoded and uneditable to achieve true stability with SlickStack
  2. we can add a sort of functions file again, but what namespace/path should it use?
  3. since most teams don't use it, it probably shouldn't exist by default

What I had proposed in Discord a few times (with zero feedback from users) is maybe conditionally loading a file from within the wp-config.php using a PHP if statement like this:

is_file($file) AND include $file;

Ref: https://stackoverflow.com/questions/4604965/how-to-include-only-if-file-exists Ref: https://stackoverflow.com/questions/792899/is-file-or-file-exists-in-php Ref: https://stackoverflow.com/questions/4099103/is-file-file-exists-performance-and-cache Ref: https://www.php.net/manual/en/function.is-file.php

jessuppi commented 2 years ago

Here's what I'm thinking maybe at the bottom of wp-config.php to conditionally load something:

$custom_functions = '/var/www/html/wp-content/custom-functions.php';
is_file($custom_functions) AND include $custom_functions;

A few years ago LittleBizzy had a free plugin called Custom Functions that could be edited inside WP Admin (kind of) but the hooks for editing PHP files are not available by default in WordPress Core so it took a lot of jiggery hackery and is not something that would be secure long-term, so we abandoned that approach.

So, this file would be something really only available to SSH or maybe SFTP users to edit, which is maybe okay since this should only be messed with by advanced users anyways.

jessuppi commented 1 year ago

I've added this now, feedback desired:

https://github.com/littlebizzy/slickstack/commit/9f61304b82be7f7ad95e1872f886c6842979214b https://github.com/littlebizzy/slickstack/commit/807750dcd6c813b47994f51b9818865e69d15107 https://github.com/littlebizzy/slickstack/commit/aa383b4814efe581638e7c42750a3b3138586003

It should work on all 3 environments (production, staging, dev). If you use this feature and it works well for you, please be sure to tell us because this has been a recurring discussion the past few years... thanks!