WordPress.org

Make WordPress Core

Ticket #14746: 14746.6.diff

File 14746.6.diff, 2.0 KB (added by ryan, 9 years ago)

Rename to post_format

  • wp-includes/taxonomy.php

     
    7171                'show_ui' => false,
    7272                '_builtin' => true,
    7373        ) ) ;
     74
     75        register_taxonomy( 'post_format', array('post', 'page', 'attachment'), array(
     76                'hierarchical' => false,
     77                'labels' => array(
     78                        'name' => '',
     79                        'singular_name' => '',
     80                ),
     81                'query_var' => false,
     82                'rewrite' => false,
     83                'show_ui' => false,
     84                '_builtin' => true,
     85                'show_in_nav_menus' => false,
     86        ) ) ;
    7487}
    7588add_action( 'init', 'create_initial_taxonomies', 0 ); // highest priority
    7689
  • wp-includes/post.php

     
    471471}
    472472
    473473/**
     474 * Retrieve the format for a post
     475 *
     476 * @param int|object $post A post
     477 *
     478 * @return mixed The format if successful. False if no format is set.  WP_Error if errors.
     479 */
     480function get_post_format( $post ) {
     481        $post = get_post($post);
     482
     483        $format = wp_get_object_terms( $post->ID, 'post_format', array('orderby' => 'none', 'fields' => 'names') );
     484
     485        if ( is_wp_error($format) )
     486                return $format;
     487
     488        if ( empty($format) )
     489                return false;
     490
     491        return ( str_replace('post-format-', '', $format[0]) );
     492}
     493
     494/**
     495 * Assign a format to a post
     496 *
     497 * @param int|object $post The post for which to assign a format
     498 * @param string $format  A format to assign.
     499 * @return mixed WP_Error on error. Array of affected term IDs on success.
     500 */
     501function set_post_format( $post, $format ) {
     502        $post = get_post($post);
     503
     504        if ( empty($post) )
     505                return new WP_Error('invalid_post', __('Invalid post'));
     506
     507        $format = sanitize_key($format);
     508
     509        return wp_set_post_terms($post->ID, array('post-format-' . $format), 'post_format');
     510}
     511
     512/**
    474513 * Retrieve the post status based on the Post ID.
    475514 *
    476515 * If the post ID is of an attachment, then the parent post status will be given