Skip to content

Commit

Permalink
Additional menu options added (title attribute, css class, etc)
Browse files Browse the repository at this point in the history
  • Loading branch information
kylephillips committed Nov 8, 2014
1 parent 214264c commit 0a2a7c5
Show file tree
Hide file tree
Showing 13 changed files with 185 additions and 26 deletions.
2 changes: 1 addition & 1 deletion assets/css/nestedpages.css

Large diffs are not rendered by default.

32 changes: 29 additions & 3 deletions assets/js/lib/nestedpages.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,11 @@ jQuery(function($){
$(this).parents('form').find('.np-taxonomies').toggle();
});

// Toggle the Menu Options
$(document).on('click', '.np-toggle-menuoptions', function(e){
$(this).parents('form').find('.np-menuoptions').toggle();
});


/**
* Set Quick Edit data
Expand All @@ -345,7 +350,10 @@ jQuery(function($){
minute : $(item).attr('data-minute'),
navstatus : $(item).attr('data-navstatus'),
npstatus : $(item).attr('data-np-status'),
navtitle : $(item).attr('data-navtitle')
navtitle : $(item).attr('data-navtitle'),
navtitleattr : $(item).attr('data-navtitleattr'),
navcss : $(item).attr('data-navcss'),
linktarget : $(item).attr('data-linktarget')
};
var parent_li = $(item).closest('.row').parent('li');

Expand Down Expand Up @@ -383,6 +391,8 @@ jQuery(function($){
$(form).find('.np_template').val(data.template);
$(form).find('.np_status').val(data.status);
$(form).find('.np_nav_title').val(data.navtitle);
$(form).find('.np_title_attribute').val(data.navtitleattr);
$(form).find('.np_nav_css_classes').val(data.navcss);
if ( data.cs === 'open' ) $(form).find('.np_cs').prop('checked', 'checked');

if ( data.npstatus === 'hide' ){
Expand All @@ -396,6 +406,12 @@ jQuery(function($){
} else {
$(form).find('.np_nav_status').removeAttr('checked');
}

if ( data.linktarget === "_blank" ) {
$(form).find('.link_target').prop('checked', 'checked');
} else {
$(form).find('.link_target').removeAttr('checked');
}

// Date Fields
$(form).find('select[name="mm"]').val(data.month);
Expand Down Expand Up @@ -497,9 +513,13 @@ jQuery(function($){
$(button).attr('data-commentstatus', data.comment_status);
$(button).attr('data-status', data._status);
$(button).attr('data-author', data.post_author);
$(button).attr('data-navstatus', data.nav_status);
$(button).attr('data-np-status', data.np_status);

$(button).attr('data-navstatus', data.nav_status);
$(button).attr('data-navtitle', data.np_nav_title);
$(button).attr('data-linktarget', data.link_target);
$(button).attr('data-navtitleattr', data.np_title_attribute);
$(button).attr('data-navcss', data.np_nav_css_classes);

$(button).attr('data-month', data.mm);
$(button).attr('data-day', data.jj);
Expand Down Expand Up @@ -625,7 +645,9 @@ jQuery(function($){
navstatus : $(item).attr('data-navstatus'),
npstatus : $(item).attr('data-np-status'),
linktarget : $(item).attr('data-linktarget'),
parentid : $(item).attr('data-parentid')
parentid : $(item).attr('data-parentid'),
navtitleattr : $(item).attr('data-navtitleattr'),
navcss : $(item).attr('data-navcss')
};
var parent_li = $(item).closest('.row').parent('li');

Expand Down Expand Up @@ -654,6 +676,8 @@ jQuery(function($){
$(form).find('.np_status').val(data.status);
$(form).find('.np_content').val(data.url);
$(form).find('.np_parent_id').val(data.parentid);
$(form).find('.np_title_attribute').val(data.navtitleattr);
$(form).find('.np_nav_css_classes').val(data.navcss);

if ( data.npstatus === 'hide' ){
$(form).find('.np_status').prop('checked', 'checked');
Expand Down Expand Up @@ -750,6 +774,8 @@ jQuery(function($){
$(button).attr('data-navstatus', data.nav_status);
$(button).attr('data-np-status', data.np_status);
$(button).attr('data-linktarget', data.link_target);
$(button).attr('data-navtitleattr', data.np_title_attribute);
$(button).attr('data-navcss', data.np_nav_css_classes);
}


Expand Down
2 changes: 1 addition & 1 deletion assets/js/nestedpages.min.js

Large diffs are not rendered by default.

27 changes: 25 additions & 2 deletions assets/scss/_quick-edit.scss
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,19 @@
}

// Taxonomies
.np-toggle-taxonomies {
.np-toggle-taxonomies, .np-toggle-menuoptions {
clear: both;
float: right;
width: 71%;
text-align: center;
}
.np-taxonomies {
.np-taxonomies, .np-menuoptions {
display: none;
clear: both;
background-color: $gray-lighter;
padding: 8px;
@include clearfix;
margin-top: 5px;
}
.np-taxonomy {
float: left;
Expand All @@ -95,6 +96,28 @@
border: 0;
}
} // .np-taxonomy

// Menu Items
.np-menuoptions {
padding: 15px;
label, input[type="text"] {
display: block;
float: none;
width: 100%;
}
.menuoptions-left {
float: left;
width: 47%;
}
.menuoptions-right {
float: right;
width: 47%;
padding-top: 18px;
label {
margin-bottom: 10px;
}
}
} // .np-menuoptions
}

.np-qe-loading {
Expand Down
1 change: 1 addition & 0 deletions includes/class-np-handler-quickedit.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ private function addData()
{
$this->data['nav_status'] = ( isset($this->data['nav_status']) ) ? 'hide' : 'show';
$this->data['np_status'] = ( isset($this->data['nested_pages_status']) ) ? 'hide' : 'show';
$this->data['link_target'] = ( isset($this->data['link_target']) ) ? '_blank' : 'none';
if ( !isset($_POST['comment_status']) ) $this->data['comment_status'] = 'closed';
}

Expand Down
13 changes: 12 additions & 1 deletion includes/class-np-navmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ public function sync($parent = 0, $menu_parent = 0)
// Link Target
$link_target = get_post_meta( get_the_id(), 'np_link_target', true );

// Title Attribue
$title_attribute = get_post_meta( get_the_id(), 'np_title_attribute', true );

// CSS Classes
$css_classes = get_post_meta( get_the_id(), 'np_nav_css_classes', true );

// Nav Title
$nav_title = get_post_meta( get_the_id(), 'np_nav_title', true );
$nav_title = ( $nav_title !== "" ) ? $nav_title : get_the_title();
Expand All @@ -100,17 +106,22 @@ public function sync($parent = 0, $menu_parent = 0)
$menu = wp_update_nav_menu_item($this->id, 0, array(
'menu-item-title' => $nav_title,
'menu-item-url' => get_the_permalink(),
'menu-item-attr-title' => $title_attribute,
'menu-item-status' => 'publish',
'menu-item-classes' => $css_classes,
'menu-item-type' => 'post_type',
'menu-item-object' => 'page',
'menu-item-object-id' => get_the_id(),
'menu-item-parent-id' => $menu_parent
'menu-item-parent-id' => $menu_parent,
'menu-item-target' => $link_target
));
} else { // redirect
$menu = wp_update_nav_menu_item($this->id, 0, array(
'menu-item-title' => $nav_title,
'menu-item-url' => $this->check_url(get_the_content()),
'menu-item-attr-title' => $title_attribute,
'menu-item-status' => 'publish',
'menu-item-classes' => $css_classes,
'menu-item-type' => 'custom',
'menu-item-object' => 'page',
'menu-item-object-id' => get_the_id(),
Expand Down
11 changes: 9 additions & 2 deletions includes/class-np-pagelisting.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,9 @@ private function defaultPagesLink()
*/
private function visiblePages()
{
$visible = get_user_meta(get_current_user_id(), 'np_visible_pages', true);
return unserialize($visible);
$visible = unserialize(get_user_meta(get_current_user_id(), 'np_visible_pages', true));
if ( !$visible ) $visible = array();
return $visible;
}


