Exemplo n.º 1
0
/**
 * Modifies the theme layout on attachment pages.  If a specific layout is not selected and the global layout
 * isn't set to '1c-narrow', this filter will change the layout to '1c'.
 *
 * @since  1.0.0
 * @access public
 * @param  string  $layout
 * @return string
 */
function stargazer_mod_theme_layout($layout)
{
    if (is_attachment() && wp_attachment_is_image()) {
        $post_layout = hybrid_get_post_layout(get_queried_object_id());
        if (!$post_layout || 'default' === $post_layout && '1c-narrow' !== $layout) {
            $layout = '1c';
        }
    }
    return $layout;
}
Exemplo n.º 2
0
/**
 * Default filter on the `theme_mod_theme_layout` hook.  By default, we'll check for per-post
 * or per-author layouts saved as metadata.  If set, we'll filter.  Else, just return the
 * global layout.
 *
 * @since  3.0.0
 * @access public
 * @param  string  $theme_layout
 * @return string
 */
function hybrid_filter_layout($theme_layout)
{
    // If viewing a singular post, get the post layout.
    if (is_singular()) {
        $layout = hybrid_get_post_layout(get_queried_object_id());
    } elseif (is_author()) {
        $layout = hybrid_get_user_layout(get_queried_object_id());
    }
    return !empty($layout) && 'default' !== $layout ? $layout : $theme_layout;
}
Exemplo n.º 3
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);
    }
}