Ticket #12267: wp-post-patch.diff

File wp-post-patch.diff, 2.6 KB (added by toppa, 10 months ago)

Patch for WP_Post class

Line 
1Index: wp-includes/class-wp-post.php
2===================================================================
3--- wp-includes/class-wp-post.php       (revision 0)
4+++ wp-includes/class-wp-post.php       (revision 0)
5@@ -0,0 +1,56 @@
6+<?php
7+
8+class WP_Post {
9+       public $ID;
10+       public $post_author;
11+       public $post_date;
12+       public $post_date_gmt;
13+       public $post_content;
14+       public $post_title;
15+       public $post_excerpt;
16+       public $post_status;
17+       public $comment_status;
18+       public $ping_status;
19+       public $post_password;
20+       public $post_name;
21+       public $to_ping;
22+       public $pinged;
23+       public $post_modified;
24+       public $post_modified_gmt;
25+       public $post_content_filtered;
26+       public $post_parent;
27+       public $guid;
28+       public $menu_order;
29+       public $post_type;
30+       public $post_mime_type;
31+       public $comment_count;
32+       public $filter;
33+
34+       public function __set( $name, $value ) {
35+               if ( property_exists('WP_Post', $name) ) {
36+                       $this->$name = $value;
37+                       return $this->$name;
38+               }
39+
40+               return false;
41+       }
42+
43+       public static function get_instance( $post_data ) {
44+               $post = new WP_Post();
45+
46+               foreach ( $post_data as $k=>$v ) {
47+                       if ( property_exists('WP_Post', $k) ) {
48+                               $post->$k = $v;
49+                       }
50+               }
51+
52+               return $post;
53+       }
54+
55+       // wrapper for get_the_title()
56+       // the idea is to add wrappers for the other functions related
57+       // to displaying post info as well
58+       public function get_the_title() {
59+               return get_the_title($this);
60+       }
61+}
62Index: wp-includes/query.php
63===================================================================
64--- wp-includes/query.php       (revision 21271)
65+++ wp-includes/query.php       (working copy)
66@@ -2660,6 +2660,11 @@
67                if ( !$q['suppress_filters'] )
68                        $this->posts = apply_filters_ref_array('posts_results', array( $this->posts, &$this ) );
69 
70+               // Convert posts to WP_Post objects
71+               if ( is_array($this->posts) ) {
72+                       $this->posts = array_map(array( 'WP_Post', 'get_instance' ), $this->posts );
73+               }
74+
75                if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) {
76                        $cjoin = apply_filters_ref_array('comment_feed_join', array( '', &$this ) );
77                        $cwhere = apply_filters_ref_array('comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) );
78Index: wp-settings.php
79===================================================================
80--- wp-settings.php     (revision 21271)
81+++ wp-settings.php     (working copy)
82@@ -142,6 +142,7 @@
83 require( ABSPATH . WPINC . '/nav-menu.php' );
84 require( ABSPATH . WPINC . '/nav-menu-template.php' );
85 require( ABSPATH . WPINC . '/admin-bar.php' );
86+require( ABSPATH . WPINC . '/class-wp-post.php' );
87 
88 // Load multisite-specific files.
89 if ( is_multisite() ) {