diff --git a/includes/admin/assets/js/um-admin-nav-menu.js b/includes/admin/assets/js/um-admin-nav-menu.js new file mode 100644 index 00000000..b0ab47dc --- /dev/null +++ b/includes/admin/assets/js/um-admin-nav-menu.js @@ -0,0 +1,15 @@ +jQuery(document).ready(function ($) { + + var template = wp.template('um-nav-menus-fields'); + + $(document).on('menu-item-added', function (e, $menuMarkup) { + var id = $($menuMarkup).attr('id').substr(10); + $('fieldset.field-move', $($menuMarkup)).before(template({menuItemID: id,restriction_data:{um_nav_public:0,um_nav_roles:[]}})); + }); + + $('ul#menu-to-edit > li').each(function () { + var id = $(this).attr('id').substr(10); + $('fieldset.field-move', $(this)).before(template({menuItemID: id,restriction_data:um_menu_restriction_data[id]})); + }); + +}); \ No newline at end of file diff --git a/includes/admin/core/class-admin-enqueue.php b/includes/admin/core/class-admin-enqueue.php index e26be8e7..74e818ce 100644 --- a/includes/admin/core/class-admin-enqueue.php +++ b/includes/admin/core/class-admin-enqueue.php @@ -339,6 +339,15 @@ if ( ! class_exists( 'Admin_Enqueue' ) ) { } + /*** + *** @Load jQuery custom code + ***/ + function load_nav_manus_scripts() { + + wp_register_script( 'um_admin_nav_manus', $this->js_url . 'um-admin-nav-menu.js', array('jquery','wp-util'), '', true ); + wp_enqueue_script( 'um_admin_nav_manus' ); + + } /*** *** @Load AJAX diff --git a/includes/core/um-navmenu-walker-edit.php b/includes/core/um-navmenu-walker-edit.php index c48c9010..c5a278fa 100644 --- a/includes/core/um-navmenu-walker-edit.php +++ b/includes/core/um-navmenu-walker-edit.php @@ -1,160 +1,255 @@ __( 'Display Mode'), - 'um_nav_roles' => __('By Role') - - ); - } + 'um_nav_public' => __( 'Display Mode' ), + 'um_nav_roles' => __( 'By Role' ) + + ); + + //add_action( 'wp_nav_menu_item_custom_fields', array( __CLASS__, '_fields' ), 1, 4 ); + add_action( 'wp_update_nav_menu_item', array( __CLASS__, '_save' ), 10, 3 ); + add_filter( 'manage_nav-menus_columns', array( __CLASS__, '_columns' ), 99 ); + + add_action( 'load-nav-menus.php', array( __CLASS__, 'enqueue_nav_menus_scripts' ) ); + add_action( 'admin_footer-nav-menus.php', array( __CLASS__, '_wp_template' ) ); + + } - public static function _save( $menu_id, $menu_item_db_id, $menu_item_args ) { - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { - return; - } - - foreach ( self::$fields as $_key => $label ) { - - if( $_key == 'um_nav_roles' ){ - - $key = sprintf( 'menu-item-%s', $_key ); - - // Sanitize - if ( ! empty( $_POST[ $key ][ $menu_item_db_id ] ) ) { - // Do some checks here... - $value = $_POST[ $key ][ $menu_item_db_id ]; - } - else { - $value = null; + public static function _save( $menu_id, $menu_item_db_id, $menu_item_args ) { + if (defined( 'DOING_AJAX' ) && DOING_AJAX) { + return; } - }else{ - - $key = sprintf( 'menu-item-%s', $_key ); - - // Sanitize - if ( ! empty( $_POST[ $key ][ $menu_item_db_id ] ) ) { - // Do some checks here... - $value = $_POST[ $key ][ $menu_item_db_id ]; - } - else { - $value = null; + foreach (self::$fields as $_key => $label) { + + if ($_key == 'um_nav_roles') { + + $key = sprintf( 'menu-item-%s', $_key ); + + // Sanitize + if (!empty( $_POST[$key][$menu_item_db_id] )) { + // Do some checks here... + $value = $_POST[$key][$menu_item_db_id]; + } else { + $value = null; + } + + } else { + + $key = sprintf( 'menu-item-%s', $_key ); + + // Sanitize + if (!empty( $_POST[$key][$menu_item_db_id] )) { + // Do some checks here... + $value = $_POST[$key][$menu_item_db_id]; + } else { + $value = null; + } + } + + // Update + if (!is_null( $value )) { + update_post_meta( $menu_item_db_id, $key, $value ); + } else { + delete_post_meta( $menu_item_db_id, $key ); + } } } - // Update - if ( ! is_null( $value ) ) { - update_post_meta( $menu_item_db_id, $key, $value ); - } - else { - delete_post_meta( $menu_item_db_id, $key ); - } - } - } + public static function _fields( $id, $item, $depth, $args ) { + ?> - public static function _fields( $id, $item, $depth, $args ) { - ?> - -
- -
+ - + + - if ( $_key == 'um_nav_roles' ) { ?> + -
+
- foreach ( $section_fields_per_page as $k => $title ) {
- $id_attr = ' id="' . $id . '_' . $k . '" ';
- $for_attr = ' for="' . $id . '_' . $k . '" ';
- $name_attr = ' name="' . $role_name . '" ';
+ roles()->get_roles();
+ $i = 0;
+ $html = '';
+ $columns = 2;
+ while ($i < $columns) {
+ $per_page = ceil( count( $options ) / $columns );
+ $section_fields_per_page = array_slice( $options, $i * $per_page, $per_page );
+ $html .= '';
- $html .= "';
- $i++;
- }
+ $html .= '