From 630ff857a59524713137bc7a07740548a4264d3d Mon Sep 17 00:00:00 2001 From: James Nylen Date: Fri, 9 Jun 2017 16:52:27 -0400 Subject: [PATCH] Improve `core/latestposts` block PHP code (#1095) --- bin/build-plugin-zip.sh | 1 + gutenberg.php | 6 ++++-- lib/blocks.php | 11 ----------- .../index.php => lib/blocks/latest-posts.php | 4 ++-- 4 files changed, 7 insertions(+), 15 deletions(-) rename blocks/library/latest-posts/index.php => lib/blocks/latest-posts.php (90%) diff --git a/bin/build-plugin-zip.sh b/bin/build-plugin-zip.sh index a8aa776e22a974..0b5b51fd7633c1 100755 --- a/bin/build-plugin-zip.sh +++ b/bin/build-plugin-zip.sh @@ -18,6 +18,7 @@ rm -f gutenberg.zip zip -r gutenberg.zip \ gutenberg.php \ lib/*.php \ + lib/blocks/*.php \ post-content.js \ blocks/build \ components/build \ diff --git a/gutenberg.php b/gutenberg.php index 98fa84bc9c0519..3436e1f6bfae83 100644 --- a/gutenberg.php +++ b/gutenberg.php @@ -9,9 +9,11 @@ * @package gutenberg */ -define( 'GUTENBERG__PLUGIN_DIR', plugin_dir_path( __FILE__ ) ); - +// Load API functions. require_once dirname( __FILE__ ) . '/lib/blocks.php'; require_once dirname( __FILE__ ) . '/lib/client-assets.php'; require_once dirname( __FILE__ ) . '/lib/i18n.php'; require_once dirname( __FILE__ ) . '/lib/register.php'; + +// Register server-side code for individual blocks. +require_once dirname( __FILE__ ) . '/lib/blocks/latest-posts.php'; diff --git a/lib/blocks.php b/lib/blocks.php index 7864b5f9b31f7b..58d23c7eb8a9d1 100644 --- a/lib/blocks.php +++ b/lib/blocks.php @@ -9,8 +9,6 @@ die( 'Silence is golden.' ); } -define( 'GUTENBERG__BLOCKS_LIBRARY_DIR', GUTENBERG__PLUGIN_DIR . 'blocks/library' ); - $wp_registered_blocks = array(); /** @@ -130,12 +128,3 @@ function do_blocks( $content ) { return $new_content; } add_filter( 'the_content', 'do_blocks', 10 ); // BEFORE do_shortcode(). - -/** - * Loads the server-side rendering of blocks. If your block supports - * server-side rendering, add it here. - */ -function gutenberg_load_blocks_server_side_rendering() { - require_once GUTENBERG__BLOCKS_LIBRARY_DIR . '/latest-posts/index.php'; -} -add_action( 'init', 'gutenberg_load_blocks_server_side_rendering' ); diff --git a/blocks/library/latest-posts/index.php b/lib/blocks/latest-posts.php similarity index 90% rename from blocks/library/latest-posts/index.php rename to lib/blocks/latest-posts.php index e947a54f8aaa2e..60719e9a12921e 100644 --- a/blocks/library/latest-posts/index.php +++ b/lib/blocks/latest-posts.php @@ -12,7 +12,7 @@ * * @return string Returns the post content with latest posts added. */ -function gutenberg_block_core_latest_posts( $attributes ) { +function gutenberg_render_block_core_latest_posts( $attributes ) { $posts_to_show = 5; if ( array_key_exists( 'poststoshow', $attributes ) ) { @@ -56,5 +56,5 @@ function gutenberg_block_core_latest_posts( $attributes ) { } register_block_type( 'core/latestposts', array( - 'render' => 'gutenberg_block_core_latest_posts', + 'render' => 'gutenberg_render_block_core_latest_posts', ) );