Repository navigation
Add WordPress Playground plugin - #154
Conversation
Co-authored-by: Adam Zielinski <adam@adamziel.com>
| '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.
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.
I used $wpdb->prepare here, but $wpdb->quote_identifier would be more appropriate here.
Done in 1eb00ee
There was a problem hiding this comment.
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))
)
);
| return ''; | ||
| } | ||
| // A query needs to be on a single line | ||
| return preg_replace("/\r?\n/", "", $schema['Create Table']); |
| extractToPath: '/wordpress', | ||
| }, | ||
| { | ||
| step: 'runSql', |
There was a problem hiding this comment.
Lovely! I'd like Playground to do that automatically eventually, but today of course let's stick to an explicit step.
| return $action_links; | ||
| } | ||
|
|
||
| $blueprint = $plugin['blueprints'][0]; |
There was a problem hiding this comment.
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.
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
playgroundplugin 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 newPreview Nowbutton next to theInstall Nowbutton.Preview now, and you should see Playground boot your site with the plugin activated.