PHP code example of wp-php-toolkit / blueprints

1. Go to this page and download the library: Download wp-php-toolkit/blueprints library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wp-php-toolkit / blueprints example snippets



WordPress\Blueprints\Runner;
use WordPress\Blueprints\RunnerConfiguration;

$config = ( new RunnerConfiguration() )
	->set_execution_mode( Runner::EXECUTION_MODE_APPLY_TO_EXISTING_SITE )
	->set_target_site_root( '/wordpress' )
	->set_target_site_url( 'http://playground.test/' );

echo "mode: " . $config->get_execution_mode() . "\n";
echo "root: " . $config->get_target_site_root() . "\n";
echo "url:  " . $config->get_target_site_url() . "\n";


e_name = 'Demo Site';
$plugins   = array( 'gutenberg', 'classic-editor' );

$blueprint = array(
	'version' => 2,
	'steps'   => array(
		array(
			'step'    => 'setSiteOptions',
			'options' => array(
				'blogname'              => $site_name,
				'permalink_structure'   => '/%postname%/',
				'show_on_front'         => 'page',
			),
		),
	),
);

foreach ( $plugins as $slug ) {
	$blueprint['steps'][] = array(
		'step'       => 'installPlugin',
		'pluginData' => "https://downloads.wordpress.org/plugin/{$slug}.zip",
	);
	$blueprint['steps'][] = array(
		'step'   => 'activatePlugin',
		'plugin' => "{$slug}/{$slug}.php",
	);
}

echo json_encode( $blueprint, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES ) . "\n";


WordPress\Blueprints\Validator\HumanFriendlySchemaValidator;

$schema = array(
	'type'       => 'object',
	'
			'items' => array(
				'type'       => 'object',
				'nData' => 'https://downloads.wordpress.org/plugin/gutenberg.zip' ),
	),
);

$error = ( new HumanFriendlySchemaValidator( $schema ) )->validate( $blueprint );
if ( null === $error ) {
	echo "valid\n";
} else {
	echo $error->get_pretty_path() . ": " . $error->message . "\n";
}