wp_ajax_inline_save

Ajax handler for Quick Edit saving a post from a list table.

Description

wp_ajax_inline_save(); 

Usage

  1. if ( !function_exists( 'wp_ajax_inline_save' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/ajax-actions.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_ajax_inline_save(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/ajax-actions.php  
  1. function wp_ajax_inline_save() { 
  2. global $mode; 
  3.  
  4. check_ajax_referer( 'inlineeditnonce', '_inline_edit' ); 
  5.  
  6. if ( ! isset($_POST['post_ID']) || ! ( $post_ID = (int) $_POST['post_ID'] ) ) 
  7. wp_die(); 
  8.  
  9. if ( 'page' == $_POST['post_type'] ) { 
  10. if ( ! current_user_can( 'edit_page', $post_ID ) ) 
  11. wp_die( __( 'Sorry, you are not allowed to edit this page.' ) ); 
  12. } else { 
  13. if ( ! current_user_can( 'edit_post', $post_ID ) ) 
  14. wp_die( __( 'Sorry, you are not allowed to edit this post.' ) ); 
  15.  
  16. if ( $last = wp_check_post_lock( $post_ID ) ) { 
  17. $last_user = get_userdata( $last ); 
  18. $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' ); 
  19. printf( $_POST['post_type'] == 'page' ? __( 'Saving is disabled: %s is currently editing this page.' ) : __( 'Saving is disabled: %s is currently editing this post.' ), esc_html( $last_user_name ) ); 
  20. wp_die(); 
  21.  
  22. $data = &$_POST; 
  23.  
  24. $post = get_post( $post_ID, ARRAY_A ); 
  25.  
  26. // Since it's coming from the database. 
  27. $post = wp_slash($post); 
  28.  
  29. $data['content'] = $post['post_content']; 
  30. $data['excerpt'] = $post['post_excerpt']; 
  31.  
  32. // Rename. 
  33. $data['user_ID'] = get_current_user_id(); 
  34.  
  35. if ( isset($data['post_parent']) ) 
  36. $data['parent_id'] = $data['post_parent']; 
  37.  
  38. // Status. 
  39. if ( isset( $data['keep_private'] ) && 'private' == $data['keep_private'] ) { 
  40. $data['visibility'] = 'private'; 
  41. $data['post_status'] = 'private'; 
  42. } else { 
  43. $data['post_status'] = $data['_status']; 
  44.  
  45. if ( empty($data['comment_status']) ) 
  46. $data['comment_status'] = 'closed'; 
  47. if ( empty($data['ping_status']) ) 
  48. $data['ping_status'] = 'closed'; 
  49.  
  50. // Exclude terms from taxonomies that are not supposed to appear in Quick Edit. 
  51. if ( ! empty( $data['tax_input'] ) ) { 
  52. foreach ( $data['tax_input'] as $taxonomy => $terms ) { 
  53. $tax_object = get_taxonomy( $taxonomy ); 
  54. /** This filter is documented in wp-admin/includes/class-wp-posts-list-table.php */ 
  55. if ( ! apply_filters( 'quick_edit_show_taxonomy', $tax_object->show_in_quick_edit, $taxonomy, $post['post_type'] ) ) { 
  56. unset( $data['tax_input'][ $taxonomy ] ); 
  57.  
  58. // Hack: wp_unique_post_slug() doesn't work for drafts, so we will fake that our post is published. 
  59. if ( ! empty( $data['post_name'] ) && in_array( $post['post_status'], array( 'draft', 'pending' ) ) ) { 
  60. $post['post_status'] = 'publish'; 
  61. $data['post_name'] = wp_unique_post_slug( $data['post_name'], $post['ID'], $post['post_status'], $post['post_type'], $post['post_parent'] ); 
  62.  
  63. // Update the post. 
  64. edit_post(); 
  65.  
  66. $wp_list_table = _get_list_table( 'WP_Posts_List_Table', array( 'screen' => $_POST['screen'] ) ); 
  67.  
  68. $mode = $_POST['post_view'] === 'excerpt' ? 'excerpt' : 'list'; 
  69.  
  70. $level = 0; 
  71. if ( is_post_type_hierarchical( $wp_list_table->screen->post_type ) ) { 
  72. $request_post = array( get_post( $_POST['post_ID'] ) ); 
  73. $parent = $request_post[0]->post_parent; 
  74.  
  75. while ( $parent > 0 ) { 
  76. $parent_post = get_post( $parent ); 
  77. $parent = $parent_post->post_parent; 
  78. $level++; 
  79.  
  80. $wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ), $level ); 
  81.  
  82. wp_die();