Skip to content

Commit

Permalink
Merge branch 'release/1.3.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike Hemberger committed Sep 21, 2017
2 parents 51ccc58 + ece8b9a commit 15329b2
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 22 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#### 1.3.1 (9/21/17)
* Fixed: Location child pages not showing on frontend.

#### 1.3.0 (9/19/17)
* Changed: Allow locations to have child (grandchild) pages.
* Changed: Added updater script in plugin so no longer relying on GitHub Updater.
Expand Down
100 changes: 97 additions & 3 deletions includes/class-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class User_Locations_Frontend {

/**
/**
* @var Parisi_Functions The one true Parisi_Functions
* @since 1.0.0
*/
Expand All @@ -31,13 +31,12 @@ public static function instance() {
}

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

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

add_filter( 'body_class', array( $this, 'location_content_body_class' ) );
add_filter( 'wp_get_nav_menu_items', array( $this, 'replace_primary_navigation' ), 10, 2 );
add_filter( 'genesis_post_info', array( $this, 'maybe_remove_post_info' ), 99 );
add_filter( 'genesis_post_meta', array( $this, 'maybe_remove_post_meta' ), 99 );

Expand All @@ -60,6 +59,101 @@ public function location_content_body_class( $classes ) {
return $classes;
}

/**
* Replace the primary navigation with the location menu items.
*
* @since 1.3.1
*
* @param array $items The existing menu items.
* @param array $menu The menu.
*
* @return array The modified menu items.
*/
public function replace_primary_navigation( $items, $menu ) {

// Bail if not location page.
if ( ! is_singular( 'location_page' ) ) {
return $items;
}

// Get all displayed locations.
$locations = get_nav_menu_locations();

// Bail if no primary nav displaying.
if ( ! isset( $locations['primary'] ) ) {
return $items;
}

// Bail if not filtering the primary nav.
if ( $locations['primary'] != $menu->term_id ) {
return $items;
}

// Get the top level parent.
$ancestors = array_reverse( get_ancestors( get_the_ID(), get_post_type() ) );
$ancestors = empty( $ancestors ) ? array( get_the_ID() ) : $ancestors;

return $this->get_menu_tree( $ancestors[0], 'location_page' );
}

/**
* Get the menu tree from a specific post ID.
*
* @since 1.3.1
*
* @param int $parent_id The post ID to base the menu off of.
* @param string $post_type The post type to check.
* @param bool $grandchild Whether we are getting first level or second level menu items.
*
* @return array The menu.
*/
public function get_menu_tree( $parent_id, $post_type, $grandchild = false ) {

static $original_parent_id = 0;

if ( ! $grandchild ) {
$original_parent_id = $parent_id;
}

$children = array();

$pages = get_pages( array(
'child_of' => $parent_id,
'parent' => -1,
'sort_column' => 'menu_order',
'post_type' => $post_type,
) );

if ( empty( $pages ) ) {
return $children;
}

$menu_order = 1;

if ( ! $grandchild ) {
// Add parent.
$home = get_post( $parent_id );
$home->post_title = __( 'Home', 'user-locations' );
array_unshift( $pages, $home );
}

foreach ( $pages as $page ) {

$child = wp_setup_nav_menu_item( $page );

$child->db_id = $page->ID;
$child->menu_item_parent = ( $original_parent_id == $page->post_parent ) ? 0 : $page->post_parent;
$child->menu_order = $menu_order;

$children[] = $child;

$menu_order++;

}

return $children;
}

/**
* Remove post info from location pages
*
Expand Down
20 changes: 10 additions & 10 deletions includes/class-template-loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,17 @@ public function init() {
*/
public function maybe_location_page_template() {

if ( ! is_singular('location_page') || ! ul_is_location_parent_page_template() ) {
return;
}
global $post;
// Bail if we're on a parent Location Page
if ( $post->post_parent == 0 ) {
return;
}
if ( ! is_singular('location_page') || ! ul_is_location_parent_page_template() ) {
return;
}
global $post;
// Bail if we're on a parent Location Page
if ( $post->post_parent == 0 ) {
return;
}
// Add custom body class to the head
add_filter( 'body_class', array( $this, 'body_classes' ) );
add_action( 'genesis_loop', array( $this, 'do_location_page_templates_loop' ) );
add_filter( 'body_class', array( $this, 'body_classes' ) );
add_action( 'genesis_entry_content', array( $this, 'do_location_page_templates_loop' ), 12 );
}

/**
Expand Down
14 changes: 7 additions & 7 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ function ul_get_location_menu() {
}

$args = array(
'post_type' => 'location_page',
'posts_per_page' => 50,
'post_status' => 'publish',
'post_parent' => $parent_id,
'orderby' => 'menu_order',
'order' => 'ASC',
'post_type' => 'location_page',
'posts_per_page' => 50,
'post_status' => 'publish',
'post_parent' => $parent_id,
'orderby' => 'menu_order',
'order' => 'ASC',
);
// Allow for filtering of the menu item args
$args = apply_filters( 'userlocations_location_menu_args', $args );
Expand Down Expand Up @@ -139,7 +139,7 @@ function ul_get_location_menu() {
$classes .= ' current-menu-item';
}
// Add each menu item
$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>';
$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>';
}

$output .= '</ul>';
Expand Down
4 changes: 2 additions & 2 deletions user-locations.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* Text Domain: user-locations
* License: GPL-2.0+
* License URI: http://www.gnu.org/licenses/gpl-2.0.txt
* Version: 1.3.0
* Version: 1.3.1
* GitHub Plugin URI: https://github.com/bizbudding/user-locations
* GitHub Branch: master
*/
Expand Down Expand Up @@ -173,7 +173,7 @@ private function setup_constants() {

// Plugin version.
if ( ! defined( 'USER_LOCATIONS_VERSION' ) ) {
define( 'USER_LOCATIONS_VERSION', '1.3.0' );
define( 'USER_LOCATIONS_VERSION', '1.3.1' );
}

// Plugin Folder Path.
Expand Down

0 comments on commit 15329b2

Please sign in to comment.