Make WordPress Core


Ignore:
Timestamp:
11/03/2014 03:03:30 AM (12 years ago)
Author:
wonderboymusic
Message:

Almost every method in wp_xmlrpc_server can also return IXR_Error and should be labeled as such. Rehabilitate some return syntax.

See #30224.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-xmlrpc-server.php

    r30153 r30181  
    2222 */
    2323class wp_xmlrpc_server extends IXR_Server {
    24 
     24        /**
     25         * @var array
     26         */
     27        public $methods;
     28        /**
     29         * @var array
     30         */
     31        public $blog_options;
     32        /**
     33         * @var IXR_Error
     34         */
     35        public $error;
    2536        /**
    2637         * Register all of the XMLRPC methods that XMLRPC server understands.
    … …  
    193204         * @param string $username User's username.
    194205         * @param string $password User's password.
    195          * @return mixed WP_User object if authentication passed, false otherwise
     206         * @return WP_User|bool WP_User object if authentication passed, false otherwise
    196207         */
    197208        public function login( $username, $password ) {
    … …  
    506517         *  - username
    507518         *  - password
    508          * @return array. Contains:
     519         * @return array|IXR_Error Array contains:
    509520         *  - 'isAdmin'
    510521         *  - 'url'
    … …  
    10901101         *      - enclosure
    10911102         *      - any other fields supported by wp_insert_post()
    1092          * @return string post_id
     1103         * @return string|IXR_Error post_id
    10931104         */
    10941105        public function wp_newPost( $args ) {
    … …  
    11461157         *
    11471158         * @param WP_User $user The post author if post_author isn't set in $content_struct.
    1148          * @param array $content_struct Post data to insert.
     1159         * @param array|IXR_Error $content_struct Post data to insert.
    11491160         */
    11501161        protected function _insert_post( $user, $content_struct ) {
    … …  
    13981409         *  - int     $post_id
    13991410         *  - array   $content_struct
    1400          * @return true on success
     1411         * @return bool|IXR_Error true on success
    14011412         */
    14021413        public function wp_editPost( $args ) {
    … …  
    14601471         *  - string  $password
    14611472         *  - int     $post_id
    1462          * @return true on success
     1473         * @return bool|IXR_Error true on success
    14631474         */
    14641475        public function wp_deletePost( $args ) {
    … …  
    15141525         *  - int     $post_id
    15151526         *  - array   $fields optional
    1516          * @return array contains (based on $fields parameter):
     1527         * @return array|IXR_Error Array contains (based on $fields parameter):
    15171528         *  - 'post_id'
    15181529         *  - 'post_title'
    … …  
    16011612         *  - array   $filter optional
    16021613         *  - array   $fields optional
    1603          * @return array contains a collection of posts.
     1614         * @return array|IXR_Error Array contains a collection of posts.
    16041615         */
    16051616        public function wp_getPosts( $args ) {
    … …  
    16971708         *      - 'description'
    16981709         *      - 'slug'
    1699          * @return string term_id
     1710         * @return string|IXR_Error term_id
    17001711         */
    17011712        public function wp_newTerm( $args ) {
    … …  
    17841795         *      - 'description'
    17851796         *      - 'slug'
    1786          * @return bool True, on success.
     1797         * @return bool|IXR_Error True, on success.
    17871798         */
    17881799        public function wp_editTerm( $args ) {
    … …  
    19341945         *  - string  $taxonomy
    19351946         *  - string  $term_id
    1936          * @return array contains:
     1947         * @return array|IXR_Error Array contains:
    19371948         *  - 'term_id'
    19381949         *  - 'name'
    … …  
    19962007         *  - string  $taxonomy
    19972008         *  - array   $filter optional
    1998          * @return array terms
     2009         * @return array|IXR_Error terms
    19992010         */
    20002011        public function wp_getTerms( $args ) {
    … …  
    20712082         *  - string  $password
    20722083         *  - string  $taxonomy
    2073          * @return array (@see get_taxonomy())
     2084         * @return array|IXR_Error (@see get_taxonomy())
    20742085         */
    20752086        public function wp_getTaxonomy( $args ) {
    … …  
    21832194         *  - int     $user_id
    21842195         *  - array   $fields optional
    2185          * @return array contains (based on $fields parameter):
     2196         * @return array|IXR_Error Array contains (based on $fields parameter):
    21862197         *  - 'user_id'
    21872198         *  - 'username'
    … …  
    22572268         *  - array   $filter optional
    22582269         *  - array   $fields optional
    2259          * @return array users data
     2270         * @return array|IXR_Error users data
    22602271         */
    22612272        public function wp_getUsers( $args ) {
    … …  
    23272338         *  - string  $password
    23282339         *  - array   $fields optional
    2329          * @return array (@see wp_getUser)
     2340         * @return array|IXR_Error (@see wp_getUser)
    23302341         */
    23312342        public function wp_getProfile( $args ) {
    … …  
    23762387         *      - 'nicename'
    23772388         *      - 'bio'
    2378          * @return bool True, on success.
     2389         * @return bool|IXR_Error True, on success.
    23792390         */
    23802391        public function wp_editProfile( $args ) {
    … …  
    24442455         *  - username
    24452456         *  - password
    2446          * @return array
     2457         * @return array|IXR_Error
    24472458         */
    24482459        public function wp_getPage($args) {
    … …  
    24872498         *  - password
    24882499         *  - num_pages
    2489          * @return array
     2500         * @return array|IXR_Error
    24902501         */
    24912502        public function wp_getPages($args) {
    … …  
    25172528                        }
    25182529
    2519                         return($pages_struct);
    2520                 }
    2521                 // If no pages were found return an error.
    2522                 else {
    2523                         return(array());
    2524                 }
     2530                        return $pages_struct;
     2531                }
     2532
     2533                return array();
    25252534        }
    25262535
    … …  
    25312540         *
    25322541         * @param array $args Method parameters. See {@link wp_xmlrpc_server::mw_newPost()}
    2533          * @return unknown
     2542         * @return int|IXR_Error
    25342543         */
    25352544        public function wp_newPage($args) {
    … …  
    25502559
    25512560                // Let mw_newPost do all of the heavy lifting.
    2552                 return($this->mw_newPost($args));
     2561                return $this->mw_newPost( $args );
    25532562        }
    25542563
    … …  
    25592568         *
    25602569         * @param array $args Method parameters.
    2561          * @return bool True, if success.
     2570         * @return bool|IXR_Error True, if success.
    25622571         */
    25632572        public function wp_deletePage($args) {
    … …  
    25782587                $actual_page = get_post($page_id, ARRAY_A);
    25792588                if ( !$actual_page || ($actual_page['post_type'] != 'page') )
    2580                         return(new IXR_Error(404, __('Sorry, no such page.')));
     2589                        return new IXR_Error( 404, __( 'Sorry, no such page.' ) );
    25812590
    25822591                // Make sure the user can delete pages.
    25832592                if ( !current_user_can('delete_page', $page_id) )
    2584                         return(new IXR_Error(401, __('Sorry, you do not have the right to delete this page.')));
     2593                        return new IXR_Error( 401, __( 'Sorry, you do not have the right to delete this page.' ) );
    25852594
    25862595                // Attempt to delete the page.
    25872596                $result = wp_delete_post($page_id);
    25882597                if ( !$result )
    2589                         return(new IXR_Error(500, __('Failed to delete the page.')));
     2598                        return new IXR_Error( 500, __( 'Failed to delete the page.' ) );
    25902599
    25912600                /**
    … …  
    25992608                do_action( 'xmlrpc_call_success_wp_deletePage', $page_id, $args );
    26002609
    2601                 return(true);
     2610                return true;
    26022611        }
    26032612
    … …  
    26082617         *
    26092618         * @param array $args Method parameters.
    2610          * @return unknown
     2619         * @return array|IXR_Error
    26112620         */
    26122621        public function wp_editPage($args) {
    … …  
    26272636                $actual_page = get_post($page_id, ARRAY_A);
    26282637                if ( !$actual_page || ($actual_page['post_type'] != 'page') )
    2629                         return(new IXR_Error(404, __('Sorry, no such page.')));
     2638                        return new IXR_Error( 404, __( 'Sorry, no such page.' ) );
    26302639
    26312640                // Make sure the user is allowed to edit pages.
    26322641                if ( !current_user_can('edit_page', $page_id) )
    2633                         return(new IXR_Error(401, __('Sorry, you do not have the right to edit this page.')));
     2642                        return new IXR_Error( 401, __( 'Sorry, you do not have the right to edit this page.' ) );
    26342643
    26352644                // Mark this as content for a page.
    … …  
    26462655
    26472656                // Let mw_editPost do all of the heavy lifting.
    2648                 return($this->mw_editPost($args));
     2657                return $this->mw_editPost( $args );
    26492658        }
    26502659
    … …  
    26552664         *
    26562665         * @param array $args Method parameters.
    2657          * @return unknown
     2666         * @return array|IXR_Error
    26582667         */
    26592668        public function wp_getPageList($args) {
    … …  
    26982707                }
    26992708
    2700                 return($page_list);
     2709                return $page_list;
    27012710        }
    27022711
    … …  
    27072716         *
    27082717         * @param array $args Method parameters.
    2709          * @return array
     2718         * @return array|IXR_Error
    27102719         */
    27112720        public function wp_getAuthors($args) {
    … …  
    27202729
    27212730                if ( !current_user_can('edit_posts') )
    2722                         return(new IXR_Error(401, __('Sorry, you cannot edit posts on this site.')));
     2731                        return new IXR_Error( 401, __( 'Sorry, you cannot edit posts on this site.' ) );
    27232732
    27242733                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    … …  
    27432752         *
    27442753         * @param array $args Method parameters.
    2745          * @return array
     2754         * @return array|IXR_Error
    27462755         */
    27472756        public function wp_getTags( $args ) {
    … …  
    27852794         *
    27862795         * @param array $args Method parameters.
    2787          * @return int Category ID.
     2796         * @return int|IXR_Error Category ID.
    27882797         */
    27892798        public function wp_newCategory($args) {
    … …  
    28022811                // Make sure the user is allowed to add a category.
    28032812                if ( !current_user_can('manage_categories') )
    2804                         return(new IXR_Error(401, __('Sorry, you do not have the right to add a category.')));
     2813                        return new IXR_Error(401, __('Sorry, you do not have the right to add a category.'));
    28052814
    28062815                // If no slug was provided make it empty so that
    … …  
    28302839                                return (int) $cat_id->get_error_data();
    28312840                        else
    2832                                 return(new IXR_Error(500, __('Sorry, the new category failed.')));
     2841                                return new IXR_Error(500, __('Sorry, the new category failed.'));
    28332842                } elseif ( ! $cat_id ) {
    2834                         return(new IXR_Error(500, __('Sorry, the new category failed.')));
     2843                        return new IXR_Error(500, __('Sorry, the new category failed.'));
    28352844                }
    28362845
    … …  
    28542863         *
    28552864         * @param array $args Method parameters.
    2856          * @return mixed See {@link wp_delete_term()} for return info.
     2865         * @return bool|IXR_Error See {@link wp_delete_term()} for return info.
    28572866         */
    28582867        public function wp_deleteCategory($args) {
    … …  
    28952904         *
    28962905         * @param array $args Method parameters.
    2897          * @return array
     2906         * @return array|IXR_Error
    28982907         */
    28992908        public function wp_suggestCategories($args) {
    … …  
    29232932                }
    29242933
    2925                 return($category_suggestions);
     2934                return $category_suggestions;
    29262935        }
    29272936
    … …  
    29322941         *
    29332942         * @param array $args Method parameters.
    2934          * @return array
     2943         * @return array|IXR_Error
    29352944         */
    29362945        public function wp_getComment($args) {
    … …  
    29732982         *
    29742983         * @param array $args Method parameters.
    2975          * @return array. Contains a collection of comments. See {@link wp_xmlrpc_server::wp_getComment()} for a description of each item contents
     2984         * @return array|IXR_Error Contains a collection of comments. See {@link wp_xmlrpc_server::wp_getComment()} for a description of each item contents
    29762985         */
    29772986        public function wp_getComments($args) {
    … …  
    30333042         *  - password
    30343043         *  - comment_id
    3035          * @return mixed {@link wp_delete_comment()}
     3044         * @return bool|IXR_Error {@link wp_delete_comment()}
    30363045         */
    30373046        public function wp_deleteComment($args) {
    … …  
    30963105         *  - comment_id
    30973106         *  - content_struct
    3098          * @return bool True, on success.
     3107         * @return bool|IXR_Error True, on success.
    30993108         */
    31003109        public function wp_editComment($args) {
    … …  
    31793188         *
    31803189         * @param array $args Method parameters.
    3181          * @return mixed {@link wp_new_comment()}
     3190         * @return int|IXR_Error {@link wp_new_comment()}
    31823191         */
    31833192        public function wp_newComment($args) {
    … …  
    32813290         *
    32823291         * @param array $args Method parameters.
    3283          * @return array
     3292         * @return array|IXR_Error
    32843293         */
    32853294        public function wp_getCommentStatusList($args) {
    … …  
    33073316         *
    33083317         * @param array $args Method parameters.
    3309          * @return array
     3318         * @return array|IXR_Error
    33103319         */
    33113320        public function wp_getCommentCount( $args ) {
    … …  
    33403349         *
    33413350         * @param array $args Method parameters.
    3342          * @return array
     3351         * @return array|IXR_Error
    33433352         */
    33443353        public function wp_getPostStatusList( $args ) {
    … …  
    33663375         *
    33673376         * @param array $args Method parameters.
    3368          * @return array
     3377         * @return array|IXR_Error
    33693378         */
    33703379        public function wp_getPageStatusList( $args ) {
    … …  
    33923401         *
    33933402         * @param array $args Method parameters.
    3394          * @return array
     3403         * @return array|IXR_Error
    33953404         */
    33963405        public function wp_getPageTemplates( $args ) {
    … …  
    34183427         *
    34193428         * @param array $args Method parameters.
    3420          * @return array
     3429         * @return array|IXR_Error
    34213430         */
    34223431        public function wp_getOptions( $args ) {
    … …  
    34713480         *
    34723481         * @param array $args Method parameters.
    3473          * @return unknown
     3482         * @return array|IXR_Error
    34743483         */
    34753484        public function wp_setOptions( $args ) {
    … …  
    35123521         *  - password
    35133522         *  - attachment_id
    3514          * @return array. Associative array containing:
     3523         * @return array|IXR_Error Associative array contains:
    35153524         *  - 'date_created_gmt'
    35163525         *  - 'parent'
    … …  
    35653574         *  - password
    35663575         *  - filter
    3567          * @return array. Contains a collection of media items. See {@link wp_xmlrpc_server::wp_getMediaItem()} for a description of each item contents
     3576         * @return array|IXR_Error Contains a collection of media items. See {@link wp_xmlrpc_server::wp_getMediaItem()} for a description of each item contents
    35683577         */
    35693578        public function wp_getMediaLibrary($args) {
    … …  
    36073616          *  - username
    36083617          *  - password
    3609           * @return array
     3618          * @return array|IXR_Error
    36103619          */
    36113620        public function wp_getPostFormats( $args ) {
    … …  
    36563665         *  - string  $post_type_name
    36573666         *  - array   $fields
    3658          * @return array contains:
     3667         * @return array|IXR_Error Array contains:
    36593668         *  - 'labels'
    36603669         *  - 'description'
    … …  
    37203729         *  - array   $filter
    37213730         *  - array   $fields
    3722          * @return array
     3731         * @return array|IXR_Error
    37233732         */
    37243733        public function wp_getPostTypes( $args ) {
    … …  
    37763785         *  - int     $post_id
    37773786         *  - array   $fields
    3778          * @return array contains a collection of posts.
     3787         * @return array|IXR_Error contains a collection of posts.
    37793788         */
    37803789        public function wp_getRevisions( $args ) {
    … …  
    38513860         *  - string  $password
    38523861         *  - int     $post_id
    3853          * @return bool false if there was an error restoring, true if success.
     3862         * @return bool|IXR_Error false if there was an error restoring, true if success.
    38543863         */
    38553864        public function wp_restoreRevision( $args ) {
    … …  
    39023911         *
    39033912         * @param array $args Method parameters.
    3904          * @return array
     3913         * @return array|IXR_Error
    39053914         */
    39063915        public function blogger_getUsersBlogs($args) {
    … …  
    39363945         *
    39373946         * @access protected
     3947         *
     3948         * @return array|IXR_Error
    39383949         */
    39393950        protected function _multisite_getUsersBlogs($args) {
    … …  
    39693980         *
    39703981         * @param array $args Method parameters.
    3971          * @return array
     3982         * @return array|IXR_Error
    39723983         */
    39733984        public function blogger_getUserInfo($args) {
    … …  
    40044015         *
    40054016         * @param array $args Method parameters.
    4006          * @return array
     4017         * @return array|IXR_Error
    40074018         */
    40084019        public function blogger_getPost($args) {
    … …  
    40494060         *
    40504061         * @param array $args Method parameters.
    4051          * @return array
     4062         * @return array|IXR_Error
    40524063         */
    40534064        public function blogger_getRecentPosts($args) {
    … …  
    41074118         * @since 1.5.0
    41084119         * @deprecated 3.5.0
     4120         * @return IXR_Error
    41094121         */
    41104122        public function blogger_getTemplate($args) {
    … …  
    41174129         * @since 1.5.0
    41184130         * @deprecated 3.5.0
     4131         * @return IXR_Error
    41194132         */
    41204133        public function blogger_setTemplate($args) {
    … …  
    41284141         *
    41294142         * @param array $args Method parameters.
    4130          * @return int
     4143         * @return int|IXR_Error
    41314144         */
    41324145        public function blogger_newPost($args) {
    … …  
    41904203         *
    41914204         * @param array $args Method parameters.
    4192          * @return bool true when done.
     4205         * @return bool|IXR_Error true when done.
    41934206         */
    41944207        public function blogger_editPost( $args ) {
    … …  
    42584271         *
    42594272         * @param array $args Method parameters.
    4260          * @return bool True when post is deleted.
     4273         * @return bool|IXR_Error True when post is deleted.
    42614274         */
    42624275        public function blogger_deletePost($args) {
    … …  
    43374350         *  - content_struct
    43384351         *  - publish
    4339          * @return int
     4352         * @return int|IXR_Error
    43404353         */
    43414354        public function mw_newPost($args) {
    … …  
    44284441                                case "post":
    44294442                                        if ( !current_user_can( 'edit_others_posts' ) )
    4430                                                 return( new IXR_Error( 401, __( 'You are not allowed to create posts as this user.' ) ) );
     4443                                                return new IXR_Error( 401, __( 'You are not allowed to create posts as this user.' ) );
    44314444                                        break;
    44324445                                case "page":
    44334446                                        if ( !current_user_can( 'edit_others_pages' ) )
    4434                                                 return( new IXR_Error( 401, __( 'You are not allowed to create pages as this user.' ) ) );
     4447                                                return new IXR_Error( 401, __( 'You are not allowed to create pages as this user.' ) );
    44354448                                        break;
    44364449                                default:
    4437                                         return( new IXR_Error( 401, __( 'Invalid post type' ) ) );
     4450                                        return new IXR_Error( 401, __( 'Invalid post type' ) );
    44384451                                        break;
    44394452                        }
    … …  
    46634676         *
    46644677         * @param array $args Method parameters.
    4665          * @return bool True on success.
     4678         * @return bool|IXR_Error True on success.
    46664679         */
    46674680        public function mw_editPost($args) {
    … …  
    47484761                                case 'post':
    47494762                                        if ( !current_user_can('edit_others_posts') )
    4750                                                 return(new IXR_Error(401, __('You are not allowed to change the post author as this user.')));
     4763                                                return new IXR_Error( 401, __( 'You are not allowed to change the post author as this user.' ) );
    47514764                                        break;
    47524765                                case 'page':
    47534766                                        if ( !current_user_can('edit_others_pages') )
    4754                                                 return(new IXR_Error(401, __('You are not allowed to change the page author as this user.')));
     4767                                                return new IXR_Error( 401, __( 'You are not allowed to change the page author as this user.' ) );
    47554768                                        break;
    47564769                                default:
    4757                                         return(new IXR_Error(401, __('Invalid post type')));
     4770                                        return new IXR_Error( 401, __( 'Invalid post type' ) );
    47584771                                        break;
    47594772                        }
    … …  
    49504963         *
    49514964         * @param array $args Method parameters.
    4952          * @return array
     4965         * @return array|IXR_Error
    49534966         */
    49544967        public function mw_getPost($args) {
    … …  
    50755088         *
    50765089         * @param array $args Method parameters.
    5077          * @return array
     5090         * @return array|IXR_Error
    50785091         */
    50795092        public function mw_getRecentPosts($args) {
    … …  
    51875200         *
    51885201         * @param array $args Method parameters.
    5189          * @return array
     5202         * @return array|IXR_Error
    51905203         */
    51915204        public function mw_getCategories($args) {
    … …  
    52355248         *
    52365249         * @param array $args Method parameters.
    5237          * @return array
     5250         * @return array|IXR_Error
    52385251         */
    52395252        public function mw_newMediaObject($args) {
    … …  
    53485361         *
    53495362         * @param array $args Method parameters.
    5350          * @return array
     5363         * @return array|IXR_Error
    53515364         */
    53525365        public function mt_getRecentPostTitles($args) {
    … …  
    53745387                }
    53755388
    5376                 $struct = array();
     5389                $recent_posts = array();
    53775390
    53785391                foreach ($posts_list as $entry) {
    … …  
    53835396                        $post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] );
    53845397
    5385                         $struct[] = array(
     5398                        $recent_posts[] = array(
    53865399                                'dateCreated' => $post_date,
    53875400                                'userid' => $entry['post_author'],
    … …  
    53915404                                'date_created_gmt' => $post_date_gmt
    53925405                        );
    5393 
    5394                 }
    5395 
    5396                 $recent_posts = array();
    5397                 for ( $j=0; $j<count($struct); $j++ ) {
    5398                         array_push($recent_posts, $struct[$j]);
    53995406                }
    54005407
    … …  
    54085415         *
    54095416         * @param array $args Method parameters.
    5410          * @return array
     5417         * @return array|IXR_Error
    54115418         */
    54125419        public function mt_getCategoryList($args) {
    … …  
    54475454         *
    54485455         * @param array $args Method parameters.
    5449          * @return array
     5456         * @return array|IXR_Error
    54505457         */
    54515458        public function mt_getPostCategories($args) {
    … …  
    54915498         *
    54925499         * @param array $args Method parameters.
    5493          * @return bool True on success.
     5500         * @return bool|IXR_Error True on success.
    54945501         */
    54955502        public function mt_setPostCategories($args) {
    … …  
    55725579         *
    55735580         * @param array $args Method parameters.
    5574          * @return mixed
     5581         * @return array|IXR_Error
    55755582         */
    55765583        public function mt_getTrackbackPings($args) {
    … …  
    56155622         *
    56165623         * @param array $args Method parameters.
    5617          * @return int
     5624         * @return int|IXR_Error
    56185625         */
    56195626        public function mt_publishPost($args) {
    … …  
    56605667         *
    56615668         * @param array $args Method parameters.
    5662          * @return array
     5669         * @return string|IXR_Error
    56635670         */
    56645671        public function pingback_ping($args) {
    … …  
    58685875         *
    58695876         * @param array $args Method parameters.
    5870          * @return array
     5877         * @return array|IXR_Error
    58715878         */
    58725879        public function pingback_extensions_getPingbacks($args) {
Note: See TracChangeset for help on using the changeset viewer.