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

Is it possible to run php after setup is complete? #641

Closed
janw-me opened this issue Sep 17, 2023 · 7 comments · Fixed by #649
Closed

Is it possible to run php after setup is complete? #641

janw-me opened this issue Sep 17, 2023 · 7 comments · Fixed by #649

Comments

@janw-me
Copy link
Contributor

janw-me commented Sep 17, 2023

I`ve got a blueprint working. It imports an xml, but I want to delete the extra user the import created.

So I got the following step at the end of my steps:

{
    "step": "importFile",
    "file": {
        "resource": "url",
        "url": "https://localurl.test/content.xml"
    }
},
{
    "step": "'runPHP'",
    "code": "<?php wp_delete_user(2,1); wp_insert_post(array('post_title'    => 'My post',))"
}

Nether php statement seems to trigger.
I suspect this snippet runs before WP is installed.
My blueprint is based on this example.
And here the echo hi appears to run early during the initialization.

How can we run php after everything else is done.

@dmsnell
Copy link
Collaborator

dmsnell commented Sep 18, 2023

@janw-me this could be a typo when pasting or writing into the GitHub box, but the step should be runPHP and not 'runPHP' as in your example. Let's ensure the extra ' simgle quotes aren't in there and see if that clears this up for you.

@janw-me
Copy link
Contributor Author

janw-me commented Sep 18, 2023

@dmsnell The single quotes are a copy paste error. I had them but playground won't even run with a unknown keyword.
So yes at one point I had this typo, but when I created this ticket I tested it with the correct keyword.

@dmsnell
Copy link
Collaborator

dmsnell commented Sep 18, 2023

@janw-me I suspected it was that but wanted to confirm. can we rule out other problems? how about some lines that echo the users or posts to confirm that this is running before the import?

it's my understanding that what you are doing is the right way to accomplish what you're asking.

@janw-me
Copy link
Contributor Author

janw-me commented Sep 20, 2023

I don't thing echos/var_dump trigger during that step.
See my full code snippet below.
Only the console.log output is visible. I don't know where to check the output fot the runPHP step.

<iframe id="wp-playground-blueprint-api" style="width: 100% !important; height: 800px; max-width: 100%;"></iframe>
<script type="module">
	import { startPlaygroundWeb } from 'https://unpkg.com/@wp-playground/client/index.js';

	const client = await startPlaygroundWeb({
		iframe: document.getElementById('wp-playground-blueprint-api'),
		remoteUrl: `https://playground.wordpress.net/remote.html`,
		blueprint: {
			landingPage: '/wp-admin/plugins.php',
			preferredVersions: {
				php: '8.0',
				wp: 'latest',
			},
			steps: [
				{
					step: 'login',
					username: 'admin',
					password: 'password',
				},
				{
					"step": "runPHP",
					"code": "<?php var_dump( 'blueprint' );"
				}
			],
		},
	});

	const response = await client.run({
		code: '<?php var_dump("js code"); var_dump(function_exists("get_posts")); ',
	});
	console.log(response.text);
</script>

Also the WP function get_posts does not appear to exist, so WP isn't loaded (yet?) during the client.run code.

@adamziel
Copy link
Collaborator

adamziel commented Sep 28, 2023

@janw-me try adding require_once "/wordpress/wp-load.php"; before calling WordPress functions. The documentation page could definitely be clearer about that.

@janw-me
Copy link
Contributor Author

janw-me commented Sep 29, 2023

@adamziel thanks.
I'll try that next week. And update the documentation.
Double checking , does this trigger after the install? So I could add posts and stuff?

@adamziel
Copy link
Collaborator

adamziel commented Sep 29, 2023

Thank you @janw-me!

Double checking , does this trigger after the install? So I could add posts and stuff?

Yes, yes it does 👍

janw-me added a commit to janw-me/wordpress-playground that referenced this issue Oct 1, 2023
janw-me added a commit to janw-me/wordpress-playground that referenced this issue Oct 6, 2023
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

Successfully merging a pull request may close this issue.

3 participants