-
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.
- Loading branch information
1 parent
85d33b2
commit 9d9abf5
Showing
10 changed files
with
141 additions
and
1 deletion.
There are no files selected for viewing
Empty file.
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,21 @@ | ||
{ | ||
"$schema": "https://schemas.wp.org/trunk/block.json", | ||
"apiVersion": 2, | ||
"title": "Block W", | ||
"name": "xywz-blocks/block-w", | ||
"description": "Block X", | ||
"version": "1.0.0-beta", | ||
"category": "xywz-blocks", | ||
"icon": "feedback", | ||
"supports": { | ||
"html": true | ||
}, | ||
"attributes": { | ||
"exampleAttribute": { | ||
"type": "string" | ||
} | ||
}, | ||
"keywords": ["basic", "model"], | ||
"editorScript": "file:./build/index.js", | ||
"editorStyle": "file:./src/style.css" | ||
} |
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 @@ | ||
<?php return array('dependencies' => array('react', 'wp-block-editor', 'wp-blocks', 'wp-element', 'wp-i18n'), 'version' => '0b7ff61aac7e64581ba9'); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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,26 @@ | ||
import React from "react"; | ||
import { __ } from "@wordpress/i18n"; | ||
import { useBlockProps } from "@wordpress/block-editor"; | ||
|
||
function Edit(props) { | ||
function setExampleAttribute(e) { | ||
props.setAttributes({ exampleAttribute: e.target.value }); | ||
} | ||
|
||
return ( | ||
<div {...useBlockProps()}> | ||
<div> | ||
<h4>Block W</h4> | ||
<p>Insert the attribute value below</p> | ||
<input | ||
type="text" | ||
value={props.attributes.exampleAttribute} | ||
onChange={setExampleAttribute} | ||
placeholder="Attribute value that will be displayed in the frontend" | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} | ||
|
||
export default Edit; |
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,10 @@ | ||
import { registerBlockType } from "@wordpress/blocks"; | ||
|
||
import Edit from "./edit"; | ||
import Save from "./save"; | ||
import metadata from "../block.json"; | ||
|
||
registerBlockType(metadata, { | ||
edit: Edit, | ||
save: Save, | ||
}); |
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,12 @@ | ||
import { __ } from "@wordpress/i18n"; | ||
import { useBlockProps } from "@wordpress/block-editor"; | ||
|
||
function Save(props) { | ||
return ( | ||
<p {...useBlockProps.save()}> | ||
{__(<div>{props.attributes.exampleAttribute}</div>)} | ||
</p> | ||
); | ||
} | ||
|
||
export default Save; |
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,60 @@ | ||
<?php | ||
/** | ||
* Block W | ||
* | ||
* @package xywzblocks | ||
*/ | ||
|
||
namespace XYWZBlocks\Inc; | ||
|
||
/** | ||
* Block W | ||
*/ | ||
class Block_W { | ||
|
||
|
||
/** | ||
* Constructor for handle WordPress Hooks | ||
*/ | ||
public function __construct() { | ||
add_action( 'init', [ $this, 'block_w_register' ] ); | ||
add_action( 'enqueue_block_editor_assets', [ $this, 'block_w_enqueues' ] ); | ||
add_filter( 'block_categories_all', [ $this, 'register_new_category' ], 10, 2 ); | ||
} | ||
|
||
/** | ||
* Register Block | ||
*/ | ||
public function block_w_register() { | ||
register_block_type( __DIR__ ); | ||
} | ||
|
||
/** | ||
* Enqueues | ||
*/ | ||
public function block_w_enqueues() { | ||
wp_enqueue_script( | ||
'block-w', | ||
plugin_dir_url( __FILE__ ) . '../blocks/block-w/build/index.js', | ||
[ 'wp-blocks', 'wp-i18n', 'wp-editor' ] | ||
); | ||
|
||
wp_enqueue_style( | ||
'block-w', | ||
plugin_dir_url( __FILE__ ) . '..style/style.css', | ||
[], | ||
); | ||
} | ||
|
||
/** | ||
* Register custom category | ||
*/ | ||
public function register_new_category( $categories ) { | ||
$categories[] = [ | ||
'slug' => 'xywz-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