Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve core/latestposts block PHP code #1095

Merged
merged 1 commit into from
Jun 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
) );