Skip to content

Commit cebb7f2

Browse files
committed
Remove classes no longer needed due to changes in WordPress and call as many WordPress functions as possible over direct returns.
1 parent 8159efa commit cebb7f2

1 file changed

Lines changed: 26 additions & 54 deletions

File tree

includes/class-mf2-feed-entry.php

Lines changed: 26 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class Mf2_Feed_Entry {
1111
public $type;
1212
public $name;
1313
public $url;
14+
public $uid;
1415
public $author = array();
1516
public $published;
1617
public $updated;
@@ -26,15 +27,23 @@ public function __construct( $post, $with_comments = false ) {
2627
return false;
2728
}
2829

29-
$this->_id = $post->ID;
30-
$this->type = 'entry';
31-
$this->name = $post->post_name;
32-
$this->published = mysql2date( DATE_W3C, $post->post_date );
33-
$this->updated = mysql2date( DATE_W3C, $post->post_modified );
34-
$this->content['html'] = $this->get_content_by_id( $post->ID );
35-
$this->content['value'] = wp_strip_all_tags( $post->post_content );
36-
$this->summary = $this->get_excerpt_by_id( $post->ID );
37-
$this->url = get_permalink( $post->ID );
30+
$this->_id = $post->ID;
31+
$this->type = 'entry';
32+
$this->name = get_the_title( $post );
33+
// Eliminate IDs as names
34+
if ( $this->name = $this->_id ) {
35+
$this->name = null;
36+
}
37+
$this->published = get_post_time( DATE_W3C, false, $post );
38+
$this->updated = get_post_modified_time( DATE_W3C, false, $post );
39+
$content = get_the_content( null, false, $post );
40+
if ( ! empty( $content ) ) {
41+
$this->content['html'] = get_the_content( null, false, $post );
42+
$this->content['value'] = wp_strip_all_tags( $this->content['html'] );
43+
}
44+
$this->summary = get_the_excerpt( $post );
45+
$this->url = get_permalink( $post );
46+
$this->uid = get_permalink( $post );
3847

3948
// Get a list of categories and extract their names
4049
$post_categories = get_the_terms( $post->ID, 'category' );
@@ -63,68 +72,31 @@ public function __construct( $post, $with_comments = false ) {
6372
foreach ( get_comments( array( 'post_id' => $post->ID ) ) as $post_comment ) {
6473
$comment = array();
6574
$comment['type'] = 'cite';
66-
$comment['content']['html'] = $post_comment->comment_content;
67-
$comment['content']['value'] = wp_strip_all_tags( $post_comment->comment_content );
68-
$comment['published'] = mysql2date( DATE_W3C, $post_comment->comment_date_gmt );
75+
$comment['content']['html'] = get_comment_text( $post_comment );
76+
$comment['content']['value'] = wp_strip_all_tags( $comment['content']['html'] );
77+
$comment['published'] = get_comment_date( DATE_W3C, $post_comment );
6978
$comment['author']['type'] = 'card';
70-
$comment['author']['name'] = $post_comment->comment_author;
71-
$comment['author']['value'] = $post_comment->comment_author;
79+
$comment['author']['name'] = get_comment_author( $post_comment );
80+
$comment['author']['value'] = $comment['author']['name'];
7281

7382
if ( $post_comment->comment_author_url ) {
74-
$comment['author']['url'] = $post_comment->comment_author_url;
83+
$comment['author']['url'] = get_comment_author_url( $post_comment );
7584
}
7685

7786
$this->comment[] = $comment;
7887
}
7988
}
8089
}
8190

82-
/**
83-
* Display the post content. Optinally allows post ID to be passed
84-
* @uses the_content()
85-
*
86-
* @param int $id Optional. Post ID.
87-
* @param string $more_link_text Optional. Content for when there is more text.
88-
* @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
89-
*/
90-
private function get_content_by_id( $post_id = 0, $more_link_text = null, $stripteaser = false ) {
91-
if ( ! $post_id ) {
92-
$post_id = get_the_ID();
93-
}
94-
$post = get_post( $post_id );
95-
$content = get_the_content();
96-
97-
return $content;
98-
}
99-
100-
/**
101-
* Display the excerpt content. Optinally allows post ID to be passed
102-
* @uses the_content()
103-
*
104-
* @param int $id Optional. Post ID.
105-
* @param string $more_link_text Optional. Content for when there is more text.
106-
* @param bool $stripteaser Optional. Strip teaser content before the more text. Default is false.
107-
*/
108-
private function get_excerpt_by_id( $post_id = 0, $more_link_text = null, $stripteaser = false ) {
109-
if ( ! $post_id ) {
110-
$post_id = get_the_ID();
111-
}
112-
$post = get_post( $post_id );
113-
$content = get_the_excerpt();
114-
115-
return $content;
116-
}
117-
11891
public function to_mf2() {
11992
$entry = apply_filters( 'jf2_entry_array', get_object_vars( $this ), $this->_id );
93+
$entry = array_filter( $entry );
12094
$entry = apply_filters( 'mf2_entry_array', $this->jf2_to_mf2( $entry ), $this->_id );
121-
122-
return array_filter( $entry );
95+
return $entry;
12396
}
12497

12598
public function to_jf2() {
12699
$entry = apply_filters( 'jf2_entry_array', get_object_vars( $this ), $this->_id );
127-
128100
return array_filter( $entry );
129101
}
130102

0 commit comments

Comments
 (0)