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.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fatal Error: Unable to determine if plugin or theme

aschweigert opened this issue · comments

Hi There -

I'm trying to use this library in a plugin to update a couple of other plugins. I have the library in a subfolder called "vendor" within my plugin and then this code in the main plugin file:

require_once( 'vendor/plugin-update-checker/plugin-update-checker.php' );
use YahnisElsts\PluginUpdateChecker\v5\PucFactory;

function ov_newspack_plugin_update() {
	$plugins_update = array(
		'newspack-plugin' => array(
			'github_url' => 'https://github.com/automattic/newspack-plugin',
			'plugin_file' => WP_PLUGIN_URL . '/newspack-plugin/newspack.php'
		),
		'newspack-popups'=> array(
			'github_url' => 'https://github.com/Automattic/newspack-popups',
			'plugin_file' => WP_PLUGIN_URL . '/newspack-popups/newspack-popups.php'
		)
	);
	foreach( $plugins_update as $key => $value ) {
		$myUpdateChecker = PucFactory::buildUpdateChecker(
			$value['github_url'],
			$value['plugin_file'],
			$key
		);
	}
}
add_action( 'plugins_loaded', 'ov_newspack_plugin_update' );

When I run this, I get a fatal error:

Fatal error: Uncaught RuntimeException: The update checker cannot determine if "https://openvallejo-stage.local/wp-content/plugins/newspack-plugin/" is a plugin or a theme. This is a bug. Please contact the PUC developer. in /Users/aschweigert/Local Sites/openvallejo-stage/app/public/wp-content/plugins/open-vallejo-newspack-mods/vendor/plugin-update-checker/Puc/v5p2/PucFactory.php:86 Stack trace: #0 /Users/aschweigert/Local Sites/openvallejo-stage/app/public/wp-content/plugins/open-vallejo-newspack-mods/open-vallejo-newspack-mods.php(45): YahnisElsts\PluginUpdateChecker\v5p2\PucFactory::buildUpdateChecker('https://github....', 'https://openval...', 'newspack-plugin') #1 /Users/aschweigert/Local Sites/openvallejo-stage/app/public/wp-includes/class-wp-hook.php(310): ov_newspack_plugin_update('') #2 /Users/aschweigert/Local Sites/openvallejo-stage/app/public/wp-includes/class-wp-hook.php(334): WP_Hook->apply_filters(NULL, Array) #3 /Users/aschweigert/Local Sites/openvallejo-stage/app/public/wp-includes/plugin.php(517): WP_Hook->do_action(Array) #4 /Users/aschweigert/Local Sites/openvallejo-stage/app/public/wp-settings.php(495): do_action('plugins_loaded') #5 /Users/aschweigert/Local Sites/openvallejo-stage/app/public/wp-config.php(103): require_once('/Users/aschweig...') #6 /Users/aschweigert/Local Sites/openvallejo-stage/app/public/wp-load.php(50): require_once('/Users/aschweig...') #7 /Users/aschweigert/Local Sites/openvallejo-stage/app/public/wp-admin/admin.php(34): require_once('/Users/aschweig...') #8 /Users/aschweigert/Local Sites/openvallejo-stage/app/public/wp-admin/plugins.php(10): require_once('/Users/aschweig...') #9 {main} thrown in /Users/aschweigert/Local Sites/openvallejo-stage/app/public/wp-content/plugins/open-vallejo-newspack-mods/vendor/plugin-update-checker/Puc/v5p2/PucFactory.php on line 86

From reading other tickets here I gathered that the second parameter passed to buildUpdateChecker() needs to be the full path to the main plugin file in these other plugins and the path looks correct in the error here so I'm wondering why it's failing...do you have any thoughts?

Thanks for your help!

I think the problem is that the second parameter needs to be a file path and you're passing in a URL. Try using the full path to the main plugin file instead.

Ah great, that worked beautifully. Thank you!

Sorry, one more question. I have this working now, but the plugins I'm trying to update use composer to generate the builds so the stable branch in github ("release") doesn't have the vendor folder included. When they tag releases the zip file for the tagged release is already built and has the vendor folder included. Is there a way to use your library to grab that zip file instead of using a branch?

PUC should already prioritize GitHub releases if you don't explicitly set a branch, and I don't see any setBranch() calls in that code. Are you sure it's using the "release" branch?

If the build that you want to use is added as a release asset, you'll need to call enableReleaseAssets() to make PUC choose that instead of the source code ZIP.

Hm, looking at the debug info, the download URL I see is: https://api.github.com/repos/Automattic/newspack-plugin/zipball/v2.9.0

and what I would want is this one: https://github.com/Automattic/newspack-plugin/releases/download/v2.9.0/newspack-plugin.zip

Which is basically the zip file in the tagged release (https://github.com/Automattic/newspack-plugin/releases/tag/v2.9.0).

is that what I need enableReleaseAssets() for?

Yes, that's what it's for.

Ah gotcha, ok. Sorry for all the questions, this has been super helpful!