Changeset 52079 for trunk/src/wp-includes/nav-menu.php
- Timestamp:
- 11/09/2021 06:58:59 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/nav-menu.php
r51301 r52079 407 407 * Save the properties of a menu item or create a new one. 408 408 * 409 * The menu-item-title, menu-item-description, and menu-item-attr-title are expected 410 * to be pre-slashed since they are passed directly into `wp_insert_post()`. 411 * 412 * @since 3.0.0 409 * The menu-item-title, menu-item-description, menu-item-attr-title, and menu-item-content are expected 410 * to be pre-slashed since they are passed directly to APIs that expect slashed data. 411 * 412 * @since 3.0.0 413 * @since 5.9.0 Added the menu-item-content parameter. 413 414 * 414 415 * @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a draft orphan. … … 449 450 'menu-item-target' => '', 450 451 'menu-item-classes' => '', 452 'menu-item-content' => '', 451 453 'menu-item-xfn' => '', 452 454 'menu-item-status' => '', … … 527 529 $post['ID'] = 0; 528 530 $post['post_status'] = 'publish' === $args['menu-item-status'] ? 'publish' : 'draft'; 529 $menu_item_db_id = wp_insert_post( $post );531 $menu_item_db_id = wp_insert_post( $post, true ); 530 532 if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) ) { 531 533 return $menu_item_db_id; … … 549 551 // Only set the menu term if it isn't set to avoid unnecessary wp_get_object_terms(). 550 552 if ( $menu_id && ( ! $update || ! is_object_in_term( $menu_item_db_id, 'nav_menu', (int) $menu->term_id ) ) ) { 551 wp_set_object_terms( $menu_item_db_id, array( $menu->term_id ), 'nav_menu' ); 553 $update_terms = wp_set_object_terms( $menu_item_db_id, array( $menu->term_id ), 'nav_menu' ); 554 if ( is_wp_error( $update_terms ) ) { 555 return $update_terms; 556 } 552 557 } 553 558 … … 570 575 update_post_meta( $menu_item_db_id, '_menu_item_xfn', $args['menu-item-xfn'] ); 571 576 update_post_meta( $menu_item_db_id, '_menu_item_url', esc_url_raw( $args['menu-item-url'] ) ); 577 update_post_meta( $menu_item_db_id, '_menu_item_content', $args['menu-item-content'] ); 572 578 573 579 if ( 0 == $menu_id ) { … … 581 587 $post['ID'] = $menu_item_db_id; 582 588 $post['post_status'] = ( 'draft' === $args['menu-item-status'] ) ? 'draft' : 'publish'; 583 wp_update_post( $post ); 589 590 $update_post = wp_update_post( $post, true ); 591 if ( is_wp_error( $update_post ) ) { 592 return $update_post; 593 } 584 594 } 585 595 … … 904 914 $menu_item->title = ( '' === $menu_item->post_title ) ? $original_title : $menu_item->post_title; 905 915 916 } elseif ( 'block' === $menu_item->type ) { 917 $menu_item->type_label = __( 'Block' ); 918 $menu_item->title = $menu_item->post_title; 919 $menu_item->menu_item_content = ! isset( $menu_item->menu_item_content ) ? get_post_meta( $menu_item->ID, '_menu_item_content', true ) : $menu_item->menu_item_content; 906 920 } else { 907 921 $menu_item->type_label = __( 'Custom Link' );
Note: See TracChangeset
for help on using the changeset viewer.