| | 959 | /** |
| | 960 | * Tests `wp_update_nav_menu_item()` with special characters in a category name. |
| | 961 | * |
| | 962 | * When inserting a category as a nav item, the `$args['menu-item-title']` should |
| | 963 | * always be empty as it should get the title from the category object itself. |
| | 964 | * |
| | 965 | * @ticket 48011 |
| | 966 | */ |
| | 967 | function test_wp_update_nav_menu_item_with_special_character_in_categories() { |
| | 968 | |
| | 969 | $category_name = 'Test Cat - \"Pre-Slashed\" Cat Name & >'; |
| | 970 | |
| | 971 | $cat = self::factory()->category->create_and_get( |
| | 972 | array( |
| | 973 | 'name' => $category_name, |
| | 974 | ) |
| | 975 | ); |
| | 976 | |
| | 977 | add_action( 'wp_update_nav_menu_item', array( $this, '_callback_wp_update_nav_menu_item_48011' ), 10, 3 ); |
| | 978 | |
| | 979 | $id = wp_update_nav_menu_item( |
| | 980 | $this->menu_id, |
| | 981 | 0, |
| | 982 | array( |
| | 983 | 'menu-item-type' => 'taxonomy', |
| | 984 | 'menu-item-object' => 'category', |
| | 985 | 'menu-item-object-id' => $cat->term_id, |
| | 986 | 'menu-item-status' => 'publish', |
| | 987 | 'menu-item-title' => $category_name, // Interesting enough, if we use `$cat->name` we won't be able to |
| | 988 | // replicate the bug because it's in htmlentities form. |
| | 989 | ) |
| | 990 | ); |
| | 991 | } |
| | 992 | |
| | 993 | /** |
| | 994 | * Callback for the `wp_update_nav_menu_item` action. |
| | 995 | * |
| | 996 | * @since 5.4.0 |
| | 997 | */ |
| | 998 | function _callback_wp_update_nav_menu_item_48011( $menu_id, $menu_item_db_id, $args ) { |
| | 999 | $this->assertEmpty( $args['menu-item-title'] ); |
| | 1000 | } |