plugin-update-checker icon indicating copy to clipboard operation
plugin-update-checker copied to clipboard

Unknown method in multisite

Open gijsomans opened this issue 5 years ago • 5 comments

Hey, Yahnis I have a problem.

We made a plugin for our company, we wanted the plugin to update automatically so we used your plugin checker. It works perfectly for all websites except for one multisite. for some reason the whole website stops working and I get the error call to undefined method setAuthentication

image

gijsomans avatar Jan 16 '20 09:01 gijsomans

The update checker class has a few subclasses and only those that are related to VCS (e.g. GitHub) have a setAuthentication method. My guess would be that you've somehow received an instance of the wrong class. Could you please show the code that initialises the update checker? Feel free to edit out any identifying details.

YahnisElsts avatar Jan 16 '20 18:01 YahnisElsts

require 'plugin-update-checker/plugin-update-checker.php';
$myUpdateChecker = Puc_v4_Factory::buildUpdateChecker(
    'https://gitlab.com/101media/101media/plugins/wordpress-101media-plugin',
    __FILE__,
    'wordpress-101media'
);

//Optional: If you're using a private repository, specify the access token like this:
$myUpdateChecker->setAuthentication('Gitlab token');

//Optional: Set the branch that contains the stable release.
$myUpdateChecker->setBranch('master');

This is the code that initialises the update checker.

The weird part is that I've tested the plugin on other multi-sites on the same server but they work fine

gijsomans avatar Jan 17 '20 13:01 gijsomans

That code looks fine to me. Here are a few ideas:

  • Make sure that all PUC files are present and valid (i.e. not zero bytes in size or otherwise corrupted). In particular, make sure that this file exists: /Puc/v4p8/Vcs/GitLabApi.php
  • Make sure that you're using the latest release (4.8.1).
  • Does the site run any other plugins or themes that also use PUC? In theory, calling Puc_v4_Factory::buildUpdateChecker() should automatically create an instance of the latest 4.x version, but some past releases had bugs that might interfere with this process. Make sure that you're actually getting a 4.8.x instance when you call that method. One way to do that is to install Debug Bar and look at the class names in the "PUC (slug)" panel.

Edit: Actually, I can see that it's a 4.8 instance based on the class name in the error message. Checking for other active PUC versions could still be useful.

YahnisElsts avatar Jan 17 '20 15:01 YahnisElsts

All the files seem to be fine.

The problem is that I can not test anything because when I use the plugin the whole website throws an error.

And the crazy thing is that Admin menu editor Pro works fine.

gijsomans avatar Jan 31 '20 10:01 gijsomans

Admin Menu Editor Pro uses the PUC JSON update format instead of the GitLab/GitHub API. Maybe that's why it isn't be affected by this particular error.

I would still recommend checking for other plugins and themes using PUC; there might be some kind of a conflict there. You can see active PUC instances in the Debug Bar. Try deactivating any other plugins that use this update checker and see if that makes a difference.

YahnisElsts avatar Jan 31 '20 12:01 YahnisElsts