Example #1
0
/**
 * Sets a post layout.
 *
 * @since  3.0.0
 * @access public
 * @param  int     $post_id
 * @param  string  $layout
 * @return bool
 */
function hybrid_set_post_layout($post_id, $layout)
{
    return 'default' !== $layout ? update_post_meta($post_id, hybrid_get_layout_meta_key(), $layout) : hybrid_delete_post_layout($post_id);
}
Example #2
0
/**
 * Saves the post layout when submitted via the layout meta box.
 *
 * @since  3.0.0
 * @access public
 * @param  int      $post_id The ID of the current post being saved.
 * @param  object   $post    The post object currently being saved.
 * @return void|int
 */
function hybrid_save_post_layout($post_id, $post = '')
{
    // Fix for attachment save issue in WordPress 3.5. @link http://core.trac.wordpress.org/ticket/21963
    if (!is_object($post)) {
        $post = get_post();
    }
    // Verify the nonce for the post formats meta box.
    if (!isset($_POST['hybrid-post-layout-nonce']) || !wp_verify_nonce($_POST['hybrid-post-layout-nonce'], basename(__FILE__))) {
        return $post_id;
    }
    // Get the previous post layout.
    $meta_value = hybrid_get_post_layout($post_id);
    // Get the submitted post layout.
    $new_meta_value = isset($_POST['hybrid-post-layout']) ? sanitize_key($_POST['hybrid-post-layout']) : '';
    // If there is no new meta value but an old value exists, delete it.
    if ('' == $new_meta_value && $meta_value) {
        hybrid_delete_post_layout($post_id);
    } elseif ($meta_value !== $new_meta_value) {
        hybrid_set_post_layout($post_id, $new_meta_value);
    }
}