Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 6d23ae1

Browse files
committed
Enhance Post Types
1 parent 132e984 commit 6d23ae1

File tree

3 files changed

+42
-19
lines changed

3 files changed

+42
-19
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Project actively developed on Github at [pfefferle/wordpress-semantic-linkbacks]
7070

7171
### 3.7.4 ###
7272
* Replace `rsvp-invite` property which is not in use with `invite` property and add unit tests
73+
* Enhance post type returns to include post, page, and sitename
7374

7475
### 3.7.3 ###
7576

includes/class-linkbacks-handler.php

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -256,15 +256,17 @@ public static function get_comment_type_strings() {
256256
}
257257

258258
/**
259-
* Returns an array of post formats (with articlex)
259+
* Returns an array of post types (with articles)
260260
*
261261
* @return array The array of translated comment type names.
262262
*/
263-
public static function get_post_format_strings() {
263+
public static function get_post_type_strings() {
264264
$strings = array(
265-
// Special case. any value that evals to false will be considered standard
265+
// Generic Post Types
266+
'post' => __( 'this Post', 'semantic-linkbacks' ),
267+
'page' => __( 'this Page', 'semantic-linkbacks' ),
268+
// Post Format Types
266269
'standard' => __( 'this Article', 'semantic-linkbacks' ),
267-
268270
'aside' => __( 'this Aside', 'semantic-linkbacks' ),
269271
'chat' => __( 'this Chat', 'semantic-linkbacks' ),
270272
'gallery' => __( 'this Gallery', 'semantic-linkbacks' ),
@@ -409,6 +411,39 @@ public static function comment_text_add_cite( $text, $comment = null, $args = ar
409411
return $text . sprintf( $cite, $url, $host );
410412
}
411413

414+
/**
415+
* Returns a post type that is used to generate text. This can be from post formats/kinds/post type/etc
416+
*
417+
* @param int $post_id Post ID
418+
*
419+
* @return string the post type
420+
*/
421+
public static function get_post_type( $post_id ) {
422+
$post_typestrings = self::get_post_type_strings();
423+
$post_format = 'post';
424+
if ( 'page' === get_post_type( $post_id ) ) {
425+
$post_format = 'page';
426+
}
427+
if ( current_theme_supports( 'post-formats' ) ) {
428+
$post_format = get_post_format( $post_id );
429+
// add "standard" as default for post format enabled types
430+
if ( ! $post_format || ! in_array( $post_format, array_keys( $post_typestrings ), true ) ) {
431+
$post_format = 'standard';
432+
}
433+
}
434+
435+
$post_type = $post_typestrings[ $post_format ];
436+
437+
// If this is the page homepages are redirected to then use the site name
438+
if ( $post_id === get_option( 'webmention_home_mentions', 0 ) ) {
439+
$post_type = get_bloginfo( 'name' );
440+
}
441+
442+
return apply_filters( 'semantic_linkbacks_post_type', $post_type, $post_id );
443+
}
444+
445+
446+
412447
/**
413448
* Generate excerpt for all types except "reply"
414449
*
@@ -441,21 +476,7 @@ public static function comment_text_excerpt( $text, $comment = null, $args = arr
441476
$semantic_linkbacks_type = 'mention';
442477
}
443478

444-
if ( ! current_theme_supports( 'post-formats' ) ) {
445-
$post_format = 'standard';
446-
} else {
447-
$post_format = get_post_format( $comment->comment_post_ID );
448-
// add "standard" as default
449-
if ( ! $post_format || ! in_array( $post_format, array_keys( self::get_post_format_strings() ), true ) ) {
450-
$post_format = 'standard';
451-
}
452-
}
453-
454-
// get post type
455-
$post_formatstrings = self::get_post_format_strings();
456-
$post_type = $post_formatstrings[ $post_format ];
457-
458-
$post_type = apply_filters( 'semantic_linkbacks_post_type', $post_type, $comment->comment_post_ID );
479+
$post_type = self::get_post_type( $comment->comment_post_ID );
459480

460481
// get all the excerpts
461482
$comment_type_excerpts = self::get_comment_type_excerpts();

readme.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Project actively developed on Github at [pfefferle/wordpress-semantic-linkbacks]
7070

7171
= 3.7.4 =
7272
* Replace `rsvp-invite` property which is not in use with `invite` property and add unit tests
73+
* Enhance post type returns to include post, page, and sitename
7374

7475
= 3.7.3 =
7576

0 commit comments

Comments
 (0)