YahnisElsts / plugin-update-checker

A custom update checker for WordPress plugins. Useful if you don't want to host your project in the official WP repository, but would still like it to support automatic updates. Despite the name, it also works with themes.
MIT License
2.27k stars 411 forks source link

"Can't to read the plugin header" errors #537

Closed MattOndo closed 1 year ago

MattOndo commented 1 year ago

Using "yahnis-elsts/plugin-update-checker": "^4.9" I am running into this issue where I get the following errors, the first two display four times each when debug is enabled:

Warning: Can't to read the plugin header for 'plugin-name'. The file does not exist. in /path/to/wp-content/plugins/plugin-name/vendor/yahnis-elsts/plugin-update-checker/Puc/v4p13/UpdateChecker.php on line 430

Warning: Can't to read the Version header for 'plugin-name'. The filename is incorrect or is not a plugin. in /path/to/wp-content/plugins/plugin-name/vendor/yahnis-elsts/plugin-update-checker/Puc/v4p13/UpdateChecker.php on line 430

Warning: Skipping update check for plugin-name - installed version unknown. in /path/to/wp-content/plugins/plugin-name/vendor/yahnis-elsts/plugin-update-checker/Puc/v4p13/UpdateChecker.php on line 430

The update checker code (my code below) lives in a subdirectory, specifically within /includes/class-plugin-name.php. I am using a defined constant PLUGIN_PATH to provide it with the correct path to the plugin directory (as per another thread I found here). The path it provides is correct, all the way to and including the plugin director: /path/to/wp-content/plugins/plugin-name/.

Note that the composer autoload is included elsewhere


if (! file_exists($composer = PLUGIN_PATH . 'vendor/autoload.php')) {
    wp_die(__('Error locating autoloader. Please contact the plugin\'s maintainer or <a href="mailto:email@domain.com">email@domain.com</a>', 'plugin-name'));
}

require $composer;

$ECUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
    'https://sub.domain.com/wp-update-server/?action=get_metadata&slug=plugin-name',
    PLUGIN_PATH,
    'plugin-name',
);

The logs show when the URL is hit it's missing some data, however, the "download" functionality still works. I see all others we have configured are pulling in version numbers, hostnames, and have a number of other parameters on the last cell. Logs below:

[2023-07-19 18:16:08 +0000] XX.XX.XX.XX     GET     get_metadata    plugin-name -   -   -   action=get_metadata&slug=plugin-name
[2023-07-19 18:25:42 +0000] XX.XX.XX.XX     GET     download    plugin-name -   -   -   action=download&slug=plugin-name

The header info in the main plugin file, plugin-name.php is as follows:

<?php
/**
 * @wordpress-plugin
 * Plugin Name:       Plugin Name
 * Plugin URI:        https://github.com/orgname/plugin-name/
 * Description:       My plugin description
 * Version:           1.0.0
 * Author:            Author Name
 * Author URI:        https://www.domain.com/
 * License:           GPL-2.0+
 * License URI:       http://www.gnu.org/licenses/gpl-2.0.txt
 * Text Domain:       plugin-name
 * Domain Path:       /languages
 */

Best I can tell, the header info is correct and the file definitely exists. Am I passing in the correct pathname to the 2nd parameter? If so, do I need to tweak anything else based on this being in a subdirectory? Help is much appreciated!

YahnisElsts commented 1 year ago

When you say "the path it provides is correct, all the way to and including the plugin directory", do you mean that it only includes the directory path? It should also include the plugin file name. In other words, it should be the fully qualified file name of the main plugin file.

MattOndo commented 1 year ago

@YahnisElsts ahah! I misunderstood the direction in another thread. The 2nd parameter I used was to the plugin directory, it did not include the main plugin file name. I updated to the following and the errors no longer persist. Thank you so much for the quick response!

✅ Solution:

if (! file_exists($composer = PLUGIN_PATH . 'vendor/autoload.php')) {
    wp_die(__('Error locating autoloader. Please contact the plugin\'s maintainer or <a href="mailto:email@domain.com">email@domain.com</a>', 'plugin-name'));
}

require $composer;

$UpdateChecker = Puc_v4_Factory::buildUpdateChecker(
    'https://wpupdates.evercommerce.com/wp-update-server/?action=get_metadata&slug=updox-calculators',
    PLUGIN_PATH . "plugin-name.php",
    'plugin-name',
);