Changeset 13536
- Timestamp:
- 07/30/2023 07:30:39 AM (18 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/bp-core/bp-core-update.php
r13533 r13536 802 802 * 803 803 * - Swith directory page post type from "page" to "buddypress". 804 * - Remove Legacy Widgets option. 805 * - Add the default community visibility value. 804 806 * 805 807 * @since 12.0.0 806 808 */ 807 809 function bp_update_to_12_0() { 808 $post_type = bp_core_get_directory_post_type(); 809 810 if ( 'page' !== $post_type ) { 811 $directory_pages = bp_core_get_directory_pages(); 812 $nav_menu_item_ids = array(); 813 814 // Do not check post slugs nor post types. 815 remove_filter( 'wp_unique_post_slug', 'bp_core_set_unique_directory_page_slug', 10 ); 816 817 // Update Directory pages post types. 818 foreach ( $directory_pages as $directory_page ) { 819 $nav_menu_item_ids[] = $directory_page->id; 820 821 // Switch the post type. 822 wp_update_post( 823 array( 824 'ID' => $directory_page->id, 825 'post_type' => $post_type, 826 'post_status' => 'publish', 827 ) 828 ); 829 } 830 831 // Update nav menu items! 832 $nav_menus = wp_get_nav_menus( array( 'hide_empty' => true ) ); 833 foreach ( $nav_menus as $nav_menu ) { 834 $items = wp_get_nav_menu_items( $nav_menu->term_id ); 835 foreach ( $items as $item ) { 836 if ( 'page' !== $item->object || ! in_array( $item->object_id, $nav_menu_item_ids, true ) ) { 837 continue; 838 } 839 840 wp_update_nav_menu_item( 841 $nav_menu->term_id, 842 $item->ID, 810 /* 811 * Only perform the BP Rewrites API & Legacy Widgets upgrade tasks 812 * when the BP Classic plugin is not active. 813 */ 814 if ( ! function_exists( 'bp_classic' ) ) { 815 $post_type = bp_core_get_directory_post_type(); 816 817 if ( 'page' !== $post_type ) { 818 $directory_pages = bp_core_get_directory_pages(); 819 $nav_menu_item_ids = array(); 820 821 // Do not check post slugs nor post types. 822 remove_filter( 'wp_unique_post_slug', 'bp_core_set_unique_directory_page_slug', 10 ); 823 824 // Update Directory pages post types. 825 foreach ( $directory_pages as $directory_page ) { 826 $nav_menu_item_ids[] = $directory_page->id; 827 828 // Switch the post type. 829 wp_update_post( 843 830 array( 844 'menu-item-db-id' => $item->db_id, 845 'menu-item-object-id' => $item->object_id, 846 'menu-item-object' => $post_type, 847 'menu-item-parent-id' => $item->menu_item_parent, 848 'menu-item-position' => $item->menu_order, 849 'menu-item-type' => 'post_type', 850 'menu-item-title' => $item->title, 851 'menu-item-url' => $item->url, 852 'menu-item-description' => $item->description, 853 'menu-item-attr-title' => $item->attr_title, 854 'menu-item-target' => $item->target, 855 'menu-item-classes' => implode( ' ', (array) $item->classes ), 856 'menu-item-xfn' => $item->xfn, 857 'menu-item-status' => 'publish', 831 'ID' => $directory_page->id, 832 'post_type' => $post_type, 833 'post_status' => 'publish', 858 834 ) 859 835 ); 860 836 } 861 } 862 863 // Finally make sure to rebuilt permalinks at next page load. 864 bp_delete_rewrite_rules(); 865 } 866 867 // Widgets. 868 $widget_options = array( 869 'widget_bp_core_login_widget', 870 'widget_bp_core_members_widget', 871 'widget_bp_core_whos_online_widget', 872 'widget_bp_core_recently_active_widget', 873 'widget_bp_groups_widget', 874 'widget_bp_messages_sitewide_notices_widget', 875 ); 876 877 foreach ( $widget_options as $widget_option ) { 878 bp_delete_option( $widget_option ); 837 838 // Update nav menu items! 839 $nav_menus = wp_get_nav_menus( array( 'hide_empty' => true ) ); 840 foreach ( $nav_menus as $nav_menu ) { 841 $items = wp_get_nav_menu_items( $nav_menu->term_id ); 842 foreach ( $items as $item ) { 843 if ( 'page' !== $item->object || ! in_array( $item->object_id, $nav_menu_item_ids, true ) ) { 844 continue; 845 } 846 847 wp_update_nav_menu_item( 848 $nav_menu->term_id, 849 $item->ID, 850 array( 851 'menu-item-db-id' => $item->db_id, 852 'menu-item-object-id' => $item->object_id, 853 'menu-item-object' => $post_type, 854 'menu-item-parent-id' => $item->menu_item_parent, 855 'menu-item-position' => $item->menu_order, 856 'menu-item-type' => 'post_type', 857 'menu-item-title' => $item->title, 858 'menu-item-url' => $item->url, 859 'menu-item-description' => $item->description, 860 'menu-item-attr-title' => $item->attr_title, 861 'menu-item-target' => $item->target, 862 'menu-item-classes' => implode( ' ', (array) $item->classes ), 863 'menu-item-xfn' => $item->xfn, 864 'menu-item-status' => 'publish', 865 ) 866 ); 867 } 868 } 869 870 // Finally make sure to rebuilt permalinks at next page load. 871 bp_delete_rewrite_rules(); 872 } 873 874 // Widgets. 875 $widget_options = array( 876 'widget_bp_core_login_widget', 877 'widget_bp_core_members_widget', 878 'widget_bp_core_whos_online_widget', 879 'widget_bp_core_recently_active_widget', 880 'widget_bp_groups_widget', 881 'widget_bp_messages_sitewide_notices_widget', 882 ); 883 884 foreach ( $widget_options as $widget_option ) { 885 bp_delete_option( $widget_option ); 886 } 879 887 } 880 888 881 889 // Community visibility. 882 890 bp_update_option( '_bp_community_visibility', array( 'global' => 'anyone' ) ); 891 892 /** 893 * Fires once BuddyPress achieved 12.0 upgrading tasks. 894 * 895 * @since 12.0.0 896 */ 897 do_action( 'bp_updated_to_12_0' ); 883 898 } 884 899
Note: See TracChangeset
for help on using the changeset viewer.