Fix menu roles

This commit is contained in:
champsupertramp
2016-04-16 14:53:54 +08:00
parent 819d0165db
commit d95522cefb
+27 -10
View File
@@ -29,16 +29,27 @@ class UM_Menu_Item_Custom_Fields_Editor {
foreach ( self::$fields as $_key => $label ) {
$key = sprintf( 'menu-item-%s', $_key );
if( $_key == 'um_nav_roles' ){
$key = sprintf( 'menu-item-%s%d', $_key, $menu_item_db_id );
// Sanitize
if ( ! empty( $_POST[ $key ] ) ) {
// Do some checks here...
$value = $_POST[ $key ];
}
else {
$value = null;
}
// Sanitize
if ( ! empty( $_POST[ $key ][ $menu_item_db_id ] ) ) {
// Do some checks here...
$value = $_POST[ $key ][ $menu_item_db_id ];
}else{
// Sanitize
if ( ! empty( $_POST[ $key ][ $menu_item_db_id ] ) ) {
// Do some checks here...
$value = $_POST[ $key ][ $menu_item_db_id ];
}
else {
$value = null;
}
}
else {
$value = null;
}
// Update
if ( ! is_null( $value ) ) {
update_post_meta( $menu_item_db_id, $key, $value );
@@ -47,6 +58,7 @@ class UM_Menu_Item_Custom_Fields_Editor {
delete_post_meta( $menu_item_db_id, $key );
}
}
}
public static function _fields( $id, $item, $depth, $args ) {
@@ -66,6 +78,10 @@ class UM_Menu_Item_Custom_Fields_Editor {
$id = sprintf( 'edit-%s-%s', $key, $item->ID );
$name = sprintf( '%s[%s]', $key, $item->ID );
$value = get_post_meta( $item->ID, $key, true );
$role_key = sprintf( 'menu-item-%s%d', $_key,$item->ID );
$role_name = sprintf( '%s%s[]', $key, $item->ID );
$role_value = get_post_meta( $item->ID, $role_key, true );
$class = sprintf( 'field-%s', $_key );
?>
@@ -98,7 +114,7 @@ class UM_Menu_Item_Custom_Fields_Editor {
<p class="description">
<?php foreach($ultimatemember->query->get_roles() as $role_id => $role) { ?>
<label><input type="checkbox" name="<?php echo $name; ?>[]" value="<?php echo $role_id; ?>" <?php if ( ( is_array($value) && in_array($role_id, $value ) ) || ( isset($value) && $role_id == $value ) ) echo 'checked="checked"'; ?> /> <?php echo $role; ?></label>&nbsp;&nbsp;
<label><input type="checkbox" data-raw="<?php echo $role_id.'='.$role.'='.$value; ?>" name="<?php echo $role_name; ?>" value="<?php echo $role_id; ?>" <?php if ( ( is_array( $role_value) && in_array($role_id, $role_value ) ) || ( isset( $role_value) && $role_id == $role_value ) ) echo 'checked="checked"'; ?> /> <?php echo $role; ?></label>&nbsp;&nbsp;
<?php } ?>
</p>
@@ -122,4 +138,5 @@ class UM_Menu_Item_Custom_Fields_Editor {
return $columns;
}
}
UM_Menu_Item_Custom_Fields_Editor::init();
UM_Menu_Item_Custom_Fields_Editor::init();