-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
converted main page elements to editor blocks (#13)
- Loading branch information
1 parent
ce9d306
commit 639b4ef
Showing
18 changed files
with
382 additions
and
28 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
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
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,23 @@ | ||
<?php | ||
namespace BipPages; | ||
defined( 'ABSPATH' ) || exit; | ||
|
||
function add_block_category( $categories, $post ) { | ||
if ( $post->post_type !== 'bip' ) { | ||
return $categories; | ||
} | ||
return array_merge( | ||
$categories, | ||
array( | ||
array( | ||
'slug' => 'bip', | ||
'title' => __( 'BIP Pages', 'bip-pages' ) | ||
), | ||
) | ||
); | ||
} | ||
add_filter( 'block_categories', __NAMESPACE__ . '\add_block_category', 10, 2 ); | ||
|
||
include( 'bip-org-info-block.php' ); | ||
include( 'bip-search-block.php' ); | ||
include( 'bip-recently-modified-block.php' ); |
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,8 @@ | ||
.bip-org-info-placeholder { | ||
display: inline-block; | ||
background-color: #ccc; | ||
width: 150px; | ||
margin-left: 0.5em; | ||
font-size: 60%; | ||
color: #ccc; | ||
} |
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,53 @@ | ||
( function( blocks, i18n, element ) { | ||
var el = element.createElement; | ||
var __ = i18n.__; | ||
|
||
blocks.registerBlockType( 'bip-pages/org-info', { | ||
title: __( 'BIP Org info', 'gutenberg-examples' ), | ||
icon: 'id-alt', | ||
category: 'bip', | ||
example: {}, | ||
supports: {multiple: false}, | ||
save: function() { return null; }, | ||
edit: function() { | ||
return el( | ||
'address', | ||
{ className: 'bip-address' }, | ||
[ | ||
el( 'p', {}, [ | ||
__( 'Address:', 'bip-pages' ), | ||
el( | ||
'span', | ||
{ className: 'bip-org-info-placeholder' }, | ||
' ' | ||
) | ||
]), | ||
el( 'p', {}, [ | ||
__( 'Editor:', 'bip-pages' ), | ||
el( | ||
'span', | ||
{ className: 'bip-org-info-placeholder' }, | ||
' ' | ||
) | ||
]), | ||
el( 'p', {}, [ | ||
__( 'E-mail address:', 'bip-pages' ), | ||
el( | ||
'span', | ||
{ className: 'bip-org-info-placeholder' }, | ||
' ' | ||
) | ||
]), | ||
el( 'p', {}, [ | ||
__( 'Phone number:', 'bip-pages' ), | ||
el( | ||
'span', | ||
{ className: 'bip-org-info-placeholder' }, | ||
' ' | ||
) | ||
]), | ||
] | ||
); | ||
} | ||
} ); | ||
} )( window.wp.blocks, window.wp.i18n, window.wp.element ); |
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,53 @@ | ||
<?php | ||
|
||
defined( 'ABSPATH' ) || exit; | ||
|
||
function org_info_register_block() { | ||
|
||
if ( ! function_exists( 'register_block_type' ) ) { | ||
// Gutenberg is not active. | ||
return; | ||
} | ||
|
||
wp_register_script( | ||
'bip-org-info-block', | ||
plugins_url( 'bip-org-info-block.js', __FILE__ ), | ||
array( 'wp-blocks', 'wp-i18n', 'wp-element' ), | ||
filemtime( plugin_dir_path( __FILE__ ) . 'bip-org-info-block.js' ) | ||
); | ||
|
||
wp_register_style( | ||
'bip-org-info-block-editor', | ||
plugins_url( 'bip-org-info-block-editor.css', __FILE__ ), | ||
array( 'wp-edit-blocks' ), | ||
filemtime( plugin_dir_path( __FILE__ ) . 'bip-org-info-block-editor.css' ) | ||
); | ||
|
||
register_block_type( 'bip-pages/org-info', array( | ||
'editor_script' => 'bip-org-info-block', | ||
'editor_style' => 'bip-org-info-block-editor', | ||
'render_callback' => 'gutenberg_examples_dynamic_render_callback' | ||
) ); | ||
|
||
if ( function_exists( 'wp_set_script_translations' ) ) { | ||
/** | ||
* May be extended to wp_set_script_translations( 'my-handle', 'my-domain', | ||
* plugin_dir_path( MY_PLUGIN ) . 'languages' ) ). For details see | ||
* https://make.wordpress.org/core/2018/11/09/new-javascript-i18n-support-in-wordpress/ | ||
*/ | ||
wp_set_script_translations( 'gutenberg-examples-01', 'gutenberg-examples' ); | ||
} | ||
|
||
} | ||
add_action( 'init', 'org_info_register_block' ); | ||
|
||
function gutenberg_examples_dynamic_render_callback( $block_attributes, $content ) { | ||
$options = get_option( BipPages\Settings\OPTION_NAME ); | ||
$bip_logo_url = plugin_dir_url( __FILE__ ) . '../assets/bip-logos/bip-full-color-pl_min.png'; | ||
|
||
ob_start(); | ||
include( __DIR__ . '/../templates/bip-org-info-template.php' ); | ||
$el = ob_get_clean(); | ||
|
||
return $el; | ||
} |
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,16 @@ | ||
( function( blocks, i18n, element ) { | ||
var el = element.createElement; | ||
var __ = i18n.__; | ||
|
||
blocks.registerBlockType( 'bip-pages/recently-modified', { | ||
title: __( 'BIP Recently Modified', 'bip-pages' ), | ||
icon: 'clock', | ||
category: 'bip', | ||
example: {}, | ||
supports: {multiple: false}, | ||
save: function() { return null; }, | ||
edit: function() { | ||
return el( 'p', {}, 'Recently Modified' ); | ||
} | ||
} ); | ||
} )( window.wp.blocks, window.wp.i18n, window.wp.element ); |
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,43 @@ | ||
<?php | ||
|
||
defined( 'ABSPATH' ) || exit; | ||
|
||
function recently_modified_register_block() { | ||
|
||
if ( ! function_exists( 'register_block_type' ) ) { | ||
// Gutenberg is not active. | ||
return; | ||
} | ||
|
||
wp_register_script( | ||
'bip-recently-modified-block', | ||
plugins_url( 'bip-recently-modified-block.js', __FILE__ ), | ||
array( 'wp-blocks', 'wp-i18n', 'wp-element' ), | ||
filemtime( plugin_dir_path( __FILE__ ) . 'bip-recently-modified-block.js' ) | ||
); | ||
|
||
register_block_type( 'bip-pages/recently-modified', array( | ||
'editor_script' => 'bip-recently-modified-block', | ||
// 'editor_style' => 'bip-org-info-block-editor', | ||
'render_callback' => 'recently_modified_dynamic_render_callback' | ||
) ); | ||
|
||
if ( function_exists( 'wp_set_script_translations' ) ) { | ||
/** | ||
* May be extended to wp_set_script_translations( 'my-handle', 'my-domain', | ||
* plugin_dir_path( MY_PLUGIN ) . 'languages' ) ). For details see | ||
* https://make.wordpress.org/core/2018/11/09/new-javascript-i18n-support-in-wordpress/ | ||
*/ | ||
wp_set_script_translations( 'gutenberg-examples-01', 'gutenberg-examples' ); | ||
} | ||
|
||
} | ||
add_action( 'init', 'recently_modified_register_block' ); | ||
|
||
function recently_modified_dynamic_render_callback( $block_attributes, $content ) { | ||
ob_start(); | ||
include( __DIR__ . '/../templates/bip-recently-modified-template.php' ); | ||
$el = ob_get_clean(); | ||
|
||
return $el; | ||
} |
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,13 @@ | ||
form.bip-search { | ||
margin: 1em 0; | ||
} | ||
|
||
form.bip-search label { | ||
width: 80%; | ||
float: left; | ||
margin-right: 0.5em; | ||
} | ||
|
||
form.bip-search input[type=search] { | ||
width: 100%; | ||
} |
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,24 @@ | ||
( function( blocks, i18n, element ) { | ||
var el = element.createElement; | ||
var __ = i18n.__; | ||
|
||
blocks.registerBlockType( 'bip-pages/search', { | ||
title: __( 'BIP Search', 'bip-pages' ), | ||
icon: 'search', | ||
category: 'bip', | ||
example: {}, | ||
save: function() { return null; }, | ||
edit: function() { | ||
return el( | ||
'form', | ||
{className: 'bip-search'}, | ||
[ | ||
el( 'label', {}, [ | ||
el( 'input', {type: 'search', placeholder: __('Search BIP pages…', 'placeholder', 'bip-pages'), disabled: 'disabled' } ), | ||
]), | ||
el( 'input', {type: 'submit', value: __( 'Search', 'submit button', 'bip-pages' ), disabled: 'disabled' } ) | ||
] | ||
); | ||
} | ||
} ); | ||
} )( window.wp.blocks, window.wp.i18n, window.wp.element ); |
Oops, something went wrong.