Changeset 1245471
- Timestamp:
- 09/14/2015 09:35:10 PM (11 years ago)
- File:
-
- 1 edited
-
storyform/trunk/class-storyform-editor-page.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
storyform/trunk/class-storyform-editor-page.php
r1242929 r1245471 128 128 129 129 public function storyform_get_post(){ 130 global $wp_query; 130 131 check_ajax_referer( 'storyform-post-nonce' ); 131 132 $id = sanitize_text_field( $_POST['id'] ); 132 $post = get_post( $id )->to_array(); 133 134 // Setup main loop to establish is_single() + is_page() for the_content filters to read 135 $wp_query = new WP_Query( array( 'p' => $id, 'post_type' => 'any' ) ); 136 if( $wp_query->have_posts() ) { 137 while ( $wp_query->have_posts() ) { 138 $wp_query->the_post(); 139 } 140 } 141 global $post; 142 $wp_query->is_page = ($post->post_type === 'page'); // Doesn't do this automatically on return 143 $data = $post->to_array(); 133 144 134 145 // If published, grab the latest revision as there may be some unpublished changes 135 if( $ post['post_status'] === 'publish' ){146 if( $data['post_status'] === 'publish' ){ 136 147 $array = array_values( wp_get_post_revisions( $id ) ); 137 148 138 149 if( count( $array ) ){ 139 150 $revision = $array[0]->to_array(); 140 $ post['post_content'] = $revision['post_content'];141 $ post['post_title'] = $revision['post_title'];142 $ post['post_excerpt'] = $revision['post_excerpt'];143 $ post['unpublished_changes'] = true;144 } 145 } 146 147 $ post['post_content'] = apply_filters( 'the_content', $post['post_content'] );148 $ post['template'] = Storyform_Options::get_instance()->get_template_for_post( $id );149 $ post['byline'] = get_userdata( $post['post_author'])->display_name;150 $ post['display_date'] = get_the_date( get_option('date_format'), $post);151 152 echo json_encode( $ post);151 $data['post_content'] = $revision['post_content']; 152 $data['post_title'] = $revision['post_title']; 153 $data['post_excerpt'] = $revision['post_excerpt']; 154 $data['unpublished_changes'] = true; 155 } 156 } 157 158 $data['post_content'] = apply_filters( 'the_content', $data['post_content'] ); 159 $data['template'] = Storyform_Options::get_instance()->get_template_for_post( $id ); 160 $data['byline'] = get_userdata( $data['post_author'])->display_name; 161 $data['display_date'] = get_the_date( get_option('date_format'), $data ); 162 163 echo json_encode( $data ); 153 164 154 165 die();
Note: See TracChangeset
for help on using the changeset viewer.