| @@ -400,9 +400,9 @@ | ||
| 400 | 400 | <!-- Debug Mode Controls --> |
| 401 | 401 | <div style="margin-bottom: 30px;"> |
| 402 | 402 | <h4 style="margin-top: 0; color: var(--dashboard-text-primary);">Controls</h4> |
| 403 | 403 | |
| 404 | - <form method="post" action="<?php echo admin_url('admin.php?page=' . $this->get_page_slug() . '&tab=advanced'); ?>"> | |
| 404 | + <form method="post" action="<?php echo esc_url(admin_url('admin.php?page=' . $this->get_page_slug() . '&tab=advanced')); ?>"> | |
| 405 | 405 | <input type="hidden" name="metasync_debug_mode_action_advanced" value="1" /> |
| 406 | 406 | <?php wp_nonce_field('metasync_debug_mode_action_advanced', 'metasync_debug_mode_nonce_advanced'); ?> |
| 407 | 407 | |
| 408 | 408 | <?php if (!$status['enabled']): ?> |
| @@ -498,9 +498,9 @@ | ||
| 498 | 498 | } |
| 499 | 499 | }); |
| 500 | 500 | |
| 501 | 501 | <?php if ($status['enabled'] && !$status['indefinite']): ?> |
| 502 | - var initialTimeRemaining = <?php echo $status['time_remaining']; ?>; | |
| 502 | + var initialTimeRemaining = <?php echo (int) $status['time_remaining']; ?>; | |
| 503 | 503 | var hasReloaded = false; |
| 504 | 504 | |
| 505 | 505 | function updateDebugTimeRemaining() { |
| 506 | 506 | if (initialTimeRemaining <= 0 || hasReloaded) { |
| @@ -507,12 +507,12 @@ | ||
| 507 | 507 | return; |
| 508 | 508 | } |
| 509 | 509 | |
| 510 | 510 | $.ajax({ |
| 511 | - url: '<?php echo rest_url('metasync/v1/debug-mode/status'); ?>', | |
| 511 | + url: '<?php echo esc_url(rest_url('metasync/v1/debug-mode/status')); ?>', | |
| 512 | 512 | method: 'GET', |
| 513 | 513 | beforeSend: function(xhr) { |
| 514 | - xhr.setRequestHeader('X-WP-Nonce', '<?php echo wp_create_nonce('wp_rest'); ?>'); | |
| 514 | + xhr.setRequestHeader('X-WP-Nonce', '<?php echo esc_attr(wp_create_nonce('wp_rest')); ?>'); | |
| 515 | 515 | }, |
| 516 | 516 | success: function(response) { |
| 517 | 517 | console.log('MetaSync Debug Mode Status:', response); |
| 518 | 518 | |
| @@ -596,9 +596,9 @@ | ||
| 596 | 596 | <td style="padding: 10px 12px; color: var(--dashboard-text-secondary); font-size: 13px;"> |
| 597 | 597 | <?php |
| 598 | 598 | $last_seen = strtotime($error['last_seen']); |
| 599 | 599 | $time_diff = human_time_diff($last_seen, current_time('timestamp')); |
| 600 | - echo esc_html($error['last_seen']) . ' <span style="color: var(--dashboard-text-secondary);">(' . $time_diff . ' ago)</span>'; | |
| 600 | + echo esc_html($error['last_seen']) . ' <span style="color: var(--dashboard-text-secondary);">(' . esc_html($time_diff) . ' ago)</span>'; | |
| 601 | 601 | ?> |
| 602 | 602 | </td> |
| 603 | 603 | <td style="padding: 10px 12px; color: var(--dashboard-text-primary); max-width: 400px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;" title="<?php echo esc_attr($error['message']); ?>"> |
| 604 | 604 | <?php echo esc_html($error['message']); ?> |
| @@ -608,9 +608,9 @@ | ||
| 608 | 608 | </tbody> |
| 609 | 609 | </table> |
| 610 | 610 | </div> |
| 611 | 611 | |
| 612 | - <form method="post" action="<?php echo admin_url('admin.php?page=' . $this->get_page_slug() . '&tab=advanced'); ?>" style="margin-bottom: 20px;"> | |
| 612 | + <form method="post" action="<?php echo esc_url(admin_url('admin.php?page=' . $this->get_page_slug() . '&tab=advanced')); ?>" style="margin-bottom: 20px;"> | |
| 613 | 613 | <input type="hidden" name="clear_error_summary" value="yes" /> |
| 614 | 614 | <?php wp_nonce_field('metasync_clear_error_summary_nonce', 'clear_error_summary_nonce'); ?> |
| 615 | 615 | <button type="submit" class="button button-secondary" style="background: #dc3232; color: #ffffff; border: none; padding: 8px 16px; border-radius: 4px; font-weight: 500; cursor: pointer;"> |
| 616 | 616 | <span class="dashicons dashicons-trash" style="margin-top:3px;font-size:15px;width:15px;height:15px;"></span> Clear Error Summary |
| @@ -642,9 +642,9 @@ | ||
| 642 | 642 | <div style="margin-bottom: 30px;"> |
| 643 | 643 | <h4 style="margin-top: 0; color: var(--dashboard-text-primary);">Clear Error Logs</h4> |
| 644 | 644 | <p style="margin-bottom: 15px; color: var(--dashboard-text-secondary);">Clear WordPress error logs to free up space and remove old entries.</p> |
| 645 | 645 | |
| 646 | - <form method="post" action="<?php echo admin_url('admin.php?page=' . $this->get_page_slug() . '&tab=advanced'); ?>" style="margin-bottom: 20px;"> | |
| 646 | + <form method="post" action="<?php echo esc_url(admin_url('admin.php?page=' . $this->get_page_slug() . '&tab=advanced')); ?>" style="margin-bottom: 20px;"> | |
| 647 | 647 | <input type="hidden" name="clear_log" value="yes" /> |
| 648 | 648 | <?php wp_nonce_field('metasync_clear_log_nonce', 'clear_log_nonce'); ?> |
| 649 | 649 | <button type="submit" class="metasync-btn-primary" style="background: var(--dashboard-gradient-primary); color: #ffffff; border: none; padding: 10px 20px; border-radius: 8px; font-weight: 500; cursor: pointer; transition: all 0.3s ease; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); display: inline-block; width: auto; min-width: 240px; max-width: fit-content;" onmouseover="this.style.transform='translateY(-2px)'; this.style.boxShadow='0 4px 8px rgba(0, 0, 0, 0.15)';" onmouseout="this.style.transform='translateY(0)'; this.style.boxShadow='0 2px 4px rgba(0, 0, 0, 0.1)';"> |
| 650 | 650 | 🧹 Clear Error Logs |
| @@ -902,8 +902,18 @@ | ||
| 902 | 902 | // Code Minification settings |
| 903 | 903 | 'metasync_code_minification', |
| 904 | 904 | ]; |
| 905 | 905 | |
| 906 | + // Capture the complete white-label identity BEFORE the | |
| 907 | + // destructive clear so it can be restored afterwards. The | |
| 908 | + // reset is meant to remove operational data and credentials, | |
| 909 | + // not the reseller's public branding, logos, domains, custom | |
| 910 | + // OTTO name, visibility/access controls, or recovery settings. | |
| 911 | + if (!class_exists('Metasync_Whitelabel_Preservation')) { | |
| 912 | + require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-metasync-whitelabel-preservation.php'; | |
| 913 | + } | |
| 914 | + $whitelabel_state = Metasync_Whitelabel_Preservation::extract_whitelabel_state(); | |
| 915 | + | |
| 906 | 916 | $cleared_count = 0; |
| 907 | 917 | foreach ($metasync_options_to_clear as $option_name) { |
| 908 | 918 | if (get_option($option_name) !== false) { |
| 909 | 919 | delete_option($option_name); |
| @@ -945,9 +955,35 @@ | ||
| 945 | 955 | 'options_cleared_count' => $cleared_count, |
| 946 | 956 | 'new_token_prefix' => substr($new_plugin_auth_token, 0, 8) . '...', |
| 947 | 957 | 'triggered_by' => 'settings_reset_action' |
| 948 | 958 | ), 'info'); |
| 949 | - | |
| 959 | + | |
| 960 | + // Restore the preserved white-label identity over the freshly | |
| 961 | + // cleared options. A failed restore must not report success. | |
| 962 | + $restored = Metasync_Whitelabel_Preservation::restore_whitelabel_state($whitelabel_state); | |
| 963 | + if (!$restored) { | |
| 964 | + $redirect_url = admin_url('admin.php?page=' . $this->get_page_slug() . '&tab=advanced&clear_settings_error=1'); | |
| 965 | + wp_redirect($redirect_url); | |
| 966 | + exit; | |
| 967 | + } | |
| 968 | + | |
| 969 | + // Re-synchronise the branded plugin file headers so the | |
| 970 | + // WordPress plugin list and the plugin UI stay branded after | |
| 971 | + // the reset. Only attempted when white-label branding exists, | |
| 972 | + // and a failed sync is logged as a warning, not reported as a | |
| 973 | + // reset failure: the reset itself (operational clear + fresh | |
| 974 | + // token + branding restore) has already succeeded at this | |
| 975 | + // point, and hosts with read-only plugin files would otherwise | |
| 976 | + // never see a successful reset. | |
| 977 | + if (!empty($whitelabel_state['whitelabel']) || !empty($whitelabel_state['general'])) { | |
| 978 | + if (!class_exists('Metasync_Activator')) { | |
| 979 | + require_once plugin_dir_path(dirname(__FILE__)) . 'includes/class-metasync-activator.php'; | |
| 980 | + } | |
| 981 | + if (!Metasync_Activator::sync_plugin_file_headers()) { | |
| 982 | + error_log('MetaSync: failed to re-synchronise branded plugin file headers after the settings reset.'); | |
| 983 | + } | |
| 984 | + } | |
| 985 | + | |
| 950 | 986 | $redirect_url = admin_url('admin.php?page=' . $this->get_page_slug() . '&tab=advanced&settings_cleared=1'); |
| 951 | 987 | wp_safe_redirect($redirect_url); |
| 952 | 988 | exit; |
| 953 | 989 | } else { |