PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.9.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.9.0
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
solid-performance / src / functions / app.php

app.php in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution 1.9.0, at src/functions/app.php

73 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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
49 /**
50 * Properly get the home path, as WordPress's function doesn't seem to work in all cases.
51 *
52 * This is based off the same code that wp-load.php uses to find wp-config.php.
53 *
54 * @throws RuntimeException If we can't find the home path.
55 *
56 * @return string
57 */
58 function swpsp_get_document_root(): string {
59 $path = '';
60
61 if ( file_exists( ABSPATH . 'wp-config.php' ) ) {
62 $path = ABSPATH;
63 } elseif ( file_exists( dirname( ABSPATH ) . '/wp-config.php' ) && ! file_exists( dirname( ABSPATH ) . '/wp-settings.php' ) ) {
64 $path = dirname( ABSPATH );
65 }
66
67 if ( ! $path ) {
68 throw new RuntimeException( 'Unable to document root' );
69 }
70
71 return trailingslashit( $path );
72 }
73