| 1 | <?php |
|---|
| 2 | /** |
|---|
| 3 | * Main plugin file. |
|---|
| 4 | * |
|---|
| 5 | * @package Bootstrap |
|---|
| 6 | * @author Pierre Lannoy <https://pierre.lannoy.fr/>. |
|---|
| 7 | * @since 1.0.0 |
|---|
| 8 | * |
|---|
| 9 | * @wordpress-plugin |
|---|
| 10 | * Plugin Name: DecaLog |
|---|
| 11 | * Plugin URI: https://perfops.one/decalog |
|---|
| 12 | * Description: Capture and log events, metrics and traces on your site. Make WordPress observable – finally! |
|---|
| 13 | * Version: 4.6.0 |
|---|
| 14 | * Requires at least: 6.4 |
|---|
| 15 | * Requires PHP: 8.2 |
|---|
| 16 | * Author: Pierre Lannoy / PerfOps One |
|---|
| 17 | * Author URI: https://perfops.one |
|---|
| 18 | * License: GPLv3 |
|---|
| 19 | * License URI: https://www.gnu.org/licenses/gpl-3.0.html |
|---|
| 20 | * Text Domain: decalog |
|---|
| 21 | * Network: true |
|---|
| 22 | * Domain Path: /languages |
|---|
| 23 | */ |
|---|
| 24 | |
|---|
| 25 | if ( ! defined( 'WPINC' ) ) { |
|---|
| 26 | die; |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | require_once __DIR__ . '/init.php'; |
|---|
| 30 | require_once __DIR__ . '/functions.php'; |
|---|
| 31 | require_once __DIR__ . '/includes/system/class-option.php'; |
|---|
| 32 | require_once __DIR__ . '/includes/system/class-environment.php'; |
|---|
| 33 | require_once __DIR__ . '/autoload.php'; |
|---|
| 34 | require_once __DIR__ . '/includes/libraries/class-libraries.php'; |
|---|
| 35 | require_once __DIR__ . '/includes/libraries/autoload.php'; |
|---|
| 36 | require_once __DIR__ . '/includes/libraries/guzzlehttp/functions_include.php'; |
|---|
| 37 | |
|---|
| 38 | /** |
|---|
| 39 | * Copy the file responsible to early initialization in mu-plugins and drop-ins dir. |
|---|
| 40 | * |
|---|
| 41 | * @since 2.4.0 |
|---|
| 42 | */ |
|---|
| 43 | function decalog_check_earlyloading() { |
|---|
| 44 | if ( (bool) get_site_option( 'decalog_earlyloading', true ) ) { |
|---|
| 45 | if ( defined( 'DECALOG_EARLY_INIT' ) && defined( 'DECALOG_BOOTSTRAPPED' ) && DECALOG_BOOTSTRAPPED && DECALOG_EARLY_INIT ) { |
|---|
| 46 | return; |
|---|
| 47 | } |
|---|
| 48 | if ( ! defined( 'DECALOG_EARLY_INIT' ) ) { |
|---|
| 49 | $target = WPMU_PLUGIN_DIR . '/_decalog_loader.php'; |
|---|
| 50 | $source = __DIR__ . '/assets/_decalog_loader.php'; |
|---|
| 51 | if ( ! file_exists( $target ) ) { |
|---|
| 52 | if ( ! file_exists( WPMU_PLUGIN_DIR ) ) { |
|---|
| 53 | // phpcs:ignore |
|---|
| 54 | @mkdir( WPMU_PLUGIN_DIR ); |
|---|
| 55 | } |
|---|
| 56 | if ( ! file_exists( WPMU_PLUGIN_DIR ) ) { |
|---|
| 57 | define( 'DECALOG_EARLY_INIT_WPMUDIR_ERROR', true ); |
|---|
| 58 | } |
|---|
| 59 | if ( file_exists( $source ) ) { |
|---|
| 60 | // phpcs:ignore |
|---|
| 61 | @copy( $source, $target ); |
|---|
| 62 | // phpcs:ignore |
|---|
| 63 | @chmod( $target, 0644 ); |
|---|
| 64 | } |
|---|
| 65 | if ( ! file_exists( $target ) ) { |
|---|
| 66 | define( 'DECALOG_EARLY_INIT_COPY_ERROR', true ); |
|---|
| 67 | } |
|---|
| 68 | } else { |
|---|
| 69 | define( 'DECALOG_EARLY_INIT_ERROR', true ); |
|---|
| 70 | } |
|---|
| 71 | } |
|---|
| 72 | if ( ! defined( 'DECALOG_BOOTSTRAPPED' ) ) { |
|---|
| 73 | $target = WP_CONTENT_DIR . '/fatal-error-handler.php'; |
|---|
| 74 | $source = __DIR__ . '/assets/fatal-error-handler.php'; |
|---|
| 75 | if ( ! file_exists( $target ) ) { |
|---|
| 76 | if ( file_exists( $source ) ) { |
|---|
| 77 | // phpcs:ignore |
|---|
| 78 | @copy( $source, $target ); |
|---|
| 79 | // phpcs:ignore |
|---|
| 80 | @chmod( $target, 0644 ); |
|---|
| 81 | } |
|---|
| 82 | if ( ! file_exists( $target ) ) { |
|---|
| 83 | define( 'DECALOG_BOOTSTRAP_COPY_ERROR', true ); |
|---|
| 84 | } |
|---|
| 85 | } else { |
|---|
| 86 | define( 'DECALOG_BOOTSTRAP_ALREADY_EXISTS_ERROR', true ); |
|---|
| 87 | } |
|---|
| 88 | } |
|---|
| 89 | } else { |
|---|
| 90 | $file = WPMU_PLUGIN_DIR . '/_decalog_loader.php'; |
|---|
| 91 | if ( file_exists( $file ) ) { |
|---|
| 92 | // phpcs:ignore |
|---|
| 93 | @unlink( $file ); |
|---|
| 94 | } |
|---|
| 95 | if ( defined( 'DECALOG_BOOTSTRAPPED' ) ) { |
|---|
| 96 | $file = WP_CONTENT_DIR . '/fatal-error-handler.php'; |
|---|
| 97 | if ( file_exists( $file ) ) { |
|---|
| 98 | // phpcs:ignore |
|---|
| 99 | @unlink( $file ); |
|---|
| 100 | } |
|---|
| 101 | } |
|---|
| 102 | } |
|---|
| 103 | } |
|---|
| 104 | |
|---|
| 105 | /** |
|---|
| 106 | * Removes the file responsible to early initialization in mu-plugins and drop-ins dir. |
|---|
| 107 | * |
|---|
| 108 | * @since 3.0.0 |
|---|
| 109 | */ |
|---|
| 110 | function decalog_reset_earlyloading() { |
|---|
| 111 | $target = WPMU_PLUGIN_DIR . '/_decalog_loader.php'; |
|---|
| 112 | if ( file_exists( $target ) ) { |
|---|
| 113 | // phpcs:ignore |
|---|
| 114 | @unlink( $target ); |
|---|
| 115 | } |
|---|
| 116 | if ( defined( 'DECALOG_BOOTSTRAPPED' ) ) { |
|---|
| 117 | $target = WP_CONTENT_DIR . '/fatal-error-handler.php'; |
|---|
| 118 | if ( file_exists( $target ) ) { |
|---|
| 119 | // phpcs:ignore |
|---|
| 120 | @unlink( $target ); |
|---|
| 121 | } |
|---|
| 122 | } |
|---|
| 123 | } |
|---|
| 124 | |
|---|
| 125 | /** |
|---|
| 126 | * Disable early loading if we update from version lower than 4.0.0. |
|---|
| 127 | * |
|---|
| 128 | * @since 4.0.0 |
|---|
| 129 | */ |
|---|
| 130 | function decalog_update_earlyloading_if_needed() { |
|---|
| 131 | if ( ! str_starts_with( (string) get_site_option( 'decalog_version', '0.0.0' ), '4.' ) ) { |
|---|
| 132 | update_site_option( 'decalog_earlyloading', false ); |
|---|
| 133 | } |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | /** |
|---|
| 137 | * The code that runs during plugin activation. |
|---|
| 138 | * |
|---|
| 139 | * @since 1.0.0 |
|---|
| 140 | */ |
|---|
| 141 | function decalog_activate() { |
|---|
| 142 | decalog_reset_earlyloading(); |
|---|
| 143 | Decalog\Plugin\Activator::activate(); |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | /** |
|---|
| 147 | * The code that runs during plugin deactivation. |
|---|
| 148 | * |
|---|
| 149 | * @since 1.0.0 |
|---|
| 150 | */ |
|---|
| 151 | function decalog_deactivate() { |
|---|
| 152 | decalog_reset_earlyloading(); |
|---|
| 153 | Decalog\Plugin\Deactivator::deactivate(); |
|---|
| 154 | } |
|---|
| 155 | |
|---|
| 156 | /** |
|---|
| 157 | * The code that runs during plugin uninstallation. |
|---|
| 158 | * |
|---|
| 159 | * @since 1.0.0 |
|---|
| 160 | */ |
|---|
| 161 | function decalog_uninstall() { |
|---|
| 162 | decalog_reset_earlyloading(); |
|---|
| 163 | Decalog\Plugin\Uninstaller::uninstall(); |
|---|
| 164 | } |
|---|
| 165 | |
|---|
| 166 | /** |
|---|
| 167 | * Begins execution of the plugin. |
|---|
| 168 | * |
|---|
| 169 | * @since 1.0.0 |
|---|
| 170 | */ |
|---|
| 171 | function decalog_run() { |
|---|
| 172 | //decalog_update_earlyloading_if_needed(); |
|---|
| 173 | require_once __DIR__ . '/includes/features/class-wpcli.php'; |
|---|
| 174 | decalog_check_earlyloading(); |
|---|
| 175 | $plugin = new Decalog\Plugin\Core(); |
|---|
| 176 | $plugin->run(); |
|---|
| 177 | } |
|---|
| 178 | if ( ! defined( 'DECALOG_MAX_SHUTDOWN_PRIORITY' ) ) { |
|---|
| 179 | define( 'DECALOG_MAX_SHUTDOWN_PRIORITY', PHP_INT_MAX - 1000 ); |
|---|
| 180 | } |
|---|
| 181 | register_activation_hook( __FILE__, 'decalog_activate' ); |
|---|
| 182 | register_deactivation_hook( __FILE__, 'decalog_deactivate' ); |
|---|
| 183 | register_uninstall_hook( __FILE__, 'decalog_uninstall' ); |
|---|
| 184 | decalog_run(); |
|---|