WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] 3.6b1 'structured-post-formats', 'post-formats' and Twenty Thirteen (3 posts)

  1. ScreenfeedFr
    Member
    Posted 1 year ago #

    Hi.

    Twenty Thirteen does this:

    add_theme_support( 'structured-post-formats', array(
    	'link', 'video'
    ) );
    add_theme_support( 'post-formats', array(
    	'aside', 'audio', 'chat', 'gallery', 'image', 'quote', 'status'
    ) );

    But, after this, if I do:
    print_r(get_theme_support('post-formats'));
    All I get then is link and video.

    After checking the add_theme_support() function, this behavior is totally understandable, because it does an array_intersect() with the new values and the formats full list, and do not take care of previously registered values (for both: even if 'post-formats' is registered before 'structured-post-formats', 'structured-post-formats' takes the lead).

    case 'structured-post-formats' :
    	if ( is_array( $args[0] ) )
    		$args[0] = array_intersect( $args[0], array_keys( get_post_format_slugs() ) );
    	// structured-post-formats support automatically adds support for post-formats.
    	$_wp_theme_features['post-formats'] = $args;
    case 'post-formats' :
    	// An existing structured-post-formats support declaration overrides post-formats.
    	if ( current_theme_supports( 'structured-post-formats' ) )
    		$args = get_theme_support( 'structured-post-formats' );
    	elseif ( is_array( $args[0] ) )
    		$args[0] = array_intersect( $args[0], array_keys( get_post_format_slugs() ) );
    	break;

    So, is registering both 'structured-post-formats' and 'post-formats' totally useless or am I missing something?

    Thanks.

  2. So, is registering both 'structured-post-formats' and 'post-formats' totally useless or am I missing something?

    It has to do with how post_formats_compat() handles outputting content on a format-by-format basis.

    Having both essentially allows you to say, "I want to add support for (format group A) + (format group B), but I only want post_formats_compat() to handle output for (format group B)."

    If you take a look at the source for post_formats_compat(), you'll notice that the function just returns the content for status, aside, chat, and gallery formats. This also goes for any additional formats specified when structured-post-formats support is defined.

    In the case of Twenty Thirteen, they want to control the output of the link and video formats. So they add theme support for the aside, audio, chat, gallery, image, quote, and status formats (via post-formats support), and additionally add support for the link, and video formats (simultaneously telling post_formats_compat() that they want to control the output for those two formats).

    They end up supporting all nine post formats in the end, but use a couple of external functions to control the output of the link and video formats.

  3. ScreenfeedFr
    Member
    Posted 1 year ago #

    Hello Drew.

    Thank you for your answer.
    I understood the difference between structured-post-formats and post-formats, but this is not my point(s).

    First:

    add_theme_support( 'structured-post-formats', array(
    	'link', 'video'
    ) );
    print_r(get_theme_support('post-formats'));
    // Array ( [0] => Array ( [0] => link, [1] => video ) )    OK!
    
    add_theme_support( 'post-formats', array(
    	'aside', 'audio', 'chat', 'gallery', 'image', 'quote', 'status'
    ) );
    print_r(get_theme_support('post-formats'));
    // Array ( [0] => Array ( [0] => link, [1] => video ) )    UH?
    
    global $_wp_theme_features;
    print_r($_wp_theme_features);
    /*
    Array
    (
        ...
        [post-formats] => Array
            (
                [0] => Array
                    (
                        [0] => link
                        [1] => video
                    )
            )
        [structured-post-formats] => Array
            (
                [0] => Array
                    (
                        [0] => link
                        [1] => video
                    )
            )
    )
    UH?
    */

    By checking the source for add_theme_support, we can understand what is going on:

    switch ( $feature ) {
    	case 'structured-post-formats' :
    		if ( is_array( $args[0] ) )
    			$args[0] = array_intersect( $args[0], array_keys( get_post_format_slugs() ) );
    		// structured-post-formats support automatically adds support for post-formats.
    		$_wp_theme_features['post-formats'] = $args;
    	case 'post-formats' :
    		// An existing structured-post-formats support declaration overrides post-formats.
    		if ( current_theme_supports( 'structured-post-formats' ) )
    			$args = get_theme_support( 'structured-post-formats' );
    		elseif ( is_array( $args[0] ) )
    			$args[0] = array_intersect( $args[0], array_keys( get_post_format_slugs() ) );
    		break;
    // ...
    $_wp_theme_features[ $feature ] = $args;

    The interesting part is the comment "An existing structured-post-formats support declaration overrides post-formats.". The question is, why?
    We could say "Now we do this like that, all formats will be supported anyway, so we store only the structured-post-formats, the post-formats info is not relevant anymore.".
    OK, I agree for the idea, BUT, this also means:

    add_theme_support( 'structured-post-formats', array(
    	'link', 'video'
    ) );
    add_theme_support( 'post-formats', array(
    	'aside', 'audio', 'chat', 'gallery', 'image', 'quote', 'status'
    ) );

    Does exactly the same thing than:

    add_theme_support( 'structured-post-formats', array(
    	'link', 'video'
    ) );

    AND, still a problem with get_theme_support('post-formats'), the returned data "is not accurate". For new themes this is not a problem, while the developer is aware that all formats are supported now and this function will return only the 'structured-post-formats' data. But this behavior breaks the compatibility with old themes (but is it intended, to return only those formats? I think so, and it's a complex matter).

    Second thing:
    I've looked at the source for post_formats_compat(). At the beginning we can see a test for 'structured-post-formats', but not a single one for 'post-formats'. Which means, as I said earlier: if you register only one post format, all will be supported. So, as I said, registering 'structured-post-formats' OR 'post-formats' is enough. The second registration for 'post-formats' does nothing more.

    Am I wrong somewhere?

Topic Closed

This topic has been closed to new replies.

About this Topic