diff --git a/index.php b/index.php
index 03c4de6f16f94..6d7adaf579de2 100644
--- a/index.php
+++ b/index.php
@@ -33,10 +33,10 @@ function gutenberg_menu() {
/**
* Registers a block.
*
- * @param string $slug Block slug including namespace.
- * @param array $settings Block settings
+ * @param string $slug Block slug including namespace.
+ * @param array $settings Block settings.
- * @return array The block, if it has been successfully registered.
+ * @return array The block, if it has been successfully registered.
*/
function register_block( $slug, $settings ) {
global $registered_blocks;
@@ -58,7 +58,7 @@ function register_block( $slug, $settings ) {
return;
}
- $settings[ 'slug' ] = $slug;
+ $settings['slug'] = $slug;
$registered_blocks[ $slug ] = $settings;
return $settings;
@@ -67,13 +67,14 @@ function register_block( $slug, $settings ) {
/**
* Unregisters a block.
*
- * @param string slug Block slug
- * @return array The previous block value, if it has been
- * successfully unregistered; otherwise `null`.
+ * @param string $slug Block slug.
+ * @return array The previous block value, if it has been
+ * successfully unregistered; otherwise `null`.
*/
function unregister_block( $slug ) {
global $registered_blocks;
if ( ! isset( $registered_blocks[ $slug ] ) ) {
+ /* translators: 1: block slug */
$message = sprintf( __( 'Block "%s" is not registered.' ), $slug );
_doing_it_wrong( __FUNCTION__, $message, '0.1.0' );
return;
@@ -86,7 +87,7 @@ function unregister_block( $slug ) {
*
* @since 0.1.0
*
- * @param string $attr_string Attributes string
+ * @param string $attr_string Attributes string.
* @return array
*/
@@ -94,8 +95,8 @@ function parse_block_attributes( $attr_string ) {
$attributes_matcher = '/([^\s]+):([^\s]+)\s*/';
preg_match_all( $attributes_matcher, $attr_string, $matches );
$attributes = array();
- foreach ( $matches[ 1 ] as $index => $attribute_match ) {
- $attributes[ $attribute_match ] = $matches[ 2 ][ $index ];
+ foreach ( $matches[1] as $index => $attribute_match ) {
+ $attributes[ $attribute_match ] = $matches[2][ $index ];
}
return $attributes;
@@ -106,40 +107,40 @@ function parse_block_attributes( $attr_string ) {
*
* @since 0.1.0
*
- * @param string $content Post content
-
- * @return string Updated post content
+ * @param string $content Post content.
+ *
+ * @return string Updated post content.
*/
function do_blocks( $content ) {
global $registered_blocks;
- // Extract the blocks from the post content
+ // Extract the blocks from the post content.
$open_matcher = '/).)*)-->.*?/';
preg_match_all( $open_matcher, $content, $matches, PREG_OFFSET_CAPTURE );
$new_content = $content;
- foreach ( $matches[ 0 ] as $index => $block_match ) {
- $block_name = $matches[ 1 ][ $index ][ 0 ];
- // do nothing if the block is not registered
+ foreach ( $matches[0] as $index => $block_match ) {
+ $block_name = $matches[1][ $index ][0];
+ // do nothing if the block is not registered.
if ( ! isset( $registered_blocks[ $block_name ] ) ) {
continue;
}
- $block_markup = $block_match[ 0 ];
- $block_position = $block_match[ 1 ];
- $block_attributes_string = $matches[ 2 ][ $index ][ 0 ];
+ $block_markup = $block_match[0];
+ $block_position = $block_match[1];
+ $block_attributes_string = $matches[2][ $index ][0];
$block_attributes = parse_block_attributes( $block_attributes_string );
- // Call the block's render function to generate the dynamic output
- $output = call_user_func( $registered_blocks[ $block_name ][ 'render' ], $block_attributes );
+ // Call the block's render function to generate the dynamic output.
+ $output = call_user_func( $registered_blocks[ $block_name ]['render'], $block_attributes );
- // Replace the matched block with the dynamic output
+ // Replace the matched block with the dynamic output.
$new_content = str_replace( $block_markup, $output, $new_content );
}
return $new_content;
}
-add_filter( 'the_content', 'do_blocks', 10 ); // BEFORE do_shortcode()
+add_filter( 'the_content', 'do_blocks', 10 ); // BEFORE do_shortcode().
/**
* Registers common scripts to be used as dependencies of the editor and plugins.
@@ -173,9 +174,9 @@ function gutenberg_register_scripts() {
* @since 0.1.0
*/
function gutenberg_add_edit_links_filters() {
- // For hierarchical post types
+ // For hierarchical post types.
add_filter( 'page_row_actions', 'gutenberg_add_edit_links', 10, 2 );
- // For non-hierarchical post types
+ // For non-hierarchical post types.
add_filter( 'post_row_actions', 'gutenberg_add_edit_links', 10, 2 );
}
add_action( 'admin_init', 'gutenberg_add_edit_links_filters' );
@@ -185,14 +186,18 @@ function gutenberg_add_edit_links_filters() {
* the Gutenberg editor.
*
* @since 0.1.0
+ *
+ * @param array $actions Post actions.
+ * @param array $post Edited post.
+ *
+ * @return array Updated post actions.
*/
function gutenberg_add_edit_links( $actions, $post ) {
$can_edit_post = current_user_can( 'edit_post', $post->ID );
$title = _draft_or_post_title( $post->ID );
if ( $can_edit_post && 'trash' !== $post->post_status ) {
- // Build the Gutenberg edit action. See also:
- // WP_Posts_List_Table::handle_row_actions()
+ // Build the Gutenberg edit action. See also: WP_Posts_List_Table::handle_row_actions().
$gutenberg_url = menu_page_url( 'gutenberg', false );
$gutenberg_action = sprintf(
'%s',
@@ -208,7 +213,9 @@ function gutenberg_add_edit_links( $actions, $post ) {
$edit_offset = array_search( 'edit', array_keys( $actions ), true );
$actions = array_merge(
array_slice( $actions, 0, $edit_offset + 1 ),
- array( 'gutenberg hide-if-no-js' => $gutenberg_action ),
+ array(
+ 'gutenberg hide-if-no-js' => $gutenberg_action,
+ ),
array_slice( $actions, $edit_offset + 1 )
);
}
@@ -221,6 +228,8 @@ function gutenberg_add_edit_links( $actions, $post ) {
*
* @since 0.1.0
*
+ * @param string $domain Translation domain.
+ *
* @return array
*/
function gutenberg_get_jed_locale_data( $domain ) {
@@ -232,10 +241,10 @@ function gutenberg_get_jed_locale_data( $domain ) {
$domain => array(
'' => array(
'domain' => $domain,
- 'lang' => is_admin() ? get_user_locale() : get_locale()
- )
- )
- )
+ 'lang' => is_admin() ? get_user_locale() : get_locale(),
+ ),
+ ),
+ ),
);
if ( ! empty( $translations->headers['Plural-Forms'] ) ) {
@@ -268,16 +277,16 @@ function gutenberg_scripts_and_styles( $hook ) {
* Scripts
*/
- // The editor code itself
+ // The editor code itself.
wp_enqueue_script(
'wp-editor',
plugins_url( 'editor/build/index.js', __FILE__ ),
array( 'wp-i18n', 'wp-blocks', 'wp-element' ),
filemtime( plugin_dir_path( __FILE__ ) . 'editor/build/index.js' ),
- true // $in_footer
+ true // enqueue in the footer.
);
- // Load an actual post if an ID is specified
+ // Load an actual post if an ID is specified.
$post_to_edit = null;
if ( isset( $_GET['post_id'] ) && (int) $_GET['post_id'] > 0 ) {
$request = new WP_REST_Request(
@@ -304,7 +313,7 @@ function gutenberg_scripts_and_styles( $hook ) {
);
}
- // Prepare Jed locale data
+ // Prepare Jed locale data.
$locale_data = gutenberg_get_jed_locale_data( 'gutenberg' );
wp_add_inline_script(
'wp-editor',
@@ -312,7 +321,7 @@ function gutenberg_scripts_and_styles( $hook ) {
'before'
);
- // Initialize the editor
+ // Initialize the editor.
wp_add_inline_script( 'wp-editor', 'wp.editor.createEditorInstance( \'editor\', _wpGutenbergPost );' );
/**
@@ -361,11 +370,3 @@ function the_gutenberg_project() {
'render_html_block'
-) );
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index ed4079d33ed58..2eb5f4eae3c4b 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -8,7 +8,7 @@
>
- ./phpunit/
+ ./phpunit/
diff --git a/phpunit/test-dynamic-blocks-render.php b/phpunit/class-dynamic-blocks-render-test.php
similarity index 54%
rename from phpunit/test-dynamic-blocks-render.php
rename to phpunit/class-dynamic-blocks-render-test.php
index eadeaf97e7eb7..a7c01439ccf2d 100644
--- a/phpunit/test-dynamic-blocks-render.php
+++ b/phpunit/class-dynamic-blocks-render-test.php
@@ -1,26 +1,35 @@
[ $this, 'render_dummy_block' ] );
+ $settings = array(
+ 'render' => array(
+ $this,
+ 'render_dummy_block',
+ ),
+ );
register_block( 'core/dummy', $settings );
$post_content =
'before' .
diff --git a/phpunit/test-registration.php b/phpunit/class-registration-test.php
similarity index 58%
rename from phpunit/test-registration.php
rename to phpunit/class-registration-test.php
index e18ee72e34817..08b86e58fe394 100644
--- a/phpunit/test-registration.php
+++ b/phpunit/class-registration-test.php
@@ -1,7 +1,17 @@
'text' );
+ $settings = array(
+ 'icon' => 'text',
+ );
$updated_settings = register_block( 'core/text', $settings );
$this->assertEquals( $updated_settings, array(
'icon' => 'text',
- 'slug' => 'core/text'
+ 'slug' => 'core/text',
) );
unregister_block( 'core/text' );
}