WordPress.org

Make WordPress Core

Ticket #21309: post-to-edit.diff

File post-to-edit.diff, 6.4 KB (added by scribu, 10 months ago)
  • wp-admin/includes/deprecated.php

    diff --git wp-admin/includes/deprecated.php wp-admin/includes/deprecated.php
    index 6a66e43..bc49030 100644
    function current_theme_info() { 
    943943 
    944944/** 
    945945 * This was once used to display an 'Insert into Post' button. Now it is deprecated and stubbed. 
    946  *  
     946 * 
    947947 * @deprecated 3.5.0 
    948948 */ 
    949949function _insert_into_post_button( $type ) { 
    function _insert_into_post_button( $type ) { 
    952952 
    953953/** 
    954954 * This was once used to display a media button. Now it is deprecated and stubbed. 
    955  *  
     955 * 
    956956 * @deprecated 3.5.0 
    957957 */ 
    958958function _media_button($title, $icon, $type, $id) { 
    959959        _deprecated_function( __FUNCTION__, '3.5' ); 
    960960} 
     961 
     962/** 
     963 * Get an existing post and format it for editing. 
     964 * 
     965 * @since 2.0.0 
     966 * @deprecated 3.5.0 
     967 * 
     968 * @param int $id 
     969 * @return object 
     970 */ 
     971function get_post_to_edit( $id ) { 
     972        _deprecated_function( __FUNCTION__, '3.5', 'get_post()' ); 
     973 
     974        return get_post( $id, OBJECT, 'edit' ); 
     975} 
     976 
  • wp-admin/includes/post.php

    diff --git wp-admin/includes/post.php wp-admin/includes/post.php
    index c57b72c..7ee873d 100644
    function get_default_page_to_edit() { 
    463463} 
    464464 
    465465/** 
    466  * Get an existing post and format it for editing. 
    467  * 
    468  * @since 2.0.0 
    469  * 
    470  * @param unknown_type $id 
    471  * @return unknown 
    472  */ 
    473 function get_post_to_edit( $id ) { 
    474  
    475         $post = get_post( $id, OBJECT, 'edit' ); 
    476  
    477         if ( $post->post_type == 'page' ) 
    478                 $post->page_template = get_post_meta( $id, '_wp_page_template', true ); 
    479  
    480         return $post; 
    481 } 
    482  
    483 /** 
    484466 * Determine if a post exists based on title, content, and date 
    485467 * 
    486468 * @since 2.0.0 
    function get_available_post_mime_types($type = 'attachment') { 
    927909/** 
    928910 * Executes a query for attachments. An array of WP_Query arguments 
    929911 * can be passed in, which will override the arguments set by this function. 
    930  *  
     912 * 
    931913 * @since 2.5.0 
    932914 * @uses apply_filters() Calls 'upload_per_page' on posts_per_page argument 
    933915 * 
  • wp-includes/deprecated.php

    diff --git wp-includes/deprecated.php wp-includes/deprecated.php
    index def4722..3deb0e3 100644
    function sticky_class( $post_id = null ) { 
    32033203 */ 
    32043204function _get_post_ancestors( &$post ) { 
    32053205        _deprecated_function( __FUNCTION__, '3.5' ); 
    3206 } 
    3207  No newline at end of file 
     3206} 
     3207 
     3208/** 
     3209 * Retrieve a single post, based on post ID. 
     3210 * 
     3211 * Has categories in 'post_category' property or key. Has tags in 'tags_input' 
     3212 * property or key. 
     3213 * 
     3214 * @since 1.0.0 
     3215 * @deprecated 3.5.0 
     3216 * @see get_post() 
     3217 * 
     3218 * @param int $postid Post ID. 
     3219 * @param string $mode How to return result, either OBJECT, ARRAY_N, or ARRAY_A. 
     3220 * @return object|array Post object or array holding post contents and information 
     3221 */ 
     3222function wp_get_single_post( $postid = 0, $mode = OBJECT ) { 
     3223        _deprecated_function( __FUNCTION__, '3.5', 'get_post()' ); 
     3224        return get_post( $postid, $mode, 'edit' ); 
     3225} 
     3226 
  • wp-includes/post.php

    diff --git wp-includes/post.php wp-includes/post.php
    index 7aed6b5..39b632e 100644
    function get_post( $post, $output = OBJECT, $filter = 'raw' ) { 
    402402 
    403403        $_post = $_post->filter( $filter ); 
    404404 
     405        if ( 'edit' == $filter ) 
     406                $_post = new WP_Post_To_Edit( $_post ); 
     407 
    405408        if ( $output == ARRAY_A ) 
    406409                return $_post->to_array(); 
    407410        elseif ( $output == ARRAY_N ) 
    function get_post( $post, $output = OBJECT, $filter = 'raw' ) { 
    440443 * @property $comment_count; 
    441444 * @property $ancestors; 
    442445 */ 
    443 final class WP_Post { 
     446class WP_Post { 
    444447 
    445448        public $filter; 
    446449 
    final class WP_Post { 
    511514} 
    512515 
    513516/** 
     517 * A WP_Post class, with added magic 
     518 */ 
     519class WP_Post_To_Edit extends WP_Post { 
     520 
     521        public function __isset( $key ) { 
     522                if ( 'page_template' == $key ) 
     523                        return ( 'page' == $this->post_type ); 
     524 
     525                if ( 'post_category' == $key ) 
     526                   return true; 
     527 
     528                if ( 'tags_input' == $key ) 
     529                   return true; 
     530 
     531                return parent::__isset( $key ); 
     532        } 
     533 
     534        public function __get( $key ) { 
     535                if ( 'page_template' == $key && $this->__isset( $key ) ) 
     536                        return get_post_meta( $this->ID, '_wp_page_template', true ); 
     537 
     538                if ( 'post_category' == $key ) { 
     539                        if  ( is_object_in_taxonomy( $this->post_type, 'category' ) ) 
     540                                return wp_get_post_categories( $this->ID ); 
     541 
     542                        return array(); 
     543                } 
     544 
     545                if ( 'tags_input' == $key && $this->__isset( $key ) ) { 
     546                        if  ( is_object_in_taxonomy( $this->post_type, 'post_tag' ) ) 
     547                                return wp_get_post_tags( $this->ID, array( 'fields' => 'names' ) ); 
     548 
     549                        return array(); 
     550                } 
     551 
     552                return parent::__get( $key ); 
     553        } 
     554 
     555        public function to_array() { 
     556                $post = parent::to_array(); 
     557 
     558                foreach ( array( 'page_template', 'post_category', 'tags_input' ) as $key ) { 
     559                        if ( $this->__isset( $key ) ) 
     560                                $post['page_template'] = $this->__get( $key ); 
     561                } 
     562 
     563                return $post; 
     564        } 
     565} 
     566 
     567/** 
    514568 * Retrieve ancestors of a post. 
    515569 * 
    516570 * @since 2.5.0 
    function wp_get_recent_posts( $args = array(), $output = ARRAY_A ) { 
    24892543} 
    24902544 
    24912545/** 
    2492  * Retrieve a single post, based on post ID. 
    2493  * 
    2494  * Has categories in 'post_category' property or key. Has tags in 'tags_input' 
    2495  * property or key. 
    2496  * 
    2497  * @since 1.0.0 
    2498  * 
    2499  * @param int $postid Post ID. 
    2500  * @param string $mode How to return result, either OBJECT, ARRAY_N, or ARRAY_A. 
    2501  * @return object|array Post object or array holding post contents and information 
    2502  */ 
    2503 function wp_get_single_post($postid = 0, $mode = OBJECT) { 
    2504         $postid = (int) $postid; 
    2505  
    2506         $post = get_post($postid, $mode); 
    2507  
    2508         if ( 
    2509                 ( OBJECT == $mode && empty( $post->ID ) ) || 
    2510                 ( OBJECT != $mode && empty( $post['ID'] ) ) 
    2511         ) 
    2512                 return ( OBJECT == $mode ? null : array() ); 
    2513  
    2514         // Set categories and tags 
    2515         if ( $mode == OBJECT ) { 
    2516                 $post->post_category = array(); 
    2517                 if ( is_object_in_taxonomy($post->post_type, 'category') ) 
    2518                         $post->post_category = wp_get_post_categories($postid); 
    2519                 $post->tags_input = array(); 
    2520                 if ( is_object_in_taxonomy($post->post_type, 'post_tag') ) 
    2521                         $post->tags_input = wp_get_post_tags($postid, array('fields' => 'names')); 
    2522         } else { 
    2523                 $post['post_category'] = array(); 
    2524                 if ( is_object_in_taxonomy($post['post_type'], 'category') ) 
    2525                         $post['post_category'] = wp_get_post_categories($postid); 
    2526                 $post['tags_input'] = array(); 
    2527                 if ( is_object_in_taxonomy($post['post_type'], 'post_tag') ) 
    2528                         $post['tags_input'] = wp_get_post_tags($postid, array('fields' => 'names')); 
    2529         } 
    2530  
    2531         return $post; 
    2532 } 
    2533  
    2534 /** 
    25352546 * Insert a post. 
    25362547 * 
    25372548 * If the $postarr parameter has 'ID' set to a value, then post will be updated.