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

Commit 3e27f4f

Browse files
authored
Merge pull request #153 from dshanske/posttypes
Enhance Post Types
2 parents 18155d9 + ea41464 commit 3e27f4f

File tree

3 files changed

+43
-19
lines changed

3 files changed

+43
-19
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ The Webmention and Pingback logos are made by [Aaron Parecki](http://aaronpareck
6969
Project actively developed on Github at [pfefferle/wordpress-semantic-linkbacks](https://github.com/pfefferle/wordpress-semantic-linkbacks). Please file support issues there.
7070

7171
### 3.7.4 ###
72+
7273
* Replace `rsvp-invite` property which is not in use with `invite` property and add unit tests
74+
* Enhance post type returns to include post, page, and sitename
7375
* Add basic person tagging support
7476

7577
### 3.7.3 ###

includes/class-linkbacks-handler.php

Lines changed: 39 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,38 @@ 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_type = $post_typestrings[ 'post' ];
424+
425+
// If this is the page homepages are redirected to then use the site name
426+
if ( $post_id === get_option( 'webmention_home_mentions', 0 ) ) {
427+
$post_type = get_bloginfo( 'name' );
428+
} else if ( 'page' === get_post_type( $post_id ) ) {
429+
$post_type = $post_typestrings[ 'page' ];
430+
} else if ( current_theme_supports( 'post-formats' ) ) {
431+
$post_format = get_post_format( $post_id );
432+
433+
// add "standard" as default for post format enabled types
434+
if ( ! $post_format || ! in_array( $post_format, array_keys( $post_typestrings ), true ) ) {
435+
$post_format = 'standard';
436+
}
437+
438+
$post_type = $post_typestrings[ $post_format ];
439+
}
440+
441+
return apply_filters( 'semantic_linkbacks_post_type', $post_type, $post_id );
442+
}
443+
444+
445+
412446
/**
413447
* Generate excerpt for all types except "reply"
414448
*
@@ -441,21 +475,7 @@ public static function comment_text_excerpt( $text, $comment = null, $args = arr
441475
$semantic_linkbacks_type = 'mention';
442476
}
443477

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 );
478+
$post_type = self::get_post_type( $comment->comment_post_ID );
459479

460480
// get all the excerpts
461481
$comment_type_excerpts = self::get_comment_type_excerpts();

readme.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ The Webmention and Pingback logos are made by [Aaron Parecki](http://aaronpareck
6969
Project actively developed on Github at [pfefferle/wordpress-semantic-linkbacks](https://github.com/pfefferle/wordpress-semantic-linkbacks). Please file support issues there.
7070

7171
= 3.7.4 =
72+
7273
* Replace `rsvp-invite` property which is not in use with `invite` property and add unit tests
74+
* Enhance post type returns to include post, page, and sitename
7375
* Add basic person tagging support
7476

7577
= 3.7.3 =

0 commit comments

Comments
 (0)