* @copyright Copyright (c) 2008 - 2015, Justin Tadlock
* @link http://themehybrid.com/hybrid-core
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
*/
# Add the layout meta box on the 'add_meta_boxes' hook.
add_action( 'add_meta_boxes', 'hybrid_add_post_layout_meta_box', 10, 2 );
# Saves the post layout on the post editing page.
add_action( 'save_post', 'hybrid_save_post_layout', 10, 2 );
add_action( 'add_attachment', 'hybrid_save_post_layout' );
add_action( 'edit_attachment', 'hybrid_save_post_layout' );
/**
* Adds the layout meta box.
*
* @since 3.0.0
* @access public
* @param string $post_type
* @param object $post
* @return void
*/
function hybrid_add_post_layout_meta_box( $post_type ) {
if ( current_theme_supports( 'theme-layouts', 'post_meta' ) && post_type_supports( $post_type, 'theme-layouts' ) && current_user_can( 'edit_theme_options' ) ) {
// Add meta box.
add_meta_box( 'hybrid-post-layout', esc_html__( 'Layout', 'hybrid-core' ), 'hybrid_post_layout_meta_box', $post_type, 'side', 'default' );
// Load scripts/styles.
add_action( 'admin_enqueue_scripts', 'hybrid_post_layout_enqueue', 5 );
}
}
/**
* Loads the scripts/styles for the layout meta box.
*
* @since 3.0.0
* @access public
* @return void
*/
function hybrid_post_layout_enqueue() {
wp_enqueue_style( 'hybrid-admin' );
}
/**
* Callback function for displaying the layout meta box.
*
* @since 3.0.0
* @access public
* @param object $object
* @param array $box
* @return void
*/
function hybrid_post_layout_meta_box( $post, $box ) {
// Get the current post's layout.
$post_layout = hybrid_get_post_layout( $post->ID );
$post_layout = $post_layout ? $post_layout : 'default';
wp_nonce_field( basename( __FILE__ ), 'hybrid-post-layout-nonce' ); ?>
is_post_layout && $layout->image && ( ! $layout->post_types || in_array( $post->post_type, $layout->post_types ) ) ) : ?>