Esempio n. 1
0
/**
 * Adds a select drop-down element to the attachment edit form for selecting the attachment layout.
 *
 * @since 0.3.0
 * @param array $fields Array of fields for the edit attachment form.
 * @param object $post The attachment post object.
 * @return array $fields
 */
function theme_layouts_attachment_fields_to_edit($fields, $post)
{
    /* Get theme-supported theme layouts. */
    $layouts = get_theme_support('theme-layouts');
    $post_layouts = $layouts[0];
    /* Get the current post's layout. */
    $post_layout = get_post_layout($post->ID);
    /* Set the default post layout. */
    $select = '<option id="post_layout_default" value="default" ' . selected($post_layout, 'default', false) . '>' . esc_html(theme_layouts_get_string('default')) . '</option>';
    /* Loop through each theme-supported layout, adding it to the select element. */
    foreach ($post_layouts as $layout) {
        $select .= '<option id="post_layout_' . esc_attr($layout) . '" value="' . esc_attr($layout) . '" ' . selected($post_layout, $layout, false) . '>' . esc_html(theme_layouts_get_string($layout)) . '</option>';
    }
    /* Set the HTML for the post layout select drop-down. */
    $select = '<select name="attachments[' . $post->ID . '][theme-layouts-post-layout]" id="attachments[' . $post->ID . '][theme-layouts-post-layout]">' . $select . '</select>';
    /* Add the attachment layout field to the $fields array. */
    $fields['theme-layouts-post-layout'] = array('label' => __('Layout', theme_layouts_textdomain()), 'input' => 'html', 'html' => $select);
    /* Return the $fields array back to WordPress. */
    return $fields;
}
Esempio n. 2
0
/**
 * Displays a meta box of radio selectors on the post editing screen, which allows theme users to select 
 * the layout they wish to use for the specific post.
 *
 * @since 0.2.0
 */
function theme_layouts_post_meta_box( $post, $box ) {

	/* Get theme-supported theme layouts. */
	$layouts = get_theme_support( 'theme-layouts' );
	$post_layouts = $layouts[0];

	/* Get the current post's layout. */
	$post_layout = get_post_layout( $post->ID ); ?>

	<div class="post-layout">

		<input type="hidden" name="theme_layouts_post_meta_box_nonce" value="<?php echo wp_create_nonce( basename( __FILE__ ) ); ?>" />

		<p><?php _e( 'Layout is a theme-specific structure for the single view of the post.', theme_layouts_textdomain() ); ?></p>

		<div class="post-layout-wrap">
			<ul>
				<li><input type="radio" name="post_layout" id="post_layout_default" value="default" <?php checked( $post_layout, 'default' );?> /> <label for="post_layout_default"><?php echo esc_html( theme_layouts_get_string( 'default' ) ); ?></label></li>

				<?php foreach ( $post_layouts as $layout ) { ?>
					<li><input type="radio" name="post_layout" id="post_layout_<?php echo esc_attr( $layout ); ?>" value="<?php echo esc_attr( $layout ); ?>" <?php checked( $post_layout, $layout ); ?> /> <label for="post_layout_<?php echo esc_attr( $layout ); ?>"><?php echo esc_html( theme_layouts_get_string( $layout ) ); ?></label></li>
				<?php } ?>
			</ul>
		</div>
	</div><?php
}