-
Notifications
You must be signed in to change notification settings - Fork 41
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
Add WordPress Playground plugin #154
Conversation
Co-authored-by: Adam Zielinski <[email protected]>
'INSERT INTO %1$s (%2$s) VALUES (%3$s);', | ||
$wpdb->quote_identifier($table), | ||
escape_array( | ||
array_keys($record) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Column names are identifiers, but they're escaped as values here. Should $wpdb->quote_identifier
be used here, too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I used $wpdb->prepare
here, but $wpdb->quote_identifier
would be more appropriate here.
Done in 1eb00ee
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now when I think of it, we don't need column names or am I missing something?
This example works.
array_push(
$sql_dump,
sprintf(
'INSERT INTO %1$s VALUES (%2$s);',
$wpdb->quote_identifier($table),
escape_array(array_values($record))
)
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed column names in dd36deb.
return ''; | ||
} | ||
// A query needs to be on a single line | ||
return preg_replace("/\r?\n/", "", $schema['Create Table']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
extractToPath: '/wordpress', | ||
}, | ||
{ | ||
step: 'runSql', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lovely! I'd like Playground to do that automatically eventually, but today of course let's stick to an explicit step.
packages/playground/playground.php
Outdated
return $action_links; | ||
} | ||
|
||
$blueprint = $plugin['blueprints'][0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oooh this is quite tricky!
We can display the Preview button on every plugin, whether it has a Blueprint or not. When you install a plugin, you don't get any initial setup other than what the plugin does on activation. It makes sense to reproduce that experience here.
Then, what should we do when the plugin ships a Blueprint? My gut says ignore the Blueprint.
Why?
These Blueprints are written with a vanilla WordPress site in mind. They'll typically create dummy content, change site options, and so on to reach a minimal preview environment. In some cases, like bbpress, that makes a lot of sense even in the context of your site as it doesn't have any forums in place. In other cases, that would only add confusing bloat like lorem ipsum pages when your site already has pages.
Then, applying a Blueprint means the preview experience will be very different from the Installing experience. At best, you won't get the setup wizard. At worst, you'll think "what the... is this plugin going to create 50 dummy posts when I install it? I better go for another one".
So I suggest let's ignore these Blueprints and open a new issue to discuss that with @tellywort, @StevenDufresne, and also some plugin authors.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed the need for blueprints in 3bdd04a
The plugin worked beautifully with a real WordPress using a local |
This fixed the whitespace but not the import: function escape_array($array)
{
global $wpdb;
$escaped = array();
foreach ($array as $value) {
if (is_numeric($value)) {
$escaped[] = $wpdb->prepare('%d', $value);
} else {
- $escaped[] = $wpdb->prepare('%s', $value);
+ $escaped[] = $wpdb->prepare('%s', str_replace("\n", "\\n", $value));
}
}
return implode(',', $escaped);
} |
@adamziel let's address the wp-now issue in a separate PR. |
Yup, it's not a blocker at all here, I was just exploring. I isolated the problem and started a new issue here: WordPress/sqlite-database-integration#74 |
This is looking really good. Thank you @bgrgicak! |
What?
This adds the
playground
plugin for plugin-preview functionality and renames the plugin to WordPress Playground.Requires:
WordPress/wordpress-playground#745 .
WordPress/blueprints#49
Why?
Users want to be able to preview plugins on their own sites before actually committing to installing them live.
Testing Instructions
Testing Previews
plugins
>add new
Preview Now
button next to theInstall Now
button.Preview now
, and you should see Playground boot your site with the plugin activated.