__( 'Display Mode', 'ultimate-member' ), 'um_nav_roles' => __( 'By Role', 'ultimate-member' ) ); add_action( 'wp_update_nav_menu_item', array( &$this, '_save' ), 10, 3 ); //add_filter( 'manage_nav-menus_columns', array( &$this, '_columns' ), 99 ); add_action( 'load-nav-menus.php', array( &$this, 'enqueue_nav_menus_scripts' ) ); add_action( 'admin_footer-nav-menus.php', array( &$this, '_wp_template' ) ); } /** * @param $menu_id * @param $menu_item_db_id * @param $menu_item_args */ function _save( $menu_id, $menu_item_db_id, $menu_item_args ) { if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { return; } if ( empty( $_POST['menu-item-db-id'] ) || ! in_array( $menu_item_db_id, $_POST['menu-item-db-id'] ) ) { return; } foreach ( self::$fields as $_key => $label ) { $key = sprintf( 'menu-item-%s', $_key ); // Sanitize if ( ! empty( $_POST[ $key ][ $menu_item_db_id ] ) ) { // Do some checks here... $value = is_array( $_POST[ $key ][ $menu_item_db_id ] ) ? array_keys( $_POST[ $key ][ $menu_item_db_id ] ) : $_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 ); } } } /** * @param $columns * * @return array */ function _columns( $columns ) { $columns = array_merge( $columns, self::$fields ); return $columns; } /** * */ function enqueue_nav_menus_scripts() { add_action( 'admin_enqueue_scripts', array( &$this, 'admin_enqueue_scripts' ) ); } /** * */ function admin_enqueue_scripts() { UM()->admin_enqueue()->load_nav_manus_scripts(); $menu_restriction_data = array(); $menus = get_posts( 'post_type=nav_menu_item&numberposts=-1' ); foreach ( $menus as $data ) { $_nav_roles_meta = get_post_meta( $data->ID, 'menu-item-um_nav_roles', true ); $um_nav_roles = array(); if ( $_nav_roles_meta ) { foreach ( $_nav_roles_meta as $key => $value ) { if ( is_int( $key ) ) { $um_nav_roles[] = $value; } } } $menu_restriction_data[ $data->ID ] = array( 'um_nav_public' => get_post_meta( $data->ID, 'menu-item-um_nav_public', true ), 'um_nav_roles' => $um_nav_roles, ); } wp_localize_script( 'um_admin_nav_manus', 'um_menu_restriction_data', $menu_restriction_data ); } /** * */ function _wp_template() { ?>