fix(mu-plugins): strengthen core management behavior and correct MU plugin metadata

This commit is contained in:
HostForge Systems
2026-04-18 12:01:20 +08:00
parent a6a904ef15
commit 854f5a2ed5
3 changed files with 52 additions and 25 deletions

View File

@@ -6,6 +6,7 @@
* Version: 1.0.0
* Author: HostForge
* Author URI: https://hostforge.cloud
* Network: true
*/
if (! defined('ABSPATH')) {

View File

@@ -4,22 +4,16 @@ if (! defined('ABSPATH')) {
exit;
}
/**
* Define the HostForge Systems base path.
*/
if (! defined('HOSTFORGE_SYSTEMS_PATH')) {
define('HOSTFORGE_SYSTEMS_PATH', __DIR__);
}
/**
* Define the HostForge Systems base URL.
*/
if (! defined('HOSTFORGE_SYSTEMS_URL')) {
define('HOSTFORGE_SYSTEMS_URL', content_url('mu-plugins/hostforge-systems'));
}
/**
* Load the required HostForge Systems core files.
* Load required HostForge core files.
*
* @return void
*/
@@ -42,7 +36,7 @@ function hostforge_systems_load_core_files()
hostforge_systems_load_core_files();
/**
* Boot the HostForge Systems loader.
* Boot HostForge Systems.
*
* @return void
*/

View File

@@ -11,14 +11,13 @@ if (! defined('ABSPATH')) {
}
/**
* Disables WordPress core updates inside wp-admin.
*
* WordPress core updates must be managed through the HostForge Dashboard.
* Disable WordPress core updates in wp-admin and route update management
* through the HostForge platform.
*/
class Disable_Core_Updates implements Module_Interface
{
/**
* Register WordPress hooks for this module.
* Register WordPress hooks.
*
* @return void
*/
@@ -30,25 +29,28 @@ class Disable_Core_Updates implements Module_Interface
add_filter('allow_minor_auto_core_updates', '__return_false');
add_filter('allow_major_auto_core_updates', '__return_false');
add_filter('pre_site_transient_update_core', [$this, 'filter_core_update_transient']);
add_filter('site_transient_update_core', [$this, 'filter_core_update_transient']);
add_filter('pre_set_site_transient_update_core', [$this, 'filter_core_update_transient']);
add_filter('pre_option__site_transient_update_core', [$this, 'force_empty_core_updates']);
add_filter('pre_site_transient_update_core', [$this, 'force_empty_core_updates'], 999);
add_filter('site_transient_update_core', [$this, 'force_empty_core_updates'], 999);
add_filter('pre_set_site_transient_update_core', [$this, 'force_empty_core_updates'], 999);
add_action('admin_init', [$this, 'clear_core_update_transient'], 1);
add_action('admin_init', [$this, 'remove_core_update_nag'], 1);
add_action('admin_init', [$this, 'maybe_redirect_updates_screen'], 1);
add_action('init', [$this, 'disable_core_version_check'], 1);
add_filter('schedule_event', [$this, 'block_core_version_check_schedule'], 1);
add_action('admin_menu', [$this, 'remove_updates_submenu'], 999);
add_action('admin_notices', [$this, 'render_admin_notice']);
}
/**
* Force an empty WordPress core update response.
* Return a clean empty core update object.
*
* @param mixed $transient Existing transient value.
* @return \stdClass
*/
public function filter_core_update_transient($transient): stdClass
public function force_empty_core_updates(): stdClass
{
$clean = new stdClass();
$clean->updates = [];
@@ -60,10 +62,7 @@ class Disable_Core_Updates implements Module_Interface
}
/**
* Clear any cached WordPress core update transient.
*
* This runs on every admin request so stale update data
* does not continue to appear in wp-admin.
* Clear cached core update transient during admin requests.
*
* @return void
*/
@@ -74,6 +73,11 @@ class Disable_Core_Updates implements Module_Interface
}
delete_site_transient('update_core');
wp_cache_delete('update_core', 'site-transient');
wp_cache_delete('update_core', 'site-options');
wp_cache_delete('_site_transient_update_core', 'options');
wp_cache_delete('update_core', 'options');
}
/**
@@ -87,7 +91,7 @@ class Disable_Core_Updates implements Module_Interface
}
/**
* Redirect users away from the WordPress Updates screen.
* Redirect users away from the native Updates screen.
*
* @return void
*/
@@ -108,7 +112,34 @@ class Disable_Core_Updates implements Module_Interface
}
/**
* Remove the Updates submenu from wp-admin.
* Disable WordPress core version checking hooks.
*
* @return void
*/
public function disable_core_version_check(): void
{
remove_action('init', 'wp_version_check');
remove_action('admin_init', '_maybe_update_core');
remove_action('wp_version_check', 'wp_version_check');
}
/**
* Block scheduling of core version checks.
*
* @param object|false $event Scheduled event object.
* @return object|false
*/
public function block_core_version_check_schedule($event)
{
if (is_object($event) && isset($event->hook) && $event->hook === 'wp_version_check') {
return false;
}
return $event;
}
/**
* Remove Updates submenu entries.
*
* @return void
*/
@@ -116,10 +147,11 @@ class Disable_Core_Updates implements Module_Interface
{
remove_submenu_page('index.php', 'update-core.php');
remove_submenu_page('options-general.php', 'update-core.php');
remove_submenu_page('tools.php', 'update-core.php');
}
/**
* Render a HostForge notice in wp-admin.
* Render HostForge notice on selected admin screens.
*
* @return void
*/