-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Block API: Enable server bootstrapping all block properties
- Loading branch information
Showing
13 changed files
with
140 additions
and
64 deletions.
There are no files selected for viewing
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,39 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
/** | ||
* Generates server-registered blocks, writing to standard output. By default | ||
* assumes plugin exists in a standard install `wp-content/plugins` directory. | ||
* Define ABSPATH environment variable pointing to WordPress install otherwise. | ||
* | ||
* @package gutenberg-build | ||
*/ | ||
|
||
// Disable error reporting which would otherwise be displayed in stdout along | ||
// with the JSON output. | ||
error_reporting( 0 ); | ||
|
||
$abspath = getenv( 'ABSPATH' ); | ||
define( 'ABSPATH', $abspath ? $abspath : dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) ) . '/' ); | ||
define( 'WPINC', 'wp-includes' ); | ||
define( 'WP_SETUP_CONFIG', true ); | ||
define( 'WP_USE_THEMES', false ); | ||
require_once( ABSPATH . WPINC . '/load.php' ); | ||
require_once( ABSPATH . WPINC . '/default-constants.php' ); | ||
wp_fix_server_vars(); | ||
wp_initial_constants(); | ||
require_once( ABSPATH . WPINC . '/functions.php' ); | ||
wp_load_translations_early(); | ||
wp_set_lang_dir(); | ||
require_once( dirname( dirname( __FILE__ ) ) . '/lib/blocks.php' ); | ||
require_once( dirname( dirname( __FILE__ ) ) . '/lib/class-wp-block-type-registry.php' ); | ||
require_once( dirname( dirname( __FILE__ ) ) . '/lib/class-wp-block-type.php' ); | ||
require_once( dirname( dirname( __FILE__ ) ) . '/lib/client-assets.php' ); | ||
|
||
// Register server-side code for individual blocks. | ||
foreach ( glob( dirname( dirname( __FILE__ ) ) . '/blocks/library/*/index.php' ) as $block_logic ) { | ||
require_once $block_logic; | ||
} | ||
|
||
do_action( 'init' ); | ||
|
||
echo json_encode( gutenberg_prepare_blocks_for_js() ); |
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
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 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 @@ | ||
{"core\/block":{"attributes":{"ref":{"type":"number"}}},"core\/latest-posts":{"attributes":{"categories":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"layout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string","default":"center"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}}} |
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,48 @@ | ||
<?php | ||
/** | ||
* Block types registration Tests | ||
* | ||
* @package Gutenberg | ||
*/ | ||
|
||
/** | ||
* Test gutenberg_prepare_blocks_for_js() | ||
*/ | ||
class Prepare_For_JS_Test extends WP_UnitTestCase { | ||
|
||
function setUp() { | ||
parent::setUp(); | ||
|
||
$this->reset(); | ||
} | ||
|
||
function tearDown() { | ||
parent::tearDown(); | ||
|
||
$this->reset(); | ||
} | ||
|
||
function reset() { | ||
foreach ( WP_Block_Type_Registry::get_instance()->get_all_registered() as $name => $block_type ) { | ||
WP_Block_Type_Registry::get_instance()->unregister( $name ); | ||
} | ||
} | ||
|
||
function test_gutenberg_prepare_blocks_for_js() { | ||
$name = 'core/paragraph'; | ||
$settings = array( | ||
'icon' => 'text', | ||
'render_callback' => 'foo', | ||
); | ||
|
||
register_block_type( $name, $settings ); | ||
|
||
$blocks = gutenberg_prepare_blocks_for_js(); | ||
|
||
$this->assertEquals( array( | ||
'core/paragraph' => array( | ||
'icon' => 'text', | ||
), | ||
), $blocks ); | ||
} | ||
} |
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