Skip to content

Commit

Permalink
add menu_name key and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joemaller committed Feb 12, 2025
1 parent 8f3a2e2 commit 83d1c9f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/DataModel/Labels.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public static function labels($singular, $plural, $is_post, $is_hierarchical = t
}
}

/**
* The menu_name label is a special case which is added after default menus are retrieved
* @link https://github.com/WordPress/wordpress-develop/blob/ac2eeb9868d995f5632fcfdc40e8b36e22724ba7/src/wp-includes/post.php#L2102
* @link https://github.com/WordPress/wordpress-develop/blob/ac2eeb9868d995f5632fcfdc40e8b36e22724ba7/src/wp-includes/taxonomy.php#L720
*/
$labels->menu_name = $labels->name;

$newLabels = self::updateLabels($singular, $plural, $labels);

return $newLabels;
Expand Down
14 changes: 14 additions & 0 deletions tests/LabelsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,18 @@ public function testTaxonomyLabels()
$actual = DataModel\Labels::taxonomy('color', 'colors');
$this->assertEqualsIgnoringCase('Colors', $actual->name);
}

public function testPostTypeLabelsHasMenuName()
{
$actual = DataModel\Labels::post_type('dog', 'Dogs');
$this->assertObjectHasProperty('menu_name', $actual);
$this->assertEqualsIgnoringCase('Dogs', $actual->menu_name);
}

public function testTaxonomyLabelsHasMenuName()
{
$actual = DataModel\Labels::taxonomy('color', 'colors');
$this->assertObjectHasProperty('menu_name', $actual);
$this->assertEqualsIgnoringCase('Colors', $actual->menu_name);
}
}

0 comments on commit 83d1c9f

Please sign in to comment.