rudrastyh / misha-update-checker

This simple plugin does nothing, only gets updates from a custom server
124 stars 44 forks source link

Two or more plugins using the self hosted functionality #11

Open lajennylove opened 1 year ago

lajennylove commented 1 year ago

Hello there!

First, I want to tank you because this plugin works amazingly good that I create a custom post type with custom fields to have an endpoint to use it as a plugin's repository. Everything worked well until I try to see the details of my second plugin.

When I click on "View version x.x details" this is what I get. Screenshot 2023-01-21 at 12 26 33 AM

The first plugin that I create works just fine. Screenshot 2023-01-21 at 12 28 54 AM

All the validations to show the updates works just fine. Screenshot 2023-01-21 at 12 30 18 AM

Do you have any ideas of how could I fix this?

baizmandesign commented 1 year ago

Hi, @lajennylove. I struggled with this as well. I combined Misha's tutorial with this thread on StackExchange, which explicitly says that information for multiple plugins can be added to the JSON output. The way Misha's code (and the code on StackExchange) is written, it's only expecting a single JSON object with a key of your_plugin_folder/your_plugin_filename.php. If, say, you added multiple items to an array in PHP and json_encode() it, a JSON array of objects would be produced. In other words, with one item your JSON looks like this...

{ "plugin_folder/plugin_filename.php" : ... }

...but with multiple items, your JSON looks like this...

[ { "plugin_folder/plugin_filename1.php" : ... },
  { "plugin_folder/plugin_filename2.php" : ... },
  { "plugin_folder/plugin_filename3.php" : ... } ]

It's an array of objects, not an object. So what can you do? Well, there are a few options:

On another note, it's no longer necessary to use the transients API. Two new filters handle that component natively and they support plugins and themes, respectively: update_plugins_{$hostname} (since 5.8) and update_themes_{$hostname} (since 6.1).

I hope this helps!