Expand Down Expand Up @@ -227,6 +228,12 @@ private function setPostData($post)
// Parent ID
$this->post_data['parent_id'] = $post->post_parent;

// Nav Title Attribute
$this->post_data['nav_title_attr'] = get_post_meta(get_the_id(), 'np_title_attribute', true);

// Nav CSS Classes
$this->post_data['nav_css'] = get_post_meta(get_the_id(), 'np_nav_css_classes', true);

// Yoast Score
if ( function_exists('wpseo_translate_score') ) {
$yoast_score = get_post_meta(get_the_id(), '_yoast_wpseo_linkdex', true);
Expand Down
1 change: 1 addition & 0 deletions includes/class-np-posttypes.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public function __construct()
add_action( 'trashed_post', array( $this, 'trashHook' ) );
}


/**
* Redirects Post Type
*/
Expand Down
51 changes: 48 additions & 3 deletions includes/class-np-repository-post.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,19 @@ public function updatePost($data)
wp_update_post($updated_post);

$this->updateTemplate($data);
$this->updateNavStatus($data);
$this->updateNestedPagesStatus($data);
$this->updateNavTitle($data);

// Taxonomies
$this->updateCategories($data);
$this->updateHierarchicalTaxonomies($data);

// Menu Options
$this->updateNavStatus($data);
$this->updateNavTitle($data);
$this->updateLinkTarget($data);
$this->updateTitleAttribute($data);
$this->updateNavCSS($data);

