Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Two or more plugins using the self hosted functionality #11

Open
lajennylove opened this issue Jan 21, 2023 · 1 comment
Open

Two or more plugins using the self hosted functionality #11

lajennylove opened this issue Jan 21, 2023 · 1 comment

Comments

@lajennylove
Copy link

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
Copy link

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:

  • Have a single JSON file (or PHP-powered file generating JSON) for each plugin.
  • If your JSON is being dynamically generated by PHP, pass a query string to the UpdateURI to ask it to only return output for a single asset.
  • Adjust the code that parses the JSON to loop over this array and identify and retrieve the correct asset's details.

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants