Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
...
Checking mergeability… Don’t worry, you can still create the pull request.
  • 2 commits
  • 5 files changed
  • 0 commit comments
  • 1 contributor
Showing with 220 additions and 131 deletions.
  1. +205 −0 wp-includes/class-wp-post.php
  2. +8 −130 wp-includes/post-template.php
  3. +2 −1 wp-includes/post.php
  4. +4 −0 wp-includes/query.php
  5. +1 −0 wp-settings.php
View
205 wp-includes/class-wp-post.php
@@ -0,0 +1,205 @@
+<?php
+
+class WP_Post {
+ public $ID;
+ public $post_author;
+ public $post_date;
+ public $post_date_gmt;
+ public $post_content;
+ public $post_title;
+ public $post_excerpt;
+ public $post_status;
+ public $comment_status;
+ public $ping_status;
+ public $post_password;
+ public $post_name;
+ public $to_ping;
+ public $pinged;
+ public $post_modified;
+ public $post_modified_gmt;
+ public $post_content_filtered;
+ public $post_parent;
+ public $guid;
+ public $menu_order;
+ public $post_type;
+ public $post_mime_type;
+ public $comment_count;
+ public $filter;
+
+ /*
+ * @param array|object $post_data post data, in the form of an array or stdClass object
+ */
+ public static function get_instance( $post_data ) {
+ $post = new WP_Post();
+
+ foreach ( $post_data as $k=>$v ) {
+ if ( property_exists('WP_Post', $k) ) {
+ $post->$k = $v;
+ }
+ }
+
+ return $post;
+ }
+
+ /*
+ * @param array $posts_data an array of posts (the posts themselves can be arrays or stdClass objects)
+ */
+ public static function get_instances( array $posts_data ) {
+ return array_map(array( 'WP_Post', 'get_instance' ), $posts_data );
+ }
+
+ // since all properties are public, this is only
+ // needed to prevent the addition of other properties
+ public function __set( $name, $value ) {
+ return false;
+ }
+
+ public function get_ID() {
+ return $this->ID;
+ }
+
+ public function get_title( $id = 0 ) {
+ $title = isset($this->post_title) ? $this->post_title : '';
+ $id = isset($this->ID) ? $this->ID : (int) $id;
+
+ if ( !is_admin() ) {
+ if ( !empty($this->post_password) ) {
+ $protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));
+ $title = sprintf($protected_title_format, $title);
+ } else if ( isset($this->post_status) && 'private' == $this->post_status ) {
+ $private_title_format = apply_filters('private_title_format', __('Private: %s'));
+ $title = sprintf($private_title_format, $title);
+ }
+ }
+ return apply_filters( 'the_title', $title, $id );
+ }
+
+ public function get_guid() {
+ return apply_filters('get_the_guid', $this->guid);
+ }
+
+ public function get_content($more_link_text = null, $stripteaser = false) {
+ global $more, $page, $pages, $multipage, $preview;
+
+ if ( null === $more_link_text )
+ $more_link_text = __( '(more...)' );
+
+ $output = '';
+ $hasTeaser = false;
+
+ // If post password required and it doesn't match the cookie.
+ if ( post_password_required($this) )
+ return get_the_password_form();
+
+ if ( $page > count($pages) ) // if the requested page doesn't exist
+ $page = count($pages); // give them the highest numbered page that DOES exist
+
+ $content = $pages[$page-1];
+ if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
+ $content = explode($matches[0], $content, 2);
+ if ( !empty($matches[1]) && !empty($more_link_text) )
+ $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1])));
+
+ $hasTeaser = true;
+ } else {
+ $content = array($content);
+ }
+ if ( (false !== strpos($this->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )
+ $stripteaser = true;
+ $teaser = $content[0];
+ if ( $more && $stripteaser && $hasTeaser )
+ $teaser = '';
+ $output .= $teaser;
+ if ( count($content) > 1 ) {
+ if ( $more ) {
+ $output .= '<span id="more-' . $this->ID . '"></span>' . $content[1];
+ } else {
+ if ( ! empty($more_link_text) )
+ $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$this->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
+ $output = force_balance_tags($output);
+ }
+
+ }
+ if ( $preview ) // preview fix for javascript bug with foreign languages
+ $output = preg_replace_callback('/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output);
+
+ return $output;
+ }
+
+ public function get_excerpt( $deprecated = '' ) {
+ if ( !empty( $deprecated ) )
+ _deprecated_argument( __FUNCTION__, '2.3' );
+
+ if ( post_password_required($this) ) {
+ return __( 'There is no excerpt because this is a protected post.' );
+ }
+
+ return apply_filters( 'get_the_excerpt', $this->post_excerpt );
+ }
+
+ public function has_excerpt() {
+ return !empty( $this->post_excerpt );
+ }
+
+ public function get_post_class( $class = '' ) {
+ $classes = array();
+
+ $object_vars = get_object_vars($this);
+ if ( empty( $object_vars ) )
+ return $classes;
+
+ $classes[] = 'post-' . $this->ID;
+ $classes[] = $this->post_type;
+ $classes[] = 'type-' . $this->post_type;
+ $classes[] = 'status-' . $this->post_status;
+
+ // Post Format
+ if ( post_type_supports( $this->post_type, 'post-formats' ) ) {
+ $post_format = get_post_format( $this->ID );
+
+ if ( $post_format && !is_wp_error($post_format) )
+ $classes[] = 'format-' . sanitize_html_class( $post_format );
+ else
+ $classes[] = 'format-standard';
+ }
+
+ // post requires password
+ if ( post_password_required($this->ID) )
+ $classes[] = 'post-password-required';
+
+ // sticky for Sticky Posts
+ if ( is_sticky($this->ID) && is_home() && !is_paged() )
+ $classes[] = 'sticky';
+
+ // hentry for hAtom compliance
+ $classes[] = 'hentry';
+
+ // Categories
+ if ( is_object_in_taxonomy( $this->post_type, 'category' ) ) {
+ foreach ( (array) get_the_category($this->ID) as $cat ) {
+ if ( empty($cat->slug ) )
+ continue;
+ $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->term_id);
+ }
+ }
+
+ // Tags
+ if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) {
+ foreach ( (array) get_the_tags($this->ID) as $tag ) {
+ if ( empty($tag->slug ) )
+ continue;
+ $classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id);
+ }
+ }
+
+ if ( !empty($class) ) {
+ if ( !is_array( $class ) )
+ $class = preg_split('#\s+#', $class);
+ $classes = array_merge($classes, $class);
+ }
+
+ $classes = array_map('esc_attr', $classes);
+
+ return apply_filters('post_class', $classes, $class, $this->ID);
+ }
+}
View
138 wp-includes/post-template.php
@@ -27,7 +27,7 @@ function the_ID() {
*/
function get_the_ID() {
global $post;
- return $post->ID;
+ return $post->get_ID();
}
/**
@@ -102,20 +102,7 @@ function the_title_attribute( $args = '' ) {
*/
function get_the_title( $id = 0 ) {
$post = &get_post($id);
-
- $title = isset($post->post_title) ? $post->post_title : '';
- $id = isset($post->ID) ? $post->ID : (int) $id;
-
- if ( !is_admin() ) {
- if ( !empty($post->post_password) ) {
- $protected_title_format = apply_filters('protected_title_format', __('Protected: %s'));
- $title = sprintf($protected_title_format, $title);
- } else if ( isset($post->post_status) && 'private' == $post->post_status ) {
- $private_title_format = apply_filters('private_title_format', __('Private: %s'));
- $title = sprintf($private_title_format, $title);
- }
- }
- return apply_filters( 'the_title', $title, $id );
+ return $post->get_title($id);
}
/**
@@ -149,8 +136,7 @@ function the_guid( $id = 0 ) {
*/
function get_the_guid( $id = 0 ) {
$post = &get_post($id);
-
- return apply_filters('get_the_guid', $post->guid);
+ return $post->get_guid($id);
}
/**
@@ -178,51 +164,8 @@ function the_content($more_link_text = null, $stripteaser = false) {
* @return string
*/
function get_the_content($more_link_text = null, $stripteaser = false) {
- global $post, $more, $page, $pages, $multipage, $preview;
-
- if ( null === $more_link_text )
- $more_link_text = __( '(more...)' );
-
- $output = '';
- $hasTeaser = false;
-
- // If post password required and it doesn't match the cookie.
- if ( post_password_required($post) )
- return get_the_password_form();
-
- if ( $page > count($pages) ) // if the requested page doesn't exist
- $page = count($pages); // give them the highest numbered page that DOES exist
-
- $content = $pages[$page-1];
- if ( preg_match('/<!--more(.*?)?-->/', $content, $matches) ) {
- $content = explode($matches[0], $content, 2);
- if ( !empty($matches[1]) && !empty($more_link_text) )
- $more_link_text = strip_tags(wp_kses_no_null(trim($matches[1])));
-
- $hasTeaser = true;
- } else {
- $content = array($content);
- }
- if ( (false !== strpos($post->post_content, '<!--noteaser-->') && ((!$multipage) || ($page==1))) )
- $stripteaser = true;
- $teaser = $content[0];
- if ( $more && $stripteaser && $hasTeaser )
- $teaser = '';
- $output .= $teaser;
- if ( count($content) > 1 ) {
- if ( $more ) {
- $output .= '<span id="more-' . $post->ID . '"></span>' . $content[1];
- } else {
- if ( ! empty($more_link_text) )
- $output .= apply_filters( 'the_content_more_link', ' <a href="' . get_permalink() . "#more-{$post->ID}\" class=\"more-link\">$more_link_text</a>", $more_link_text );
- $output = force_balance_tags($output);
- }
-
- }
- if ( $preview ) // preview fix for javascript bug with foreign languages
- $output = preg_replace_callback('/\%u([0-9A-F]{4})/', '_convert_urlencoded_to_entities', $output);
-
- return $output;
+ global $post;
+ return $post->get_content($more_link_text, $stripteaser);
}
/**
@@ -256,15 +199,8 @@ function the_excerpt() {
* @return string
*/
function get_the_excerpt( $deprecated = '' ) {
- if ( !empty( $deprecated ) )
- _deprecated_argument( __FUNCTION__, '2.3' );
-
global $post;
- if ( post_password_required($post) ) {
- return __( 'There is no excerpt because this is a protected post.' );
- }
-
- return apply_filters( 'get_the_excerpt', $post->post_excerpt );
+ return $post->get_excerpt($deprecated = '');
}
/**
@@ -277,7 +213,7 @@ function get_the_excerpt( $deprecated = '' ) {
*/
function has_excerpt( $id = 0 ) {
$post = &get_post( $id );
- return ( !empty( $post->post_excerpt ) );
+ return $post->has_excerpt();
}
/**
@@ -312,65 +248,7 @@ function post_class( $class = '', $post_id = null ) {
*/
function get_post_class( $class = '', $post_id = null ) {
$post = get_post($post_id);
-
- $classes = array();
-
- if ( empty($post) )
- return $classes;
-
- $classes[] = 'post-' . $post->ID;
- $classes[] = $post->post_type;
- $classes[] = 'type-' . $post->post_type;
- $classes[] = 'status-' . $post->post_status;
-
- // Post Format
- if ( post_type_supports( $post->post_type, 'post-formats' ) ) {
- $post_format = get_post_format( $post->ID );
-
- if ( $post_format && !is_wp_error($post_format) )
- $classes[] = 'format-' . sanitize_html_class( $post_format );
- else
- $classes[] = 'format-standard';
- }
-
- // post requires password
- if ( post_password_required($post->ID) )
- $classes[] = 'post-password-required';
-
- // sticky for Sticky Posts
- if ( is_sticky($post->ID) && is_home() && !is_paged() )
- $classes[] = 'sticky';
-
- // hentry for hAtom compliance
- $classes[] = 'hentry';
-
- // Categories
- if ( is_object_in_taxonomy( $post->post_type, 'category' ) ) {
- foreach ( (array) get_the_category($post->ID) as $cat ) {
- if ( empty($cat->slug ) )
- continue;
- $classes[] = 'category-' . sanitize_html_class($cat->slug, $cat->term_id);
- }
- }
-
- // Tags
- if ( is_object_in_taxonomy( $post->post_type, 'post_tag' ) ) {
- foreach ( (array) get_the_tags($post->ID) as $tag ) {
- if ( empty($tag->slug ) )
- continue;
- $classes[] = 'tag-' . sanitize_html_class($tag->slug, $tag->term_id);
- }
- }
-
- if ( !empty($class) ) {
- if ( !is_array( $class ) )
- $class = preg_split('#\s+#', $class);
- $classes = array_merge($classes, $class);
- }
-
- $classes = array_map('esc_attr', $classes);
-
- return apply_filters('post_class', $classes, $class, $post->ID);
+ return $post->get_post_class( $class );
}
/**
View
3 wp-includes/post.php
@@ -403,6 +403,7 @@ function &get_post(&$post, $output = OBJECT, $filter = 'raw') {
$_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wpdb->posts WHERE ID = %d LIMIT 1", $post_id));
if ( ! $_post )
return $null;
+ $_post = WP_Post::get_instance($_post);
_get_post_ancestors($_post);
$_post = sanitize_post($_post, 'raw');
wp_cache_add($_post->ID, $_post, 'posts');
@@ -5347,7 +5348,7 @@ function _prime_post_caches( $ids, $update_term_cache = true, $update_meta_cache
$non_cached_ids = _get_non_cached_ids( $ids, 'posts' );
if ( !empty( $non_cached_ids ) ) {
$fresh_posts = $wpdb->get_results( sprintf( "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE ID IN (%s)", join( ",", $non_cached_ids ) ) );
-
+ $fresh_posts = WP_Post::get_instances($fresh_posts);
update_post_caches( $fresh_posts, 'any', $update_term_cache, $update_meta_cache );
}
}
View
4 wp-includes/query.php
@@ -2660,6 +2660,10 @@ function &get_posts() {
if ( !$q['suppress_filters'] )
$this->posts = apply_filters_ref_array('posts_results', array( $this->posts, &$this ) );
+ if ( is_array($this->posts) ) {
+ $this->posts = WP_Post::get_instances( $this->posts );
+ }
+
if ( !empty($this->posts) && $this->is_comment_feed && $this->is_singular ) {
$cjoin = apply_filters_ref_array('comment_feed_join', array( '', &$this ) );
$cwhere = apply_filters_ref_array('comment_feed_where', array( "WHERE comment_post_ID = '{$this->posts[0]->ID}' AND comment_approved = '1'", &$this ) );
View
1 wp-settings.php
@@ -142,6 +142,7 @@
require( ABSPATH . WPINC . '/nav-menu.php' );
require( ABSPATH . WPINC . '/nav-menu-template.php' );
require( ABSPATH . WPINC . '/admin-bar.php' );
+require( ABSPATH . WPINC . '/class-wp-post.php' );
// Load multisite-specific files.
if ( is_multisite() ) {

No commit comments for this range

Something went wrong with that request. Please try again.