~canonical-sysadmins/wordpress/4.8.3

« back to all changes in this revision

Viewing changes to wp-includes/class-wp-xmlrpc-server.php

  • Committer: Ryan Finnie
  • Date: 2015-08-31 16:09:47 UTC
  • mfrom: (1.1.9 upstream)
  • Revision ID: ryan.finnie@canonical.com-20150831160947-1h6rfxby9z1ec62u
Merge WP4.3 from upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 */
23
23
class wp_xmlrpc_server extends IXR_Server {
24
24
        /**
 
25
         * Methods.
 
26
         *
 
27
         * @access public
25
28
         * @var array
26
29
         */
27
30
        public $methods;
 
31
 
28
32
        /**
 
33
         * Blog options.
 
34
         *
 
35
         * @access public
29
36
         * @var array
30
37
         */
31
38
        public $blog_options;
 
39
 
32
40
        /**
 
41
         * IXR_Error instance.
 
42
         *
 
43
         * @access public
33
44
         * @var IXR_Error
34
45
         */
35
46
        public $error;
 
47
 
36
48
        /**
37
49
         * Register all of the XMLRPC methods that XMLRPC server understands.
38
50
         *
158
170
         *
159
171
         * @param callable $name      Method to call.
160
172
         * @param array    $arguments Arguments to pass when calling.
161
 
         * @return mixed|bool Return value of the callback, false otherwise.
 
173
         * @return array|IXR_Error|false Return value of the callback, false otherwise.
162
174
         */
163
175
        public function __call( $name, $arguments ) {
164
176
                if ( '_multisite_getUsersBlogs' === $name ) {
167
179
                return false;
168
180
        }
169
181
 
 
182
        /**
 
183
         * @access public
 
184
         */
170
185
        public function serve_request() {
171
186
                $this->IXR_Server($this->methods);
172
187
        }
176
191
         *
177
192
         * @since 1.5.0
178
193
         *
179
 
         * @param array $args Method Parameters.
180
 
         * @return string
 
194
         * @return string Hello string response.
181
195
         */
182
 
        public function sayHello($args) {
 
196
        public function sayHello() {
183
197
                return 'Hello!';
184
198
        }
185
199
 
188
202
         *
189
203
         * @since 1.5.0
190
204
         *
191
 
         * @param array $args Method Parameters.
192
 
         * @return int
 
205
         * @param array  $args {
 
206
         *     Method arguments. Note: arguments must be ordered as documented.
 
207
         *
 
208
         *     @type int $number1 A number to add.
 
209
         *     @type int $number2 A second number to add.
 
210
         * }
 
211
         * @return int Sum of the two given numbers.
193
212
         */
194
 
        public function addTwoNumbers($args) {
 
213
        public function addTwoNumbers( $args ) {
195
214
                $number1 = $args[0];
196
215
                $number2 = $args[1];
197
216
                return $number1 + $number2;
275
294
         * @since 1.5.2
276
295
         *
277
296
         * @param string|array $data Escape single string or array of strings.
278
 
         * @return string|array Type matches $data and sanitized for the database.
 
297
         * @return string|void Returns with string is passed, alters by-reference
 
298
         *                     when array is passed.
279
299
         */
280
300
        public function escape( &$data ) {
281
301
                if ( ! is_array( $data ) )
351
371
        /**
352
372
         * Set up blog options property.
353
373
         *
354
 
         * Passes property through 'xmlrpc_blog_options' filter.
 
374
         * Passes property through {@see 'xmlrpc_blog_options'} filter.
355
375
         *
356
376
         * @since 2.6.0
 
377
         *
 
378
         * @global string $wp_version
357
379
         */
358
380
        public function initialise_blog_option_info() {
359
381
                global $wp_version;
493
515
                                'option'        => 'default_comment_status'
494
516
                        ),
495
517
                        'default_ping_status' => array(
496
 
                                'desc'          => __( 'Allow link notifications from other blogs (pingbacks and trackbacks)' ),
 
518
                                'desc'          => __( 'Allow link notifications from other blogs (pingbacks and trackbacks) on new articles' ),
497
519
                                'readonly'      => false,
498
520
                                'option'        => 'default_ping_status'
499
521
                        )
514
536
         *
515
537
         * @since 2.6.0
516
538
         *
517
 
         * @param array $args Method parameters. Contains:
518
 
         *  - username
519
 
         *  - password
 
539
         * @param array $args {
 
540
         *     Method arguments. Note: arguments must be ordered as documented.
 
541
         *
 
542
         *     @type string $username Username.
 
543
         *     @type string $password Password.
 
544
         * }
520
545
         * @return array|IXR_Error Array contains:
521
546
         *  - 'isAdmin'
522
547
         *  - 'url'
548
573
                 *
549
574
                 * @since 2.5.0
550
575
                 *
551
 
                 * @param method $name The method name.
 
576
                 * @param string $name The method name.
552
577
                 */
553
578
                do_action( 'xmlrpc_call', 'wp.getUsersBlogs' );
554
579
 
556
581
                $struct = array();
557
582
 
558
583
                foreach ( $blogs as $blog ) {
559
 
                        // Don't include blogs that aren't hosted at this site
 
584
                        // Don't include blogs that aren't hosted at this site.
560
585
                        if ( $blog->site_id != get_current_site()->id )
561
586
                                continue;
562
587
 
584
609
         * Checks if the method received at least the minimum number of arguments.
585
610
         *
586
611
         * @since 3.4.0
 
612
         * @access protected
587
613
         *
588
614
         * @param string|array $args Sanitize single string or array of strings.
589
 
         * @param int $count Minimum number of arguments.
590
 
         * @return boolean if $args contains at least $count arguments.
 
615
         * @param int $count         Minimum number of arguments.
 
616
         * @return bool if `$args` contains at least $count arguments.
591
617
         */
592
618
        protected function minimum_args( $args, $count ) {
593
619
                if ( count( $args ) < $count ) {
603
629
         *
604
630
         * @access protected
605
631
         *
606
 
         * @param object $taxonomy The unprepared taxonomy data
607
 
         * @param array $fields The subset of taxonomy fields to return
608
 
         * @return array The prepared taxonomy data
 
632
         * @param object $taxonomy The unprepared taxonomy data.
 
633
         * @param array $fields    The subset of taxonomy fields to return.
 
634
         * @return array The prepared taxonomy data.
609
635
         */
610
636
        protected function _prepare_taxonomy( $taxonomy, $fields ) {
611
637
                $_taxonomy = array(
646
672
         *
647
673
         * @access protected
648
674
         *
649
 
         * @param array|object $term The unprepared term data
650
 
         * @return array The prepared term data
 
675
         * @param array|object $term The unprepared term data.
 
676
         * @return array The prepared term data.
651
677
         */
652
678
        protected function _prepare_term( $term ) {
653
679
                $_term = $term;
654
 
                if ( ! is_array( $_term) )
 
680
                if ( ! is_array( $_term ) )
655
681
                        $_term = get_object_vars( $_term );
656
682
 
657
683
                // For integers which may be larger than XML-RPC supports ensure we return strings.
679
705
         *
680
706
         * @access protected
681
707
         *
682
 
         * @param string $date
683
 
         * @return IXR_Date
 
708
         * @param string $date Date string to convert.
 
709
         * @return IXR_Date IXR_Date object.
684
710
         */
685
711
        protected function _convert_date( $date ) {
686
712
                if ( $date === '0000-00-00 00:00:00' ) {
694
720
         *
695
721
         * @access protected
696
722
         *
697
 
         * @param string $date_gmt
698
 
         * @param string $date
699
 
         * @return IXR_Date
 
723
         * @param string $date_gmt WordPress GMT date string.
 
724
         * @param string $date     Date string.
 
725
         * @return IXR_Date IXR_Date object.
700
726
         */
701
727
        protected function _convert_date_gmt( $date_gmt, $date ) {
702
728
                if ( $date !== '0000-00-00 00:00:00' && $date_gmt === '0000-00-00 00:00:00' ) {
710
736
         *
711
737
         * @access protected
712
738
         *
713
 
         * @param array $post The unprepared post data
714
 
         * @param array $fields The subset of post type fields to return
715
 
         * @return array The prepared post data
 
739
         * @param array $post   The unprepared post data.
 
740
         * @param array $fields The subset of post type fields to return.
 
741
         * @return array The prepared post data.
716
742
         */
717
743
        protected function _prepare_post( $post, $fields ) {
718
 
                // holds the data for this post. built up based on $fields
 
744
                // Holds the data for this post. built up based on $fields.
719
745
                $_post = array( 'post_id' => strval( $post['ID'] ) );
720
746
 
721
 
                // prepare common post fields
 
747
                // Prepare common post fields.
722
748
                $post_fields = array(
723
749
                        'post_title'        => $post['post_title'],
724
750
                        'post_date'         => $this->_convert_date( $post['post_date'] ),
742
768
                        'sticky'            => ( $post['post_type'] === 'post' && is_sticky( $post['ID'] ) ),
743
769
                );
744
770
 
745
 
                // Thumbnail
 
771
                // Thumbnail.
746
772
                $post_fields['post_thumbnail'] = array();
747
773
                $thumbnail_id = get_post_thumbnail_id( $post['ID'] );
748
774
                if ( $thumbnail_id ) {
750
776
                        $post_fields['post_thumbnail'] = $this->_prepare_media_item( get_post( $thumbnail_id ), $thumbnail_size );
751
777
                }
752
778
 
753
 
                // Consider future posts as published
 
779
                // Consider future posts as published.
754
780
                if ( $post_fields['post_status'] === 'future' )
755
781
                        $post_fields['post_status'] = 'publish';
756
782
 
757
 
                // Fill in blank post format
 
783
                // Fill in blank post format.
758
784
                $post_fields['post_format'] = get_post_format( $post['ID'] );
759
785
                if ( empty( $post_fields['post_format'] ) )
760
786
                        $post_fields['post_format'] = 'standard';
761
787
 
762
 
                // Merge requested $post_fields fields into $_post
 
788
                // Merge requested $post_fields fields into $_post.
763
789
                if ( in_array( 'post', $fields ) ) {
764
790
                        $_post = array_merge( $_post, $post_fields );
765
791
                } else {
809
835
         *
810
836
         * @access protected
811
837
         *
812
 
         * @param object $post_type Post type object
813
 
         * @param array $fields The subset of post fields to return
814
 
         * @return array The prepared post type data
 
838
         * @param object $post_type Post type object.
 
839
         * @param array  $fields    The subset of post fields to return.
 
840
         * @return array The prepared post type data.
815
841
         */
816
842
        protected function _prepare_post_type( $post_type, $fields ) {
817
843
                $_post_type = array(
859
885
         *
860
886
         * @access protected
861
887
         *
862
 
         * @param object $media_item The unprepared media item data
863
 
         * @param string $thumbnail_size The image size to use for the thumbnail URL
864
 
         * @return array The prepared media item data
 
888
         * @param object $media_item     The unprepared media item data.
 
889
         * @param string $thumbnail_size The image size to use for the thumbnail URL.
 
890
         * @return array The prepared media item data.
865
891
         */
866
892
        protected function _prepare_media_item( $media_item, $thumbnail_size = 'thumbnail' ) {
867
893
                $_media_item = array(
898
924
         *
899
925
         * @access protected
900
926
         *
901
 
         * @param object $page The unprepared page data
902
 
         * @return array The prepared page data
 
927
         * @param object $page The unprepared page data.
 
928
         * @return array The prepared page data.
903
929
         */
904
930
        protected function _prepare_page( $page ) {
905
931
                // Get all of the page content and link.
979
1005
         *
980
1006
         * @access protected
981
1007
         *
982
 
         * @param object $comment The unprepared comment data
983
 
         * @return array The prepared comment data
 
1008
         * @param object $comment The unprepared comment data.
 
1009
         * @return array The prepared comment data.
984
1010
         */
985
1011
        protected function _prepare_comment( $comment ) {
986
1012
                // Format page date.
1028
1054
         *
1029
1055
         * @access protected
1030
1056
         *
1031
 
         * @param WP_User $user The unprepared user object
1032
 
         * @param array $fields The subset of user fields to return
1033
 
         * @return array The prepared user data
 
1057
         * @param WP_User $user   The unprepared user object.
 
1058
         * @param array   $fields The subset of user fields to return.
 
1059
         * @return array The prepared user data.
1034
1060
         */
1035
1061
        protected function _prepare_user( $user, $fields ) {
1036
1062
                $_user = array( 'user_id' => strval( $user->ID ) );
1077
1103
         *
1078
1104
         * @since 3.4.0
1079
1105
         *
1080
 
         * @param array $args Method parameters. Contains:
1081
 
         *  - int     $blog_id (unused)
1082
 
         *  - string  $username
1083
 
         *  - string  $password
1084
 
         *  - array   $content_struct
1085
 
         *      $content_struct can contain:
1086
 
         *      - post_type (default: 'post')
1087
 
         *      - post_status (default: 'draft')
1088
 
         *      - post_title
1089
 
         *      - post_author
1090
 
         *      - post_excerpt
1091
 
         *      - post_content
1092
 
         *      - post_date_gmt | post_date
1093
 
         *      - post_format
1094
 
         *      - post_password
1095
 
         *      - comment_status - can be 'open' | 'closed'
1096
 
         *      - ping_status - can be 'open' | 'closed'
1097
 
         *      - sticky
1098
 
         *      - post_thumbnail - ID of a media item to use as the post thumbnail/featured image
1099
 
         *      - custom_fields - array, with each element containing 'key' and 'value'
1100
 
         *      - terms - array, with taxonomy names as keys and arrays of term IDs as values
1101
 
         *      - terms_names - array, with taxonomy names as keys and arrays of term names as values
1102
 
         *      - enclosure
1103
 
         *      - any other fields supported by wp_insert_post()
1104
 
         * @return string|IXR_Error post_id
 
1106
         * @link http://en.wikipedia.org/wiki/RSS_enclosure for information on RSS enclosures.
 
1107
         *
 
1108
         * @param array  $args {
 
1109
         *     Method arguments. Note: top-level arguments must be ordered as documented.
 
1110
         *
 
1111
         *     @type int    $blog_id        Blog ID (unused).
 
1112
         *     @type string $username       Username.
 
1113
         *     @type string $password       Password.
 
1114
         *     @type array  $content_struct {
 
1115
         *         Content struct for adding a new post. See wp_insert_post() for information on
 
1116
         *         additional post fields
 
1117
         *
 
1118
         *         @type string $post_type      Post type. Default 'post'.
 
1119
         *         @type string $post_status    Post status. Default 'draft'
 
1120
         *         @type string $post_title     Post title.
 
1121
         *         @type int    $post_author    Post author ID.
 
1122
         *         @type string $post_excerpt   Post excerpt.
 
1123
         *         @type string $post_content   Post content.
 
1124
         *         @type string $post_date_gmt  Post date in GMT.
 
1125
         *         @type string $post_date      Post date.
 
1126
         *         @type string $post_password  Post password (20-character limit).
 
1127
         *         @type string $comment_status Post comment enabled status. Accepts 'open' or 'closed'.
 
1128
         *         @type string $ping_status    Post ping status. Accepts 'open' or 'closed'.
 
1129
         *         @type bool   $sticky         Whether the post should be sticky. Automatically false if
 
1130
         *                                      `$post_status` is 'private'.
 
1131
         *         @type int    $post_thumbnail ID of an image to use as the post thumbnail/featured image.
 
1132
         *         @type array  $custom_fields  Array of meta key/value pairs to add to the post.
 
1133
         *         @type array  $terms          Associative array with taxonomy names as keys and arrays
 
1134
         *                                      of term IDs as values.
 
1135
         *         @type array  $terms_names    Associative array with taxonomy names as keys and arrays
 
1136
         *                                      of term names as values.
 
1137
         *         @type array  $enclosure      {
 
1138
         *             Array of feed enclosure data to add to post meta.
 
1139
         *
 
1140
         *             @type string $url    URL for the feed enclosure.
 
1141
         *             @type int    $length Size in bytes of the enclosure.
 
1142
         *             @type string $type   Mime-type for the enclosure.
 
1143
         *         }
 
1144
         *     }
 
1145
         * }
 
1146
         * @return int|IXR_Error Post ID on success, IXR_Error instance otherwise.
1105
1147
         */
1106
1148
        public function wp_newPost( $args ) {
1107
1149
                if ( ! $this->minimum_args( $args, 4 ) )
1151
1193
        }
1152
1194
 
1153
1195
        /**
1154
 
         * Helper method for wp_newPost and wp_editPost, containing shared logic.
 
1196
         * Encapsulate the logic for sticking a post
 
1197
         * and determining if the user has permission to do so
 
1198
         *
 
1199
         * @since 4.3.0
 
1200
         * @access private
 
1201
         *
 
1202
         * @param array $post_data
 
1203
         * @param bool  $update
 
1204
         * @return void|IXR_Error
 
1205
         */
 
1206
        private function _toggle_sticky( $post_data, $update = false ) {
 
1207
                $post_type = get_post_type_object( $post_data['post_type'] );
 
1208
 
 
1209
                // Private and password-protected posts cannot be stickied.
 
1210
                if ( 'private' === $post_data['post_status'] || ! empty( $post_data['post_password'] ) ) {
 
1211
                        // Error if the client tried to stick the post, otherwise, silently unstick.
 
1212
                        if ( ! empty( $post_data['sticky'] ) ) {
 
1213
                                return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
 
1214
                        }
 
1215
 
 
1216
                        if ( $update ) {
 
1217
                                unstick_post( $post_data['ID'] );
 
1218
                        }
 
1219
                } elseif ( isset( $post_data['sticky'] ) )  {
 
1220
                        if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) {
 
1221
                                return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) );
 
1222
                        }
 
1223
 
 
1224
                        $sticky = wp_validate_boolean( $post_data['sticky'] );
 
1225
                        if ( $sticky ) {
 
1226
                                stick_post( $post_data['ID'] );
 
1227
                        } else {
 
1228
                                unstick_post( $post_data['ID'] );
 
1229
                        }
 
1230
                }
 
1231
        }
 
1232
 
 
1233
        /**
 
1234
         * Helper method for wp_newPost() and wp_editPost(), containing shared logic.
1155
1235
         *
1156
1236
         * @since 3.4.0
1157
 
         * @uses wp_insert_post()
1158
 
         *
1159
 
         * @param WP_User $user The post author if post_author isn't set in $content_struct.
 
1237
         * @access protected
 
1238
         *
 
1239
         * @see wp_insert_post()
 
1240
         *
 
1241
         * @param WP_User         $user           The post author if post_author isn't set in $content_struct.
1160
1242
         * @param array|IXR_Error $content_struct Post data to insert.
 
1243
         * @return IXR_Error|string
1161
1244
         */
1162
1245
        protected function _insert_post( $user, $content_struct ) {
1163
1246
                $defaults = array( 'post_status' => 'draft', 'post_type' => 'post', 'post_author' => 0,
1224
1307
                if ( isset( $post_data['ping_status'] ) && $post_data['ping_status'] != 'open' && $post_data['ping_status'] != 'closed' )
1225
1308
                        unset( $post_data['ping_status'] );
1226
1309
 
1227
 
                // Do some timestamp voodoo
 
1310
                // Do some timestamp voodoo.
1228
1311
                if ( ! empty( $post_data['post_date_gmt'] ) ) {
1229
 
                        // We know this is supposed to be GMT, so we're going to slap that Z on there by force
 
1312
                        // We know this is supposed to be GMT, so we're going to slap that Z on there by force.
1230
1313
                        $dateCreated = rtrim( $post_data['post_date_gmt']->getIso(), 'Z' ) . 'Z';
1231
1314
                } elseif ( ! empty( $post_data['post_date'] ) ) {
1232
1315
                        $dateCreated = $post_data['post_date']->getIso();
1242
1325
                $post_ID = $post_data['ID'];
1243
1326
 
1244
1327
                if ( $post_data['post_type'] == 'post' ) {
1245
 
                        // Private and password-protected posts cannot be stickied.
1246
 
                        if ( $post_data['post_status'] == 'private' || ! empty( $post_data['post_password'] ) ) {
1247
 
                                // Error if the client tried to stick the post, otherwise, silently unstick.
1248
 
                                if ( ! empty( $post_data['sticky'] ) )
1249
 
                                        return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) );
1250
 
                                if ( $update )
1251
 
                                        unstick_post( $post_ID );
1252
 
                        } elseif ( isset( $post_data['sticky'] ) )  {
1253
 
                                if ( ! current_user_can( $post_type->cap->edit_others_posts ) )
1254
 
                                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to stick this post.' ) );
1255
 
                                if ( $post_data['sticky'] )
1256
 
                                        stick_post( $post_ID );
1257
 
                                else
1258
 
                                        unstick_post( $post_ID );
 
1328
                        $error = $this->_toggle_sticky( $post_data, $update );
 
1329
                        if ( $error ) {
 
1330
                                return $error;
1259
1331
                        }
1260
1332
                }
1261
1333
 
1262
1334
                if ( isset( $post_data['post_thumbnail'] ) ) {
1263
 
                        // empty value deletes, non-empty value adds/updates
 
1335
                        // empty value deletes, non-empty value adds/updates.
1264
1336
                        if ( ! $post_data['post_thumbnail'] )
1265
1337
                                delete_post_thumbnail( $post_ID );
1266
1338
                        elseif ( ! get_post( absint( $post_data['post_thumbnail'] ) ) )
1275
1347
                if ( isset( $post_data['terms'] ) || isset( $post_data['terms_names'] ) ) {
1276
1348
                        $post_type_taxonomies = get_object_taxonomies( $post_data['post_type'], 'objects' );
1277
1349
 
1278
 
                        // accumulate term IDs from terms and terms_names
 
1350
                        // Accumulate term IDs from terms and terms_names.
1279
1351
                        $terms = array();
1280
1352
 
1281
 
                        // first validate the terms specified by ID
 
1353
                        // First validate the terms specified by ID.
1282
1354
                        if ( isset( $post_data['terms'] ) && is_array( $post_data['terms'] ) ) {
1283
1355
                                $taxonomies = array_keys( $post_data['terms'] );
1284
1356
 
1285
 
                                // validating term ids
 
1357
                                // Validating term ids.
1286
1358
                                foreach ( $taxonomies as $taxonomy ) {
1287
1359
                                        if ( ! array_key_exists( $taxonomy , $post_type_taxonomies ) )
1288
1360
                                                return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) );
1303
1375
                                }
1304
1376
                        }
1305
1377
 
1306
 
                        // now validate terms specified by name
 
1378
                        // Now validate terms specified by name.
1307
1379
                        if ( isset( $post_data['terms_names'] ) && is_array( $post_data['terms_names'] ) ) {
1308
1380
                                $taxonomies = array_keys( $post_data['terms_names'] );
1309
1381
 
1314
1386
                                        if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->assign_terms ) )
1315
1387
                                                return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) );
1316
1388
 
1317
 
                                        // for hierarchical taxonomies, we can't assign a term when multiple terms in the hierarchy share the same name
 
1389
                                        /*
 
1390
                                         * For hierarchical taxonomies, we can't assign a term when multiple terms
 
1391
                                         * in the hierarchy share the same name.
 
1392
                                         */
1318
1393
                                        $ambiguous_terms = array();
1319
1394
                                        if ( is_taxonomy_hierarchical( $taxonomy ) ) {
1320
1395
                                                $tax_term_names = get_terms( $taxonomy, array( 'fields' => 'names', 'hide_empty' => false ) );
1321
1396
 
1322
 
                                                // count the number of terms with the same name
 
1397
                                                // Count the number of terms with the same name.
1323
1398
                                                $tax_term_names_count = array_count_values( $tax_term_names );
1324
1399
 
1325
 
                                                // filter out non-ambiguous term names
 
1400
                                                // Filter out non-ambiguous term names.
1326
1401
                                                $ambiguous_tax_term_counts = array_filter( $tax_term_names_count, array( $this, '_is_greater_than_one') );
1327
1402
 
1328
1403
                                                $ambiguous_terms = array_keys( $ambiguous_tax_term_counts );
1336
1411
                                                $term = get_term_by( 'name', $term_name, $taxonomy );
1337
1412
 
1338
1413
                                                if ( ! $term ) {
1339
 
                                                        // term doesn't exist, so check that the user is allowed to create new terms
 
1414
                                                        // Term doesn't exist, so check that the user is allowed to create new terms.
1340
1415
                                                        if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->edit_terms ) )
1341
1416
                                                                return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a term to one of the given taxonomies.' ) );
1342
1417
 
1343
 
                                                        // create the new term
 
1418
                                                        // Create the new term.
1344
1419
                                                        $term_info = wp_insert_term( $term_name, $taxonomy );
1345
1420
                                                        if ( is_wp_error( $term_info ) )
1346
1421
                                                                return new IXR_Error( 500, $term_info->get_error_message() );
1356
1431
                        $post_data['tax_input'] = $terms;
1357
1432
                        unset( $post_data['terms'], $post_data['terms_names'] );
1358
1433
                } else {
1359
 
                        // do not allow direct submission of 'tax_input', clients must use 'terms' and/or 'terms_names'
 
1434
                        // Do not allow direct submission of 'tax_input', clients must use 'terms' and/or 'terms_names'.
1360
1435
                        unset( $post_data['tax_input'], $post_data['post_category'], $post_data['tags_input'] );
1361
1436
                }
1362
1437
 
1369
1444
                        unset( $post_data['post_format'] );
1370
1445
                }
1371
1446
 
1372
 
                // Handle enclosures
 
1447
                // Handle enclosures.
1373
1448
                $enclosure = isset( $post_data['enclosure'] ) ? $post_data['enclosure'] : null;
1374
1449
                $this->add_enclosure_if_new( $post_ID, $enclosure );
1375
1450
 
1403
1478
         *
1404
1479
         * @since 3.4.0
1405
1480
         *
1406
 
         * @param array $args Method parameters. Contains:
1407
 
         *  - int     $blog_id (unused)
1408
 
         *  - string  $username
1409
 
         *  - string  $password
1410
 
         *  - int     $post_id
1411
 
         *  - array   $content_struct
1412
 
         * @return bool|IXR_Error true on success
 
1481
         * @param array  $args {
 
1482
         *     Method arguments. Note: arguments must be ordered as documented.
 
1483
         *
 
1484
         *     @type int    $blog_id        Blog ID (unused).
 
1485
         *     @type string $username       Username.
 
1486
         *     @type string $password       Password.
 
1487
         *     @type int    $post_id        Post ID.
 
1488
         *     @type array  $content_struct Extra content arguments.
 
1489
         * }
 
1490
         * @return true|IXR_Error True on success, IXR_Error on failure.
1413
1491
         */
1414
1492
        public function wp_editPost( $args ) {
1415
1493
                if ( ! $this->minimum_args( $args, 5 ) )
1440
1518
                        }
1441
1519
                }
1442
1520
 
1443
 
                // convert the date field back to IXR form
 
1521
                // Convert the date field back to IXR form.
1444
1522
                $post['post_date'] = $this->_convert_date( $post['post_date'] );
1445
1523
 
1446
 
                // ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct,
1447
 
                // since _insert_post will ignore the non-GMT date if the GMT date is set
 
1524
                /*
 
1525
                 * Ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct,
 
1526
                 * since _insert_post() will ignore the non-GMT date if the GMT date is set.
 
1527
                 */
1448
1528
                if ( $post['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) )
1449
1529
                        unset( $post['post_date_gmt'] );
1450
1530
                else
1465
1545
         *
1466
1546
         * @since 3.4.0
1467
1547
         *
1468
 
         * @uses wp_delete_post()
1469
 
         * @param array $args Method parameters. Contains:
1470
 
         *  - int     $blog_id (unused)
1471
 
         *  - string  $username
1472
 
         *  - string  $password
1473
 
         *  - int     $post_id
1474
 
         * @return bool|IXR_Error true on success
 
1548
         * @see wp_delete_post()
 
1549
         *
 
1550
         * @param array  $args {
 
1551
         *     Method arguments. Note: arguments must be ordered as documented.
 
1552
         *
 
1553
         *     @type int    $blog_id  Blog ID (unused).
 
1554
         *     @type string $username Username.
 
1555
         *     @type string $password Password.
 
1556
         *     @type int    $post_id  Post ID.
 
1557
         * }
 
1558
         * @return true|IXR_Error True on success, IXR_Error instance on failure.
1475
1559
         */
1476
1560
        public function wp_deletePost( $args ) {
1477
1561
                if ( ! $this->minimum_args( $args, 4 ) )
1518
1602
         * groups are 'post' (all basic fields), 'taxonomies', 'custom_fields',
1519
1603
         * and 'enclosure'.
1520
1604
         *
1521
 
         * @uses get_post()
1522
 
         * @param array $args Method parameters. Contains:
1523
 
         *  - int     $blog_id (unused)
1524
 
         *  - string  $username
1525
 
         *  - string  $password
1526
 
         *  - int     $post_id
1527
 
         *  - array   $fields optional
 
1605
         * @see get_post()
 
1606
         *
 
1607
         * @param array $args {
 
1608
         *     Method arguments. Note: arguments must be ordered as documented.
 
1609
         *
 
1610
         *     @type int    $blog_id  Blog ID (unused).
 
1611
         *     @type string $username Username.
 
1612
         *     @type string $password Password.
 
1613
         *     @type int    $post_id  Post ID.
 
1614
         *     @type array  $fields   The subset of post type fields to return.
 
1615
         * }
1528
1616
         * @return array|IXR_Error Array contains (based on $fields parameter):
1529
1617
         *  - 'post_id'
1530
1618
         *  - 'post_title'
1555
1643
 
1556
1644
                $this->escape( $args );
1557
1645
 
1558
 
                $username           = $args[1];
1559
 
                $password           = $args[2];
1560
 
                $post_id            = (int) $args[3];
 
1646
                $username = $args[1];
 
1647
                $password = $args[2];
 
1648
                $post_id  = (int) $args[3];
1561
1649
 
1562
1650
                if ( isset( $args[4] ) ) {
1563
1651
                        $fields = $args[4];
1567
1655
                         *
1568
1656
                         * @since 3.4.0
1569
1657
                         *
1570
 
                         * @param array $fields  Array of post fields.
 
1658
                         * @param array  $fields Array of post fields. Default array contains 'post', 'terms', and 'custom_fields'.
1571
1659
                         * @param string $method Method name.
1572
1660
                         */
1573
1661
                        $fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPost' );
1595
1683
         *
1596
1684
         * @since 3.4.0
1597
1685
         *
1598
 
         * The optional $filter parameter modifies the query used to retrieve posts.
1599
 
         * Accepted keys are 'post_type', 'post_status', 'number', 'offset',
1600
 
         * 'orderby', and 'order'.
1601
 
         *
1602
 
         * The optional $fields parameter specifies what fields will be included
1603
 
         * in the response array.
1604
 
         *
1605
 
         * @uses wp_get_recent_posts()
1606
 
         * @see wp_getPost() for more on $fields
1607
 
         * @see get_posts() for more on $filter values
1608
 
         *
1609
 
         * @param array $args Method parameters. Contains:
1610
 
         *  - int     $blog_id (unused)
1611
 
         *  - string  $username
1612
 
         *  - string  $password
1613
 
         *  - array   $filter optional
1614
 
         *  - array   $fields optional
 
1686
         * @see wp_get_recent_posts()
 
1687
         * @see wp_getPost() for more on `$fields`
 
1688
         * @see get_posts() for more on `$filter` values
 
1689
         *
 
1690
         * @param array $args {
 
1691
         *     Method arguments. Note: arguments must be ordered as documented.
 
1692
         *
 
1693
         *     @type int    $blog_id  Blog ID (unused).
 
1694
         *     @type string $username Username.
 
1695
         *     @type string $password Password.
 
1696
         *     @type array  $filter   Optional. Modifies the query used to retrieve posts. Accepts 'post_type',
 
1697
         *                            'post_status', 'number', 'offset', 'orderby', and 'order'.
 
1698
         *                            Default empty array.
 
1699
         *     @type array  $fields   Optional. The subset of post type fields to return in the response array.
 
1700
         * }
1615
1701
         * @return array|IXR_Error Array contains a collection of posts.
1616
1702
         */
1617
1703
        public function wp_getPosts( $args ) {
1620
1706
 
1621
1707
                $this->escape( $args );
1622
1708
 
1623
 
                $username   = $args[1];
1624
 
                $password   = $args[2];
1625
 
                $filter     = isset( $args[3] ) ? $args[3] : array();
 
1709
                $username = $args[1];
 
1710
                $password = $args[2];
 
1711
                $filter   = isset( $args[3] ) ? $args[3] : array();
1626
1712
 
1627
1713
                if ( isset( $args[4] ) ) {
1628
1714
                        $fields = $args[4];
1677
1763
                if ( ! $posts_list )
1678
1764
                        return array();
1679
1765
 
1680
 
                // holds all the posts data
 
1766
                // Holds all the posts data.
1681
1767
                $struct = array();
1682
1768
 
1683
1769
                foreach ( $posts_list as $post ) {
1695
1781
         *
1696
1782
         * @since 3.4.0
1697
1783
         *
1698
 
         * @uses wp_insert_term()
1699
 
         * @param array $args Method parameters. Contains:
1700
 
         *  - int     $blog_id (unused)
1701
 
         *  - string  $username
1702
 
         *  - string  $password
1703
 
         *  - array   $content_struct
1704
 
         *      The $content_struct must contain:
1705
 
         *      - 'name'
1706
 
         *      - 'taxonomy'
1707
 
         *      Also, it can optionally contain:
1708
 
         *      - 'parent'
1709
 
         *      - 'description'
1710
 
         *      - 'slug'
1711
 
         * @return string|IXR_Error term_id
 
1784
         * @see wp_insert_term()
 
1785
         *
 
1786
         * @param array $args {
 
1787
         *     Method arguments. Note: arguments must be ordered as documented.
 
1788
         *
 
1789
         *     @type int    $blog_id        Blog ID (unused).
 
1790
         *     @type string $username       Username.
 
1791
         *     @type string $password       Password.
 
1792
         *     @type array  $content_struct Content struct for adding a new term. The struct must contain
 
1793
         *                                  the term 'name' and 'taxonomy'. Optional accepted values include
 
1794
         *                                  'parent', 'description', and 'slug'.
 
1795
         * }
 
1796
         * @return int|IXR_Error The term ID on success, or an IXR_Error object on failure.
1712
1797
         */
1713
1798
        public function wp_newTerm( $args ) {
1714
1799
                if ( ! $this->minimum_args( $args, 4 ) )
1716
1801
 
1717
1802
                $this->escape( $args );
1718
1803
 
1719
 
                $username           = $args[1];
1720
 
                $password           = $args[2];
1721
 
                $content_struct     = $args[3];
 
1804
                $username       = $args[1];
 
1805
                $password       = $args[2];
 
1806
                $content_struct = $args[3];
1722
1807
 
1723
1808
                if ( ! $user = $this->login( $username, $password ) )
1724
1809
                        return $this->error;
1781
1866
         *
1782
1867
         * @since 3.4.0
1783
1868
         *
1784
 
         * @uses wp_update_term()
1785
 
         * @param array $args Method parameters. Contains:
1786
 
         *  - int     $blog_id (unused)
1787
 
         *  - string  $username
1788
 
         *  - string  $password
1789
 
         *  - string  $term_id
1790
 
         *  - array   $content_struct
1791
 
         *      The $content_struct must contain:
1792
 
         *      - 'taxonomy'
1793
 
         *      Also, it can optionally contain:
1794
 
         *      - 'name'
1795
 
         *      - 'parent'
1796
 
         *      - 'description'
1797
 
         *      - 'slug'
1798
 
         * @return bool|IXR_Error True, on success.
 
1869
         * @see wp_update_term()
 
1870
         *
 
1871
         * @param array $args {
 
1872
         *     Method arguments. Note: arguments must be ordered as documented.
 
1873
         *
 
1874
         *     @type int    $blog_id        Blog ID (unused).
 
1875
         *     @type string $username       Username.
 
1876
         *     @type string $password       Password.
 
1877
         *     @type int    $term_id        Term ID.
 
1878
         *     @type array  $content_struct Content struct for editing a term. The struct must contain the
 
1879
         *                                  term ''taxonomy'. Optional accepted values include 'name', 'parent',
 
1880
         *                                  'description', and 'slug'.
 
1881
         * }
 
1882
         * @return true|IXR_Error True on success, IXR_Error instance on failure.
1799
1883
         */
1800
1884
        public function wp_editTerm( $args ) {
1801
1885
                if ( ! $this->minimum_args( $args, 5 ) )
1803
1887
 
1804
1888
                $this->escape( $args );
1805
1889
 
1806
 
                $username           = $args[1];
1807
 
                $password           = $args[2];
1808
 
                $term_id            = (int) $args[3];
1809
 
                $content_struct     = $args[4];
 
1890
                $username       = $args[1];
 
1891
                $password       = $args[2];
 
1892
                $term_id        = (int) $args[3];
 
1893
                $content_struct = $args[4];
1810
1894
 
1811
1895
                if ( ! $user = $this->login( $username, $password ) )
1812
1896
                        return $this->error;
1880
1964
         *
1881
1965
         * @since 3.4.0
1882
1966
         *
1883
 
         * @uses wp_delete_term()
1884
 
         * @param array $args Method parameters. Contains:
1885
 
         *  - int     $blog_id (unused)
1886
 
         *  - string  $username
1887
 
         *  - string  $password
1888
 
         *  - string  $taxnomy_name
1889
 
         *  - string     $term_id
1890
 
         * @return boolean|IXR_Error If it suceeded true else a reason why not
 
1967
         * @see wp_delete_term()
 
1968
         *
 
1969
         * @param array  $args {
 
1970
         *     Method arguments. Note: arguments must be ordered as documented.
 
1971
         *
 
1972
         *     @type int    $blog_id      Blog ID (unused).
 
1973
         *     @type string $username     Username.
 
1974
         *     @type string $password     Password.
 
1975
         *     @type string $taxnomy_name Taxonomy name.
 
1976
         *     @type int    $term_id      Term ID.
 
1977
         * }
 
1978
         * @return bool|IXR_Error True on success, IXR_Error instance on failure.
1891
1979
         */
1892
1980
        public function wp_deleteTerm( $args ) {
1893
1981
                if ( ! $this->minimum_args( $args, 5 ) )
1938
2026
         *
1939
2027
         * @since 3.4.0
1940
2028
         *
1941
 
         * @uses get_term()
1942
 
         * @param array $args Method parameters. Contains:
1943
 
         *  - int     $blog_id (unused)
1944
 
         *  - string  $username
1945
 
         *  - string  $password
1946
 
         *  - string  $taxonomy
1947
 
         *  - string  $term_id
1948
 
         * @return array|IXR_Error Array contains:
 
2029
         * @see get_term()
 
2030
         *
 
2031
         * @param array  $args {
 
2032
         *     Method arguments. Note: arguments must be ordered as documented.
 
2033
         *
 
2034
         *     @type int    $blog_id  Blog ID (unused).
 
2035
         *     @type string $username Username.
 
2036
         *     @type string $password Password.
 
2037
         *     @type string $taxnomy  Taxonomy name.
 
2038
         *     @type string $term_id  Term ID.
 
2039
         * }
 
2040
         * @return array|IXR_Error IXR_Error on failure, array on success, containing:
1949
2041
         *  - 'term_id'
1950
2042
         *  - 'name'
1951
2043
         *  - 'slug'
2000
2092
         * The optional $filter parameter modifies the query used to retrieve terms.
2001
2093
         * Accepted keys are 'number', 'offset', 'orderby', 'order', 'hide_empty', and 'search'.
2002
2094
         *
2003
 
         * @uses get_terms()
2004
 
         * @param array $args Method parameters. Contains:
2005
 
         *  - int     $blog_id (unused)
2006
 
         *  - string  $username
2007
 
         *  - string  $password
2008
 
         *  - string  $taxonomy
2009
 
         *  - array   $filter optional
2010
 
         * @return array|IXR_Error terms
 
2095
         * @see get_terms()
 
2096
         *
 
2097
         * @param array  $args {
 
2098
         *     Method arguments. Note: arguments must be ordered as documented.
 
2099
         *
 
2100
         *     @type int    $blog_id  Blog ID (unused).
 
2101
         *     @type string $username Username.
 
2102
         *     @type string $password Password.
 
2103
         *     @type string $taxnomy  Taxonomy name.
 
2104
         *     @type array  $filter   Optional. Modifies the query used to retrieve posts. Accepts 'number',
 
2105
         *                            'offset', 'orderby', 'order', 'hide_empty', and 'search'. Default empty array.
 
2106
         * }
 
2107
         * @return array|IXR_Error An associative array of terms data on success, IXR_Error instance otherwise.
2011
2108
         */
2012
2109
        public function wp_getTerms( $args ) {
2013
2110
                if ( ! $this->minimum_args( $args, 4 ) )
2076
2173
         *
2077
2174
         * @since 3.4.0
2078
2175
         *
2079
 
         * @uses get_taxonomy()
2080
 
         * @param array $args Method parameters. Contains:
2081
 
         *  - int     $blog_id (unused)
2082
 
         *  - string  $username
2083
 
         *  - string  $password
2084
 
         *  - string  $taxonomy
2085
 
         * @return array|IXR_Error (@see get_taxonomy())
 
2176
         * @see get_taxonomy()
 
2177
         *
 
2178
         * @param array  $args {
 
2179
         *     Method arguments. Note: arguments must be ordered as documented.
 
2180
         *
 
2181
         *     @type int    $blog_id  Blog ID (unused).
 
2182
         *     @type string $username Username.
 
2183
         *     @type string $password Password.
 
2184
         *     @type string $taxnomy  Taxonomy name.
 
2185
         *     @type array  $fields   Optional. Array of taxonomy fields to limit to in the return.
 
2186
         *                            Accepts 'labels', 'cap', 'menu', and 'object_type'.
 
2187
         *                            Default empty array.
 
2188
         * }
 
2189
         * @return array|IXR_Error An array of taxonomy data on success, IXR_Error instance otherwise.
2086
2190
         */
2087
2191
        public function wp_getTaxonomy( $args ) {
2088
2192
                if ( ! $this->minimum_args( $args, 4 ) )
2090
2194
 
2091
2195
                $this->escape( $args );
2092
2196
 
2093
 
                $username       = $args[1];
2094
 
                $password       = $args[2];
2095
 
                $taxonomy       = $args[3];
 
2197
                $username = $args[1];
 
2198
                $password = $args[2];
 
2199
                $taxonomy = $args[3];
2096
2200
 
2097
2201
                if ( isset( $args[4] ) ) {
2098
2202
                        $fields = $args[4];
2130
2234
         *
2131
2235
         * @since 3.4.0
2132
2236
         *
2133
 
         * @uses get_taxonomies()
2134
 
         * @param array $args Method parameters. Contains:
2135
 
         *  - int     $blog_id (unused)
2136
 
         *  - string  $username
2137
 
         *  - string  $password
2138
 
         * @return array taxonomies
 
2237
         * @see get_taxonomies()
 
2238
         *
 
2239
         * @param array  $args {
 
2240
         *     Method arguments. Note: arguments must be ordered as documented.
 
2241
         *
 
2242
         *     @type int    $blog_id  Blog ID (unused).
 
2243
         *     @type string $username Username.
 
2244
         *     @type string $password Password.
 
2245
         *     @type array  $filter   Optional. An array of arguments for retrieving taxonomies.
 
2246
         *     @type array  $fields   Optional. The subset of taxonomy fields to return.
 
2247
         * }
 
2248
         * @return array|IXR_Error An associative array of taxonomy data with returned fields determined
 
2249
         *                         by `$fields`, or an IXR_Error instance on failure.
2139
2250
         */
2140
2251
        public function wp_getTaxonomies( $args ) {
2141
2252
                if ( ! $this->minimum_args( $args, 3 ) )
2143
2254
 
2144
2255
                $this->escape( $args );
2145
2256
 
2146
 
                $username           = $args[1];
2147
 
                $password           = $args[2];
2148
 
                $filter             = isset( $args[3] ) ? $args[3] : array( 'public' => true );
 
2257
                $username = $args[1];
 
2258
                $password = $args[2];
 
2259
                $filter   = isset( $args[3] ) ? $args[3] : array( 'public' => true );
2149
2260
 
2150
2261
                if ( isset( $args[4] ) ) {
2151
2262
                        $fields = $args[4];
2188
2299
         * groups are 'basic' and 'all'.
2189
2300
         *
2190
2301
         * @uses get_userdata()
2191
 
         * @param array $args Method parameters. Contains:
2192
 
         *  - int     $blog_id (unused)
2193
 
         *  - string  $username
2194
 
         *  - string  $password
2195
 
         *  - int     $user_id
2196
 
         *  - array   $fields optional
 
2302
         *
 
2303
         * @param array  $args {
 
2304
         *     Method arguments. Note: arguments must be ordered as documented.
 
2305
         *
 
2306
         *     @type int    $blog_id (unused)
 
2307
         *     @type string $username
 
2308
         *     @type string $password
 
2309
         *     @type int    $user_id
 
2310
         *     @type array  $fields (optional)
 
2311
         * }
2197
2312
         * @return array|IXR_Error Array contains (based on $fields parameter):
2198
2313
         *  - 'user_id'
2199
2314
         *  - 'username'
2214
2329
 
2215
2330
                $this->escape( $args );
2216
2331
 
2217
 
                $username   = $args[1];
2218
 
                $password   = $args[2];
2219
 
                $user_id    = (int) $args[3];
 
2332
                $username = $args[1];
 
2333
                $password = $args[2];
 
2334
                $user_id  = (int) $args[3];
2220
2335
 
2221
2336
                if ( isset( $args[4] ) ) {
2222
2337
                        $fields = $args[4];
2244
2359
                $user_data = get_userdata( $user_id );
2245
2360
 
2246
2361
                if ( ! $user_data )
2247
 
                        return new IXR_Error( 404, __( 'Invalid user ID' ) );
 
2362
                        return new IXR_Error( 404, __( 'Invalid user ID.' ) );
2248
2363
 
2249
2364
                return $this->_prepare_user( $user_data, $fields );
2250
2365
        }
2262
2377
         * @uses get_users()
2263
2378
         * @see wp_getUser() for more on $fields and return values
2264
2379
         *
2265
 
         * @param array $args Method parameters. Contains:
2266
 
         *  - int     $blog_id (unused)
2267
 
         *  - string  $username
2268
 
         *  - string  $password
2269
 
         *  - array   $filter optional
2270
 
         *  - array   $fields optional
 
2380
         * @param array  $args {
 
2381
         *     Method arguments. Note: arguments must be ordered as documented.
 
2382
         *
 
2383
         *     @type int    $blog_id (unused)
 
2384
         *     @type string $username
 
2385
         *     @type string $password
 
2386
         *     @type array  $filter (optional)
 
2387
         *     @type array  $fields (optional)
 
2388
         * }
2271
2389
         * @return array|IXR_Error users data
2272
2390
         */
2273
2391
        public function wp_getUsers( $args ) {
2276
2394
 
2277
2395
                $this->escape( $args );
2278
2396
 
2279
 
                $username   = $args[1];
2280
 
                $password   = $args[2];
2281
 
                $filter     = isset( $args[3] ) ? $args[3] : array();
 
2397
                $username = $args[1];
 
2398
                $password = $args[2];
 
2399
                $filter   = isset( $args[3] ) ? $args[3] : array();
2282
2400
 
2283
2401
                if ( isset( $args[4] ) ) {
2284
2402
                        $fields = $args[4];
2333
2451
         * Retrieve information about the requesting user.
2334
2452
         *
2335
2453
         * @uses get_userdata()
2336
 
         * @param array $args Method parameters. Contains:
2337
 
         *  - int     $blog_id (unused)
2338
 
         *  - string  $username
2339
 
         *  - string  $password
2340
 
         *  - array   $fields optional
 
2454
         *
 
2455
         * @param array  $args {
 
2456
         *     Method arguments. Note: arguments must be ordered as documented.
 
2457
         *
 
2458
         *     @type int    $blog_id (unused)
 
2459
         *     @type string $username
 
2460
         *     @type string $password
 
2461
         *     @type array  $fields (optional)
 
2462
         * }
2341
2463
         * @return array|IXR_Error (@see wp_getUser)
2342
2464
         */
2343
2465
        public function wp_getProfile( $args ) {
2346
2468
 
2347
2469
                $this->escape( $args );
2348
2470
 
2349
 
                $username   = $args[1];
2350
 
                $password   = $args[2];
 
2471
                $username = $args[1];
 
2472
                $password = $args[2];
2351
2473
 
2352
2474
                if ( isset( $args[3] ) ) {
2353
2475
                        $fields = $args[3];
2374
2496
         * Edit user's profile.
2375
2497
         *
2376
2498
         * @uses wp_update_user()
2377
 
         * @param array $args Method parameters. Contains:
2378
 
         *  - int     $blog_id (unused)
2379
 
         *  - string  $username
2380
 
         *  - string  $password
2381
 
         *  - array   $content_struct
2382
 
         *      It can optionally contain:
 
2499
         *
 
2500
         * @param array  $args {
 
2501
         *     Method arguments. Note: arguments must be ordered as documented.
 
2502
         *
 
2503
         *     @type int    $blog_id (unused)
 
2504
         *     @type string $username
 
2505
         *     @type string $password
 
2506
         *     @type array  $content_struct It can optionally contain:
2383
2507
         *      - 'first_name'
2384
2508
         *      - 'last_name'
2385
2509
         *      - 'website'
2387
2511
         *      - 'nickname'
2388
2512
         *      - 'nicename'
2389
2513
         *      - 'bio'
2390
 
         * @return bool|IXR_Error True, on success.
 
2514
         * }
 
2515
         * @return true|IXR_Error True, on success.
2391
2516
         */
2392
2517
        public function wp_editProfile( $args ) {
2393
2518
                if ( ! $this->minimum_args( $args, 4 ) )
2450
2575
         *
2451
2576
         * @since 2.2.0
2452
2577
         *
2453
 
         * @param array $args Method parameters. Contains:
2454
 
         *  - blog_id (unused)
2455
 
         *  - page_id
2456
 
         *  - username
2457
 
         *  - password
 
2578
         * @param array  $args {
 
2579
         *     Method arguments. Note: arguments must be ordered as documented.
 
2580
         *
 
2581
         *     @type int    $blog_id (unused)
 
2582
         *     @type int    $page_id
 
2583
         *     @type string $username
 
2584
         *     @type string $password
 
2585
         * }
2458
2586
         * @return array|IXR_Error
2459
2587
         */
2460
 
        public function wp_getPage($args) {
2461
 
                $this->escape($args);
 
2588
        public function wp_getPage( $args ) {
 
2589
                $this->escape( $args );
2462
2590
 
2463
 
                $page_id        = (int) $args[1];
2464
 
                $username       = $args[2];
2465
 
                $password       = $args[3];
 
2591
                $page_id  = (int) $args[1];
 
2592
                $username = $args[2];
 
2593
                $password = $args[3];
2466
2594
 
2467
2595
                if ( !$user = $this->login($username, $password) ) {
2468
2596
                        return $this->error;
2493
2621
         *
2494
2622
         * @since 2.2.0
2495
2623
         *
2496
 
         * @param array $args Method parameters. Contains:
2497
 
         *  - blog_id (unused)
2498
 
         *  - username
2499
 
         *  - password
2500
 
         *  - num_pages
 
2624
         * @param array  $args {
 
2625
         *     Method arguments. Note: arguments must be ordered as documented.
 
2626
         *
 
2627
         *     @type int    $blog_id (unused)
 
2628
         *     @type string $username
 
2629
         *     @type string $password
 
2630
         *     @type int    $num_pages
 
2631
         * }
2501
2632
         * @return array|IXR_Error
2502
2633
         */
2503
 
        public function wp_getPages($args) {
2504
 
                $this->escape($args);
 
2634
        public function wp_getPages( $args ) {
 
2635
                $this->escape( $args );
2505
2636
 
2506
 
                $username       = $args[1];
2507
 
                $password       = $args[2];
2508
 
                $num_pages      = isset($args[3]) ? (int) $args[3] : 10;
 
2637
                $username  = $args[1];
 
2638
                $password  = $args[2];
 
2639
                $num_pages = isset($args[3]) ? (int) $args[3] : 10;
2509
2640
 
2510
2641
                if ( !$user = $this->login($username, $password) )
2511
2642
                        return $this->error;
2539
2670
         *
2540
2671
         * @since 2.2.0
2541
2672
         *
2542
 
         * @param array $args Method parameters. See {@link wp_xmlrpc_server::mw_newPost()}
 
2673
         * @see wp_xmlrpc_server::mw_newPost()
 
2674
         *
 
2675
         * @param array  $args {
 
2676
         *     Method arguments. Note: arguments must be ordered as documented.
 
2677
         *
 
2678
         *     @type int    $blog_id (unused)
 
2679
         *     @type string $username
 
2680
         *     @type string $password
 
2681
         *     @type array  $content_struct
 
2682
         * }
2543
2683
         * @return int|IXR_Error
2544
2684
         */
2545
 
        public function wp_newPage($args) {
 
2685
        public function wp_newPage( $args ) {
2546
2686
                // Items not escaped here will be escaped in newPost.
2547
 
                $username       = $this->escape($args[1]);
2548
 
                $password       = $this->escape($args[2]);
 
2687
                $username = $this->escape( $args[1] );
 
2688
                $password = $this->escape( $args[2] );
2549
2689
 
2550
2690
                if ( !$user = $this->login($username, $password) )
2551
2691
                        return $this->error;
2565
2705
         *
2566
2706
         * @since 2.2.0
2567
2707
         *
2568
 
         * @param array $args Method parameters.
2569
 
         * @return bool|IXR_Error True, if success.
 
2708
         * @param array  $args {
 
2709
         *     Method arguments. Note: arguments must be ordered as documented.
 
2710
         *
 
2711
         *     @type int    $blog_id (unused)
 
2712
         *     @type string $username
 
2713
         *     @type string $password
 
2714
         *     @type int    $page_id
 
2715
         * }
 
2716
         * @return true|IXR_Error True, if success.
2570
2717
         */
2571
 
        public function wp_deletePage($args) {
2572
 
                $this->escape($args);
 
2718
        public function wp_deletePage( $args ) {
 
2719
                $this->escape( $args );
2573
2720
 
2574
 
                $username       = $args[1];
2575
 
                $password       = $args[2];
2576
 
                $page_id        = (int) $args[3];
 
2721
                $username = $args[1];
 
2722
                $password = $args[2];
 
2723
                $page_id  = (int) $args[3];
2577
2724
 
2578
2725
                if ( !$user = $this->login($username, $password) )
2579
2726
                        return $this->error;
2614
2761
         *
2615
2762
         * @since 2.2.0
2616
2763
         *
2617
 
         * @param array $args Method parameters.
 
2764
         * @param array  $args {
 
2765
         *     Method arguments. Note: arguments must be ordered as documented.
 
2766
         *
 
2767
         *     @type int    $blog_id (unused)
 
2768
         *     @type int    $page_id
 
2769
         *     @type string $username
 
2770
         *     @type string $password
 
2771
         *     @type string $content
 
2772
         *     @type string $publish
 
2773
         * }
2618
2774
         * @return array|IXR_Error
2619
2775
         */
2620
 
        public function wp_editPage($args) {
2621
 
                // Items not escaped here will be escaped in editPost.
2622
 
                $page_id        = (int) $this->escape($args[1]);
2623
 
                $username       = $this->escape($args[2]);
2624
 
                $password       = $this->escape($args[3]);
2625
 
                $content        = $args[4];
2626
 
                $publish        = $args[5];
2627
 
 
2628
 
                if ( !$user = $this->login($username, $password) )
 
2776
        public function wp_editPage( $args ) {
 
2777
                // Items will be escaped in mw_editPost.
 
2778
                $page_id  = (int) $args[1];
 
2779
                $username = $args[2];
 
2780
                $password = $args[3];
 
2781
                $content  = $args[4];
 
2782
                $publish  = $args[5];
 
2783
 
 
2784
                $escaped_username = $this->escape( $username );
 
2785
                $escaped_password = $this->escape( $password );
 
2786
 
 
2787
                if ( !$user = $this->login( $escaped_username, $escaped_password ) ) {
2629
2788
                        return $this->error;
 
2789
                }
2630
2790
 
2631
2791
                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
2632
2792
                do_action( 'xmlrpc_call', 'wp.editPage' );
2661
2821
         *
2662
2822
         * @since 2.2.0
2663
2823
         *
2664
 
         * @param array $args Method parameters.
 
2824
         * @global wpdb $wpdb
 
2825
         *
 
2826
         * @param array  $args {
 
2827
         *     Method arguments. Note: arguments must be ordered as documented.
 
2828
         *
 
2829
         *     @type int    $blog_id (unused)
 
2830
         *     @type string $username
 
2831
         *     @type string $password
 
2832
         * }
2665
2833
         * @return array|IXR_Error
2666
2834
         */
2667
 
        public function wp_getPageList($args) {
 
2835
        public function wp_getPageList( $args ) {
2668
2836
                global $wpdb;
2669
2837
 
2670
 
                $this->escape($args);
 
2838
                $this->escape( $args );
2671
2839
 
2672
 
                $username                               = $args[1];
2673
 
                $password                               = $args[2];
 
2840
                $username = $args[1];
 
2841
                $password = $args[2];
2674
2842
 
2675
2843
                if ( !$user = $this->login($username, $password) )
2676
2844
                        return $this->error;
2713
2881
         *
2714
2882
         * @since 2.2.0
2715
2883
         *
2716
 
         * @param array $args Method parameters.
 
2884
         * @param array  $args {
 
2885
         *     Method arguments. Note: arguments must be ordered as documented.
 
2886
         *
 
2887
         *     @type int    $blog_id (unused)
 
2888
         *     @type string $username
 
2889
         *     @type string $password
 
2890
         * }
2717
2891
         * @return array|IXR_Error
2718
2892
         */
2719
 
        public function wp_getAuthors($args) {
2720
 
 
2721
 
                $this->escape($args);
2722
 
 
2723
 
                $username       = $args[1];
2724
 
                $password       = $args[2];
 
2893
        public function wp_getAuthors( $args ) {
 
2894
                $this->escape( $args );
 
2895
 
 
2896
                $username = $args[1];
 
2897
                $password = $args[2];
2725
2898
 
2726
2899
                if ( !$user = $this->login($username, $password) )
2727
2900
                        return $this->error;
2749
2922
         *
2750
2923
         * @since 2.7.0
2751
2924
         *
2752
 
         * @param array $args Method parameters.
 
2925
         * @param array  $args {
 
2926
         *     Method arguments. Note: arguments must be ordered as documented.
 
2927
         *
 
2928
         *     @type int    $blog_id (unused)
 
2929
         *     @type string $username
 
2930
         *     @type string $password
 
2931
         * }
2753
2932
         * @return array|IXR_Error
2754
2933
         */
2755
2934
        public function wp_getTags( $args ) {
2756
2935
                $this->escape( $args );
2757
2936
 
2758
 
                $username               = $args[1];
2759
 
                $password               = $args[2];
 
2937
                $username = $args[1];
 
2938
                $password = $args[2];
2760
2939
 
2761
2940
                if ( !$user = $this->login($username, $password) )
2762
2941
                        return $this->error;
2791
2970
         *
2792
2971
         * @since 2.2.0
2793
2972
         *
2794
 
         * @param array $args Method parameters.
 
2973
         * @param array  $args {
 
2974
         *     Method arguments. Note: arguments must be ordered as documented.
 
2975
         *
 
2976
         *     @type int    $blog_id (unused)
 
2977
         *     @type string $username
 
2978
         *     @type string $password
 
2979
         *     @type array  $category
 
2980
         * }
2795
2981
         * @return int|IXR_Error Category ID.
2796
2982
         */
2797
 
        public function wp_newCategory($args) {
2798
 
                $this->escape($args);
 
2983
        public function wp_newCategory( $args ) {
 
2984
                $this->escape( $args );
2799
2985
 
2800
 
                $username                               = $args[1];
2801
 
                $password                               = $args[2];
2802
 
                $category                               = $args[3];
 
2986
                $username = $args[1];
 
2987
                $password = $args[2];
 
2988
                $category = $args[3];
2803
2989
 
2804
2990
                if ( !$user = $this->login($username, $password) )
2805
2991
                        return $this->error;
2860
3046
         *
2861
3047
         * @since 2.5.0
2862
3048
         *
2863
 
         * @param array $args Method parameters.
 
3049
         * @param array  $args {
 
3050
         *     Method arguments. Note: arguments must be ordered as documented.
 
3051
         *
 
3052
         *     @type int    $blog_id (unused)
 
3053
         *     @type string $username
 
3054
         *     @type string $password
 
3055
         *     @type int    $category_id
 
3056
         * }
2864
3057
         * @return bool|IXR_Error See {@link wp_delete_term()} for return info.
2865
3058
         */
2866
 
        public function wp_deleteCategory($args) {
2867
 
                $this->escape($args);
 
3059
        public function wp_deleteCategory( $args ) {
 
3060
                $this->escape( $args );
2868
3061
 
2869
 
                $username               = $args[1];
2870
 
                $password               = $args[2];
2871
 
                $category_id    = (int) $args[3];
 
3062
                $username    = $args[1];
 
3063
                $password    = $args[2];
 
3064
                $category_id = (int) $args[3];
2872
3065
 
2873
3066
                if ( !$user = $this->login($username, $password) )
2874
3067
                        return $this->error;
2901
3094
         *
2902
3095
         * @since 2.2.0
2903
3096
         *
2904
 
         * @param array $args Method parameters.
 
3097
         * @param array  $args {
 
3098
         *     Method arguments. Note: arguments must be ordered as documented.
 
3099
         *
 
3100
         *     @type int    $blog_id (unused)
 
3101
         *     @type string $username
 
3102
         *     @type string $password
 
3103
         *     @type array  $category
 
3104
         *     @type int    $max_results
 
3105
         * }
2905
3106
         * @return array|IXR_Error
2906
3107
         */
2907
 
        public function wp_suggestCategories($args) {
2908
 
                $this->escape($args);
 
3108
        public function wp_suggestCategories( $args ) {
 
3109
                $this->escape( $args );
2909
3110
 
2910
 
                $username                               = $args[1];
2911
 
                $password                               = $args[2];
2912
 
                $category                               = $args[3];
2913
 
                $max_results                    = (int) $args[4];
 
3111
                $username    = $args[1];
 
3112
                $password    = $args[2];
 
3113
                $category    = $args[3];
 
3114
                $max_results = (int) $args[4];
2914
3115
 
2915
3116
                if ( !$user = $this->login($username, $password) )
2916
3117
                        return $this->error;
2938
3139
         *
2939
3140
         * @since 2.7.0
2940
3141
         *
2941
 
         * @param array $args Method parameters.
 
3142
         * @param array  $args {
 
3143
         *     Method arguments. Note: arguments must be ordered as documented.
 
3144
         *
 
3145
         *     @type int    $blog_id (unused)
 
3146
         *     @type string $username
 
3147
         *     @type string $password
 
3148
         *     @type int    $comment_id
 
3149
         * }
2942
3150
         * @return array|IXR_Error
2943
3151
         */
2944
3152
        public function wp_getComment($args) {
2979
3187
         *
2980
3188
         * @since 2.7.0
2981
3189
         *
2982
 
         * @param array $args Method parameters.
 
3190
         * @param array  $args {
 
3191
         *     Method arguments. Note: arguments must be ordered as documented.
 
3192
         *
 
3193
         *     @type int    $blog_id (unused)
 
3194
         *     @type string $username
 
3195
         *     @type string $password
 
3196
         *     @type array  $struct
 
3197
         * }
2983
3198
         * @return array|IXR_Error Contains a collection of comments. See {@link wp_xmlrpc_server::wp_getComment()} for a description of each item contents
2984
3199
         */
2985
 
        public function wp_getComments($args) {
2986
 
                $this->escape($args);
 
3200
        public function wp_getComments( $args ) {
 
3201
                $this->escape( $args );
2987
3202
 
2988
 
                $username       = $args[1];
2989
 
                $password       = $args[2];
2990
 
                $struct         = isset( $args[3] ) ? $args[3] : array();
 
3203
                $username = $args[1];
 
3204
                $password = $args[2];
 
3205
                $struct   = isset( $args[3] ) ? $args[3] : array();
2991
3206
 
2992
3207
                if ( !$user = $this->login($username, $password) )
2993
3208
                        return $this->error;
3015
3230
                if ( isset($struct['number']) )
3016
3231
                        $number = absint($struct['number']);
3017
3232
 
3018
 
                $comments = get_comments( array('status' => $status, 'post_id' => $post_id, 'offset' => $offset, 'number' => $number ) );
 
3233
                $comments = get_comments( array( 'status' => $status, 'post_id' => $post_id, 'offset' => $offset, 'number' => $number ) );
3019
3234
 
3020
3235
                $comments_struct = array();
3021
 
 
3022
 
                foreach ( $comments as $comment ) {
3023
 
                        $comments_struct[] = $this->_prepare_comment( $comment );
 
3236
                if ( is_array( $comments ) ) {
 
3237
                        foreach ( $comments as $comment ) {
 
3238
                                $comments_struct[] = $this->_prepare_comment( $comment );
 
3239
                        }
3024
3240
                }
3025
3241
 
3026
3242
                return $comments_struct;
3035
3251
         *
3036
3252
         * @since 2.7.0
3037
3253
         *
3038
 
         * @param array $args Method parameters. Contains:
3039
 
         *  - blog_id (unused)
3040
 
         *  - username
3041
 
         *  - password
3042
 
         *  - comment_id
 
3254
         * @param array  $args {
 
3255
         *     Method arguments. Note: arguments must be ordered as documented.
 
3256
         *
 
3257
         *     @type int    $blog_id (unused)
 
3258
         *     @type string $username
 
3259
         *     @type string $password
 
3260
         *     @type int    $comment_ID
 
3261
         * }
3043
3262
         * @return bool|IXR_Error {@link wp_delete_comment()}
3044
3263
         */
3045
3264
        public function wp_deleteComment($args) {
3066
3285
 
3067
3286
                $status = wp_delete_comment( $comment_ID );
3068
3287
 
3069
 
                if ( true == $status ) {
 
3288
                if ( $status ) {
3070
3289
                        /**
3071
3290
                         * Fires after a comment has been successfully deleted via XML-RPC.
3072
3291
                         *
3093
3312
         *  - 'author_email'
3094
3313
         *  - 'content'
3095
3314
         *  - 'date_created_gmt'
3096
 
         *  - 'status'. Common statuses are 'approve', 'hold', 'spam'. See {@link get_comment_statuses()} for more details
 
3315
         *  - 'status'. Common statuses are 'approve', 'hold', 'spam'. See get_comment_statuses() for more details
3097
3316
         *
3098
3317
         * @since 2.7.0
3099
3318
         *
3100
 
         * @param array $args Contains:
3101
 
         *  - blog_id (unused)
3102
 
         *  - username
3103
 
         *  - password
3104
 
         *  - comment_id
3105
 
         *  - content_struct
3106
 
         * @return bool|IXR_Error True, on success.
 
3319
         * @param array  $args {
 
3320
         *     Method arguments. Note: arguments must be ordered as documented.
 
3321
         *
 
3322
         *     @type int    $blog_id (unused)
 
3323
         *     @type string $username
 
3324
         *     @type string $password
 
3325
         *     @type int    $comment_ID
 
3326
         *     @type array  $content_struct
 
3327
         * }
 
3328
         * @return true|IXR_Error True, on success.
3107
3329
         */
3108
 
        public function wp_editComment($args) {
3109
 
                $this->escape($args);
 
3330
        public function wp_editComment( $args ) {
 
3331
                $this->escape( $args );
3110
3332
 
3111
3333
                $username       = $args[1];
3112
3334
                $password       = $args[2];
3185
3407
         *
3186
3408
         * @since 2.7.0
3187
3409
         *
3188
 
         * @param array $args Method parameters.
 
3410
         * @param array  $args {
 
3411
         *     Method arguments. Note: arguments must be ordered as documented.
 
3412
         *
 
3413
         *     @type int        $blog_id (unused)
 
3414
         *     @type string     $username
 
3415
         *     @type string     $password
 
3416
         *     @type string|int $post
 
3417
         *     @type array      $content_struct
 
3418
         * }
3189
3419
         * @return int|IXR_Error {@link wp_new_comment()}
3190
3420
         */
3191
3421
        public function wp_newComment($args) {
3192
3422
                $this->escape($args);
3193
3423
 
3194
 
                $username       = $args[1];
3195
 
                $password       = $args[2];
3196
 
                $post           = $args[3];
 
3424
                $username       = $args[1];
 
3425
                $password       = $args[2];
 
3426
                $post           = $args[3];
3197
3427
                $content_struct = $args[4];
3198
3428
 
3199
3429
                /**
3288
3518
         *
3289
3519
         * @since 2.7.0
3290
3520
         *
3291
 
         * @param array $args Method parameters.
 
3521
         * @param array  $args {
 
3522
         *     Method arguments. Note: arguments must be ordered as documented.
 
3523
         *
 
3524
         *     @type int    $blog_id (unused)
 
3525
         *     @type string $username
 
3526
         *     @type string $password
 
3527
         * }
3292
3528
         * @return array|IXR_Error
3293
3529
         */
3294
3530
        public function wp_getCommentStatusList($args) {
3295
3531
                $this->escape( $args );
3296
3532
 
3297
 
                $username       = $args[1];
3298
 
                $password       = $args[2];
 
3533
                $username = $args[1];
 
3534
                $password = $args[2];
3299
3535
 
3300
3536
                if ( !$user = $this->login($username, $password) )
3301
3537
                        return $this->error;
3314
3550
         *
3315
3551
         * @since 2.5.0
3316
3552
         *
3317
 
         * @param array $args Method parameters.
 
3553
         * @param array  $args {
 
3554
         *     Method arguments. Note: arguments must be ordered as documented.
 
3555
         *
 
3556
         *     @type int    $blog_id (unused)
 
3557
         *     @type string $username
 
3558
         *     @type string $password
 
3559
         *     @type int    $post_id
 
3560
         * }
3318
3561
         * @return array|IXR_Error
3319
3562
         */
3320
3563
        public function wp_getCommentCount( $args ) {
3321
 
                $this->escape($args);
 
3564
                $this->escape( $args );
3322
3565
 
3323
3566
                $username       = $args[1];
3324
3567
                $password       = $args[2];
3347
3590
         *
3348
3591
         * @since 2.5.0
3349
3592
         *
3350
 
         * @param array $args Method parameters.
 
3593
         * @param array  $args {
 
3594
         *     Method arguments. Note: arguments must be ordered as documented.
 
3595
         *
 
3596
         *     @type int    $blog_id (unused)
 
3597
         *     @type string $username
 
3598
         *     @type string $password
 
3599
         * }
3351
3600
         * @return array|IXR_Error
3352
3601
         */
3353
3602
        public function wp_getPostStatusList( $args ) {
3354
3603
                $this->escape( $args );
3355
3604
 
3356
 
                $username       = $args[1];
3357
 
                $password       = $args[2];
 
3605
                $username = $args[1];
 
3606
                $password = $args[2];
3358
3607
 
3359
3608
                if ( !$user = $this->login($username, $password) )
3360
3609
                        return $this->error;
3373
3622
         *
3374
3623
         * @since 2.5.0
3375
3624
         *
3376
 
         * @param array $args Method parameters.
 
3625
         * @param array  $args {
 
3626
         *     Method arguments. Note: arguments must be ordered as documented.
 
3627
         *
 
3628
         *     @type int    $blog_id (unused)
 
3629
         *     @type string $username
 
3630
         *     @type string $password
 
3631
         * }
3377
3632
         * @return array|IXR_Error
3378
3633
         */
3379
3634
        public function wp_getPageStatusList( $args ) {
3380
3635
                $this->escape( $args );
3381
3636
 
3382
 
                $username       = $args[1];
3383
 
                $password       = $args[2];
 
3637
                $username = $args[1];
 
3638
                $password = $args[2];
3384
3639
 
3385
3640
                if ( !$user = $this->login($username, $password) )
3386
3641
                        return $this->error;
3399
3654
         *
3400
3655
         * @since 2.6.0
3401
3656
         *
3402
 
         * @param array $args Method parameters.
 
3657
         * @param array  $args {
 
3658
         *     Method arguments. Note: arguments must be ordered as documented.
 
3659
         *
 
3660
         *     @type int    $blog_id (unused)
 
3661
         *     @type string $username
 
3662
         *     @type string $password
 
3663
         * }
3403
3664
         * @return array|IXR_Error
3404
3665
         */
3405
3666
        public function wp_getPageTemplates( $args ) {
3406
3667
                $this->escape( $args );
3407
3668
 
3408
 
                $username       = $args[1];
3409
 
                $password       = $args[2];
 
3669
                $username = $args[1];
 
3670
                $password = $args[2];
3410
3671
 
3411
3672
                if ( !$user = $this->login($username, $password) )
3412
3673
                        return $this->error;
3425
3686
         *
3426
3687
         * @since 2.6.0
3427
3688
         *
3428
 
         * @param array $args Method parameters.
 
3689
         * @param array  $args {
 
3690
         *     Method arguments. Note: arguments must be ordered as documented.
 
3691
         *
 
3692
         *     @type int    $blog_id (unused)
 
3693
         *     @type string $username
 
3694
         *     @type string $password
 
3695
         *     @type array  $options
 
3696
         * }
3429
3697
         * @return array|IXR_Error
3430
3698
         */
3431
3699
        public function wp_getOptions( $args ) {
3478
3746
         *
3479
3747
         * @since 2.6.0
3480
3748
         *
3481
 
         * @param array $args Method parameters.
 
3749
         * @param array  $args {
 
3750
         *     Method arguments. Note: arguments must be ordered as documented.
 
3751
         *
 
3752
         *     @type int    $blog_id (unused)
 
3753
         *     @type string $username
 
3754
         *     @type string $password
 
3755
         *     @type array  $options
 
3756
         * }
3482
3757
         * @return array|IXR_Error
3483
3758
         */
3484
3759
        public function wp_setOptions( $args ) {
3515
3790
         *
3516
3791
         * @since 3.1.0
3517
3792
         *
3518
 
         * @param array $args Method parameters. Contains:
3519
 
         *  - blog_id (unused)
3520
 
         *  - username
3521
 
         *  - password
3522
 
         *  - attachment_id
 
3793
         * @param array  $args {
 
3794
         *     Method arguments. Note: arguments must be ordered as documented.
 
3795
         *
 
3796
         *     @type int    $blog_id (unused)
 
3797
         *     @type string $username
 
3798
         *     @type string $password
 
3799
         *     @type int    $attachment_id
 
3800
         * }
3523
3801
         * @return array|IXR_Error Associative array contains:
3524
3802
         *  - 'date_created_gmt'
3525
3803
         *  - 'parent'
3530
3808
         *  - 'description'
3531
3809
         *  - 'metadata'
3532
3810
         */
3533
 
        public function wp_getMediaItem($args) {
3534
 
                $this->escape($args);
 
3811
        public function wp_getMediaItem( $args ) {
 
3812
                $this->escape( $args );
3535
3813
 
3536
3814
                $username               = $args[1];
3537
3815
                $password               = $args[2];
3562
3840
         *
3563
3841
         * The defaults are as follows:
3564
3842
         * - 'number' - Default is 5. Total number of media items to retrieve.
3565
 
         * - 'offset' - Default is 0. See {@link WP_Query::query()} for more.
 
3843
         * - 'offset' - Default is 0. See WP_Query::query() for more.
3566
3844
         * - 'parent_id' - Default is ''. The post where the media item is attached. Empty string shows all media items. 0 shows unattached media items.
3567
3845
         * - 'mime_type' - Default is ''. Filter by mime type (e.g., 'image/jpeg', 'application/pdf')
3568
3846
         *
3569
3847
         * @since 3.1.0
3570
3848
         *
3571
 
         * @param array $args Method parameters. Contains:
3572
 
         *  - blog_id (unused)
3573
 
         *  - username
3574
 
         *  - password
3575
 
         *  - filter
3576
 
         * @return array|IXR_Error Contains a collection of media items. See {@link wp_xmlrpc_server::wp_getMediaItem()} for a description of each item contents
 
3849
         * @param array  $args {
 
3850
         *     Method arguments. Note: arguments must be ordered as documented.
 
3851
         *
 
3852
         *     @type int    $blog_id (unused)
 
3853
         *     @type string $username
 
3854
         *     @type string $password
 
3855
         *     @type array  $struct
 
3856
         * }
 
3857
         * @return array|IXR_Error Contains a collection of media items. See wp_xmlrpc_server::wp_getMediaItem() for a description of each item contents
3577
3858
         */
3578
3859
        public function wp_getMediaLibrary($args) {
3579
3860
                $this->escape($args);
3607
3888
        }
3608
3889
 
3609
3890
        /**
3610
 
          * Retrieves a list of post formats used by the site
3611
 
          *
3612
 
          * @since 3.1.0
3613
 
          *
3614
 
          * @param array $args Method parameters. Contains:
3615
 
          *  - blog_id (unused)
3616
 
          *  - username
3617
 
          *  - password
3618
 
          * @return array|IXR_Error
3619
 
          */
 
3891
         * Retrieves a list of post formats used by the site.
 
3892
         *
 
3893
         * @since 3.1.0
 
3894
         *
 
3895
         * @param array  $args {
 
3896
         *     Method arguments. Note: arguments must be ordered as documented.
 
3897
         *
 
3898
         *     @type int    $blog_id (unused)
 
3899
         *     @type string $username
 
3900
         *     @type string $password
 
3901
         * }
 
3902
         * @return array|IXR_Error List of post formats, otherwise IXR_Error object.
 
3903
         */
3620
3904
        public function wp_getPostFormats( $args ) {
3621
3905
                $this->escape( $args );
3622
3906
 
3657
3941
         *
3658
3942
         * @since 3.4.0
3659
3943
         *
3660
 
         * @uses get_post_type_object()
3661
 
         * @param array $args Method parameters. Contains:
3662
 
         *  - int     $blog_id (unused)
3663
 
         *  - string  $username
3664
 
         *  - string  $password
3665
 
         *  - string  $post_type_name
3666
 
         *  - array   $fields
 
3944
         * @see get_post_type_object()
 
3945
         *
 
3946
         * @param array  $args {
 
3947
         *     Method arguments. Note: arguments must be ordered as documented.
 
3948
         *
 
3949
         *     @type int    $blog_id (unused)
 
3950
         *     @type string $username
 
3951
         *     @type string $password
 
3952
         *     @type string $post_type_name
 
3953
         *     @type array  $fields (optional)
 
3954
         * }
3667
3955
         * @return array|IXR_Error Array contains:
3668
3956
         *  - 'labels'
3669
3957
         *  - 'description'
3705
3993
                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
3706
3994
                do_action( 'xmlrpc_call', 'wp.getPostType' );
3707
3995
 
3708
 
                if( ! post_type_exists( $post_type_name ) )
 
3996
                if ( ! post_type_exists( $post_type_name ) )
3709
3997
                        return new IXR_Error( 403, __( 'Invalid post type' ) );
3710
3998
 
3711
3999
                $post_type = get_post_type_object( $post_type_name );
3712
4000
 
3713
 
                if( ! current_user_can( $post_type->cap->edit_posts ) )
 
4001
                if ( ! current_user_can( $post_type->cap->edit_posts ) )
3714
4002
                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post type.' ) );
3715
4003
 
3716
4004
                return $this->_prepare_post_type( $post_type, $fields );
3721
4009
         *
3722
4010
         * @since 3.4.0
3723
4011
         *
3724
 
         * @uses get_post_types()
3725
 
         * @param array $args Method parameters. Contains:
3726
 
         *  - int     $blog_id (unused)
3727
 
         *  - string  $username
3728
 
         *  - string  $password
3729
 
         *  - array   $filter
3730
 
         *  - array   $fields
 
4012
         * @see get_post_types()
 
4013
         *
 
4014
         * @param array  $args {
 
4015
         *     Method arguments. Note: arguments must be ordered as documented.
 
4016
         *
 
4017
         *     @type int    $blog_id (unused)
 
4018
         *     @type string $username
 
4019
         *     @type string $password
 
4020
         *     @type array  $filter (optional)
 
4021
         *     @type array  $fields (optional)
 
4022
         * }
3731
4023
         * @return array|IXR_Error
3732
4024
         */
3733
4025
        public function wp_getPostTypes( $args ) {
3736
4028
 
3737
4029
                $this->escape( $args );
3738
4030
 
3739
 
                $username           = $args[1];
3740
 
                $password           = $args[2];
3741
 
                $filter             = isset( $args[3] ) ? $args[3] : array( 'public' => true );
 
4031
                $username = $args[1];
 
4032
                $password = $args[2];
 
4033
                $filter   = isset( $args[3] ) ? $args[3] : array( 'public' => true );
3742
4034
 
3743
4035
                if ( isset( $args[4] ) ) {
3744
4036
                        $fields = $args[4];
3758
4050
                $struct = array();
3759
4051
 
3760
4052
                foreach( $post_types as $post_type ) {
3761
 
                        if( ! current_user_can( $post_type->cap->edit_posts ) )
 
4053
                        if ( ! current_user_can( $post_type->cap->edit_posts ) )
3762
4054
                                continue;
3763
4055
 
3764
4056
                        $struct[$post_type->name] = $this->_prepare_post_type( $post_type, $fields );
3778
4070
         * @uses wp_get_post_revisions()
3779
4071
         * @see wp_getPost() for more on $fields
3780
4072
         *
3781
 
         * @param array $args Method parameters. Contains:
3782
 
         *  - int     $blog_id (unused)
3783
 
         *  - string  $username
3784
 
         *  - string  $password
3785
 
         *  - int     $post_id
3786
 
         *  - array   $fields
 
4073
         * @param array  $args {
 
4074
         *     Method arguments. Note: arguments must be ordered as documented.
 
4075
         *
 
4076
         *     @type int    $blog_id (unused)
 
4077
         *     @type string $username
 
4078
         *     @type string $password
 
4079
         *     @type int    $post_id
 
4080
         *     @type array  $fields (optional)
 
4081
         * }
3787
4082
         * @return array|IXR_Error contains a collection of posts.
3788
4083
         */
3789
4084
        public function wp_getRevisions( $args ) {
3792
4087
 
3793
4088
                $this->escape( $args );
3794
4089
 
3795
 
                $username   = $args[1];
3796
 
                $password   = $args[2];
3797
 
                $post_id    = (int) $args[3];
 
4090
                $username = $args[1];
 
4091
                $password = $args[2];
 
4092
                $post_id  = (int) $args[3];
3798
4093
 
3799
4094
                if ( isset( $args[4] ) ) {
3800
4095
                        $fields = $args[4];
3817
4112
                do_action( 'xmlrpc_call', 'wp.getRevisions' );
3818
4113
 
3819
4114
                if ( ! $post = get_post( $post_id ) )
3820
 
                        return new IXR_Error( 404, __( 'Invalid post ID' ) );
 
4115
                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
3821
4116
 
3822
4117
                if ( ! current_user_can( 'edit_post', $post_id ) )
3823
4118
                        return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) );
3854
4149
         *
3855
4150
         * @uses wp_restore_post_revision()
3856
4151
         *
3857
 
         * @param array $args Method parameters. Contains:
3858
 
         *  - int     $blog_id (unused)
3859
 
         *  - string  $username
3860
 
         *  - string  $password
3861
 
         *  - int     $post_id
 
4152
         * @param array  $args {
 
4153
         *     Method arguments. Note: arguments must be ordered as documented.
 
4154
         *
 
4155
         *     @type int    $blog_id (unused)
 
4156
         *     @type string $username
 
4157
         *     @type string $password
 
4158
         *     @type int    $revision_id
 
4159
         * }
3862
4160
         * @return bool|IXR_Error false if there was an error restoring, true if success.
3863
4161
         */
3864
4162
        public function wp_restoreRevision( $args ) {
3878
4176
                do_action( 'xmlrpc_call', 'wp.restoreRevision' );
3879
4177
 
3880
4178
                if ( ! $revision = wp_get_post_revision( $revision_id ) )
3881
 
                        return new IXR_Error( 404, __( 'Invalid post ID' ) );
 
4179
                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
3882
4180
 
3883
4181
                if ( wp_is_post_autosave( $revision ) )
3884
 
                        return new IXR_Error( 404, __( 'Invalid post ID' ) );
 
4182
                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
3885
4183
 
3886
4184
                if ( ! $post = get_post( $revision->post_parent ) )
3887
 
                        return new IXR_Error( 404, __( 'Invalid post ID' ) );
 
4185
                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
3888
4186
 
3889
4187
                if ( ! current_user_can( 'edit_post', $revision->post_parent ) )
3890
4188
                        return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) );
3909
4207
         *
3910
4208
         * @since 1.5.0
3911
4209
         *
3912
 
         * @param array $args Method parameters.
 
4210
         * @param array  $args {
 
4211
         *     Method arguments. Note: arguments must be ordered as documented.
 
4212
         *
 
4213
         *     @type int    $blog_id (unused)
 
4214
         *     @type string $username
 
4215
         *     @type string $password
 
4216
         * }
3913
4217
         * @return array|IXR_Error
3914
4218
         */
3915
4219
        public function blogger_getUsersBlogs($args) {
3919
4223
                $this->escape($args);
3920
4224
 
3921
4225
                $username = $args[1];
3922
 
                $password  = $args[2];
 
4226
                $password = $args[2];
3923
4227
 
3924
4228
                if ( !$user = $this->login($username, $password) )
3925
4229
                        return $this->error;
3978
4282
         *
3979
4283
         * @since 1.5.0
3980
4284
         *
3981
 
         * @param array $args Method parameters.
 
4285
         * @param array  $args {
 
4286
         *     Method arguments. Note: arguments must be ordered as documented.
 
4287
         *
 
4288
         *     @type int    $blog_id (unused)
 
4289
         *     @type string $username
 
4290
         *     @type string $password
 
4291
         * }
3982
4292
         * @return array|IXR_Error
3983
4293
         */
3984
 
        public function blogger_getUserInfo($args) {
3985
 
 
3986
 
                $this->escape($args);
 
4294
        public function blogger_getUserInfo( $args ) {
 
4295
                $this->escape( $args );
3987
4296
 
3988
4297
                $username = $args[1];
3989
 
                $password  = $args[2];
 
4298
                $password = $args[2];
3990
4299
 
3991
4300
                if ( !$user = $this->login($username, $password) )
3992
4301
                        return $this->error;
4013
4322
         *
4014
4323
         * @since 1.5.0
4015
4324
         *
4016
 
         * @param array $args Method parameters.
 
4325
         * @param array  $args {
 
4326
         *     Method arguments. Note: arguments must be ordered as documented.
 
4327
         *
 
4328
         *     @type int    $blog_id (unused)
 
4329
         *     @type int    $post_ID
 
4330
         *     @type string $username
 
4331
         *     @type string $password
 
4332
         * }
4017
4333
         * @return array|IXR_Error
4018
4334
         */
4019
 
        public function blogger_getPost($args) {
4020
 
 
4021
 
                $this->escape($args);
4022
 
 
4023
 
                $post_ID    = (int) $args[1];
 
4335
        public function blogger_getPost( $args ) {
 
4336
                $this->escape( $args );
 
4337
 
 
4338
                $post_ID  = (int) $args[1];
4024
4339
                $username = $args[2];
4025
 
                $password  = $args[3];
 
4340
                $password = $args[3];
4026
4341
 
4027
4342
                if ( !$user = $this->login($username, $password) )
4028
4343
                        return $this->error;
4058
4373
         *
4059
4374
         * @since 1.5.0
4060
4375
         *
4061
 
         * @param array $args Method parameters.
 
4376
         * @param array  $args {
 
4377
         *     Method arguments. Note: arguments must be ordered as documented.
 
4378
         *
 
4379
         *     @type string $appkey (unused)
 
4380
         *     @type int    $blog_id (unused)
 
4381
         *     @type string $username
 
4382
         *     @type string $password
 
4383
         *     @type int    $numberposts (optional)
 
4384
         * }
4062
4385
         * @return array|IXR_Error
4063
4386
         */
4064
 
        public function blogger_getRecentPosts($args) {
 
4387
        public function blogger_getRecentPosts( $args ) {
4065
4388
 
4066
4389
                $this->escape($args);
4067
4390
 
4068
4391
                // $args[0] = appkey - ignored
4069
4392
                $username = $args[2];
4070
 
                $password  = $args[3];
 
4393
                $password = $args[3];
4071
4394
                if ( isset( $args[4] ) )
4072
4395
                        $query = array( 'numberposts' => absint( $args[4] ) );
4073
4396
                else
4139
4462
         *
4140
4463
         * @since 1.5.0
4141
4464
         *
4142
 
         * @param array $args Method parameters.
 
4465
         * @param array  $args {
 
4466
         *     Method arguments. Note: arguments must be ordered as documented.
 
4467
         *
 
4468
         *     @type string $appkey (unused)
 
4469
         *     @type int    $blog_id (unused)
 
4470
         *     @type string $username
 
4471
         *     @type string $password
 
4472
         *     @type string $content
 
4473
         *     @type string $publish
 
4474
         * }
4143
4475
         * @return int|IXR_Error
4144
4476
         */
4145
 
        public function blogger_newPost($args) {
4146
 
 
4147
 
                $this->escape($args);
 
4477
        public function blogger_newPost( $args ) {
 
4478
                $this->escape( $args );
4148
4479
 
4149
4480
                $username = $args[2];
4150
 
                $password  = $args[3];
4151
 
                $content    = $args[4];
4152
 
                $publish    = $args[5];
 
4481
                $password = $args[3];
 
4482
                $content  = $args[4];
 
4483
                $publish  = $args[5];
4153
4484
 
4154
4485
                if ( !$user = $this->login($username, $password) )
4155
4486
                        return $this->error;
4201
4532
         *
4202
4533
         * @since 1.5.0
4203
4534
         *
4204
 
         * @param array $args Method parameters.
4205
 
         * @return bool|IXR_Error true when done.
 
4535
         * @param array  $args {
 
4536
         *     Method arguments. Note: arguments must be ordered as documented.
 
4537
         *
 
4538
         *     @type int    $blog_id (unused)
 
4539
         *     @type int    $post_ID
 
4540
         *     @type string $username
 
4541
         *     @type string $password
 
4542
         *     @type string $content
 
4543
         * }
 
4544
         * @return true|IXR_Error true when done.
4206
4545
         */
4207
4546
        public function blogger_editPost( $args ) {
4208
4547
 
4209
4548
                $this->escape($args);
4210
4549
 
4211
 
                $post_ID     = (int) $args[1];
4212
 
                $username  = $args[2];
4213
 
                $password   = $args[3];
4214
 
                $content     = $args[4];
 
4550
                $post_ID  = (int) $args[1];
 
4551
                $username = $args[2];
 
4552
                $password = $args[3];
 
4553
                $content  = $args[4];
4215
4554
 
4216
4555
                if ( ! $user = $this->login( $username, $password ) ) {
4217
4556
                        return $this->error;
4268
4607
         *
4269
4608
         * @since 1.5.0
4270
4609
         *
4271
 
         * @param array $args Method parameters.
4272
 
         * @return bool|IXR_Error True when post is deleted.
 
4610
         * @param array  $args {
 
4611
         *     Method arguments. Note: arguments must be ordered as documented.
 
4612
         *
 
4613
         *     @type int    $blog_id (unused)
 
4614
         *     @type int    $post_ID
 
4615
         *     @type string $username
 
4616
         *     @type string $password
 
4617
         * }
 
4618
         * @return true|IXR_Error True when post is deleted.
4273
4619
         */
4274
 
        public function blogger_deletePost($args) {
4275
 
                $this->escape($args);
 
4620
        public function blogger_deletePost( $args ) {
 
4621
                $this->escape( $args );
4276
4622
 
4277
 
                $post_ID     = (int) $args[1];
4278
 
                $username  = $args[2];
4279
 
                $password   = $args[3];
 
4623
                $post_ID  = (int) $args[1];
 
4624
                $username = $args[2];
 
4625
                $password = $args[3];
4280
4626
 
4281
4627
                if ( !$user = $this->login($username, $password) )
4282
4628
                        return $this->error;
4341
4687
         *
4342
4688
         * @since 1.5.0
4343
4689
         *
4344
 
         * @param array $args Method parameters. Contains:
4345
 
         *  - blog_id (unused)
4346
 
         *  - username
4347
 
         *  - password
4348
 
         *  - content_struct
4349
 
         *  - publish
 
4690
         * @param array  $args {
 
4691
         *     Method arguments. Note: arguments must be ordered as documented.
 
4692
         *
 
4693
         *     @type int    $blog_id (unused)
 
4694
         *     @type string $username
 
4695
         *     @type string $password
 
4696
         *     @type array  $content_struct
 
4697
         *     @type int    $publish
 
4698
         * }
4350
4699
         * @return int|IXR_Error
4351
4700
         */
4352
4701
        public function mw_newPost($args) {
4353
4702
                $this->escape($args);
4354
4703
 
4355
 
                $username  = $args[1];
4356
 
                $password   = $args[2];
 
4704
                $username       = $args[1];
 
4705
                $password       = $args[2];
4357
4706
                $content_struct = $args[3];
4358
 
                $publish     = isset( $args[4] ) ? $args[4] : 0;
 
4707
                $publish        = isset( $args[4] ) ? $args[4] : 0;
4359
4708
 
4360
4709
                if ( !$user = $this->login($username, $password) )
4361
4710
                        return $this->error;
4487
4836
                                                $comment_status = 'open';
4488
4837
                                                break;
4489
4838
                                        default:
4490
 
                                                $comment_status = get_option('default_comment_status');
 
4839
                                                $comment_status = get_default_comment_status( $post_type );
4491
4840
                                                break;
4492
4841
                                }
4493
4842
                        } else {
4500
4849
                                                $comment_status = 'open';
4501
4850
                                                break;
4502
4851
                                        default:
4503
 
                                                $comment_status = get_option('default_comment_status');
 
4852
                                                $comment_status = get_default_comment_status( $post_type );
4504
4853
                                                break;
4505
4854
                                }
4506
4855
                        }
4507
4856
                } else {
4508
 
                        $comment_status = get_option('default_comment_status');
 
4857
                        $comment_status = get_default_comment_status( $post_type );
4509
4858
                }
4510
4859
 
4511
4860
                if ( isset($content_struct['mt_allow_pings']) ) {
4518
4867
                                                $ping_status = 'open';
4519
4868
                                                break;
4520
4869
                                        default:
4521
 
                                                $ping_status = get_option('default_ping_status');
 
4870
                                                $ping_status = get_default_comment_status( $post_type, 'pingback' );
4522
4871
                                                break;
4523
4872
                                }
4524
4873
                        } else {
4530
4879
                                                $ping_status = 'open';
4531
4880
                                                break;
4532
4881
                                        default:
4533
 
                                                $ping_status = get_option('default_ping_status');
 
4882
                                                $ping_status = get_default_comment_status( $post_type, 'pingback' );
4534
4883
                                                break;
4535
4884
                                }
4536
4885
                        }
4537
4886
                } else {
4538
 
                        $ping_status = get_option('default_ping_status');
 
4887
                        $ping_status = get_default_comment_status( $post_type, 'pingback' );
4539
4888
                }
4540
4889
 
4541
4890
                if ( $post_more )
4580
4929
 
4581
4930
                // Only posts can be sticky
4582
4931
                if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
4583
 
                        if ( $content_struct['sticky'] == true )
4584
 
                                stick_post( $post_ID );
4585
 
                        elseif ( $content_struct['sticky'] == false )
4586
 
                                unstick_post( $post_ID );
 
4932
                        $data = $postdata;
 
4933
                        $data['sticky'] = $content_struct['sticky'];
 
4934
                        $error = $this->_toggle_sticky( $data );
 
4935
                        if ( $error ) {
 
4936
                                return $error;
 
4937
                        }
4587
4938
                }
4588
4939
 
4589
4940
                if ( isset($content_struct['custom_fields']) )
4654
5005
         *
4655
5006
         * @since 2.1.0
4656
5007
         *
 
5008
         * @global wpdb $wpdb
 
5009
         *
4657
5010
         * @param int $post_ID Post ID.
4658
5011
         * @param string $post_content Post Content for attachment.
4659
5012
         */
4675
5028
         *
4676
5029
         * @since 1.5.0
4677
5030
         *
4678
 
         * @param array $args Method parameters.
 
5031
         * @param array  $args {
 
5032
         *     Method arguments. Note: arguments must be ordered as documented.
 
5033
         *
 
5034
         *     @type int    $blog_id (unused)
 
5035
         *     @type string $username
 
5036
         *     @type string $password
 
5037
         *     @type array  $content_struct
 
5038
         *     @type int    $publish
 
5039
         * }
4679
5040
         * @return bool|IXR_Error True on success.
4680
5041
         */
4681
 
        public function mw_editPost($args) {
4682
 
 
4683
 
                $this->escape($args);
 
5042
        public function mw_editPost( $args ) {
 
5043
                $this->escape( $args );
4684
5044
 
4685
5045
                $post_ID        = (int) $args[0];
4686
5046
                $username       = $args[1];
4696
5056
 
4697
5057
                $postdata = get_post( $post_ID, ARRAY_A );
4698
5058
 
4699
 
                // If there is no post data for the give post id, stop
4700
 
                // now and return an error. Other wise a new post will be
4701
 
                // created (which was the old behavior).
 
5059
                /*
 
5060
                 * If there is no post data for the give post id, stop now and return an error.
 
5061
                 * Otherwise a new post will be created (which was the old behavior).
 
5062
                 */
4702
5063
                if ( ! $postdata || empty( $postdata[ 'ID' ] ) )
4703
5064
                        return new IXR_Error( 404, __( 'Invalid post ID.' ) );
4704
5065
 
4788
5149
                                                $comment_status = 'open';
4789
5150
                                                break;
4790
5151
                                        default:
4791
 
                                                $comment_status = get_option('default_comment_status');
 
5152
                                                $comment_status = get_default_comment_status( $post_type );
4792
5153
                                                break;
4793
5154
                                }
4794
5155
                        } else {
4801
5162
                                                $comment_status = 'open';
4802
5163
                                                break;
4803
5164
                                        default:
4804
 
                                                $comment_status = get_option('default_comment_status');
 
5165
                                                $comment_status = get_default_comment_status( $post_type );
4805
5166
                                                break;
4806
5167
                                }
4807
5168
                        }
4817
5178
                                                $ping_status = 'open';
4818
5179
                                                break;
4819
5180
                                        default:
4820
 
                                                $ping_status = get_option('default_ping_status');
 
5181
                                                $ping_status = get_default_comment_status( $post_type, 'pingback' );
4821
5182
                                                break;
4822
5183
                                }
4823
5184
                        } else {
4829
5190
                                                $ping_status = 'open';
4830
5191
                                                break;
4831
5192
                                        default:
4832
 
                                                $ping_status = get_option('default_ping_status');
 
5193
                                                $ping_status = get_default_comment_status( $post_type, 'pingback' );
4833
5194
                                                break;
4834
5195
                                }
4835
5196
                        }
4891
5252
                                $to_ping = implode(' ', $to_ping);
4892
5253
                }
4893
5254
 
4894
 
                // Do some timestamp voodoo
 
5255
                // Do some timestamp voodoo.
4895
5256
                if ( !empty( $content_struct['date_created_gmt'] ) )
4896
 
                        // We know this is supposed to be GMT, so we're going to slap that Z on there by force
 
5257
                        // We know this is supposed to be GMT, so we're going to slap that Z on there by force.
4897
5258
                        $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z';
4898
5259
                elseif ( !empty( $content_struct['dateCreated']) )
4899
5260
                        $dateCreated = $content_struct['dateCreated']->getIso();
4906
5267
                        $post_date_gmt = $postdata['post_date_gmt'];
4907
5268
                }
4908
5269
 
4909
 
                // We've got all the data -- post it:
 
5270
                // We've got all the data -- post it.
4910
5271
                $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template');
4911
5272
 
4912
5273
                $result = wp_update_post($newpost, true);
4918
5279
 
4919
5280
                // Only posts can be sticky
4920
5281
                if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) {
4921
 
                        if ( $content_struct['sticky'] == true )
4922
 
                                stick_post( $post_ID );
4923
 
                        elseif ( $content_struct['sticky'] == false )
4924
 
                                unstick_post( $post_ID );
 
5282
                        $data = $newpost;
 
5283
                        $data['sticky'] = $content_struct['sticky'];
 
5284
                        $data['post_type'] = 'post';
 
5285
                        $error = $this->_toggle_sticky( $data, true );
 
5286
                        if ( $error ) {
 
5287
                                return $error;
 
5288
                        }
4925
5289
                }
4926
5290
 
4927
5291
                if ( isset($content_struct['custom_fields']) )
4928
5292
                        $this->set_custom_fields($post_ID, $content_struct['custom_fields']);
4929
5293
 
4930
5294
                if ( isset ( $content_struct['wp_post_thumbnail'] ) ) {
4931
 
                        // empty value deletes, non-empty value adds/updates
 
5295
 
 
5296
                        // Empty value deletes, non-empty value adds/updates.
4932
5297
                        if ( empty( $content_struct['wp_post_thumbnail'] ) ) {
4933
5298
                                delete_post_thumbnail( $post_ID );
4934
5299
                        } else {
4938
5303
                        unset( $content_struct['wp_post_thumbnail'] );
4939
5304
                }
4940
5305
 
4941
 
                // Handle enclosures
 
5306
                // Handle enclosures.
4942
5307
                $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null;
4943
5308
                $this->add_enclosure_if_new($post_ID, $thisEnclosure);
4944
5309
 
4945
5310
                $this->attach_uploads( $ID, $post_content );
4946
5311
 
4947
 
                // Handle post formats if assigned, validation is handled
4948
 
                // earlier in this function
 
5312
                // Handle post formats if assigned, validation is handled earlier in this function.
4949
5313
                if ( isset( $content_struct['wp_post_format'] ) )
4950
5314
                        set_post_format( $post_ID, $content_struct['wp_post_format'] );
4951
5315
 
4967
5331
         *
4968
5332
         * @since 1.5.0
4969
5333
         *
4970
 
         * @param array $args Method parameters.
 
5334
         * @param array  $args {
 
5335
         *     Method arguments. Note: arguments must be ordered as documented.
 
5336
         *
 
5337
         *     @type int    $blog_id (unused)
 
5338
         *     @type int    $post_ID
 
5339
         *     @type string $username
 
5340
         *     @type string $password
 
5341
         * }
4971
5342
         * @return array|IXR_Error
4972
5343
         */
4973
 
        public function mw_getPost($args) {
4974
 
 
4975
 
                $this->escape($args);
4976
 
 
4977
 
                $post_ID     = (int) $args[0];
4978
 
                $username  = $args[1];
4979
 
                $password   = $args[2];
 
5344
        public function mw_getPost( $args ) {
 
5345
                $this->escape( $args );
 
5346
 
 
5347
                $post_ID  = (int) $args[0];
 
5348
                $username = $args[1];
 
5349
                $password = $args[2];
4980
5350
 
4981
5351
                if ( !$user = $this->login($username, $password) )
4982
5352
                        return $this->error;
5092
5462
         *
5093
5463
         * @since 1.5.0
5094
5464
         *
5095
 
         * @param array $args Method parameters.
 
5465
         * @param array  $args {
 
5466
         *     Method arguments. Note: arguments must be ordered as documented.
 
5467
         *
 
5468
         *     @type int    $blog_id (unused)
 
5469
         *     @type string $username
 
5470
         *     @type string $password
 
5471
         *     @type int    $numberposts
 
5472
         * }
5096
5473
         * @return array|IXR_Error
5097
5474
         */
5098
 
        public function mw_getRecentPosts($args) {
5099
 
 
5100
 
                $this->escape($args);
5101
 
 
5102
 
                $username  = $args[1];
5103
 
                $password   = $args[2];
 
5475
        public function mw_getRecentPosts( $args ) {
 
5476
                $this->escape( $args );
 
5477
 
 
5478
                $username = $args[1];
 
5479
                $password = $args[2];
5104
5480
                if ( isset( $args[3] ) )
5105
5481
                        $query = array( 'numberposts' => absint( $args[3] ) );
5106
5482
                else
5204
5580
         *
5205
5581
         * @since 1.5.0
5206
5582
         *
5207
 
         * @param array $args Method parameters.
 
5583
         * @param array  $args {
 
5584
         *     Method arguments. Note: arguments must be ordered as documented.
 
5585
         *
 
5586
         *     @type int    $blog_id (unused)
 
5587
         *     @type string $username
 
5588
         *     @type string $password
 
5589
         * }
5208
5590
         * @return array|IXR_Error
5209
5591
         */
5210
 
        public function mw_getCategories($args) {
5211
 
 
5212
 
                $this->escape($args);
5213
 
 
5214
 
                $username  = $args[1];
5215
 
                $password   = $args[2];
 
5592
        public function mw_getCategories( $args ) {
 
5593
                $this->escape( $args );
 
5594
 
 
5595
                $username = $args[1];
 
5596
                $password = $args[2];
5216
5597
 
5217
5598
                if ( !$user = $this->login($username, $password) )
5218
5599
                        return $this->error;
5252
5633
         *
5253
5634
         * @since 1.5.0
5254
5635
         *
5255
 
         * @param array $args Method parameters.
 
5636
         * @global wpdb $wpdb
 
5637
         *
 
5638
         * @param array  $args {
 
5639
         *     Method arguments. Note: arguments must be ordered as documented.
 
5640
         *
 
5641
         *     @type int    $blog_id (unused)
 
5642
         *     @type string $username
 
5643
         *     @type string $password
 
5644
         *     @type array  $data
 
5645
         * }
5256
5646
         * @return array|IXR_Error
5257
5647
         */
5258
 
        public function mw_newMediaObject($args) {
 
5648
        public function mw_newMediaObject( $args ) {
5259
5649
                global $wpdb;
5260
5650
 
5261
 
                $username  = $this->escape($args[1]);
5262
 
                $password   = $this->escape($args[2]);
5263
 
                $data        = $args[3];
 
5651
                $username = $this->escape( $args[1] );
 
5652
                $password = $this->escape( $args[2] );
 
5653
                $data     = $args[3];
5264
5654
 
5265
5655
                $name = sanitize_file_name( $data['name'] );
5266
5656
                $type = $data['type'];
5365
5755
         *
5366
5756
         * @since 1.5.0
5367
5757
         *
5368
 
         * @param array $args Method parameters.
 
5758
         * @param array  $args {
 
5759
         *     Method arguments. Note: arguments must be ordered as documented.
 
5760
         *
 
5761
         *     @type int    $blog_id (unused)
 
5762
         *     @type string $username
 
5763
         *     @type string $password
 
5764
         *     @type int    $numberposts
 
5765
         * }
5369
5766
         * @return array|IXR_Error
5370
5767
         */
5371
 
        public function mt_getRecentPostTitles($args) {
5372
 
 
5373
 
                $this->escape($args);
5374
 
 
5375
 
                $username  = $args[1];
5376
 
                $password   = $args[2];
 
5768
        public function mt_getRecentPostTitles( $args ) {
 
5769
                $this->escape( $args );
 
5770
 
 
5771
                $username = $args[1];
 
5772
                $password = $args[2];
5377
5773
                if ( isset( $args[3] ) )
5378
5774
                        $query = array( 'numberposts' => absint( $args[3] ) );
5379
5775
                else
5419
5815
         *
5420
5816
         * @since 1.5.0
5421
5817
         *
5422
 
         * @param array $args Method parameters.
 
5818
         * @param array  $args {
 
5819
         *     Method arguments. Note: arguments must be ordered as documented.
 
5820
         *
 
5821
         *     @type int    $blog_id (unused)
 
5822
         *     @type string $username
 
5823
         *     @type string $password
 
5824
         * }
5423
5825
         * @return array|IXR_Error
5424
5826
         */
5425
 
        public function mt_getCategoryList($args) {
5426
 
 
5427
 
                $this->escape($args);
5428
 
 
5429
 
                $username  = $args[1];
5430
 
                $password   = $args[2];
 
5827
        public function mt_getCategoryList( $args ) {
 
5828
                $this->escape( $args );
 
5829
 
 
5830
                $username = $args[1];
 
5831
                $password = $args[2];
5431
5832
 
5432
5833
                if ( !$user = $this->login($username, $password) )
5433
5834
                        return $this->error;
5458
5859
         *
5459
5860
         * @since 1.5.0
5460
5861
         *
5461
 
         * @param array $args Method parameters.
 
5862
         * @param array  $args {
 
5863
         *     Method arguments. Note: arguments must be ordered as documented.
 
5864
         *
 
5865
         *     @type int    $post_ID
 
5866
         *     @type string $username
 
5867
         *     @type string $password
 
5868
         * }
5462
5869
         * @return array|IXR_Error
5463
5870
         */
5464
 
        public function mt_getPostCategories($args) {
5465
 
 
5466
 
                $this->escape($args);
5467
 
 
5468
 
                $post_ID     = (int) $args[0];
5469
 
                $username  = $args[1];
5470
 
                $password   = $args[2];
 
5871
        public function mt_getPostCategories( $args ) {
 
5872
                $this->escape( $args );
 
5873
 
 
5874
                $post_ID  = (int) $args[0];
 
5875
                $username = $args[1];
 
5876
                $password = $args[2];
5471
5877
 
5472
5878
                if ( !$user = $this->login($username, $password) )
5473
5879
                        return $this->error;
5502
5908
         *
5503
5909
         * @since 1.5.0
5504
5910
         *
5505
 
         * @param array $args Method parameters.
5506
 
         * @return bool|IXR_Error True on success.
 
5911
         * @param array  $args {
 
5912
         *     Method arguments. Note: arguments must be ordered as documented.
 
5913
         *
 
5914
         *     @type int    $post_ID
 
5915
         *     @type string $username
 
5916
         *     @type string $password
 
5917
         *     @type array  $categories
 
5918
         * }
 
5919
         * @return true|IXR_Error True on success.
5507
5920
         */
5508
 
        public function mt_setPostCategories($args) {
5509
 
 
5510
 
                $this->escape($args);
5511
 
 
5512
 
                $post_ID     = (int) $args[0];
5513
 
                $username  = $args[1];
 
5921
        public function mt_setPostCategories( $args ) {
 
5922
                $this->escape( $args );
 
5923
 
 
5924
                $post_ID    = (int) $args[0];
 
5925
                $username   = $args[1];
5514
5926
                $password   = $args[2];
5515
 
                $categories  = $args[3];
 
5927
                $categories = $args[3];
5516
5928
 
5517
5929
                if ( !$user = $this->login($username, $password) )
5518
5930
                        return $this->error;
5541
5953
         *
5542
5954
         * @since 1.5.0
5543
5955
         *
5544
 
         * @param array $args Method parameters.
5545
5956
         * @return array
5546
5957
         */
5547
 
        public function mt_supportedMethods($args) {
5548
 
 
 
5958
        public function mt_supportedMethods() {
5549
5959
                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
5550
5960
                do_action( 'xmlrpc_call', 'mt.supportedMethods' );
5551
5961
 
5552
 
                $supported_methods = array();
5553
 
                foreach ( $this->methods as $key => $value ) {
5554
 
                        $supported_methods[] = $key;
5555
 
                }
5556
 
 
5557
 
                return $supported_methods;
 
5962
                return array_keys( $this->methods );
5558
5963
        }
5559
5964
 
5560
5965
        /**
5561
5966
         * Retrieve an empty array because we don't support per-post text filters.
5562
5967
         *
5563
5968
         * @since 1.5.0
5564
 
         *
5565
 
         * @param array $args Method parameters.
5566
5969
         */
5567
 
        public function mt_supportedTextFilters($args) {
 
5970
        public function mt_supportedTextFilters() {
5568
5971
                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
5569
5972
                do_action( 'xmlrpc_call', 'mt.supportedTextFilters' );
5570
5973
 
5583
5986
         *
5584
5987
         * @since 1.5.0
5585
5988
         *
5586
 
         * @param array $args Method parameters.
 
5989
         * @global wpdb $wpdb
 
5990
         *
 
5991
         * @param int $post_ID
5587
5992
         * @return array|IXR_Error
5588
5993
         */
5589
 
        public function mt_getTrackbackPings($args) {
5590
 
 
 
5994
        public function mt_getTrackbackPings( $post_ID ) {
5591
5995
                global $wpdb;
5592
5996
 
5593
 
                $post_ID = intval($args);
5594
 
 
5595
5997
                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
5596
5998
                do_action( 'xmlrpc_call', 'mt.getTrackbackPings' );
5597
5999
 
5626
6028
         *
5627
6029
         * @since 1.5.0
5628
6030
         *
5629
 
         * @param array $args Method parameters.
 
6031
         * @param array  $args {
 
6032
         *     Method arguments. Note: arguments must be ordered as documented.
 
6033
         *
 
6034
         *     @type int    $post_ID
 
6035
         *     @type string $username
 
6036
         *     @type string $password
 
6037
         * }
5630
6038
         * @return int|IXR_Error
5631
6039
         */
5632
 
        public function mt_publishPost($args) {
5633
 
 
5634
 
                $this->escape($args);
5635
 
 
5636
 
                $post_ID     = (int) $args[0];
5637
 
                $username  = $args[1];
5638
 
                $password   = $args[2];
 
6040
        public function mt_publishPost( $args ) {
 
6041
                $this->escape( $args );
 
6042
 
 
6043
                $post_ID  = (int) $args[0];
 
6044
                $username = $args[1];
 
6045
                $password = $args[2];
5639
6046
 
5640
6047
                if ( !$user = $this->login($username, $password) )
5641
6048
                        return $this->error;
5657
6064
                $postdata['post_category'] = $cats;
5658
6065
                $this->escape($postdata);
5659
6066
 
5660
 
                $result = wp_update_post($postdata);
5661
 
 
5662
 
                return $result;
 
6067
                return wp_update_post( $postdata );
5663
6068
        }
5664
6069
 
5665
6070
        /* PingBack functions
5671
6076
         *
5672
6077
         * @since 1.5.0
5673
6078
         *
5674
 
         * @param array $args Method parameters.
 
6079
         * @global wpdb $wpdb
 
6080
         * @global string $wp_version
 
6081
         *
 
6082
         * @param array  $args {
 
6083
         *     Method arguments. Note: arguments must be ordered as documented.
 
6084
         *
 
6085
         *     @type string $pagelinkedfrom
 
6086
         *     @type string $pagelinkedto
 
6087
         * }
5675
6088
         * @return string|IXR_Error
5676
6089
         */
5677
 
        public function pingback_ping($args) {
5678
 
                global $wpdb;
 
6090
        public function pingback_ping( $args ) {
 
6091
                global $wpdb, $wp_version;
5679
6092
 
5680
6093
                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
5681
6094
                do_action( 'xmlrpc_call', 'pingback.ping' );
5682
6095
 
5683
 
                $this->escape($args);
5684
 
 
5685
 
                $pagelinkedfrom = $args[0];
5686
 
                $pagelinkedto   = $args[1];
5687
 
 
5688
 
                $pagelinkedfrom = str_replace('&amp;', '&', $pagelinkedfrom);
5689
 
                $pagelinkedto = str_replace('&amp;', '&', $pagelinkedto);
5690
 
                $pagelinkedto = str_replace('&', '&amp;', $pagelinkedto);
 
6096
                $this->escape( $args );
 
6097
 
 
6098
                $pagelinkedfrom = str_replace( '&amp;', '&', $args[0] );
 
6099
                $pagelinkedto = str_replace( '&amp;', '&', $args[1] );
 
6100
                $pagelinkedto = str_replace( '&', '&amp;', $pagelinkedto );
5691
6101
 
5692
6102
                /**
5693
6103
                 * Filter the pingback source URI.
5766
6176
                $remote_ip = preg_replace( '/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR'] );
5767
6177
 
5768
6178
                /** This filter is documented in wp-includes/class-http.php */
5769
 
                $user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . $GLOBALS['wp_version'] . '; ' . get_bloginfo( 'url' ) );
 
6179
                $user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . get_bloginfo( 'url' ) );
5770
6180
 
5771
6181
                // Let's check the remote site
5772
6182
                $http_api_args = array(
5877
6287
         *
5878
6288
         * @since 1.5.0
5879
6289
         *
5880
 
         * @param array $args Method parameters.
 
6290
         * @global wpdb $wpdb
 
6291
         *
 
6292
         * @param string $url
5881
6293
         * @return array|IXR_Error
5882
6294
         */
5883
 
        public function pingback_extensions_getPingbacks($args) {
5884
 
 
 
6295
        public function pingback_extensions_getPingbacks( $url ) {
5885
6296
                global $wpdb;
5886
6297
 
5887
6298
                /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */
5888
6299
                do_action( 'xmlrpc_call', 'pingback.extensions.getPingbacks' );
5889
6300
 
5890
 
                $this->escape($args);
5891
 
 
5892
 
                $url = $args;
 
6301
                $url = $this->escape( $url );
5893
6302
 
5894
6303
                $post_ID = url_to_postid($url);
5895
6304
                if ( !$post_ID ) {
5921
6330
        /**
5922
6331
         * @param integer $code
5923
6332
         * @param string $message
 
6333
         * @return IXR_Error
5924
6334
         */
5925
6335
        protected function pingback_error( $code, $message ) {
5926
6336
                /**