fix(mu-plugins): improve HostForge platform module behavior and plugin metadata
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Plugin Name: HostForge Systems
|
||||
* Description: Required HostForge system integrations and platform-enforced WordPress behavior.
|
||||
* Author: HostForge
|
||||
* Plugin Name: HostForge Platform
|
||||
* Plugin URI: https://hostforge.cloud
|
||||
* Description: Required HostForge platform integrations and managed WordPress behaviors.
|
||||
* Version: 1.0.0
|
||||
* Author: HostForge
|
||||
* Author URI: https://hostforge.cloud
|
||||
*/
|
||||
|
||||
if (! defined('ABSPATH')) {
|
||||
|
||||
@@ -24,42 +24,48 @@ class Disable_Core_Updates implements Module_Interface
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
add_filter('automatic_updater_disabled', '__return_true');
|
||||
add_filter('auto_update_core', '__return_false');
|
||||
add_filter('allow_dev_auto_core_updates', '__return_false');
|
||||
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_action('admin_init', [$this, 'remove_core_update_nag']);
|
||||
add_action('admin_init', [$this, 'block_manual_core_upgrade']);
|
||||
add_action('admin_notices', [$this, 'render_updates_screen_notice']);
|
||||
add_action('admin_init', [$this, 'clear_existing_core_update_transient']);
|
||||
add_action('admin_menu', [$this, 'remove_update_core_submenu'], 999);
|
||||
add_action('admin_notices', [$this, 'render_dashboard_notice']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the WordPress core update transient.
|
||||
*
|
||||
* This makes WordPress behave as if no core updates are available
|
||||
* from wp-admin.
|
||||
* Return an empty core update response.
|
||||
*
|
||||
* @param mixed $transient Existing transient value.
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function filter_core_update_transient($transient): stdClass
|
||||
{
|
||||
if (! is_object($transient)) {
|
||||
$transient = new stdClass();
|
||||
$current_version = get_bloginfo('version');
|
||||
|
||||
$clean = new stdClass();
|
||||
$clean->updates = [];
|
||||
$clean->version_checked = $current_version;
|
||||
$clean->last_checked = time();
|
||||
|
||||
if (isset($transient->translations) && is_array($transient->translations)) {
|
||||
$clean->translations = $transient->translations;
|
||||
} else {
|
||||
$clean->translations = [];
|
||||
}
|
||||
|
||||
$transient->updates = [];
|
||||
$transient->version_checked = get_bloginfo('version');
|
||||
$transient->last_checked = time();
|
||||
|
||||
return $transient;
|
||||
return $clean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the default WordPress update nag from the admin area.
|
||||
* Remove the default WordPress core update nag.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
@@ -69,80 +75,63 @@ class Disable_Core_Updates implements Module_Interface
|
||||
}
|
||||
|
||||
/**
|
||||
* Block manual WordPress core upgrade attempts from wp-admin.
|
||||
* Clear any previously cached core update transient.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function block_manual_core_upgrade(): void
|
||||
public function clear_existing_core_update_transient(): void
|
||||
{
|
||||
if (! is_admin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
delete_site_transient('update_core');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the WordPress Updates submenu.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function remove_update_core_submenu(): void
|
||||
{
|
||||
if (! current_user_can('update_core')) {
|
||||
return;
|
||||
}
|
||||
|
||||
$page = isset($_GET['page']) ? sanitize_text_field(wp_unslash($_GET['page'])) : '';
|
||||
$action = isset($_GET['action']) ? sanitize_text_field(wp_unslash($_GET['action'])) : '';
|
||||
|
||||
$is_core_upgrade_request =
|
||||
$action === 'do-core-upgrade' ||
|
||||
$page === 'update-core.php' ||
|
||||
(isset($_SERVER['PHP_SELF']) && str_contains(wp_unslash($_SERVER['PHP_SELF']), 'update-core.php'));
|
||||
|
||||
if (! $is_core_upgrade_request) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($action !== 'do-core-upgrade') {
|
||||
return;
|
||||
}
|
||||
|
||||
wp_die(
|
||||
esc_html__(
|
||||
'WordPress core updates are disabled in wp-admin. Please use the HostForge Dashboard to manage core updates.',
|
||||
'hostforge-systems'
|
||||
),
|
||||
esc_html__('Core Updates Disabled', 'hostforge-systems'),
|
||||
['response' => 403]
|
||||
);
|
||||
remove_submenu_page('index.php', 'update-core.php');
|
||||
remove_submenu_page('options-general.php', 'update-core.php');
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a HostForge notice on the Updates screen.
|
||||
* Render a HostForge notice on dashboard and update-related screens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function render_updates_screen_notice(): void
|
||||
public function render_dashboard_notice(): void
|
||||
{
|
||||
if (! $this->is_updates_screen()) {
|
||||
if (! is_admin()) {
|
||||
return;
|
||||
}
|
||||
|
||||
$screen = function_exists('get_current_screen') ? get_current_screen() : null;
|
||||
|
||||
if (! $screen || empty($screen->id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$allowed_screens = [
|
||||
'dashboard',
|
||||
'update-core',
|
||||
];
|
||||
|
||||
if (! in_array($screen->id, $allowed_screens, true)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Notice::render(
|
||||
'<strong>HostForge Notice:</strong> WordPress core updates are managed through the HostForge Dashboard and are disabled in wp-admin.',
|
||||
'<strong>HostForge Notice:</strong> WordPress core updates are managed through the HostForge Dashboard.',
|
||||
'info'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the current screen is the Updates screen.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function is_updates_screen(): bool
|
||||
{
|
||||
if (! is_admin() || ! function_exists('get_current_screen')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$screen = get_current_screen();
|
||||
|
||||
if (! $screen || empty($screen->id)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return $screen->id === 'update-core';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user