Changeset 52276
- Timestamp:
- 11/30/2021 01:08:05 AM (3 years ago)
- Location:
- trunk/src/wp-includes
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/nav-menu.php
r52184 r52276 411 411 * 412 412 * @since 3.0.0 413 * @since 5.9.0 Added the `$fire_after_hooks` parameter. 413 414 * 414 415 * @param int $menu_id The ID of the menu. Required. If "0", makes the menu item a draft orphan. 415 416 * @param int $menu_item_db_id The ID of the menu item. If "0", creates a new menu item. 416 417 * @param array $menu_item_data The menu item's data. 418 * @param bool $fire_after_hooks Whether to fire the after insert hooks. Default true. 417 419 * @return int|WP_Error The menu item's database ID or WP_Error object on failure. 418 420 */ 419 function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array() ) {421 function wp_update_nav_menu_item( $menu_id = 0, $menu_item_db_id = 0, $menu_item_data = array(), $fire_after_hooks = true ) { 420 422 $menu_id = (int) $menu_id; 421 423 $menu_item_db_id = (int) $menu_item_db_id; … … 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, true );531 $menu_item_db_id = wp_insert_post( $post, true, $fire_after_hooks ); 530 532 if ( ! $menu_item_db_id || is_wp_error( $menu_item_db_id ) ) { 531 533 return $menu_item_db_id; -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-global-styles-controller.php
r52275 r52276 147 147 */ 148 148 public function update_item( $request ) { 149 $post = get_post( $request['id'] );150 if ( ! $post || 'wp_global_styles' !== $post->post_type ) {149 $post_before = get_post( $request['id'] ); 150 if ( ! $post_before || 'wp_global_styles' !== $post_before->post_type ) { 151 151 return new WP_Error( 'rest_global_styles_not_found', __( 'No global styles config exist with that id.' ), array( 'status' => 404 ) ); 152 152 } 153 153 154 154 $changes = $this->prepare_item_for_database( $request ); 155 $result = wp_update_post( wp_slash( (array) $changes ), true );155 $result = wp_update_post( wp_slash( (array) $changes ), true, false ); 156 156 if ( is_wp_error( $result ) ) { 157 157 return $result; … … 164 164 } 165 165 166 return $this->prepare_item_for_response( 167 get_post( $request['id'] ), 168 $request 169 ); 166 wp_after_insert_post( $post, true, $post_before ); 167 168 $response = $this->prepare_item_for_response( $post, $request ); 169 170 return rest_ensure_response( $response ); 170 171 } 171 172 -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php
r52184 r52276 123 123 $prepared_nav_item = (array) $prepared_nav_item; 124 124 125 $nav_menu_item_id = wp_update_nav_menu_item( $prepared_nav_item['menu-id'], $prepared_nav_item['menu-item-db-id'], wp_slash( $prepared_nav_item ) );125 $nav_menu_item_id = wp_update_nav_menu_item( $prepared_nav_item['menu-id'], $prepared_nav_item['menu-item-db-id'], wp_slash( $prepared_nav_item ), false ); 126 126 if ( is_wp_error( $nav_menu_item_id ) ) { 127 127 if ( 'db_insert_error' === $nav_menu_item_id->get_error_code() ) { … … 182 182 do_action( 'rest_after_insert_nav_menu_item', $nav_menu_item, $request, true ); 183 183 184 $response = $this->prepare_item_for_response( get_post( $nav_menu_item_id ), $request ); 184 $post = get_post( $nav_menu_item_id ); 185 wp_after_insert_post( $post, false, null ); 186 187 $response = $this->prepare_item_for_response( $post, $request ); 185 188 $response = rest_ensure_response( $response ); 186 189 … … 205 208 return $valid_check; 206 209 } 207 210 $post_before = get_post( $request['id'] ); 208 211 $prepared_nav_item = $this->prepare_item_for_database( $request ); 209 212 … … 214 217 $prepared_nav_item = (array) $prepared_nav_item; 215 218 216 $nav_menu_item_id = wp_update_nav_menu_item( $prepared_nav_item['menu-id'], $prepared_nav_item['menu-item-db-id'], wp_slash( $prepared_nav_item ) );219 $nav_menu_item_id = wp_update_nav_menu_item( $prepared_nav_item['menu-id'], $prepared_nav_item['menu-item-db-id'], wp_slash( $prepared_nav_item ), false ); 217 220 218 221 if ( is_wp_error( $nav_menu_item_id ) ) { … … 246 249 } 247 250 251 $post = get_post( $nav_menu_item_id ); 248 252 $nav_menu_item = $this->get_nav_menu_item( $nav_menu_item_id ); 249 253 $fields_update = $this->update_additional_fields_for_object( $nav_menu_item, $request ); … … 257 261 /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-menu-items-controller.php */ 258 262 do_action( 'rest_after_insert_nav_menu_item', $nav_menu_item, $request, false ); 263 264 wp_after_insert_post( $post, true, $post_before ); 259 265 260 266 $response = $this->prepare_item_for_response( get_post( $nav_menu_item_id ), $request ); -
trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-templates-controller.php
r52275 r52276 267 267 } 268 268 269 $post_before = get_post( $template->wp_id ); 270 269 271 if ( isset( $request['source'] ) && 'theme' === $request['source'] ) { 270 272 wp_delete_post( $template->wp_id, true ); … … 284 286 285 287 if ( 'custom' === $template->source ) { 286 $result = wp_update_post( wp_slash( (array) $changes ), true ); 288 $update = true; 289 $result = wp_update_post( wp_slash( (array) $changes ), false ); 287 290 } else { 288 $result = wp_insert_post( wp_slash( (array) $changes ), true ); 291 $update = false; 292 $post_before = null; 293 $result = wp_insert_post( wp_slash( (array) $changes ), false ); 289 294 } 290 295 … … 309 314 /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */ 310 315 do_action( "rest_after_insert_{$this->post_type}", $post, $request, false ); 316 317 wp_after_insert_post( $post, $update, $post_before ); 311 318 312 319 $response = $this->prepare_item_for_response( $template, $request ); … … 367 374 /** This action is documented in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php */ 368 375 do_action( "rest_after_insert_{$this->post_type}", $post, $request, true ); 376 377 wp_after_insert_post( $post, false, null ); 369 378 370 379 $response = $this->prepare_item_for_response( $template, $request );
Note: See TracChangeset
for help on using the changeset viewer.