Post formats, take one. see #14746
git-svn-id: http://svn.automattic.com/wordpress/trunk@15777 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
ce6b055cf8
commit
0982c3c0f9
|
@ -470,6 +470,45 @@ function get_post_mime_type($ID = '') {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the format for a post
|
||||
*
|
||||
* @param int|object $post A post
|
||||
*
|
||||
* @return mixed The format if successful. False if no format is set. WP_Error if errors.
|
||||
*/
|
||||
function get_post_format( $post ) {
|
||||
$post = get_post($post);
|
||||
|
||||
$format = wp_get_object_terms( $post->ID, 'post_format', array('orderby' => 'none', 'fields' => 'names') );
|
||||
|
||||
if ( is_wp_error($format) )
|
||||
return $format;
|
||||
|
||||
if ( empty($format) )
|
||||
return false;
|
||||
|
||||
return ( str_replace('post-format-', '', $format[0]) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a format to a post
|
||||
*
|
||||
* @param int|object $post The post for which to assign a format
|
||||
* @param string $format A format to assign.
|
||||
* @return mixed WP_Error on error. Array of affected term IDs on success.
|
||||
*/
|
||||
function set_post_format( $post, $format ) {
|
||||
$post = get_post($post);
|
||||
|
||||
if ( empty($post) )
|
||||
return new WP_Error('invalid_post', __('Invalid post'));
|
||||
|
||||
$format = sanitize_key($format);
|
||||
|
||||
return wp_set_post_terms($post->ID, array('post-format-' . $format), 'post_format');
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the post status based on the Post ID.
|
||||
*
|
||||
|
|
|
@ -71,6 +71,19 @@ function create_initial_taxonomies() {
|
|||
'show_ui' => false,
|
||||
'_builtin' => true,
|
||||
) ) ;
|
||||
|
||||
register_taxonomy( 'post_format', array('post', 'page', 'attachment'), array(
|
||||
'hierarchical' => false,
|
||||
'labels' => array(
|
||||
'name' => '',
|
||||
'singular_name' => '',
|
||||
),
|
||||
'query_var' => false,
|
||||
'rewrite' => false,
|
||||
'show_ui' => false,
|
||||
'_builtin' => true,
|
||||
'show_in_nav_menus' => false,
|
||||
) ) ;
|
||||
}
|
||||
add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority
|
||||
|
||||
|
|
Loading…
Reference in New Issue