+case 'inline-save':
+ check_ajax_referer( 'inlineeditnonce', '_inline_edit' );
+
+ if ( ! isset($_POST['post_ID']) || ! ( $post_ID = (int) $_POST['post_ID'] ) )
+ exit;
+
+ if ( 'page' == $_POST['post_type'] ) {
+ if ( ! current_user_can( 'edit_page', $post_ID ) )
+ die( __('You are not allowed to edit this page.') );
+ } else {
+ if ( ! current_user_can( 'edit_post', $post_ID ) )
+ die( __('You are not allowed to edit this post.') );
+ }
+
+ set_current_screen( $_POST['screen'] );
+
+ if ( $last = wp_check_post_lock( $post_ID ) ) {
+ $last_user = get_userdata( $last );
+ $last_user_name = $last_user ? $last_user->display_name : __( 'Someone' );
+ 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 ) );
+ exit;
+ }
+
+ $data = &$_POST;
+
+ $post = get_post( $post_ID, ARRAY_A );
+ $post = add_magic_quotes($post); //since it is from db
+
+ $data['content'] = $post['post_content'];
+ $data['excerpt'] = $post['post_excerpt'];
+
+ // rename
+ $data['user_ID'] = $GLOBALS['user_ID'];
+
+ if ( isset($data['post_parent']) )
+ $data['parent_id'] = $data['post_parent'];
+
+ // status
+ if ( isset($data['keep_private']) && 'private' == $data['keep_private'] )
+ $data['post_status'] = 'private';
+ else
+ $data['post_status'] = $data['_status'];
+
+ if ( empty($data['comment_status']) )
+ $data['comment_status'] = 'closed';
+ if ( empty($data['ping_status']) )
+ $data['ping_status'] = 'closed';
+
+ // update the post
+ edit_post();
+
+ $wp_list_table = _get_list_table('WP_Posts_List_Table');
+
+ $mode = $_POST['post_view'];
+ $wp_list_table->display_rows( array( get_post( $_POST['post_ID'] ) ) );
+
+ exit;
+ break;
+case 'inline-save-tax':
+ check_ajax_referer( 'taxinlineeditnonce', '_inline_edit' );
+
+ $taxonomy = sanitize_key( $_POST['taxonomy'] );
+ $tax = get_taxonomy( $taxonomy );
+ if ( ! $tax )
+ die( '0' );
+
+ if ( ! current_user_can( $tax->cap->edit_terms ) )
+ die( '-1' );
+
+ set_current_screen( 'edit-' . $taxonomy );
+
+ $wp_list_table = _get_list_table('WP_Terms_List_Table');
+
+ if ( ! isset($_POST['tax_ID']) || ! ( $id = (int) $_POST['tax_ID'] ) )
+ die(-1);
+
+ $tag = get_term( $id, $taxonomy );
+ $_POST['description'] = $tag->description;
+
+ $updated = wp_update_term($id, $taxonomy, $_POST);
+ if ( $updated && !is_wp_error($updated) ) {
+ $tag = get_term( $updated['term_id'], $taxonomy );
+ if ( !$tag || is_wp_error( $tag ) ) {
+ if ( is_wp_error($tag) && $tag->get_error_message() )
+ die( $tag->get_error_message() );
+ die( __('Item not updated.') );
+ }
+
+ echo $wp_list_table->single_row( $tag );
+ } else {
+ if ( is_wp_error($updated) && $updated->get_error_message() )
+ die( $updated->get_error_message() );
+ die( __('Item not updated.') );
+ }
+
+ exit;
+ break;
+case 'find_posts':
+ check_ajax_referer( 'find-posts' );
+
+ if ( empty($_POST['ps']) )
+ exit;
+
+ if ( !empty($_POST['post_type']) && in_array( $_POST['post_type'], get_post_types() ) )
+ $what = $_POST['post_type'];
+ else
+ $what = 'post';
+
+ $s = stripslashes($_POST['ps']);
+ preg_match_all('/".*?("|$)|((?<=[\\s",+])|^)[^\\s",+]+/', $s, $matches);
+ $search_terms = array_map('_search_terms_tidy', $matches[0]);
+
+ $searchand = $search = '';
+ foreach ( (array) $search_terms as $term ) {
+ $term = esc_sql( like_escape( $term ) );
+ $search .= "{$searchand}(($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%'))";
+ $searchand = ' AND ';
+ }
+ $term = esc_sql( like_escape( $s ) );
+ if ( count($search_terms) > 1 && $search_terms[0] != $s )
+ $search .= " OR ($wpdb->posts.post_title LIKE '%{$term}%') OR ($wpdb->posts.post_content LIKE '%{$term}%')";
+
+ $posts = $wpdb->get_results( "SELECT ID, post_title, post_status, post_date FROM $wpdb->posts WHERE post_type = '$what' AND post_status IN ('draft', 'publish') AND ($search) ORDER BY post_date_gmt DESC LIMIT 50" );
+
+ if ( ! $posts ) {
+ $posttype = get_post_type_object($what);
+ exit($posttype->labels->not_found);
+ }
+
+ $html = '<table class="widefat" cellspacing="0"><thead><tr><th class="found-radio"><br /></th><th>'.__('Title').'</th><th>'.__('Date').'</th><th>'.__('Status').'</th></tr></thead><tbody>';
+ foreach ( $posts as $post ) {
+
+ switch ( $post->post_status ) {
+ case 'publish' :
+ case 'private' :
+ $stat = __('Published');
+ break;
+ case 'future' :
+ $stat = __('Scheduled');
+ break;
+ case 'pending' :
+ $stat = __('Pending Review');
+ break;
+ case 'draft' :
+ $stat = __('Draft');
+ break;
+ }
+
+ if ( '0000-00-00 00:00:00' == $post->post_date ) {
+ $time = '';
+ } else {
+ /* translators: date format in table columns, see http://php.net/date */
+ $time = mysql2date(__('Y/m/d'), $post->post_date);
+ }
+
+ $html .= '<tr class="found-posts"><td class="found-radio"><input type="radio" id="found-'.$post->ID.'" name="found_post_id" value="' . esc_attr($post->ID) . '"></td>';
+ $html .= '<td><label for="found-'.$post->ID.'">'.esc_html( $post->post_title ).'</label></td><td>'.esc_html( $time ).'</td><td>'.esc_html( $stat ).'</td></tr>'."\n\n";
+ }
+ $html .= '</tbody></table>';
+
+ $x = new WP_Ajax_Response();
+ $x->add( array(
+ 'what' => $what,
+ 'data' => $html
+ ));
+ $x->send();
+
+ break;
+case 'widgets-order' :
+ check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
+
+ if ( !current_user_can('edit_theme_options') )
+ die('-1');
+
+ unset( $_POST['savewidgets'], $_POST['action'] );
+
+ // save widgets order for all sidebars
+ if ( is_array($_POST['sidebars']) ) {
+ $sidebars = array();
+ foreach ( $_POST['sidebars'] as $key => $val ) {
+ $sb = array();
+ if ( !empty($val) ) {
+ $val = explode(',', $val);
+ foreach ( $val as $k => $v ) {
+ if ( strpos($v, 'widget-') === false )
+ continue;
+
+ $sb[$k] = substr($v, strpos($v, '_') + 1);
+ }
+ }
+ $sidebars[$key] = $sb;
+ }
+ wp_set_sidebars_widgets($sidebars);
+ die('1');
+ }
+
+ die('-1');
+ break;
+case 'save-widget' :
+ check_ajax_referer( 'save-sidebar-widgets', 'savewidgets' );
+
+ if ( !current_user_can('edit_theme_options') || !isset($_POST['id_base']) )
+ die('-1');
+
+ unset( $_POST['savewidgets'], $_POST['action'] );
+
+ do_action('load-widgets.php');
+ do_action('widgets.php');
+ do_action('sidebar_admin_setup');
+
+ $id_base = $_POST['id_base'];
+ $widget_id = $_POST['widget-id'];
+ $sidebar_id = $_POST['sidebar'];
+ $multi_number = !empty($_POST['multi_number']) ? (int) $_POST['multi_number'] : 0;
+ $settings = isset($_POST['widget-' . $id_base]) && is_array($_POST['widget-' . $id_base]) ? $_POST['widget-' . $id_base] : false;
+ $error = '<p>' . __('An error has occurred. Please reload the page and try again.') . '</p>';
+
+ $sidebars = wp_get_sidebars_widgets();
+ $sidebar = isset($sidebars[$sidebar_id]) ? $sidebars[$sidebar_id] : array();
+
+ // delete
+ if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
+
+ if ( !isset($wp_registered_widgets[$widget_id]) )
+ die($error);
+
+ $sidebar = array_diff( $sidebar, array($widget_id) );
+ $_POST = array('sidebar' => $sidebar_id, 'widget-' . $id_base => array(), 'the-widget-id' => $widget_id, 'delete_widget' => '1');
+ } elseif ( $settings && preg_match( '/__i__|%i%/', key($settings) ) ) {
+ if ( !$multi_number )
+ die($error);
+
+ $_POST['widget-' . $id_base] = array( $multi_number => array_shift($settings) );
+ $widget_id = $id_base . '-' . $multi_number;
+ $sidebar[] = $widget_id;
+ }
+ $_POST['widget-id'] = $sidebar;
+
+ foreach ( (array) $wp_registered_widget_updates as $name => $control ) {
+
+ if ( $name == $id_base ) {
+ if ( !is_callable( $control['callback'] ) )
+ continue;
+
+ ob_start();
+ call_user_func_array( $control['callback'], $control['params'] );
+ ob_end_clean();
+ break;
+ }
+ }
+
+ if ( isset($_POST['delete_widget']) && $_POST['delete_widget'] ) {
+ $sidebars[$sidebar_id] = $sidebar;
+ wp_set_sidebars_widgets($sidebars);
+ echo "deleted:$widget_id";
+ die();
+ }
+
+ if ( !empty($_POST['add_new']) )
+ die();
+
+ if ( $form = $wp_registered_widget_controls[$widget_id] )
+ call_user_func_array( $form['callback'], $form['params'] );
+
+ die();
+ break;
+case 'image-editor':
+ $attachment_id = intval($_POST['postid']);
+ if ( empty($attachment_id) || !current_user_can('edit_post', $attachment_id) )
+ die('-1');
+
+ check_ajax_referer( "image_editor-$attachment_id" );
+ include_once( ABSPATH . 'wp-admin/includes/image-edit.php' );
+
+ $msg = false;
+ switch ( $_POST['do'] ) {
+ case 'save' :
+ $msg = wp_save_image($attachment_id);
+ $msg = json_encode($msg);
+ die($msg);
+ break;
+ case 'scale' :
+ $msg = wp_save_image($attachment_id);
+ break;
+ case 'restore' :
+ $msg = wp_restore_image($attachment_id);
+ break;
+ }
+
+ wp_image_editor($attachment_id, $msg);
+ die();
+ break;
+case 'set-post-thumbnail':
+ $post_ID = intval( $_POST['post_id'] );
+ if ( !current_user_can( 'edit_post', $post_ID ) )
+ die( '-1' );
+ $thumbnail_id = intval( $_POST['thumbnail_id'] );
+
+ check_ajax_referer( "set_post_thumbnail-$post_ID" );
+
+ if ( $thumbnail_id == '-1' ) {
+ if ( delete_post_thumbnail( $post_ID ) )
+ die( _wp_post_thumbnail_html() );
+ else
+ die( '0' );
+ }
+
+ if ( set_post_thumbnail( $post_ID, $thumbnail_id ) )
+ die( _wp_post_thumbnail_html( $thumbnail_id ) );
+ die( '0' );
+ break;
+case 'date_format' :
+ die( date_i18n( sanitize_option( 'date_format', $_POST['date'] ) ) );
+ break;
+case 'time_format' :
+ die( date_i18n( sanitize_option( 'time_format', $_POST['date'] ) ) );
+ break;
+case 'wp-fullscreen-save-post' :
+ $post_id = isset( $_POST['post_ID'] ) ? (int) $_POST['post_ID'] : 0;
+
+ $post = $post_type = null;
+
+ if ( $post_id )
+ $post = get_post( $post_id );
+
+ if ( $post )
+ $post_type = $post->post_type;
+ elseif ( isset( $_POST['post_type'] ) && post_type_exists( $_POST['post_type'] ) )
+ $post_type = $_POST['post_type'];
+
+ check_ajax_referer('update-' . $post_type . '_' . $post_id, '_wpnonce');
+
+ $post_id = edit_post();
+
+ if ( is_wp_error($post_id) ) {
+ if ( $post_id->get_error_message() )
+ $message = $post_id->get_error_message();
+ else
+ $message = __('Save failed');
+
+ echo json_encode( array( 'message' => $message, 'last_edited' => '' ) );
+ die();
+ } else {
+ $message = __('Saved.');
+ }
+
+ if ( $post ) {
+ $last_date = mysql2date( get_option('date_format'), $post->post_modified );
+ $last_time = mysql2date( get_option('time_format'), $post->post_modified );
+ } else {
+ $last_date = date_i18n( get_option('date_format') );
+ $last_time = date_i18n( get_option('time_format') );
+ }
+
+ if ( $last_id = get_post_meta($post_id, '_edit_last', true) ) {
+ $last_user = get_userdata($last_id);
+ $last_edited = sprintf( __('Last edited by %1$s on %2$s at %3$s'), esc_html( $last_user->display_name ), $last_date, $last_time );
+ } else {
+ $last_edited = sprintf( __('Last edited on %1$s at %2$s'), $last_date, $last_time );
+ }
+
+ echo json_encode( array( 'message' => $message, 'last_edited' => $last_edited ) );
+ die();
+ break;
+case 'wp-remove-post-lock' :
+ if ( empty( $_POST['post_ID'] ) || empty( $_POST['active_post_lock'] ) )
+ die( '0' );
+ $post_id = (int) $_POST['post_ID'];
+ if ( ! $post = get_post( $post_id ) )
+ die( '0' );
+
+ check_ajax_referer( 'update-' . $post->post_type . '_' . $post_id );
+
+ if ( ! current_user_can( 'edit_post', $post_id ) )
+ die( '-1' );
+
+ $active_lock = array_map( 'absint', explode( ':', $_POST['active_post_lock'] ) );
+ if ( $active_lock[1] != get_current_user_id() )
+ die( '0' );
+
+ $new_lock = ( time() - apply_filters( 'wp_check_post_lock_window', AUTOSAVE_INTERVAL * 2 ) + 5 ) . ':' . $active_lock[1];
+ update_post_meta( $post_id, '_edit_lock', $new_lock, implode( ':', $active_lock ) );
+ die( '1' );
+case 'dismiss-wp-pointer' :
+ $pointer = $_POST['pointer'];
+ if ( $pointer != sanitize_key( $pointer ) )
+ die( '0' );
+
+// check_ajax_referer( 'dismiss-pointer_' . $pointer );
+
+ $dismissed = array_filter( explode( ',', (string) get_user_meta( get_current_user_id(), 'dismissed_wp_pointers', true ) ) );
+
+ if ( in_array( $pointer, $dismissed ) )
+ die( '0' );
+
+ $dismissed[] = $pointer;
+ $dismissed = implode( ',', $dismissed );
+
+ update_user_meta( get_current_user_id(), 'dismissed_wp_pointers', $dismissed );
+ die( '1' );
+ break;