| 1 |
<?php |
| 2 |
|
| 3 |
namespace DLM\Classes; |
| 4 |
|
| 5 |
/** |
| 6 |
* Plugin Activation |
| 7 |
* |
| 8 |
* @since 1.0.0 |
| 9 |
*/ |
| 10 |
class Activation { |
| 11 |
|
| 12 |
/** |
| 13 |
* Code that runs on plugin activation |
| 14 |
* |
| 15 |
* @since 1.0.0 |
| 16 |
*/ |
| 17 |
public function activate() { |
| 18 |
|
| 19 |
// Create option to store logger status |
| 20 |
|
| 21 |
$option_value = array( |
| 22 |
'status' => 'disabled', |
| 23 |
'on' => date( 'Y-m-d H:i:s' ), |
| 24 |
); |
| 25 |
|
| 26 |
update_option( 'debug_log_manager', $option_value, false ); |
| 27 |
|
| 28 |
// Create option to store auto-refresh feature status |
| 29 |
|
| 30 |
$autorefresh_status = 'disabled'; |
| 31 |
|
| 32 |
update_option( 'debug_log_manager_autorefresh', $autorefresh_status, false ); |
| 33 |
|
| 34 |
// Create debug.log file in custom location for use in WP_DEBUG_LOG constant |
| 35 |
|
| 36 |
$uploads_path = wp_upload_dir()['basedir'] . '/debug-log-manager'; |
| 37 |
|
| 38 |
$plain_domain = str_replace( array( ".", "-" ), "", sanitize_text_field( $_SERVER['SERVER_NAME'] ) ); // e.g. wwwgooglecom |
| 39 |
|
| 40 |
$unique_key = date( 'YmdHi' ) . rand(12345678, 87654321); |
| 41 |
|
| 42 |
$debug_log_file_path = $uploads_path . '/' . $plain_domain . '_' . $unique_key .'_debug.log'; |
| 43 |
|
| 44 |
$debug_log_file_path_in_option = get_option( 'debug_log_manager_file_path' ); |
| 45 |
|
| 46 |
if ( false === $debug_log_file_path_in_option |
| 47 |
|| false === strpos( $debug_log_file_path_in_option, ABSPATH ) |
| 48 |
) { |
| 49 |
|
| 50 |
update_option( 'debug_log_manager_file_path', $debug_log_file_path, false ); |
| 51 |
|
| 52 |
$debug_log_file_path_in_option = get_option( 'debug_log_manager_file_path' ); |
| 53 |
|
| 54 |
} |
| 55 |
|
| 56 |
if ( ! is_dir( $uploads_path ) ) { |
| 57 |
mkdir( $uploads_path ); // create directory in /uploads folder |
| 58 |
// create empty index to prevent directory browsing and download of the debug log file |
| 59 |
file_put_contents( $uploads_path . '/index.php', '<?php // Nothing to show here' ); |
| 60 |
} |
| 61 |
|
| 62 |
if ( ! is_file( $debug_log_file_path_in_option ) ) { |
| 63 |
file_put_contents( $debug_log_file_path_in_option, '' ); // create empty log file |
| 64 |
} else {} |
| 65 |
|
| 66 |
} |
| 67 |
|
| 68 |
} |