c12b9da403
* Disregard invalid slug * Change logic for invalid slug -- plugin dir with the slug must exist * Use put_contents correctly --------- Co-authored-by: Ilyas Foo <foo.ilyas@gmail.com> |
||
---|---|---|
.. | ||
src | ||
tests | ||
.wp-env.json | ||
README.md | ||
blueprint.php | ||
composer.json | ||
composer.lock | ||
development.md | ||
phpcs.xml | ||
phpunit.xml.dist |
README.md
Blueprint
This PHP Composer package facilitates exporting and importing WordPress Blueprint compatible JSON formats. It offers a solid framework for seamless integration with WordPress sites and supports extensibility, enabling plugins to customize export and import functionalities. Manage site configurations, options, and settings effortlessly with JSON files.
Built-in Steps
Step |
---|
installPlugin |
activatePlugin |
deactivatePlugin |
deletePlugin |
installTheme |
activateTheme |
setSiteOptions |
Hooks
Hook | Description |
---|---|
wooblueprint_exporters |
A hook to add custom exporters. |
wooblueprint_importers |
A hook to add custom importers. |
Example: Adding a Custom Exporter
- Create a new class that extends
Automattic\WooCommerce\Blueprint\Exporters\StepExporter
.
<?php
use Automattic\WooCommerce\Blueprint\Exporters\StepExporter;
use Automattic\WooCommerce\Blueprint\Steps\Step;
class MyCustomExporter extends StepExporter {
public function export( array $data ): Step {
}
public function get_step_name() {
return 'setSiteOptions';
}
}
- The
export
method should return aStep
object. - Let's use a built-in
SetSiteOptions
step for this example. - Create a new instance of
SetSiteOptions
and return it.
use Automattic\WooCommerce\Blueprint\Exporters\StepExporter;
use Automattic\WooCommerce\Blueprint\Steps\Step;
class MyCustomExporter extends StepExporter {
public function export(): Step {
$data = [
'option1' => get_option( 'option1', 'value1' ),
'option2' => get_option( 'option2', 'value2' ),
];
return new SetSiteOptions( $data );
}
public function get_step_name() {
return SetSiteOptions::get_step_name();
}
}
- Lastly, register the exporter with the Blueprint package via
wooblueprint_exporters
filter.
use Automattic\WooCommerce\Blueprint\Exporters\StepExporter;
use Automattic\WooCommerce\Blueprint\Steps\Step;
class MyCustomExporter extends StepExporter {
public function export(): Step {
$data = [
'option1' => get_option( 'option1', 'value1' ),
'option2' => get_option( 'option2', 'value2' ),
];
return new SetSiteOptions( $data );
}
public function get_step_name() {
return SetSiteOptions::get_step_name();
}
}
add_filter( 'wooblueprint_exporters', function( array $exporters ) {
$exporters[] = new MyCustomExporter();
return $exporters;
} );
When exporting a Blueprint, the MyCustomExporter
class will be called and the SetSiteOptions
step will be added to the Blueprint JSON.
Output:
{
"steps": [
{
"name": "setSiteOptions",
"options": {
"option1": "value1",
"option2": "value2"
}
}
]
}