Skip to content
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

Feature/wdsus 7 implement wp cli #1006

Merged
Merged
Changes from 21 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
abb9a36
composer install wp-cli
Apr 28, 2023
97357b2
initial copy wp-cli command from acf-wds-blocks
Apr 28, 2023
e6f011d
adding some additional stubs used in the project
Apr 28, 2023
87bc681
scripts to build and watch blocks
Apr 28, 2023
63750db
including inc/wpcli/ folder
Apr 28, 2023
7e82049
we need this folder for the custom blocks
Apr 28, 2023
75d627d
instead of separated build, adding copy-php setting for blocks
Apr 28, 2023
8cbe194
fixing string replacement for namespace
Apr 28, 2023
56cda02
composer.lock
Apr 28, 2023
7979a6c
Merge branch 'main' into feature/WDSUS-7-Implement-WP-CLI
May 19, 2023
12c342a
Merge branch 'main' into feature/WDSUS-7-Implement-WP-CLI
May 26, 2023
a8f077b
adds schema | fixes supports.color and references to scripts and styles
May 26, 2023
bcce5f4
reverts adding -webpack-copy-php, not needed without tailwind
May 26, 2023
27a920a
early exit is class is already defined
May 26, 2023
9f1eeb1
renames prefix to wds (wd_s is not a valid block name)
May 26, 2023
a24a7b3
removes tailwind config
May 26, 2023
9049ec1
changes acf registration hook from `acf/init` to `init` | changed bloโ€ฆ
May 26, 2023
2e555af
exclude generated ACF JSON files
May 26, 2023
ffdeef9
simplified ACF block call-to-action
May 26, 2023
036e070
Merge branch 'main' into feature/WDSUS-7-Implement-WP-CLI
May 26, 2023
09ff681
Merge branch 'release/WDSUS-2-4.0-Theme-Revamp' into feature/WDSUS-7-โ€ฆ
khleomix Jun 1, 2023
f6a6c5d
removed CSS files | fixed JS file inclusion | set block category
Jun 2, 2023
9e6c878
test exlude acf json files
Jun 2, 2023
038f9ad
properly exclude generated ACF field groups (otherwise changes to fieโ€ฆ
Jun 2, 2023
936cac3
WDSUS-7 - Change CTA block category
khleomix Jun 6, 2023
0e6ad46
Merge branch 'feature/WDSUS-7-Implement-WP-CLI' of github.com:WebDevSโ€ฆ
khleomix Jun 6, 2023
b42f28c
porting changes from `wd_f`
Jun 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -7,7 +7,7 @@
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
"intelephense.format.enable": false,
"intelephense.stubs": [ "acf", "wordpress" ],
"intelephense.stubs": [ "acf", "wordpress", "standard", "Core", "pcre" ],

"workbench.colorCustomizations": {
"activityBar.background": "#3F4040",
149 changes: 149 additions & 0 deletions acf-json/group_6346c08d323e8.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{
"key": "group_6346c08d323e8",
"title": "Block: Call to Action",
"fields": [
{
"key": "field_635294c342393",
"label": "",
"name": "",
"aria-label": "",
"type": "message",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"message": "<h2>Call to Action Block</h2>",
"new_lines": "wpautop",
"esc_html": 0
},
{
"key": "field_6346c08d2eb6f",
"label": "Eyebrow",
"name": "eyebrow",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
},
{
"key": "field_6346c135fd3e5",
"label": "Heading",
"name": "heading",
"aria-label": "",
"type": "text",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"placeholder": "",
"prepend": "",
"append": ""
},
{
"key": "field_6346c16186509",
"label": "Content",
"name": "content",
"aria-label": "",
"type": "textarea",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"default_value": "",
"maxlength": "",
"rows": 3,
"placeholder": "",
"new_lines": "wpautop"
},
{
"key": "field_6346c13efd3e6",
"label": "Button",
"name": "button_args",
"aria-label": "",
"type": "clone",
"instructions": "",
"required": 0,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"clone": [ "group_59416d894b7c7" ],
"display": "seamless",
"layout": "block",
"prefix_label": 0,
"prefix_name": 0
},
{
"key": "field_6346ce226e894",
"label": "Layout",
"name": "layout",
"aria-label": "",
"type": "radio",
"instructions": "Left-aligned or Right-aligned content. The button will be on the opposite side of the content.\r\nCenter will stack and center-align the content.",
"required": 1,
"conditional_logic": 0,
"wrapper": {
"width": "",
"class": "",
"id": ""
},
"choices": {
"left": "Left",
"right": "Right",
"center": "Center"
},
"default_value": "left",
"return_format": "value",
"allow_null": 0,
"other_choice": 0,
"layout": "vertical",
"save_other_choice": 0
}
],
"location": [
[
{
"param": "block",
"operator": "==",
"value": "wds/call-to-action"
}
]
],
"menu_order": 0,
"position": "normal",
"style": "default",
"label_placement": "top",
"instruction_placement": "label",
"hide_on_screen": "",
"active": true,
"description": "",
"show_in_rest": 0,
"modified": 1685136357
}
Empty file added blocks/.gitkeep
Empty file.
33 changes: 33 additions & 0 deletions blocks/call-to-action/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "wds/call-to-action",
"title": "Call to Action",
"description": "This block is used for wds.",
"editorStyle": "file:./editor.css",
"editorScript": "./editor.js",
"style": "file:./style.css",
"script": "./script.js",
"category": "WDS",
"icon": "megaphone",
"keywords": [ "call-to-action", "call-to-action", "block" ],
"acf": {
"mode": "auto",
"renderTemplate": "call-to-action.php"
},
"supports": {
"align": false,
"anchor": true,
"color": {},
"customClassName": true,
"jsx": true
},
"example": {
"attributes": {
"mode": "preview",
"data": {
"_is_preview": "true"
}
}
}
}
29 changes: 29 additions & 0 deletions blocks/call-to-action/call-to-action.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* BLOCK - Renders a Call to Action block
*
* @link https://developer.wordpress.org/block-editor/
*
* @package wd_s
*/

$wds_block = $block ?? '';
$wds_args = $args ?? get_fields();

$wds_atts = [
'class' => [ 'wds-block', 'wds-block-call-to-action' ],
'allowed_innerblocks' => [ 'core/heading', 'core/paragraph' ],
'id' => ( isset( $wds_block ) && ! empty( $wds_block['anchor'] ) ) ? $wds_block['anchor'] : '',
'fields' => [ 'eyebrow', 'heading', 'content', 'button_args', 'layout' ],
];

?>
<section class="<?php echo esc_attr( implode( ' ', $wds_atts['class'] ) ); ?>">
<?php
if ( ! empty( $wds_atts['allowed_innerblocks'] ) ) :
echo '<InnerBlocks allowedBlocks="' . esc_attr( wp_json_encode( $wds_atts['allowed_innerblocks'] ) ) . '" />';
endif;

get_template_part( 'blocks/modules/call-to-action-' . get_field( 'layout' ), null, $wds_args );
?>
</section>
5 changes: 5 additions & 0 deletions blocks/call-to-action/editor.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php // phpcs:ignore Squiz.Commenting.FileComment.Missing
return array(
'dependencies' => array(),
'version' => 'dcc7a84d-24a4498fa6946bbc7acaf8df',
);
1 change: 1 addition & 0 deletions blocks/call-to-action/editor.css
guzmandrade-dev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* stylelint-disable-next-line no-empty-source */
3 changes: 3 additions & 0 deletions blocks/call-to-action/editor.js
guzmandrade-dev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './editor.css';

// Editor JS here.
1 change: 1 addition & 0 deletions blocks/call-to-action/index.js
guzmandrade-dev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import './style.css';
5 changes: 5 additions & 0 deletions blocks/call-to-action/script.asset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php // phpcs:ignore Squiz.Commenting.FileComment.Missing
return array(
'dependencies' => array(),
'version' => '17f883e691f5408985a1d4725664e7f5',
);
9 changes: 9 additions & 0 deletions blocks/call-to-action/script.js
guzmandrade-dev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Block script.
*
* @package
* @since 2.0.0
*/
import './style.css';

// add JS here.
51 changes: 51 additions & 0 deletions blocks/call-to-action/style.css
guzmandrade-dev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
.wds-block-call-to-action {
margin-left: auto;
margin-right: auto;
padding-left: 1rem;
padding-right: 1rem;
width: 100%
}

@media (min-width:100%) {
.wds-block-call-to-action {
max-width: 100%
}
}

@media (min-width:1200px) {
.wds-block-call-to-action {
max-width: 1200px
}
}

@media (min-width:600px) {
.wds-block-call-to-action .wds-module-call-to-action {
-moz-column-gap: 1rem;
column-gap: 1rem;
display: grid;
grid-template-columns: repeat(12, minmax(0, 1fr))
}
}

.wds-block-call-to-action .center-content {
grid-column: span 12/span 12;
text-align: center
}

@media (min-width:600px) {

.wds-block-call-to-action .left-content,
.wds-block-call-to-action .right-content {
grid-column: span 9/span 9
}
}

.wds-block-call-to-action .right-content {
grid-column-start: 1
}

@media (min-width:600px) {
.wds-block-call-to-action .right-content {
grid-column-start: 4
}
}
56 changes: 56 additions & 0 deletions blocks/modules/call-to-action-center.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* MODULE - Call to Action
*
* Modules are analagous to 'Molecules' in Brad Frost's Atomic Design Methodology.
*
* @link https://atomicdesign.bradfrost.com/chapter-2/#molecules
*
* @package abs
*/

$wds_defaults = [
'class' => [ 'wds-module', 'wds-module-call-to-action' ],
'eyebrow' => false,
'heading' => false,
'content' => false,
'button_args' => false,
];

$wds_args = wp_parse_args( $args, $wds_defaults );

// Set up element attributes.
$wds_atts = $wds_args['class'];

?>
<div class="<?php echo esc_attr( implode( ' ', $wds_atts ) ); ?>">
<div class="center-content">
<?php
// Eyebrow.
if ( $wds_args['eyebrow'] ) :
?>
<span class="wds-element wds-element-eyebrow"><?php echo wp_kses_post( $wds_args['eyebrow'] ); ?></span>
<?php
endif;

// Heading.
if ( $wds_args['heading'] ) :
?>
<h2 class="wds-element wds-element-heading"><?php echo wp_kses_post( $wds_args['heading'] ); ?></h2>
<?php
endif;

// Content.
if ( $wds_args['content'] ) :
?>
<section class="wds-element wds-element-content"><?php echo wp_kses_post( $wds_args['content'] ); ?></section>
<?php
endif;

// Button.
if ( ! empty( $wds_args['button_args']['button'] ) ) :
?>
<button class="wds-element wds-element-button"><?php echo wp_kses_post( $wds_args['button_args']['title'] ); ?></button>
<?php endif; ?>
</div>
</div>
56 changes: 56 additions & 0 deletions blocks/modules/call-to-action-left.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* MODULE - Call to Action
*
* Modules are analagous to 'Molecules' in Brad Frost's Atomic Design Methodology.
*
* @link https://atomicdesign.bradfrost.com/chapter-2/#molecules
*
* @package abs
*/

$wds_defaults = [
'class' => [ 'wds-module', 'wds-module-call-to-action' ],
'eyebrow' => false,
'heading' => false,
'content' => false,
'button_args' => false,
];

$wds_args = wp_parse_args( $args, $wds_defaults );

// Set up element attributes.
$wds_atts = $wds_args['class'];

?>
<div class="<?php echo esc_attr( implode( ' ', $wds_atts ) ); ?>">
<div class="left-content">
<?php
// Eyebrow.
if ( $wds_args['eyebrow'] ) :
?>
<span class="wds-element wds-element-eyebrow"><?php echo wp_kses_post( $wds_args['eyebrow'] ); ?></span>
<?php
endif;

// Heading.
if ( $wds_args['heading'] ) :
?>
<h2 class="wds-element wds-element-heading"><?php echo wp_kses_post( $wds_args['heading'] ); ?></h2>
<?php
endif;

// Content.
if ( $wds_args['content'] ) :
?>
<section class="wds-element wds-element-content"><?php echo wp_kses_post( $wds_args['content'] ); ?></section>
<?php
endif;

// Button.
if ( ! empty( $wds_args['button_args']['button'] ) ) :
?>
<button class="wds-element wds-element-button"><?php echo wp_kses_post( $wds_args['button_args']['title'] ); ?></button>
<?php endif; ?>
</div>
</div>
56 changes: 56 additions & 0 deletions blocks/modules/call-to-action-right.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php
/**
* MODULE - Call to Action
*
* Modules are analagous to 'Molecules' in Brad Frost's Atomic Design Methodology.
*
* @link https://atomicdesign.bradfrost.com/chapter-2/#molecules
*
* @package abs
*/

$wds_defaults = [
'class' => [ 'wds-module', 'wds-module-call-to-action' ],
'eyebrow' => false,
'heading' => false,
'content' => false,
'button_args' => false,
];

$wds_args = wp_parse_args( $args, $wds_defaults );

// Set up element attributes.
$wds_atts = $wds_args['class'];

?>
<div class="<?php echo esc_attr( implode( ' ', $wds_atts ) ); ?>">
<div class="right-content">
<?php
// Eyebrow.
if ( $wds_args['eyebrow'] ) :
?>
<span class="wds-element wds-element-eyebrow"><?php echo wp_kses_post( $wds_args['eyebrow'] ); ?></span>
<?php
endif;

// Heading.
if ( $wds_args['heading'] ) :
?>
<h2 class="wds-element wds-element-heading"><?php echo wp_kses_post( $wds_args['heading'] ); ?></h2>
<?php
endif;

// Content.
if ( $wds_args['content'] ) :
?>
<section class="wds-element wds-element-content"><?php echo wp_kses_post( $wds_args['content'] ); ?></section>
<?php
endif;

// Button.
if ( ! empty( $wds_args['button_args']['button'] ) ) :
?>
<button class="wds-element wds-element-button"><?php echo wp_kses_post( $wds_args['button_args']['title'] ); ?></button>
<?php endif; ?>
</div>
</div>
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@
"dealerdirect/phpcodesniffer-composer-installer": "^1.0.0",
"php-stubs/acf-pro-stubs": "6.0.6",
"phpcompatibility/phpcompatibility-wp": "^2.1.4",
"wp-cli/wp-cli-bundle": "^2.7.1",
"wp-cli/wp-cli-bundle": "^2.7",
"wp-coding-standards/wpcs": "^2.3.0"
},
"scripts": {
4 changes: 2 additions & 2 deletions composer.lock
1 change: 1 addition & 0 deletions functions.php
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ function include_inc_files() {
'inc/setup/', // Theme setup.
'inc/shortcodes/', // Load shortcodes.
'inc/template-tags/', // Custom template tags for this theme.
'inc/wpcli/',
];

foreach ( $files as $include ) {
33 changes: 33 additions & 0 deletions inc/wpcli/block-starter/block.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"$schema": "https://schemas.wp.org/trunk/block.json",
"apiVersion": 2,
"name": "wds/{{name}}",
"title": "{{title}}",
"description": "{{description}}",
"editorStyle": "file:./editor.css",
guzmandrade-dev marked this conversation as resolved.
Show resolved Hide resolved
"editorScript": "./editor.js",
"style": "file:./style.css",
guzmandrade-dev marked this conversation as resolved.
Show resolved Hide resolved
"script": "./script.js",
"category": "WDS",
"icon": "{{icon}}",
"keywords": [ "{{name}}", "{{keyword}}", "block" ],
"acf": {
"mode": "auto",
"renderTemplate": "{{name}}.php"
},
"supports": {
"align": false,
"anchor": true,
"color": {},
"customClassName": true,
"jsx": true
},
"example": {
"attributes": {
"mode": "preview",
"data": {
"_is_preview": "true"
}
}
}
}
6 changes: 6 additions & 0 deletions inc/wpcli/block-starter/block.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?php
/**
* Your block render code goes here.
*
* @package wd_s
*/
1 change: 1 addition & 0 deletions inc/wpcli/block-starter/editor.css
guzmandrade-dev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* stylelint-disable-next-line no-empty-source */
3 changes: 3 additions & 0 deletions inc/wpcli/block-starter/editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import './editor.css';
guzmandrade-dev marked this conversation as resolved.
Show resolved Hide resolved

// Editor JS here.
9 changes: 9 additions & 0 deletions inc/wpcli/block-starter/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Block script.
*
* @package
* @since 2.0.0
*/
import './style.css';
guzmandrade-dev marked this conversation as resolved.
Show resolved Hide resolved

// add JS here.
1 change: 1 addition & 0 deletions inc/wpcli/block-starter/style.css
guzmandrade-dev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* stylelint-disable-next-line no-empty-source */
279 changes: 279 additions & 0 deletions inc/wpcli/class-blocks-scaffold.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,279 @@
<?php
/**
* Add a CLI command for scaffolding a block.
*
* @package wd_s
*/

namespace WebDevStudios\wd_s;

// Exit if class already exists (for example when the plugin `WDS ACF Blocks` is active).
if ( class_exists( 'Blocks_Scaffold' ) ) {
return;
}

// Define a global path and url.
define( 'WebDevStudios\wd_s\ROOT_PATH', trailingslashit( get_template_directory() ) );
define( 'WebDevStudios\wd_s\ROOT_URL', trailingslashit( get_template_directory_uri() ) );

// Import wpcli.

use \WP_CLI as WP_CLI;

/**
* Class Blocks_Scaffold
*
* @package WebDevStudios\wd_s
*/
class Blocks_Scaffold {

/**
* Block Name
*
* @var string
*/
private $name = '';

/**
* Create a new block.
*
* @synopsis <blockname> [--title=<blocktitle>] [--desc=<blockdescription>] [--keyword=<blockkeyword>] [--icon=<blockicon>] [--namespace=<namespace>]
*
* ## OPTIONS
*
* <blockname>
* : The block name. Must only have alphabetical characters.
*
* [--desc=<blockdescription>]
* : The bloc description.
*
* [--keyword=<blockkeyword>]
* : They keyword for the block.
*
* [--icon=<blockicon>]
* : Block Icon.
*
* [--namespace=<blocknamespace>]
* : Block Namespace.
* : Default: WebDevStudios\wd_s
*
* ## EXAMPLES
*
* wp abs create_portable_block myblock --title="This is myblock" --desc="This block is used for wds." --keywords="myblock" --icon="table-row-before" --namespace="WebDevStudios\wd_s"
* @since 2.0.0
* @param string $name The block name.
* @param array $assoc_args The block args.
*/
public function create_portable_block( $name, $assoc_args ) {
$this->name = esc_html( $name[0] );

// validate name.
if ( ! preg_match( '/^[a-zA-Z0-9\-]+$/', $this->name ) ) {
WP_CLI::error( 'Invalid name, Block name must only contain upper and lowercase letters.', true );
}

// Merge with default args.
$args = wp_parse_args(
$assoc_args,
[
'title' => ucfirst( $this->name ),
'desc' => '',
'keywords' => strtolower( $this->name ),
'icon' => 'table-row-before',
'namespace' => 'wds',
]
);

// create the directory.
$this->create_block_dir();

// create block json.
$this->create_block_json( $args );

// create block renderer.
$this->create_block_render_php( $args );

// create editor assets.
$this->create_block_editor_assets();

// create FE assets.
$this->create_block_assets();

WP_CLI::success( $this->name . ' block created.' );
}

/**
* Init file system.
*
* @since 2.0.0
*/
private function init_filesystem() {
// File system support.
global $wp_filesystem;
require_once ABSPATH . '/wp-admin/includes/file.php';
WP_Filesystem();

return $wp_filesystem;
}

/**
* Create the block directory.
*
* @author Biplav Subedi <biplav.subedi@webdevstudios.com>
* @since 2.0.0
*/
private function create_block_dir() {
$dir = ROOT_PATH . 'blocks/' . $this->name;

if ( ! $this->init_filesystem()->exists( $dir ) ) {
$this->init_filesystem()->mkdir( $dir, 0755 );
} else {
WP_CLI::error( 'Block directory already exists.', true );
}
}

/**
* Create the block render file.
*
* @param array $args Block details.
* @since 2.0.0
* @author Biplav Subedi <biplav.subedi@webdevstudios.com>
*/
private function create_block_render_php( $args ) {
$local_file = ROOT_PATH . 'inc/wpcli/block-starter/block.php';
$content = '';

if ( $this->init_filesystem()->exists( $local_file ) ) {
$content = $this->init_filesystem()->get_contents( $local_file );
$content = str_replace( 'wds', $args['namespace'], $content );
if ( ! $this->init_filesystem()->put_contents( ROOT_PATH . 'blocks/' . $this->name . '/' . $this->name . '.php', $content ) ) {
WP_CLI::error( 'ERROR :: Could not create a render file.', true );
}
} else {
WP_CLI::error( 'ERROR :: Could not create a render file.', true );
}

}

/**
* Create the block json.
*
* @param array $args Block details.
* @since 2.0.0
* @author Biplav Subedi <biplav.subedi@webdevstudios.com>
*/
private function create_block_json( $args ) {
$local_file = ROOT_PATH . 'inc/wpcli/block-starter/block.json';
$content = '';

if ( $this->init_filesystem()->exists( $local_file ) ) {
$content = $this->init_filesystem()->get_contents( $local_file );
$content = str_replace(
[
'{{name}}',
'{{title}}',
'{{description}}',
'{{icon}}',
'wds/',
'{{keyword}}',
],
[
$this->name,
$args['title'],
$args['desc'],
$args['icon'],
trailingslashit( $args['namespace'] ),
$args['keyword'],
],
$content
);
}

if ( ! $this->init_filesystem()->put_contents( ROOT_PATH . 'blocks/' . $this->name . '/block.json', $content ) ) {
WP_CLI::error( 'ERROR :: Could not create a block json file.', true );
}
}

/**
* Create the block editor styles.
*
* @since 2.0.0
* @author Biplav Subedi <biplav.subedi@webdevstudios.com>
*/
private function create_block_editor_assets() {
$assets_js = ROOT_PATH . 'inc/wpcli/block-starter/editor.js';
$assets_css = ROOT_PATH . 'inc/wpcli/block-starter/editor.css';
guzmandrade-dev marked this conversation as resolved.
Show resolved Hide resolved

if ( ! $this->init_filesystem()->exists( $assets_js ) || ! $this->init_filesystem()->exists( $assets_css ) ) {
WP_CLI::error( 'ERROR :: Could not find editor assets.', true );
}

// copy editor js.
if ( ! $this->init_filesystem()->copy( $assets_js, ROOT_PATH . 'blocks/' . $this->name . '/editor.js' ) ) {
WP_CLI::error( 'ERROR :: Could not create editor js file.', true );
}

// copy editor css.
if ( ! $this->init_filesystem()->copy( $assets_css, ROOT_PATH . 'blocks/' . $this->name . '/editor.css' ) ) {
WP_CLI::error( 'ERROR :: Could not create editor js file.', true );
}

}

/**
* Create the block main styles.
*
* @since 2.0.0
* @author Biplav Subedi <biplav.subedi@webdevstudios.com>
*/
private function create_block_assets() {
$assets_js = ROOT_PATH . 'inc/wpcli/block-starter/script.js';
$assets_css = ROOT_PATH . 'inc/wpcli/block-starter/style.css';
guzmandrade-dev marked this conversation as resolved.
Show resolved Hide resolved

if (
! $this->init_filesystem()->exists( $assets_js )
|| ! $this->init_filesystem()->exists( $assets_css )
) {
WP_CLI::error( 'ERROR :: Could not find block assets.', true );
}

// copy editor js.
if ( ! $this->init_filesystem()->copy( $assets_js, ROOT_PATH . 'blocks/' . $this->name . '/script.js' ) ) {
WP_CLI::error( 'ERROR :: Could not create editor js file.', true );
}

// copy editor css.
if ( ! $this->init_filesystem()->copy( $assets_css, ROOT_PATH . 'blocks/' . $this->name . '/style.css' ) ) {
WP_CLI::error( 'ERROR :: Could not create editor js file.', true );
}
}

}

/**
* Registers our command when cli get's initialized.
*
* @since 4.0.0
* @author Biplav Subedi <biplav.subedi@webdevstudios.com>
* @return void
*/
function cli_register_commands() {
WP_CLI::add_command( 'abs', __NAMESPACE__ . '\Blocks_Scaffold' );
}
add_action( 'cli_init', __NAMESPACE__ . '\cli_register_commands' );

/**
* Register Blocks
*
* @return void
* @author Jenna Hines
* @since 2.0.0
*/
function wds_acf_register_blocks() {
$wds_acf_blocks = glob( ROOT_PATH . 'blocks/*/block.json' );

foreach ( $wds_acf_blocks as $block ) {
register_block_type( $block );
}
}
add_action( 'init', __NAMESPACE__ . '\wds_acf_register_blocks' );
1 change: 1 addition & 0 deletions lefthook.yml
Original file line number Diff line number Diff line change
@@ -25,4 +25,5 @@ pre-commit:
run: npx markdownlint-cli {staged_files} --fix
other:
glob: '*.{yml,json,html}'
exclude: 'acf-json/*.json'
run: npx prettier {staged_files} --write
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -49,7 +49,7 @@
Multiple valid prefixes can be provided as a comma-delimited list. -->
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<property name="prefixes" type="array" value="WebDevStudios\wd_s,wd_s" />
<property name="prefixes" type="array" value="WebDevStudios\wd_s,wd_s,wds" />
</properties>
</rule>