Skip to content

Commit

Permalink
Merge branch 'master' of github.com:timber/timber
Browse files Browse the repository at this point in the history
# Conflicts:
#	readme.txt
  • Loading branch information
jarednova committed Oct 18, 2019
2 parents d4b6ffb + 6c4a2cb commit 25e91be
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 6 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,11 @@ Timber is great for any WordPress developer who cares about writing good, mainta
* [**Timber Debugger**](https://github.com/djboris88/timber-debugger) Package that provides extra debugging options for Timber
* [**Timber Dump Extension**](https://github.com/nlemoine/timber-dump-extension) Debug output with nice formatting
* [**Timber Photon**](https://github.com/slimndap/TimberPhoton) Plug-in to use JetPack's free Photon image manipulation and CDN with Timber
* [**Timber VS Code Extension**](https://github.com/JDevx97/Timber-Snippets) Snippets for Timber in Visual Studio Code
* [**Timber Sugar**](https://github.com/timber/sugar) A catch-all for goodies to use w Timber
* [**Timber WebLink Extension**](https://github.com/nlemoine/timber-weblink-extension) Provides Twig functions to manage the Link HTTP header needed for Web Linking when using HTTP/2 Server Push as well as Resource Hints
* [**Timmy**](https://github.com/MINDKomm/Timmy) Advanced image manipulation for Timber
* [**Timber ACF WP Blocks**](https://github.com/palmiak/timber-acf-wp-blocks) Easy ACF Gutenberg blocks creation

#### Projects that use Timber
* [**Branch**](https://github.com/JeyKeu/branch/) Bootstrap 3 + Timber = Branch starter theme!
Expand Down
25 changes: 19 additions & 6 deletions lib/MenuItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,14 @@ class MenuItem extends Core implements CoreInterface {
public $current_item_ancestor;

/**
* Timber Menu.
* Timber Menu. Previously this was a public property, but converted to a method to avoid
* recursion (see #2071).
*
* @api
* @since 1.9.6
* @since 1.12.0
* @see \Timber\Menu::menu();
* @var \Timber\Menu The `Timber\Menu` object the menu item is associated with.
*/
public $menu;
protected $menu;

protected $_name;
protected $_menu_item_object_id;
Expand Down Expand Up @@ -252,9 +253,9 @@ public function import_classes( $data ) {
$this->classes = array_unique($this->classes);

$options = new \stdClass();
if ( isset( $this->menu->options ) ) {
if ( isset($this->menu()->options) ) {
// The options need to be an object.
$options = (object) $this->menu->options;
$options = (object) $this->menu()->options;
}

/**
Expand Down Expand Up @@ -339,6 +340,18 @@ public function type() {
return $this->_menu_item_type;
}

/**
* Timber Menu.
*
* @api
* @since 1.12.0
* @return \Timber\Menu The `Timber\Menu` object the menu item is associated with.
*/
public function menu() {
return $this->menu;
}


/**
* Get a meta value of the menu item.
*
Expand Down
16 changes: 16 additions & 0 deletions tests/test-timber-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,22 @@ function testPagesMenu() {
$this->assertGreaterThanOrEqual( 3, count( $menu->get_items() ) );
}

function testJSONEncodedMenu() {
$pg_1 = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'Foo Page', 'menu_order' => 10 ) );
$pg_2 = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'Bar Page', 'menu_order' => 1 ) );
$page_menu = new Timber\Menu();
$text = json_encode($page_menu->get_items());
$this->assertGreaterThan(1, strlen($text));
}

function testMenuItemMenuProperty() {
$pg_1 = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'Foo Page', 'menu_order' => 10 ) );
$pg_2 = $this->factory->post->create( array( 'post_type' => 'page', 'post_title' => 'Bar Page', 'menu_order' => 1 ) );
$page_menu = new Timber\Menu();
$items = $page_menu->get_items();
$menu = $items[0]->menu;
$this->assertEquals('Timber\Menu', get_class($menu));
}


function testPagesMenuWithFalse() {
Expand Down

0 comments on commit 25e91be

Please sign in to comment.