You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
How to use files from plugin / blueprint repo in wp-cli blueprint step #99
I'm currently looking to implement a preview for one of our wp.org hosted plugins. In order to set up a meaningful demo we'd like to import some sample data using a wp-cli command. It looks like I can specify a wp-cli step, but I'm unsure what the execution context is of that command and what files it can access.
Ideally I'd be looking at providing this sort of structure in the SVN repo:
assets
blueprints
blueprint.json
sample-replacements.csv
I tried referencing the file directly without any path information, as the example below, but that doesn't appear to work.
I'm currently looking to implement a preview for one of our wp.org hosted plugins. In order to set up a meaningful demo we'd like to import some sample data using a wp-cli command. It looks like I can specify a wp-cli step, but I'm unsure what the execution context is of that command and what files it can access.
@leewillis77 - a prime example of how to use Playground!
Once you have the import working correctly, you'll want to include a blueprint on SVN so uses can use the "Preview Plugin" feature to demo the plugin
If one of the approaches above works, please let me know which. And if possible if I could include a link to importing demo content to this example use case from the docs, that would be excellent!
Thanks for the quick reply, but I don't think either of those examples really help.
Human Made's package is for running a WordPress import, which isn't the case here, the data is plugin-specific, so it's not done via a WordPress import. Even in the Simple User Listing plugin example while the data is not included in the blueprint.json file it looks like it's pulled from an external URL.
Interesting. I'm able to click and download the file, so it should be publicly accessible?
This may be a limitation of the WP-CLI package or how it's implemented in Playground.
Definitely a use case we are looking to get ironed out very soon, so I will be following here and also trying to work on an example myself. The only problem is I don't have anything on SVN, or really know how to use Subversion at all. :/
This may be a limitation of the WP-CLI package or how it's implemented in Playground.
Maybe, since essentially wp-cli is expecting a "local" file, not a URL, so I'm not clear on how I can either a) fetch the file from a remote and then have the wp-cli step access it somehow or b) have the wp-cli step use a remote file directly.
@leewillis77 My understanding on import was that it needs to be somewhere public with a CORS policy set. I couldn't tell you in the SVN repo has that or not, but in a github repo with the raw github url should be accessible via cli.
I'm working on the docs, if you're able to get a technique similar to this to work, or however you get this working, please link the blueprint you come up with!
@helgatheviking@flexseth Thanks both for the comments, but they're not really relevant to the issue at hand - probably I'm explaining things badly, apologies.
This is not an importFile step, so neither Ryan's example nor the issue with requiring cors headers on importFile fetches are relevant. It's a wp-cli step so I either need to understand if there's a way I can write a step to fetch a remote URL into the local filesystem somewhere that I can point a subsequent wp-cli step at, or in some way allow the wp-cli step to directly access the content from a URL not a local file.
changed the title [-]How to use files from plugin / blueprint repo in blueprint step[/-][+]How to use files from plugin / blueprint repo in wp-cli blueprint step[/+]on Apr 10, 2024
I know there have been a lot of changes made to how fetch works behind the scenes but had to turn off email notifications because there was soo many updates 👍
That looks like exactly what I was asking. It won't work as-is since plugins.svn.wordpress.org doesn't set the appropriate CORS headers to allow the fetch to work. Is that something we could get changed do you think?
I can confirm that it does work if you (for example) point it at a GitHub raw URL (thanks @helgatheviking!)
It won't work as-is since plugins.svn.wordpress.org doesn't set the appropriate CORS headers to allow the fetch to work. Is that something we could get changed do you think?
cc @tellyworth@dd32 – should plugins.svn.wordpress.org expose the CORS headers to allow using additional assets in Blueprints?
should plugins.svn.wordpress.org expose the CORS headers to allow using additional assets in Blueprints?
We probably don't want plugins.svn being accessed, but the CDN in front of it at ps.w.org can probably be used (We could add some code to playground to rewrite the fetches). But it doesn't currently support CORS and it requires cache-busters be included in the urls..
Alex requested systems input back in November, and there hasn't been an outcome on whether adding CORS is possible. Private systems request: https://make.wordpress.org/systems/?p=2330
Activity
flexseth commentedon Apr 10, 2024
@leewillis77 - a prime example of how to use Playground!
WordPress Importerpackage has now been integratedIf one of the approaches above works, please let me know which. And if possible if I could include a link to importing demo content to this example use case from the docs, that would be excellent!
leewillis77 commentedon Apr 10, 2024
Hi @flexseth;
Thanks for the quick reply, but I don't think either of those examples really help.
Human Made's package is for running a WordPress import, which isn't the case here, the data is plugin-specific, so it's not done via a WordPress import. Even in the Simple User Listing plugin example while the data is not included in the blueprint.json file it looks like it's pulled from an external URL.
What I'm asking in this issue is the ability to have a way for a step (in this case a wp-cli step) to access a file in the SVN repo. I can't currently see how to do that? See the 'wp-cli' step here https://plugins.svn.wordpress.org/say-what/assets/blueprints/blueprint.json
The wp-cli command needs to access a file to read the information from, but I can't work out how to point that at https://plugins.svn.wordpress.org/say-what/assets/blueprints/sample-replacements.csv
flexseth commentedon Apr 10, 2024
Interesting. I'm able to click and download the file, so it should be publicly accessible?
This may be a limitation of the
WP-CLIpackage or how it's implemented in Playground.Definitely a use case we are looking to get ironed out very soon, so I will be following here and also trying to work on an example myself. The only problem is I don't have anything on SVN, or really know how to use Subversion at all. :/
leewillis77 commentedon Apr 10, 2024
Maybe, since essentially wp-cli is expecting a "local" file, not a URL, so I'm not clear on how I can either a) fetch the file from a remote and then have the wp-cli step access it somehow or b) have the wp-cli step use a remote file directly.
helgatheviking commentedon Apr 10, 2024
@leewillis77 My understanding on import was that it needs to be somewhere public with a CORS policy set. I couldn't tell you in the SVN repo has that or not, but in a github repo with the raw github url should be accessible via cli.
flexseth commentedon Apr 10, 2024
@leewillis77 - try out the demo from @ryanwelcher's livestream
I'm working on the docs, if you're able to get a technique similar to this to work, or however you get this working, please link the blueprint you come up with!
CORS
Can totally be a "gotcha"
@helgatheviking may be correct with the Cross-Origin headers. You can try adding a PHP headers with a
RunPHPWithOptionsStepstep - providing the CORS headers?{ "steps": [ { "step": "runPHP", "options": { "code": "<?php echo $_SERVER['CONTENT_TYPE']; ?>", "headers": { "Content-type": "text/plain" } } } ] }leewillis77 commentedon Apr 10, 2024
@helgatheviking @flexseth Thanks both for the comments, but they're not really relevant to the issue at hand - probably I'm explaining things badly, apologies.
This is not an
importFilestep, so neither Ryan's example nor the issue with requiring cors headers on importFile fetches are relevant. It's awp-clistep so I either need to understand if there's a way I can write a step to fetch a remote URL into the local filesystem somewhere that I can point a subsequentwp-clistep at, or in some way allow thewp-clistep to directly access the content from a URL not a local file.[-]How to use files from plugin / blueprint repo in blueprint step[/-][+]How to use files from plugin / blueprint repo in wp-cli blueprint step[/+]flexseth commentedon Apr 10, 2024
How about with PHP?
What if you create a PHP snippet that will achieve what you need, and pass that through the
runPHPstep - similar to the following blueprintIn this example, Adam refactors a PHP snippet as a call to a
runPHPstepchanges to
fetchOtherwise, if you search the WordPress Playground repo for "fetch" - you may find more information on the changes they've been making relative to data handling.
I know there have been a lot of changes made to how
fetchworks behind the scenes but had to turn off email notifications because there was soo many updates 👍adamziel commentedon Apr 12, 2024
@leewillis77 here's what I would do:
{ "steps": [ { "step": "writeFile", "path": "/wordpress/sample-replacements.csv", "data": { "resource": "url", "url": "https://plugins.svn.wordpress.org/<YOUR PLUGIN>/assets/blueprints/sample-replacements.csv" } }, { "step": "wp-cli", "command": "wp say-what import /wordpress/sample-replacements.csv" } ] }Let me know if that's helpful.
leewillis77 commentedon Apr 12, 2024
Hey @adamziel;
That looks like exactly what I was asking. It won't work as-is since plugins.svn.wordpress.org doesn't set the appropriate CORS headers to allow the fetch to work. Is that something we could get changed do you think?
I can confirm that it does work if you (for example) point it at a GitHub raw URL (thanks @helgatheviking!)
adamziel commentedon Apr 12, 2024
cc @tellyworth @dd32 – should
plugins.svn.wordpress.orgexpose the CORS headers to allow using additional assets in Blueprints?leewillis77 commentedon Apr 12, 2024
The
blueprint.jsonat https://plugins.svn.wordpress.org/say-what/assets/blueprints/ is an example of how this would be used. Ideally the resource would fetch the file from https://plugins.svn.wordpress.org/say-what/assets/blueprints/sample-replacements.csv rather than GitHub.dd32 commentedon Apr 15, 2024
We probably don't want plugins.svn being accessed, but the CDN in front of it at
ps.w.orgcan probably be used (We could add some code to playground to rewrite the fetches). But it doesn't currently support CORS and it requires cache-busters be included in the urls..Alex requested systems input back in November, and there hasn't been an outcome on whether adding CORS is possible. Private systems request: https://make.wordpress.org/systems/?p=2330