| 1 |
<?php |
| 2 |
/** |
| 3 |
* Application/Plugin specific functions. |
| 4 |
*/ |
| 5 |
|
| 6 |
declare( strict_types=1 ); |
| 7 |
|
| 8 |
use SolidWP\Performance\Container; |
| 9 |
use SolidWP\Performance\Core; |
| 10 |
use SolidWP\Performance\lucatume\DI52\Container as DI52Container; |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
/** |
| 17 |
* Initialize the plugin singleton and ensure we only have a single |
| 18 |
* instance of our container. |
| 19 |
* |
| 20 |
* @return Core |
| 21 |
*/ |
| 22 |
function swpsp_plugin(): Core { |
| 23 |
// In the event we don't have a container in our core class yet. |
| 24 |
$container = new Container( new DI52Container() ); |
| 25 |
|
| 26 |
// This singleton will not use a new container if one is already set. |
| 27 |
return Core::instance( realpath( __DIR__ . '/../../solid-performance.php' ), $container ); |
| 28 |
} |
| 29 |
|
| 30 |
/** |
| 31 |
* Log to the error log if WP_DEBUG is set to true. |
| 32 |
* |
| 33 |
* @param string|mixed[] $data The data to log. |
| 34 |
* |
| 35 |
* @return void |
| 36 |
*/ |
| 37 |
function swpsp_log( $data ): void { |
| 38 |
if ( ! defined( 'WP_DEBUG' ) || ! WP_DEBUG || ! function_exists( 'error_log' ) ) { |
| 39 |
return; |
| 40 |
} |
| 41 |
|
| 42 |
if ( is_array( $data ) ) { |
| 43 |
$data = print_r( $data, true ); |
| 44 |
} |
| 45 |
|
| 46 |
error_log( $data ); |
| 47 |
} |
| 48 |
|