From 65da70b00a427228638d019c0993cdbbe11e54bf Mon Sep 17 00:00:00 2001 From: namithj <48271037+namithj@users.noreply.github.com> Date: Fri, 8 Nov 2024 07:39:05 +0530 Subject: [PATCH 1/8] Backup Backup --- assets/css/aspire-update.css | 138 ++++++++++++++++++++++++++++-- assets/js/aspire-update.js | 76 ++++++++++++++++ includes/class-admin-settings.php | 19 ++++ 3 files changed, 225 insertions(+), 8 deletions(-) diff --git a/assets/css/aspire-update.css b/assets/css/aspire-update.css index 1a53466..4c43b36 100644 --- a/assets/css/aspire-update.css +++ b/assets/css/aspire-update.css @@ -40,22 +40,143 @@ } .aspireupdate-notice { - background-color: #f0f6fc; - border: 1px solid #70b9e3; - border-radius: 50px; - max-width: max-content; + background-color: #f0f6fc; + border: 1px solid #70b9e3; + border-radius: 50px; + max-width: max-content; } .aspireupdate-notice p::before { - content: ''; - display: inline-block; - margin-inline-end: .5em; - vertical-align: middle; + content: ""; + display: inline-block; + margin-inline-end: 0.5em; + vertical-align: middle; background: url(../images/aspirepress-logo-icon.svg) no-repeat center center / 20px 20px; height: 20px; width: 20px; } +.button.button-clearlog { + border-color: #b32d2e; + color: #b32d2e; +} + +#aspireupdate-log-viewer { + position: fixed; + width: 100%; + height: 100%; + top: 0; + right: 0; + bottom: 0; + left: 0; + z-index: 999998; + display: none; +} + +#aspireupdate-log-viewer:before { + content: ""; + position: fixed; + width: 100%; + height: 100%; + top: 0; + right: 0; + bottom: 0; + left: 0; + z-index: 999998; + background: rgba(255, 255, 255, 0.9); +} + +#aspireupdate-log-viewer .outer { + position: fixed; + width: calc(100% - 60px); + height: calc(100% - 60px); + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + background-color: lightgray; + z-index: 999999; + box-shadow: 0 0 5px #000; + padding: 15px; +} + +#aspireupdate-log-viewer .outer span.close { + position: fixed; + right: -1px; + z-index: 999999; + display: block; + width: 20px; + height: 20px; + line-height: 20px; + font-size: 20px; + top: 1px; + text-align: center; + font-weight: 600; + cursor: pointer; +} + +#aspireupdate-log-viewer .outer span.close:before, +#aspireupdate-log-viewer .outer span.close:after { + position: absolute; + top: 50%; + left: 50%; + width: 4px; + height: 20px; + background-color: #b32d2e; + transform: rotate(45deg) translate(-50%, -50%); + transform-origin: top left; + content: ''; +} +#aspireupdate-log-viewer .outer span.close:after { + transform: rotate(-45deg) translate(-50%, -50%); +} + +#aspireupdate-log-viewer .inner { + position: fixed; + width: calc(100% - 40px); + height: calc(100% - 40px); + top: 20px; + right: 20px; + bottom: 20px; + left: 20px; + counter-reset: line; + overflow: auto; +} + +#aspireupdate-log-viewer .inner div { + display: flex; + align-items: flex-start; +} + +#aspireupdate-log-viewer .inner > div:nth-child(odd) { + background-color: #e9e9e9; + /* Light shade */ +} + +#aspireupdate-log-viewer .inner > div:nth-child(even) { + background-color: #e0e0e0; + /* Darker shade */ +} + +#aspireupdate-log-viewer .inner .number { + counter-increment: line; + width: 60px; + text-align: right; + padding-right: 10px; + font-weight: bold; + color: #555; +} + +#aspireupdate-log-viewer .inner .number::before { + content: counter(line); +} + +#aspireupdate-log-viewer .inner .content { + white-space: pre-wrap; + word-break: break-all; + margin: 0; + flex: 1; +} + #voltron { color: transparent; font-size: clamp(4px, 0.9vw, 8px); @@ -74,6 +195,7 @@ 100% { color: inherit; } + 50% { color: transparent; } diff --git a/assets/js/aspire-update.js b/assets/js/aspire-update.js index dd6e76e..b0d1191 100644 --- a/assets/js/aspire-update.js +++ b/assets/js/aspire-update.js @@ -2,8 +2,84 @@ jQuery(document).ready(function () { new ApiRewrites(); new ApiDebug(); + + new ViewLog(); }); +class ViewLog { + constructor() { + ViewLog.viewlog_button.init(); + ViewLog.viewlog_popup.init(); + } + + static viewlog_button = { + field: jQuery('#aspireupdate-button-viewlog'), + init() { + ViewLog.viewlog_button.field.click(function () { + ViewLog.viewlog_popup.show(); + }); + } + } + + static viewlog_popup = { + field: jQuery('#aspireupdate-log-viewer'), + popup_inner: jQuery('#aspireupdate-log-viewer .inner'), + close_button: jQuery('#aspireupdate-log-viewer span.close'), + init() { + ViewLog.viewlog_popup.close_button.click(function () { + ViewLog.viewlog_popup.close(); + }); + + jQuery(document).keydown(function (event) { + if ((event.keyCode === 27) && ViewLog.viewlog_popup.field.is(':visible')) { + ViewLog.viewlog_popup.close(); + } + }); + }, + show() { + let lines = jQuery('#voltron').html().split('\n'); + + jQuery.each(lines, function (index, line) { + jQuery('
...................................................................................................:?%,............................................................................. .................................................................................................,;*%:.............................................................................. @@ -548,6 +557,16 @@ public function register_settings() { ); } + /** + * Render content inside sections. + * + * @param array $args The Field Parameters. + * + * @return void Echos the Field HTML. + */ + public function add_settings_section_callback( $args = [] ) { + } + /** * The Fields API which any CMS should have in its core but something we dont, hence this ugly hack. * From 5b8efdfb52bac5fa7a83104030d3719d220fb226 Mon Sep 17 00:00:00 2001 From: Namith Jawahar <48271037+namithj@users.noreply.github.com> Date: Fri, 8 Nov 2024 22:53:33 +0530 Subject: [PATCH 2/8] Backup Backup --- assets/js/aspire-update.js | 33 ++++++++++- includes/class-debug.php | 114 +++++++++++++++++++++++++++++-------- 2 files changed, 122 insertions(+), 25 deletions(-) diff --git a/assets/js/aspire-update.js b/assets/js/aspire-update.js index b0d1191..bef88f3 100644 --- a/assets/js/aspire-update.js +++ b/assets/js/aspire-update.js @@ -6,6 +6,27 @@ jQuery(document).ready(function () { new ViewLog(); }); +class ClearLog { + constructor() { + ClearLog.clearlog_button.init(); + } + + static clearlog_button = { + field: jQuery('#aspireupdate-button-clearlog'), + init() { + ClearLog.clearlog_button.field.click(function () { + + }); + }, + show() { + ClearLog.clearlog_button.field.show(); + }, + hide() { + ClearLog.clearlog_button.field.hide(); + } + } +} + class ViewLog { constructor() { ViewLog.viewlog_button.init(); @@ -18,6 +39,12 @@ class ViewLog { ViewLog.viewlog_button.field.click(function () { ViewLog.viewlog_popup.show(); }); + }, + show() { + ViewLog.viewlog_button.field.show(); + }, + hide() { + ViewLog.viewlog_button.field.hide(); } } @@ -268,7 +295,7 @@ class ApiDebug { init() { ApiDebug.enabled_debug.sub_fields = [ ApiDebug.debug_type, - ApiDebug.disable_ssl_verification + ApiDebug.disable_ssl_verification, ]; ApiDebug.enabled_debug.field.change(function () { @@ -281,9 +308,13 @@ class ApiDebug { }, show_options() { Fields.show(ApiDebug.enabled_debug.sub_fields); + ViewLog.viewlog_button.show(); + ClearLog.clearlog_button.show(); }, hide_options() { Fields.hide(ApiDebug.enabled_debug.sub_fields); + ViewLog.viewlog_button.hide(); + ClearLog.clearlog_button.hide(); } } diff --git a/includes/class-debug.php b/includes/class-debug.php index 5a64b24..e2a0f8e 100644 --- a/includes/class-debug.php +++ b/includes/class-debug.php @@ -19,6 +19,15 @@ class Debug { */ private static $log_file = 'debug-aspire-update.log'; + /** + * Get the Log file path. + * + * @return string The Log file path. + */ + private static function get_file_path() { + return WP_CONTENT_DIR . '/' . self::$log_file; + } + /** * Initializes the WordPress Filesystem. * @@ -36,14 +45,13 @@ private static function init_filesystem() { } /** - * Logs a message to the debug log file. + * Checks the filesystem status and logs error to debug log. * - * @param mixed $message The message to log. - * @param string $type The log level ('string', 'request', 'response'). + * @param WP_Filesystem_Base $wp_filesystem The filesystem object. + * + * @return true|false true omn success and false on failure. */ - public static function log( $message, $type = 'string' ) { - $wp_filesystem = self::init_filesystem(); - + private static function verify_filesystem( $wp_filesystem ) { if ( ! $wp_filesystem ) { if ( defined( 'WP_DEBUG' ) && @@ -58,29 +66,87 @@ public static function log( $message, $type = 'string' ) { error_log( 'AspireUpdate - Could not open or write to the file system. Check file system permissions to debug log directory.' ); // phpcs:enable } - return; + return false; } + return true; + } - $timestamp = gmdate( 'Y-m-d H:i:s' ); - $formatted_message = sprintf( - "[%s] [%s]: %s\n" . PHP_EOL, - $timestamp, - strtoupper( $type ), - self::format_message( $message ) - ); - - $file_path = WP_CONTENT_DIR . '/' . self::$log_file; + /** + * Get the content of the log file truncated upto N number of lines. + * + * @param integer $limit Max no of lines to return. + * + * @return string The File content truncate upto the number of lines set in the limit parameter. + */ + public static function read( $limit ) { + $wp_filesystem = self::init_filesystem(); + if ( self::verify_filesystem( $wp_filesystem ) ) { + $file_path = self::get_file_path(); + + if ( $wp_filesystem->exists( $file_path ) && $wp_filesystem->is_readable( $file_path ) ) { + $file_handle = $wp_filesystem->get_contents_array( $file_path ); + return implode( "\n", array_slice( $file_handle, 0, $limit ) ); + } else { + return esc_html__( 'Error: Unable to read the log file.', 'AspireUpdate' ); + } + } + } - $content = ''; - if ( $wp_filesystem->exists( $file_path ) ) { - $content = $wp_filesystem->get_contents( $file_path ); + /** + * Clear content of the log file. + * + * @return void + */ + public static function clear() { + $wp_filesystem = self::init_filesystem(); + if ( self::verify_filesystem( $wp_filesystem ) ) { + $file_path = self::get_file_path(); + if ( $wp_filesystem->exists( $file_path ) ) { + if ( $wp_filesystem->is_writable( $file_path ) ) { + $wp_filesystem->put_contents( + $file_path, + '', + FS_CHMOD_FILE + ); + } + } } + } + + /** + * Logs a message to the debug log file. + * + * @param mixed $message The message to log. + * @param string $type The log level ('string', 'request', 'response'). + */ + public static function log( $message, $type = 'string' ) { + $wp_filesystem = self::init_filesystem(); + if ( self::verify_filesystem( $wp_filesystem ) ) { + $timestamp = gmdate( 'Y-m-d H:i:s' ); + $formatted_message = sprintf( + "[%s] [%s]: %s\n" . PHP_EOL, + $timestamp, + strtoupper( $type ), + self::format_message( $message ) + ); + + $file_path = self::get_file_path(); + + $content = ''; + if ( $wp_filesystem->exists( $file_path ) ) { + if ( $wp_filesystem->is_readable( $file_path ) ) { + $content = $wp_filesystem->get_contents( $file_path ); + } + } - $wp_filesystem->put_contents( - $file_path, - $content . $formatted_message, - FS_CHMOD_FILE - ); + if ( $wp_filesystem->is_writable( $file_path ) ) { + $wp_filesystem->put_contents( + $file_path, + $formatted_message . $content, + FS_CHMOD_FILE + ); + } + } } /** From 631572d32080948f90b1b124a84a3d0e1f8992c7 Mon Sep 17 00:00:00 2001 From: Namith Jawahar <48271037+namithj@users.noreply.github.com> Date: Sat, 9 Nov 2024 01:10:09 +0530 Subject: [PATCH 3/8] Clear and View Logs Clear and View Logs --- assets/js/aspire-update.js | 81 +++++++++++++++++-------------- includes/class-admin-settings.php | 12 +++-- includes/class-controller.php | 32 ++++++++++++ includes/class-debug.php | 42 ++++++++++------ 4 files changed, 112 insertions(+), 55 deletions(-) diff --git a/assets/js/aspire-update.js b/assets/js/aspire-update.js index bef88f3..a7343cd 100644 --- a/assets/js/aspire-update.js +++ b/assets/js/aspire-update.js @@ -3,6 +3,7 @@ jQuery(document).ready(function () { new ApiRewrites(); new ApiDebug(); + new ClearLog(); new ViewLog(); }); @@ -15,7 +16,7 @@ class ClearLog { field: jQuery('#aspireupdate-button-clearlog'), init() { ClearLog.clearlog_button.field.click(function () { - + ClearLog.clearlog_button.clear(); }); }, show() { @@ -23,7 +24,24 @@ class ClearLog { }, hide() { ClearLog.clearlog_button.field.hide(); - } + }, + clear() { + let parameters = { + "url": aspireupdate.ajax_url, + "type": "POST", + "data": { + "nonce": aspireupdate.nonce, + "action": "aspireupdate_clear_log" + } + }; + jQuery.ajax(parameters) + .done(function (response) { + alert(aspireupdate.clear_log_success_message); + }) + .fail(function (response) { + alert(aspireupdate.clear_log_failed_message); + }); + }, } } @@ -64,41 +82,30 @@ class ViewLog { }); }, show() { - let lines = jQuery('#voltron').html().split('\n'); - - jQuery.each(lines, function (index, line) { - jQuery('') - .append( - jQuery('').addClass('number'), - jQuery('').addClass('content').text(line) - ) - .appendTo(ViewLog.viewlog_popup.popup_inner); - jQuery('') - .append( - jQuery('').addClass('number'), - jQuery('').addClass('content').text(line) - ) - .appendTo(ViewLog.viewlog_popup.popup_inner); - jQuery('') - .append( - jQuery('').addClass('number'), - jQuery('').addClass('content').text(line) - ) - .appendTo(ViewLog.viewlog_popup.popup_inner); - jQuery('') - .append( - jQuery('').addClass('number'), - jQuery('').addClass('content').text(line) - ) - .appendTo(ViewLog.viewlog_popup.popup_inner); - jQuery('') - .append( - jQuery('').addClass('number'), - jQuery('').addClass('content').text(line) - ) - .appendTo(ViewLog.viewlog_popup.popup_inner); - }); - ViewLog.viewlog_popup.field.show(); + let parameters = { + "url": aspireupdate.ajax_url, + "type": "POST", + "data": { + "nonce": aspireupdate.nonce, + "action": "aspireupdate_read_log" + } + }; + jQuery.ajax(parameters) + .done(function (response) { + let lines = response.data.content.split(aspireupdate.line_ending); + jQuery.each(lines, function (index, line) { + jQuery('') + .append( + jQuery('').addClass('number'), + jQuery('').addClass('content').text(line) + ) + .appendTo(ViewLog.viewlog_popup.popup_inner); + }); + ViewLog.viewlog_popup.field.show(); + }) + .fail(function (response) { + alert(aspireupdate.read_log_failed_message); + }); }, close() { ViewLog.viewlog_popup.field.hide(); diff --git a/includes/class-admin-settings.php b/includes/class-admin-settings.php index 839714a..65092a1 100644 --- a/includes/class-admin-settings.php +++ b/includes/class-admin-settings.php @@ -292,10 +292,14 @@ public function admin_enqueue_scripts( $hook ) { 'aspire_update_settings_js', 'aspireupdate', [ - 'ajax_url' => network_admin_url( 'admin-ajax.php' ), - 'nonce' => wp_create_nonce( 'aspireupdate-ajax' ), - 'domain' => Utilities::get_top_level_domain(), - 'string_unexpected_error' => esc_html__( 'Unexpected Error:', 'AspireUpdate' ), + 'ajax_url' => network_admin_url( 'admin-ajax.php' ), + 'nonce' => wp_create_nonce( 'aspireupdate-ajax' ), + 'domain' => Utilities::get_top_level_domain(), + 'line_ending' => PHP_EOL, + 'string_unexpected_error' => esc_html__( 'Unexpected Error:', 'AspireUpdate' ), + 'clear_log_success_message' => esc_html__( 'Log file successfully cleared.', 'AspireUpdate' ), + 'clear_log_failed_message' => esc_html__( 'Clearing Log file failed.', 'AspireUpdate' ), + 'read_log_failed_message' => esc_html__( 'Reading Log file failed.', 'AspireUpdate' ), ] ); } diff --git a/includes/class-controller.php b/includes/class-controller.php index e537455..7d65780 100644 --- a/includes/class-controller.php +++ b/includes/class-controller.php @@ -22,6 +22,8 @@ public function __construct() { $this->api_rewrite(); add_action( 'init', [ $this, 'load_textdomain' ] ); + add_action( 'wp_ajax_aspireupdate_clear_log', [ $this, 'clear_log' ] ); + add_action( 'wp_ajax_aspireupdate_read_log', [ $this, 'read_log' ] ); } /** @@ -49,8 +51,38 @@ private function api_rewrite() { } } + /** + * Ajax action to clear the Log file. + * + * @return void + */ + public function clear_log() { + if ( isset( $_POST['nonce'] ) || wp_verify_nonce( $_POST['nonce'], 'aspireupdate-ajax' ) ) { + Debug::clear(); + wp_send_json_success(); + } + wp_send_json_error(); + } + + /** + * Ajax action to read the Log file. + * + * @return void + */ + public function read_log() { + if ( isset( $_POST['nonce'] ) || wp_verify_nonce( $_POST['nonce'], 'aspireupdate-ajax' ) ) { + wp_send_json_success( + [ + 'content' => Debug::read( 1000 ), + ] + ); + } + wp_send_json_error(); + } + /** * Load translations. + * * @return void */ public function load_textdomain() { diff --git a/includes/class-debug.php b/includes/class-debug.php index e2a0f8e..8548108 100644 --- a/includes/class-debug.php +++ b/includes/class-debug.php @@ -74,18 +74,35 @@ private static function verify_filesystem( $wp_filesystem ) { /** * Get the content of the log file truncated upto N number of lines. * - * @param integer $limit Max no of lines to return. + * @param integer $limit Max no of lines to return. Defaults to a 1000 lines. * * @return string The File content truncate upto the number of lines set in the limit parameter. */ - public static function read( $limit ) { + public static function read( $limit = 1000 ) { $wp_filesystem = self::init_filesystem(); if ( self::verify_filesystem( $wp_filesystem ) ) { $file_path = self::get_file_path(); if ( $wp_filesystem->exists( $file_path ) && $wp_filesystem->is_readable( $file_path ) ) { - $file_handle = $wp_filesystem->get_contents_array( $file_path ); - return implode( "\n", array_slice( $file_handle, 0, $limit ) ); + $file_content = $wp_filesystem->get_contents_array( $file_path ); + $content = ''; + $index = 0; + foreach ( $file_content as $file_content_lines ) { + if ( ( $index < $limit ) ) { + $content .= $file_content_lines . PHP_EOL; + ++$index; + } + } + if ( '' === trim( $content ) ) { + $content = esc_html__( '*****Log file is empty.*****', 'AspireUpdate' ); + } elseif ( $limit < count( $file_content ) ) { + $content .= PHP_EOL . sprintf( + /* translators: 1: The number of lines at which the content was truncated. */ + esc_html__( '*****Log truncated at %s lines.*****', 'AspireUpdate' ), + $limit + ); + } + return $content; } else { return esc_html__( 'Error: Unable to read the log file.', 'AspireUpdate' ); } @@ -124,11 +141,11 @@ public static function log( $message, $type = 'string' ) { if ( self::verify_filesystem( $wp_filesystem ) ) { $timestamp = gmdate( 'Y-m-d H:i:s' ); $formatted_message = sprintf( - "[%s] [%s]: %s\n" . PHP_EOL, + '[%s] [%s]: %s', $timestamp, strtoupper( $type ), self::format_message( $message ) - ); + ) . PHP_EOL; $file_path = self::get_file_path(); @@ -138,14 +155,11 @@ public static function log( $message, $type = 'string' ) { $content = $wp_filesystem->get_contents( $file_path ); } } - - if ( $wp_filesystem->is_writable( $file_path ) ) { - $wp_filesystem->put_contents( - $file_path, - $formatted_message . $content, - FS_CHMOD_FILE - ); - } + $wp_filesystem->put_contents( + $file_path, + $formatted_message . $content, + FS_CHMOD_FILE + ); } } From b5e2eb2a03f14c89ecf1e82d27121d1fd16d8400 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]"Date: Fri, 8 Nov 2024 19:42:40 +0000 Subject: [PATCH 4/8] Update blueprint.json for branch/tag --- assets/playground/blueprint.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/playground/blueprint.json b/assets/playground/blueprint.json index d9e8453..193f5b9 100644 --- a/assets/playground/blueprint.json +++ b/assets/playground/blueprint.json @@ -17,7 +17,7 @@ "blogname": "AspireUpdate Demo Site" }, "plugins": [ - "https://github-proxy.com/proxy/?repo=AspirePress/AspireUpdate&branch=playground-ready", + "https://github-proxy.com/proxy/?repo=namithj/AspireUpdate&branch=main", "error-log-viewer", "plugin-check" ], From 869502fd1cdad8b612f55533fa5f5d167b1db4f7 Mon Sep 17 00:00:00 2001 From: Namith Jawahar <48271037+namithj@users.noreply.github.com> Date: Sat, 9 Nov 2024 07:46:21 +0530 Subject: [PATCH 5/8] Review Updates Review Updates --- assets/css/aspire-update.css | 270 +++++++++++++++--------------- assets/js/aspire-update.js | 30 ++-- includes/class-admin-settings.php | 12 +- includes/class-controller.php | 12 +- includes/class-debug.php | 76 +++++---- 5 files changed, 203 insertions(+), 197 deletions(-) diff --git a/assets/css/aspire-update.css b/assets/css/aspire-update.css index 4c43b36..5731446 100644 --- a/assets/css/aspire-update.css +++ b/assets/css/aspire-update.css @@ -1,208 +1,210 @@ @keyframes glow { - 0% { - background-color: rgba(255, 223, 0, 0.1); - } + 0% { + background-color: rgba(255, 223, 0, 0.1); + } - 100% { - background-color: none; - } + 100% { + background-color: none; + } } .glow-reveal { - animation: glow 0.5s ease-in-out; + animation: glow 0.5s ease-in-out; } .aspireupdate-settings-field-hosts-wrapper .aspireupdate-settings-field-hosts-row { - margin: 0 0 10px; + margin: 0 0 10px; } #aspireupdate-generate-api-key { - display: inline-block; - width: 30px; - height: 30px; - background: url(../images/icon-key.svg) no-repeat center center / 24px 24px; - background-color: #cbcbcb; - border: 1px solid #8c8f94; - border-radius: 3px; - clip-path: inset(0 0 0 0); - color: transparent; - cursor: pointer; - transition: background-color 0.3s ease; + display: inline-block; + width: 30px; + height: 30px; + background: url(../images/icon-key.svg) no-repeat center center / 24px 24px; + background-color: #cbcbcb; + border: 1px solid #8c8f94; + border-radius: 3px; + clip-path: inset(0 0 0 0); + color: transparent; + cursor: pointer; + transition: background-color 0.3s ease; } #aspireupdate-generate-api-key:hover { - background-color: #e3e3e3; + background-color: #e3e3e3; } .aspireupdate-settings-field-wrapper p.error { - color: #bc3b3b; - display: none; + color: #bc3b3b; + display: none; } .aspireupdate-notice { - background-color: #f0f6fc; - border: 1px solid #70b9e3; - border-radius: 50px; - max-width: max-content; + background-color: #f0f6fc; + border: 1px solid #70b9e3; + border-radius: 50px; + max-width: max-content; } .aspireupdate-notice p::before { - content: ""; - display: inline-block; - margin-inline-end: 0.5em; - vertical-align: middle; - background: url(../images/aspirepress-logo-icon.svg) no-repeat center center / 20px 20px; - height: 20px; - width: 20px; + content: ""; + display: inline-block; + margin-inline-end: 0.5em; + vertical-align: middle; + background: url(../images/aspirepress-logo-icon.svg) no-repeat center center / 20px 20px; + height: 20px; + width: 20px; } .button.button-clearlog { - border-color: #b32d2e; - color: #b32d2e; + border-color: #b32d2e; + color: #b32d2e; } #aspireupdate-log-viewer { - position: fixed; - width: 100%; - height: 100%; - top: 0; - right: 0; - bottom: 0; - left: 0; - z-index: 999998; - display: none; + position: fixed; + width: 100%; + height: 100%; + top: 0; + right: 0; + bottom: 0; + left: 0; + z-index: 999998; + display: none; } #aspireupdate-log-viewer:before { - content: ""; - position: fixed; - width: 100%; - height: 100%; - top: 0; - right: 0; - bottom: 0; - left: 0; - z-index: 999998; - background: rgba(255, 255, 255, 0.9); + content: ""; + position: fixed; + width: 100%; + height: 100%; + top: 0; + right: 0; + bottom: 0; + left: 0; + z-index: 999998; + background: rgba(255, 255, 255, 0.9); } #aspireupdate-log-viewer .outer { - position: fixed; - width: calc(100% - 60px); - height: calc(100% - 60px); - top: 50%; - left: 50%; - transform: translate(-50%, -50%); - background-color: lightgray; - z-index: 999999; - box-shadow: 0 0 5px #000; - padding: 15px; + position: fixed; + width: calc(100% - 60px); + height: calc(100% - 60px); + top: 50%; + left: 50%; + transform: translate(-50%, -50%); + background-color: lightgray; + z-index: 999999; + box-shadow: 0 0 5px #000; + padding: 15px; } #aspireupdate-log-viewer .outer span.close { - position: fixed; - right: -1px; - z-index: 999999; - display: block; - width: 20px; - height: 20px; - line-height: 20px; - font-size: 20px; - top: 1px; - text-align: center; - font-weight: 600; - cursor: pointer; -} - -#aspireupdate-log-viewer .outer span.close:before, + position: fixed; + right: -1px; + z-index: 999999; + display: block; + width: 20px; + height: 20px; + line-height: 20px; + font-size: 20px; + top: 1px; + text-align: center; + font-weight: 600; + cursor: pointer; +} + +#aspireupdate-log-viewer .outer span.close:before, #aspireupdate-log-viewer .outer span.close:after { - position: absolute; - top: 50%; - left: 50%; - width: 4px; - height: 20px; - background-color: #b32d2e; - transform: rotate(45deg) translate(-50%, -50%); - transform-origin: top left; - content: ''; + position: absolute; + top: 50%; + left: 50%; + width: 4px; + height: 20px; + background-color: #b32d2e; + transform: rotate(45deg) translate(-50%, -50%); + transform-origin: top left; + content: ''; } + #aspireupdate-log-viewer .outer span.close:after { - transform: rotate(-45deg) translate(-50%, -50%); + transform: rotate(-45deg) translate(-50%, -50%); } #aspireupdate-log-viewer .inner { - position: fixed; - width: calc(100% - 40px); - height: calc(100% - 40px); - top: 20px; - right: 20px; - bottom: 20px; - left: 20px; - counter-reset: line; - overflow: auto; + position: fixed; + width: calc(100% - 40px); + height: calc(100% - 40px); + top: 20px; + right: 20px; + bottom: 20px; + left: 20px; + counter-reset: line; + overflow: auto; } #aspireupdate-log-viewer .inner div { - display: flex; - align-items: flex-start; + display: flex; + align-items: flex-start; } -#aspireupdate-log-viewer .inner > div:nth-child(odd) { - background-color: #e9e9e9; - /* Light shade */ +#aspireupdate-log-viewer .inner>div:nth-child(odd) { + background-color: #e9e9e9; + /* Light shade */ } -#aspireupdate-log-viewer .inner > div:nth-child(even) { - background-color: #e0e0e0; - /* Darker shade */ +#aspireupdate-log-viewer .inner>div:nth-child(even) { + background-color: #e0e0e0; + /* Darker shade */ } #aspireupdate-log-viewer .inner .number { - counter-increment: line; - width: 60px; - text-align: right; - padding-right: 10px; - font-weight: bold; - color: #555; + counter-increment: line; + width: 60px; + text-align: right; + padding-right: 10px; + font-weight: bold; + color: #555; } #aspireupdate-log-viewer .inner .number::before { - content: counter(line); + content: counter(line); } #aspireupdate-log-viewer .inner .content { - white-space: pre-wrap; - word-break: break-all; - margin: 0; - flex: 1; + white-space: pre-wrap; + word-break: break-all; + margin: 0; + flex: 1; } #voltron { - color: transparent; - font-size: clamp(4px, 0.9vw, 8px); - line-height: 6px; - display: inline-block; - cursor: default; + color: transparent; + font-size: clamp(4px, 0.9vw, 8px); + line-height: 6px; + display: inline-block; + cursor: default; } #voltron:hover { - animation: blink 1.8s ease-in-out infinite; - animation-delay: 5s; + animation: blink 1.8s ease-in-out infinite; + animation-delay: 5s; } @keyframes blink { - 0%, - 100% { - color: inherit; - } - 50% { - color: transparent; - } + 0%, + 100% { + color: inherit; + } + + 50% { + color: transparent; + } } @media only screen and (max-width: 576px) { - #voltron { - display: none; - } + #voltron { + display: none; + } } diff --git a/assets/js/aspire-update.js b/assets/js/aspire-update.js index a7343cd..f0289ea 100644 --- a/assets/js/aspire-update.js +++ b/assets/js/aspire-update.js @@ -36,7 +36,11 @@ class ClearLog { }; jQuery.ajax(parameters) .done(function (response) { - alert(aspireupdate.clear_log_success_message); + if (true == response.data.cleared) { + alert(aspireupdate.clear_log_success_message); + } else { + alert(aspireupdate.clear_log_failed_message); + } }) .fail(function (response) { alert(aspireupdate.clear_log_failed_message); @@ -92,16 +96,20 @@ class ViewLog { }; jQuery.ajax(parameters) .done(function (response) { - let lines = response.data.content.split(aspireupdate.line_ending); - jQuery.each(lines, function (index, line) { - jQuery(' ') - .append( - jQuery('').addClass('number'), - jQuery('').addClass('content').text(line) - ) - .appendTo(ViewLog.viewlog_popup.popup_inner); - }); - ViewLog.viewlog_popup.field.show(); + if ('' != response.data.content) { + let lines = response.data.content.split(aspireupdate.line_ending); + jQuery.each(lines, function (index, line) { + jQuery('') + .append( + jQuery('').addClass('number'), + jQuery('').addClass('content').text(line) + ) + .appendTo(ViewLog.viewlog_popup.popup_inner); + }); + ViewLog.viewlog_popup.field.show(); + } else { + alert(aspireupdate.read_log_failed_message); + } }) .fail(function (response) { alert(aspireupdate.read_log_failed_message); diff --git a/includes/class-admin-settings.php b/includes/class-admin-settings.php index 65092a1..8962a84 100644 --- a/includes/class-admin-settings.php +++ b/includes/class-admin-settings.php @@ -338,7 +338,7 @@ public function the_settings_page() {-@@ -561,16 +561,6 @@ public function register_settings() { ); } - /** - * Render content inside sections. - * - * @param array $args The Field Parameters. - * - * @return void Echos the Field HTML. - */ - public function add_settings_section_callback( $args = [] ) { - } - /** * The Fields API which any CMS should have in its core but something we dont, hence this ugly hack. * diff --git a/includes/class-controller.php b/includes/class-controller.php index 7d65780..6bf534e 100644 --- a/includes/class-controller.php +++ b/includes/class-controller.php @@ -57,9 +57,13 @@ private function api_rewrite() { * @return void */ public function clear_log() { - if ( isset( $_POST['nonce'] ) || wp_verify_nonce( $_POST['nonce'], 'aspireupdate-ajax' ) ) { - Debug::clear(); - wp_send_json_success(); + if ( isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'aspireupdate-ajax' ) ) { + $status = Debug::clear(); + wp_send_json_success( + [ + 'cleared' => $status, + ] + ); } wp_send_json_error(); } @@ -70,7 +74,7 @@ public function clear_log() { * @return void */ public function read_log() { - if ( isset( $_POST['nonce'] ) || wp_verify_nonce( $_POST['nonce'], 'aspireupdate-ajax' ) ) { + if ( isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'aspireupdate-ajax' ) ) { wp_send_json_success( [ 'content' => Debug::read( 1000 ), diff --git a/includes/class-debug.php b/includes/class-debug.php index 8548108..8303013 100644 --- a/includes/class-debug.php +++ b/includes/class-debug.php @@ -49,7 +49,7 @@ private static function init_filesystem() { * * @param WP_Filesystem_Base $wp_filesystem The filesystem object. * - * @return true|false true omn success and false on failure. + * @return boolean true on success and false on failure. */ private static function verify_filesystem( $wp_filesystem ) { if ( ! $wp_filesystem ) { @@ -74,60 +74,62 @@ private static function verify_filesystem( $wp_filesystem ) { /** * Get the content of the log file truncated upto N number of lines. * - * @param integer $limit Max no of lines to return. Defaults to a 1000 lines. + * @param integer $limit Max no of lines to return. Defaults to a 1000 lines. * * @return string The File content truncate upto the number of lines set in the limit parameter. */ public static function read( $limit = 1000 ) { $wp_filesystem = self::init_filesystem(); - if ( self::verify_filesystem( $wp_filesystem ) ) { - $file_path = self::get_file_path(); + if ( ! self::verify_filesystem( $wp_filesystem ) ) { + return esc_html__( 'Error: Unable to read the log file.', 'AspireUpdate' ); + } - if ( $wp_filesystem->exists( $file_path ) && $wp_filesystem->is_readable( $file_path ) ) { - $file_content = $wp_filesystem->get_contents_array( $file_path ); - $content = ''; - $index = 0; - foreach ( $file_content as $file_content_lines ) { - if ( ( $index < $limit ) ) { - $content .= $file_content_lines . PHP_EOL; - ++$index; - } - } - if ( '' === trim( $content ) ) { - $content = esc_html__( '*****Log file is empty.*****', 'AspireUpdate' ); - } elseif ( $limit < count( $file_content ) ) { - $content .= PHP_EOL . sprintf( - /* translators: 1: The number of lines at which the content was truncated. */ - esc_html__( '*****Log truncated at %s lines.*****', 'AspireUpdate' ), - $limit - ); + $file_path = self::get_file_path(); + + if ( $wp_filesystem->exists( $file_path ) && $wp_filesystem->is_readable( $file_path ) ) { + $file_content = $wp_filesystem->get_contents_array( $file_path ); + $content = ''; + $index = 0; + foreach ( $file_content as $file_content_lines ) { + if ( ( $index < $limit ) ) { + $content .= $file_content_lines . PHP_EOL; + ++$index; } - return $content; - } else { - return esc_html__( 'Error: Unable to read the log file.', 'AspireUpdate' ); } + if ( '' === trim( $content ) ) { + $content = esc_html__( '*****Log file is empty.*****', 'AspireUpdate' ); + } elseif ( $limit < count( $file_content ) ) { + $content .= PHP_EOL . sprintf( + /* translators: 1: The number of lines at which the content was truncated. */ + esc_html__( '*****Log truncated at %s lines.*****', 'AspireUpdate' ), + $limit + ); + } + return $content; } + return esc_html__( 'Error: Unable to read the log file.', 'AspireUpdate' ); } /** * Clear content of the log file. * - * @return void + * @return boolean true on success and false on failure. */ public static function clear() { $wp_filesystem = self::init_filesystem(); - if ( self::verify_filesystem( $wp_filesystem ) ) { - $file_path = self::get_file_path(); - if ( $wp_filesystem->exists( $file_path ) ) { - if ( $wp_filesystem->is_writable( $file_path ) ) { - $wp_filesystem->put_contents( - $file_path, - '', - FS_CHMOD_FILE - ); - } - } + if ( ! self::verify_filesystem( $wp_filesystem ) ) { + return false; + } + $file_path = self::get_file_path(); + if ( $wp_filesystem->exists( $file_path ) && $wp_filesystem->is_writable( $file_path ) ) { + $wp_filesystem->put_contents( + $file_path, + '', + FS_CHMOD_FILE + ); + return true; } + return false; } /** From 74a7a224a835080cde529fdd6b240accb05b9df6 Mon Sep 17 00:00:00 2001 From: Namith Jawahar <48271037+namithj@users.noreply.github.com> Date: Tue, 12 Nov 2024 21:27:52 +0530 Subject: [PATCH 6/8] Use WP_Error Class Use WP_Error Class for returning error conditions. --- includes/class-controller.php | 4 +++ includes/class-debug.php | 52 ++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 25 deletions(-) diff --git a/includes/class-controller.php b/includes/class-controller.php index 6bf534e..01c0234 100644 --- a/includes/class-controller.php +++ b/includes/class-controller.php @@ -75,6 +75,10 @@ public function clear_log() { */ public function read_log() { if ( isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'aspireupdate-ajax' ) ) { + $content = Debug::read( 1000 ); + if ( is_wp_error( $content ) ) { + $content = $content->get_error_message(); + } wp_send_json_success( [ 'content' => Debug::read( 1000 ), diff --git a/includes/class-debug.php b/includes/class-debug.php index 8303013..9d6f87f 100644 --- a/includes/class-debug.php +++ b/includes/class-debug.php @@ -76,38 +76,34 @@ private static function verify_filesystem( $wp_filesystem ) { * * @param integer $limit Max no of lines to return. Defaults to a 1000 lines. * - * @return string The File content truncate upto the number of lines set in the limit parameter. + * @return string|WP_Error The File content truncate upto the number of lines set in the limit parameter. */ public static function read( $limit = 1000 ) { $wp_filesystem = self::init_filesystem(); - if ( ! self::verify_filesystem( $wp_filesystem ) ) { - return esc_html__( 'Error: Unable to read the log file.', 'AspireUpdate' ); + $file_path = self::get_file_path(); + if ( ! self::verify_filesystem( $wp_filesystem ) || ! $wp_filesystem->exists( $file_path ) || ! $wp_filesystem->is_readable( $file_path ) ) { + return new \WP_Error( 'not_readable', __( 'Error: Unable to read the log file.', 'AspireUpdate' ) ); } - $file_path = self::get_file_path(); - - if ( $wp_filesystem->exists( $file_path ) && $wp_filesystem->is_readable( $file_path ) ) { - $file_content = $wp_filesystem->get_contents_array( $file_path ); - $content = ''; - $index = 0; - foreach ( $file_content as $file_content_lines ) { - if ( ( $index < $limit ) ) { - $content .= $file_content_lines . PHP_EOL; - ++$index; - } - } - if ( '' === trim( $content ) ) { - $content = esc_html__( '*****Log file is empty.*****', 'AspireUpdate' ); - } elseif ( $limit < count( $file_content ) ) { - $content .= PHP_EOL . sprintf( - /* translators: 1: The number of lines at which the content was truncated. */ - esc_html__( '*****Log truncated at %s lines.*****', 'AspireUpdate' ), - $limit - ); + $file_content = $wp_filesystem->get_contents_array( $file_path ); + $content = ''; + $index = 0; + foreach ( $file_content as $file_content_lines ) { + if ( ( $index < $limit ) ) { + $content .= $file_content_lines . PHP_EOL; + ++$index; } - return $content; } - return esc_html__( 'Error: Unable to read the log file.', 'AspireUpdate' ); + if ( '' === trim( $content ) ) { + $content = esc_html__( '*****Log file is empty.*****', 'AspireUpdate' ); + } elseif ( $limit < count( $file_content ) ) { + $content .= PHP_EOL . sprintf( + /* translators: 1: The number of lines at which the content was truncated. */ + esc_html__( '*****Log truncated at %s lines.*****', 'AspireUpdate' ), + $limit + ); + } + return $content; } /** @@ -187,6 +183,8 @@ private static function format_message( $message ) { * Log an info message. * * @param mixed $message The message to log. + * + * @return void */ public static function log_string( $message ) { $admin_settings = Admin_Settings::get_instance(); @@ -201,6 +199,8 @@ public static function log_string( $message ) { * Log a warning message. * * @param mixed $message The message to log. + * + * @return void */ public static function log_request( $message ) { $admin_settings = Admin_Settings::get_instance(); @@ -215,6 +215,8 @@ public static function log_request( $message ) { * Log an error message. * * @param mixed $message The message to log. + * + * @return void */ public static function log_response( $message ) { $admin_settings = Admin_Settings::get_instance(); From 05a0b9c90a4b103871805a7e1c9c1fb1cd976744 Mon Sep 17 00:00:00 2001 From: Namith Jawahar <48271037+namithj@users.noreply.github.com> Date: Wed, 13 Nov 2024 08:02:46 +0530 Subject: [PATCH 7/8] Errors handling Errors are shown in alert boxes instead of inside the viewer. New error states added for clear logs. --- assets/css/aspire-update.css | 2 -- assets/js/aspire-update.js | 18 +++++----- includes/class-admin-settings.php | 3 +- includes/class-controller.php | 49 +++++++++++++++++++------- includes/class-debug.php | 10 +++--- includes/views/page-admin-settings.php | 9 +++++ 6 files changed, 62 insertions(+), 29 deletions(-) diff --git a/assets/css/aspire-update.css b/assets/css/aspire-update.css index 5731446..7eea8b2 100644 --- a/assets/css/aspire-update.css +++ b/assets/css/aspire-update.css @@ -150,12 +150,10 @@ #aspireupdate-log-viewer .inner>div:nth-child(odd) { background-color: #e9e9e9; - /* Light shade */ } #aspireupdate-log-viewer .inner>div:nth-child(even) { background-color: #e0e0e0; - /* Darker shade */ } #aspireupdate-log-viewer .inner .number { diff --git a/assets/js/aspire-update.js b/assets/js/aspire-update.js index f0289ea..eeaa95c 100644 --- a/assets/js/aspire-update.js +++ b/assets/js/aspire-update.js @@ -36,14 +36,14 @@ class ClearLog { }; jQuery.ajax(parameters) .done(function (response) { - if (true == response.data.cleared) { - alert(aspireupdate.clear_log_success_message); + if ('' != response.data.message) { + alert(response.data.message); } else { - alert(aspireupdate.clear_log_failed_message); + alert(aspireupdate.unexpected_error); } }) .fail(function (response) { - alert(aspireupdate.clear_log_failed_message); + alert(aspireupdate.unexpected_error); }); }, } @@ -96,7 +96,7 @@ class ViewLog { }; jQuery.ajax(parameters) .done(function (response) { - if ('' != response.data.content) { + if ((true == response.success) && ('' != response.data.content)) { let lines = response.data.content.split(aspireupdate.line_ending); jQuery.each(lines, function (index, line) { jQuery('+') @@ -107,12 +107,14 @@ class ViewLog { .appendTo(ViewLog.viewlog_popup.popup_inner); }); ViewLog.viewlog_popup.field.show(); + } else if ('' != response.data.message) { + alert(response.data.message); } else { - alert(aspireupdate.read_log_failed_message); + alert(aspireupdate.unexpected_error); } }) .fail(function (response) { - alert(aspireupdate.read_log_failed_message); + alert(aspireupdate.unexpected_error); }); }, close() { @@ -268,7 +270,7 @@ class ApiRewrites { if ((response.status === 400) || (response.status === 401)) { ApiRewrites.api_key.show_error(response.responseJSON?.error); } else { - ApiRewrites.api_key.show_error(aspireupdate.string_unexpected_error + ' ' + response.status); + ApiRewrites.api_key.show_error(aspireupdate.unexpected_error + ' : ' + response.status); } }); }, diff --git a/includes/class-admin-settings.php b/includes/class-admin-settings.php index e02f792..339aa99 100644 --- a/includes/class-admin-settings.php +++ b/includes/class-admin-settings.php @@ -295,7 +295,8 @@ public function admin_enqueue_scripts( $hook ) { 'ajax_url' => network_admin_url( 'admin-ajax.php' ), 'nonce' => wp_create_nonce( 'aspireupdate-ajax' ), 'domain' => Utilities::get_top_level_domain(), - 'string_unexpected_error' => esc_html__( 'Unexpected Error:', 'AspireUpdate' ), + 'line_ending' => PHP_EOL, + 'unexpected_error' => esc_html__( 'Unexpected Error', 'AspireUpdate' ), ] ); } diff --git a/includes/class-controller.php b/includes/class-controller.php index 1174519..43b41c7 100644 --- a/includes/class-controller.php +++ b/includes/class-controller.php @@ -56,15 +56,28 @@ private function api_rewrite() { * @return void */ public function clear_log() { - if ( isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'aspireupdate-ajax' ) ) { - $status = Debug::clear(); - wp_send_json_success( + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'aspireupdate-ajax' ) ) { + wp_send_json_error( [ - 'cleared' => $status, + 'message' => __( 'Error: You are not authorized to access this resource.', 'AspireUpdate' ), ] ); } - wp_send_json_error(); + + $status = Debug::clear(); + if ( is_wp_error( $status ) ) { + wp_send_json_error( + [ + 'message' => $status->get_error_message(), + ] + ); + } + + wp_send_json_success( + [ + 'message' => __( 'Log file cleared successfully.', 'AspireUpdate' ), + ] + ); } /** @@ -73,18 +86,28 @@ public function clear_log() { * @return void */ public function read_log() { - if ( isset( $_POST['nonce'] ) && wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'aspireupdate-ajax' ) ) { - $content = Debug::read( 1000 ); - if ( is_wp_error( $content ) ) { - $content = $content->get_error_message(); - } - wp_send_json_success( + if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_key( $_POST['nonce'] ), 'aspireupdate-ajax' ) ) { + wp_send_json_error( [ - 'content' => Debug::read( 1000 ), + 'message' => __( 'Error: You are not authorized to access this resource.', 'AspireUpdate' ), ] ); } - wp_send_json_error(); + + $content = Debug::read( 1000 ); + if ( is_wp_error( $content ) ) { + wp_send_json_error( + [ + 'message' => $content->get_error_message(), + ] + ); + } + + wp_send_json_success( + [ + 'content' => $content, + ] + ); } /** diff --git a/includes/class-debug.php b/includes/class-debug.php index 9d6f87f..7adf319 100644 --- a/includes/class-debug.php +++ b/includes/class-debug.php @@ -109,14 +109,15 @@ public static function read( $limit = 1000 ) { /** * Clear content of the log file. * - * @return boolean true on success and false on failure. + * @return boolean|WP_Error true on success and false on failure. */ public static function clear() { $wp_filesystem = self::init_filesystem(); - if ( ! self::verify_filesystem( $wp_filesystem ) ) { - return false; + $file_path = self::get_file_path(); + if ( ! self::verify_filesystem( $wp_filesystem ) || ! $wp_filesystem->exists( $file_path ) || ! $wp_filesystem->is_writable( $file_path ) ) { + return new \WP_Error( 'not_accessible', __( 'Error: Unable to access the log file.', 'AspireUpdate' ) ); } - $file_path = self::get_file_path(); + if ( $wp_filesystem->exists( $file_path ) && $wp_filesystem->is_writable( $file_path ) ) { $wp_filesystem->put_contents( $file_path, @@ -125,7 +126,6 @@ public static function clear() { ); return true; } - return false; } /** diff --git a/includes/views/page-admin-settings.php b/includes/views/page-admin-settings.php index 5174d2e..4649029 100644 --- a/includes/views/page-admin-settings.php +++ b/includes/views/page-admin-settings.php @@ -15,7 +15,16 @@ + + +From c663bb4ed5e756f865bc9580736a6383545c0368 Mon Sep 17 00:00:00 2001 From: Namith Jawahar <48271037+namithj@users.noreply.github.com> Date: Wed, 13 Nov 2024 08:16:29 +0530 Subject: [PATCH 8/8] Redundant check removed Redundant check removed --- includes/class-debug.php | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/includes/class-debug.php b/includes/class-debug.php index 7adf319..182cc02 100644 --- a/includes/class-debug.php +++ b/includes/class-debug.php @@ -118,14 +118,12 @@ public static function clear() { return new \WP_Error( 'not_accessible', __( 'Error: Unable to access the log file.', 'AspireUpdate' ) ); } - if ( $wp_filesystem->exists( $file_path ) && $wp_filesystem->is_writable( $file_path ) ) { - $wp_filesystem->put_contents( - $file_path, - '', - FS_CHMOD_FILE - ); - return true; - } + $wp_filesystem->put_contents( + $file_path, + '', + FS_CHMOD_FILE + ); + return true; } /**++ ++++