Changeset 1105717
- Timestamp:
- 03/05/2015 05:17:58 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
storyform/trunk/class-storyform-admin-meta-box.php
r1105500 r1105717 8 8 9 9 public static function init() { 10 add_action( 'content_save_pre', array( __CLASS__, 'save_add_remove_attributes' ) ); 10 11 add_action( 'save_post', array( __CLASS__, 'save_meta_box_data' ) ); 11 12 add_action( 'load-post.php', array( __CLASS__, 'post_meta_boxes_setup' ) ); … … 190 191 $id = intval( $post_id ); 191 192 $template = sanitize_text_field( $_POST['storyform-templates'] ); 192 $template = ( $template == 'pthemedefault' ) ? null : $template;193 $template = ( $template == 'pthemedefault' ) ? null : $template; 193 194 $name = sanitize_text_field( strtolower( $_POST['post_name'] ) ); 195 194 196 $layout_type = $template ? sanitize_text_field( strtolower( $_POST['storyform-layout-type'] ) ) : null; 195 197 $use_featured_image = $template ? isset( $_POST['storyform-use-featured-image'] ) && $_POST['storyform-use-featured-image'] === 'on' : true; 198 196 199 $ab = isset( $_POST['storyform-ab'] ); 197 200 … … 201 204 $options->update_layout_type_for_post( $id, $layout_type ); 202 205 $options->update_use_featured_image_for_post( $id, $use_featured_image ); 203 204 // Avoid infinite loop by removing save_post hook temporarily 205 remove_action( 'save_post', array( __CLASS__, 'save_meta_box_data' ) ); 206 } 207 208 /** 209 * Adds and removes data- attributes as Storyform is turned off and on on a post. 210 * 211 * @param string $content The content of a post 212 */ 213 public static function save_add_remove_attributes( $content ) { 214 global $post; 215 global $_POST; 216 global $storyform_media; 217 218 if( !is_object($post) || !$post->ID ){ 219 return; 220 } 221 222 $post_id = $post->ID; 223 224 // If this is an autosave, our form has not been submitted, so we don't want to do anything. 225 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 226 return $content; 227 } 228 229 // If this is a revision, don't do anything 230 if ( wp_is_post_revision( $post_id ) ) { 231 return $content; 232 } 233 234 // Check the user's permissions. 235 if ( isset( $_POST['post_type'] ) && 'page' == $_POST['post_type'] ) { 236 237 if ( ! current_user_can( 'edit_page', $post_id ) ) { 238 return $content; 239 } 240 241 } else { 242 243 if ( ! current_user_can( 'edit_post', $post_id ) ) { 244 return $content; 245 } 246 } 247 248 // Make sure that it is set. 249 if ( ! isset( $_POST['storyform-templates'] ) ) { 250 return $content; 251 } 252 253 // Read POST as we may be changing the value 254 $template = sanitize_text_field( $_POST['storyform-templates'] ); 255 $template = ( $template == 'pthemedefault' ) ? null : $template; 256 206 257 if( $template ) { 207 $content = $storyform_media->add_data_attributes( $ id, $_POST['content']);258 $content = $storyform_media->add_data_attributes( $post_id, $content ); 208 259 } else { 209 $content = $storyform_media->remove_data_attributes( $id, $_POST['content'] ); 210 } 211 wp_update_post( array( 'ID' => $id, 'post_content' => $content ) ); 212 add_action( 'save_post', array( __CLASS__, 'save_meta_box_data' ) ); 260 $content = $storyform_media->remove_data_attributes( $post_id, $content ); 261 } 262 return $content; 213 263 } 214 264 }
Note: See TracChangeset
for help on using the changeset viewer.