Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (9 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

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

    r42201 r42343  
    6262                $this->methods = array(
    6363                        // WordPress API
    64                         'wp.getUsersBlogs'              => 'this:wp_getUsersBlogs',
    65                         'wp.newPost'                    => 'this:wp_newPost',
    66                         'wp.editPost'                   => 'this:wp_editPost',
    67                         'wp.deletePost'                 => 'this:wp_deletePost',
    68                         'wp.getPost'                    => 'this:wp_getPost',
    69                         'wp.getPosts'                   => 'this:wp_getPosts',
    70                         'wp.newTerm'                    => 'this:wp_newTerm',
    71                         'wp.editTerm'                   => 'this:wp_editTerm',
    72                         'wp.deleteTerm'                 => 'this:wp_deleteTerm',
    73                         'wp.getTerm'                    => 'this:wp_getTerm',
    74                         'wp.getTerms'                   => 'this:wp_getTerms',
    75                         'wp.getTaxonomy'                => 'this:wp_getTaxonomy',
    76                         'wp.getTaxonomies'              => 'this:wp_getTaxonomies',
    77                         'wp.getUser'                    => 'this:wp_getUser',
    78                         'wp.getUsers'                   => 'this:wp_getUsers',
    79                         'wp.getProfile'                 => 'this:wp_getProfile',
    80                         'wp.editProfile'                => 'this:wp_editProfile',
    81                         'wp.getPage'                    => 'this:wp_getPage',
    82                         'wp.getPages'                   => 'this:wp_getPages',
    83                         'wp.newPage'                    => 'this:wp_newPage',
    84                         'wp.deletePage'                 => 'this:wp_deletePage',
    85                         'wp.editPage'                   => 'this:wp_editPage',
    86                         'wp.getPageList'                => 'this:wp_getPageList',
    87                         'wp.getAuthors'                 => 'this:wp_getAuthors',
    88                         'wp.getCategories'              => 'this:mw_getCategories',             // Alias
    89                         'wp.getTags'                    => 'this:wp_getTags',
    90                         'wp.newCategory'                => 'this:wp_newCategory',
    91                         'wp.deleteCategory'             => 'this:wp_deleteCategory',
    92                         'wp.suggestCategories'  => 'this:wp_suggestCategories',
    93                         'wp.uploadFile'                 => 'this:mw_newMediaObject',    // Alias
    94                         'wp.deleteFile'                 => 'this:wp_deletePost',                // Alias
    95                         'wp.getCommentCount'    => 'this:wp_getCommentCount',
    96                         'wp.getPostStatusList'  => 'this:wp_getPostStatusList',
    97                         'wp.getPageStatusList'  => 'this:wp_getPageStatusList',
    98                         'wp.getPageTemplates'   => 'this:wp_getPageTemplates',
    99                         'wp.getOptions'                 => 'this:wp_getOptions',
    100                         'wp.setOptions'                 => 'this:wp_setOptions',
    101                         'wp.getComment'                 => 'this:wp_getComment',
    102                         'wp.getComments'                => 'this:wp_getComments',
    103                         'wp.deleteComment'              => 'this:wp_deleteComment',
    104                         'wp.editComment'                => 'this:wp_editComment',
    105                         'wp.newComment'                 => 'this:wp_newComment',
    106                         'wp.getCommentStatusList' => 'this:wp_getCommentStatusList',
    107                         'wp.getMediaItem'               => 'this:wp_getMediaItem',
    108                         'wp.getMediaLibrary'    => 'this:wp_getMediaLibrary',
    109                         'wp.getPostFormats'     => 'this:wp_getPostFormats',
    110                         'wp.getPostType'                => 'this:wp_getPostType',
    111                         'wp.getPostTypes'               => 'this:wp_getPostTypes',
    112                         'wp.getRevisions'               => 'this:wp_getRevisions',
    113                         'wp.restoreRevision'    => 'this:wp_restoreRevision',
     64                        'wp.getUsersBlogs'                 => 'this:wp_getUsersBlogs',
     65                        'wp.newPost'                       => 'this:wp_newPost',
     66                        'wp.editPost'                      => 'this:wp_editPost',
     67                        'wp.deletePost'                    => 'this:wp_deletePost',
     68                        'wp.getPost'                       => 'this:wp_getPost',
     69                        'wp.getPosts'                      => 'this:wp_getPosts',
     70                        'wp.newTerm'                       => 'this:wp_newTerm',
     71                        'wp.editTerm'                      => 'this:wp_editTerm',
     72                        'wp.deleteTerm'                    => 'this:wp_deleteTerm',
     73                        'wp.getTerm'                       => 'this:wp_getTerm',
     74                        'wp.getTerms'                      => 'this:wp_getTerms',
     75                        'wp.getTaxonomy'                   => 'this:wp_getTaxonomy',
     76                        'wp.getTaxonomies'                 => 'this:wp_getTaxonomies',
     77                        'wp.getUser'                       => 'this:wp_getUser',
     78                        'wp.getUsers'                      => 'this:wp_getUsers',
     79                        'wp.getProfile'                    => 'this:wp_getProfile',
     80                        'wp.editProfile'                   => 'this:wp_editProfile',
     81                        'wp.getPage'                       => 'this:wp_getPage',
     82                        'wp.getPages'                      => 'this:wp_getPages',
     83                        'wp.newPage'                       => 'this:wp_newPage',
     84                        'wp.deletePage'                    => 'this:wp_deletePage',
     85                        'wp.editPage'                      => 'this:wp_editPage',
     86                        'wp.getPageList'                   => 'this:wp_getPageList',
     87                        'wp.getAuthors'                    => 'this:wp_getAuthors',
     88                        'wp.getCategories'                 => 'this:mw_getCategories',     // Alias
     89                        'wp.getTags'                       => 'this:wp_getTags',
     90                        'wp.newCategory'                   => 'this:wp_newCategory',
     91                        'wp.deleteCategory'                => 'this:wp_deleteCategory',
     92                        'wp.suggestCategories'             => 'this:wp_suggestCategories',
     93                        'wp.uploadFile'                    => 'this:mw_newMediaObject',    // Alias
     94                        'wp.deleteFile'                    => 'this:wp_deletePost',        // Alias
     95                        'wp.getCommentCount'               => 'this:wp_getCommentCount',
     96                        'wp.getPostStatusList'             => 'this:wp_getPostStatusList',
     97                        'wp.getPageStatusList'             => 'this:wp_getPageStatusList',
     98                        'wp.getPageTemplates'              => 'this:wp_getPageTemplates',
     99                        'wp.getOptions'                    => 'this:wp_getOptions',
     100                        'wp.setOptions'                    => 'this:wp_setOptions',
     101                        'wp.getComment'                    => 'this:wp_getComment',
     102                        'wp.getComments'                   => 'this:wp_getComments',
     103                        'wp.deleteComment'                 => 'this:wp_deleteComment',
     104                        'wp.editComment'                   => 'this:wp_editComment',
     105                        'wp.newComment'                    => 'this:wp_newComment',
     106                        'wp.getCommentStatusList'          => 'this:wp_getCommentStatusList',
     107                        'wp.getMediaItem'                  => 'this:wp_getMediaItem',
     108                        'wp.getMediaLibrary'               => 'this:wp_getMediaLibrary',
     109                        'wp.getPostFormats'                => 'this:wp_getPostFormats',
     110                        'wp.getPostType'                   => 'this:wp_getPostType',
     111                        'wp.getPostTypes'                  => 'this:wp_getPostTypes',
     112                        'wp.getRevisions'                  => 'this:wp_getRevisions',
     113                        'wp.restoreRevision'               => 'this:wp_restoreRevision',
    114114
    115115                        // Blogger API
    116                         'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
    117                         'blogger.getUserInfo' => 'this:blogger_getUserInfo',
    118                         'blogger.getPost' => 'this:blogger_getPost',
    119                         'blogger.getRecentPosts' => 'this:blogger_getRecentPosts',
    120                         'blogger.newPost' => 'this:blogger_newPost',
    121                         'blogger.editPost' => 'this:blogger_editPost',
    122                         'blogger.deletePost' => 'this:blogger_deletePost',
     116                        'blogger.getUsersBlogs'            => 'this:blogger_getUsersBlogs',
     117                        'blogger.getUserInfo'              => 'this:blogger_getUserInfo',
     118                        'blogger.getPost'                  => 'this:blogger_getPost',
     119                        'blogger.getRecentPosts'           => 'this:blogger_getRecentPosts',
     120                        'blogger.newPost'                  => 'this:blogger_newPost',
     121                        'blogger.editPost'                 => 'this:blogger_editPost',
     122                        'blogger.deletePost'               => 'this:blogger_deletePost',
    123123
    124124                        // MetaWeblog API (with MT extensions to structs)
    125                         'metaWeblog.newPost' => 'this:mw_newPost',
    126                         'metaWeblog.editPost' => 'this:mw_editPost',
    127                         'metaWeblog.getPost' => 'this:mw_getPost',
    128                         'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts',
    129                         'metaWeblog.getCategories' => 'this:mw_getCategories',
    130                         'metaWeblog.newMediaObject' => 'this:mw_newMediaObject',
     125                        'metaWeblog.newPost'               => 'this:mw_newPost',
     126                        'metaWeblog.editPost'              => 'this:mw_editPost',
     127                        'metaWeblog.getPost'               => 'this:mw_getPost',
     128                        'metaWeblog.getRecentPosts'        => 'this:mw_getRecentPosts',
     129                        'metaWeblog.getCategories'         => 'this:mw_getCategories',
     130                        'metaWeblog.newMediaObject'        => 'this:mw_newMediaObject',
    131131
    132132                        // MetaWeblog API aliases for Blogger API
    133133                        // see http://www.xmlrpc.com/stories/storyReader$2460
    134                         'metaWeblog.deletePost' => 'this:blogger_deletePost',
    135                         'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs',
     134                        'metaWeblog.deletePost'            => 'this:blogger_deletePost',
     135                        'metaWeblog.getUsersBlogs'         => 'this:blogger_getUsersBlogs',
    136136
    137137                        // MovableType API
    138                         'mt.getCategoryList' => 'this:mt_getCategoryList',
    139                         'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles',
    140                         'mt.getPostCategories' => 'this:mt_getPostCategories',
    141                         'mt.setPostCategories' => 'this:mt_setPostCategories',
    142                         'mt.supportedMethods' => 'this:mt_supportedMethods',
    143                         'mt.supportedTextFilters' => 'this:mt_supportedTextFilters',
    144                         'mt.getTrackbackPings' => 'this:mt_getTrackbackPings',
    145                         'mt.publishPost' => 'this:mt_publishPost',
     138                        'mt.getCategoryList'               => 'this:mt_getCategoryList',
     139                        'mt.getRecentPostTitles'           => 'this:mt_getRecentPostTitles',
     140                        'mt.getPostCategories'             => 'this:mt_getPostCategories',
     141                        'mt.setPostCategories'             => 'this:mt_setPostCategories',
     142                        'mt.supportedMethods'              => 'this:mt_supportedMethods',
     143                        'mt.supportedTextFilters'          => 'this:mt_supportedTextFilters',
     144                        'mt.getTrackbackPings'             => 'this:mt_getTrackbackPings',
     145                        'mt.publishPost'                   => 'this:mt_publishPost',
    146146
    147147                        // PingBack
    148                         'pingback.ping' => 'this:pingback_ping',
     148                        'pingback.ping'                    => 'this:pingback_ping',
    149149                        'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks',
    150150
    151                         'demo.sayHello' => 'this:sayHello',
    152                         'demo.addTwoNumbers' => 'this:addTwoNumbers'
     151                        'demo.sayHello'                    => 'this:sayHello',
     152                        'demo.addTwoNumbers'               => 'this:addTwoNumbers',
    153153                );
    154154
     
    189189         */
    190190        public function serve_request() {
    191                 $this->IXR_Server($this->methods);
     191                $this->IXR_Server( $this->methods );
    192192        }
    193193
     
    323323         */
    324324        public function escape( &$data ) {
    325                 if ( ! is_array( $data ) )
     325                if ( ! is_array( $data ) ) {
    326326                        return wp_slash( $data );
     327                }
    327328
    328329                foreach ( $data as &$v ) {
    329                         if ( is_array( $v ) )
     330                        if ( is_array( $v ) ) {
    330331                                $this->escape( $v );
    331                         elseif ( ! is_object( $v ) )
     332                        } elseif ( ! is_object( $v ) ) {
    332333                                $v = wp_slash( $v );
     334                        }
    333335                }
    334336        }
     
    342344         * @return array Custom fields, if exist.
    343345         */
    344         public function get_custom_fields($post_id) {
     346        public function get_custom_fields( $post_id ) {
    345347                $post_id = (int) $post_id;
    346348
    347349                $custom_fields = array();
    348350
    349                 foreach ( (array) has_meta($post_id) as $meta ) {
     351                foreach ( (array) has_meta( $post_id ) as $meta ) {
    350352                        // Don't expose protected fields.
    351                         if ( ! current_user_can( 'edit_post_meta', $post_id , $meta['meta_key'] ) )
     353                        if ( ! current_user_can( 'edit_post_meta', $post_id, $meta['meta_key'] ) ) {
    352354                                continue;
     355                        }
    353356
    354357                        $custom_fields[] = array(
    355                                 "id"    => $meta['meta_id'],
    356                                 "key"   => $meta['meta_key'],
    357                                 "value" => $meta['meta_value']
     358                                'id'    => $meta['meta_id'],
     359                                'key'   => $meta['meta_key'],
     360                                'value' => $meta['meta_value'],
    358361                        );
    359362                }
     
    370373         * @param array $fields Custom fields.
    371374         */
    372         public function set_custom_fields($post_id, $fields) {
     375        public function set_custom_fields( $post_id, $fields ) {
    373376                $post_id = (int) $post_id;
    374377
    375378                foreach ( (array) $fields as $meta ) {
    376                         if ( isset($meta['id']) ) {
     379                        if ( isset( $meta['id'] ) ) {
    377380                                $meta['id'] = (int) $meta['id'];
    378                                 $pmeta = get_metadata_by_mid( 'post', $meta['id'] );
     381                                $pmeta      = get_metadata_by_mid( 'post', $meta['id'] );
    379382
    380383                                if ( ! $pmeta || $pmeta->post_id != $post_id ) {
     
    382385                                }
    383386
    384                                 if ( isset($meta['key']) ) {
     387                                if ( isset( $meta['key'] ) ) {
    385388                                        $meta['key'] = wp_unslash( $meta['key'] );
    386                                         if ( $meta['key'] !== $pmeta->meta_key )
     389                                        if ( $meta['key'] !== $pmeta->meta_key ) {
    387390                                                continue;
     391                                        }
    388392                                        $meta['value'] = wp_unslash( $meta['value'] );
    389                                         if ( current_user_can( 'edit_post_meta', $post_id, $meta['key'] ) )
     393                                        if ( current_user_can( 'edit_post_meta', $post_id, $meta['key'] ) ) {
    390394                                                update_metadata_by_mid( 'post', $meta['id'], $meta['value'] );
     395                                        }
    391396                                } elseif ( current_user_can( 'delete_post_meta', $post_id, $pmeta->meta_key ) ) {
    392397                                        delete_metadata_by_mid( 'post', $meta['id'] );
     
    441446                        if ( isset( $meta['id'] ) ) {
    442447                                $meta['id'] = (int) $meta['id'];
    443                                 $pmeta = get_metadata_by_mid( 'term', $meta['id'] );
     448                                $pmeta      = get_metadata_by_mid( 'term', $meta['id'] );
    444449                                if ( isset( $meta['key'] ) ) {
    445450                                        $meta['key'] = wp_unslash( $meta['key'] );
     
    470475                $this->blog_options = array(
    471476                        // Read only options
    472                         'software_name'     => array(
    473                                 'desc'          => __( 'Software Name' ),
    474                                 'readonly'      => true,
    475                                 'value'         => 'WordPress'
     477                        'software_name'           => array(
     478                                'desc'     => __( 'Software Name' ),
     479                                'readonly' => true,
     480                                'value'    => 'WordPress',
    476481                        ),
    477                         'software_version'  => array(
    478                                 'desc'          => __( 'Software Version' ),
    479                                 'readonly'      => true,
    480                                 'value'         => get_bloginfo( 'version' )
     482                        'software_version'        => array(
     483                                'desc'     => __( 'Software Version' ),
     484                                'readonly' => true,
     485                                'value'    => get_bloginfo( 'version' ),
    481486                        ),
    482                         'blog_url'          => array(
    483                                 'desc'          => __( 'WordPress Address (URL)' ),
    484                                 'readonly'      => true,
    485                                 'option'        => 'siteurl'
     487                        'blog_url'                => array(
     488                                'desc'     => __( 'WordPress Address (URL)' ),
     489                                'readonly' => true,
     490                                'option'   => 'siteurl',
    486491                        ),
    487                         'home_url'          => array(
    488                                 'desc'          => __( 'Site Address (URL)' ),
    489                                 'readonly'      => true,
    490                                 'option'        => 'home'
     492                        'home_url'                => array(
     493                                'desc'     => __( 'Site Address (URL)' ),
     494                                'readonly' => true,
     495                                'option'   => 'home',
    491496                        ),
    492                         'login_url'          => array(
    493                                 'desc'          => __( 'Login Address (URL)' ),
    494                                 'readonly'      => true,
    495                                 'value'         => wp_login_url( )
     497                        'login_url'               => array(
     498                                'desc'     => __( 'Login Address (URL)' ),
     499                                'readonly' => true,
     500                                'value'    => wp_login_url(),
    496501                        ),
    497                         'admin_url'          => array(
    498                                 'desc'          => __( 'The URL to the admin area' ),
    499                                 'readonly'      => true,
    500                                 'value'         => get_admin_url( )
     502                        'admin_url'               => array(
     503                                'desc'     => __( 'The URL to the admin area' ),
     504                                'readonly' => true,
     505                                'value'    => get_admin_url(),
    501506                        ),
    502507                        'image_default_link_type' => array(
    503                                 'desc'          => __( 'Image default link type' ),
    504                                 'readonly'      => true,
    505                                 'option'        => 'image_default_link_type'
     508                                'desc'     => __( 'Image default link type' ),
     509                                'readonly' => true,
     510                                'option'   => 'image_default_link_type',
    506511                        ),
    507                         'image_default_size' => array(
    508                                 'desc'          => __( 'Image default size' ),
    509                                 'readonly'      => true,
    510                                 'option'        => 'image_default_size'
     512                        'image_default_size'      => array(
     513                                'desc'     => __( 'Image default size' ),
     514                                'readonly' => true,
     515                                'option'   => 'image_default_size',
    511516                        ),
    512                         'image_default_align' => array(
    513                                 'desc'          => __( 'Image default align' ),
    514                                 'readonly'      => true,
    515                                 'option'        => 'image_default_align'
     517                        'image_default_align'     => array(
     518                                'desc'     => __( 'Image default align' ),
     519                                'readonly' => true,
     520                                'option'   => 'image_default_align',
    516521                        ),
    517                         'template'          => array(
    518                                 'desc'          => __( 'Template' ),
    519                                 'readonly'      => true,
    520                                 'option'        => 'template'
     522                        'template'                => array(
     523                                'desc'     => __( 'Template' ),
     524                                'readonly' => true,
     525                                'option'   => 'template',
    521526                        ),
    522                         'stylesheet'        => array(
    523                                 'desc'          => __( 'Stylesheet' ),
    524                                 'readonly'      => true,
    525                                 'option'        => 'stylesheet'
     527                        'stylesheet'              => array(
     528                                'desc'     => __( 'Stylesheet' ),
     529                                'readonly' => true,
     530                                'option'   => 'stylesheet',
    526531                        ),
    527                         'post_thumbnail'    => array(
    528                                 'desc'          => __('Post Thumbnail'),
    529                                 'readonly'      => true,
    530                                 'value'         => current_theme_supports( 'post-thumbnails' )
     532                        'post_thumbnail'          => array(
     533                                'desc'     => __( 'Post Thumbnail' ),
     534                                'readonly' => true,
     535                                'value'    => current_theme_supports( 'post-thumbnails' ),
    531536                        ),
    532537
    533538                        // Updatable options
    534                         'time_zone'         => array(
    535                                 'desc'          => __( 'Time Zone' ),
    536                                 'readonly'      => false,
    537                                 'option'        => 'gmt_offset'
     539                        'time_zone'               => array(
     540                                'desc'     => __( 'Time Zone' ),
     541                                'readonly' => false,
     542                                'option'   => 'gmt_offset',
    538543                        ),
    539                         'blog_title'        => array(
    540                                 'desc'          => __( 'Site Title' ),
    541                                 'readonly'      => false,
    542                                 'option'        => 'blogname'
     544                        'blog_title'              => array(
     545                                'desc'     => __( 'Site Title' ),
     546                                'readonly' => false,
     547                                'option'   => 'blogname',
    543548                        ),
    544                         'blog_tagline'      => array(
    545                                 'desc'          => __( 'Site Tagline' ),
    546                                 'readonly'      => false,
    547                                 'option'        => 'blogdescription'
     549                        'blog_tagline'            => array(
     550                                'desc'     => __( 'Site Tagline' ),
     551                                'readonly' => false,
     552                                'option'   => 'blogdescription',
    548553                        ),
    549                         'date_format'       => array(
    550                                 'desc'          => __( 'Date Format' ),
    551                                 'readonly'      => false,
    552                                 'option'        => 'date_format'
     554                        'date_format'             => array(
     555                                'desc'     => __( 'Date Format' ),
     556                                'readonly' => false,
     557                                'option'   => 'date_format',
    553558                        ),
    554                         'time_format'       => array(
    555                                 'desc'          => __( 'Time Format' ),
    556                                 'readonly'      => false,
    557                                 'option'        => 'time_format'
     559                        'time_format'             => array(
     560                                'desc'     => __( 'Time Format' ),
     561                                'readonly' => false,
     562                                'option'   => 'time_format',
    558563                        ),
    559                         'users_can_register' => array(
    560                                 'desc'          => __( 'Allow new users to sign up' ),
    561                                 'readonly'      => false,
    562                                 'option'        => 'users_can_register'
     564                        'users_can_register'      => array(
     565                                'desc'     => __( 'Allow new users to sign up' ),
     566                                'readonly' => false,
     567                                'option'   => 'users_can_register',
    563568                        ),
    564                         'thumbnail_size_w'  => array(
    565                                 'desc'          => __( 'Thumbnail Width' ),
    566                                 'readonly'      => false,
    567                                 'option'        => 'thumbnail_size_w'
     569                        'thumbnail_size_w'        => array(
     570                                'desc'     => __( 'Thumbnail Width' ),
     571                                'readonly' => false,
     572                                'option'   => 'thumbnail_size_w',
    568573                        ),
    569                         'thumbnail_size_h'  => array(
    570                                 'desc'          => __( 'Thumbnail Height' ),
    571                                 'readonly'      => false,
    572                                 'option'        => 'thumbnail_size_h'
     574                        'thumbnail_size_h'        => array(
     575                                'desc'     => __( 'Thumbnail Height' ),
     576                                'readonly' => false,
     577                                'option'   => 'thumbnail_size_h',
    573578                        ),
    574                         'thumbnail_crop'    => array(
    575                                 'desc'          => __( 'Crop thumbnail to exact dimensions' ),
    576                                 'readonly'      => false,
    577                                 'option'        => 'thumbnail_crop'
     579                        'thumbnail_crop'          => array(
     580                                'desc'     => __( 'Crop thumbnail to exact dimensions' ),
     581                                'readonly' => false,
     582                                'option'   => 'thumbnail_crop',
    578583                        ),
    579                         'medium_size_w'     => array(
    580                                 'desc'          => __( 'Medium size image width' ),
    581                                 'readonly'      => false,
    582                                 'option'        => 'medium_size_w'
     584                        'medium_size_w'           => array(
     585                                'desc'     => __( 'Medium size image width' ),
     586                                'readonly' => false,
     587                                'option'   => 'medium_size_w',
    583588                        ),
    584                         'medium_size_h'     => array(
    585                                 'desc'          => __( 'Medium size image height' ),
    586                                 'readonly'      => false,
    587                                 'option'        => 'medium_size_h'
     589                        'medium_size_h'           => array(
     590                                'desc'     => __( 'Medium size image height' ),
     591                                'readonly' => false,
     592                                'option'   => 'medium_size_h',
    588593                        ),
    589                         'medium_large_size_w'   => array(
    590                                 'desc'          => __( 'Medium-Large size image width' ),
    591                                 'readonly'      => false,
    592                                 'option'        => 'medium_large_size_w'
     594                        'medium_large_size_w'     => array(
     595                                'desc'     => __( 'Medium-Large size image width' ),
     596                                'readonly' => false,
     597                                'option'   => 'medium_large_size_w',
    593598                        ),
    594                         'medium_large_size_h'   => array(
    595                                 'desc'          => __( 'Medium-Large size image height' ),
    596                                 'readonly'      => false,
    597                                 'option'        => 'medium_large_size_h'
     599                        'medium_large_size_h'     => array(
     600                                'desc'     => __( 'Medium-Large size image height' ),
     601                                'readonly' => false,
     602                                'option'   => 'medium_large_size_h',
    598603                        ),
    599                         'large_size_w'      => array(
    600                                 'desc'          => __( 'Large size image width' ),
    601                                 'readonly'      => false,
    602                                 'option'        => 'large_size_w'
     604                        'large_size_w'            => array(
     605                                'desc'     => __( 'Large size image width' ),
     606                                'readonly' => false,
     607                                'option'   => 'large_size_w',
    603608                        ),
    604                         'large_size_h'      => array(
    605                                 'desc'          => __( 'Large size image height' ),
    606                                 'readonly'      => false,
    607                                 'option'        => 'large_size_h'
     609                        'large_size_h'            => array(
     610                                'desc'     => __( 'Large size image height' ),
     611                                'readonly' => false,
     612                                'option'   => 'large_size_h',
    608613                        ),
    609                         'default_comment_status' => array(
    610                                 'desc'          => __( 'Allow people to post comments on new articles' ),
    611                                 'readonly'      => false,
    612                                 'option'        => 'default_comment_status'
     614                        'default_comment_status'  => array(
     615                                'desc'     => __( 'Allow people to post comments on new articles' ),
     616                                'readonly' => false,
     617                                'option'   => 'default_comment_status',
    613618                        ),
    614                         'default_ping_status' => array(
    615                                 'desc'          => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles' ),
    616                                 'readonly'      => false,
    617                                 'option'        => 'default_ping_status'
    618                         )
     619                        'default_ping_status'     => array(
     620                                'desc'     => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles' ),
     621                                'readonly' => false,
     622                                'option'   => 'default_ping_status',
     623                        ),
    619624                );
    620625
     
    654659
    655660                // If this isn't on WPMU then just use blogger_getUsersBlogs
    656                 if ( !is_multisite() ) {
     661                if ( ! is_multisite() ) {
    657662                        array_unshift( $args, 1 );
    658663                        return $this->blogger_getUsersBlogs( $args );
     
    664669                $password = $args[1];
    665670
    666                 if ( !$user = $this->login($username, $password) )
    667                         return $this->error;
     671                if ( ! $user = $this->login( $username, $password ) ) {
     672                        return $this->error;
     673                }
    668674
    669675                /**
     
    680686                do_action( 'xmlrpc_call', 'wp.getUsersBlogs' );
    681687
    682                 $blogs = (array) get_blogs_of_user( $user->ID );
    683                 $struct = array();
     688                $blogs           = (array) get_blogs_of_user( $user->ID );
     689                $struct          = array();
    684690                $primary_blog_id = 0;
    685                 $active_blog = get_active_blog_for_user( $user->ID );
     691                $active_blog     = get_active_blog_for_user( $user->ID );
    686692                if ( $active_blog ) {
    687693                        $primary_blog_id = (int) $active_blog->blog_id;
     
    690696                foreach ( $blogs as $blog ) {
    691697                        // Don't include blogs that aren't hosted at this site.
    692                         if ( $blog->site_id != get_current_network_id() )
     698                        if ( $blog->site_id != get_current_network_id() ) {
    693699                                continue;
     700                        }
    694701
    695702                        $blog_id = $blog->userblog_id;
     
    697704                        switch_to_blog( $blog_id );
    698705
    699                         $is_admin = current_user_can( 'manage_options' );
     706                        $is_admin   = current_user_can( 'manage_options' );
    700707                        $is_primary = ( (int) $blog_id === $primary_blog_id );
    701708
     
    736743         * Prepares taxonomy data for return in an XML-RPC object.
    737744         *
    738          *
    739745         * @param object $taxonomy The unprepared taxonomy data.
    740746         * @param array $fields    The subset of taxonomy fields to return.
     
    743749        protected function _prepare_taxonomy( $taxonomy, $fields ) {
    744750                $_taxonomy = array(
    745                         'name' => $taxonomy->name,
    746                         'label' => $taxonomy->label,
     751                        'name'         => $taxonomy->name,
     752                        'label'        => $taxonomy->label,
    747753                        'hierarchical' => (bool) $taxonomy->hierarchical,
    748                         'public' => (bool) $taxonomy->public,
    749                         'show_ui' => (bool) $taxonomy->show_ui,
    750                         '_builtin' => (bool) $taxonomy->_builtin,
     754                        'public'       => (bool) $taxonomy->public,
     755                        'show_ui'      => (bool) $taxonomy->show_ui,
     756                        '_builtin'     => (bool) $taxonomy->_builtin,
    751757                );
    752758
    753                 if ( in_array( 'labels', $fields ) )
     759                if ( in_array( 'labels', $fields ) ) {
    754760                        $_taxonomy['labels'] = (array) $taxonomy->labels;
    755 
    756                 if ( in_array( 'cap', $fields ) )
     761                }
     762
     763                if ( in_array( 'cap', $fields ) ) {
    757764                        $_taxonomy['cap'] = (array) $taxonomy->cap;
    758 
    759                 if ( in_array( 'menu', $fields ) )
     765                }
     766
     767                if ( in_array( 'menu', $fields ) ) {
    760768                        $_taxonomy['show_in_menu'] = (bool) $_taxonomy->show_in_menu;
    761 
    762                 if ( in_array( 'object_type', $fields ) )
     769                }
     770
     771                if ( in_array( 'object_type', $fields ) ) {
    763772                        $_taxonomy['object_type'] = array_unique( (array) $taxonomy->object_type );
     773                }
    764774
    765775                /**
     
    778788         * Prepares term data for return in an XML-RPC object.
    779789         *
    780          *
    781790         * @param array|object $term The unprepared term data.
    782791         * @return array The prepared term data.
     
    784793        protected function _prepare_term( $term ) {
    785794                $_term = $term;
    786                 if ( ! is_array( $_term ) )
     795                if ( ! is_array( $_term ) ) {
    787796                        $_term = get_object_vars( $_term );
     797                }
    788798
    789799                // For integers which may be larger than XML-RPC supports ensure we return strings.
    790                 $_term['term_id'] = strval( $_term['term_id'] );
    791                 $_term['term_group'] = strval( $_term['term_group'] );
     800                $_term['term_id']          = strval( $_term['term_id'] );
     801                $_term['term_group']       = strval( $_term['term_group'] );
    792802                $_term['term_taxonomy_id'] = strval( $_term['term_taxonomy_id'] );
    793                 $_term['parent'] = strval( $_term['parent'] );
     803                $_term['parent']           = strval( $_term['parent'] );
    794804
    795805                // Count we are happy to return as an integer because people really shouldn't use terms that much.
     
    813823         * Convert a WordPress date string to an IXR_Date object.
    814824         *
    815          *
    816825         * @param string $date Date string to convert.
    817826         * @return IXR_Date IXR_Date object.
     
    827836         * Convert a WordPress GMT date string to an IXR_Date object.
    828837         *
    829          *
    830838         * @param string $date_gmt WordPress GMT date string.
    831839         * @param string $date     Date string.
     
    841849        /**
    842850         * Prepares post data for return in an XML-RPC object.
    843          *
    844851         *
    845852         * @param array $post   The unprepared post data.
     
    877884                // Thumbnail.
    878885                $post_fields['post_thumbnail'] = array();
    879                 $thumbnail_id = get_post_thumbnail_id( $post['ID'] );
     886                $thumbnail_id                  = get_post_thumbnail_id( $post['ID'] );
    880887                if ( $thumbnail_id ) {
    881                         $thumbnail_size = current_theme_supports('post-thumbnail') ? 'post-thumbnail' : 'thumbnail';
     888                        $thumbnail_size                = current_theme_supports( 'post-thumbnail' ) ? 'post-thumbnail' : 'thumbnail';
    882889                        $post_fields['post_thumbnail'] = $this->_prepare_media_item( get_post( $thumbnail_id ), $thumbnail_size );
    883890                }
    884891
    885892                // Consider future posts as published.
    886                 if ( $post_fields['post_status'] === 'future' )
     893                if ( $post_fields['post_status'] === 'future' ) {
    887894                        $post_fields['post_status'] = 'publish';
     895                }
    888896
    889897                // Fill in blank post format.
    890898                $post_fields['post_format'] = get_post_format( $post['ID'] );
    891                 if ( empty( $post_fields['post_format'] ) )
     899                if ( empty( $post_fields['post_format'] ) ) {
    892900                        $post_fields['post_format'] = 'standard';
     901                }
    893902
    894903                // Merge requested $post_fields fields into $_post.
     
    897906                } else {
    898907                        $requested_fields = array_intersect_key( $post_fields, array_flip( $fields ) );
    899                         $_post = array_merge( $_post, $requested_fields );
     908                        $_post            = array_merge( $_post, $requested_fields );
    900909                }
    901910
     
    904913                if ( $all_taxonomy_fields || in_array( 'terms', $fields ) ) {
    905914                        $post_type_taxonomies = get_object_taxonomies( $post['post_type'], 'names' );
    906                         $terms = wp_get_object_terms( $post['ID'], $post_type_taxonomies );
    907                         $_post['terms'] = array();
     915                        $terms                = wp_get_object_terms( $post['ID'], $post_type_taxonomies );
     916                        $_post['terms']       = array();
    908917                        foreach ( $terms as $term ) {
    909918                                $_post['terms'][] = $this->_prepare_term( $term );
     
    911920                }
    912921
    913                 if ( in_array( 'custom_fields', $fields ) )
     922                if ( in_array( 'custom_fields', $fields ) ) {
    914923                        $_post['custom_fields'] = $this->get_custom_fields( $post['ID'] );
     924                }
    915925
    916926                if ( in_array( 'enclosure', $fields ) ) {
    917927                        $_post['enclosure'] = array();
    918                         $enclosures = (array) get_post_meta( $post['ID'], 'enclosure' );
     928                        $enclosures         = (array) get_post_meta( $post['ID'], 'enclosure' );
    919929                        if ( ! empty( $enclosures ) ) {
    920                                 $encdata = explode( "\n", $enclosures[0] );
    921                                 $_post['enclosure']['url'] = trim( htmlspecialchars( $encdata[0] ) );
     930                                $encdata                      = explode( "\n", $enclosures[0] );
     931                                $_post['enclosure']['url']    = trim( htmlspecialchars( $encdata[0] ) );
    922932                                $_post['enclosure']['length'] = (int) trim( $encdata[1] );
    923                                 $_post['enclosure']['type'] = trim( $encdata[2] );
     933                                $_post['enclosure']['type']   = trim( $encdata[2] );
    924934                        }
    925935                }
     
    949959        protected function _prepare_post_type( $post_type, $fields ) {
    950960                $_post_type = array(
    951                         'name' => $post_type->name,
    952                         'label' => $post_type->label,
     961                        'name'         => $post_type->name,
     962                        'label'        => $post_type->label,
    953963                        'hierarchical' => (bool) $post_type->hierarchical,
    954                         'public' => (bool) $post_type->public,
    955                         'show_ui' => (bool) $post_type->show_ui,
    956                         '_builtin' => (bool) $post_type->_builtin,
    957                         'has_archive' => (bool) $post_type->has_archive,
    958                         'supports' => get_all_post_type_supports( $post_type->name ),
     964                        'public'       => (bool) $post_type->public,
     965                        'show_ui'      => (bool) $post_type->show_ui,
     966                        '_builtin'     => (bool) $post_type->_builtin,
     967                        'has_archive'  => (bool) $post_type->has_archive,
     968                        'supports'     => get_all_post_type_supports( $post_type->name ),
    959969                );
    960970
     
    964974
    965975                if ( in_array( 'cap', $fields ) ) {
    966                         $_post_type['cap'] = (array) $post_type->cap;
     976                        $_post_type['cap']          = (array) $post_type->cap;
    967977                        $_post_type['map_meta_cap'] = (bool) $post_type->map_meta_cap;
    968978                }
     
    970980                if ( in_array( 'menu', $fields ) ) {
    971981                        $_post_type['menu_position'] = (int) $post_type->menu_position;
    972                         $_post_type['menu_icon'] = $post_type->menu_icon;
    973                         $_post_type['show_in_menu'] = (bool) $post_type->show_in_menu;
    974                 }
    975 
    976                 if ( in_array( 'taxonomies', $fields ) )
     982                        $_post_type['menu_icon']     = $post_type->menu_icon;
     983                        $_post_type['show_in_menu']  = (bool) $post_type->show_in_menu;
     984                }
     985
     986                if ( in_array( 'taxonomies', $fields ) ) {
    977987                        $_post_type['taxonomies'] = get_object_taxonomies( $post_type->name, 'names' );
     988                }
    978989
    979990                /**
     
    9921003         * Prepares media item data for return in an XML-RPC object.
    9931004         *
    994          *
    9951005         * @param object $media_item     The unprepared media item data.
    9961006         * @param string $thumbnail_size The image size to use for the thumbnail URL.
     
    10071017                        'description'      => $media_item->post_content,
    10081018                        'metadata'         => wp_get_attachment_metadata( $media_item->ID ),
    1009                         'type'             => $media_item->post_mime_type
     1019                        'type'             => $media_item->post_mime_type,
    10101020                );
    10111021
    10121022                $thumbnail_src = image_downsize( $media_item->ID, $thumbnail_size );
    1013                 if ( $thumbnail_src )
     1023                if ( $thumbnail_src ) {
    10141024                        $_media_item['thumbnail'] = $thumbnail_src[0];
    1015                 else
     1025                } else {
    10161026                        $_media_item['thumbnail'] = $_media_item['link'];
     1027                }
    10171028
    10181029                /**
     
    10311042         * Prepares page data for return in an XML-RPC object.
    10321043         *
    1033          *
    10341044         * @param object $page The unprepared page data.
    10351045         * @return array The prepared page data.
     
    10381048                // Get all of the page content and link.
    10391049                $full_page = get_extended( $page->post_content );
    1040                 $link = get_permalink( $page->ID );
     1050                $link      = get_permalink( $page->ID );
    10411051
    10421052                // Get info the page parent if there is one.
    1043                 $parent_title = "";
     1053                $parent_title = '';
    10441054                if ( ! empty( $page->post_parent ) ) {
    1045                         $parent = get_post( $page->post_parent );
     1055                        $parent       = get_post( $page->post_parent );
    10461056                        $parent_title = $parent->post_title;
    10471057                }
     
    10491059                // Determine comment and ping settings.
    10501060                $allow_comments = comments_open( $page->ID ) ? 1 : 0;
    1051                 $allow_pings = pings_open( $page->ID ) ? 1 : 0;
     1061                $allow_pings    = pings_open( $page->ID ) ? 1 : 0;
    10521062
    10531063                // Format page date.
    1054                 $page_date = $this->_convert_date( $page->post_date );
     1064                $page_date     = $this->_convert_date( $page->post_date );
    10551065                $page_date_gmt = $this->_convert_date_gmt( $page->post_date_gmt, $page->post_date );
    10561066
     
    10671077
    10681078                $page_template = get_page_template_slug( $page->ID );
    1069                 if ( empty( $page_template ) )
     1079                if ( empty( $page_template ) ) {
    10701080                        $page_template = 'default';
     1081                }
    10711082
    10721083                $_page = array(
     
    10941105                        'date_created_gmt'       => $page_date_gmt,
    10951106                        'custom_fields'          => $this->get_custom_fields( $page->ID ),
    1096                         'wp_page_template'       => $page_template
     1107                        'wp_page_template'       => $page_template,
    10971108                );
    10981109
     
    11111122         * Prepares comment data for return in an XML-RPC object.
    11121123         *
    1113          *
    11141124         * @param object $comment The unprepared comment data.
    11151125         * @return array The prepared comment data.
     
    11351145                        'status'           => $comment_status,
    11361146                        'content'          => $comment->comment_content,
    1137                         'link'             => get_comment_link($comment),
     1147                        'link'             => get_comment_link( $comment ),
    11381148                        'post_id'          => $comment->comment_post_ID,
    1139                         'post_title'       => get_the_title($comment->comment_post_ID),
     1149                        'post_title'       => get_the_title( $comment->comment_post_ID ),
    11401150                        'author'           => $comment->comment_author,
    11411151                        'author_url'       => $comment->comment_author_url,
     
    11591169         * Prepares user data for return in an XML-RPC object.
    11601170         *
    1161          *
    11621171         * @param WP_User $user   The unprepared user object.
    11631172         * @param array   $fields The subset of user fields to return.
     
    11681177
    11691178                $user_fields = array(
    1170                         'username'          => $user->user_login,
    1171                         'first_name'        => $user->user_firstname,
    1172                         'last_name'         => $user->user_lastname,
    1173                         'registered'        => $this->_convert_date( $user->user_registered ),
    1174                         'bio'               => $user->user_description,
    1175                         'email'             => $user->user_email,
    1176                         'nickname'          => $user->nickname,
    1177                         'nicename'          => $user->user_nicename,
    1178                         'url'               => $user->user_url,
    1179                         'display_name'      => $user->display_name,
    1180                         'roles'             => $user->roles,
     1179                        'username'     => $user->user_login,
     1180                        'first_name'   => $user->user_firstname,
     1181                        'last_name'    => $user->user_lastname,
     1182                        'registered'   => $this->_convert_date( $user->user_registered ),
     1183                        'bio'          => $user->user_description,
     1184                        'email'        => $user->user_email,
     1185                        'nickname'     => $user->nickname,
     1186                        'nicename'     => $user->user_nicename,
     1187                        'url'          => $user->user_url,
     1188                        'display_name' => $user->display_name,
     1189                        'roles'        => $user->roles,
    11811190                );
    11821191
     
    11861195                        if ( in_array( 'basic', $fields ) ) {
    11871196                                $basic_fields = array( 'username', 'email', 'registered', 'display_name', 'nicename' );
    1188                                 $fields = array_merge( $fields, $basic_fields );
     1197                                $fields       = array_merge( $fields, $basic_fields );
    11891198                        }
    11901199                        $requested_fields = array_intersect_key( $user_fields, array_flip( $fields ) );
    1191                         $_user = array_merge( $_user, $requested_fields );
     1200                        $_user            = array_merge( $_user, $requested_fields );
    11921201                }
    11931202
     
    12521261         */
    12531262        public function wp_newPost( $args ) {
    1254                 if ( ! $this->minimum_args( $args, 4 ) )
    1255                         return $this->error;
     1263                if ( ! $this->minimum_args( $args, 4 ) ) {
     1264                        return $this->error;
     1265                }
    12561266
    12571267                $this->escape( $args );
     
    12611271                $content_struct = $args[3];
    12621272
    1263                 if ( ! $user = $this->login( $username, $password ) )
    1264                         return $this->error;
     1273                if ( ! $user = $this->login( $username, $password ) ) {
     1274                        return $this->error;
     1275                }
    12651276
    12661277                // convert the date field back to IXR form
     
    13211332                                unstick_post( $post_data['ID'] );
    13221333                        }
    1323                 } elseif ( isset( $post_data['sticky'] ) )  {
     1334                } elseif ( isset( $post_data['sticky'] ) ) {
    13241335                        if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
    13251336                                return new IXR_Error( 401, __( 'Sorry, you are not allowed to make posts sticky.' ) );
     
    13741385
    13751386                $post_type = get_post_type_object( $post_data['post_type'] );
    1376                 if ( ! $post_type )
     1387                if ( ! $post_type ) {
    13771388                        return new IXR_Error( 403, __( 'Invalid post type.' ) );
     1389                }
    13781390
    13791391                $update = ! empty( $post_data['ID'] );
    13801392
    13811393                if ( $update ) {
    1382                         if ( ! get_post( $post_data['ID'] ) )
     1394                        if ( ! get_post( $post_data['ID'] ) ) {
    13831395                                return new IXR_Error( 401, __( 'Invalid post ID.' ) );
    1384                         if ( ! current_user_can( 'edit_post', $post_data['ID'] ) )
     1396                        }
     1397                        if ( ! current_user_can( 'edit_post', $post_data['ID'] ) ) {
    13851398                                return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
    1386                         if ( $post_data['post_type'] != get_post_type( $post_data['ID'] ) )
     1399                        }
     1400                        if ( $post_data['post_type'] != get_post_type( $post_data['ID'] ) ) {
    13871401                                return new IXR_Error( 401, __( 'The post type may not be changed.' ) );
     1402                        }
    13881403                } else {
    1389                         if ( ! current_user_can( $post_type->cap->create_posts ) || ! current_user_can( $post_type->cap->edit_posts ) )
     1404                        if ( ! current_user_can( $post_type->cap->create_posts ) || ! current_user_can( $post_type->cap->edit_posts ) ) {
    13901405                                return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) );
     1406                        }
    13911407                }
    13921408
     
    13961412                                break;
    13971413                        case 'private':
    1398                                 if ( ! current_user_can( $post_type->cap->publish_posts ) )
     1414                                if ( ! current_user_can( $post_type->cap->publish_posts ) ) {
    13991415                                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to create private posts in this post type.' ) );
     1416                                }
    14001417                                break;
    14011418                        case 'publish':
    14021419                        case 'future':
    1403                                 if ( ! current_user_can( $post_type->cap->publish_posts ) )
     1420                                if ( ! current_user_can( $post_type->cap->publish_posts ) ) {
    14041421                                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts in this post type.' ) );
     1422                                }
    14051423                                break;
    14061424                        default:
    1407                                 if ( ! get_post_status_object( $post_data['post_status'] ) )
     1425                                if ( ! get_post_status_object( $post_data['post_status'] ) ) {
    14081426                                        $post_data['post_status'] = 'draft';
    1409                         break;
    1410                 }
    1411 
    1412                 if ( ! empty( $post_data['post_password'] ) && ! current_user_can( $post_type->cap->publish_posts ) )
     1427                                }
     1428                                break;
     1429                }
     1430
     1431                if ( ! empty( $post_data['post_password'] ) && ! current_user_can( $post_type->cap->publish_posts ) ) {
    14131432                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to create password protected posts in this post type.' ) );
     1433                }
    14141434
    14151435                $post_data['post_author'] = absint( $post_data['post_author'] );
    14161436                if ( ! empty( $post_data['post_author'] ) && $post_data['post_author'] != $user->ID ) {
    1417                         if ( ! current_user_can( $post_type->cap->edit_others_posts ) )
     1437                        if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
    14181438                                return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) );
     1439                        }
    14191440
    14201441                        $author = get_userdata( $post_data['post_author'] );
    14211442
    1422                         if ( ! $author )
     1443                        if ( ! $author ) {
    14231444                                return new IXR_Error( 404, __( 'Invalid author ID.' ) );
     1445                        }
    14241446                } else {
    14251447                        $post_data['post_author'] = $user->ID;
    14261448                }
    14271449
    1428                 if ( isset( $post_data['comment_status'] ) && $post_data['comment_status'] != 'open' && $post_data['comment_status'] != 'closed' )
     1450                if ( isset( $post_data['comment_status'] ) && $post_data['comment_status'] != 'open' && $post_data['comment_status'] != 'closed' ) {
    14291451                        unset( $post_data['comment_status'] );
    1430 
    1431                 if ( isset( $post_data['ping_status'] ) && $post_data['ping_status'] != 'open' && $post_data['ping_status'] != 'closed' )
     1452                }
     1453
     1454                if ( isset( $post_data['ping_status'] ) && $post_data['ping_status'] != 'open' && $post_data['ping_status'] != 'closed' ) {
    14321455                        unset( $post_data['ping_status'] );
     1456                }
    14331457
    14341458                // Do some timestamp voodoo.
     
    14441468
    14451469                if ( ! empty( $dateCreated ) ) {
    1446                         $post_data['post_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
     1470                        $post_data['post_date']     = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
    14471471                        $post_data['post_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' );
    14481472
     
    14511475                }
    14521476
    1453                 if ( ! isset( $post_data['ID'] ) )
     1477                if ( ! isset( $post_data['ID'] ) ) {
    14541478                        $post_data['ID'] = get_default_post_to_edit( $post_data['post_type'], true )->ID;
     1479                }
    14551480                $post_ID = $post_data['ID'];
    14561481
     
    14641489                if ( isset( $post_data['post_thumbnail'] ) ) {
    14651490                        // empty value deletes, non-empty value adds/updates.
    1466                         if ( ! $post_data['post_thumbnail'] )
     1491                        if ( ! $post_data['post_thumbnail'] ) {
    14671492                                delete_post_thumbnail( $post_ID );
    1468                         elseif ( ! get_post( absint( $post_data['post_thumbnail'] ) ) )
     1493                        } elseif ( ! get_post( absint( $post_data['post_thumbnail'] ) ) ) {
    14691494                                return new IXR_Error( 404, __( 'Invalid attachment ID.' ) );
     1495                        }
    14701496                        set_post_thumbnail( $post_ID, $post_data['post_thumbnail'] );
    14711497                        unset( $content_struct['post_thumbnail'] );
    14721498                }
    14731499
    1474                 if ( isset( $post_data['custom_fields'] ) )
     1500                if ( isset( $post_data['custom_fields'] ) ) {
    14751501                        $this->set_custom_fields( $post_ID, $post_data['custom_fields'] );
     1502                }
    14761503
    14771504                if ( isset( $post_data['terms'] ) || isset( $post_data['terms_names'] ) ) {
     
    14871514                                // Validating term ids.
    14881515                                foreach ( $taxonomies as $taxonomy ) {
    1489                                         if ( ! array_key_exists( $taxonomy , $post_type_taxonomies ) )
     1516                                        if ( ! array_key_exists( $taxonomy, $post_type_taxonomies ) ) {
    14901517                                                return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) );
    1491 
    1492                                         if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->assign_terms ) )
     1518                                        }
     1519
     1520                                        if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->assign_terms ) ) {
    14931521                                                return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) );
    1494 
    1495                                         $term_ids = $post_data['terms'][$taxonomy];
     1522                                        }
     1523
     1524                                        $term_ids           = $post_data['terms'][ $taxonomy ];
    14961525                                        $terms[ $taxonomy ] = array();
    14971526                                        foreach ( $term_ids as $term_id ) {
    14981527                                                $term = get_term_by( 'id', $term_id, $taxonomy );
    14991528
    1500                                                 if ( ! $term )
     1529                                                if ( ! $term ) {
    15011530                                                        return new IXR_Error( 403, __( 'Invalid term ID.' ) );
    1502 
    1503                                                 $terms[$taxonomy][] = (int) $term_id;
     1531                                                }
     1532
     1533                                                $terms[ $taxonomy ][] = (int) $term_id;
    15041534                                        }
    15051535                                }
     
    15111541
    15121542                                foreach ( $taxonomies as $taxonomy ) {
    1513                                         if ( ! array_key_exists( $taxonomy , $post_type_taxonomies ) )
     1543                                        if ( ! array_key_exists( $taxonomy, $post_type_taxonomies ) ) {
    15141544                                                return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) );
    1515 
    1516                                         if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->assign_terms ) )
     1545                                        }
     1546
     1547                                        if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->assign_terms ) ) {
    15171548                                                return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) );
     1549                                        }
    15181550
    15191551                                        /*
     
    15231555                                        $ambiguous_terms = array();
    15241556                                        if ( is_taxonomy_hierarchical( $taxonomy ) ) {
    1525                                                 $tax_term_names = get_terms( $taxonomy, array( 'fields' => 'names', 'hide_empty' => false ) );
     1557                                                $tax_term_names = get_terms(
     1558                                                        $taxonomy, array(
     1559                                                                'fields'     => 'names',
     1560                                                                'hide_empty' => false,
     1561                                                        )
     1562                                                );
    15261563
    15271564                                                // Count the number of terms with the same name.
     
    15291566
    15301567                                                // Filter out non-ambiguous term names.
    1531                                                 $ambiguous_tax_term_counts = array_filter( $tax_term_names_count, array( $this, '_is_greater_than_one') );
     1568                                                $ambiguous_tax_term_counts = array_filter( $tax_term_names_count, array( $this, '_is_greater_than_one' ) );
    15321569
    15331570                                                $ambiguous_terms = array_keys( $ambiguous_tax_term_counts );
    15341571                                        }
    15351572
    1536                                         $term_names = $post_data['terms_names'][$taxonomy];
     1573                                        $term_names = $post_data['terms_names'][ $taxonomy ];
    15371574                                        foreach ( $term_names as $term_name ) {
    1538                                                 if ( in_array( $term_name, $ambiguous_terms ) )
     1575                                                if ( in_array( $term_name, $ambiguous_terms ) ) {
    15391576                                                        return new IXR_Error( 401, __( 'Ambiguous term name used in a hierarchical taxonomy. Please use term ID instead.' ) );
     1577                                                }
    15401578
    15411579                                                $term = get_term_by( 'name', $term_name, $taxonomy );
     
    15431581                                                if ( ! $term ) {
    15441582                                                        // Term doesn't exist, so check that the user is allowed to create new terms.
    1545                                                         if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->edit_terms ) )
     1583                                                        if ( ! current_user_can( $post_type_taxonomies[ $taxonomy ]->cap->edit_terms ) ) {
    15461584                                                                return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a term to one of the given taxonomies.' ) );
     1585                                                        }
    15471586
    15481587                                                        // Create the new term.
    15491588                                                        $term_info = wp_insert_term( $term_name, $taxonomy );
    1550                                                         if ( is_wp_error( $term_info ) )
     1589                                                        if ( is_wp_error( $term_info ) ) {
    15511590                                                                return new IXR_Error( 500, $term_info->get_error_message() );
    1552 
    1553                                                         $terms[$taxonomy][] = (int) $term_info['term_id'];
     1591                                                        }
     1592
     1593                                                        $terms[ $taxonomy ][] = (int) $term_info['term_id'];
    15541594                                                } else {
    1555                                                         $terms[$taxonomy][] = (int) $term->term_id;
     1595                                                        $terms[ $taxonomy ][] = (int) $term->term_id;
    15561596                                                }
    15571597                                        }
     
    15661606                        $format = set_post_format( $post_ID, $post_data['post_format'] );
    15671607
    1568                         if ( is_wp_error( $format ) )
     1608                        if ( is_wp_error( $format ) ) {
    15691609                                return new IXR_Error( 500, $format->get_error_message() );
     1610                        }
    15701611
    15711612                        unset( $post_data['post_format'] );
     
    15891630
    15901631                $post_ID = $update ? wp_update_post( $post_data, true ) : wp_insert_post( $post_data, true );
    1591                 if ( is_wp_error( $post_ID ) )
     1632                if ( is_wp_error( $post_ID ) ) {
    15921633                        return new IXR_Error( 500, $post_ID->get_error_message() );
    1593 
    1594                 if ( ! $post_ID )
     1634                }
     1635
     1636                if ( ! $post_ID ) {
    15951637                        return new IXR_Error( 401, __( 'Sorry, your entry could not be posted.' ) );
     1638                }
    15961639
    15971640                return strval( $post_ID );
     
    16181661         */
    16191662        public function wp_editPost( $args ) {
    1620                 if ( ! $this->minimum_args( $args, 5 ) )
    1621                         return $this->error;
     1663                if ( ! $this->minimum_args( $args, 5 ) ) {
     1664                        return $this->error;
     1665                }
    16221666
    16231667                $this->escape( $args );
     
    16281672                $content_struct = $args[4];
    16291673
    1630                 if ( ! $user = $this->login( $username, $password ) )
    1631                         return $this->error;
     1674                if ( ! $user = $this->login( $username, $password ) ) {
     1675                        return $this->error;
     1676                }
    16321677
    16331678                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    16361681                $post = get_post( $post_id, ARRAY_A );
    16371682
    1638                 if ( empty( $post['ID'] ) )
     1683                if ( empty( $post['ID'] ) ) {
    16391684                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
     1685                }
    16401686
    16411687                if ( isset( $content_struct['if_not_modified_since'] ) ) {
     
    16531699                 * since _insert_post() will ignore the non-GMT date if the GMT date is set.
    16541700                 */
    1655                 if ( $post['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) )
     1701                if ( $post['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) ) {
    16561702                        unset( $post['post_date_gmt'] );
    1657                 else
     1703                } else {
    16581704                        $post['post_date_gmt'] = $this->_convert_date( $post['post_date_gmt'] );
     1705                }
    16591706
    16601707                $this->escape( $post );
     
    16621709
    16631710                $retval = $this->_insert_post( $user, $merged_content_struct );
    1664                 if ( $retval instanceof IXR_Error )
     1711                if ( $retval instanceof IXR_Error ) {
    16651712                        return $retval;
     1713                }
    16661714
    16671715                return true;
     
    16861734         */
    16871735        public function wp_deletePost( $args ) {
    1688                 if ( ! $this->minimum_args( $args, 4 ) )
    1689                         return $this->error;
     1736                if ( ! $this->minimum_args( $args, 4 ) ) {
     1737                        return $this->error;
     1738                }
    16901739
    16911740                $this->escape( $args );
    16921741
    1693                 $username   = $args[1];
    1694                 $password   = $args[2];
    1695                 $post_id    = (int) $args[3];
    1696 
    1697                 if ( ! $user = $this->login( $username, $password ) )
    1698                         return $this->error;
     1742                $username = $args[1];
     1743                $password = $args[2];
     1744                $post_id  = (int) $args[3];
     1745
     1746                if ( ! $user = $this->login( $username, $password ) ) {
     1747                        return $this->error;
     1748                }
    16991749
    17001750                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    17691819         */
    17701820        public function wp_getPost( $args ) {
    1771                 if ( ! $this->minimum_args( $args, 4 ) )
    1772                         return $this->error;
     1821                if ( ! $this->minimum_args( $args, 4 ) ) {
     1822                        return $this->error;
     1823                }
    17731824
    17741825                $this->escape( $args );
     
    17921843                }
    17931844
    1794                 if ( ! $user = $this->login( $username, $password ) )
    1795                         return $this->error;
     1845                if ( ! $user = $this->login( $username, $password ) ) {
     1846                        return $this->error;
     1847                }
    17961848
    17971849                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    18001852                $post = get_post( $post_id, ARRAY_A );
    18011853
    1802                 if ( empty( $post['ID'] ) )
     1854                if ( empty( $post['ID'] ) ) {
    18031855                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    1804 
    1805                 if ( ! current_user_can( 'edit_post', $post_id ) )
     1856                }
     1857
     1858                if ( ! current_user_can( 'edit_post', $post_id ) ) {
    18061859                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
     1860                }
    18071861
    18081862                return $this->_prepare_post( $post, $fields );
     
    18321886         */
    18331887        public function wp_getPosts( $args ) {
    1834                 if ( ! $this->minimum_args( $args, 3 ) )
    1835                         return $this->error;
     1888                if ( ! $this->minimum_args( $args, 3 ) ) {
     1889                        return $this->error;
     1890                }
    18361891
    18371892                $this->escape( $args );
     
    18481903                }
    18491904
    1850                 if ( ! $user = $this->login( $username, $password ) )
    1851                         return $this->error;
     1905                if ( ! $user = $this->login( $username, $password ) ) {
     1906                        return $this->error;
     1907                }
    18521908
    18531909                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    18581914                if ( isset( $filter['post_type'] ) ) {
    18591915                        $post_type = get_post_type_object( $filter['post_type'] );
    1860                         if ( ! ( (bool) $post_type ) )
     1916                        if ( ! ( (bool) $post_type ) ) {
    18611917                                return new IXR_Error( 403, __( 'Invalid post type.' ) );
     1918                        }
    18621919                } else {
    18631920                        $post_type = get_post_type_object( 'post' );
    18641921                }
    18651922
    1866                 if ( ! current_user_can( $post_type->cap->edit_posts ) )
     1923                if ( ! current_user_can( $post_type->cap->edit_posts ) ) {
    18671924                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type.' ) );
     1925                }
    18681926
    18691927                $query['post_type'] = $post_type->name;
    18701928
    1871                 if ( isset( $filter['post_status'] ) )
     1929                if ( isset( $filter['post_status'] ) ) {
    18721930                        $query['post_status'] = $filter['post_status'];
    1873 
    1874                 if ( isset( $filter['number'] ) )
     1931                }
     1932
     1933                if ( isset( $filter['number'] ) ) {
    18751934                        $query['numberposts'] = absint( $filter['number'] );
    1876 
    1877                 if ( isset( $filter['offset'] ) )
     1935                }
     1936
     1937                if ( isset( $filter['offset'] ) ) {
    18781938                        $query['offset'] = absint( $filter['offset'] );
     1939                }
    18791940
    18801941                if ( isset( $filter['orderby'] ) ) {
    18811942                        $query['orderby'] = $filter['orderby'];
    18821943
    1883                         if ( isset( $filter['order'] ) )
     1944                        if ( isset( $filter['order'] ) ) {
    18841945                                $query['order'] = $filter['order'];
     1946                        }
    18851947                }
    18861948
     
    18911953                $posts_list = wp_get_recent_posts( $query );
    18921954
    1893                 if ( ! $posts_list )
     1955                if ( ! $posts_list ) {
    18941956                        return array();
     1957                }
    18951958
    18961959                // Holds all the posts data.
     
    18981961
    18991962                foreach ( $posts_list as $post ) {
    1900                         if ( ! current_user_can( 'edit_post', $post['ID'] ) )
     1963                        if ( ! current_user_can( 'edit_post', $post['ID'] ) ) {
    19011964                                continue;
     1965                        }
    19021966
    19031967                        $struct[] = $this->_prepare_post( $post, $fields );
     
    19271991         */
    19281992        public function wp_newTerm( $args ) {
    1929                 if ( ! $this->minimum_args( $args, 4 ) )
    1930                         return $this->error;
     1993                if ( ! $this->minimum_args( $args, 4 ) ) {
     1994                        return $this->error;
     1995                }
    19311996
    19321997                $this->escape( $args );
     
    19362001                $content_struct = $args[3];
    19372002
    1938                 if ( ! $user = $this->login( $username, $password ) )
    1939                         return $this->error;
     2003                if ( ! $user = $this->login( $username, $password ) ) {
     2004                        return $this->error;
     2005                }
    19402006
    19412007                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    19422008                do_action( 'xmlrpc_call', 'wp.newTerm' );
    19432009
    1944                 if ( ! taxonomy_exists( $content_struct['taxonomy'] ) )
     2010                if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) {
    19452011                        return new IXR_Error( 403, __( 'Invalid taxonomy.' ) );
     2012                }
    19462013
    19472014                $taxonomy = get_taxonomy( $content_struct['taxonomy'] );
     
    19572024
    19582025                $term_data['name'] = trim( $content_struct['name'] );
    1959                 if ( empty( $term_data['name'] ) )
     2026                if ( empty( $term_data['name'] ) ) {
    19602027                        return new IXR_Error( 403, __( 'The term name cannot be empty.' ) );
     2028                }
    19612029
    19622030                if ( isset( $content_struct['parent'] ) ) {
    1963                         if ( ! $taxonomy['hierarchical'] )
     2031                        if ( ! $taxonomy['hierarchical'] ) {
    19642032                                return new IXR_Error( 403, __( 'This taxonomy is not hierarchical.' ) );
     2033                        }
    19652034
    19662035                        $parent_term_id = (int) $content_struct['parent'];
    1967                         $parent_term = get_term( $parent_term_id , $taxonomy['name'] );
    1968 
    1969                         if ( is_wp_error( $parent_term ) )
     2036                        $parent_term    = get_term( $parent_term_id, $taxonomy['name'] );
     2037
     2038                        if ( is_wp_error( $parent_term ) ) {
    19702039                                return new IXR_Error( 500, $parent_term->get_error_message() );
    1971 
    1972                         if ( ! $parent_term )
     2040                        }
     2041
     2042                        if ( ! $parent_term ) {
    19732043                                return new IXR_Error( 403, __( 'Parent term does not exist.' ) );
     2044                        }
    19742045
    19752046                        $term_data['parent'] = $content_struct['parent'];
    19762047                }
    19772048
    1978                 if ( isset( $content_struct['description'] ) )
     2049                if ( isset( $content_struct['description'] ) ) {
    19792050                        $term_data['description'] = $content_struct['description'];
    1980 
    1981                 if ( isset( $content_struct['slug'] ) )
     2051                }
     2052
     2053                if ( isset( $content_struct['slug'] ) ) {
    19822054                        $term_data['slug'] = $content_struct['slug'];
    1983 
    1984                 $term = wp_insert_term( $term_data['name'] , $taxonomy['name'] , $term_data );
    1985 
    1986                 if ( is_wp_error( $term ) )
     2055                }
     2056
     2057                $term = wp_insert_term( $term_data['name'], $taxonomy['name'], $term_data );
     2058
     2059                if ( is_wp_error( $term ) ) {
    19872060                        return new IXR_Error( 500, $term->get_error_message() );
    1988 
    1989                 if ( ! $term )
     2061                }
     2062
     2063                if ( ! $term ) {
    19902064                        return new IXR_Error( 500, __( 'Sorry, your term could not be created.' ) );
     2065                }
    19912066
    19922067                // Add term meta.
     
    20192094         */
    20202095        public function wp_editTerm( $args ) {
    2021                 if ( ! $this->minimum_args( $args, 5 ) )
    2022                         return $this->error;
     2096                if ( ! $this->minimum_args( $args, 5 ) ) {
     2097                        return $this->error;
     2098                }
    20232099
    20242100                $this->escape( $args );
     
    20292105                $content_struct = $args[4];
    20302106
    2031                 if ( ! $user = $this->login( $username, $password ) )
    2032                         return $this->error;
     2107                if ( ! $user = $this->login( $username, $password ) ) {
     2108                        return $this->error;
     2109                }
    20332110
    20342111                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    20352112                do_action( 'xmlrpc_call', 'wp.editTerm' );
    20362113
    2037                 if ( ! taxonomy_exists( $content_struct['taxonomy'] ) )
     2114                if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) {
    20382115                        return new IXR_Error( 403, __( 'Invalid taxonomy.' ) );
     2116                }
    20392117
    20402118                $taxonomy = get_taxonomy( $content_struct['taxonomy'] );
     
    20452123                $term_data = array();
    20462124
    2047                 $term = get_term( $term_id , $content_struct['taxonomy'] );
    2048 
    2049                 if ( is_wp_error( $term ) )
     2125                $term = get_term( $term_id, $content_struct['taxonomy'] );
     2126
     2127                if ( is_wp_error( $term ) ) {
    20502128                        return new IXR_Error( 500, $term->get_error_message() );
    2051 
    2052                 if ( ! $term )
     2129                }
     2130
     2131                if ( ! $term ) {
    20532132                        return new IXR_Error( 404, __( 'Invalid term ID.' ) );
     2133                }
    20542134
    20552135                if ( ! current_user_can( 'edit_term', $term_id ) ) {
     
    20602140                        $term_data['name'] = trim( $content_struct['name'] );
    20612141
    2062                         if ( empty( $term_data['name'] ) )
     2142                        if ( empty( $term_data['name'] ) ) {
    20632143                                return new IXR_Error( 403, __( 'The term name cannot be empty.' ) );
     2144                        }
    20642145                }
    20652146
    20662147                if ( ! empty( $content_struct['parent'] ) ) {
    2067                         if ( ! $taxonomy['hierarchical'] )
     2148                        if ( ! $taxonomy['hierarchical'] ) {
    20682149                                return new IXR_Error( 403, __( 'Cannot set parent term, taxonomy is not hierarchical.' ) );
     2150                        }
    20692151
    20702152                        $parent_term_id = (int) $content_struct['parent'];
    2071                         $parent_term = get_term( $parent_term_id , $taxonomy['name'] );
    2072 
    2073                         if ( is_wp_error( $parent_term ) )
     2153                        $parent_term    = get_term( $parent_term_id, $taxonomy['name'] );
     2154
     2155                        if ( is_wp_error( $parent_term ) ) {
    20742156                                return new IXR_Error( 500, $parent_term->get_error_message() );
    2075 
    2076                         if ( ! $parent_term )
     2157                        }
     2158
     2159                        if ( ! $parent_term ) {
    20772160                                return new IXR_Error( 403, __( 'Parent term does not exist.' ) );
     2161                        }
    20782162
    20792163                        $term_data['parent'] = $content_struct['parent'];
    20802164                }
    20812165
    2082                 if ( isset( $content_struct['description'] ) )
     2166                if ( isset( $content_struct['description'] ) ) {
    20832167                        $term_data['description'] = $content_struct['description'];
    2084 
    2085                 if ( isset( $content_struct['slug'] ) )
     2168                }
     2169
     2170                if ( isset( $content_struct['slug'] ) ) {
    20862171                        $term_data['slug'] = $content_struct['slug'];
    2087 
    2088                 $term = wp_update_term( $term_id , $taxonomy['name'] , $term_data );
    2089 
    2090                 if ( is_wp_error( $term ) )
     2172                }
     2173
     2174                $term = wp_update_term( $term_id, $taxonomy['name'], $term_data );
     2175
     2176                if ( is_wp_error( $term ) ) {
    20912177                        return new IXR_Error( 500, $term->get_error_message() );
    2092 
    2093                 if ( ! $term )
     2178                }
     2179
     2180                if ( ! $term ) {
    20942181                        return new IXR_Error( 500, __( 'Sorry, editing the term failed.' ) );
     2182                }
    20952183
    20962184                // Update term meta.
     
    21212209         */
    21222210        public function wp_deleteTerm( $args ) {
    2123                 if ( ! $this->minimum_args( $args, 5 ) )
    2124                         return $this->error;
     2211                if ( ! $this->minimum_args( $args, 5 ) ) {
     2212                        return $this->error;
     2213                }
    21252214
    21262215                $this->escape( $args );
    21272216
    2128                 $username           = $args[1];
    2129                 $password           = $args[2];
    2130                 $taxonomy           = $args[3];
    2131                 $term_id            = (int) $args[4];
    2132 
    2133                 if ( ! $user = $this->login( $username, $password ) )
    2134                         return $this->error;
     2217                $username = $args[1];
     2218                $password = $args[2];
     2219                $taxonomy = $args[3];
     2220                $term_id  = (int) $args[4];
     2221
     2222                if ( ! $user = $this->login( $username, $password ) ) {
     2223                        return $this->error;
     2224                }
    21352225
    21362226                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    21372227                do_action( 'xmlrpc_call', 'wp.deleteTerm' );
    21382228
    2139                 if ( ! taxonomy_exists( $taxonomy ) )
     2229                if ( ! taxonomy_exists( $taxonomy ) ) {
    21402230                        return new IXR_Error( 403, __( 'Invalid taxonomy.' ) );
     2231                }
    21412232
    21422233                $taxonomy = get_taxonomy( $taxonomy );
    2143                 $term = get_term( $term_id, $taxonomy->name );
    2144 
    2145                 if ( is_wp_error( $term ) )
     2234                $term     = get_term( $term_id, $taxonomy->name );
     2235
     2236                if ( is_wp_error( $term ) ) {
    21462237                        return new IXR_Error( 500, $term->get_error_message() );
    2147 
    2148                 if ( ! $term )
     2238                }
     2239
     2240                if ( ! $term ) {
    21492241                        return new IXR_Error( 404, __( 'Invalid term ID.' ) );
     2242                }
    21502243
    21512244                if ( ! current_user_can( 'delete_term', $term_id ) ) {
     
    21552248                $result = wp_delete_term( $term_id, $taxonomy->name );
    21562249
    2157                 if ( is_wp_error( $result ) )
     2250                if ( is_wp_error( $result ) ) {
    21582251                        return new IXR_Error( 500, $term->get_error_message() );
    2159 
    2160                 if ( ! $result )
     2252                }
     2253
     2254                if ( ! $result ) {
    21612255                        return new IXR_Error( 500, __( 'Sorry, deleting the term failed.' ) );
     2256                }
    21622257
    21632258                return $result;
     
    21922287         */
    21932288        public function wp_getTerm( $args ) {
    2194                 if ( ! $this->minimum_args( $args, 5 ) )
    2195                         return $this->error;
     2289                if ( ! $this->minimum_args( $args, 5 ) ) {
     2290                        return $this->error;
     2291                }
    21962292
    21972293                $this->escape( $args );
    21982294
    2199                 $username           = $args[1];
    2200                 $password           = $args[2];
    2201                 $taxonomy           = $args[3];
    2202                 $term_id            = (int) $args[4];
    2203 
    2204                 if ( ! $user = $this->login( $username, $password ) )
    2205                         return $this->error;
     2295                $username = $args[1];
     2296                $password = $args[2];
     2297                $taxonomy = $args[3];
     2298                $term_id  = (int) $args[4];
     2299
     2300                if ( ! $user = $this->login( $username, $password ) ) {
     2301                        return $this->error;
     2302                }
    22062303
    22072304                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    22082305                do_action( 'xmlrpc_call', 'wp.getTerm' );
    22092306
    2210                 if ( ! taxonomy_exists( $taxonomy ) )
     2307                if ( ! taxonomy_exists( $taxonomy ) ) {
    22112308                        return new IXR_Error( 403, __( 'Invalid taxonomy.' ) );
     2309                }
    22122310
    22132311                $taxonomy = get_taxonomy( $taxonomy );
    22142312
    2215                 $term = get_term( $term_id , $taxonomy->name, ARRAY_A );
    2216 
    2217                 if ( is_wp_error( $term ) )
     2313                $term = get_term( $term_id, $taxonomy->name, ARRAY_A );
     2314
     2315                if ( is_wp_error( $term ) ) {
    22182316                        return new IXR_Error( 500, $term->get_error_message() );
    2219 
    2220                 if ( ! $term )
     2317                }
     2318
     2319                if ( ! $term ) {
    22212320                        return new IXR_Error( 404, __( 'Invalid term ID.' ) );
     2321                }
    22222322
    22232323                if ( ! current_user_can( 'assign_term', $term_id ) ) {
     
    22512351         */
    22522352        public function wp_getTerms( $args ) {
    2253                 if ( ! $this->minimum_args( $args, 4 ) )
    2254                         return $this->error;
     2353                if ( ! $this->minimum_args( $args, 4 ) ) {
     2354                        return $this->error;
     2355                }
    22552356
    22562357                $this->escape( $args );
    22572358
    2258                 $username       = $args[1];
    2259                 $password       = $args[2];
    2260                 $taxonomy       = $args[3];
    2261                 $filter         = isset( $args[4] ) ? $args[4] : array();
    2262 
    2263                 if ( ! $user = $this->login( $username, $password ) )
    2264                         return $this->error;
     2359                $username = $args[1];
     2360                $password = $args[2];
     2361                $taxonomy = $args[3];
     2362                $filter   = isset( $args[4] ) ? $args[4] : array();
     2363
     2364                if ( ! $user = $this->login( $username, $password ) ) {
     2365                        return $this->error;
     2366                }
    22652367
    22662368                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    22672369                do_action( 'xmlrpc_call', 'wp.getTerms' );
    22682370
    2269                 if ( ! taxonomy_exists( $taxonomy ) )
     2371                if ( ! taxonomy_exists( $taxonomy ) ) {
    22702372                        return new IXR_Error( 403, __( 'Invalid taxonomy.' ) );
     2373                }
    22712374
    22722375                $taxonomy = get_taxonomy( $taxonomy );
    22732376
    2274                 if ( ! current_user_can( $taxonomy->cap->assign_terms ) )
     2377                if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) {
    22752378                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) );
     2379                }
    22762380
    22772381                $query = array();
    22782382
    2279                 if ( isset( $filter['number'] ) )
     2383                if ( isset( $filter['number'] ) ) {
    22802384                        $query['number'] = absint( $filter['number'] );
    2281 
    2282                 if ( isset( $filter['offset'] ) )
     2385                }
     2386
     2387                if ( isset( $filter['offset'] ) ) {
    22832388                        $query['offset'] = absint( $filter['offset'] );
     2389                }
    22842390
    22852391                if ( isset( $filter['orderby'] ) ) {
    22862392                        $query['orderby'] = $filter['orderby'];
    22872393
    2288                         if ( isset( $filter['order'] ) )
     2394                        if ( isset( $filter['order'] ) ) {
    22892395                                $query['order'] = $filter['order'];
    2290                 }
    2291 
    2292                 if ( isset( $filter['hide_empty'] ) )
     2396                        }
     2397                }
     2398
     2399                if ( isset( $filter['hide_empty'] ) ) {
    22932400                        $query['hide_empty'] = $filter['hide_empty'];
    2294                 else
     2401                } else {
    22952402                        $query['get'] = 'all';
    2296 
    2297                 if ( isset( $filter['search'] ) )
     2403                }
     2404
     2405                if ( isset( $filter['search'] ) ) {
    22982406                        $query['search'] = $filter['search'];
     2407                }
    22992408
    23002409                $terms = get_terms( $taxonomy->name, $query );
    23012410
    2302                 if ( is_wp_error( $terms ) )
     2411                if ( is_wp_error( $terms ) ) {
    23032412                        return new IXR_Error( 500, $terms->get_error_message() );
     2413                }
    23042414
    23052415                $struct = array();
     
    23332443         */
    23342444        public function wp_getTaxonomy( $args ) {
    2335                 if ( ! $this->minimum_args( $args, 4 ) )
    2336                         return $this->error;
     2445                if ( ! $this->minimum_args( $args, 4 ) ) {
     2446                        return $this->error;
     2447                }
    23372448
    23382449                $this->escape( $args );
     
    23562467                }
    23572468
    2358                 if ( ! $user = $this->login( $username, $password ) )
    2359                         return $this->error;
     2469                if ( ! $user = $this->login( $username, $password ) ) {
     2470                        return $this->error;
     2471                }
    23602472
    23612473                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    23622474                do_action( 'xmlrpc_call', 'wp.getTaxonomy' );
    23632475
    2364                 if ( ! taxonomy_exists( $taxonomy ) )
     2476                if ( ! taxonomy_exists( $taxonomy ) ) {
    23652477                        return new IXR_Error( 403, __( 'Invalid taxonomy.' ) );
     2478                }
    23662479
    23672480                $taxonomy = get_taxonomy( $taxonomy );
    23682481
    2369                 if ( ! current_user_can( $taxonomy->cap->assign_terms ) )
     2482                if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) {
    23702483                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) );
     2484                }
    23712485
    23722486                return $this->_prepare_taxonomy( $taxonomy, $fields );
     
    23932507         */
    23942508        public function wp_getTaxonomies( $args ) {
    2395                 if ( ! $this->minimum_args( $args, 3 ) )
    2396                         return $this->error;
     2509                if ( ! $this->minimum_args( $args, 3 ) ) {
     2510                        return $this->error;
     2511                }
    23972512
    23982513                $this->escape( $args );
     
    24092524                }
    24102525
    2411                 if ( ! $user = $this->login( $username, $password ) )
    2412                         return $this->error;
     2526                if ( ! $user = $this->login( $username, $password ) ) {
     2527                        return $this->error;
     2528                }
    24132529
    24142530                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    24222538                foreach ( $taxonomies as $taxonomy ) {
    24232539                        // capability check for post_types
    2424                         if ( ! current_user_can( $taxonomy->cap->assign_terms ) )
     2540                        if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) {
    24252541                                continue;
     2542                        }
    24262543
    24272544                        $struct[] = $this->_prepare_taxonomy( $taxonomy, $fields );
     
    24682585         */
    24692586        public function wp_getUser( $args ) {
    2470                 if ( ! $this->minimum_args( $args, 4 ) )
    2471                         return $this->error;
     2587                if ( ! $this->minimum_args( $args, 4 ) ) {
     2588                        return $this->error;
     2589                }
    24722590
    24732591                $this->escape( $args );
     
    24912609                }
    24922610
    2493                 if ( ! $user = $this->login( $username, $password ) )
    2494                         return $this->error;
     2611                if ( ! $user = $this->login( $username, $password ) ) {
     2612                        return $this->error;
     2613                }
    24952614
    24962615                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    24972616                do_action( 'xmlrpc_call', 'wp.getUser' );
    24982617
    2499                 if ( ! current_user_can( 'edit_user', $user_id ) )
     2618                if ( ! current_user_can( 'edit_user', $user_id ) ) {
    25002619                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this user.' ) );
     2620                }
    25012621
    25022622                $user_data = get_userdata( $user_id );
    25032623
    2504                 if ( ! $user_data )
     2624                if ( ! $user_data ) {
    25052625                        return new IXR_Error( 404, __( 'Invalid user ID.' ) );
     2626                }
    25062627
    25072628                return $this->_prepare_user( $user_data, $fields );
     
    25332654         */
    25342655        public function wp_getUsers( $args ) {
    2535                 if ( ! $this->minimum_args( $args, 3 ) )
    2536                         return $this->error;
     2656                if ( ! $this->minimum_args( $args, 3 ) ) {
     2657                        return $this->error;
     2658                }
    25372659
    25382660                $this->escape( $args );
     
    25492671                }
    25502672
    2551                 if ( ! $user = $this->login( $username, $password ) )
    2552                         return $this->error;
     2673                if ( ! $user = $this->login( $username, $password ) ) {
     2674                        return $this->error;
     2675                }
    25532676
    25542677                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    25552678                do_action( 'xmlrpc_call', 'wp.getUsers' );
    25562679
    2557                 if ( ! current_user_can( 'list_users' ) )
     2680                if ( ! current_user_can( 'list_users' ) ) {
    25582681                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to list users.' ) );
     2682                }
    25592683
    25602684                $query = array( 'fields' => 'all_with_meta' );
     
    25662690                        $query['orderby'] = $filter['orderby'];
    25672691
    2568                         if ( isset( $filter['order'] ) )
     2692                        if ( isset( $filter['order'] ) ) {
    25692693                                $query['order'] = $filter['order'];
     2694                        }
    25702695                }
    25712696
    25722697                if ( isset( $filter['role'] ) ) {
    2573                         if ( get_role( $filter['role'] ) === null )
     2698                        if ( get_role( $filter['role'] ) === null ) {
    25742699                                return new IXR_Error( 403, __( 'Invalid role.' ) );
     2700                        }
    25752701
    25762702                        $query['role'] = $filter['role'];
     
    25852711                $_users = array();
    25862712                foreach ( $users as $user_data ) {
    2587                         if ( current_user_can( 'edit_user', $user_data->ID ) )
     2713                        if ( current_user_can( 'edit_user', $user_data->ID ) ) {
    25882714                                $_users[] = $this->_prepare_user( $user_data, $fields );
     2715                        }
    25892716                }
    25902717                return $_users;
     
    26072734         */
    26082735        public function wp_getProfile( $args ) {
    2609                 if ( ! $this->minimum_args( $args, 3 ) )
    2610                         return $this->error;
     2736                if ( ! $this->minimum_args( $args, 3 ) ) {
     2737                        return $this->error;
     2738                }
    26112739
    26122740                $this->escape( $args );
     
    26222750                }
    26232751
    2624                 if ( ! $user = $this->login( $username, $password ) )
    2625                         return $this->error;
     2752                if ( ! $user = $this->login( $username, $password ) ) {
     2753                        return $this->error;
     2754                }
    26262755
    26272756                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    26282757                do_action( 'xmlrpc_call', 'wp.getProfile' );
    26292758
    2630                 if ( ! current_user_can( 'edit_user', $user->ID ) )
     2759                if ( ! current_user_can( 'edit_user', $user->ID ) ) {
    26312760                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) );
     2761                }
    26322762
    26332763                $user_data = get_userdata( $user->ID );
     
    26592789         */
    26602790        public function wp_editProfile( $args ) {
    2661                 if ( ! $this->minimum_args( $args, 4 ) )
    2662                         return $this->error;
     2791                if ( ! $this->minimum_args( $args, 4 ) ) {
     2792                        return $this->error;
     2793                }
    26632794
    26642795                $this->escape( $args );
     
    26682799                $content_struct = $args[3];
    26692800
    2670                 if ( ! $user = $this->login( $username, $password ) )
    2671                         return $this->error;
     2801                if ( ! $user = $this->login( $username, $password ) ) {
     2802                        return $this->error;
     2803                }
    26722804
    26732805                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    26742806                do_action( 'xmlrpc_call', 'wp.editProfile' );
    26752807
    2676                 if ( ! current_user_can( 'edit_user', $user->ID ) )
     2808                if ( ! current_user_can( 'edit_user', $user->ID ) ) {
    26772809                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) );
     2810                }
    26782811
    26792812                // holds data of the user
    2680                 $user_data = array();
     2813                $user_data       = array();
    26812814                $user_data['ID'] = $user->ID;
    26822815
    26832816                // only set the user details if it was given
    2684                 if ( isset( $content_struct['first_name'] ) )
     2817                if ( isset( $content_struct['first_name'] ) ) {
    26852818                        $user_data['first_name'] = $content_struct['first_name'];
    2686 
    2687                 if ( isset( $content_struct['last_name'] ) )
     2819                }
     2820
     2821                if ( isset( $content_struct['last_name'] ) ) {
    26882822                        $user_data['last_name'] = $content_struct['last_name'];
    2689 
    2690                 if ( isset( $content_struct['url'] ) )
     2823                }
     2824
     2825                if ( isset( $content_struct['url'] ) ) {
    26912826                        $user_data['user_url'] = $content_struct['url'];
    2692 
    2693                 if ( isset( $content_struct['display_name'] ) )
     2827                }
     2828
     2829                if ( isset( $content_struct['display_name'] ) ) {
    26942830                        $user_data['display_name'] = $content_struct['display_name'];
    2695 
    2696                 if ( isset( $content_struct['nickname'] ) )
     2831                }
     2832
     2833                if ( isset( $content_struct['nickname'] ) ) {
    26972834                        $user_data['nickname'] = $content_struct['nickname'];
    2698 
    2699                 if ( isset( $content_struct['nicename'] ) )
     2835                }
     2836
     2837                if ( isset( $content_struct['nicename'] ) ) {
    27002838                        $user_data['user_nicename'] = $content_struct['nicename'];
    2701 
    2702                 if ( isset( $content_struct['bio'] ) )
     2839                }
     2840
     2841                if ( isset( $content_struct['bio'] ) ) {
    27032842                        $user_data['description'] = $content_struct['bio'];
     2843                }
    27042844
    27052845                $result = wp_update_user( $user_data );
    27062846
    2707                 if ( is_wp_error( $result ) )
     2847                if ( is_wp_error( $result ) ) {
    27082848                        return new IXR_Error( 500, $result->get_error_message() );
    2709 
    2710                 if ( ! $result )
     2849                }
     2850
     2851                if ( ! $result ) {
    27112852                        return new IXR_Error( 500, __( 'Sorry, the user cannot be updated.' ) );
     2853                }
    27122854
    27132855                return true;
     
    27362878                $password = $args[3];
    27372879
    2738                 if ( !$user = $this->login($username, $password) ) {
    2739                         return $this->error;
    2740                 }
    2741 
    2742                 $page = get_post($page_id);
    2743                 if ( ! $page )
     2880                if ( ! $user = $this->login( $username, $password ) ) {
     2881                        return $this->error;
     2882                }
     2883
     2884                $page = get_post( $page_id );
     2885                if ( ! $page ) {
    27442886                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    2745 
    2746                 if ( !current_user_can( 'edit_page', $page_id ) )
     2887                }
     2888
     2889                if ( ! current_user_can( 'edit_page', $page_id ) ) {
    27472890                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) );
     2891                }
    27482892
    27492893                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    27512895
    27522896                // If we found the page then format the data.
    2753                 if ( $page->ID && ($page->post_type == 'page') ) {
     2897                if ( $page->ID && ( $page->post_type == 'page' ) ) {
    27542898                        return $this->_prepare_page( $page );
    2755                 }
    2756                 // If the page doesn't exist indicate that.
     2899                } // If the page doesn't exist indicate that.
    27572900                else {
    27582901                        return new IXR_Error( 404, __( 'Sorry, no such page.' ) );
     
    27802923                $username  = $args[1];
    27812924                $password  = $args[2];
    2782                 $num_pages = isset($args[3]) ? (int) $args[3] : 10;
    2783 
    2784                 if ( !$user = $this->login($username, $password) )
    2785                         return $this->error;
    2786 
    2787                 if ( !current_user_can( 'edit_pages' ) )
     2925                $num_pages = isset( $args[3] ) ? (int) $args[3] : 10;
     2926
     2927                if ( ! $user = $this->login( $username, $password ) ) {
     2928                        return $this->error;
     2929                }
     2930
     2931                if ( ! current_user_can( 'edit_pages' ) ) {
    27882932                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) );
     2933                }
    27892934
    27902935                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    27912936                do_action( 'xmlrpc_call', 'wp.getPages' );
    27922937
    2793                 $pages = get_posts( array('post_type' => 'page', 'post_status' => 'any', 'numberposts' => $num_pages) );
    2794                 $num_pages = count($pages);
     2938                $pages     = get_posts(
     2939                        array(
     2940                                'post_type'   => 'page',
     2941                                'post_status' => 'any',
     2942                                'numberposts' => $num_pages,
     2943                        )
     2944                );
     2945                $num_pages = count( $pages );
    27952946
    27962947                // If we have pages, put together their info.
     
    27982949                        $pages_struct = array();
    27992950
    2800                         foreach ($pages as $page) {
    2801                                 if ( current_user_can( 'edit_page', $page->ID ) )
     2951                        foreach ( $pages as $page ) {
     2952                                if ( current_user_can( 'edit_page', $page->ID ) ) {
    28022953                                        $pages_struct[] = $this->_prepare_page( $page );
     2954                                }
    28032955                        }
    28042956
     
    28312983                $password = $this->escape( $args[2] );
    28322984
    2833                 if ( !$user = $this->login($username, $password) )
    2834                         return $this->error;
     2985                if ( ! $user = $this->login( $username, $password ) ) {
     2986                        return $this->error;
     2987                }
    28352988
    28362989                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    28382991
    28392992                // Mark this as content for a page.
    2840                 $args[3]["post_type"] = 'page';
     2993                $args[3]['post_type'] = 'page';
    28412994
    28422995                // Let mw_newPost do all of the heavy lifting.
     
    28663019                $page_id  = (int) $args[3];
    28673020
    2868                 if ( !$user = $this->login($username, $password) )
    2869                         return $this->error;
     3021                if ( ! $user = $this->login( $username, $password ) ) {
     3022                        return $this->error;
     3023                }
    28703024
    28713025                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    28743028                // Get the current page based on the page_id and
    28753029                // make sure it is a page and not a post.
    2876                 $actual_page = get_post($page_id, ARRAY_A);
    2877                 if ( !$actual_page || ($actual_page['post_type'] != 'page') )
     3030                $actual_page = get_post( $page_id, ARRAY_A );
     3031                if ( ! $actual_page || ( $actual_page['post_type'] != 'page' ) ) {
    28783032                        return new IXR_Error( 404, __( 'Sorry, no such page.' ) );
     3033                }
    28793034
    28803035                // Make sure the user can delete pages.
    2881                 if ( !current_user_can('delete_page', $page_id) )
     3036                if ( ! current_user_can( 'delete_page', $page_id ) ) {
    28823037                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this page.' ) );
     3038                }
    28833039
    28843040                // Attempt to delete the page.
    2885                 $result = wp_delete_post($page_id);
    2886                 if ( !$result )
     3041                $result = wp_delete_post( $page_id );
     3042                if ( ! $result ) {
    28873043                        return new IXR_Error( 500, __( 'Failed to delete the page.' ) );
     3044                }
    28883045
    28893046                /**
     
    29283085                $escaped_password = $this->escape( $password );
    29293086
    2930                 if ( !$user = $this->login( $escaped_username, $escaped_password ) ) {
     3087                if ( ! $user = $this->login( $escaped_username, $escaped_password ) ) {
    29313088                        return $this->error;
    29323089                }
     
    29363093
    29373094                // Get the page data and make sure it is a page.
    2938                 $actual_page = get_post($page_id, ARRAY_A);
    2939                 if ( !$actual_page || ($actual_page['post_type'] != 'page') )
     3095                $actual_page = get_post( $page_id, ARRAY_A );
     3096                if ( ! $actual_page || ( $actual_page['post_type'] != 'page' ) ) {
    29403097                        return new IXR_Error( 404, __( 'Sorry, no such page.' ) );
     3098                }
    29413099
    29423100                // Make sure the user is allowed to edit pages.
    2943                 if ( !current_user_can('edit_page', $page_id) )
     3101                if ( ! current_user_can( 'edit_page', $page_id ) ) {
    29443102                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) );
     3103                }
    29453104
    29463105                // Mark this as content for a page.
     
    29533112                        $password,
    29543113                        $content,
    2955                         $publish
     3114                        $publish,
    29563115                );
    29573116
     
    29843143                $password = $args[2];
    29853144
    2986                 if ( !$user = $this->login($username, $password) )
    2987                         return $this->error;
    2988 
    2989                 if ( !current_user_can( 'edit_pages' ) )
     3145                if ( ! $user = $this->login( $username, $password ) ) {
     3146                        return $this->error;
     3147                }
     3148
     3149                if ( ! current_user_can( 'edit_pages' ) ) {
    29903150                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) );
     3151                }
    29913152
    29923153                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    29943155
    29953156                // Get list of pages ids and titles
    2996                 $page_list = $wpdb->get_results("
     3157                $page_list = $wpdb->get_results(
     3158                        "
    29973159                        SELECT ID page_id,
    29983160                                post_title page_title,
     
    30043166                        WHERE post_type = 'page'
    30053167                        ORDER BY ID
    3006                 ");
     3168                "
     3169                );
    30073170
    30083171                // The date needs to be formatted properly.
    3009                 $num_pages = count($page_list);
     3172                $num_pages = count( $page_list );
    30103173                for ( $i = 0; $i < $num_pages; $i++ ) {
    3011                         $page_list[$i]->dateCreated = $this->_convert_date(  $page_list[$i]->post_date );
    3012                         $page_list[$i]->date_created_gmt = $this->_convert_date_gmt( $page_list[$i]->post_date_gmt, $page_list[$i]->post_date );
    3013 
    3014                         unset($page_list[$i]->post_date_gmt);
    3015                         unset($page_list[$i]->post_date);
    3016                         unset($page_list[$i]->post_status);
     3174                        $page_list[ $i ]->dateCreated      = $this->_convert_date( $page_list[ $i ]->post_date );
     3175                        $page_list[ $i ]->date_created_gmt = $this->_convert_date_gmt( $page_list[ $i ]->post_date_gmt, $page_list[ $i ]->post_date );
     3176
     3177                        unset( $page_list[ $i ]->post_date_gmt );
     3178                        unset( $page_list[ $i ]->post_date );
     3179                        unset( $page_list[ $i ]->post_status );
    30173180                }
    30183181
     
    30403203                $password = $args[2];
    30413204
    3042                 if ( !$user = $this->login($username, $password) )
    3043                         return $this->error;
    3044 
    3045                 if ( !current_user_can('edit_posts') )
     3205                if ( ! $user = $this->login( $username, $password ) ) {
     3206                        return $this->error;
     3207                }
     3208
     3209                if ( ! current_user_can( 'edit_posts' ) ) {
    30463210                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) );
     3211                }
    30473212
    30483213                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    30503215
    30513216                $authors = array();
    3052                 foreach ( get_users( array( 'fields' => array('ID','user_login','display_name') ) ) as $user ) {
     3217                foreach ( get_users( array( 'fields' => array( 'ID', 'user_login', 'display_name' ) ) ) as $user ) {
    30533218                        $authors[] = array(
    3054                                 'user_id'       => $user->ID,
    3055                                 'user_login'    => $user->user_login,
    3056                                 'display_name'  => $user->display_name
     3219                                'user_id'      => $user->ID,
     3220                                'user_login'   => $user->user_login,
     3221                                'display_name' => $user->display_name,
    30573222                        );
    30583223                }
     
    30813246                $password = $args[2];
    30823247
    3083                 if ( !$user = $this->login($username, $password) )
    3084                         return $this->error;
    3085 
    3086                 if ( !current_user_can( 'edit_posts' ) )
     3248                if ( ! $user = $this->login( $username, $password ) ) {
     3249                        return $this->error;
     3250                }
     3251
     3252                if ( ! current_user_can( 'edit_posts' ) ) {
    30873253                        return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view tags.' ) );
     3254                }
    30883255
    30893256                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    30943261                if ( $all_tags = get_tags() ) {
    30953262                        foreach ( (array) $all_tags as $tag ) {
    3096                                 $struct = array();
    3097                                 $struct['tag_id']                       = $tag->term_id;
    3098                                 $struct['name']                         = $tag->name;
    3099                                 $struct['count']                        = $tag->count;
    3100                                 $struct['slug']                         = $tag->slug;
    3101                                 $struct['html_url']                     = esc_html( get_tag_link( $tag->term_id ) );
    3102                                 $struct['rss_url']                      = esc_html( get_tag_feed_link( $tag->term_id ) );
     3263                                $struct             = array();
     3264                                $struct['tag_id']   = $tag->term_id;
     3265                                $struct['name']     = $tag->name;
     3266                                $struct['count']    = $tag->count;
     3267                                $struct['slug']     = $tag->slug;
     3268                                $struct['html_url'] = esc_html( get_tag_link( $tag->term_id ) );
     3269                                $struct['rss_url']  = esc_html( get_tag_feed_link( $tag->term_id ) );
    31033270
    31043271                                $tags[] = $struct;
     
    31313298                $category = $args[3];
    31323299
    3133                 if ( !$user = $this->login($username, $password) )
    3134                         return $this->error;
     3300                if ( ! $user = $this->login( $username, $password ) ) {
     3301                        return $this->error;
     3302                }
    31353303
    31363304                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    31443312                // If no slug was provided make it empty so that
    31453313                // WordPress will generate one.
    3146                 if ( empty($category['slug']) )
     3314                if ( empty( $category['slug'] ) ) {
    31473315                        $category['slug'] = '';
     3316                }
    31483317
    31493318                // If no parent_id was provided make it empty
    31503319                // so that it will be a top level page (no parent).
    3151                 if ( !isset($category['parent_id']) )
     3320                if ( ! isset( $category['parent_id'] ) ) {
    31523321                        $category['parent_id'] = '';
     3322                }
    31533323
    31543324                // If no description was provided make it empty.
    3155                 if ( empty($category["description"]) )
    3156                         $category["description"] = "";
     3325                if ( empty( $category['description'] ) ) {
     3326                        $category['description'] = '';
     3327                }
    31573328
    31583329                $new_category = array(
    3159                         'cat_name'                              => $category['name'],
    3160                         'category_nicename'             => $category['slug'],
    3161                         'category_parent'               => $category['parent_id'],
    3162                         'category_description'  => $category['description']
     3330                        'cat_name'             => $category['name'],
     3331                        'category_nicename'    => $category['slug'],
     3332                        'category_parent'      => $category['parent_id'],
     3333                        'category_description' => $category['description'],
    31633334                );
    31643335
    3165                 $cat_id = wp_insert_category($new_category, true);
     3336                $cat_id = wp_insert_category( $new_category, true );
    31663337                if ( is_wp_error( $cat_id ) ) {
    3167                         if ( 'term_exists' == $cat_id->get_error_code() )
     3338                        if ( 'term_exists' == $cat_id->get_error_code() ) {
    31683339                                return (int) $cat_id->get_error_data();
    3169                         else
    3170                                 return new IXR_Error(500, __('Sorry, the new category failed.'));
     3340                        } else {
     3341                                return new IXR_Error( 500, __( 'Sorry, the new category failed.' ) );
     3342                        }
    31713343                } elseif ( ! $cat_id ) {
    3172                         return new IXR_Error(500, __('Sorry, the new category failed.'));
     3344                        return new IXR_Error( 500, __( 'Sorry, the new category failed.' ) );
    31733345                }
    31743346
     
    32083380                $category_id = (int) $args[3];
    32093381
    3210                 if ( !$user = $this->login($username, $password) )
    3211                         return $this->error;
     3382                if ( ! $user = $this->login( $username, $password ) ) {
     3383                        return $this->error;
     3384                }
    32123385
    32133386                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    32593432                $max_results = (int) $args[4];
    32603433
    3261                 if ( !$user = $this->login($username, $password) )
    3262                         return $this->error;
    3263 
    3264                 if ( !current_user_can( 'edit_posts' ) )
     3434                if ( ! $user = $this->login( $username, $password ) ) {
     3435                        return $this->error;
     3436                }
     3437
     3438                if ( ! current_user_can( 'edit_posts' ) ) {
    32653439                        return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) );
     3440                }
    32663441
    32673442                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    32693444
    32703445                $category_suggestions = array();
    3271                 $args = array('get' => 'all', 'number' => $max_results, 'name__like' => $category);
    3272                 foreach ( (array) get_categories($args) as $cat ) {
     3446                $args                 = array(
     3447                        'get'        => 'all',
     3448                        'number'     => $max_results,
     3449                        'name__like' => $category,
     3450                );
     3451                foreach ( (array) get_categories( $args ) as $cat ) {
    32733452                        $category_suggestions[] = array(
    3274                                 'category_id'   => $cat->term_id,
    3275                                 'category_name' => $cat->name
     3453                                'category_id'   => $cat->term_id,
     3454                                'category_name' => $cat->name,
    32763455                        );
    32773456                }
     
    32953474         * @return array|IXR_Error
    32963475         */
    3297         public function wp_getComment($args) {
    3298                 $this->escape($args);
    3299 
    3300                 $username       = $args[1];
    3301                 $password       = $args[2];
    3302                 $comment_id     = (int) $args[3];
     3476        public function wp_getComment( $args ) {
     3477                $this->escape( $args );
     3478
     3479                $username   = $args[1];
     3480                $password   = $args[2];
     3481                $comment_id = (int) $args[3];
    33033482
    33043483                if ( ! $user = $this->login( $username, $password ) ) {
     
    33513530                $username = $args[1];
    33523531                $password = $args[2];
    3353                 $struct   = isset( $args[3] ) ? $args[3] : array();
     3532                $struct   = isset( $args[3] ) ? $args[3] : array();
    33543533
    33553534                if ( ! $user = $this->login( $username, $password ) ) {
     
    33943573                }
    33953574
    3396                 $comments = get_comments( array(
    3397                         'status' => $status,
    3398                         'post_id' => $post_id,
    3399                         'offset' => $offset,
    3400                         'number' => $number,
    3401                         'post_type' => $post_type,
    3402                 ) );
     3575                $comments = get_comments(
     3576                        array(
     3577                                'status'    => $status,
     3578                                'post_id'   => $post_id,
     3579                                'offset'    => $offset,
     3580                                'number'    => $number,
     3581                                'post_type' => $post_type,
     3582                        )
     3583                );
    34033584
    34043585                $comments_struct = array();
     
    34313612         */
    34323613        public function wp_deleteComment( $args ) {
    3433                 $this->escape($args);
    3434 
    3435                 $username       = $args[1];
    3436                 $password       = $args[2];
    3437                 $comment_ID     = (int) $args[3];
     3614                $this->escape( $args );
     3615
     3616                $username   = $args[1];
     3617                $password   = $args[2];
     3618                $comment_ID = (int) $args[3];
    34383619
    34393620                if ( ! $user = $this->login( $username, $password ) ) {
     
    34993680                $this->escape( $args );
    35003681
    3501                 $username       = $args[1];
    3502                 $password       = $args[2];
    3503                 $comment_ID     = (int) $args[3];
     3682                $username       = $args[1];
     3683                $password       = $args[2];
     3684                $comment_ID     = (int) $args[3];
    35043685                $content_struct = $args[4];
    35053686
    3506                 if ( !$user = $this->login( $username, $password ) ) {
     3687                if ( ! $user = $this->login( $username, $password ) ) {
    35073688                        return $this->error;
    35083689                }
     
    35193700                do_action( 'xmlrpc_call', 'wp.editComment' );
    35203701
    3521                 if ( isset($content_struct['status']) ) {
     3702                if ( isset( $content_struct['status'] ) ) {
    35223703                        $statuses = get_comment_statuses();
    3523                         $statuses = array_keys($statuses);
    3524 
    3525                         if ( ! in_array($content_struct['status'], $statuses) )
     3704                        $statuses = array_keys( $statuses );
     3705
     3706                        if ( ! in_array( $content_struct['status'], $statuses ) ) {
    35263707                                return new IXR_Error( 401, __( 'Invalid comment status.' ) );
     3708                        }
    35273709                        $comment_approved = $content_struct['status'];
    35283710                }
    35293711
    35303712                // Do some timestamp voodoo
    3531                 if ( !empty( $content_struct['date_created_gmt'] ) ) {
     3713                if ( ! empty( $content_struct['date_created_gmt'] ) ) {
    35323714                        // We know this is supposed to be GMT, so we're going to slap that Z on there by force
    3533                         $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
    3534                         $comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
    3535                         $comment_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
    3536                 }
    3537 
    3538                 if ( isset($content_struct['content']) )
     3715                        $dateCreated      = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
     3716                        $comment_date     = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
     3717                        $comment_date_gmt = iso8601_to_datetime( $dateCreated, 'GMT' );
     3718                }
     3719
     3720                if ( isset( $content_struct['content'] ) ) {
    35393721                        $comment_content = $content_struct['content'];
    3540 
    3541                 if ( isset($content_struct['author']) )
     3722                }
     3723
     3724                if ( isset( $content_struct['author'] ) ) {
    35423725                        $comment_author = $content_struct['author'];
    3543 
    3544                 if ( isset($content_struct['author_url']) )
     3726                }
     3727
     3728                if ( isset( $content_struct['author_url'] ) ) {
    35453729                        $comment_author_url = $content_struct['author_url'];
    3546 
    3547                 if ( isset($content_struct['author_email']) )
     3730                }
     3731
     3732                if ( isset( $content_struct['author_email'] ) ) {
    35483733                        $comment_author_email = $content_struct['author_email'];
     3734                }
    35493735
    35503736                // We've got all the data -- post it:
    3551                 $comment = compact('comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url');
    3552 
    3553                 $result = wp_update_comment($comment);
    3554                 if ( is_wp_error( $result ) )
    3555                         return new IXR_Error(500, $result->get_error_message());
    3556 
    3557                 if ( !$result )
    3558                         return new IXR_Error(500, __('Sorry, the comment could not be edited.'));
     3737                $comment = compact( 'comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url' );
     3738
     3739                $result = wp_update_comment( $comment );
     3740                if ( is_wp_error( $result ) ) {
     3741                        return new IXR_Error( 500, $result->get_error_message() );
     3742                }
     3743
     3744                if ( ! $result ) {
     3745                        return new IXR_Error( 500, __( 'Sorry, the comment could not be edited.' ) );
     3746                }
    35593747
    35603748                /**
     
    35873775         * @return int|IXR_Error See wp_new_comment().
    35883776         */
    3589         public function wp_newComment($args) {
    3590                 $this->escape($args);
     3777        public function wp_newComment( $args ) {
     3778                $this->escape( $args );
    35913779
    35923780                $username       = $args[1];
     
    36053793                $allow_anon = apply_filters( 'xmlrpc_allow_anonymous_comments', false );
    36063794
    3607                 $user = $this->login($username, $password);
    3608 
    3609                 if ( !$user ) {
     3795                $user = $this->login( $username, $password );
     3796
     3797                if ( ! $user ) {
    36103798                        $logged_in = false;
    3611                         if ( $allow_anon && get_option('comment_registration') ) {
     3799                        if ( $allow_anon && get_option( 'comment_registration' ) ) {
    36123800                                return new IXR_Error( 403, __( 'You must be registered to comment.' ) );
    36133801                        } elseif ( ! $allow_anon ) {
     
    36183806                }
    36193807
    3620                 if ( is_numeric($post) )
    3621                         $post_id = absint($post);
    3622                 else
    3623                         $post_id = url_to_postid($post);
     3808                if ( is_numeric( $post ) ) {
     3809                        $post_id = absint( $post );
     3810                } else {
     3811                        $post_id = url_to_postid( $post );
     3812                }
    36243813
    36253814                if ( ! $post_id ) {
     
    36463835                if ( $logged_in ) {
    36473836                        $display_name = $user->display_name;
    3648                         $user_email = $user->user_email;
    3649                         $user_url = $user->user_url;
    3650 
    3651                         $comment['comment_author'] = $this->escape( $display_name );
     3837                        $user_email   = $user->user_email;
     3838                        $user_url     = $user->user_url;
     3839
     3840                        $comment['comment_author']       = $this->escape( $display_name );
    36523841                        $comment['comment_author_email'] = $this->escape( $user_email );
    3653                         $comment['comment_author_url'] = $this->escape( $user_url );
    3654                         $comment['user_ID'] = $user->ID;
     3842                        $comment['comment_author_url']   = $this->escape( $user_url );
     3843                        $comment['user_ID']              = $user->ID;
    36553844                } else {
    36563845                        $comment['comment_author'] = '';
    3657                         if ( isset($content_struct['author']) )
     3846                        if ( isset( $content_struct['author'] ) ) {
    36583847                                $comment['comment_author'] = $content_struct['author'];
     3848                        }
    36593849
    36603850                        $comment['comment_author_email'] = '';
    3661                         if ( isset($content_struct['author_email']) )
     3851                        if ( isset( $content_struct['author_email'] ) ) {
    36623852                                $comment['comment_author_email'] = $content_struct['author_email'];
     3853                        }
    36633854
    36643855                        $comment['comment_author_url'] = '';
    3665                         if ( isset($content_struct['author_url']) )
     3856                        if ( isset( $content_struct['author_url'] ) ) {
    36663857                                $comment['comment_author_url'] = $content_struct['author_url'];
     3858                        }
    36673859
    36683860                        $comment['user_ID'] = 0;
    36693861
    3670                         if ( get_option('require_name_email') ) {
    3671                                 if ( 6 > strlen($comment['comment_author_email']) || '' == $comment['comment_author'] )
     3862                        if ( get_option( 'require_name_email' ) ) {
     3863                                if ( 6 > strlen( $comment['comment_author_email'] ) || '' == $comment['comment_author'] ) {
    36723864                                        return new IXR_Error( 403, __( 'Comment author name and email are required.' ) );
    3673                                 elseif ( !is_email($comment['comment_author_email']) )
     3865                                } elseif ( ! is_email( $comment['comment_author_email'] ) ) {
    36743866                                        return new IXR_Error( 403, __( 'A valid email address is required.' ) );
    3675                         }
    3676                 }
    3677 
    3678                 $comment['comment_parent'] = isset($content_struct['comment_parent']) ? absint($content_struct['comment_parent']) : 0;
     3867                                }
     3868                        }
     3869                }
     3870
     3871                $comment['comment_parent'] = isset( $content_struct['comment_parent'] ) ? absint( $content_struct['comment_parent'] ) : 0;
    36793872
    36803873                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    37553948                $this->escape( $args );
    37563949
    3757                 $username       = $args[1];
    3758                 $password       = $args[2];
    3759                 $post_id        = (int) $args[3];
     3950                $username = $args[1];
     3951                $password = $args[2];
     3952                $post_id  = (int) $args[3];
    37603953
    37613954                if ( ! $user = $this->login( $username, $password ) ) {
     
    37783971
    37793972                return array(
    3780                         'approved' => $count->approved,
     3973                        'approved'            => $count->approved,
    37813974                        'awaiting_moderation' => $count->moderated,
    3782                         'spam' => $count->spam,
    3783                         'total_comments' => $count->total_comments
     3975                        'spam'                => $count->spam,
     3976                        'total_comments'      => $count->total_comments,
    37843977                );
    37853978        }
     
    38053998                $password = $args[2];
    38063999
    3807                 if ( !$user = $this->login($username, $password) )
    3808                         return $this->error;
    3809 
    3810                 if ( !current_user_can( 'edit_posts' ) )
     4000                if ( ! $user = $this->login( $username, $password ) ) {
     4001                        return $this->error;
     4002                }
     4003
     4004                if ( ! current_user_can( 'edit_posts' ) ) {
    38114005                        return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details about this site.' ) );
     4006                }
    38124007
    38134008                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    38374032                $password = $args[2];
    38384033
    3839                 if ( !$user = $this->login($username, $password) )
    3840                         return $this->error;
    3841 
    3842                 if ( !current_user_can( 'edit_pages' ) )
     4034                if ( ! $user = $this->login( $username, $password ) ) {
     4035                        return $this->error;
     4036                }
     4037
     4038                if ( ! current_user_can( 'edit_pages' ) ) {
    38434039                        return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details about this site.' ) );
     4040                }
    38444041
    38454042                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    38694066                $password = $args[2];
    38704067
    3871                 if ( !$user = $this->login($username, $password) )
    3872                         return $this->error;
    3873 
    3874                 if ( !current_user_can( 'edit_pages' ) )
     4068                if ( ! $user = $this->login( $username, $password ) ) {
     4069                        return $this->error;
     4070                }
     4071
     4072                if ( ! current_user_can( 'edit_pages' ) ) {
    38754073                        return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details about this site.' ) );
    3876 
    3877                 $templates = get_page_templates();
     4074                }
     4075
     4076                $templates            = get_page_templates();
    38784077                $templates['Default'] = 'default';
    38794078
     
    38994098                $this->escape( $args );
    39004099
    3901                 $username       = $args[1];
    3902                 $password       = $args[2];
    3903                 $options        = isset( $args[3] ) ? (array) $args[3] : array();
    3904 
    3905                 if ( !$user = $this->login($username, $password) )
    3906                         return $this->error;
     4100                $username = $args[1];
     4101                $password = $args[2];
     4102                $options  = isset( $args[3] ) ? (array) $args[3] : array();
     4103
     4104                if ( ! $user = $this->login( $username, $password ) ) {
     4105                        return $this->error;
     4106                }
    39074107
    39084108                // If no specific options where asked for, return all of them
    3909                 if ( count( $options ) == 0 )
    3910                         $options = array_keys($this->blog_options);
    3911 
    3912                 return $this->_getOptions($options);
     4109                if ( count( $options ) == 0 ) {
     4110                        $options = array_keys( $this->blog_options );
     4111                }
     4112
     4113                return $this->_getOptions( $options );
    39134114        }
    39144115
     
    39214122         * @return array
    39224123         */
    3923         public function _getOptions($options) {
    3924                 $data = array();
     4124        public function _getOptions( $options ) {
     4125                $data       = array();
    39254126                $can_manage = current_user_can( 'manage_options' );
    39264127                foreach ( $options as $option ) {
    39274128                        if ( array_key_exists( $option, $this->blog_options ) ) {
    3928                                 $data[$option] = $this->blog_options[$option];
     4129                                $data[ $option ] = $this->blog_options[ $option ];
    39294130                                //Is the value static or dynamic?
    3930                                 if ( isset( $data[$option]['option'] ) ) {
    3931                                         $data[$option]['value'] = get_option( $data[$option]['option'] );
    3932                                         unset($data[$option]['option']);
     4131                                if ( isset( $data[ $option ]['option'] ) ) {
     4132                                        $data[ $option ]['value'] = get_option( $data[ $option ]['option'] );
     4133                                        unset( $data[ $option ]['option'] );
    39334134                                }
    39344135
    3935                                 if ( ! $can_manage )
    3936                                         $data[$option]['readonly'] = true;
     4136                                if ( ! $can_manage ) {
     4137                                        $data[ $option ]['readonly'] = true;
     4138                                }
    39374139                        }
    39384140                }
     
    39594161                $this->escape( $args );
    39604162
    3961                 $username       = $args[1];
    3962                 $password       = $args[2];
    3963                 $options        = (array) $args[3];
    3964 
    3965                 if ( !$user = $this->login($username, $password) )
    3966                         return $this->error;
    3967 
    3968                 if ( !current_user_can( 'manage_options' ) )
     4163                $username = $args[1];
     4164                $password = $args[2];
     4165                $options  = (array) $args[3];
     4166
     4167                if ( ! $user = $this->login( $username, $password ) ) {
     4168                        return $this->error;
     4169                }
     4170
     4171                if ( ! current_user_can( 'manage_options' ) ) {
    39694172                        return new IXR_Error( 403, __( 'Sorry, you are not allowed to update options.' ) );
     4173                }
    39704174
    39714175                $option_names = array();
    39724176                foreach ( $options as $o_name => $o_value ) {
    39734177                        $option_names[] = $o_name;
    3974                         if ( !array_key_exists( $o_name, $this->blog_options ) )
     4178                        if ( ! array_key_exists( $o_name, $this->blog_options ) ) {
    39754179                                continue;
    3976 
    3977                         if ( $this->blog_options[$o_name]['readonly'] == true )
     4180                        }
     4181
     4182                        if ( $this->blog_options[ $o_name ]['readonly'] == true ) {
    39784183                                continue;
    3979 
    3980                         update_option( $this->blog_options[$o_name]['option'], wp_unslash( $o_value ) );
     4184                        }
     4185
     4186                        update_option( $this->blog_options[ $o_name ]['option'], wp_unslash( $o_value ) );
    39814187                }
    39824188
    39834189                //Now return the updated values
    3984                 return $this->_getOptions($option_names);
     4190                return $this->_getOptions( $option_names );
    39854191        }
    39864192
     
    40114217                $this->escape( $args );
    40124218
    4013                 $username               = $args[1];
    4014                 $password               = $args[2];
    4015                 $attachment_id  = (int) $args[3];
    4016 
    4017                 if ( !$user = $this->login($username, $password) )
    4018                         return $this->error;
    4019 
    4020                 if ( !current_user_can( 'upload_files' ) )
     4219                $username      = $args[1];
     4220                $password      = $args[2];
     4221                $attachment_id = (int) $args[3];
     4222
     4223                if ( ! $user = $this->login( $username, $password ) ) {
     4224                        return $this->error;
     4225                }
     4226
     4227                if ( ! current_user_can( 'upload_files' ) ) {
    40214228                        return new IXR_Error( 403, __( 'Sorry, you are not allowed to upload files.' ) );
     4229                }
    40224230
    40234231                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    40244232                do_action( 'xmlrpc_call', 'wp.getMediaItem' );
    40254233
    4026                 if ( ! $attachment = get_post($attachment_id) )
     4234                if ( ! $attachment = get_post( $attachment_id ) ) {
    40274235                        return new IXR_Error( 404, __( 'Invalid attachment ID.' ) );
     4236                }
    40284237
    40294238                return $this->_prepare_media_item( $attachment );
     
    40564265         * @return array|IXR_Error Contains a collection of media items. See wp_xmlrpc_server::wp_getMediaItem() for a description of each item contents
    40574266         */
    4058         public function wp_getMediaLibrary($args) {
    4059                 $this->escape($args);
    4060 
    4061                 $username       = $args[1];
    4062                 $password       = $args[2];
    4063                 $struct         = isset( $args[3] ) ? $args[3] : array() ;
    4064 
    4065                 if ( !$user = $this->login($username, $password) )
    4066                         return $this->error;
    4067 
    4068                 if ( !current_user_can( 'upload_files' ) )
     4267        public function wp_getMediaLibrary( $args ) {
     4268                $this->escape( $args );
     4269
     4270                $username = $args[1];
     4271                $password = $args[2];
     4272                $struct   = isset( $args[3] ) ? $args[3] : array();
     4273
     4274                if ( ! $user = $this->login( $username, $password ) ) {
     4275                        return $this->error;
     4276                }
     4277
     4278                if ( ! current_user_can( 'upload_files' ) ) {
    40694279                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to upload files.' ) );
     4280                }
    40704281
    40714282                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    40724283                do_action( 'xmlrpc_call', 'wp.getMediaLibrary' );
    40734284
    4074                 $parent_id = ( isset($struct['parent_id']) ) ? absint($struct['parent_id']) : '' ;
    4075                 $mime_type = ( isset($struct['mime_type']) ) ? $struct['mime_type'] : '' ;
    4076                 $offset = ( isset($struct['offset']) ) ? absint($struct['offset']) : 0 ;
    4077                 $number = ( isset($struct['number']) ) ? absint($struct['number']) : -1 ;
    4078 
    4079                 $attachments = get_posts( array('post_type' => 'attachment', 'post_parent' => $parent_id, 'offset' => $offset, 'numberposts' => $number, 'post_mime_type' => $mime_type ) );
     4285                $parent_id = ( isset( $struct['parent_id'] ) ) ? absint( $struct['parent_id'] ) : '';
     4286                $mime_type = ( isset( $struct['mime_type'] ) ) ? $struct['mime_type'] : '';
     4287                $offset    = ( isset( $struct['offset'] ) ) ? absint( $struct['offset'] ) : 0;
     4288                $number    = ( isset( $struct['number'] ) ) ? absint( $struct['number'] ) : -1;
     4289
     4290                $attachments = get_posts(
     4291                        array(
     4292                                'post_type'      => 'attachment',
     4293                                'post_parent'    => $parent_id,
     4294                                'offset'         => $offset,
     4295                                'numberposts'    => $number,
     4296                                'post_mime_type' => $mime_type,
     4297                        )
     4298                );
    40804299
    40814300                $attachments_struct = array();
    40824301
    4083                 foreach ($attachments as $attachment )
     4302                foreach ( $attachments as $attachment ) {
    40844303                        $attachments_struct[] = $this->_prepare_media_item( $attachment );
     4304                }
    40854305
    40864306                return $attachments_struct;
     
    41074327                $password = $args[2];
    41084328
    4109                 if ( !$user = $this->login( $username, $password ) )
    4110                         return $this->error;
    4111 
    4112                 if ( !current_user_can( 'edit_posts' ) )
     4329                if ( ! $user = $this->login( $username, $password ) ) {
     4330                        return $this->error;
     4331                }
     4332
     4333                if ( ! current_user_can( 'edit_posts' ) ) {
    41134334                        return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details about this site.' ) );
     4335                }
    41144336
    41154337                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    41244346                                        $supported = get_theme_support( 'post-formats' );
    41254347
    4126                                         $data = array();
    4127                                         $data['all'] = $formats;
     4348                                        $data              = array();
     4349                                        $data['all']       = $formats;
    41284350                                        $data['supported'] = $supported[0];
    41294351
     
    41644386         */
    41654387        public function wp_getPostType( $args ) {
    4166                 if ( ! $this->minimum_args( $args, 4 ) )
    4167                         return $this->error;
     4388                if ( ! $this->minimum_args( $args, 4 ) ) {
     4389                        return $this->error;
     4390                }
    41684391
    41694392                $this->escape( $args );
     
    41874410                }
    41884411
    4189                 if ( !$user = $this->login( $username, $password ) )
    4190                         return $this->error;
     4412                if ( ! $user = $this->login( $username, $password ) ) {
     4413                        return $this->error;
     4414                }
    41914415
    41924416                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    41934417                do_action( 'xmlrpc_call', 'wp.getPostType' );
    41944418
    4195                 if ( ! post_type_exists( $post_type_name ) )
     4419                if ( ! post_type_exists( $post_type_name ) ) {
    41964420                        return new IXR_Error( 403, __( 'Invalid post type.' ) );
     4421                }
    41974422
    41984423                $post_type = get_post_type_object( $post_type_name );
    41994424
    4200                 if ( ! current_user_can( $post_type->cap->edit_posts ) )
     4425                if ( ! current_user_can( $post_type->cap->edit_posts ) ) {
    42014426                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type.' ) );
     4427                }
    42024428
    42034429                return $this->_prepare_post_type( $post_type, $fields );
     
    42234449         */
    42244450        public function wp_getPostTypes( $args ) {
    4225                 if ( ! $this->minimum_args( $args, 3 ) )
    4226                         return $this->error;
     4451                if ( ! $this->minimum_args( $args, 3 ) ) {
     4452                        return $this->error;
     4453                }
    42274454
    42284455                $this->escape( $args );
     
    42394466                }
    42404467
    4241                 if ( ! $user = $this->login( $username, $password ) )
    4242                         return $this->error;
     4468                if ( ! $user = $this->login( $username, $password ) ) {
     4469                        return $this->error;
     4470                }
    42434471
    42444472                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    42504478
    42514479                foreach ( $post_types as $post_type ) {
    4252                         if ( ! current_user_can( $post_type->cap->edit_posts ) )
     4480                        if ( ! current_user_can( $post_type->cap->edit_posts ) ) {
    42534481                                continue;
    4254 
    4255                         $struct[$post_type->name] = $this->_prepare_post_type( $post_type, $fields );
     4482                        }
     4483
     4484                        $struct[ $post_type->name ] = $this->_prepare_post_type( $post_type, $fields );
    42564485                }
    42574486
     
    42824511         */
    42834512        public function wp_getRevisions( $args ) {
    4284                 if ( ! $this->minimum_args( $args, 4 ) )
    4285                         return $this->error;
     4513                if ( ! $this->minimum_args( $args, 4 ) ) {
     4514                        return $this->error;
     4515                }
    42864516
    42874517                $this->escape( $args );
     
    43054535                }
    43064536
    4307                 if ( ! $user = $this->login( $username, $password ) )
    4308                         return $this->error;
     4537                if ( ! $user = $this->login( $username, $password ) ) {
     4538                        return $this->error;
     4539                }
    43094540
    43104541                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    43114542                do_action( 'xmlrpc_call', 'wp.getRevisions' );
    43124543
    4313                 if ( ! $post = get_post( $post_id ) )
     4544                if ( ! $post = get_post( $post_id ) ) {
    43144545                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    4315 
    4316                 if ( ! current_user_can( 'edit_post', $post_id ) )
     4546                }
     4547
     4548                if ( ! current_user_can( 'edit_post', $post_id ) ) {
    43174549                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) );
     4550                }
    43184551
    43194552                // Check if revisions are enabled.
    4320                 if ( ! wp_revisions_enabled( $post ) )
     4553                if ( ! wp_revisions_enabled( $post ) ) {
    43214554                        return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
     4555                }
    43224556
    43234557                $revisions = wp_get_post_revisions( $post_id );
    43244558
    4325                 if ( ! $revisions )
     4559                if ( ! $revisions ) {
    43264560                        return array();
     4561                }
    43274562
    43284563                $struct = array();
    43294564
    43304565                foreach ( $revisions as $revision ) {
    4331                         if ( ! current_user_can( 'read_post', $revision->ID ) )
     4566                        if ( ! current_user_can( 'read_post', $revision->ID ) ) {
    43324567                                continue;
     4568                        }
    43334569
    43344570                        // Skip autosaves
    4335                         if ( wp_is_post_autosave( $revision ) )
     4571                        if ( wp_is_post_autosave( $revision ) ) {
    43364572                                continue;
     4573                        }
    43374574
    43384575                        $struct[] = $this->_prepare_post( get_object_vars( $revision ), $fields );
     
    43604597         */
    43614598        public function wp_restoreRevision( $args ) {
    4362                 if ( ! $this->minimum_args( $args, 3 ) )
    4363                         return $this->error;
     4599                if ( ! $this->minimum_args( $args, 3 ) ) {
     4600                        return $this->error;
     4601                }
    43644602
    43654603                $this->escape( $args );
     
    43694607                $revision_id = (int) $args[3];
    43704608
    4371                 if ( ! $user = $this->login( $username, $password ) )
    4372                         return $this->error;
     4609                if ( ! $user = $this->login( $username, $password ) ) {
     4610                        return $this->error;
     4611                }
    43734612
    43744613                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    43754614                do_action( 'xmlrpc_call', 'wp.restoreRevision' );
    43764615
    4377                 if ( ! $revision = wp_get_post_revision( $revision_id ) )
     4616                if ( ! $revision = wp_get_post_revision( $revision_id ) ) {
    43784617                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    4379 
    4380                 if ( wp_is_post_autosave( $revision ) )
     4618                }
     4619
     4620                if ( wp_is_post_autosave( $revision ) ) {
    43814621                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    4382 
    4383                 if ( ! $post = get_post( $revision->post_parent ) )
     4622                }
     4623
     4624                if ( ! $post = get_post( $revision->post_parent ) ) {
    43844625                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    4385 
    4386                 if ( ! current_user_can( 'edit_post', $revision->post_parent ) )
     4626                }
     4627
     4628                if ( ! current_user_can( 'edit_post', $revision->post_parent ) ) {
    43874629                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
     4630                }
    43884631
    43894632                // Check if revisions are disabled.
    4390                 if ( ! wp_revisions_enabled( $post ) )
     4633                if ( ! wp_revisions_enabled( $post ) ) {
    43914634                        return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) );
     4635                }
    43924636
    43934637                $post = wp_restore_post_revision( $revision_id );
     
    44164660         * @return array|IXR_Error
    44174661         */
    4418         public function blogger_getUsersBlogs($args) {
     4662        public function blogger_getUsersBlogs( $args ) {
    44194663                if ( ! $this->minimum_args( $args, 3 ) ) {
    44204664                        return $this->error;
     
    44224666
    44234667                if ( is_multisite() ) {
    4424                         return $this->_multisite_getUsersBlogs($args);
    4425                 }
    4426 
    4427                 $this->escape($args);
     4668                        return $this->_multisite_getUsersBlogs( $args );
     4669                }
     4670
     4671                $this->escape( $args );
    44284672
    44294673                $username = $args[1];
    44304674                $password = $args[2];
    44314675
    4432                 if ( !$user = $this->login($username, $password) )
    4433                         return $this->error;
     4676                if ( ! $user = $this->login( $username, $password ) ) {
     4677                        return $this->error;
     4678                }
    44344679
    44354680                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    44364681                do_action( 'xmlrpc_call', 'blogger.getUsersBlogs' );
    44374682
    4438                 $is_admin = current_user_can('manage_options');
     4683                $is_admin = current_user_can( 'manage_options' );
    44394684
    44404685                $struct = array(
    44414686                        'isAdmin'  => $is_admin,
    4442                         'url'      => get_option('home') . '/',
     4687                        'url'      => get_option( 'home' ) . '/',
    44434688                        'blogid'   => '1',
    4444                         'blogName' => get_option('blogname'),
     4689                        'blogName' => get_option( 'blogname' ),
    44454690                        'xmlrpc'   => site_url( 'xmlrpc.php', 'rpc' ),
    44464691                );
    44474692
    4448                 return array($struct);
     4693                return array( $struct );
    44494694        }
    44504695
     
    44664711
    44674712                $domain = $current_blog->domain;
    4468                 $path = $current_blog->path . 'xmlrpc.php';
     4713                $path   = $current_blog->path . 'xmlrpc.php';
    44694714
    44704715                $rpc = new IXR_Client( set_url_scheme( "http://{$domain}{$path}" ) );
    4471                 $rpc->query('wp.getUsersBlogs', $args[1], $args[2]);
     4716                $rpc->query( 'wp.getUsersBlogs', $args[1], $args[2] );
    44724717                $blogs = $rpc->getResponse();
    44734718
    4474                 if ( isset($blogs['faultCode']) )
    4475                         return new IXR_Error($blogs['faultCode'], $blogs['faultString']);
     4719                if ( isset( $blogs['faultCode'] ) ) {
     4720                        return new IXR_Error( $blogs['faultCode'], $blogs['faultString'] );
     4721                }
    44764722
    44774723                if ( $_SERVER['HTTP_HOST'] == $domain && $_SERVER['REQUEST_URI'] == $path ) {
     
    44794725                } else {
    44804726                        foreach ( (array) $blogs as $blog ) {
    4481                                 if ( strpos($blog['url'], $_SERVER['HTTP_HOST']) )
    4482                                         return array($blog);
     4727                                if ( strpos( $blog['url'], $_SERVER['HTTP_HOST'] ) ) {
     4728                                        return array( $blog );
     4729                                }
    44834730                        }
    44844731                        return array();
     
    45084755                $password = $args[2];
    45094756
    4510                 if ( !$user = $this->login($username, $password) )
    4511                         return $this->error;
    4512 
    4513                 if ( !current_user_can( 'edit_posts' ) )
     4757                if ( ! $user = $this->login( $username, $password ) ) {
     4758                        return $this->error;
     4759                }
     4760
     4761                if ( ! current_user_can( 'edit_posts' ) ) {
    45144762                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to access user data on this site.' ) );
     4763                }
    45154764
    45164765                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    45224771                        'url'       => $user->user_url,
    45234772                        'lastname'  => $user->last_name,
    4524                         'firstname' => $user->first_name
     4773                        'firstname' => $user->first_name,
    45254774                );
    45264775
     
    45504799                $password = $args[3];
    45514800
    4552                 if ( !$user = $this->login($username, $password) )
    4553                         return $this->error;
    4554 
    4555                 $post_data = get_post($post_ID, ARRAY_A);
    4556                 if ( ! $post_data )
     4801                if ( ! $user = $this->login( $username, $password ) ) {
     4802                        return $this->error;
     4803                }
     4804
     4805                $post_data = get_post( $post_ID, ARRAY_A );
     4806                if ( ! $post_data ) {
    45574807                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    4558 
    4559                 if ( !current_user_can( 'edit_post', $post_ID ) )
     4808                }
     4809
     4810                if ( ! current_user_can( 'edit_post', $post_ID ) ) {
    45604811                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
     4812                }
    45614813
    45624814                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    45634815                do_action( 'xmlrpc_call', 'blogger.getPost' );
    45644816
    4565                 $categories = implode(',', wp_get_post_categories($post_ID));
    4566 
    4567                 $content  = '<title>'.wp_unslash($post_data['post_title']).'</title>';
    4568                 $content .= '<category>'.$categories.'</category>';
    4569                 $content .= wp_unslash($post_data['post_content']);
     4817                $categories = implode( ',', wp_get_post_categories( $post_ID ) );
     4818
     4819                $content  = '<title>' . wp_unslash( $post_data['post_title'] ) . '</title>';
     4820                $content .= '<category>' . $categories . '</category>';
     4821                $content .= wp_unslash( $post_data['post_content'] );
    45704822
    45714823                $struct = array(
    4572                         'userid'    => $post_data['post_author'],
     4824                        'userid'      => $post_data['post_author'],
    45734825                        'dateCreated' => $this->_convert_date( $post_data['post_date'] ),
    45744826                        'content'     => $content,
    4575                         'postid'  => (string) $post_data['ID']
     4827                        'postid'      => (string) $post_data['ID'],
    45764828                );
    45774829
     
    45974849        public function blogger_getRecentPosts( $args ) {
    45984850
    4599                 $this->escape($args);
     4851                $this->escape( $args );
    46004852
    46014853                // $args[0] = appkey - ignored
    46024854                $username = $args[2];
    46034855                $password = $args[3];
    4604                 if ( isset( $args[4] ) )
     4856                if ( isset( $args[4] ) ) {
    46054857                        $query = array( 'numberposts' => absint( $args[4] ) );
    4606                 else
     4858                } else {
    46074859                        $query = array();
    4608 
    4609                 if ( !$user = $this->login($username, $password) )
    4610                         return $this->error;
    4611 
    4612                 if ( ! current_user_can( 'edit_posts' ) )
     4860                }
     4861
     4862                if ( ! $user = $this->login( $username, $password ) ) {
     4863                        return $this->error;
     4864                }
     4865
     4866                if ( ! current_user_can( 'edit_posts' ) ) {
    46134867                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) );
     4868                }
    46144869
    46154870                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    46184873                $posts_list = wp_get_recent_posts( $query );
    46194874
    4620                 if ( !$posts_list ) {
    4621                         $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.'));
     4875                if ( ! $posts_list ) {
     4876                        $this->error = new IXR_Error( 500, __( 'Either there are no posts, or something went wrong.' ) );
    46224877                        return $this->error;
    46234878                }
    46244879
    46254880                $recent_posts = array();
    4626                 foreach ($posts_list as $entry) {
    4627                         if ( !current_user_can( 'edit_post', $entry['ID'] ) )
     4881                foreach ( $posts_list as $entry ) {
     4882                        if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) {
    46284883                                continue;
     4884                        }
    46294885
    46304886                        $post_date  = $this->_convert_date( $entry['post_date'] );
    4631                         $categories = implode(',', wp_get_post_categories($entry['ID']));
    4632 
    4633                         $content  = '<title>'.wp_unslash($entry['post_title']).'</title>';
    4634                         $content .= '<category>'.$categories.'</category>';
    4635                         $content .= wp_unslash($entry['post_content']);
     4887                        $categories = implode( ',', wp_get_post_categories( $entry['ID'] ) );
     4888
     4889                        $content  = '<title>' . wp_unslash( $entry['post_title'] ) . '</title>';
     4890                        $content .= '<category>' . $categories . '</category>';
     4891                        $content .= wp_unslash( $entry['post_content'] );
    46364892
    46374893                        $recent_posts[] = array(
    4638                                 'userid' => $entry['post_author'],
     4894                                'userid'      => $entry['post_author'],
    46394895                                'dateCreated' => $post_date,
    4640                                 'content' => $content,
    4641                                 'postid' => (string) $entry['ID'],
     4896                                'content'     => $content,
     4897                                'postid'      => (string) $entry['ID'],
    46424898                        );
    46434899                }
     
    46554911         * @return IXR_Error Error object.
    46564912         */
    4657         public function blogger_getTemplate($args) {
    4658                 return new IXR_Error( 403, __('Sorry, that file cannot be edited.' ) );
     4913        public function blogger_getTemplate( $args ) {
     4914                return new IXR_Error( 403, __( 'Sorry, that file cannot be edited.' ) );
    46594915        }
    46604916
     
    46684924         * @return IXR_Error Error object.
    46694925         */
    4670         public function blogger_setTemplate($args) {
    4671                 return new IXR_Error( 403, __('Sorry, that file cannot be edited.' ) );
     4926        public function blogger_setTemplate( $args ) {
     4927                return new IXR_Error( 403, __( 'Sorry, that file cannot be edited.' ) );
    46724928        }
    46734929
     
    46974953                $publish  = $args[5];
    46984954
    4699                 if ( !$user = $this->login($username, $password) )
    4700                         return $this->error;
     4955                if ( ! $user = $this->login( $username, $password ) ) {
     4956                        return $this->error;
     4957                }
    47014958
    47024959                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    47034960                do_action( 'xmlrpc_call', 'blogger.newPost' );
    47044961
    4705                 $cap = ($publish) ? 'publish_posts' : 'edit_posts';
    4706                 if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) || !current_user_can($cap) )
    4707                         return new IXR_Error(401, __('Sorry, you are not allowed to post on this site.'));
    4708 
    4709                 $post_status = ($publish) ? 'publish' : 'draft';
     4962                $cap = ( $publish ) ? 'publish_posts' : 'edit_posts';
     4963                if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) || ! current_user_can( $cap ) ) {
     4964                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) );
     4965                }
     4966
     4967                $post_status = ( $publish ) ? 'publish' : 'draft';
    47104968
    47114969                $post_author = $user->ID;
    47124970
    4713                 $post_title = xmlrpc_getposttitle($content);
    4714                 $post_category = xmlrpc_getpostcategory($content);
    4715                 $post_content = xmlrpc_removepostdata($content);
    4716 
    4717                 $post_date = current_time('mysql');
    4718                 $post_date_gmt = current_time('mysql', 1);
    4719 
    4720                 $post_data = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status');
    4721 
    4722                 $post_ID = wp_insert_post($post_data);
    4723                 if ( is_wp_error( $post_ID ) )
    4724                         return new IXR_Error(500, $post_ID->get_error_message());
    4725 
    4726                 if ( !$post_ID )
    4727                         return new IXR_Error(500, __('Sorry, your entry could not be posted.'));
     4971                $post_title    = xmlrpc_getposttitle( $content );
     4972                $post_category = xmlrpc_getpostcategory( $content );
     4973                $post_content  = xmlrpc_removepostdata( $content );
     4974
     4975                $post_date     = current_time( 'mysql' );
     4976                $post_date_gmt = current_time( 'mysql', 1 );
     4977
     4978                $post_data = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status' );
     4979
     4980                $post_ID = wp_insert_post( $post_data );
     4981                if ( is_wp_error( $post_ID ) ) {
     4982                        return new IXR_Error( 500, $post_ID->get_error_message() );
     4983                }
     4984
     4985                if ( ! $post_ID ) {
     4986                        return new IXR_Error( 500, __( 'Sorry, your entry could not be posted.' ) );
     4987                }
    47284988
    47294989                $this->attach_uploads( $post_ID, $post_content );
     
    47615021        public function blogger_editPost( $args ) {
    47625022
    4763                 $this->escape($args);
     5023                $this->escape( $args );
    47645024
    47655025                $post_ID  = (int) $args[1];
     
    47825042                }
    47835043
    4784                 $this->escape($actual_post);
     5044                $this->escape( $actual_post );
    47855045
    47865046                if ( ! current_user_can( 'edit_post', $post_ID ) ) {
    4787                         return new IXR_Error(401, __('Sorry, you are not allowed to edit this post.'));
     5047                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
    47885048                }
    47895049                if ( 'publish' == $actual_post['post_status'] && ! current_user_can( 'publish_posts' ) ) {
     
    47915051                }
    47925052
    4793                 $postdata = array();
    4794                 $postdata['ID'] = $actual_post['ID'];
    4795                 $postdata['post_content'] = xmlrpc_removepostdata( $content );
    4796                 $postdata['post_title'] = xmlrpc_getposttitle( $content );
     5053                $postdata                  = array();
     5054                $postdata['ID']            = $actual_post['ID'];
     5055                $postdata['post_content']  = xmlrpc_removepostdata( $content );
     5056                $postdata['post_title']    = xmlrpc_getposttitle( $content );
    47975057                $postdata['post_category'] = xmlrpc_getpostcategory( $content );
    4798                 $postdata['post_status'] = $actual_post['post_status'];
    4799                 $postdata['post_excerpt'] = $actual_post['post_excerpt'];
    4800                 $postdata['post_status'] = $publish ? 'publish' : 'draft';
     5058                $postdata['post_status']   = $actual_post['post_status'];
     5059                $postdata['post_excerpt']  = $actual_post['post_excerpt'];
     5060                $postdata['post_status']   = $publish ? 'publish' : 'draft';
    48015061
    48025062                $result = wp_update_post( $postdata );
    48035063
    48045064                if ( ! $result ) {
    4805                         return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be edited.'));
     5065                        return new IXR_Error( 500, __( 'For some strange yet very annoying reason, this post could not be edited.' ) );
    48065066                }
    48075067                $this->attach_uploads( $actual_post['ID'], $postdata['post_content'] );
     
    48425102                $password = $args[3];
    48435103
    4844                 if ( !$user = $this->login($username, $password) )
    4845                         return $this->error;
     5104                if ( ! $user = $this->login( $username, $password ) ) {
     5105                        return $this->error;
     5106                }
    48465107
    48475108                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    49195180         * @return int|IXR_Error
    49205181         */
    4921         public function mw_newPost($args) {
    4922                 $this->escape($args);
     5182        public function mw_newPost( $args ) {
     5183                $this->escape( $args );
    49235184
    49245185                $username       = $args[1];
     
    49275188                $publish        = isset( $args[4] ) ? $args[4] : 0;
    49285189
    4929                 if ( !$user = $this->login($username, $password) )
    4930                         return $this->error;
     5190                if ( ! $user = $this->login( $username, $password ) ) {
     5191                        return $this->error;
     5192                }
    49315193
    49325194                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    49345196
    49355197                $page_template = '';
    4936                 if ( !empty( $content_struct['post_type'] ) ) {
     5198                if ( ! empty( $content_struct['post_type'] ) ) {
    49375199                        if ( $content_struct['post_type'] == 'page' ) {
    4938                                 if ( $publish )
    4939                                         $cap  = 'publish_pages';
    4940                                 elseif ( isset( $content_struct['page_status'] ) && 'publish' == $content_struct['page_status'] )
    4941                                         $cap  = 'publish_pages';
    4942                                 else
     5200                                if ( $publish ) {
     5201                                        $cap = 'publish_pages';
     5202                                } elseif ( isset( $content_struct['page_status'] ) && 'publish' == $content_struct['page_status'] ) {
     5203                                        $cap = 'publish_pages';
     5204                                } else {
    49435205                                        $cap = 'edit_pages';
     5206                                }
    49445207                                $error_message = __( 'Sorry, you are not allowed to publish pages on this site.' );
    4945                                 $post_type = 'page';
    4946                                 if ( !empty( $content_struct['wp_page_template'] ) )
     5208                                $post_type     = 'page';
     5209                                if ( ! empty( $content_struct['wp_page_template'] ) ) {
    49475210                                        $page_template = $content_struct['wp_page_template'];
     5211                                }
    49485212                        } elseif ( $content_struct['post_type'] == 'post' ) {
    4949                                 if ( $publish )
    4950                                         $cap  = 'publish_posts';
    4951                                 elseif ( isset( $content_struct['post_status'] ) && 'publish' == $content_struct['post_status'] )
    4952                                         $cap  = 'publish_posts';
    4953                                 else
     5213                                if ( $publish ) {
     5214                                        $cap = 'publish_posts';
     5215                                } elseif ( isset( $content_struct['post_status'] ) && 'publish' == $content_struct['post_status'] ) {
     5216                                        $cap = 'publish_posts';
     5217                                } else {
    49545218                                        $cap = 'edit_posts';
     5219                                }
    49555220                                $error_message = __( 'Sorry, you are not allowed to publish posts on this site.' );
    4956                                 $post_type = 'post';
     5221                                $post_type     = 'post';
    49575222                        } else {
    49585223                                // No other post_type values are allowed here
     
    49605225                        }
    49615226                } else {
    4962                         if ( $publish )
    4963                                 $cap  = 'publish_posts';
    4964                         elseif ( isset( $content_struct['post_status'] ) && 'publish' == $content_struct['post_status'])
    4965                                 $cap  = 'publish_posts';
    4966                         else
     5227                        if ( $publish ) {
     5228                                $cap = 'publish_posts';
     5229                        } elseif ( isset( $content_struct['post_status'] ) && 'publish' == $content_struct['post_status'] ) {
     5230                                $cap = 'publish_posts';
     5231                        } else {
    49675232                                $cap = 'edit_posts';
     5233                        }
    49685234                        $error_message = __( 'Sorry, you are not allowed to publish posts on this site.' );
    4969                         $post_type = 'post';
    4970                 }
    4971 
    4972                 if ( ! current_user_can( get_post_type_object( $post_type )->cap->create_posts ) )
     5235                        $post_type     = 'post';
     5236                }
     5237
     5238                if ( ! current_user_can( get_post_type_object( $post_type )->cap->create_posts ) ) {
    49735239                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts on this site.' ) );
    4974                 if ( !current_user_can( $cap ) )
     5240                }
     5241                if ( ! current_user_can( $cap ) ) {
    49755242                        return new IXR_Error( 401, $error_message );
     5243                }
    49765244
    49775245                // Check for a valid post format if one was given
    49785246                if ( isset( $content_struct['wp_post_format'] ) ) {
    49795247                        $content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] );
    4980                         if ( !array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) {
     5248                        if ( ! array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) {
    49815249                                return new IXR_Error( 404, __( 'Invalid post format.' ) );
    49825250                        }
     
    49855253                // Let WordPress generate the post_name (slug) unless
    49865254                // one has been provided.
    4987                 $post_name = "";
    4988                 if ( isset($content_struct['wp_slug']) )
     5255                $post_name = '';
     5256                if ( isset( $content_struct['wp_slug'] ) ) {
    49895257                        $post_name = $content_struct['wp_slug'];
     5258                }
    49905259
    49915260                // Only use a password if one was given.
    4992                 if ( isset($content_struct['wp_password']) )
     5261                if ( isset( $content_struct['wp_password'] ) ) {
    49935262                        $post_password = $content_struct['wp_password'];
     5263                }
    49945264
    49955265                // Only set a post parent if one was provided.
    4996                 if ( isset($content_struct['wp_page_parent_id']) )
     5266                if ( isset( $content_struct['wp_page_parent_id'] ) ) {
    49975267                        $post_parent = $content_struct['wp_page_parent_id'];
     5268                }
    49985269
    49995270                // Only set the menu_order if it was provided.
    5000                 if ( isset($content_struct['wp_page_order']) )
     5271                if ( isset( $content_struct['wp_page_order'] ) ) {
    50015272                        $menu_order = $content_struct['wp_page_order'];
     5273                }
    50025274
    50035275                $post_author = $user->ID;
     
    50065278                if ( isset( $content_struct['wp_author_id'] ) && ( $user->ID != $content_struct['wp_author_id'] ) ) {
    50075279                        switch ( $post_type ) {
    5008                                 case "post":
    5009                                         if ( !current_user_can( 'edit_others_posts' ) )
     5280                                case 'post':
     5281                                        if ( ! current_user_can( 'edit_others_posts' ) ) {
    50105282                                                return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) );
     5283                                        }
    50115284                                        break;
    5012                                 case "page":
    5013                                         if ( !current_user_can( 'edit_others_pages' ) )
     5285                                case 'page':
     5286                                        if ( ! current_user_can( 'edit_others_pages' ) ) {
    50145287                                                return new IXR_Error( 401, __( 'Sorry, you are not allowed to create pages as this user.' ) );
     5288                                        }
    50155289                                        break;
    50165290                                default:
     
    50185292                        }
    50195293                        $author = get_userdata( $content_struct['wp_author_id'] );
    5020                         if ( ! $author )
     5294                        if ( ! $author ) {
    50215295                                return new IXR_Error( 404, __( 'Invalid author ID.' ) );
     5296                        }
    50225297                        $post_author = $content_struct['wp_author_id'];
    50235298                }
    50245299
    5025                 $post_title = isset( $content_struct['title'] ) ? $content_struct['title'] : null;
     5300                $post_title   = isset( $content_struct['title'] ) ? $content_struct['title'] : null;
    50265301                $post_content = isset( $content_struct['description'] ) ? $content_struct['description'] : null;
    50275302
    50285303                $post_status = $publish ? 'publish' : 'draft';
    50295304
    5030                 if ( isset( $content_struct["{$post_type}_status"] ) ) {
    5031                         switch ( $content_struct["{$post_type}_status"] ) {
     5305                if ( isset( $content_struct[ "{$post_type}_status" ] ) ) {
     5306                        switch ( $content_struct[ "{$post_type}_status" ] ) {
    50325307                                case 'draft':
    50335308                                case 'pending':
    50345309                                case 'private':
    50355310                                case 'publish':
    5036                                         $post_status = $content_struct["{$post_type}_status"];
     5311                                        $post_status = $content_struct[ "{$post_type}_status" ];
    50375312                                        break;
    50385313                                default:
     
    50425317                }
    50435318
    5044                 $post_excerpt = isset($content_struct['mt_excerpt']) ? $content_struct['mt_excerpt'] : null;
    5045                 $post_more = isset($content_struct['mt_text_more']) ? $content_struct['mt_text_more'] : null;
    5046 
    5047                 $tags_input = isset($content_struct['mt_keywords']) ? $content_struct['mt_keywords'] : null;
    5048 
    5049                 if ( isset($content_struct['mt_allow_comments']) ) {
    5050                         if ( !is_numeric($content_struct['mt_allow_comments']) ) {
     5319                $post_excerpt = isset( $content_struct['mt_excerpt'] ) ? $content_struct['mt_excerpt'] : null;
     5320                $post_more    = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : null;
     5321
     5322                $tags_input = isset( $content_struct['mt_keywords'] ) ? $content_struct['mt_keywords'] : null;
     5323
     5324                if ( isset( $content_struct['mt_allow_comments'] ) ) {
     5325                        if ( ! is_numeric( $content_struct['mt_allow_comments'] ) ) {
    50515326                                switch ( $content_struct['mt_allow_comments'] ) {
    50525327                                        case 'closed':
     
    50785353                }
    50795354
    5080                 if ( isset($content_struct['mt_allow_pings']) ) {
    5081                         if ( !is_numeric($content_struct['mt_allow_pings']) ) {
     5355                if ( isset( $content_struct['mt_allow_pings'] ) ) {
     5356                        if ( ! is_numeric( $content_struct['mt_allow_pings'] ) ) {
    50825357                                switch ( $content_struct['mt_allow_pings'] ) {
    50835358                                        case 'closed':
     
    51085383                }
    51095384
    5110                 if ( $post_more )
     5385                if ( $post_more ) {
    51115386                        $post_content = $post_content . '<!--more-->' . $post_more;
     5387                }
    51125388
    51135389                $to_ping = null;
    51145390                if ( isset( $content_struct['mt_tb_ping_urls'] ) ) {
    51155391                        $to_ping = $content_struct['mt_tb_ping_urls'];
    5116                         if ( is_array($to_ping) )
    5117                                 $to_ping = implode(' ', $to_ping);
     5392                        if ( is_array( $to_ping ) ) {
     5393                                $to_ping = implode( ' ', $to_ping );
     5394                        }
    51185395                }
    51195396
    51205397                // Do some timestamp voodoo
    5121                 if ( !empty( $content_struct['date_created_gmt'] ) )
     5398                if ( ! empty( $content_struct['date_created_gmt'] ) ) {
    51225399                        // We know this is supposed to be GMT, so we're going to slap that Z on there by force
    51235400                        $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
    5124                 elseif ( !empty( $content_struct['dateCreated']) )
     5401                } elseif ( ! empty( $content_struct['dateCreated'] ) ) {
    51255402                        $dateCreated = $content_struct['dateCreated']->getIso();
    5126 
    5127                 if ( !empty( $dateCreated ) ) {
    5128                         $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
    5129                         $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
     5403                }
     5404
     5405                if ( ! empty( $dateCreated ) ) {
     5406                        $post_date     = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
     5407                        $post_date_gmt = iso8601_to_datetime( $dateCreated, 'GMT' );
    51305408                } else {
    5131                         $post_date = '';
     5409                        $post_date     = '';
    51325410                        $post_date_gmt = '';
    51335411                }
     
    51375415                        $catnames = $content_struct['categories'];
    51385416
    5139                         if ( is_array($catnames) ) {
    5140                                 foreach ($catnames as $cat) {
    5141                                         $post_category[] = get_cat_ID($cat);
     5417                        if ( is_array( $catnames ) ) {
     5418                                foreach ( $catnames as $cat ) {
     5419                                        $post_category[] = get_cat_ID( $cat );
    51425420                                }
    51435421                        }
    51445422                }
    51455423
    5146                 $postdata = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping', 'post_type', 'post_name', 'post_password', 'post_parent', 'menu_order', 'tags_input', 'page_template');
     5424                $postdata = compact( 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'to_ping', 'post_type', 'post_name', 'post_password', 'post_parent', 'menu_order', 'tags_input', 'page_template' );
    51475425
    51485426                $post_ID = $postdata['ID'] = get_default_post_to_edit( $post_type, true )->ID;
     
    51505428                // Only posts can be sticky
    51515429                if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
    5152                         $data = $postdata;
     5430                        $data           = $postdata;
    51535431                        $data['sticky'] = $content_struct['sticky'];
    5154                         $error = $this->_toggle_sticky( $data );
     5432                        $error          = $this->_toggle_sticky( $data );
    51555433                        if ( $error ) {
    51565434                                return $error;
     
    51585436                }
    51595437
    5160                 if ( isset($content_struct['custom_fields']) )
    5161                         $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
    5162 
    5163                 if ( isset ( $content_struct['wp_post_thumbnail'] ) ) {
    5164                         if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false )
     5438                if ( isset( $content_struct['custom_fields'] ) ) {
     5439                        $this->set_custom_fields( $post_ID, $content_struct['custom_fields'] );
     5440                }
     5441
     5442                if ( isset( $content_struct['wp_post_thumbnail'] ) ) {
     5443                        if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false ) {
    51655444                                return new IXR_Error( 404, __( 'Invalid attachment ID.' ) );
     5445                        }
    51665446
    51675447                        unset( $content_struct['wp_post_thumbnail'] );
     
    51695449
    51705450                // Handle enclosures
    5171                 $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null;
    5172                 $this->add_enclosure_if_new($post_ID, $thisEnclosure);
     5451                $thisEnclosure = isset( $content_struct['enclosure'] ) ? $content_struct['enclosure'] : null;
     5452                $this->add_enclosure_if_new( $post_ID, $thisEnclosure );
    51735453
    51745454                $this->attach_uploads( $post_ID, $post_content );
     
    51765456                // Handle post formats if assigned, value is validated earlier
    51775457                // in this function
    5178                 if ( isset( $content_struct['wp_post_format'] ) )
     5458                if ( isset( $content_struct['wp_post_format'] ) ) {
    51795459                        set_post_format( $post_ID, $content_struct['wp_post_format'] );
     5460                }
    51805461
    51815462                $post_ID = wp_insert_post( $postdata, true );
    5182                 if ( is_wp_error( $post_ID ) )
    5183                         return new IXR_Error(500, $post_ID->get_error_message());
    5184 
    5185                 if ( !$post_ID )
    5186                         return new IXR_Error(500, __('Sorry, your entry could not be posted.'));
     5463                if ( is_wp_error( $post_ID ) ) {
     5464                        return new IXR_Error( 500, $post_ID->get_error_message() );
     5465                }
     5466
     5467                if ( ! $post_ID ) {
     5468                        return new IXR_Error( 500, __( 'Sorry, your entry could not be posted.' ) );
     5469                }
    51875470
    51885471                /**
     
    51965479                do_action( 'xmlrpc_call_success_mw_newPost', $post_ID, $args );
    51975480
    5198                 return strval($post_ID);
     5481                return strval( $post_ID );
    51995482        }
    52005483
     
    52105493                if ( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) {
    52115494                        $encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] . "\n";
    5212                         $found = false;
     5495                        $found     = false;
    52135496                        if ( $enclosures = get_post_meta( $post_ID, 'enclosure' ) ) {
    52145497                                foreach ( $enclosures as $enc ) {
     
    52205503                                }
    52215504                        }
    5222                         if ( ! $found )
     5505                        if ( ! $found ) {
    52235506                                add_post_meta( $post_ID, 'enclosure', $encstring );
     5507                        }
    52245508                }
    52255509        }
     
    52425526                if ( is_array( $attachments ) ) {
    52435527                        foreach ( $attachments as $file ) {
    5244                                 if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false )
    5245                                         $wpdb->update($wpdb->posts, array('post_parent' => $post_ID), array('ID' => $file->ID) );
     5528                                if ( ! empty( $file->guid ) && strpos( $post_content, $file->guid ) !== false ) {
     5529                                        $wpdb->update( $wpdb->posts, array( 'post_parent' => $post_ID ), array( 'ID' => $file->ID ) );
     5530                                }
    52465531                        }
    52475532                }
     
    52735558                $publish        = isset( $args[4] ) ? $args[4] : 0;
    52745559
    5275                 if ( ! $user = $this->login($username, $password) )
    5276                         return $this->error;
     5560                if ( ! $user = $this->login( $username, $password ) ) {
     5561                        return $this->error;
     5562                }
    52775563
    52785564                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    52855571                 * Otherwise a new post will be created (which was the old behavior).
    52865572                 */
    5287                 if ( ! $postdata || empty( $postdata[ 'ID' ] ) )
     5573                if ( ! $postdata || empty( $postdata['ID'] ) ) {
    52885574                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    5289 
    5290                 if ( ! current_user_can( 'edit_post', $post_ID ) )
     5575                }
     5576
     5577                if ( ! current_user_can( 'edit_post', $post_ID ) ) {
    52915578                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
     5579                }
    52925580
    52935581                // Use wp.editPost to edit post types other than post and page.
    5294                 if ( ! in_array( $postdata[ 'post_type' ], array( 'post', 'page' ) ) )
     5582                if ( ! in_array( $postdata['post_type'], array( 'post', 'page' ) ) ) {
    52955583                        return new IXR_Error( 401, __( 'Invalid post type.' ) );
     5584                }
    52965585
    52975586                // Thwart attempt to change the post type.
    5298                 if ( ! empty( $content_struct[ 'post_type' ] ) && ( $content_struct['post_type'] != $postdata[ 'post_type' ] ) )
     5587                if ( ! empty( $content_struct['post_type'] ) && ( $content_struct['post_type'] != $postdata['post_type'] ) ) {
    52995588                        return new IXR_Error( 401, __( 'The post type may not be changed.' ) );
     5589                }
    53005590
    53015591                // Check for a valid post format if one was given
    53025592                if ( isset( $content_struct['wp_post_format'] ) ) {
    53035593                        $content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] );
    5304                         if ( !array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) {
     5594                        if ( ! array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) {
    53055595                                return new IXR_Error( 404, __( 'Invalid post format.' ) );
    53065596                        }
    53075597                }
    53085598
    5309                 $this->escape($postdata);
    5310 
    5311                 $ID = $postdata['ID'];
    5312                 $post_content = $postdata['post_content'];
    5313                 $post_title = $postdata['post_title'];
    5314                 $post_excerpt = $postdata['post_excerpt'];
     5599                $this->escape( $postdata );
     5600
     5601                $ID            = $postdata['ID'];
     5602                $post_content  = $postdata['post_content'];
     5603                $post_title    = $postdata['post_title'];
     5604                $post_excerpt  = $postdata['post_excerpt'];
    53155605                $post_password = $postdata['post_password'];
    5316                 $post_parent = $postdata['post_parent'];
    5317                 $post_type = $postdata['post_type'];
    5318                 $menu_order = $postdata['menu_order'];
     5606                $post_parent   = $postdata['post_parent'];
     5607                $post_type     = $postdata['post_type'];
     5608                $menu_order    = $postdata['menu_order'];
    53195609
    53205610                // Let WordPress manage slug if none was provided.
    53215611                $post_name = $postdata['post_name'];
    5322                 if ( isset($content_struct['wp_slug']) )
     5612                if ( isset( $content_struct['wp_slug'] ) ) {
    53235613                        $post_name = $content_struct['wp_slug'];
     5614                }
    53245615
    53255616                // Only use a password if one was given.
    5326                 if ( isset($content_struct['wp_password']) )
     5617                if ( isset( $content_struct['wp_password'] ) ) {
    53275618                        $post_password = $content_struct['wp_password'];
     5619                }
    53285620
    53295621                // Only set a post parent if one was given.
    5330                 if ( isset($content_struct['wp_page_parent_id']) )
     5622                if ( isset( $content_struct['wp_page_parent_id'] ) ) {
    53315623                        $post_parent = $content_struct['wp_page_parent_id'];
     5624                }
    53325625
    53335626                // Only set the menu_order if it was given.
    5334                 if ( isset($content_struct['wp_page_order']) )
     5627                if ( isset( $content_struct['wp_page_order'] ) ) {
    53355628                        $menu_order = $content_struct['wp_page_order'];
     5629                }
    53365630
    53375631                $page_template = null;
    5338                 if ( ! empty( $content_struct['wp_page_template'] ) && 'page' == $post_type )
     5632                if ( ! empty( $content_struct['wp_page_template'] ) && 'page' == $post_type ) {
    53395633                        $page_template = $content_struct['wp_page_template'];
     5634                }
    53405635
    53415636                $post_author = $postdata['post_author'];
     
    53635658                }
    53645659
    5365                 if ( isset($content_struct['mt_allow_comments']) ) {
    5366                         if ( !is_numeric($content_struct['mt_allow_comments']) ) {
     5660                if ( isset( $content_struct['mt_allow_comments'] ) ) {
     5661                        if ( ! is_numeric( $content_struct['mt_allow_comments'] ) ) {
    53675662                                switch ( $content_struct['mt_allow_comments'] ) {
    53685663                                        case 'closed':
     
    53925687                }
    53935688
    5394                 if ( isset($content_struct['mt_allow_pings']) ) {
    5395                         if ( !is_numeric($content_struct['mt_allow_pings']) ) {
     5689                if ( isset( $content_struct['mt_allow_pings'] ) ) {
     5690                        if ( ! is_numeric( $content_struct['mt_allow_pings'] ) ) {
    53965691                                switch ( $content_struct['mt_allow_pings'] ) {
    53975692                                        case 'closed':
     
    54065701                                }
    54075702                        } else {
    5408                                 switch ( (int) $content_struct["mt_allow_pings"] ) {
     5703                                switch ( (int) $content_struct['mt_allow_pings'] ) {
    54095704                                        case 0:
    54105705                                                $ping_status = 'closed';
     
    54205715                }
    54215716
    5422                 if ( isset( $content_struct['title'] ) )
    5423                         $post_title =  $content_struct['title'];
    5424 
    5425                 if ( isset( $content_struct['description'] ) )
     5717                if ( isset( $content_struct['title'] ) ) {
     5718                        $post_title = $content_struct['title'];
     5719                }
     5720
     5721                if ( isset( $content_struct['description'] ) ) {
    54265722                        $post_content = $content_struct['description'];
     5723                }
    54275724
    54285725                $post_category = array();
    54295726                if ( isset( $content_struct['categories'] ) ) {
    54305727                        $catnames = $content_struct['categories'];
    5431                         if ( is_array($catnames) ) {
    5432                                 foreach ($catnames as $cat) {
    5433                                         $post_category[] = get_cat_ID($cat);
     5728                        if ( is_array( $catnames ) ) {
     5729                                foreach ( $catnames as $cat ) {
     5730                                        $post_category[] = get_cat_ID( $cat );
    54345731                                }
    54355732                        }
    54365733                }
    54375734
    5438                 if ( isset( $content_struct['mt_excerpt'] ) )
    5439                         $post_excerpt =  $content_struct['mt_excerpt'];
     5735                if ( isset( $content_struct['mt_excerpt'] ) ) {
     5736                        $post_excerpt = $content_struct['mt_excerpt'];
     5737                }
    54405738
    54415739                $post_more = isset( $content_struct['mt_text_more'] ) ? $content_struct['mt_text_more'] : null;
    54425740
    54435741                $post_status = $publish ? 'publish' : 'draft';
    5444                 if ( isset( $content_struct["{$post_type}_status"] ) ) {
    5445                         switch( $content_struct["{$post_type}_status"] ) {
     5742                if ( isset( $content_struct[ "{$post_type}_status" ] ) ) {
     5743                        switch ( $content_struct[ "{$post_type}_status" ] ) {
    54465744                                case 'draft':
    54475745                                case 'pending':
    54485746                                case 'private':
    54495747                                case 'publish':
    5450                                         $post_status = $content_struct["{$post_type}_status"];
     5748                                        $post_status = $content_struct[ "{$post_type}_status" ];
    54515749                                        break;
    54525750                                default:
     
    54665764                }
    54675765
    5468                 if ( $post_more )
    5469                         $post_content = $post_content . "<!--more-->" . $post_more;
     5766                if ( $post_more ) {
     5767                        $post_content = $post_content . '<!--more-->' . $post_more;
     5768                }
    54705769
    54715770                $to_ping = null;
    54725771                if ( isset( $content_struct['mt_tb_ping_urls'] ) ) {
    54735772                        $to_ping = $content_struct['mt_tb_ping_urls'];
    5474                         if ( is_array($to_ping) )
    5475                                 $to_ping = implode(' ', $to_ping);
     5773                        if ( is_array( $to_ping ) ) {
     5774                                $to_ping = implode( ' ', $to_ping );
     5775                        }
    54765776                }
    54775777
    54785778                // Do some timestamp voodoo.
    5479                 if ( !empty( $content_struct['date_created_gmt'] ) )
     5779                if ( ! empty( $content_struct['date_created_gmt'] ) ) {
    54805780                        // We know this is supposed to be GMT, so we're going to slap that Z on there by force.
    54815781                        $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
    5482                 elseif ( !empty( $content_struct['dateCreated']) )
     5782                } elseif ( ! empty( $content_struct['dateCreated'] ) ) {
    54835783                        $dateCreated = $content_struct['dateCreated']->getIso();
     5784                }
    54845785
    54855786                // Default to not flagging the post date to be edited unless it's intentional.
    54865787                $edit_date = false;
    54875788
    5488                 if ( !empty( $dateCreated ) ) {
    5489                         $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
    5490                         $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT');
     5789                if ( ! empty( $dateCreated ) ) {
     5790                        $post_date     = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) );
     5791                        $post_date_gmt = iso8601_to_datetime( $dateCreated, 'GMT' );
    54915792
    54925793                        // Flag the post date to be edited.
     
    54985799
    54995800                // We've got all the data -- post it.
    5500                 $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'edit_date', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template');
    5501 
    5502                 $result = wp_update_post($newpost, true);
    5503                 if ( is_wp_error( $result ) )
    5504                         return new IXR_Error(500, $result->get_error_message());
    5505 
    5506                 if ( !$result )
    5507                         return new IXR_Error(500, __('Sorry, your entry could not be edited.'));
     5801                $newpost = compact( 'ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'edit_date', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template' );
     5802
     5803                $result = wp_update_post( $newpost, true );
     5804                if ( is_wp_error( $result ) ) {
     5805                        return new IXR_Error( 500, $result->get_error_message() );
     5806                }
     5807
     5808                if ( ! $result ) {
     5809                        return new IXR_Error( 500, __( 'Sorry, your entry could not be edited.' ) );
     5810                }
    55085811
    55095812                // Only posts can be sticky
    55105813                if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
    5511                         $data = $newpost;
    5512                         $data['sticky'] = $content_struct['sticky'];
     5814                        $data              = $newpost;
     5815                        $data['sticky']    = $content_struct['sticky'];
    55135816                        $data['post_type'] = 'post';
    5514                         $error = $this->_toggle_sticky( $data, true );
     5817                        $error             = $this->_toggle_sticky( $data, true );
    55155818                        if ( $error ) {
    55165819                                return $error;
     
    55185821                }
    55195822
    5520                 if ( isset($content_struct['custom_fields']) )
    5521                         $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
    5522 
    5523                 if ( isset ( $content_struct['wp_post_thumbnail'] ) ) {
     5823                if ( isset( $content_struct['custom_fields'] ) ) {
     5824                        $this->set_custom_fields( $post_ID, $content_struct['custom_fields'] );
     5825                }
     5826
     5827                if ( isset( $content_struct['wp_post_thumbnail'] ) ) {
    55245828
    55255829                        // Empty value deletes, non-empty value adds/updates.
     
    55275831                                delete_post_thumbnail( $post_ID );
    55285832                        } else {
    5529                                 if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false )
     5833                                if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false ) {
    55305834                                        return new IXR_Error( 404, __( 'Invalid attachment ID.' ) );
     5835                                }
    55315836                        }
    55325837                        unset( $content_struct['wp_post_thumbnail'] );
     
    55345839
    55355840                // Handle enclosures.
    5536                 $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null;
    5537                 $this->add_enclosure_if_new($post_ID, $thisEnclosure);
     5841                $thisEnclosure = isset( $content_struct['enclosure'] ) ? $content_struct['enclosure'] : null;
     5842                $this->add_enclosure_if_new( $post_ID, $thisEnclosure );
    55385843
    55395844                $this->attach_uploads( $ID, $post_content );
    55405845
    55415846                // Handle post formats if assigned, validation is handled earlier in this function.
    5542                 if ( isset( $content_struct['wp_post_format'] ) )
     5847                if ( isset( $content_struct['wp_post_format'] ) ) {
    55435848                        set_post_format( $post_ID, $content_struct['wp_post_format'] );
     5849                }
    55445850
    55455851                /**
     
    55785884                $password = $args[2];
    55795885
    5580                 if ( !$user = $this->login($username, $password) )
    5581                         return $this->error;
    5582 
    5583                 $postdata = get_post($post_ID, ARRAY_A);
    5584                 if ( ! $postdata )
     5886                if ( ! $user = $this->login( $username, $password ) ) {
     5887                        return $this->error;
     5888                }
     5889
     5890                $postdata = get_post( $post_ID, ARRAY_A );
     5891                if ( ! $postdata ) {
    55855892                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    5586 
    5587                 if ( !current_user_can( 'edit_post', $post_ID ) )
     5893                }
     5894
     5895                if ( ! current_user_can( 'edit_post', $post_ID ) ) {
    55885896                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
     5897                }
    55895898
    55905899                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    55915900                do_action( 'xmlrpc_call', 'metaWeblog.getPost' );
    55925901
    5593                 if ($postdata['post_date'] != '') {
    5594                         $post_date = $this->_convert_date( $postdata['post_date'] );
    5595                         $post_date_gmt = $this->_convert_date_gmt( $postdata['post_date_gmt'], $postdata['post_date'] );
    5596                         $post_modified = $this->_convert_date( $postdata['post_modified'] );
     5902                if ( $postdata['post_date'] != '' ) {
     5903                        $post_date         = $this->_convert_date( $postdata['post_date'] );
     5904                        $post_date_gmt     = $this->_convert_date_gmt( $postdata['post_date_gmt'], $postdata['post_date'] );
     5905                        $post_modified     = $this->_convert_date( $postdata['post_modified'] );
    55975906                        $post_modified_gmt = $this->_convert_date_gmt( $postdata['post_modified_gmt'], $postdata['post_modified'] );
    55985907
    55995908                        $categories = array();
    5600                         $catids = wp_get_post_categories($post_ID);
    5601                         foreach ($catids as $catid)
    5602                                 $categories[] = get_cat_name($catid);
     5909                        $catids     = wp_get_post_categories( $post_ID );
     5910                        foreach ( $catids as $catid ) {
     5911                                $categories[] = get_cat_name( $catid );
     5912                        }
    56035913
    56045914                        $tagnames = array();
    5605                         $tags = wp_get_post_tags( $post_ID );
    5606                         if ( !empty( $tags ) ) {
    5607                                 foreach ( $tags as $tag )
     5915                        $tags     = wp_get_post_tags( $post_ID );
     5916                        if ( ! empty( $tags ) ) {
     5917                                foreach ( $tags as $tag ) {
    56085918                                        $tagnames[] = $tag->name;
     5919                                }
    56095920                                $tagnames = implode( ', ', $tagnames );
    56105921                        } else {
     
    56125923                        }
    56135924
    5614                         $post = get_extended($postdata['post_content']);
    5615                         $link = get_permalink($postdata['ID']);
     5925                        $post = get_extended( $postdata['post_content'] );
     5926                        $link = get_permalink( $postdata['ID'] );
    56165927
    56175928                        // Get the author info.
    5618                         $author = get_userdata($postdata['post_author']);
    5619 
    5620                         $allow_comments = ('open' == $postdata['comment_status']) ? 1 : 0;
    5621                         $allow_pings = ('open' == $postdata['ping_status']) ? 1 : 0;
     5929                        $author = get_userdata( $postdata['post_author'] );
     5930
     5931                        $allow_comments = ( 'open' == $postdata['comment_status'] ) ? 1 : 0;
     5932                        $allow_pings    = ( 'open' == $postdata['ping_status'] ) ? 1 : 0;
    56225933
    56235934                        // Consider future posts as published
    5624                         if ( $postdata['post_status'] === 'future' )
     5935                        if ( $postdata['post_status'] === 'future' ) {
    56255936                                $postdata['post_status'] = 'publish';
     5937                        }
    56265938
    56275939                        // Get post format
    56285940                        $post_format = get_post_format( $post_ID );
    5629                         if ( empty( $post_format ) )
     5941                        if ( empty( $post_format ) ) {
    56305942                                $post_format = 'standard';
     5943                        }
    56315944
    56325945                        $sticky = false;
    5633                         if ( is_sticky( $post_ID ) )
     5946                        if ( is_sticky( $post_ID ) ) {
    56345947                                $sticky = true;
     5948                        }
    56355949
    56365950                        $enclosure = array();
    5637                         foreach ( (array) get_post_custom($post_ID) as $key => $val) {
    5638                                 if ($key == 'enclosure') {
     5951                        foreach ( (array) get_post_custom( $post_ID ) as $key => $val ) {
     5952                                if ( $key == 'enclosure' ) {
    56395953                                        foreach ( (array) $val as $enc ) {
    5640                                                 $encdata = explode("\n", $enc);
    5641                                                 $enclosure['url'] = trim(htmlspecialchars($encdata[0]));
    5642                                                 $enclosure['length'] = (int) trim($encdata[1]);
    5643                                                 $enclosure['type'] = trim($encdata[2]);
     5954                                                $encdata             = explode( "\n", $enc );
     5955                                                $enclosure['url']    = trim( htmlspecialchars( $encdata[0] ) );
     5956                                                $enclosure['length'] = (int) trim( $encdata[1] );
     5957                                                $enclosure['type']   = trim( $encdata[2] );
    56445958                                                break 2;
    56455959                                        }
     
    56485962
    56495963                        $resp = array(
    5650                                 'dateCreated' => $post_date,
    5651                                 'userid' => $postdata['post_author'],
    5652                                 'postid' => $postdata['ID'],
    5653                                 'description' => $post['main'],
    5654                                 'title' => $postdata['post_title'],
    5655                                 'link' => $link,
    5656                                 'permaLink' => $link,
     5964                                'dateCreated'            => $post_date,
     5965                                'userid'                 => $postdata['post_author'],
     5966                                'postid'                 => $postdata['ID'],
     5967                                'description'            => $post['main'],
     5968                                'title'                  => $postdata['post_title'],
     5969                                'link'                   => $link,
     5970                                'permaLink'              => $link,
    56575971                                // commented out because no other tool seems to use this
    56585972                                //            'content' => $entry['post_content'],
    5659                                 'categories' => $categories,
    5660                                 'mt_excerpt' => $postdata['post_excerpt'],
    5661                                 'mt_text_more' => $post['extended'],
    5662                                 'wp_more_text' => $post['more_text'],
    5663                                 'mt_allow_comments' => $allow_comments,
    5664                                 'mt_allow_pings' => $allow_pings,
    5665                                 'mt_keywords' => $tagnames,
    5666                                 'wp_slug' => $postdata['post_name'],
    5667                                 'wp_password' => $postdata['post_password'],
    5668                                 'wp_author_id' => (string) $author->ID,
     5973                                'categories'             => $categories,
     5974                                'mt_excerpt'             => $postdata['post_excerpt'],
     5975                                'mt_text_more'           => $post['extended'],
     5976                                'wp_more_text'           => $post['more_text'],
     5977                                'mt_allow_comments'      => $allow_comments,
     5978                                'mt_allow_pings'         => $allow_pings,
     5979                                'mt_keywords'            => $tagnames,
     5980                                'wp_slug'                => $postdata['post_name'],
     5981                                'wp_password'            => $postdata['post_password'],
     5982                                'wp_author_id'           => (string) $author->ID,
    56695983                                'wp_author_display_name' => $author->display_name,
    5670                                 'date_created_gmt' => $post_date_gmt,
    5671                                 'post_status' => $postdata['post_status'],
    5672                                 'custom_fields' => $this->get_custom_fields($post_ID),
    5673                                 'wp_post_format' => $post_format,
    5674                                 'sticky' => $sticky,
    5675                                 'date_modified' => $post_modified,
    5676                                 'date_modified_gmt' => $post_modified_gmt
     5984                                'date_created_gmt'       => $post_date_gmt,
     5985                                'post_status'            => $postdata['post_status'],
     5986                                'custom_fields'          => $this->get_custom_fields( $post_ID ),
     5987                                'wp_post_format'         => $post_format,
     5988                                'sticky'                 => $sticky,
     5989                                'date_modified'          => $post_modified,
     5990                                'date_modified_gmt'      => $post_modified_gmt,
    56775991                        );
    56785992
    5679                         if ( !empty($enclosure) ) $resp['enclosure'] = $enclosure;
     5993                        if ( ! empty( $enclosure ) ) {
     5994                                $resp['enclosure'] = $enclosure;
     5995                        }
    56805996
    56815997                        $resp['wp_post_thumbnail'] = get_post_thumbnail_id( $postdata['ID'] );
     
    56835999                        return $resp;
    56846000                } else {
    5685                         return new IXR_Error(404, __('Sorry, no such post.'));
     6001                        return new IXR_Error( 404, __( 'Sorry, no such post.' ) );
    56866002                }
    56876003        }
     
    57076023                $username = $args[1];
    57086024                $password = $args[2];
    5709                 if ( isset( $args[3] ) )
     6025                if ( isset( $args[3] ) ) {
    57106026                        $query = array( 'numberposts' => absint( $args[3] ) );
    5711                 else
     6027                } else {
    57126028                        $query = array();
    5713 
    5714                 if ( !$user = $this->login($username, $password) )
    5715                         return $this->error;
    5716 
    5717                 if ( ! current_user_can( 'edit_posts' ) )
     6029                }
     6030
     6031                if ( ! $user = $this->login( $username, $password ) ) {
     6032                        return $this->error;
     6033                }
     6034
     6035                if ( ! current_user_can( 'edit_posts' ) ) {
    57186036                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) );
     6037                }
    57196038
    57206039                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    57236042                $posts_list = wp_get_recent_posts( $query );
    57246043
    5725                 if ( !$posts_list )
     6044                if ( ! $posts_list ) {
    57266045                        return array();
     6046                }
    57276047
    57286048                $recent_posts = array();
    5729                 foreach ($posts_list as $entry) {
    5730                         if ( !current_user_can( 'edit_post', $entry['ID'] ) )
     6049                foreach ( $posts_list as $entry ) {
     6050                        if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) {
    57316051                                continue;
    5732 
    5733                         $post_date = $this->_convert_date( $entry['post_date'] );
    5734                         $post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] );
    5735                         $post_modified = $this->_convert_date( $entry['post_modified'] );
     6052                        }
     6053
     6054                        $post_date         = $this->_convert_date( $entry['post_date'] );
     6055                        $post_date_gmt     = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] );
     6056                        $post_modified     = $this->_convert_date( $entry['post_modified'] );
    57366057                        $post_modified_gmt = $this->_convert_date_gmt( $entry['post_modified_gmt'], $entry['post_modified'] );
    57376058
    57386059                        $categories = array();
    5739                         $catids = wp_get_post_categories($entry['ID']);
    5740                         foreach ( $catids as $catid )
    5741                                 $categories[] = get_cat_name($catid);
     6060                        $catids     = wp_get_post_categories( $entry['ID'] );
     6061                        foreach ( $catids as $catid ) {
     6062                                $categories[] = get_cat_name( $catid );
     6063                        }
    57426064
    57436065                        $tagnames = array();
    5744                         $tags = wp_get_post_tags( $entry['ID'] );
    5745                         if ( !empty( $tags ) ) {
     6066                        $tags     = wp_get_post_tags( $entry['ID'] );
     6067                        if ( ! empty( $tags ) ) {
    57466068                                foreach ( $tags as $tag ) {
    57476069                                        $tagnames[] = $tag->name;
     
    57526074                        }
    57536075
    5754                         $post = get_extended($entry['post_content']);
    5755                         $link = get_permalink($entry['ID']);
     6076                        $post = get_extended( $entry['post_content'] );
     6077                        $link = get_permalink( $entry['ID'] );
    57566078
    57576079                        // Get the post author info.
    5758                         $author = get_userdata($entry['post_author']);
    5759 
    5760                         $allow_comments = ('open' == $entry['comment_status']) ? 1 : 0;
    5761                         $allow_pings = ('open' == $entry['ping_status']) ? 1 : 0;
     6080                        $author = get_userdata( $entry['post_author'] );
     6081
     6082                        $allow_comments = ( 'open' == $entry['comment_status'] ) ? 1 : 0;
     6083                        $allow_pings    = ( 'open' == $entry['ping_status'] ) ? 1 : 0;
    57626084
    57636085                        // Consider future posts as published
    5764                         if ( $entry['post_status'] === 'future' )
     6086                        if ( $entry['post_status'] === 'future' ) {
    57656087                                $entry['post_status'] = 'publish';
     6088                        }
    57666089
    57676090                        // Get post format
    57686091                        $post_format = get_post_format( $entry['ID'] );
    5769                         if ( empty( $post_format ) )
     6092                        if ( empty( $post_format ) ) {
    57706093                                $post_format = 'standard';
     6094                        }
    57716095
    57726096                        $recent_posts[] = array(
    5773                                 'dateCreated' => $post_date,
    5774                                 'userid' => $entry['post_author'],
    5775                                 'postid' => (string) $entry['ID'],
    5776                                 'description' => $post['main'],
    5777                                 'title' => $entry['post_title'],
    5778                                 'link' => $link,
    5779                                 'permaLink' => $link,
     6097                                'dateCreated'            => $post_date,
     6098                                'userid'                 => $entry['post_author'],
     6099                                'postid'                 => (string) $entry['ID'],
     6100                                'description'            => $post['main'],
     6101                                'title'                  => $entry['post_title'],
     6102                                'link'                   => $link,
     6103                                'permaLink'              => $link,
    57806104                                // commented out because no other tool seems to use this
    57816105                                // 'content' => $entry['post_content'],
    5782                                 'categories' => $categories,
    5783                                 'mt_excerpt' => $entry['post_excerpt'],
    5784                                 'mt_text_more' => $post['extended'],
    5785                                 'wp_more_text' => $post['more_text'],
    5786                                 'mt_allow_comments' => $allow_comments,
    5787                                 'mt_allow_pings' => $allow_pings,
    5788                                 'mt_keywords' => $tagnames,
    5789                                 'wp_slug' => $entry['post_name'],
    5790                                 'wp_password' => $entry['post_password'],
    5791                                 'wp_author_id' => (string) $author->ID,
     6106                                'categories'             => $categories,
     6107                                'mt_excerpt'             => $entry['post_excerpt'],
     6108                                'mt_text_more'           => $post['extended'],
     6109                                'wp_more_text'           => $post['more_text'],
     6110                                'mt_allow_comments'      => $allow_comments,
     6111                                'mt_allow_pings'         => $allow_pings,
     6112                                'mt_keywords'            => $tagnames,
     6113                                'wp_slug'                => $entry['post_name'],
     6114                                'wp_password'            => $entry['post_password'],
     6115                                'wp_author_id'           => (string) $author->ID,
    57926116                                'wp_author_display_name' => $author->display_name,
    5793                                 'date_created_gmt' => $post_date_gmt,
    5794                                 'post_status' => $entry['post_status'],
    5795                                 'custom_fields' => $this->get_custom_fields($entry['ID']),
    5796                                 'wp_post_format' => $post_format,
    5797                                 'date_modified' => $post_modified,
    5798                                 'date_modified_gmt' => $post_modified_gmt,
    5799                                 'sticky' => ( $entry['post_type'] === 'post' && is_sticky( $entry['ID'] ) ),
    5800                                 'wp_post_thumbnail' => get_post_thumbnail_id( $entry['ID'] )
     6117                                'date_created_gmt'       => $post_date_gmt,
     6118                                'post_status'            => $entry['post_status'],
     6119                                'custom_fields'          => $this->get_custom_fields( $entry['ID'] ),
     6120                                'wp_post_format'         => $post_format,
     6121                                'date_modified'          => $post_modified,
     6122                                'date_modified_gmt'      => $post_modified_gmt,
     6123                                'sticky'                 => ( $entry['post_type'] === 'post' && is_sticky( $entry['ID'] ) ),
     6124                                'wp_post_thumbnail'      => get_post_thumbnail_id( $entry['ID'] ),
    58016125                        );
    58026126                }
     
    58256149                $password = $args[2];
    58266150
    5827                 if ( !$user = $this->login($username, $password) )
    5828                         return $this->error;
    5829 
    5830                 if ( !current_user_can( 'edit_posts' ) )
     6151                if ( ! $user = $this->login( $username, $password ) ) {
     6152                        return $this->error;
     6153                }
     6154
     6155                if ( ! current_user_can( 'edit_posts' ) ) {
    58316156                        return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) );
     6157                }
    58326158
    58336159                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    58366162                $categories_struct = array();
    58376163
    5838                 if ( $cats = get_categories(array('get' => 'all')) ) {
     6164                if ( $cats = get_categories( array( 'get' => 'all' ) ) ) {
    58396165                        foreach ( $cats as $cat ) {
    5840                                 $struct = array();
    5841                                 $struct['categoryId'] = $cat->term_id;
    5842                                 $struct['parentId'] = $cat->parent;
    5843                                 $struct['description'] = $cat->name;
     6166                                $struct                        = array();
     6167                                $struct['categoryId']          = $cat->term_id;
     6168                                $struct['parentId']            = $cat->parent;
     6169                                $struct['description']         = $cat->name;
    58446170                                $struct['categoryDescription'] = $cat->description;
    5845                                 $struct['categoryName'] = $cat->name;
    5846                                 $struct['htmlUrl'] = esc_html(get_category_link($cat->term_id));
    5847                                 $struct['rssUrl'] = esc_html(get_category_feed_link($cat->term_id, 'rss2'));
     6171                                $struct['categoryName']        = $cat->name;
     6172                                $struct['htmlUrl']             = esc_html( get_category_link( $cat->term_id ) );
     6173                                $struct['rssUrl']              = esc_html( get_category_feed_link( $cat->term_id, 'rss2' ) );
    58486174
    58496175                                $categories_struct[] = $struct;
     
    58866212                $bits = $data['bits'];
    58876213
    5888                 if ( !$user = $this->login($username, $password) )
    5889                         return $this->error;
     6214                if ( ! $user = $this->login( $username, $password ) ) {
     6215                        return $this->error;
     6216                }
    58906217
    58916218                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    58926219                do_action( 'xmlrpc_call', 'metaWeblog.newMediaObject' );
    58936220
    5894                 if ( !current_user_can('upload_files') ) {
     6221                if ( ! current_user_can( 'upload_files' ) ) {
    58956222                        $this->error = new IXR_Error( 401, __( 'Sorry, you are not allowed to upload files.' ) );
    58966223                        return $this->error;
     
    59166243                }
    59176244
    5918                 $upload = wp_upload_bits($name, null, $bits);
    5919                 if ( ! empty($upload['error']) ) {
     6245                $upload = wp_upload_bits( $name, null, $bits );
     6246                if ( ! empty( $upload['error'] ) ) {
    59206247                        /* translators: 1: file name, 2: error message */
    59216248                        $errorString = sprintf( __( 'Could not write file %1$s (%2$s).' ), $name, $upload['error'] );
     
    59276254                        $post_id = (int) $data['post_id'];
    59286255
    5929                         if ( ! current_user_can( 'edit_post', $post_id ) )
     6256                        if ( ! current_user_can( 'edit_post', $post_id ) ) {
    59306257                                return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
     6258                        }
    59316259                }
    59326260                $attachment = array(
    5933                         'post_title' => $name,
    5934                         'post_content' => '',
    5935                         'post_type' => 'attachment',
    5936                         'post_parent' => $post_id,
     6261                        'post_title'     => $name,
     6262                        'post_content'   => '',
     6263                        'post_type'      => 'attachment',
     6264                        'post_parent'    => $post_id,
    59376265                        'post_mime_type' => $type,
    5938                         'guid' => $upload[ 'url' ]
     6266                        'guid'           => $upload['url'],
    59396267                );
    59406268
    59416269                // Save the data
    5942                 $id = wp_insert_attachment( $attachment, $upload[ 'file' ], $post_id );
     6270                $id = wp_insert_attachment( $attachment, $upload['file'], $post_id );
    59436271                wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
    59446272
     
    59876315                $username = $args[1];
    59886316                $password = $args[2];
    5989                 if ( isset( $args[3] ) )
     6317                if ( isset( $args[3] ) ) {
    59906318                        $query = array( 'numberposts' => absint( $args[3] ) );
    5991                 else
     6319                } else {
    59926320                        $query = array();
    5993 
    5994                 if ( !$user = $this->login($username, $password) )
    5995                         return $this->error;
     6321                }
     6322
     6323                if ( ! $user = $this->login( $username, $password ) ) {
     6324                        return $this->error;
     6325                }
    59966326
    59976327                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    60006330                $posts_list = wp_get_recent_posts( $query );
    60016331
    6002                 if ( !$posts_list ) {
    6003                         $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.'));
     6332                if ( ! $posts_list ) {
     6333                        $this->error = new IXR_Error( 500, __( 'Either there are no posts, or something went wrong.' ) );
    60046334                        return $this->error;
    60056335                }
     
    60076337                $recent_posts = array();
    60086338
    6009                 foreach ($posts_list as $entry) {
    6010                         if ( !current_user_can( 'edit_post', $entry['ID'] ) )
     6339                foreach ( $posts_list as $entry ) {
     6340                        if ( ! current_user_can( 'edit_post', $entry['ID'] ) ) {
    60116341                                continue;
    6012 
    6013                         $post_date = $this->_convert_date( $entry['post_date'] );
     6342                        }
     6343
     6344                        $post_date     = $this->_convert_date( $entry['post_date'] );
    60146345                        $post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] );
    60156346
    60166347                        $recent_posts[] = array(
    6017                                 'dateCreated' => $post_date,
    6018                                 'userid' => $entry['post_author'],
    6019                                 'postid' => (string) $entry['ID'],
    6020                                 'title' => $entry['post_title'],
    6021                                 'post_status' => $entry['post_status'],
    6022                                 'date_created_gmt' => $post_date_gmt
     6348                                'dateCreated'      => $post_date,
     6349                                'userid'           => $entry['post_author'],
     6350                                'postid'           => (string) $entry['ID'],
     6351                                'title'            => $entry['post_title'],
     6352                                'post_status'      => $entry['post_status'],
     6353                                'date_created_gmt' => $post_date_gmt,
    60236354                        );
    60246355                }
     
    60476378                $password = $args[2];
    60486379
    6049                 if ( !$user = $this->login($username, $password) )
    6050                         return $this->error;
    6051 
    6052                 if ( !current_user_can( 'edit_posts' ) )
     6380                if ( ! $user = $this->login( $username, $password ) ) {
     6381                        return $this->error;
     6382                }
     6383
     6384                if ( ! current_user_can( 'edit_posts' ) ) {
    60536385                        return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) );
     6386                }
    60546387
    60556388                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    60586391                $categories_struct = array();
    60596392
    6060                 if ( $cats = get_categories(array('hide_empty' => 0, 'hierarchical' => 0)) ) {
     6393                if ( $cats = get_categories(
     6394                        array(
     6395                                'hide_empty'   => 0,
     6396                                'hierarchical' => 0,
     6397                        )
     6398                ) ) {
    60616399                        foreach ( $cats as $cat ) {
    6062                                 $struct = array();
    6063                                 $struct['categoryId'] = $cat->term_id;
     6400                                $struct                 = array();
     6401                                $struct['categoryId']   = $cat->term_id;
    60646402                                $struct['categoryName'] = $cat->name;
    60656403
     
    60926430                $password = $args[2];
    60936431
    6094                 if ( !$user = $this->login($username, $password) )
    6095                         return $this->error;
    6096 
    6097                 if ( ! get_post( $post_ID ) )
     6432                if ( ! $user = $this->login( $username, $password ) ) {
     6433                        return $this->error;
     6434                }
     6435
     6436                if ( ! get_post( $post_ID ) ) {
    60986437                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    6099 
    6100                 if ( !current_user_can( 'edit_post', $post_ID ) )
     6438                }
     6439
     6440                if ( ! current_user_can( 'edit_post', $post_ID ) ) {
    61016441                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
     6442                }
    61026443
    61036444                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
     
    61056446
    61066447                $categories = array();
    6107                 $catids = wp_get_post_categories(intval($post_ID));
     6448                $catids     = wp_get_post_categories( intval( $post_ID ) );
    61086449                // first listed category will be the primary category
    61096450                $isPrimary = true;
    61106451                foreach ( $catids as $catid ) {
    61116452                        $categories[] = array(
    6112                                 'categoryName' => get_cat_name($catid),
    6113                                 'categoryId' => (string) $catid,
    6114                                 'isPrimary' => $isPrimary
     6453                                'categoryName' => get_cat_name( $catid ),
     6454                                'categoryId'   => (string) $catid,
     6455                                'isPrimary'    => $isPrimary,
    61156456                        );
    6116                         $isPrimary = false;
     6457                        $isPrimary    = false;
    61176458                }
    61186459
     
    61436484                $categories = $args[3];
    61446485
    6145                 if ( !$user = $this->login($username, $password) )
    6146                         return $this->error;
     6486                if ( ! $user = $this->login( $username, $password ) ) {
     6487                        return $this->error;
     6488                }
    61476489
    61486490                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    61496491                do_action( 'xmlrpc_call', 'mt.setPostCategories' );
    61506492
    6151                 if ( ! get_post( $post_ID ) )
     6493                if ( ! get_post( $post_ID ) ) {
    61526494                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    6153 
    6154                 if ( !current_user_can('edit_post', $post_ID) )
    6155                         return new IXR_Error(401, __('Sorry, you are not allowed to edit this post.'));
     6495                }
     6496
     6497                if ( ! current_user_can( 'edit_post', $post_ID ) ) {
     6498                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) );
     6499                }
    61566500
    61576501                $catids = array();
     
    61606504                }
    61616505
    6162                 wp_set_post_categories($post_ID, $catids);
     6506                wp_set_post_categories( $post_ID, $catids );
    61636507
    61646508                return true;
     
    62146558                do_action( 'xmlrpc_call', 'mt.getTrackbackPings' );
    62156559
    6216                 $actual_post = get_post($post_ID, ARRAY_A);
    6217 
    6218                 if ( !$actual_post )
    6219                         return new IXR_Error(404, __('Sorry, no such post.'));
    6220 
    6221                 $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) );
    6222 
    6223                 if ( !$comments )
     6560                $actual_post = get_post( $post_ID, ARRAY_A );
     6561
     6562                if ( ! $actual_post ) {
     6563                        return new IXR_Error( 404, __( 'Sorry, no such post.' ) );
     6564                }
     6565
     6566                $comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID ) );
     6567
     6568                if ( ! $comments ) {
    62246569                        return array();
     6570                }
    62256571
    62266572                $trackback_pings = array();
    62276573                foreach ( $comments as $comment ) {
    62286574                        if ( 'trackback' == $comment->comment_type ) {
    6229                                 $content = $comment->comment_content;
    6230                                 $title = substr($content, 8, (strpos($content, '</strong>') - 8));
     6575                                $content           = $comment->comment_content;
     6576                                $title             = substr( $content, 8, ( strpos( $content, '</strong>' ) - 8 ) );
    62316577                                $trackback_pings[] = array(
    62326578                                        'pingTitle' => $title,
    62336579                                        'pingURL'   => $comment->comment_author_url,
    6234                                         'pingIP'    => $comment->comment_author_IP
     6580                                        'pingIP'    => $comment->comment_author_IP,
    62356581                                );
    62366582                        }
     
    62616607                $password = $args[2];
    62626608
    6263                 if ( !$user = $this->login($username, $password) )
    6264                         return $this->error;
     6609                if ( ! $user = $this->login( $username, $password ) ) {
     6610                        return $this->error;
     6611                }
    62656612
    62666613                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
    62676614                do_action( 'xmlrpc_call', 'mt.publishPost' );
    62686615
    6269                 $postdata = get_post($post_ID, ARRAY_A);
    6270                 if ( ! $postdata )
     6616                $postdata = get_post( $post_ID, ARRAY_A );
     6617                if ( ! $postdata ) {
    62716618                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
    6272 
    6273                 if ( !current_user_can('publish_posts') || !current_user_can('edit_post', $post_ID) )
    6274                         return new IXR_Error(401, __('Sorry, you are not allowed to publish this post.'));
     6619                }
     6620
     6621                if ( ! current_user_can( 'publish_posts' ) || ! current_user_can( 'edit_post', $post_ID ) ) {
     6622                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) );
     6623                }
    62756624
    62766625                $postdata['post_status'] = 'publish';
    62776626
    62786627                // retain old cats
    6279                 $cats = wp_get_post_categories($post_ID);
     6628                $cats                      = wp_get_post_categories( $post_ID );
    62806629                $postdata['post_category'] = $cats;
    6281                 $this->escape($postdata);
     6630                $this->escape( $postdata );
    62826631
    62836632                return wp_update_post( $postdata );
     
    63106659
    63116660                $pagelinkedfrom = str_replace( '&amp;', '&', $args[0] );
    6312                 $pagelinkedto = str_replace( '&amp;', '&', $args[1] );
    6313                 $pagelinkedto = str_replace( '&', '&amp;', $pagelinkedto );
     6661                $pagelinkedto   = str_replace( '&amp;', '&', $args[1] );
     6662                $pagelinkedto   = str_replace( '&', '&amp;', $pagelinkedto );
    63146663
    63156664                /**
     
    63236672                $pagelinkedfrom = apply_filters( 'pingback_ping_source_uri', $pagelinkedfrom, $pagelinkedto );
    63246673
    6325                 if ( ! $pagelinkedfrom )
     6674                if ( ! $pagelinkedfrom ) {
    63266675                        return $this->pingback_error( 0, __( 'A valid URL was not provided.' ) );
     6676                }
    63276677
    63286678                // Check if the page linked to is in our site
    6329                 $pos1 = strpos($pagelinkedto, str_replace(array('http://www.','http://','https://www.','https://'), '', get_option('home')));
    6330                 if ( !$pos1 )
     6679                $pos1 = strpos( $pagelinkedto, str_replace( array( 'http://www.', 'http://', 'https://www.', 'https://' ), '', get_option( 'home' ) ) );
     6680                if ( ! $pos1 ) {
    63316681                        return $this->pingback_error( 0, __( 'Is there no link to us?' ) );
     6682                }
    63326683
    63336684                // let's find which post is linked to
    63346685                // FIXME: does url_to_postid() cover all these cases already?
    63356686                //        if so, then let's use it and drop the old code.
    6336                 $urltest = parse_url($pagelinkedto);
    6337                 if ( $post_ID = url_to_postid($pagelinkedto) ) {
     6687                $urltest = parse_url( $pagelinkedto );
     6688                if ( $post_ID = url_to_postid( $pagelinkedto ) ) {
    63386689                        // $way
    6339                 } elseif ( isset( $urltest['path'] ) && preg_match('#p/[0-9]{1,}#', $urltest['path'], $match) ) {
     6690                } elseif ( isset( $urltest['path'] ) && preg_match( '#p/[0-9]{1,}#', $urltest['path'], $match ) ) {
    63406691                        // the path defines the post_ID (archives/p/XXXX)
    6341                         $blah = explode('/', $match[0]);
     6692                        $blah    = explode( '/', $match[0] );
    63426693                        $post_ID = (int) $blah[1];
    6343                 } elseif ( isset( $urltest['query'] ) && preg_match('#p=[0-9]{1,}#', $urltest['query'], $match) ) {
     6694                } elseif ( isset( $urltest['query'] ) && preg_match( '#p=[0-9]{1,}#', $urltest['query'], $match ) ) {
    63446695                        // the querystring defines the post_ID (?p=XXXX)
    6345                         $blah = explode('=', $match[0]);
     6696                        $blah    = explode( '=', $match[0] );
    63466697                        $post_ID = (int) $blah[1];
    6347                 } elseif ( isset($urltest['fragment']) ) {
     6698                } elseif ( isset( $urltest['fragment'] ) ) {
    63486699                        // an #anchor is there, it's either...
    6349                         if ( intval($urltest['fragment']) ) {
     6700                        if ( intval( $urltest['fragment'] ) ) {
    63506701                                // ...an integer #XXXX (simplest case)
    63516702                                $post_ID = (int) $urltest['fragment'];
    6352                         } elseif ( preg_match('/post-[0-9]+/',$urltest['fragment']) ) {
     6703                        } elseif ( preg_match( '/post-[0-9]+/', $urltest['fragment'] ) ) {
    63536704                                // ...a post id in the form 'post-###'
    6354                                 $post_ID = preg_replace('/[^0-9]+/', '', $urltest['fragment']);
    6355                         } elseif ( is_string($urltest['fragment']) ) {
     6705                                $post_ID = preg_replace( '/[^0-9]+/', '', $urltest['fragment'] );
     6706                        } elseif ( is_string( $urltest['fragment'] ) ) {
    63566707                                // ...or a string #title, a little more complicated
    6357                                 $title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']);
    6358                                 $sql = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", $title );
    6359                                 if (! ($post_ID = $wpdb->get_var($sql)) ) {
     6708                                $title = preg_replace( '/[^a-z0-9]/i', '.', $urltest['fragment'] );
     6709                                $sql   = $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", $title );
     6710                                if ( ! ( $post_ID = $wpdb->get_var( $sql ) ) ) {
    63606711                                        // returning unknown error '0' is better than die()ing
    6361                                         return $this->pingback_error( 0, '' );
     6712                                        return $this->pingback_error( 0, '' );
    63626713                                }
    63636714                        }
    63646715                } else {
    63656716                        // TODO: Attempt to extract a post ID from the given URL
    6366                         return $this->pingback_error( 33, __('The specified target URL cannot be used as a target. It either doesn&#8217;t exist, or it is not a pingback-enabled resource.' ) );
     6717                        return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn&#8217;t exist, or it is not a pingback-enabled resource.' ) );
    63676718                }
    63686719                $post_ID = (int) $post_ID;
    63696720
    6370                 $post = get_post($post_ID);
    6371 
    6372                 if ( !$post ) // Post_ID not found
    6373                         return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn&#8217;t exist, or it is not a pingback-enabled resource.' ) );
    6374 
    6375                 if ( $post_ID == url_to_postid($pagelinkedfrom) )
     6721                $post = get_post( $post_ID );
     6722
     6723                if ( ! $post ) { // Post_ID not found
     6724                        return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn&#8217;t exist, or it is not a pingback-enabled resource.' ) );
     6725                }
     6726
     6727                if ( $post_ID == url_to_postid( $pagelinkedfrom ) ) {
    63766728                        return $this->pingback_error( 0, __( 'The source URL and the target URL cannot both point to the same resource.' ) );
     6729                }
    63776730
    63786731                // Check if pings are on
    6379                 if ( !pings_open($post) )
    6380                         return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn&#8217;t exist, or it is not a pingback-enabled resource.' ) );
     6732                if ( ! pings_open( $post ) ) {
     6733                        return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn&#8217;t exist, or it is not a pingback-enabled resource.' ) );
     6734                }
    63816735
    63826736                // Let's check that the remote site didn't already pingback this entry
    6383                 if ( $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom) ) )
     6737                if ( $wpdb->get_results( $wpdb->prepare( "SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom ) ) ) {
    63846738                        return $this->pingback_error( 48, __( 'The pingback has already been registered.' ) );
     6739                }
    63856740
    63866741                // very stupid, but gives time to the 'from' server to publish !
    6387                 sleep(1);
     6742                sleep( 1 );
    63886743
    63896744                $remote_ip = preg_replace( '/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR'] );
     
    63946749                // Let's check the remote site
    63956750                $http_api_args = array(
    6396                         'timeout' => 10,
    6397                         'redirection' => 0,
     6751                        'timeout'             => 10,
     6752                        'redirection'         => 0,
    63986753                        'limit_response_size' => 153600, // 150 KB
    6399                         'user-agent' => "$user_agent; verifying pingback from $remote_ip",
    6400                         'headers' => array(
     6754                        'user-agent'          => "$user_agent; verifying pingback from $remote_ip",
     6755                        'headers'             => array(
    64016756                                'X-Pingback-Forwarded-For' => $remote_ip,
    64026757                        ),
    64036758                );
    64046759
    6405                 $request = wp_safe_remote_get( $pagelinkedfrom, $http_api_args );
     6760                $request       = wp_safe_remote_get( $pagelinkedfrom, $http_api_args );
    64066761                $remote_source = $remote_source_original = wp_remote_retrieve_body( $request );
    64076762
     
    64236778                $remote_source = str_replace( '<!DOC', '<DOC', $remote_source );
    64246779                $remote_source = preg_replace( '/[\r\n\t ]+/', ' ', $remote_source ); // normalize spaces
    6425                 $remote_source = preg_replace( "/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/", "\n\n", $remote_source );
     6780                $remote_source = preg_replace( '/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/', "\n\n", $remote_source );
    64266781
    64276782                preg_match( '|<title>([^<]*?)</title>|is', $remote_source, $matchtitle );
     
    64356790                $p = explode( "\n\n", $remote_source );
    64366791
    6437                 $preg_target = preg_quote($pagelinkedto, '|');
     6792                $preg_target = preg_quote( $pagelinkedto, '|' );
    64386793
    64396794                foreach ( $p as $para ) {
    6440                         if ( strpos($para, $pagelinkedto) !== false ) { // it exists, but is it a link?
    6441                                 preg_match("|<a[^>]+?".$preg_target."[^>]*>([^>]+?)</a>|", $para, $context);
     6795                        if ( strpos( $para, $pagelinkedto ) !== false ) { // it exists, but is it a link?
     6796                                preg_match( '|<a[^>]+?' . $preg_target . '[^>]*>([^>]+?)</a>|', $para, $context );
    64426797
    64436798                                // If the URL isn't in a link context, keep looking
    6444                                 if ( empty($context) )
     6799                                if ( empty( $context ) ) {
    64456800                                        continue;
     6801                                }
    64466802
    64476803                                // We're going to use this fake tag to mark the context in a bit
    64486804                                // the marker is needed in case the link text appears more than once in the paragraph
    6449                                 $excerpt = preg_replace('|\</?wpcontext\>|', '', $para);
     6805                                $excerpt = preg_replace( '|\</?wpcontext\>|', '', $para );
    64506806
    64516807                                // prevent really long link text
    6452                                 if ( strlen($context[1]) > 100 )
    6453                                         $context[1] = substr($context[1], 0, 100) . '&#8230;';
    6454 
    6455                                 $marker = '<wpcontext>'.$context[1].'</wpcontext>';    // set up our marker
    6456                                 $excerpt= str_replace($context[0], $marker, $excerpt); // swap out the link for our marker
    6457                                 $excerpt = strip_tags($excerpt, '<wpcontext>');        // strip all tags but our context marker
    6458                                 $excerpt = trim($excerpt);
    6459                                 $preg_marker = preg_quote($marker, '|');
    6460                                 $excerpt = preg_replace("|.*?\s(.{0,100}$preg_marker.{0,100})\s.*|s", '$1', $excerpt);
    6461                                 $excerpt = strip_tags($excerpt); // YES, again, to remove the marker wrapper
     6808                                if ( strlen( $context[1] ) > 100 ) {
     6809                                        $context[1] = substr( $context[1], 0, 100 ) . '&#8230;';
     6810                                }
     6811
     6812                                $marker      = '<wpcontext>' . $context[1] . '</wpcontext>';    // set up our marker
     6813                                $excerpt     = str_replace( $context[0], $marker, $excerpt ); // swap out the link for our marker
     6814                                $excerpt     = strip_tags( $excerpt, '<wpcontext>' );        // strip all tags but our context marker
     6815                                $excerpt     = trim( $excerpt );
     6816                                $preg_marker = preg_quote( $marker, '|' );
     6817                                $excerpt     = preg_replace( "|.*?\s(.{0,100}$preg_marker.{0,100})\s.*|s", '$1', $excerpt );
     6818                                $excerpt     = strip_tags( $excerpt ); // YES, again, to remove the marker wrapper
    64626819                                break;
    64636820                        }
    64646821                }
    64656822
    6466                 if ( empty($context) ) // Link to target not found
     6823                if ( empty( $context ) ) { // Link to target not found
    64676824                        return $this->pingback_error( 17, __( 'The source URL does not contain a link to the target URL, and so cannot be used as a source.' ) );
    6468 
    6469                 $pagelinkedfrom = str_replace('&', '&amp;', $pagelinkedfrom);
    6470 
    6471                 $context = '[&#8230;] ' . esc_html( $excerpt ) . ' [&#8230;]';
     6825                }
     6826
     6827                $pagelinkedfrom = str_replace( '&', '&amp;', $pagelinkedfrom );
     6828
     6829                $context        = '[&#8230;] ' . esc_html( $excerpt ) . ' [&#8230;]';
    64726830                $pagelinkedfrom = $this->escape( $pagelinkedfrom );
    64736831
    6474                 $comment_post_ID = (int) $post_ID;
    6475                 $comment_author = $title;
     6832                $comment_post_ID      = (int) $post_ID;
     6833                $comment_author       = $title;
    64766834                $comment_author_email = '';
    6477                 $this->escape($comment_author);
     6835                $this->escape( $comment_author );
    64786836                $comment_author_url = $pagelinkedfrom;
    6479                 $comment_content = $context;
    6480                 $this->escape($comment_content);
     6837                $comment_content    = $context;
     6838                $this->escape( $comment_content );
    64816839                $comment_type = 'pingback';
    64826840
     
    64866844                );
    64876845
    6488                 $comment_ID = wp_new_comment($commentdata);
     6846                $comment_ID = wp_new_comment( $commentdata );
    64896847
    64906848                if ( is_wp_error( $comment_ID ) ) {
     
    65256883                $url = $this->escape( $url );
    65266884
    6527                 $post_ID = url_to_postid($url);
    6528                 if ( !$post_ID ) {
     6885                $post_ID = url_to_postid( $url );
     6886                if ( ! $post_ID ) {
    65296887                        // We aren't sure that the resource is available and/or pingback enabled
    6530                         return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn&#8217;t exist, or it is not a pingback-enabled resource.' ) );
    6531                 }
    6532 
    6533                 $actual_post = get_post($post_ID, ARRAY_A);
    6534 
    6535                 if ( !$actual_post ) {
     6888                        return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn&#8217;t exist, or it is not a pingback-enabled resource.' ) );
     6889                }
     6890
     6891                $actual_post = get_post( $post_ID, ARRAY_A );
     6892
     6893                if ( ! $actual_post ) {
    65366894                        // No such post = resource not found
    6537                         return $this->pingback_error( 32, __('The specified target URL does not exist.' ) );
    6538                 }
    6539 
    6540                 $comments = $wpdb->get_results( $wpdb->prepare("SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID) );
    6541 
    6542                 if ( !$comments )
     6895                        return $this->pingback_error( 32, __( 'The specified target URL does not exist.' ) );
     6896                }
     6897
     6898                $comments = $wpdb->get_results( $wpdb->prepare( "SELECT comment_author_url, comment_content, comment_author_IP, comment_type FROM $wpdb->comments WHERE comment_post_ID = %d", $post_ID ) );
     6899
     6900                if ( ! $comments ) {
    65436901                        return array();
     6902                }
    65446903
    65456904                $pingbacks = array();
    65466905                foreach ( $comments as $comment ) {
    6547                         if ( 'pingback' == $comment->comment_type )
     6906                        if ( 'pingback' == $comment->comment_type ) {
    65486907                                $pingbacks[] = $comment->comment_author_url;
     6908                        }
    65496909                }
    65506910
Note: See TracChangeset for help on using the changeset viewer.