return true;
}

Expand Down Expand Up @@ -129,7 +136,7 @@ private function updateNestedPagesStatus($data)


/**
* Update Nested Pages Menu Title
* Update Nested Pages Menu Navigation Label
* @since 1.0
* @param array data
*/
Expand All @@ -146,6 +153,42 @@ private function updateNavTitle($data)
}


/**
* Update Nested Pages Menu Navigation CSS Classes
* @since 1.0
* @param array data
*/
private function updateNavCSS($data)
{
if ( isset($data['np_nav_css_classes']) ){
$css_classes = sanitize_text_field($data['np_nav_css_classes']);
update_post_meta(
$data['post_id'],
'np_nav_css_classes',
$css_classes
);
}
}


/**
* Update Nested Pages Menu Title Attribute
* @since 1.0
* @param array data
*/
private function updateTitleAttribute($data)
{
if ( isset($data['np_title_attribute']) ){
$title_attr = sanitize_text_field($data['np_title_attribute']);
update_post_meta(
$data['post_id'],
'np_title_attribute',
$title_attr
);
}
}


/**
* Update Categories
* @since 1.0
Expand Down Expand Up @@ -221,6 +264,8 @@ public function updateRedirect($data)
$this->updateNavStatus($data);
$this->updateNestedPagesStatus($data);
$this->updateLinkTarget($data);
$this->updateTitleAttribute($data);
$this->updateNavCSS($data);

return true;
}
Expand Down
11 changes: 10 additions & 1 deletion views/quickedit-redirect.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<div class="left">

<div class="form-control">
<label><?php _e( 'Menu Title' ); ?></label>
<label><?php _e( 'Label', 'nestedpages' ); ?></label>
<input type="text" name="post_title" class="np_title" value="" />
</div>

Expand All @@ -38,7 +38,16 @@
</div><!-- .left -->

<div class="right">

<?php if ( current_user_can('edit_theme_options') ) : ?>
<div class="form-control">
<label><?php _e( 'Title Attribute', 'nestedpages' ); ?></label>
<input type="text" name="np_title_attribute" class="np_title_attribute" value="" />
</div>
<div class="form-control">
<label><?php _e( 'CSS Classes', 'nestedpages' ); ?></label>
<input type="text" name="np_nav_css_classes" class="np_nav_css_classes" value="" />
</div>
<div class="comments">
<label>
<input type="checkbox" name="nav_status" class="np_nav_status" value="hide" />
Expand Down
Loading

0 comments on commit 0a2a7c5

Please sign in to comment.