Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Admin: Show post display state for Gutenberg posts
  • Loading branch information
aduth committed Sep 1, 2017
commit 547d0386c83389e848d9a2c213c50ea5e9749bc9
16 changes: 16 additions & 0 deletions lib/register.php
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,19 @@ function gutenberg_post_has_blocks( $post_id ) {
$post = get_post( $post_id );
return $post && strpos( $post->post_content, '<!-- wp:' ) !== false;
}

/**
* Adds a "Gutenberg" post state for post tables, if the post contains blocks.
*
* @param array $post_states An array of post display states.
* @param WP_Post $post The current post object.
* @return array A filtered array of post display states.
*/
function gutenberg_add_gutenberg_post_state( $post_states, $post ) {
if ( gutenberg_post_has_blocks( $post->ID ) ) {
$post_states[] = 'Gutenberg';
}

return $post_states;
}
add_filter( 'display_post_states', 'gutenberg_add_gutenberg_post_state', 10, 2 );
15 changes: 15 additions & 0 deletions phpunit/class-admin-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,19 @@ function test_gutenberg_post_has_blocks() {
$this->assertTrue( gutenberg_post_has_blocks( self::$post_with_blocks ) );
$this->assertFalse( gutenberg_post_has_blocks( self::$post_without_blocks ) );
}

/**
* Tests gutenberg_add_gutenberg_post_state().
*
* @covers gutenberg_add_gutenberg_post_state
*/
function test_add_gutenberg_post_state() {
// With blocks.
$post_states = apply_filters( 'display_post_states', array(), get_post( self::$post_with_blocks ) );
$this->assertEquals( array( 'Gutenberg' ), $post_states );

// Without blocks.
$post_states = apply_filters( 'display_post_states', array(), get_post( self::$post_without_blocks ) );
$this->assertEquals( array(), $post_states );
}
}