Skip to content

Commit 15329b2

Browse files
author
Mike Hemberger
committed
Merge branch 'release/1.3.1'
2 parents 51ccc58 + ece8b9a commit 15329b2

File tree

5 files changed

+119
-22
lines changed

5 files changed

+119
-22
lines changed

CHANGES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
#### 1.3.1 (9/21/17)
2+
* Fixed: Location child pages not showing on frontend.
3+
14
#### 1.3.0 (9/19/17)
25
* Changed: Allow locations to have child (grandchild) pages.
36
* Changed: Added updater script in plugin so no longer relying on GitHub Updater.

includes/class-frontend.php

Lines changed: 97 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
class User_Locations_Frontend {
1616

17-
/**
17+
/**
1818
* @var Parisi_Functions The one true Parisi_Functions
1919
* @since 1.0.0
2020
*/
@@ -31,13 +31,12 @@ public static function instance() {
3131
}
3232

3333
function init() {
34-
// Hook in the location menu ( not OOP so it can easily be removed/moved )
35-
add_action( 'genesis_after_header', 'ul_do_location_menu', 20 );
3634

3735
// Hook in the location posts ( not OOP so it can easily be removed/moved )
3836
add_action( 'genesis_after_loop', 'ul_do_location_posts' );
3937

4038
add_filter( 'body_class', array( $this, 'location_content_body_class' ) );
39+
add_filter( 'wp_get_nav_menu_items', array( $this, 'replace_primary_navigation' ), 10, 2 );
4140
add_filter( 'genesis_post_info', array( $this, 'maybe_remove_post_info' ), 99 );
4241
add_filter( 'genesis_post_meta', array( $this, 'maybe_remove_post_meta' ), 99 );
4342

@@ -60,6 +59,101 @@ public function location_content_body_class( $classes ) {
6059
return $classes;
6160
}
6261

62+
/**
63+
* Replace the primary navigation with the location menu items.
64+
*
65+
* @since 1.3.1
66+
*
67+
* @param array $items The existing menu items.
68+
* @param array $menu The menu.
69+
*
70+
* @return array The modified menu items.
71+
*/
72+
public function replace_primary_navigation( $items, $menu ) {
73+
74+
// Bail if not location page.
75+
if ( ! is_singular( 'location_page' ) ) {
76+
return $items;
77+
}
78+
79+
// Get all displayed locations.
80+
$locations = get_nav_menu_locations();
81+
82+
// Bail if no primary nav displaying.
83+
if ( ! isset( $locations['primary'] ) ) {
84+
return $items;
85+
}
86+
87+
// Bail if not filtering the primary nav.
88+
if ( $locations['primary'] != $menu->term_id ) {
89+
return $items;
90+
}
91+
92+
// Get the top level parent.
93+
$ancestors = array_reverse( get_ancestors( get_the_ID(), get_post_type() ) );
94+
$ancestors = empty( $ancestors ) ? array( get_the_ID() ) : $ancestors;
95+
96+
return $this->get_menu_tree( $ancestors[0], 'location_page' );
97+
}
98+
99+
/**
100+
* Get the menu tree from a specific post ID.
101+
*
102+
* @since 1.3.1
103+
*
104+
* @param int $parent_id The post ID to base the menu off of.
105+
* @param string $post_type The post type to check.
106+
* @param bool $grandchild Whether we are getting first level or second level menu items.
107+
*
108+
* @return array The menu.
109+
*/
110+
public function get_menu_tree( $parent_id, $post_type, $grandchild = false ) {
111+
112+
static $original_parent_id = 0;
113+
114+
if ( ! $grandchild ) {
115+
$original_parent_id = $parent_id;
116+
}
117+
118+
$children = array();
119+
120+
$pages = get_pages( array(
121+
'child_of' => $parent_id,
122+
'parent' => -1,
123+
'sort_column' => 'menu_order',
124+
'post_type' => $post_type,
125+
) );
126+
127+
if ( empty( $pages ) ) {
128+
return $children;
129+
}
130+
131+
$menu_order = 1;
132+
133+
if ( ! $grandchild ) {
134+
// Add parent.
135+
$home = get_post( $parent_id );
136+
$home->post_title = __( 'Home', 'user-locations' );
137+
array_unshift( $pages, $home );
138+
}
139+
140+
foreach ( $pages as $page ) {
141+
142+
$child = wp_setup_nav_menu_item( $page );
143+
144+
$child->db_id = $page->ID;
145+
$child->menu_item_parent = ( $original_parent_id == $page->post_parent ) ? 0 : $page->post_parent;
146+
$child->menu_order = $menu_order;
147+
148+
$children[] = $child;
149+
150+
$menu_order++;
151+
152+
}
153+
154+
return $children;
155+
}
156+
63157
/**
64158
* Remove post info from location pages
65159
*

includes/class-template-loader.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ public function init() {
9292
*/
9393
public function maybe_location_page_template() {
9494

95-
if ( ! is_singular('location_page') || ! ul_is_location_parent_page_template() ) {
96-
return;
97-
}
98-
global $post;
99-
// Bail if we're on a parent Location Page
100-
if ( $post->post_parent == 0 ) {
101-
return;
102-
}
95+
if ( ! is_singular('location_page') || ! ul_is_location_parent_page_template() ) {
96+
return;
97+
}
98+
global $post;
99+
// Bail if we're on a parent Location Page
100+
if ( $post->post_parent == 0 ) {
101+
return;
102+
}
103103
// Add custom body class to the head
104-
add_filter( 'body_class', array( $this, 'body_classes' ) );
105-
add_action( 'genesis_loop', array( $this, 'do_location_page_templates_loop' ) );
104+
add_filter( 'body_class', array( $this, 'body_classes' ) );
105+
add_action( 'genesis_entry_content', array( $this, 'do_location_page_templates_loop' ), 12 );
106106
}
107107

108108
/**

includes/functions.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,12 +100,12 @@ function ul_get_location_menu() {
100100
}
101101

102102
$args = array(
103-
'post_type' => 'location_page',
104-
'posts_per_page' => 50,
105-
'post_status' => 'publish',
106-
'post_parent' => $parent_id,
107-
'orderby' => 'menu_order',
108-
'order' => 'ASC',
103+
'post_type' => 'location_page',
104+
'posts_per_page' => 50,
105+
'post_status' => 'publish',
106+
'post_parent' => $parent_id,
107+
'orderby' => 'menu_order',
108+
'order' => 'ASC',
109109
);
110110
// Allow for filtering of the menu item args
111111
$args = apply_filters( 'userlocations_location_menu_args', $args );
@@ -139,7 +139,7 @@ function ul_get_location_menu() {
139139
$classes .= ' current-menu-item';
140140
}
141141
// Add each menu item
142-
$output .= '<li id="menu-item-' . $page_id . '" class="' . $classes . '"><a href="' . get_the_permalink( $page->ID ) . '" itemprop="url"><span itemprop="name">' . get_the_title( $page->ID ) . '</span></a></li>';
142+
$output .= '<li id="menu-item-' . $page_id . '" class="' . $classes . '"><a href="' . get_the_permalink( $page->ID ) . '" itemprop="url"><span itemprop="name">' . get_the_title( $page->ID ) . '</span></a></li>';
143143
}
144144

145145
$output .= '</ul>';

user-locations.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* Text Domain: user-locations
1616
* License: GPL-2.0+
1717
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
18-
* Version: 1.3.0
18+
* Version: 1.3.1
1919
* GitHub Plugin URI: https://github.com/bizbudding/user-locations
2020
* GitHub Branch: master
2121
*/
@@ -173,7 +173,7 @@ private function setup_constants() {
173173

174174
// Plugin version.
175175
if ( ! defined( 'USER_LOCATIONS_VERSION' ) ) {
176-
define( 'USER_LOCATIONS_VERSION', '1.3.0' );
176+
define( 'USER_LOCATIONS_VERSION', '1.3.1' );
177177
}
178178

179179
// Plugin Folder Path.

0 commit comments

Comments
 (0)