Skip to content

Fix WP Menu post title notice #552

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

Merged
merged 1 commit into from
Dec 12, 2019
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
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 );
}
}