/** * Saves the attachment layout for the attachment edit form. * * @since 0.3.0 * @param array $post The attachment post array (not the post object!). * @param array $fields Array of fields for the edit attachment form. * @return array $post */ function theme_layouts_attachment_fields_to_save($post, $fields) { /* If the theme layouts field was submitted. */ if (isset($fields['theme-layouts-post-layout'])) { /* Get the previous post layout. */ $old_layout = get_post_layout($post['ID']); /* Get the submitted post layout. */ $new_layout = esc_attr($fields['theme-layouts-post-layout']); /* If the old layout doesn't match the new layout, update the post layout meta. */ if ($old_layout !== $new_layout) { set_post_layout($post['ID'], $new_layout); } } /* Return the attachment post array. */ return $post; }
/** * Saves the attachment layout for the attachment edit form. * * @since 0.3.0 * @access private * @param array $post The attachment post array (not the post object!). * @param array $fields Array of fields for the edit attachment form. * @return array $post */ function theme_layouts_attachment_fields_to_save($post, $fields) { /* If the theme layouts field was submitted. */ if (isset($fields['theme-layouts-post-layout'])) { /* Get the meta key. */ $meta_key = theme_layouts_get_meta_key(); /* Get the previous post layout. */ $meta_value = get_post_layout($post['ID']); /* Get the submitted post layout. */ $new_meta_value = $fields['theme-layouts-post-layout']; /* If there is no new meta value but an old value exists, delete it. */ if (current_user_can('delete_post_meta', $post['ID'], $meta_key) && '' == $new_meta_value && $meta_value) { delete_post_layout($post['ID']); } elseif (current_user_can('add_post_meta', $post['ID'], $meta_key) && $new_meta_value && '' == $meta_value) { set_post_layout($post['ID'], $new_meta_value); } elseif (current_user_can('edit_post_meta', $post['ID'], $meta_key) && $meta_value !== $new_meta_value) { set_post_layout($post['ID'], $new_meta_value); } } /* Return the attachment post array. */ return $post; }
/** * Saves the post layout metadata if on the post editing screen in the admin. * * @since 0.2.0 */ function theme_layouts_save_post( $post_id, $post ) { /* Verify the nonce for the post formats meta box. */ if ( !isset( $_POST['theme_layouts_post_meta_box_nonce'] ) || !wp_verify_nonce( $_POST['theme_layouts_post_meta_box_nonce'], basename( __FILE__ ) ) ) return $post_id; /* Get the previous post layout. */ $old_layout = get_post_layout( $post_id ); /* Get the submitted post layout. */ $new_layout = esc_attr( $_POST['post_layout'] ); /* If the old layout doesn't match the new layout, update the post layout meta. */ if ( $old_layout !== $new_layout ) set_post_layout( $post_id, $new_layout ); }