-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from sarahcssiqueira/develop
Refactor encompassing duplicated code removed, updates Init class, doc updates
- Loading branch information
Showing
9 changed files
with
178 additions
and
219 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
{ | ||
"phpCodeSniffer.standard": "Automatic", | ||
"phpCodeSniffer.exec.osx":"./vendor/bin/phpcs" | ||
} | ||
"phpsab.fixerEnable":true, | ||
"phpsab.snifferEnable": true, | ||
} | ||
|
||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
/** | ||
* Init | ||
* | ||
* @package wxyzblocks | ||
*/ | ||
|
||
namespace WXYZBlocks\Inc; | ||
|
||
/** | ||
* Class to be used by all blocks | ||
*/ | ||
class Blocks { | ||
|
||
/** | ||
* Custom constructor for handle WordPress Hooks | ||
*/ | ||
public static function initialize() { | ||
$self = new self(); | ||
add_filter( 'block_categories_all', [ $self, 'register_new_category' ] ); | ||
} | ||
|
||
/** | ||
* Register new blocks category | ||
* | ||
* @param array $categories Existing block categories. | ||
* @return array Modified block categories | ||
*/ | ||
public function register_new_category( $categories ) { | ||
$categories[] = [ | ||
'slug' => 'wxyz-blocks', | ||
'title' => 'XYW...Z Blocks', | ||
]; | ||
|
||
return $categories; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
/** | ||
* Block Z | ||
* | ||
* @package wxyzblocks | ||
*/ | ||
|
||
namespace WXYZBlocks\Inc; | ||
|
||
/** | ||
* Block Y | ||
*/ | ||
class SingleBlock { | ||
|
||
/** | ||
* Custom constructor for handle WordPress Hooks | ||
*/ | ||
public static function initialize() { | ||
$self = new self(); | ||
add_action( 'init', [ $self, 'blocks_list' ] ); | ||
add_action( 'init', [ $self, 'blocks_register' ] ); | ||
add_action( 'init', [ $self, 'blocks_enqueues' ] ); | ||
add_action( 'init', [ $self, 'custom_block_register' ] ); | ||
add_action( 'enqueue_block_editor_assets', [ $self, 'custom_block_enqueues' ] ); | ||
} | ||
|
||
/** | ||
* Store the block names and paths at an array | ||
* | ||
* @return array Full list of block names and paths | ||
*/ | ||
public static function blocks_list() { | ||
return [ | ||
'block-w', | ||
'block-x', | ||
'block-y', | ||
'block-z', | ||
]; | ||
} | ||
|
||
/** | ||
* Register all blocks. | ||
* | ||
* Iterates over the list of block names returned by the blocks_list method | ||
* and registers each block using the custom_block_register method. | ||
*/ | ||
public function blocks_register() { | ||
foreach ( self::blocks_list() as $block ) { | ||
self::custom_block_register( $block ); | ||
} | ||
} | ||
|
||
/** | ||
* Enqueue all block assets. | ||
* | ||
* Iterates over the list of block names returned by the blocks_list method | ||
* and enqueues the scripts and styles for each block using the custom_block_enqueues method. | ||
*/ | ||
public function blocks_enqueues() { | ||
foreach ( self::blocks_list() as $block ) { | ||
self::custom_block_enqueues( $block ); | ||
} | ||
} | ||
|
||
/** | ||
* Register Block | ||
* | ||
* @param block $block block from the blocks_list method. | ||
*/ | ||
public function custom_block_register( $block ) { | ||
register_block_type( __DIR__ . "/../blocks/$block" ); | ||
} | ||
|
||
/** | ||
* Enqueues | ||
* | ||
* @param block $block block from the blocks_list method. | ||
*/ | ||
public function custom_block_enqueues( $block ) { | ||
wp_enqueue_script( | ||
'$block', | ||
plugin_dir_url( __FILE__ ) . '../blocks/' . $block . '/build/index.js', | ||
[ 'wp-blocks', 'wp-i18n', 'wp-editor' ] | ||
); | ||
|
||
wp_enqueue_style( | ||
'$block', | ||
plugin_dir_url( __FILE__ ) . '..style/style.css', | ||
[], | ||
); | ||
} | ||
} |
Oops, something went wrong.