post_format_meta_box

Display post format form elements.

Description

post_format_meta_box( (WP_Post) $post, (array) $box ); 

Parameters (2)

0. $post (WP_Post)
Post object.
1. $box (array)
Post formats meta box arguments.

Options

  • id (string) => ''

    Meta box id attribute.

  • title (string) => ''

    Meta box title.

  • callback (callable) => null

    Meta box display callback.

array(

    /**
     * Meta box 'id' attribute.
     *
     * @type string
     * @default ''
     */
    'id' => '',

    /**
     * Meta box title.
     *
     * @type string
     * @default ''
     */
    'title' => '',

    /**
     * Meta box display callback.
     *
     * @type callable
     * @default null
     */
    'callback' => null
);        


Usage

  1. if ( !function_exists( 'post_format_meta_box' ) ) { 
  2. require_once ABSPATH . '/wp-admin/includes/meta-boxes.php'; 
  3.  
  4. // Post object. 
  5. $post = null; 
  6.  
  7. // Post formats meta box arguments. 
  8. $box = array( 
  9. 'id' => '', 
  10. 'title' => '', 
  11. 'callback' => null 
  12. ); 
  13.  
  14. // NOTICE! Understand what this does before running. 
  15. $result = post_format_meta_box($post, $box); 
  16.  

Defined (1)

The function is defined in the following location(s).

/wp-admin/includes/meta-boxes.php  
  1. function post_format_meta_box( $post, $box ) { 
  2. if ( current_theme_supports( 'post-formats' ) && post_type_supports( $post->post_type, 'post-formats' ) ) : 
  3. $post_formats = get_theme_support( 'post-formats' ); 
  4.  
  5. if ( is_array( $post_formats[0] ) ) : 
  6. $post_format = get_post_format( $post->ID ); 
  7. if ( !$post_format ) 
  8. $post_format = '0'; 
  9. // Add in the current one if it isn't there yet, in case the current theme doesn't support it 
  10. if ( $post_format && !in_array( $post_format, $post_formats[0] ) ) 
  11. $post_formats[0][] = $post_format; 
  12. ?> 
  13. <div id="post-formats-select"> 
  14. <fieldset> 
  15. <legend class="screen-reader-text"><?php _e( 'Post Formats' ); ?></legend> 
  16. <input type="radio" name="post_format" class="post-format" id="post-format-0" value="0" <?php checked( $post_format, '0' ); ?> /> <label for="post-format-0" class="post-format-icon post-format-standard"><?php echo get_post_format_string( 'standard' ); ?></label> 
  17. <?php foreach ( $post_formats[0] as $format ) : ?> 
  18. <br /><input type="radio" name="post_format" class="post-format" id="post-format-<?php echo esc_attr( $format ); ?>" value="<?php echo esc_attr( $format ); ?>" <?php checked( $post_format, $format ); ?> /> <label for="post-format-<?php echo esc_attr( $format ); ?>" class="post-format-icon post-format-<?php echo esc_attr( $format ); ?>"><?php echo esc_html( get_post_format_string( $format ) ); ?></label> 
  19. <?php endforeach; ?> 
  20. </fieldset> 
  21. </div> 
  22. <?php endif; endif;