diff --git a/1984-hosting-support.php b/1984-hosting-support.php index 73a31a2..22ece69 100644 --- a/1984-hosting-support.php +++ b/1984-hosting-support.php @@ -272,22 +272,26 @@ class HostingSupport1984 { * * @return string[] */ - private function get_protected_plugins(): array { - $own = plugin_basename( __FILE__ ); + private function get_protected_plugins(): array { + // Always protect this plugin from deactivation/deletion. + $own = plugin_basename( __FILE__ ); + $protected = array( $own ); - return array( - $own, - 'patchstack/patchstack.php', - ); - } + // Additionally protect Patchstack - but only while it is active. + if ( $this->is_patchstack_active() ) { + $protected[] = 'patchstack/patchstack.php'; + } + + return $protected; + } /** * Intercept admin actions attempting to deactivate or delete protected plugins and block them. */ - public function protect_plugins_admin_actions() { - // Collect requested action(s). - $action = isset( $_REQUEST['action'] ) ? sanitize_key( (string) $_REQUEST['action'] ) : ''; - $action2 = isset( $_REQUEST['action2'] ) ? sanitize_key( (string) $_REQUEST['action2'] ) : ''; + public function protect_plugins_admin_actions() { + // Collect requested action(s). + $action = isset( $_REQUEST['action'] ) ? sanitize_key( (string) $_REQUEST['action'] ) : ''; + $action2 = isset( $_REQUEST['action2'] ) ? sanitize_key( (string) $_REQUEST['action2'] ) : ''; $targets = array(); if ( ! empty( $_REQUEST['plugin'] ) ) { @@ -315,19 +319,19 @@ class HostingSupport1984 { return; } - $protected = $this->get_protected_plugins(); - $intersect = array_intersect( $targets, $protected ); - if ( ! empty( $intersect ) ) { - wp_die( - __( 'For security, this action is blocked: 1984 Hosting Support and Patchstack cannot be deactivated or deleted while this policy is active.', 'hostingsupport1984' ), - 403 - ); - } - } + $protected = $this->get_protected_plugins(); + $intersect = array_intersect( $targets, $protected ); + if ( ! empty( $intersect ) ) { + wp_die( + __( 'For security, this action is blocked: 1984 Hosting Support cannot be deactivated or deleted. Patchstack cannot be deactivated or deleted while it is active.', 'hostingsupport1984' ), + 403 + ); + } + } } $hosting_support_1984 = new HostingSupport1984(); -const A1984_HOSTING_SUPPORT_BASE_FILE = __FILE__; +define( 'A1984_HOSTING_SUPPORT_BASE_FILE', __FILE__ ); require_once __DIR__ . '/1984-hosting-support-ui.php'; diff --git a/js/1984-hosting-support.js b/js/1984-hosting-support.js index c70d2fe..2d6a6c1 100644 --- a/js/1984-hosting-support.js +++ b/js/1984-hosting-support.js @@ -11,12 +11,7 @@ function HostingSupport1984CopyEmailAddress(e) { .catch(err => console.error("Clipboard write failed:", err)); } -document.querySelector('#hosting-support-1984-link') - ?.addEventListener('click', HostingSupport1984CopyEmailAddress); - -if (document.querySelector('#hosting-support-1984-link')) { - document.querySelector('#hosting-support-1984-link').addEventListener( - 'click', - HostingSupport1984CopyEmailAddress - ); +const hostingSupport1984Link = document.querySelector('#hosting-support-1984-link'); +if (hostingSupport1984Link) { + hostingSupport1984Link.addEventListener('click', HostingSupport1984CopyEmailAddress); }