mirror of
https://github.com/djav1985/v-wordpress-plugin-updater.git
synced 2025-10-04 16:31:05 +08:00
Merge pull request #38 from djav1985/codex/fix-codebase-errors-and-optimize
Fix plugin/theme updater and API scanning
This commit is contained in:
commit
745b8145ad
5 changed files with 15 additions and 3 deletions
|
@ -55,7 +55,10 @@ function vontmnt_plugin_updater_run_updates(): void
|
|||
if (! is_main_site()) {
|
||||
return;
|
||||
}
|
||||
$plugins = get_plugins();
|
||||
if (! function_exists('get_plugins')) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
$plugins = get_plugins();
|
||||
foreach ($plugins as $plugin_path => $plugin) {
|
||||
$plugin_slug = dirname($plugin_path);
|
||||
$installed_version = $plugin['Version'];
|
||||
|
|
|
@ -46,6 +46,9 @@ add_action('vontmnt_plugin_updater_check_updates', 'vontmnt_plugin_updater_run_u
|
|||
* Run plugin updates for all installed plugins. */
|
||||
function vontmnt_plugin_updater_run_updates(): void
|
||||
{
|
||||
if (! function_exists('get_plugins')) {
|
||||
require_once ABSPATH . 'wp-admin/includes/plugin.php';
|
||||
}
|
||||
$plugins = get_plugins();
|
||||
foreach ($plugins as $plugin_path => $plugin) {
|
||||
$plugin_slug = dirname($plugin_path);
|
||||
|
|
|
@ -47,6 +47,9 @@ add_action('vontmnt_theme_updater_check_updates', 'vontmnt_theme_updater_run_upd
|
|||
* Run theme updates for all installed themes. */
|
||||
function vontmnt_theme_updater_run_updates(): void
|
||||
{
|
||||
if (! function_exists('wp_get_themes')) {
|
||||
require_once ABSPATH . 'wp-includes/theme.php';
|
||||
}
|
||||
$themes = wp_get_themes();
|
||||
foreach ($themes as $theme) {
|
||||
$theme_slug = $theme->get_stylesheet();
|
||||
|
|
|
@ -202,7 +202,7 @@ class HomeController // @phpcs:disable PSR1.Classes.ClassDeclaration.MissingName
|
|||
public static function getHostsTableHtml(): string
|
||||
{
|
||||
$hostsFile = HOSTS_ACL . '/HOSTS';
|
||||
$entries = file($hostsFile, FILE_IGNORE_NEW_LINES);
|
||||
$entries = file_exists($hostsFile) ? file($hostsFile, FILE_IGNORE_NEW_LINES) : [];
|
||||
$hostsTableHtml = '';
|
||||
if (count($entries) > 0) {
|
||||
$halfCount = ceil(count($entries) / 2);
|
||||
|
|
|
@ -84,11 +84,14 @@ if (UtilityHandler::isBlacklisted($ip) || $_SERVER['REQUEST_METHOD'] !== 'GET')
|
|||
fclose($host_file);
|
||||
// Find and serve update if available
|
||||
foreach (scandir($dir) as $filename) {
|
||||
if ($filename === '.' || $filename === '..') {
|
||||
continue;
|
||||
}
|
||||
if (strpos($filename, $slug) === 0) {
|
||||
$filename_parts = explode('_', $filename);
|
||||
if (isset($filename_parts[1]) && version_compare($filename_parts[1], $version, '>')) {
|
||||
$file_path = $dir . '/' . $filename;
|
||||
if (file_exists($file_path)) {
|
||||
if (is_file($file_path)) {
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="' . basename($file_path) . '"');
|
||||
header('Content-Length: ' . filesize($file_path));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue