Skip to content

Commit 6d76880

Browse files
pfefferleobenland
andauthored
Better Post-Formats support (#990)
* Better Post-Formats support This change uses the Post-Format also for Custom-Post-Type if they support them. * improve check * changed based on the feedback of @obenland * a less restrictive check * handle all `! Pages` the same way @obenland that puts a knot in my brain ^^ what about this change? * Add test for CPT with post format support. * Combine control structures --------- Co-authored-by: Konstantin Obenland <[email protected]>
1 parent 317dc9b commit 6d76880

File tree

2 files changed

+42
-27
lines changed

2 files changed

+42
-27
lines changed

includes/transformer/class-post.php

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -729,33 +729,14 @@ protected function get_type() {
729729
return 'Note';
730730
}
731731

732-
// Default to Article.
733-
$object_type = 'Article';
734-
$post_format = 'standard';
735-
736-
if ( \get_theme_support( 'post-formats' ) ) {
737-
$post_format = \get_post_format( $this->wp_object );
738-
}
739-
740-
$post_type = \get_post_type( $this->wp_object );
741-
switch ( $post_type ) {
742-
case 'post':
743-
switch ( $post_format ) {
744-
case 'standard':
745-
case '':
746-
$object_type = 'Article';
747-
break;
748-
default:
749-
$object_type = 'Note';
750-
break;
751-
}
752-
break;
753-
case 'page':
754-
$object_type = 'Page';
755-
break;
756-
default:
757-
$object_type = 'Article';
758-
break;
732+
// Default to Note.
733+
$object_type = 'Note';
734+
$post_type = \get_post_type( $this->wp_object );
735+
736+
if ( 'page' === $post_type ) {
737+
$object_type = 'Page';
738+
} elseif ( ! \get_post_format( $this->wp_object ) ) {
739+
$object_type = 'Article';
759740
}
760741

761742
return $object_type;

tests/class-test-transformer-post.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,4 +229,38 @@ public function test_get_type_respects_post_type_title_support() {
229229
// Clean up.
230230
unregister_post_type( 'no_title_type' );
231231
}
232+
233+
/**
234+
* Test that the get_type method returns article for custom post type with post format support.
235+
*
236+
* @covers ::get_type
237+
*/
238+
public function test_get_type_respects_post_format_support() {
239+
240+
// Create custom post type without title support.
241+
register_post_type(
242+
'no_title_type',
243+
array(
244+
'public' => true,
245+
'supports' => array( 'editor', 'title', 'post-formats' ), // Needs to include 'title'.
246+
)
247+
);
248+
249+
$post_id = $this->factory->post->create(
250+
array(
251+
'post_title' => 'Test Post',
252+
'post_content' => str_repeat( 'Long content. ', 100 ),
253+
'post_type' => 'no_title_type',
254+
)
255+
);
256+
$post = get_post( $post_id );
257+
258+
$transformer = new Post( $post );
259+
$type = $this->reflection_method->invoke( $transformer );
260+
261+
$this->assertSame( 'Article', $type );
262+
263+
// Clean up.
264+
unregister_post_type( 'no_title_type' );
265+
}
232266
}

0 commit comments

Comments
 (0)