Ticket #33187: 33187.2.diff
File 33187.2.diff, 10.1 KB (added by , 10 years ago) |
---|
-
src/wp-admin/nav-menus.php
switch ( $action ) { 342 342 } 343 343 344 344 if ( ! is_wp_error( $_menu_object ) ) { 345 345 $_nav_menu_selected_id = wp_update_nav_menu_object( $nav_menu_selected_id, array( 'menu-name' => $menu_title ) ); 346 346 if ( is_wp_error( $_nav_menu_selected_id ) ) { 347 347 $_menu_object = $_nav_menu_selected_id; 348 348 $messages[] = '<div id="message" class="error notice is-dismissible"><p>' . $_nav_menu_selected_id->get_error_message() . '</p></div>'; 349 349 } else { 350 350 $_menu_object = wp_get_nav_menu_object( $_nav_menu_selected_id ); 351 351 $nav_menu_selected_title = $_menu_object->name; 352 352 } 353 353 } 354 354 355 355 // Update menu items. 356 356 if ( ! is_wp_error( $_menu_object ) ) { 357 $messages = array_merge( $messages, wp_nav_menu_update_menu_items( $nav_menu_selected_id, $nav_menu_selected_title ) ); 357 $messages = array_merge( $messages, wp_nav_menu_update_menu_items( $_nav_menu_selected_id, $nav_menu_selected_title ) ); 358 359 // If the menu ID changed, redirect to the new URL, this will loose all $messages 360 if ( $nav_menu_selected_id != $_nav_menu_selected_id ) { 361 wp_redirect( admin_url( 'nav-menus.php?menu=' . intval( $_nav_menu_selected_id ) ) ); 362 exit(); 363 } 358 364 } 359 365 } 360 366 break; 361 367 case 'locations': 362 368 if ( ! $num_locations ) { 363 369 wp_redirect( admin_url( 'nav-menus.php' ) ); 364 370 exit(); 365 371 } 366 372 367 373 add_filter( 'screen_options_show_screen', '__return_false' ); 368 374 369 375 if ( isset( $_POST['menu-locations'] ) ) { 370 376 check_admin_referer( 'save-menu-locations' ); 371 377 372 378 $new_menu_locations = array_map( 'absint', $_POST['menu-locations'] ); -
src/wp-includes/default-filters.php
add_filter( 'heartbeat_settings', 'wp_he 318 318 319 319 // Check if the user is logged out 320 320 add_action( 'admin_enqueue_scripts', 'wp_auth_check_load' ); 321 321 add_filter( 'heartbeat_send', 'wp_auth_check' ); 322 322 add_filter( 'heartbeat_nopriv_send', 'wp_auth_check' ); 323 323 324 324 // Default authentication filters 325 325 add_filter( 'authenticate', 'wp_authenticate_username_password', 20, 3 ); 326 326 add_filter( 'authenticate', 'wp_authenticate_spam_check', 99 ); 327 327 add_filter( 'determine_current_user', 'wp_validate_auth_cookie' ); 328 328 add_filter( 'determine_current_user', 'wp_validate_logged_in_cookie', 20 ); 329 329 330 330 // Split term updates. 331 331 add_action( 'split_shared_term', '_wp_check_split_default_terms', 10, 4 ); 332 332 add_action( 'split_shared_term', '_wp_check_split_terms_in_menus', 10, 4 ); 333 add_action( 'split_shared_term', '_wp_check_split_nav_menu_terms', 10, 4 ); 333 334 334 335 /** 335 336 * Filters formerly mixed into wp-includes 336 337 */ 337 338 // Theme 338 339 add_action( 'wp_loaded', '_custom_header_background_just_in_time' ); 339 340 add_action( 'plugins_loaded', '_wp_customize_include' ); 340 341 add_action( 'admin_enqueue_scripts', '_wp_customize_loader_settings' ); 341 342 add_action( 'delete_attachment', '_delete_attachment_theme_mod' ); 342 343 343 344 // Calendar widget cache 344 345 add_action( 'save_post', 'delete_get_calendar_cache' ); 345 346 add_action( 'delete_post', 'delete_get_calendar_cache' ); 346 347 add_action( 'update_option_start_of_week', 'delete_get_calendar_cache' ); 347 348 add_action( 'update_option_gmt_offset', 'delete_get_calendar_cache' ); -
src/wp-includes/nav-menu.php
function wp_update_nav_menu_object( $men 299 299 * 300 300 * @param int $term_id ID of the new menu. 301 301 * @param array $menu_data An array of menu data. 302 302 */ 303 303 do_action( 'wp_create_nav_menu', $_menu['term_id'], $menu_data ); 304 304 305 305 return (int) $_menu['term_id']; 306 306 } 307 307 308 308 if ( ! $_menu || ! isset( $_menu->term_id ) ) 309 309 return 0; 310 310 311 311 $menu_id = (int) $_menu->term_id; 312 312 313 313 $update_response = wp_update_term( $menu_id, 'nav_menu', $args ); 314 $menu_id = (int) $update_response['term_id']; 314 315 315 316 if ( is_wp_error( $update_response ) ) 316 317 return $update_response; 317 318 318 319 /** 319 320 * Fires after a navigation menu has been successfully updated. 320 321 * 321 322 * @since 3.0.0 322 323 * 323 324 * @param int $menu_id ID of the updated menu. 324 325 * @param array $menu_data An array of menu data. 325 326 */ 326 327 do_action( 'wp_update_nav_menu', $menu_id, $menu_data ); 327 328 return $menu_id; 328 329 } -
src/wp-includes/taxonomy.php
function _wp_check_split_terms_in_menus( 4384 4384 WHERE ( m1.meta_key = '_menu_item_type' AND m1.meta_value = 'taxonomy' ) 4385 4385 AND ( m2.meta_key = '_menu_item_object' AND m2.meta_value = '%s' ) 4386 4386 AND ( m3.meta_key = '_menu_item_object_id' AND m3.meta_value = %d )", 4387 4387 $taxonomy, 4388 4388 $term_id 4389 4389 ) ); 4390 4390 4391 4391 if ( $post_ids ) { 4392 4392 foreach ( $post_ids as $post_id ) { 4393 4393 update_post_meta( $post_id, '_menu_item_object_id', $new_term_id, $term_id ); 4394 4394 } 4395 4395 } 4396 4396 } 4397 4397 4398 4398 /** 4399 * If the term being split is a nav_menu, change associations. 4400 * 4401 * @ignore 4402 * @since 4.3.0 4403 * 4404 * @global wpdb $wpdb 4405 * 4406 * @param int $term_id ID of the formerly shared term. 4407 * @param int $new_term_id ID of the new term created for the $term_taxonomy_id. 4408 * @param int $term_taxonomy_id ID for the term_taxonomy row affected by the split. 4409 * @param string $taxonomy Taxonomy for the split term. 4410 */ 4411 function _wp_check_split_nav_menu_terms( $term_id, $new_term_id, $term_taxonomy_id, $taxonomy ) { 4412 if ( 'nav_menu' !== $taxonomy ) { 4413 return; 4414 } 4415 4416 // Update menu locations. 4417 $locations = get_nav_menu_locations(); 4418 foreach ( $locations as $location => $menu_id ) { 4419 if ( $term_id == $menu_id ) { 4420 $locations[ $location ] = $new_term_id; 4421 } 4422 } 4423 set_theme_mod( 'nav_menu_locations', $locations ); 4424 } 4425 4426 /** 4399 4427 * Get data about terms that previously shared a single term_id, but have since been split. 4400 4428 * 4401 4429 * @since 4.2.0 4402 4430 * 4403 4431 * @param int $old_term_id Term ID. This is the old, pre-split term ID. 4404 4432 * @return array Array of new term IDs, keyed by taxonomy. 4405 4433 */ 4406 4434 function wp_get_split_terms( $old_term_id ) { 4407 4435 $split_terms = get_option( '_split_terms', array() ); 4408 4436 4409 4437 $terms = array(); 4410 4438 if ( isset( $split_terms[ $old_term_id ] ) ) { 4411 4439 $terms = $split_terms[ $old_term_id ]; 4412 4440 } 4413 4441 -
tests/phpunit/tests/term/splitSharedTerm.php
class Tests_Term_SplitSharedTerm extends 183 183 184 184 $menu_id = wp_create_nav_menu( rand_str() ); 185 185 $cat_menu_item = wp_update_nav_menu_item( $menu_id, 0, array( 186 186 'menu-item-type' => 'taxonomy', 187 187 'menu-item-object' => 'category', 188 188 'menu-item-object-id' => $t1['term_id'], 189 189 'menu-item-status' => 'publish' 190 190 ) ); 191 191 $this->assertEquals( $t1['term_id'], get_post_meta( $cat_menu_item, '_menu_item_object_id', true ) ); 192 192 193 193 $new_term_id = _split_shared_term( $t1['term_id'], $t1['term_taxonomy_id'] ); 194 194 $this->assertNotEquals( $new_term_id, $t1['term_id'] ); 195 195 $this->assertEquals( $new_term_id, get_post_meta( $cat_menu_item, '_menu_item_object_id', true ) ); 196 196 } 197 197 198 /** 199 * @ticket 33187 200 * @group navmenus 201 */ 202 public function test_nav_menu_locations_should_be_updated_on_split() { 203 global $wpdb; 204 205 $cat_term = wp_insert_term( 'Foo Menu', 'category' ); 206 $shared_term_id = $cat_term['term_id']; 207 208 $nav_term_id = wp_create_nav_menu( 'Foo Menu' ); 209 $nav_term = get_term( $nav_term_id, 'nav_menu' ); 210 211 // Manually modify because shared terms shouldn't naturally occur. 212 $wpdb->update( $wpdb->term_taxonomy, 213 array( 'term_id' => $shared_term_id ), 214 array( 'term_taxonomy_id' => $nav_term->term_taxonomy_id ) 215 ); 216 217 set_theme_mod( 'nav_menu_locations', array( 'foo' => $shared_term_id ) ); 218 219 // Splitsville. 220 $new_term_id = _split_shared_term( $shared_term_id, $nav_term->term_taxonomy_id ); 221 222 $locations = get_nav_menu_locations(); 223 $this->assertEquals( $new_term_id, $locations['foo'] ); 224 } 225 226 /** 227 * @ticket 33187 228 * @group navmenus 229 */ 230 public function test_nav_menu_term_should_retain_menu_items_on_split() { 231 global $wpdb; 232 233 $cat_term = wp_insert_term( 'Foo Menu', 'category' ); 234 $shared_term_id = $cat_term['term_id']; 235 236 $nav_term_id = wp_create_nav_menu( 'Foo Menu' ); 237 $nav_term = get_term( $nav_term_id, 'nav_menu' ); 238 239 // Manually modify because shared terms shouldn't naturally occur. 240 $wpdb->update( $wpdb->term_taxonomy, 241 array( 'term_id' => $shared_term_id ), 242 array( 'term_taxonomy_id' => $nav_term->term_taxonomy_id ) 243 ); 244 245 $t1 = wp_insert_term( 'Random term', 'category' ); 246 $cat_menu_item = wp_update_nav_menu_item( $shared_term_id, 0, array( 247 'menu-item-type' => 'taxonomy', 248 'menu-item-object' => 'category', 249 'menu-item-object-id' => $t1['term_id'], 250 'menu-item-status' => 'publish' 251 ) ); 252 253 // Updating the menu will split the shared term. 254 $new_nav_menu_id = wp_update_nav_menu_object( $shared_term_id, array( 255 'description' => 'Updated Foo Menu', 256 'menu-name' => 'Updated Foo Menu', 257 ) ); 258 259 $menu = wp_get_nav_menu_object( $new_nav_menu_id ); 260 $this->assertSame( 'Updated Foo Menu', $menu->name ); 261 $this->assertSame( 'Updated Foo Menu', $menu->description ); 262 263 $menu_items = wp_get_nav_menu_items( $new_nav_menu_id ); 264 $this->assertEquals( array( $cat_menu_item ), wp_list_pluck( $menu_items, 'ID' ) ); 265 } 266 198 267 public function test_wp_get_split_terms() { 199 268 $found = wp_get_split_terms( $this->terms['t1']['term_id'] ); 200 269 201 270 $expected = array( 202 271 'wptests_tax_2' => $this->terms['t2']['term_id'], 203 272 'wptests_tax_3' => $this->terms['t3']['term_id'], 204 273 ); 205 274 206 275 $this->assertEqualSets( $expected, $found ); 207 276 } 208 277 209 278 public function test_wp_get_split_term() { 210 279 $found = wp_get_split_term( $this->terms['t1']['term_id'], 'wptests_tax_3' ); 211 280 $this->assertEquals( $this->terms['t3']['term_id'], $found ); 212 281 }