class-helper.php
67 lines
| 1 | <?php |
| 2 | namespace RSSSL\lib\admin; |
| 3 | |
| 4 | /** |
| 5 | * Trait admin helper |
| 6 | * |
| 7 | * |
| 8 | * @package RSSSL\helper |
| 9 | * @since 8.2 |
| 10 | * |
| 11 | * @author Really Simple Security |
| 12 | * @see https://really-simple-ssl.com |
| 13 | */ |
| 14 | trait Helper { |
| 15 | /** |
| 16 | * Get the wp-config path |
| 17 | * |
| 18 | * @return string |
| 19 | */ |
| 20 | public function wpconfig_path(): string { |
| 21 | // Allow the wp-config.php path to be overridden via a filter. |
| 22 | $filtered_path = apply_filters( 'rsssl_wpconfig_path', '' ); |
| 23 | |
| 24 | // If a filtered path is provided, validate it. |
| 25 | if ( ! empty( $filtered_path ) ) { |
| 26 | $directory = dirname( $filtered_path ); |
| 27 | |
| 28 | // Ensure the directory exists before checking for the file. |
| 29 | if ( is_dir( $directory ) && file_exists( $filtered_path ) ) { |
| 30 | return $filtered_path; |
| 31 | } |
| 32 | } |
| 33 | |
| 34 | // Default behavior to locate wp-config.php |
| 35 | $location_of_wp_config = ABSPATH; |
| 36 | if ( ! file_exists( ABSPATH . 'wp-config.php' ) && file_exists( dirname( ABSPATH ) . '/wp-config.php' ) ) { |
| 37 | $location_of_wp_config = dirname( ABSPATH ); |
| 38 | } |
| 39 | |
| 40 | $location_of_wp_config = trailingslashit( $location_of_wp_config ); |
| 41 | $wpconfig_path = $location_of_wp_config . 'wp-config.php'; |
| 42 | |
| 43 | // Check if the file exists and return the path if valid. |
| 44 | if ( file_exists( $wpconfig_path ) ) { |
| 45 | return $wpconfig_path; |
| 46 | } |
| 47 | |
| 48 | // Return an empty string if no valid wp-config.php path is found. |
| 49 | return ''; |
| 50 | } |
| 51 | |
| 52 | |
| 53 | /** |
| 54 | * Log a message if WP_DEBUG is enabled |
| 55 | * |
| 56 | * @param string $message |
| 57 | * |
| 58 | * @return void |
| 59 | */ |
| 60 | public function log( string $message ): void { |
| 61 | if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) { |
| 62 | error_log( "Really Simple Security: ".$message ); |
| 63 | } |
| 64 | } |
| 65 | |
| 66 | } |
| 67 |