* @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 post template meta box on the 'add_meta_boxes' hook. add_action( 'add_meta_boxes', 'hybrid_meta_box_post_add_template', 10, 2 ); # Save the post template meta box data on the 'save_post' hook. add_action( 'save_post', 'hybrid_meta_box_post_save_template', 10, 2 ); add_action( 'add_attachment', 'hybrid_meta_box_post_save_template' ); add_action( 'edit_attachment', 'hybrid_meta_box_post_save_template' ); /** * Adds the post template meta box for all public post types, excluding the 'page' post type since WordPress * core already handles page templates. * * @since 1.2.0 * @access public * @param string $post_type * @param object $post * @return void */ function hybrid_meta_box_post_add_template( $post_type, $post ) { // Get the post templates. $templates = hybrid_get_post_templates( $post_type ); // If there's templates, add the meta box. if ( ! empty( $templates ) && 'page' !== $post_type ) add_meta_box( 'hybrid-post-template', esc_html__( 'Template', 'hybrid-core' ), 'hybrid_meta_box_post_display_template', $post_type, 'side', 'default' ); } /** * Displays the post template meta box. * * @since 1.2.0 * @access public * @param object $object * @param array $box * @return void */ function hybrid_meta_box_post_display_template( $post, $box ) { $templates = hybrid_get_post_templates( $post->post_type ); $post_template = hybrid_get_post_template( $post->ID ); wp_nonce_field( basename( __FILE__ ), 'hybrid-post-template-nonce' ); ?>