Skip to content

Commit

Permalink
Improve core/latestposts block PHP code (#1095)
Browse files Browse the repository at this point in the history
  • Loading branch information
nylen authored Jun 9, 2017
1 parent 6dea0df commit 630ff85
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 15 deletions.
1 change: 1 addition & 0 deletions bin/build-plugin-zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
6 changes: 4 additions & 2 deletions gutenberg.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
11 changes: 0 additions & 11 deletions lib/blocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
die( 'Silence is golden.' );
}

define( 'GUTENBERG__BLOCKS_LIBRARY_DIR', GUTENBERG__PLUGIN_DIR . 'blocks/library' );

$wp_registered_blocks = array();

/**
Expand Down Expand Up @@ -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' );
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) {
Expand Down Expand Up @@ -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',
) );

0 comments on commit 630ff85

Please sign in to comment.