woocommerce/packages/php/blueprint
Moon c12b9da403
Blueprint - Disregard invalid slug and continue (#50607)
* 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>
2024-08-14 09:19:43 -07:00
..
src Blueprint - Disregard invalid slug and continue (#50607) 2024-08-14 09:19:43 -07:00
tests Blueprint - Disregard invalid slug and continue (#50607) 2024-08-14 09:19:43 -07:00
.wp-env.json blueprint - add php package and cli commands (#49763) 2024-08-12 16:33:05 -07:00
README.md blueprint - add php package and cli commands (#49763) 2024-08-12 16:33:05 -07:00
blueprint.php blueprint - add php package and cli commands (#49763) 2024-08-12 16:33:05 -07:00
composer.json blueprint - add php package and cli commands (#49763) 2024-08-12 16:33:05 -07:00
composer.lock blueprint - add php package and cli commands (#49763) 2024-08-12 16:33:05 -07:00
development.md blueprint - add php package and cli commands (#49763) 2024-08-12 16:33:05 -07:00
phpcs.xml blueprint - add php package and cli commands (#49763) 2024-08-12 16:33:05 -07:00
phpunit.xml.dist blueprint - add php package and cli commands (#49763) 2024-08-12 16:33:05 -07:00

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

  1. 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';
    }

}
  1. The export method should return a Step object.
  2. Let's use a built-in SetSiteOptions step for this example.
  3. 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();
    }
}

  1. 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"
            }
        }
    ]
}

Example: Adding a Custom Importer

Example: Adding a Custom Step

Example: Aliasing a Custom Exporter