Skip to content

Commit

Permalink
Merge pull request #552 from Automattic/fix/custom-status-title
Browse files Browse the repository at this point in the history
Fix WP Menu post title notice
  • Loading branch information
cojennin authored Dec 12, 2019
2 parents 3eb2acd + 8276b63 commit 2b8f7b8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
8 changes: 4 additions & 4 deletions modules/custom-status/custom-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -749,16 +749,16 @@ function _filter_manage_posts_custom_column( $column_name ) {
*
* @param array $post_states An array of post display states.
*/
function check_if_post_state_is_status($post_states) {
function check_if_post_state_is_status( $post_states, $post ) {

global $post;
$statuses = get_post_status_object(get_post_status($post->ID));
$statuses = get_post_status_object( get_post_status( $post->ID ) );
foreach ( $post_states as $state ) {
if ( $state !== $statuses->label ) {
echo '<span class="show"></span>';
}
}
return $post_states;

return $post_states;
}

/**
Expand Down
44 changes: 44 additions & 0 deletions tests/test-edit-flow-custom-status.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ class WP_Test_Edit_Flow_Custom_Status extends WP_UnitTestCase {

protected static $admin_user_id;
protected static $EF_Custom_Status;

/**
* @var \Walker_Nav_Menu The instance of the walker.
*/
public $walker;

public static function wpSetUpBeforeClass( $factory ) {
self::$admin_user_id = $factory->user->create( array( 'role' => 'administrator' ) );
Expand All @@ -21,6 +26,10 @@ public static function wpTearDownAfterClass() {
function setUp() {
parent::setUp();

/** Walker_Nav_Menu class */
require_once ABSPATH . 'wp-admin/includes/class-walker-nav-menu-checklist.php';
$this->walker = new Walker_Nav_Menu_Checklist();

global $pagenow;
$pagenow = 'post.php';
}
Expand Down Expand Up @@ -332,4 +341,39 @@ public function test_fix_get_sample_permalink_should_respect_hierarchy_of_publis
$this->assertSame( home_url() . '/publish-parent-page/%pagename%/', $actual[0] );
$this->assertSame( 'child-page', $actual[1] );
}

/**
* Validate the usage of $post in `check_if_post_state_is_status` hook
*/
public function test_walker_nav_menu_checklist_title() {
$expected = '';
$post_id = $this->factory->post->create();
$post_title = get_the_title( $post_id );

$item = array(
'ID' => $post_id,
'object_id' => $post_id,
'title' => $post_title,
'menu_item_parent' => null,
'object' => null,
'type' => 'post',
'url' => '',
'attr_title' => '',
'classes' => array(),
'target' => '_blank',
'xfn' => '',
'current' => false,
);

$args = array(
'before' => '',
'after' => '',
'link_before' => '',
'link_after' => '',
);

$this->walker->start_el( $expected, (object) $item, 0, (object) $args );

$this->assertStringStartsWith( "<li><label class=\"menu-item-title\"><input type=\"checkbox\" class=\"menu-item-checkbox\" name=\"menu-item[-1][menu-item-object-id]\" value=\"$post_id\" /> $post_title</label>", $expected );
}
}

0 comments on commit 2b8f7b8

Please sign in to comment.