Add tags_input, page_template, and post_category get magic to WP_Post.
Deprecate get_post_to_edit() and wp_get_single_post(). Props scribu see #21309 git-svn-id: http://core.svn.wordpress.org/trunk@21651 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
bdec91100c
commit
52b3f498e6
|
@ -958,3 +958,19 @@ function _insert_into_post_button( $type ) {
|
|||
function _media_button($title, $icon, $type, $id) {
|
||||
_deprecated_function( __FUNCTION__, '3.5' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an existing post and format it for editing.
|
||||
*
|
||||
* @since 2.0.0
|
||||
* @deprecated 3.5.0
|
||||
*
|
||||
* @param int $id
|
||||
* @return object
|
||||
*/
|
||||
function get_post_to_edit( $id ) {
|
||||
_deprecated_function( __FUNCTION__, '3.5', 'get_post()' );
|
||||
|
||||
return get_post( $id, OBJECT, 'edit' );
|
||||
}
|
||||
|
||||
|
|
|
@ -463,24 +463,6 @@ function get_default_page_to_edit() {
|
|||
return $page;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an existing post and format it for editing.
|
||||
*
|
||||
* @since 2.0.0
|
||||
*
|
||||
* @param int $id
|
||||
* @return WP_Post
|
||||
*/
|
||||
function get_post_to_edit( $id ) {
|
||||
|
||||
$post = get_post( $id, OBJECT, 'edit' );
|
||||
|
||||
if ( $post->post_type == 'page' )
|
||||
$post->page_template = get_post_meta( $id, '_wp_page_template', true );
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if a post exists based on title, content, and date
|
||||
*
|
||||
|
|
|
@ -165,7 +165,7 @@ case 'edit':
|
|||
}
|
||||
|
||||
$title = $post_type_object->labels->edit_item;
|
||||
$post = get_post_to_edit($post_id);
|
||||
$post = get_post($post_id, OBJECT, 'edit');
|
||||
|
||||
if ( post_type_supports($post_type, 'comments') ) {
|
||||
wp_enqueue_script('admin-comments');
|
||||
|
|
|
@ -913,7 +913,7 @@ EOD;
|
|||
$this->not_found();
|
||||
}
|
||||
|
||||
$entry = wp_get_single_post($postID,ARRAY_A);
|
||||
$entry = get_post($postID,ARRAY_A);
|
||||
|
||||
if (!isset($entry) || !isset($entry['ID']))
|
||||
$this->not_found();
|
||||
|
@ -1410,7 +1410,7 @@ EOD;
|
|||
switch($this->params[0]) {
|
||||
case $this->ENTRY_PATH:
|
||||
global $post;
|
||||
$post = wp_get_single_post($this->params[1]);
|
||||
$post = get_post($this->params[1]);
|
||||
$wp_last_modified = get_post_modified_time('D, d M Y H:i:s', true);
|
||||
$post = null;
|
||||
break;
|
||||
|
|
|
@ -1256,7 +1256,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
|
||||
do_action( 'xmlrpc_call', 'wp.deletePost' );
|
||||
|
||||
$post = wp_get_single_post( $post_id, ARRAY_A );
|
||||
$post = get_post( $post_id, ARRAY_A );
|
||||
if ( empty( $post['ID'] ) )
|
||||
return new IXR_Error( 404, __( 'Invalid post ID.' ) );
|
||||
|
||||
|
@ -1286,7 +1286,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
* groups are 'post' (all basic fields), 'taxonomies', 'custom_fields',
|
||||
* and 'enclosure'.
|
||||
*
|
||||
* @uses wp_get_single_post()
|
||||
* @uses get_post()
|
||||
* @param array $args Method parameters. Contains:
|
||||
* - int $post_id
|
||||
* - string $username
|
||||
|
@ -1337,7 +1337,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
|
||||
do_action( 'xmlrpc_call', 'wp.getPost' );
|
||||
|
||||
$post = wp_get_single_post( $post_id, ARRAY_A );
|
||||
$post = get_post( $post_id, ARRAY_A );
|
||||
|
||||
if ( empty( $post['ID'] ) )
|
||||
return new IXR_Error( 404, __( 'Invalid post ID.' ) );
|
||||
|
@ -2060,7 +2060,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
|
||||
// Get the current page based on the page_id and
|
||||
// make sure it is a page and not a post.
|
||||
$actual_page = wp_get_single_post($page_id, ARRAY_A);
|
||||
$actual_page = get_post($page_id, ARRAY_A);
|
||||
if ( !$actual_page || ($actual_page['post_type'] != 'page') )
|
||||
return(new IXR_Error(404, __('Sorry, no such page.')));
|
||||
|
||||
|
@ -2101,7 +2101,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
do_action('xmlrpc_call', 'wp.editPage');
|
||||
|
||||
// Get the page data and make sure it is a page.
|
||||
$actual_page = wp_get_single_post($page_id, ARRAY_A);
|
||||
$actual_page = get_post($page_id, ARRAY_A);
|
||||
if ( !$actual_page || ($actual_page['post_type'] != 'page') )
|
||||
return(new IXR_Error(404, __('Sorry, no such page.')));
|
||||
|
||||
|
@ -3296,7 +3296,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
if ( !$user = $this->login($username, $password) )
|
||||
return $this->error;
|
||||
|
||||
$post_data = wp_get_single_post($post_ID, ARRAY_A);
|
||||
$post_data = get_post($post_ID, ARRAY_A);
|
||||
if ( ! $post_data )
|
||||
return new IXR_Error( 404, __( 'Invalid post ID.' ) );
|
||||
|
||||
|
@ -3538,7 +3538,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
|
||||
do_action('xmlrpc_call', 'blogger.editPost');
|
||||
|
||||
$actual_post = wp_get_single_post($post_ID,ARRAY_A);
|
||||
$actual_post = get_post($post_ID,ARRAY_A);
|
||||
|
||||
if ( !$actual_post || $actual_post['post_type'] != 'post' )
|
||||
return new IXR_Error(404, __('Sorry, no such post.'));
|
||||
|
@ -3592,7 +3592,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
|
||||
do_action('xmlrpc_call', 'blogger.deletePost');
|
||||
|
||||
$actual_post = wp_get_single_post($post_ID,ARRAY_A);
|
||||
$actual_post = get_post($post_ID,ARRAY_A);
|
||||
|
||||
if ( !$actual_post || $actual_post['post_type'] != 'post' )
|
||||
return new IXR_Error(404, __('Sorry, no such post.'));
|
||||
|
@ -3982,7 +3982,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
|
||||
do_action('xmlrpc_call', 'metaWeblog.editPost');
|
||||
|
||||
$postdata = wp_get_single_post( $post_ID, ARRAY_A );
|
||||
$postdata = get_post( $post_ID, ARRAY_A );
|
||||
|
||||
// If there is no post data for the give post id, stop
|
||||
// now and return an error. Other wise a new post will be
|
||||
|
@ -4247,7 +4247,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
if ( !$user = $this->login($username, $password) )
|
||||
return $this->error;
|
||||
|
||||
$postdata = wp_get_single_post($post_ID, ARRAY_A);
|
||||
$postdata = get_post($post_ID, ARRAY_A);
|
||||
if ( ! $postdata )
|
||||
return new IXR_Error( 404, __( 'Invalid post ID.' ) );
|
||||
|
||||
|
@ -4827,7 +4827,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
|
||||
do_action('xmlrpc_call', 'mt.getTrackbackPings');
|
||||
|
||||
$actual_post = wp_get_single_post($post_ID, ARRAY_A);
|
||||
$actual_post = get_post($post_ID, ARRAY_A);
|
||||
|
||||
if ( !$actual_post )
|
||||
return new IXR_Error(404, __('Sorry, no such post.'));
|
||||
|
@ -4874,7 +4874,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
|
||||
do_action('xmlrpc_call', 'mt.publishPost');
|
||||
|
||||
$postdata = wp_get_single_post($post_ID, ARRAY_A);
|
||||
$postdata = get_post($post_ID, ARRAY_A);
|
||||
if ( ! $postdata )
|
||||
return new IXR_Error( 404, __( 'Invalid post ID.' ) );
|
||||
|
||||
|
@ -5088,7 +5088,7 @@ class wp_xmlrpc_server extends IXR_Server {
|
|||
return new IXR_Error(33, __('The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.'));
|
||||
}
|
||||
|
||||
$actual_post = wp_get_single_post($post_ID, ARRAY_A);
|
||||
$actual_post = get_post($post_ID, ARRAY_A);
|
||||
|
||||
if ( !$actual_post ) {
|
||||
// No such post = resource not found
|
||||
|
|
|
@ -3204,3 +3204,23 @@ function sticky_class( $post_id = null ) {
|
|||
function _get_post_ancestors( &$post ) {
|
||||
_deprecated_function( __FUNCTION__, '3.5' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single post, based on post ID.
|
||||
*
|
||||
* Has categories in 'post_category' property or key. Has tags in 'tags_input'
|
||||
* property or key.
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @deprecated 3.5.0
|
||||
* @see get_post()
|
||||
*
|
||||
* @param int $postid Post ID.
|
||||
* @param string $mode How to return result, either OBJECT, ARRAY_N, or ARRAY_A.
|
||||
* @return object|array Post object or array holding post contents and information
|
||||
*/
|
||||
function wp_get_single_post( $postid = 0, $mode = OBJECT ) {
|
||||
_deprecated_function( __FUNCTION__, '3.5', 'get_post()' );
|
||||
return get_post( $postid, $mode, 'edit' );
|
||||
}
|
||||
|
||||
|
|
|
@ -475,10 +475,44 @@ final class WP_Post {
|
|||
if ( 'ancestors' == $key )
|
||||
return true;
|
||||
|
||||
if ( 'page_template' == $key )
|
||||
return ( 'page' == $this->post_type );
|
||||
|
||||
if ( 'post_category' == $key )
|
||||
return true;
|
||||
|
||||
if ( 'tags_input' == $key )
|
||||
return true;
|
||||
|
||||
return metadata_exists( 'post', $this->ID, $key );
|
||||
}
|
||||
|
||||
public function &__get( $key ) {
|
||||
if ( 'page_template' == $key && $this->__isset( $key ) ) {
|
||||
$_ref = get_post_meta( $this->ID, '_wp_page_template', true );
|
||||
}
|
||||
|
||||
if ( 'post_category' == $key ) {
|
||||
if ( is_object_in_taxonomy( $this->post_type, 'category' ) ) {
|
||||
$_ref = wp_get_post_categories( $this->ID );
|
||||
} else {
|
||||
$_ref = array();
|
||||
}
|
||||
}
|
||||
|
||||
if ( 'tags_input' == $key ) {
|
||||
if ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) {
|
||||
$_ref = wp_get_post_tags( $this->ID, array( 'fields' => 'names' ) );
|
||||
} else {
|
||||
$_ref = array();
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset( $_ref ) )
|
||||
return $_ref;
|
||||
|
||||
// Rest of the values need filtering
|
||||
|
||||
if ( 'ancestors' == $key ) {
|
||||
$value = get_post_ancestors( $this );
|
||||
} else {
|
||||
|
@ -504,7 +538,11 @@ final class WP_Post {
|
|||
|
||||
public function to_array() {
|
||||
$post = get_object_vars( $this );
|
||||
$post['ancestors'] = array();
|
||||
|
||||
foreach ( array( 'ancestors', 'page_template', 'post_category', 'tags_input' ) as $key ) {
|
||||
if ( $this->__isset( $key ) )
|
||||
$post[ $key ] = $this->__get( $key );
|
||||
}
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
@ -2226,7 +2264,7 @@ function wp_trash_post($post_id = 0) {
|
|||
if ( !EMPTY_TRASH_DAYS )
|
||||
return wp_delete_post($post_id, true);
|
||||
|
||||
if ( !$post = wp_get_single_post($post_id, ARRAY_A) )
|
||||
if ( !$post = get_post($post_id, ARRAY_A) )
|
||||
return $post;
|
||||
|
||||
if ( $post['post_status'] == 'trash' )
|
||||
|
@ -2258,7 +2296,7 @@ function wp_trash_post($post_id = 0) {
|
|||
* @return mixed False on failure
|
||||
*/
|
||||
function wp_untrash_post($post_id = 0) {
|
||||
if ( !$post = wp_get_single_post($post_id, ARRAY_A) )
|
||||
if ( !$post = get_post($post_id, ARRAY_A) )
|
||||
return $post;
|
||||
|
||||
if ( $post['post_status'] != 'trash' )
|
||||
|
@ -2488,49 +2526,6 @@ function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) {
|
|||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a single post, based on post ID.
|
||||
*
|
||||
* Has categories in 'post_category' property or key. Has tags in 'tags_input'
|
||||
* property or key.
|
||||
*
|
||||
* @since 1.0.0
|
||||
*
|
||||
* @param int $postid Post ID.
|
||||
* @param string $mode How to return result, either OBJECT, ARRAY_N, or ARRAY_A.
|
||||
* @return WP_Post|array WP_Post object or array holding post contents and information
|
||||
*/
|
||||
function wp_get_single_post($postid = 0, $mode = OBJECT) {
|
||||
$postid = (int) $postid;
|
||||
|
||||
$post = get_post($postid, $mode);
|
||||
|
||||
if (
|
||||
( OBJECT == $mode && empty( $post->ID ) ) ||
|
||||
( OBJECT != $mode && empty( $post['ID'] ) )
|
||||
)
|
||||
return ( OBJECT == $mode ? null : array() );
|
||||
|
||||
// Set categories and tags
|
||||
if ( $mode == OBJECT ) {
|
||||
$post->post_category = array();
|
||||
if ( is_object_in_taxonomy($post->post_type, 'category') )
|
||||
$post->post_category = wp_get_post_categories($postid);
|
||||
$post->tags_input = array();
|
||||
if ( is_object_in_taxonomy($post->post_type, 'post_tag') )
|
||||
$post->tags_input = wp_get_post_tags($postid, array('fields' => 'names'));
|
||||
} else {
|
||||
$post['post_category'] = array();
|
||||
if ( is_object_in_taxonomy($post['post_type'], 'category') )
|
||||
$post['post_category'] = wp_get_post_categories($postid);
|
||||
$post['tags_input'] = array();
|
||||
if ( is_object_in_taxonomy($post['post_type'], 'post_tag') )
|
||||
$post['tags_input'] = wp_get_post_tags($postid, array('fields' => 'names'));
|
||||
}
|
||||
|
||||
return $post;
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a post.
|
||||
*
|
||||
|
@ -2832,7 +2827,7 @@ function wp_update_post( $postarr = array(), $wp_error = false ) {
|
|||
}
|
||||
|
||||
// First, get all of the original fields
|
||||
$post = wp_get_single_post($postarr['ID'], ARRAY_A);
|
||||
$post = get_post($postarr['ID'], ARRAY_A);
|
||||
|
||||
// Escape data pulled from DB.
|
||||
$post = add_magic_quotes($post);
|
||||
|
@ -3241,7 +3236,7 @@ function get_to_ping($post_id) {
|
|||
function trackback_url_list($tb_list, $post_id) {
|
||||
if ( ! empty( $tb_list ) ) {
|
||||
// get post data
|
||||
$postdata = wp_get_single_post($post_id, ARRAY_A);
|
||||
$postdata = get_post($post_id, ARRAY_A);
|
||||
|
||||
// import postdata as variables
|
||||
extract($postdata, EXTR_SKIP);
|
||||
|
|
Loading…
Reference in New Issue