12 * Implements compatibility for Blogger API, MetaWeblog API, MovableType, and |
12 * Implements compatibility for Blogger API, MetaWeblog API, MovableType, and |
13 * pingback. Additional WordPress API for managing comments, pages, posts, |
13 * pingback. Additional WordPress API for managing comments, pages, posts, |
14 * options, etc. |
14 * options, etc. |
15 * |
15 * |
16 * As of WordPress 3.5.0, XML-RPC is enabled by default. It can be disabled |
16 * As of WordPress 3.5.0, XML-RPC is enabled by default. It can be disabled |
17 * via the xmlrpc_enabled filter found in wp_xmlrpc_server::login(). |
17 * via the {@see 'xmlrpc_enabled'} filter found in wp_xmlrpc_server::login(). |
18 * |
18 * |
19 * @package WordPress |
|
20 * @subpackage Publishing |
|
21 * @since 1.5.0 |
19 * @since 1.5.0 |
|
20 * |
|
21 * @see IXR_Server |
22 */ |
22 */ |
23 class wp_xmlrpc_server extends IXR_Server { |
23 class wp_xmlrpc_server extends IXR_Server { |
24 /** |
24 /** |
|
25 * Methods. |
|
26 * |
25 * @var array |
27 * @var array |
26 */ |
28 */ |
27 public $methods; |
29 public $methods; |
28 /** |
30 |
|
31 /** |
|
32 * Blog options. |
|
33 * |
29 * @var array |
34 * @var array |
30 */ |
35 */ |
31 public $blog_options; |
36 public $blog_options; |
32 /** |
37 |
|
38 /** |
|
39 * IXR_Error instance. |
|
40 * |
33 * @var IXR_Error |
41 * @var IXR_Error |
34 */ |
42 */ |
35 public $error; |
43 public $error; |
36 /** |
44 |
37 * Register all of the XMLRPC methods that XMLRPC server understands. |
45 /** |
|
46 * Flags that the user authentication has failed in this instance of wp_xmlrpc_server. |
|
47 * |
|
48 * @var bool |
|
49 */ |
|
50 protected $auth_failed = false; |
|
51 |
|
52 /** |
|
53 * Registers all of the XMLRPC methods that XMLRPC server understands. |
38 * |
54 * |
39 * Sets up server and method property. Passes XMLRPC |
55 * Sets up server and method property. Passes XMLRPC |
40 * methods through the 'xmlrpc_methods' filter to allow plugins to extend |
56 * methods through the {@see 'xmlrpc_methods'} filter to allow plugins to extend |
41 * or replace XMLRPC methods. |
57 * or replace XML-RPC methods. |
42 * |
58 * |
43 * @since 1.5.0 |
59 * @since 1.5.0 |
44 */ |
60 */ |
45 public function __construct() { |
61 public function __construct() { |
46 $this->methods = array( |
62 $this->methods = array( |
149 */ |
165 */ |
150 $this->methods = apply_filters( 'xmlrpc_methods', $this->methods ); |
166 $this->methods = apply_filters( 'xmlrpc_methods', $this->methods ); |
151 } |
167 } |
152 |
168 |
153 /** |
169 /** |
154 * Make private/protected methods readable for backwards compatibility. |
170 * Make private/protected methods readable for backward compatibility. |
155 * |
171 * |
156 * @since 4.0.0 |
172 * @since 4.0.0 |
157 * @access public |
|
158 * |
173 * |
159 * @param callable $name Method to call. |
174 * @param callable $name Method to call. |
160 * @param array $arguments Arguments to pass when calling. |
175 * @param array $arguments Arguments to pass when calling. |
161 * @return mixed|bool Return value of the callback, false otherwise. |
176 * @return array|IXR_Error|false Return value of the callback, false otherwise. |
162 */ |
177 */ |
163 public function __call( $name, $arguments ) { |
178 public function __call( $name, $arguments ) { |
164 if ( '_multisite_getUsersBlogs' === $name ) { |
179 if ( '_multisite_getUsersBlogs' === $name ) { |
165 return call_user_func_array( array( $this, $name ), $arguments ); |
180 return call_user_func_array( array( $this, $name ), $arguments ); |
166 } |
181 } |
167 return false; |
182 return false; |
168 } |
183 } |
169 |
184 |
|
185 /** |
|
186 * Serves the XML-RPC request. |
|
187 * |
|
188 * @since 2.9.0 |
|
189 */ |
170 public function serve_request() { |
190 public function serve_request() { |
171 $this->IXR_Server($this->methods); |
191 $this->IXR_Server($this->methods); |
172 } |
192 } |
173 |
193 |
174 /** |
194 /** |
175 * Test XMLRPC API by saying, "Hello!" to client. |
195 * Test XMLRPC API by saying, "Hello!" to client. |
176 * |
196 * |
177 * @since 1.5.0 |
197 * @since 1.5.0 |
178 * |
198 * |
179 * @param array $args Method Parameters. |
199 * @return string Hello string response. |
180 * @return string |
200 */ |
181 */ |
201 public function sayHello() { |
182 public function sayHello($args) { |
|
183 return 'Hello!'; |
202 return 'Hello!'; |
184 } |
203 } |
185 |
204 |
186 /** |
205 /** |
187 * Test XMLRPC API by adding two numbers for client. |
206 * Test XMLRPC API by adding two numbers for client. |
188 * |
207 * |
189 * @since 1.5.0 |
208 * @since 1.5.0 |
190 * |
209 * |
191 * @param array $args Method Parameters. |
210 * @param array $args { |
192 * @return int |
211 * Method arguments. Note: arguments must be ordered as documented. |
193 */ |
212 * |
194 public function addTwoNumbers($args) { |
213 * @type int $number1 A number to add. |
|
214 * @type int $number2 A second number to add. |
|
215 * } |
|
216 * @return int Sum of the two given numbers. |
|
217 */ |
|
218 public function addTwoNumbers( $args ) { |
195 $number1 = $args[0]; |
219 $number1 = $args[0]; |
196 $number2 = $args[1]; |
220 $number2 = $args[1]; |
197 return $number1 + $number2; |
221 return $number1 + $number2; |
198 } |
222 } |
199 |
223 |
347 } |
396 } |
348 } |
397 } |
349 } |
398 } |
350 |
399 |
351 /** |
400 /** |
|
401 * Retrieve custom fields for a term. |
|
402 * |
|
403 * @since 4.9.0 |
|
404 * |
|
405 * @param int $term_id Term ID. |
|
406 * @return array Array of custom fields, if they exist. |
|
407 */ |
|
408 public function get_term_custom_fields( $term_id ) { |
|
409 $term_id = (int) $term_id; |
|
410 |
|
411 $custom_fields = array(); |
|
412 |
|
413 foreach ( (array) has_term_meta( $term_id ) as $meta ) { |
|
414 |
|
415 if ( ! current_user_can( 'edit_term_meta', $term_id ) ) { |
|
416 continue; |
|
417 } |
|
418 |
|
419 $custom_fields[] = array( |
|
420 'id' => $meta['meta_id'], |
|
421 'key' => $meta['meta_key'], |
|
422 'value' => $meta['meta_value'], |
|
423 ); |
|
424 } |
|
425 |
|
426 return $custom_fields; |
|
427 } |
|
428 |
|
429 /** |
|
430 * Set custom fields for a term. |
|
431 * |
|
432 * @since 4.9.0 |
|
433 * |
|
434 * @param int $term_id Term ID. |
|
435 * @param array $fields Custom fields. |
|
436 */ |
|
437 public function set_term_custom_fields( $term_id, $fields ) { |
|
438 $term_id = (int) $term_id; |
|
439 |
|
440 foreach ( (array) $fields as $meta ) { |
|
441 if ( isset( $meta['id'] ) ) { |
|
442 $meta['id'] = (int) $meta['id']; |
|
443 $pmeta = get_metadata_by_mid( 'term', $meta['id'] ); |
|
444 if ( isset( $meta['key'] ) ) { |
|
445 $meta['key'] = wp_unslash( $meta['key'] ); |
|
446 if ( $meta['key'] !== $pmeta->meta_key ) { |
|
447 continue; |
|
448 } |
|
449 $meta['value'] = wp_unslash( $meta['value'] ); |
|
450 if ( current_user_can( 'edit_term_meta', $term_id ) ) { |
|
451 update_metadata_by_mid( 'term', $meta['id'], $meta['value'] ); |
|
452 } |
|
453 } elseif ( current_user_can( 'delete_term_meta', $term_id ) ) { |
|
454 delete_metadata_by_mid( 'term', $meta['id'] ); |
|
455 } |
|
456 } elseif ( current_user_can( 'add_term_meta', $term_id ) ) { |
|
457 add_term_meta( $term_id, $meta['key'], $meta['value'] ); |
|
458 } |
|
459 } |
|
460 } |
|
461 |
|
462 /** |
352 * Set up blog options property. |
463 * Set up blog options property. |
353 * |
464 * |
354 * Passes property through 'xmlrpc_blog_options' filter. |
465 * Passes property through {@see 'xmlrpc_blog_options'} filter. |
355 * |
466 * |
356 * @since 2.6.0 |
467 * @since 2.6.0 |
357 */ |
468 */ |
358 public function initialise_blog_option_info() { |
469 public function initialise_blog_option_info() { |
359 global $wp_version; |
|
360 |
|
361 $this->blog_options = array( |
470 $this->blog_options = array( |
362 // Read only options |
471 // Read only options |
363 'software_name' => array( |
472 'software_name' => array( |
364 'desc' => __( 'Software Name' ), |
473 'desc' => __( 'Software Name' ), |
365 'readonly' => true, |
474 'readonly' => true, |
366 'value' => 'WordPress' |
475 'value' => 'WordPress' |
367 ), |
476 ), |
368 'software_version' => array( |
477 'software_version' => array( |
369 'desc' => __( 'Software Version' ), |
478 'desc' => __( 'Software Version' ), |
370 'readonly' => true, |
479 'readonly' => true, |
371 'value' => $wp_version |
480 'value' => get_bloginfo( 'version' ) |
372 ), |
481 ), |
373 'blog_url' => array( |
482 'blog_url' => array( |
374 'desc' => __( 'WordPress Address (URL)' ), |
483 'desc' => __( 'WordPress Address (URL)' ), |
375 'readonly' => true, |
484 'readonly' => true, |
376 'option' => 'siteurl' |
485 'option' => 'siteurl' |
546 * All built-in XML-RPC methods use the action xmlrpc_call, with a parameter |
673 * All built-in XML-RPC methods use the action xmlrpc_call, with a parameter |
547 * equal to the method's name, e.g., wp.getUsersBlogs, wp.newPost, etc. |
674 * equal to the method's name, e.g., wp.getUsersBlogs, wp.newPost, etc. |
548 * |
675 * |
549 * @since 2.5.0 |
676 * @since 2.5.0 |
550 * |
677 * |
551 * @param method $name The method name. |
678 * @param string $name The method name. |
552 */ |
679 */ |
553 do_action( 'xmlrpc_call', 'wp.getUsersBlogs' ); |
680 do_action( 'xmlrpc_call', 'wp.getUsersBlogs' ); |
554 |
681 |
555 $blogs = (array) get_blogs_of_user( $user->ID ); |
682 $blogs = (array) get_blogs_of_user( $user->ID ); |
556 $struct = array(); |
683 $struct = array(); |
|
684 $primary_blog_id = 0; |
|
685 $active_blog = get_active_blog_for_user( $user->ID ); |
|
686 if ( $active_blog ) { |
|
687 $primary_blog_id = (int) $active_blog->blog_id; |
|
688 } |
557 |
689 |
558 foreach ( $blogs as $blog ) { |
690 foreach ( $blogs as $blog ) { |
559 // Don't include blogs that aren't hosted at this site |
691 // Don't include blogs that aren't hosted at this site. |
560 if ( $blog->site_id != get_current_site()->id ) |
692 if ( $blog->site_id != get_current_network_id() ) |
561 continue; |
693 continue; |
562 |
694 |
563 $blog_id = $blog->userblog_id; |
695 $blog_id = $blog->userblog_id; |
564 |
696 |
565 switch_to_blog( $blog_id ); |
697 switch_to_blog( $blog_id ); |
566 |
698 |
567 $is_admin = current_user_can( 'manage_options' ); |
699 $is_admin = current_user_can( 'manage_options' ); |
|
700 $is_primary = ( (int) $blog_id === $primary_blog_id ); |
568 |
701 |
569 $struct[] = array( |
702 $struct[] = array( |
570 'isAdmin' => $is_admin, |
703 'isAdmin' => $is_admin, |
571 'url' => home_url( '/' ), |
704 'isPrimary' => $is_primary, |
572 'blogid' => (string) $blog_id, |
705 'url' => home_url( '/' ), |
573 'blogName' => get_option( 'blogname' ), |
706 'blogid' => (string) $blog_id, |
574 'xmlrpc' => site_url( 'xmlrpc.php', 'rpc' ), |
707 'blogName' => get_option( 'blogname' ), |
|
708 'xmlrpc' => site_url( 'xmlrpc.php', 'rpc' ), |
575 ); |
709 ); |
576 |
710 |
577 restore_current_blog(); |
711 restore_current_blog(); |
578 } |
712 } |
579 |
713 |
628 |
761 |
629 if ( in_array( 'object_type', $fields ) ) |
762 if ( in_array( 'object_type', $fields ) ) |
630 $_taxonomy['object_type'] = array_unique( (array) $taxonomy->object_type ); |
763 $_taxonomy['object_type'] = array_unique( (array) $taxonomy->object_type ); |
631 |
764 |
632 /** |
765 /** |
633 * Filter XML-RPC-prepared data for the given taxonomy. |
766 * Filters XML-RPC-prepared data for the given taxonomy. |
634 * |
767 * |
635 * @since 3.4.0 |
768 * @since 3.4.0 |
636 * |
769 * |
637 * @param array $_taxonomy An array of taxonomy data. |
770 * @param array $_taxonomy An array of taxonomy data. |
638 * @param object $taxonomy Taxonomy object. |
771 * @param WP_Taxonomy $taxonomy Taxonomy object. |
639 * @param array $fields The subset of taxonomy fields to return. |
772 * @param array $fields The subset of taxonomy fields to return. |
640 */ |
773 */ |
641 return apply_filters( 'xmlrpc_prepare_taxonomy', $_taxonomy, $taxonomy, $fields ); |
774 return apply_filters( 'xmlrpc_prepare_taxonomy', $_taxonomy, $taxonomy, $fields ); |
642 } |
775 } |
643 |
776 |
644 /** |
777 /** |
645 * Prepares term data for return in an XML-RPC object. |
778 * Prepares term data for return in an XML-RPC object. |
646 * |
779 * |
647 * @access protected |
780 * |
648 * |
781 * @param array|object $term The unprepared term data. |
649 * @param array|object $term The unprepared term data |
782 * @return array The prepared term data. |
650 * @return array The prepared term data |
|
651 */ |
783 */ |
652 protected function _prepare_term( $term ) { |
784 protected function _prepare_term( $term ) { |
653 $_term = $term; |
785 $_term = $term; |
654 if ( ! is_array( $_term) ) |
786 if ( ! is_array( $_term ) ) |
655 $_term = get_object_vars( $_term ); |
787 $_term = get_object_vars( $_term ); |
656 |
788 |
657 // For integers which may be larger than XML-RPC supports ensure we return strings. |
789 // For integers which may be larger than XML-RPC supports ensure we return strings. |
658 $_term['term_id'] = strval( $_term['term_id'] ); |
790 $_term['term_id'] = strval( $_term['term_id'] ); |
659 $_term['term_group'] = strval( $_term['term_group'] ); |
791 $_term['term_group'] = strval( $_term['term_group'] ); |
706 } |
839 } |
707 |
840 |
708 /** |
841 /** |
709 * Prepares post data for return in an XML-RPC object. |
842 * Prepares post data for return in an XML-RPC object. |
710 * |
843 * |
711 * @access protected |
844 * |
712 * |
845 * @param array $post The unprepared post data. |
713 * @param array $post The unprepared post data |
846 * @param array $fields The subset of post type fields to return. |
714 * @param array $fields The subset of post type fields to return |
847 * @return array The prepared post data. |
715 * @return array The prepared post data |
|
716 */ |
848 */ |
717 protected function _prepare_post( $post, $fields ) { |
849 protected function _prepare_post( $post, $fields ) { |
718 // holds the data for this post. built up based on $fields |
850 // Holds the data for this post. built up based on $fields. |
719 $_post = array( 'post_id' => strval( $post['ID'] ) ); |
851 $_post = array( 'post_id' => strval( $post['ID'] ) ); |
720 |
852 |
721 // prepare common post fields |
853 // Prepare common post fields. |
722 $post_fields = array( |
854 $post_fields = array( |
723 'post_title' => $post['post_title'], |
855 'post_title' => $post['post_title'], |
724 'post_date' => $this->_convert_date( $post['post_date'] ), |
856 'post_date' => $this->_convert_date( $post['post_date'] ), |
725 'post_date_gmt' => $this->_convert_date_gmt( $post['post_date_gmt'], $post['post_date'] ), |
857 'post_date_gmt' => $this->_convert_date_gmt( $post['post_date_gmt'], $post['post_date'] ), |
726 'post_modified' => $this->_convert_date( $post['post_modified'] ), |
858 'post_modified' => $this->_convert_date( $post['post_modified'] ), |
732 'post_password' => $post['post_password'], |
864 'post_password' => $post['post_password'], |
733 'post_excerpt' => $post['post_excerpt'], |
865 'post_excerpt' => $post['post_excerpt'], |
734 'post_content' => $post['post_content'], |
866 'post_content' => $post['post_content'], |
735 'post_parent' => strval( $post['post_parent'] ), |
867 'post_parent' => strval( $post['post_parent'] ), |
736 'post_mime_type' => $post['post_mime_type'], |
868 'post_mime_type' => $post['post_mime_type'], |
737 'link' => post_permalink( $post['ID'] ), |
869 'link' => get_permalink( $post['ID'] ), |
738 'guid' => $post['guid'], |
870 'guid' => $post['guid'], |
739 'menu_order' => intval( $post['menu_order'] ), |
871 'menu_order' => intval( $post['menu_order'] ), |
740 'comment_status' => $post['comment_status'], |
872 'comment_status' => $post['comment_status'], |
741 'ping_status' => $post['ping_status'], |
873 'ping_status' => $post['ping_status'], |
742 'sticky' => ( $post['post_type'] === 'post' && is_sticky( $post['ID'] ) ), |
874 'sticky' => ( $post['post_type'] === 'post' && is_sticky( $post['ID'] ) ), |
743 ); |
875 ); |
744 |
876 |
745 // Thumbnail |
877 // Thumbnail. |
746 $post_fields['post_thumbnail'] = array(); |
878 $post_fields['post_thumbnail'] = array(); |
747 $thumbnail_id = get_post_thumbnail_id( $post['ID'] ); |
879 $thumbnail_id = get_post_thumbnail_id( $post['ID'] ); |
748 if ( $thumbnail_id ) { |
880 if ( $thumbnail_id ) { |
749 $thumbnail_size = current_theme_supports('post-thumbnail') ? 'post-thumbnail' : 'thumbnail'; |
881 $thumbnail_size = current_theme_supports('post-thumbnail') ? 'post-thumbnail' : 'thumbnail'; |
750 $post_fields['post_thumbnail'] = $this->_prepare_media_item( get_post( $thumbnail_id ), $thumbnail_size ); |
882 $post_fields['post_thumbnail'] = $this->_prepare_media_item( get_post( $thumbnail_id ), $thumbnail_size ); |
751 } |
883 } |
752 |
884 |
753 // Consider future posts as published |
885 // Consider future posts as published. |
754 if ( $post_fields['post_status'] === 'future' ) |
886 if ( $post_fields['post_status'] === 'future' ) |
755 $post_fields['post_status'] = 'publish'; |
887 $post_fields['post_status'] = 'publish'; |
756 |
888 |
757 // Fill in blank post format |
889 // Fill in blank post format. |
758 $post_fields['post_format'] = get_post_format( $post['ID'] ); |
890 $post_fields['post_format'] = get_post_format( $post['ID'] ); |
759 if ( empty( $post_fields['post_format'] ) ) |
891 if ( empty( $post_fields['post_format'] ) ) |
760 $post_fields['post_format'] = 'standard'; |
892 $post_fields['post_format'] = 'standard'; |
761 |
893 |
762 // Merge requested $post_fields fields into $_post |
894 // Merge requested $post_fields fields into $_post. |
763 if ( in_array( 'post', $fields ) ) { |
895 if ( in_array( 'post', $fields ) ) { |
764 $_post = array_merge( $_post, $post_fields ); |
896 $_post = array_merge( $_post, $post_fields ); |
765 } else { |
897 } else { |
766 $requested_fields = array_intersect_key( $post_fields, array_flip( $fields ) ); |
898 $requested_fields = array_intersect_key( $post_fields, array_flip( $fields ) ); |
767 $_post = array_merge( $_post, $requested_fields ); |
899 $_post = array_merge( $_post, $requested_fields ); |
842 |
975 |
843 if ( in_array( 'taxonomies', $fields ) ) |
976 if ( in_array( 'taxonomies', $fields ) ) |
844 $_post_type['taxonomies'] = get_object_taxonomies( $post_type->name, 'names' ); |
977 $_post_type['taxonomies'] = get_object_taxonomies( $post_type->name, 'names' ); |
845 |
978 |
846 /** |
979 /** |
847 * Filter XML-RPC-prepared date for the given post type. |
980 * Filters XML-RPC-prepared date for the given post type. |
848 * |
981 * |
849 * @since 3.4.0 |
982 * @since 3.4.0 |
850 * |
983 * @since 4.6.0 Converted the `$post_type` parameter to accept a WP_Post_Type object. |
851 * @param array $_post_type An array of post type data. |
984 * |
852 * @param object $post_type Post type object. |
985 * @param array $_post_type An array of post type data. |
|
986 * @param WP_Post_Type $post_type Post type object. |
853 */ |
987 */ |
854 return apply_filters( 'xmlrpc_prepare_post_type', $_post_type, $post_type ); |
988 return apply_filters( 'xmlrpc_prepare_post_type', $_post_type, $post_type ); |
855 } |
989 } |
856 |
990 |
857 /** |
991 /** |
858 * Prepares media item data for return in an XML-RPC object. |
992 * Prepares media item data for return in an XML-RPC object. |
859 * |
993 * |
860 * @access protected |
994 * |
861 * |
995 * @param object $media_item The unprepared media item data. |
862 * @param object $media_item The unprepared media item data |
996 * @param string $thumbnail_size The image size to use for the thumbnail URL. |
863 * @param string $thumbnail_size The image size to use for the thumbnail URL |
997 * @return array The prepared media item data. |
864 * @return array The prepared media item data |
|
865 */ |
998 */ |
866 protected function _prepare_media_item( $media_item, $thumbnail_size = 'thumbnail' ) { |
999 protected function _prepare_media_item( $media_item, $thumbnail_size = 'thumbnail' ) { |
867 $_media_item = array( |
1000 $_media_item = array( |
868 'attachment_id' => strval( $media_item->ID ), |
1001 'attachment_id' => strval( $media_item->ID ), |
869 'date_created_gmt' => $this->_convert_date_gmt( $media_item->post_date_gmt, $media_item->post_date ), |
1002 'date_created_gmt' => $this->_convert_date_gmt( $media_item->post_date_gmt, $media_item->post_date ), |
871 'link' => wp_get_attachment_url( $media_item->ID ), |
1004 'link' => wp_get_attachment_url( $media_item->ID ), |
872 'title' => $media_item->post_title, |
1005 'title' => $media_item->post_title, |
873 'caption' => $media_item->post_excerpt, |
1006 'caption' => $media_item->post_excerpt, |
874 'description' => $media_item->post_content, |
1007 'description' => $media_item->post_content, |
875 'metadata' => wp_get_attachment_metadata( $media_item->ID ), |
1008 'metadata' => wp_get_attachment_metadata( $media_item->ID ), |
|
1009 'type' => $media_item->post_mime_type |
876 ); |
1010 ); |
877 |
1011 |
878 $thumbnail_src = image_downsize( $media_item->ID, $thumbnail_size ); |
1012 $thumbnail_src = image_downsize( $media_item->ID, $thumbnail_size ); |
879 if ( $thumbnail_src ) |
1013 if ( $thumbnail_src ) |
880 $_media_item['thumbnail'] = $thumbnail_src[0]; |
1014 $_media_item['thumbnail'] = $thumbnail_src[0]; |
881 else |
1015 else |
882 $_media_item['thumbnail'] = $_media_item['link']; |
1016 $_media_item['thumbnail'] = $_media_item['link']; |
883 |
1017 |
884 /** |
1018 /** |
885 * Filter XML-RPC-prepared data for the given media item. |
1019 * Filters XML-RPC-prepared data for the given media item. |
886 * |
1020 * |
887 * @since 3.4.0 |
1021 * @since 3.4.0 |
888 * |
1022 * |
889 * @param array $_media_item An array of media item data. |
1023 * @param array $_media_item An array of media item data. |
890 * @param object $media_item Media item object. |
1024 * @param object $media_item Media item object. |
1011 'author_ip' => $comment->comment_author_IP, |
1143 'author_ip' => $comment->comment_author_IP, |
1012 'type' => $comment->comment_type, |
1144 'type' => $comment->comment_type, |
1013 ); |
1145 ); |
1014 |
1146 |
1015 /** |
1147 /** |
1016 * Filter XML-RPC-prepared data for the given comment. |
1148 * Filters XML-RPC-prepared data for the given comment. |
1017 * |
1149 * |
1018 * @since 3.4.0 |
1150 * @since 3.4.0 |
1019 * |
1151 * |
1020 * @param array $_comment An array of prepared comment data. |
1152 * @param array $_comment An array of prepared comment data. |
1021 * @param object $comment Comment object. |
1153 * @param WP_Comment $comment Comment object. |
1022 */ |
1154 */ |
1023 return apply_filters( 'xmlrpc_prepare_comment', $_comment, $comment ); |
1155 return apply_filters( 'xmlrpc_prepare_comment', $_comment, $comment ); |
1024 } |
1156 } |
1025 |
1157 |
1026 /** |
1158 /** |
1027 * Prepares user data for return in an XML-RPC object. |
1159 * Prepares user data for return in an XML-RPC object. |
1028 * |
1160 * |
1029 * @access protected |
1161 * |
1030 * |
1162 * @param WP_User $user The unprepared user object. |
1031 * @param WP_User $user The unprepared user object |
1163 * @param array $fields The subset of user fields to return. |
1032 * @param array $fields The subset of user fields to return |
1164 * @return array The prepared user data. |
1033 * @return array The prepared user data |
|
1034 */ |
1165 */ |
1035 protected function _prepare_user( $user, $fields ) { |
1166 protected function _prepare_user( $user, $fields ) { |
1036 $_user = array( 'user_id' => strval( $user->ID ) ); |
1167 $_user = array( 'user_id' => strval( $user->ID ) ); |
1037 |
1168 |
1038 $user_fields = array( |
1169 $user_fields = array( |
1075 /** |
1206 /** |
1076 * Create a new post for any registered post type. |
1207 * Create a new post for any registered post type. |
1077 * |
1208 * |
1078 * @since 3.4.0 |
1209 * @since 3.4.0 |
1079 * |
1210 * |
1080 * @param array $args Method parameters. Contains: |
1211 * @link https://en.wikipedia.org/wiki/RSS_enclosure for information on RSS enclosures. |
1081 * - int $blog_id (unused) |
1212 * |
1082 * - string $username |
1213 * @param array $args { |
1083 * - string $password |
1214 * Method arguments. Note: top-level arguments must be ordered as documented. |
1084 * - array $content_struct |
1215 * |
1085 * $content_struct can contain: |
1216 * @type int $blog_id Blog ID (unused). |
1086 * - post_type (default: 'post') |
1217 * @type string $username Username. |
1087 * - post_status (default: 'draft') |
1218 * @type string $password Password. |
1088 * - post_title |
1219 * @type array $content_struct { |
1089 * - post_author |
1220 * Content struct for adding a new post. See wp_insert_post() for information on |
1090 * - post_excerpt |
1221 * additional post fields |
1091 * - post_content |
1222 * |
1092 * - post_date_gmt | post_date |
1223 * @type string $post_type Post type. Default 'post'. |
1093 * - post_format |
1224 * @type string $post_status Post status. Default 'draft' |
1094 * - post_password |
1225 * @type string $post_title Post title. |
1095 * - comment_status - can be 'open' | 'closed' |
1226 * @type int $post_author Post author ID. |
1096 * - ping_status - can be 'open' | 'closed' |
1227 * @type string $post_excerpt Post excerpt. |
1097 * - sticky |
1228 * @type string $post_content Post content. |
1098 * - post_thumbnail - ID of a media item to use as the post thumbnail/featured image |
1229 * @type string $post_date_gmt Post date in GMT. |
1099 * - custom_fields - array, with each element containing 'key' and 'value' |
1230 * @type string $post_date Post date. |
1100 * - terms - array, with taxonomy names as keys and arrays of term IDs as values |
1231 * @type string $post_password Post password (20-character limit). |
1101 * - terms_names - array, with taxonomy names as keys and arrays of term names as values |
1232 * @type string $comment_status Post comment enabled status. Accepts 'open' or 'closed'. |
1102 * - enclosure |
1233 * @type string $ping_status Post ping status. Accepts 'open' or 'closed'. |
1103 * - any other fields supported by wp_insert_post() |
1234 * @type bool $sticky Whether the post should be sticky. Automatically false if |
1104 * @return string|IXR_Error post_id |
1235 * `$post_status` is 'private'. |
|
1236 * @type int $post_thumbnail ID of an image to use as the post thumbnail/featured image. |
|
1237 * @type array $custom_fields Array of meta key/value pairs to add to the post. |
|
1238 * @type array $terms Associative array with taxonomy names as keys and arrays |
|
1239 * of term IDs as values. |
|
1240 * @type array $terms_names Associative array with taxonomy names as keys and arrays |
|
1241 * of term names as values. |
|
1242 * @type array $enclosure { |
|
1243 * Array of feed enclosure data to add to post meta. |
|
1244 * |
|
1245 * @type string $url URL for the feed enclosure. |
|
1246 * @type int $length Size in bytes of the enclosure. |
|
1247 * @type string $type Mime-type for the enclosure. |
|
1248 * } |
|
1249 * } |
|
1250 * } |
|
1251 * @return int|IXR_Error Post ID on success, IXR_Error instance otherwise. |
1105 */ |
1252 */ |
1106 public function wp_newPost( $args ) { |
1253 public function wp_newPost( $args ) { |
1107 if ( ! $this->minimum_args( $args, 4 ) ) |
1254 if ( ! $this->minimum_args( $args, 4 ) ) |
1108 return $this->error; |
1255 return $this->error; |
1109 |
1256 |
1149 private function _is_greater_than_one( $count ) { |
1296 private function _is_greater_than_one( $count ) { |
1150 return $count > 1; |
1297 return $count > 1; |
1151 } |
1298 } |
1152 |
1299 |
1153 /** |
1300 /** |
1154 * Helper method for wp_newPost and wp_editPost, containing shared logic. |
1301 * Encapsulate the logic for sticking a post |
|
1302 * and determining if the user has permission to do so |
|
1303 * |
|
1304 * @since 4.3.0 |
|
1305 * |
|
1306 * @param array $post_data |
|
1307 * @param bool $update |
|
1308 * @return void|IXR_Error |
|
1309 */ |
|
1310 private function _toggle_sticky( $post_data, $update = false ) { |
|
1311 $post_type = get_post_type_object( $post_data['post_type'] ); |
|
1312 |
|
1313 // Private and password-protected posts cannot be stickied. |
|
1314 if ( 'private' === $post_data['post_status'] || ! empty( $post_data['post_password'] ) ) { |
|
1315 // Error if the client tried to stick the post, otherwise, silently unstick. |
|
1316 if ( ! empty( $post_data['sticky'] ) ) { |
|
1317 return new IXR_Error( 401, __( 'Sorry, you cannot stick a private post.' ) ); |
|
1318 } |
|
1319 |
|
1320 if ( $update ) { |
|
1321 unstick_post( $post_data['ID'] ); |
|
1322 } |
|
1323 } elseif ( isset( $post_data['sticky'] ) ) { |
|
1324 if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) { |
|
1325 return new IXR_Error( 401, __( 'Sorry, you are not allowed to make posts sticky.' ) ); |
|
1326 } |
|
1327 |
|
1328 $sticky = wp_validate_boolean( $post_data['sticky'] ); |
|
1329 if ( $sticky ) { |
|
1330 stick_post( $post_data['ID'] ); |
|
1331 } else { |
|
1332 unstick_post( $post_data['ID'] ); |
|
1333 } |
|
1334 } |
|
1335 } |
|
1336 |
|
1337 /** |
|
1338 * Helper method for wp_newPost() and wp_editPost(), containing shared logic. |
1155 * |
1339 * |
1156 * @since 3.4.0 |
1340 * @since 3.4.0 |
1157 * @uses wp_insert_post() |
1341 * |
1158 * |
1342 * @see wp_insert_post() |
1159 * @param WP_User $user The post author if post_author isn't set in $content_struct. |
1343 * |
|
1344 * @param WP_User $user The post author if post_author isn't set in $content_struct. |
1160 * @param array|IXR_Error $content_struct Post data to insert. |
1345 * @param array|IXR_Error $content_struct Post data to insert. |
|
1346 * @return IXR_Error|string |
1161 */ |
1347 */ |
1162 protected function _insert_post( $user, $content_struct ) { |
1348 protected function _insert_post( $user, $content_struct ) { |
1163 $defaults = array( 'post_status' => 'draft', 'post_type' => 'post', 'post_author' => 0, |
1349 $defaults = array( |
1164 'post_password' => '', 'post_excerpt' => '', 'post_content' => '', 'post_title' => '' ); |
1350 'post_status' => 'draft', |
1165 |
1351 'post_type' => 'post', |
1166 $post_data = wp_parse_args( $content_struct, $defaults ); |
1352 'post_author' => null, |
|
1353 'post_password' => null, |
|
1354 'post_excerpt' => null, |
|
1355 'post_content' => null, |
|
1356 'post_title' => null, |
|
1357 'post_date' => null, |
|
1358 'post_date_gmt' => null, |
|
1359 'post_format' => null, |
|
1360 'post_name' => null, |
|
1361 'post_thumbnail' => null, |
|
1362 'post_parent' => null, |
|
1363 'ping_status' => null, |
|
1364 'comment_status' => null, |
|
1365 'custom_fields' => null, |
|
1366 'terms_names' => null, |
|
1367 'terms' => null, |
|
1368 'sticky' => null, |
|
1369 'enclosure' => null, |
|
1370 'ID' => null, |
|
1371 ); |
|
1372 |
|
1373 $post_data = wp_parse_args( array_intersect_key( $content_struct, $defaults ), $defaults ); |
1167 |
1374 |
1168 $post_type = get_post_type_object( $post_data['post_type'] ); |
1375 $post_type = get_post_type_object( $post_data['post_type'] ); |
1169 if ( ! $post_type ) |
1376 if ( ! $post_type ) |
1170 return new IXR_Error( 403, __( 'Invalid post type' ) ); |
1377 return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
1171 |
1378 |
1172 $update = ! empty( $post_data['ID'] ); |
1379 $update = ! empty( $post_data['ID'] ); |
1173 |
1380 |
1174 if ( $update ) { |
1381 if ( $update ) { |
1175 if ( ! get_post( $post_data['ID'] ) ) |
1382 if ( ! get_post( $post_data['ID'] ) ) |
1187 case 'draft': |
1394 case 'draft': |
1188 case 'pending': |
1395 case 'pending': |
1189 break; |
1396 break; |
1190 case 'private': |
1397 case 'private': |
1191 if ( ! current_user_can( $post_type->cap->publish_posts ) ) |
1398 if ( ! current_user_can( $post_type->cap->publish_posts ) ) |
1192 return new IXR_Error( 401, __( 'Sorry, you are not allowed to create private posts in this post type' ) ); |
1399 return new IXR_Error( 401, __( 'Sorry, you are not allowed to create private posts in this post type.' ) ); |
1193 break; |
1400 break; |
1194 case 'publish': |
1401 case 'publish': |
1195 case 'future': |
1402 case 'future': |
1196 if ( ! current_user_can( $post_type->cap->publish_posts ) ) |
1403 if ( ! current_user_can( $post_type->cap->publish_posts ) ) |
1197 return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts in this post type' ) ); |
1404 return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish posts in this post type.' ) ); |
1198 break; |
1405 break; |
1199 default: |
1406 default: |
1200 if ( ! get_post_status_object( $post_data['post_status'] ) ) |
1407 if ( ! get_post_status_object( $post_data['post_status'] ) ) |
1201 $post_data['post_status'] = 'draft'; |
1408 $post_data['post_status'] = 'draft'; |
1202 break; |
1409 break; |
1203 } |
1410 } |
1204 |
1411 |
1205 if ( ! empty( $post_data['post_password'] ) && ! current_user_can( $post_type->cap->publish_posts ) ) |
1412 if ( ! empty( $post_data['post_password'] ) && ! current_user_can( $post_type->cap->publish_posts ) ) |
1206 return new IXR_Error( 401, __( 'Sorry, you are not allowed to create password protected posts in this post type' ) ); |
1413 return new IXR_Error( 401, __( 'Sorry, you are not allowed to create password protected posts in this post type.' ) ); |
1207 |
1414 |
1208 $post_data['post_author'] = absint( $post_data['post_author'] ); |
1415 $post_data['post_author'] = absint( $post_data['post_author'] ); |
1209 if ( ! empty( $post_data['post_author'] ) && $post_data['post_author'] != $user->ID ) { |
1416 if ( ! empty( $post_data['post_author'] ) && $post_data['post_author'] != $user->ID ) { |
1210 if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) |
1417 if ( ! current_user_can( $post_type->cap->edit_others_posts ) ) |
1211 return new IXR_Error( 401, __( 'You are not allowed to create posts as this user.' ) ); |
1418 return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) ); |
1212 |
1419 |
1213 $author = get_userdata( $post_data['post_author'] ); |
1420 $author = get_userdata( $post_data['post_author'] ); |
1214 |
1421 |
1215 if ( ! $author ) |
1422 if ( ! $author ) |
1216 return new IXR_Error( 404, __( 'Invalid author ID.' ) ); |
1423 return new IXR_Error( 404, __( 'Invalid author ID.' ) ); |
1222 unset( $post_data['comment_status'] ); |
1429 unset( $post_data['comment_status'] ); |
1223 |
1430 |
1224 if ( isset( $post_data['ping_status'] ) && $post_data['ping_status'] != 'open' && $post_data['ping_status'] != 'closed' ) |
1431 if ( isset( $post_data['ping_status'] ) && $post_data['ping_status'] != 'open' && $post_data['ping_status'] != 'closed' ) |
1225 unset( $post_data['ping_status'] ); |
1432 unset( $post_data['ping_status'] ); |
1226 |
1433 |
1227 // Do some timestamp voodoo |
1434 // Do some timestamp voodoo. |
1228 if ( ! empty( $post_data['post_date_gmt'] ) ) { |
1435 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 |
1436 // We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
1230 $dateCreated = rtrim( $post_data['post_date_gmt']->getIso(), 'Z' ) . 'Z'; |
1437 $dateCreated = rtrim( $post_data['post_date_gmt']->getIso(), 'Z' ) . 'Z'; |
1231 } elseif ( ! empty( $post_data['post_date'] ) ) { |
1438 } elseif ( ! empty( $post_data['post_date'] ) ) { |
1232 $dateCreated = $post_data['post_date']->getIso(); |
1439 $dateCreated = $post_data['post_date']->getIso(); |
1233 } |
1440 } |
1234 |
1441 |
|
1442 // Default to not flagging the post date to be edited unless it's intentional. |
|
1443 $post_data['edit_date'] = false; |
|
1444 |
1235 if ( ! empty( $dateCreated ) ) { |
1445 if ( ! empty( $dateCreated ) ) { |
1236 $post_data['post_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) ); |
1446 $post_data['post_date'] = get_date_from_gmt( iso8601_to_datetime( $dateCreated ) ); |
1237 $post_data['post_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' ); |
1447 $post_data['post_date_gmt'] = iso8601_to_datetime( $dateCreated, 'GMT' ); |
|
1448 |
|
1449 // Flag the post date to be edited. |
|
1450 $post_data['edit_date'] = true; |
1238 } |
1451 } |
1239 |
1452 |
1240 if ( ! isset( $post_data['ID'] ) ) |
1453 if ( ! isset( $post_data['ID'] ) ) |
1241 $post_data['ID'] = get_default_post_to_edit( $post_data['post_type'], true )->ID; |
1454 $post_data['ID'] = get_default_post_to_edit( $post_data['post_type'], true )->ID; |
1242 $post_ID = $post_data['ID']; |
1455 $post_ID = $post_data['ID']; |
1243 |
1456 |
1244 if ( $post_data['post_type'] == 'post' ) { |
1457 if ( $post_data['post_type'] == 'post' ) { |
1245 // Private and password-protected posts cannot be stickied. |
1458 $error = $this->_toggle_sticky( $post_data, $update ); |
1246 if ( $post_data['post_status'] == 'private' || ! empty( $post_data['post_password'] ) ) { |
1459 if ( $error ) { |
1247 // Error if the client tried to stick the post, otherwise, silently unstick. |
1460 return $error; |
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 ); |
|
1259 } |
1461 } |
1260 } |
1462 } |
1261 |
1463 |
1262 if ( isset( $post_data['post_thumbnail'] ) ) { |
1464 if ( isset( $post_data['post_thumbnail'] ) ) { |
1263 // empty value deletes, non-empty value adds/updates |
1465 // empty value deletes, non-empty value adds/updates. |
1264 if ( ! $post_data['post_thumbnail'] ) |
1466 if ( ! $post_data['post_thumbnail'] ) |
1265 delete_post_thumbnail( $post_ID ); |
1467 delete_post_thumbnail( $post_ID ); |
1266 elseif ( ! get_post( absint( $post_data['post_thumbnail'] ) ) ) |
1468 elseif ( ! get_post( absint( $post_data['post_thumbnail'] ) ) ) |
1267 return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
1469 return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
1268 set_post_thumbnail( $post_ID, $post_data['post_thumbnail'] ); |
1470 set_post_thumbnail( $post_ID, $post_data['post_thumbnail'] ); |
1273 $this->set_custom_fields( $post_ID, $post_data['custom_fields'] ); |
1475 $this->set_custom_fields( $post_ID, $post_data['custom_fields'] ); |
1274 |
1476 |
1275 if ( isset( $post_data['terms'] ) || isset( $post_data['terms_names'] ) ) { |
1477 if ( isset( $post_data['terms'] ) || isset( $post_data['terms_names'] ) ) { |
1276 $post_type_taxonomies = get_object_taxonomies( $post_data['post_type'], 'objects' ); |
1478 $post_type_taxonomies = get_object_taxonomies( $post_data['post_type'], 'objects' ); |
1277 |
1479 |
1278 // accumulate term IDs from terms and terms_names |
1480 // Accumulate term IDs from terms and terms_names. |
1279 $terms = array(); |
1481 $terms = array(); |
1280 |
1482 |
1281 // first validate the terms specified by ID |
1483 // First validate the terms specified by ID. |
1282 if ( isset( $post_data['terms'] ) && is_array( $post_data['terms'] ) ) { |
1484 if ( isset( $post_data['terms'] ) && is_array( $post_data['terms'] ) ) { |
1283 $taxonomies = array_keys( $post_data['terms'] ); |
1485 $taxonomies = array_keys( $post_data['terms'] ); |
1284 |
1486 |
1285 // validating term ids |
1487 // Validating term ids. |
1286 foreach ( $taxonomies as $taxonomy ) { |
1488 foreach ( $taxonomies as $taxonomy ) { |
1287 if ( ! array_key_exists( $taxonomy , $post_type_taxonomies ) ) |
1489 if ( ! array_key_exists( $taxonomy , $post_type_taxonomies ) ) |
1288 return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) ); |
1490 return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) ); |
1289 |
1491 |
1290 if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->assign_terms ) ) |
1492 if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->assign_terms ) ) |
1294 $terms[ $taxonomy ] = array(); |
1496 $terms[ $taxonomy ] = array(); |
1295 foreach ( $term_ids as $term_id ) { |
1497 foreach ( $term_ids as $term_id ) { |
1296 $term = get_term_by( 'id', $term_id, $taxonomy ); |
1498 $term = get_term_by( 'id', $term_id, $taxonomy ); |
1297 |
1499 |
1298 if ( ! $term ) |
1500 if ( ! $term ) |
1299 return new IXR_Error( 403, __( 'Invalid term ID' ) ); |
1501 return new IXR_Error( 403, __( 'Invalid term ID.' ) ); |
1300 |
1502 |
1301 $terms[$taxonomy][] = (int) $term_id; |
1503 $terms[$taxonomy][] = (int) $term_id; |
1302 } |
1504 } |
1303 } |
1505 } |
1304 } |
1506 } |
1305 |
1507 |
1306 // now validate terms specified by name |
1508 // Now validate terms specified by name. |
1307 if ( isset( $post_data['terms_names'] ) && is_array( $post_data['terms_names'] ) ) { |
1509 if ( isset( $post_data['terms_names'] ) && is_array( $post_data['terms_names'] ) ) { |
1308 $taxonomies = array_keys( $post_data['terms_names'] ); |
1510 $taxonomies = array_keys( $post_data['terms_names'] ); |
1309 |
1511 |
1310 foreach ( $taxonomies as $taxonomy ) { |
1512 foreach ( $taxonomies as $taxonomy ) { |
1311 if ( ! array_key_exists( $taxonomy , $post_type_taxonomies ) ) |
1513 if ( ! array_key_exists( $taxonomy , $post_type_taxonomies ) ) |
1312 return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) ); |
1514 return new IXR_Error( 401, __( 'Sorry, one of the given taxonomies is not supported by the post type.' ) ); |
1313 |
1515 |
1314 if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->assign_terms ) ) |
1516 if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->assign_terms ) ) |
1315 return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) ); |
1517 return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign a term to one of the given taxonomies.' ) ); |
1316 |
1518 |
1317 // for hierarchical taxonomies, we can't assign a term when multiple terms in the hierarchy share the same name |
1519 /* |
|
1520 * For hierarchical taxonomies, we can't assign a term when multiple terms |
|
1521 * in the hierarchy share the same name. |
|
1522 */ |
1318 $ambiguous_terms = array(); |
1523 $ambiguous_terms = array(); |
1319 if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
1524 if ( is_taxonomy_hierarchical( $taxonomy ) ) { |
1320 $tax_term_names = get_terms( $taxonomy, array( 'fields' => 'names', 'hide_empty' => false ) ); |
1525 $tax_term_names = get_terms( $taxonomy, array( 'fields' => 'names', 'hide_empty' => false ) ); |
1321 |
1526 |
1322 // count the number of terms with the same name |
1527 // Count the number of terms with the same name. |
1323 $tax_term_names_count = array_count_values( $tax_term_names ); |
1528 $tax_term_names_count = array_count_values( $tax_term_names ); |
1324 |
1529 |
1325 // filter out non-ambiguous term names |
1530 // Filter out non-ambiguous term names. |
1326 $ambiguous_tax_term_counts = array_filter( $tax_term_names_count, array( $this, '_is_greater_than_one') ); |
1531 $ambiguous_tax_term_counts = array_filter( $tax_term_names_count, array( $this, '_is_greater_than_one') ); |
1327 |
1532 |
1328 $ambiguous_terms = array_keys( $ambiguous_tax_term_counts ); |
1533 $ambiguous_terms = array_keys( $ambiguous_tax_term_counts ); |
1329 } |
1534 } |
1330 |
1535 |
1334 return new IXR_Error( 401, __( 'Ambiguous term name used in a hierarchical taxonomy. Please use term ID instead.' ) ); |
1539 return new IXR_Error( 401, __( 'Ambiguous term name used in a hierarchical taxonomy. Please use term ID instead.' ) ); |
1335 |
1540 |
1336 $term = get_term_by( 'name', $term_name, $taxonomy ); |
1541 $term = get_term_by( 'name', $term_name, $taxonomy ); |
1337 |
1542 |
1338 if ( ! $term ) { |
1543 if ( ! $term ) { |
1339 // term doesn't exist, so check that the user is allowed to create new terms |
1544 // Term doesn't exist, so check that the user is allowed to create new terms. |
1340 if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->edit_terms ) ) |
1545 if ( ! current_user_can( $post_type_taxonomies[$taxonomy]->cap->edit_terms ) ) |
1341 return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a term to one of the given taxonomies.' ) ); |
1546 return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a term to one of the given taxonomies.' ) ); |
1342 |
1547 |
1343 // create the new term |
1548 // Create the new term. |
1344 $term_info = wp_insert_term( $term_name, $taxonomy ); |
1549 $term_info = wp_insert_term( $term_name, $taxonomy ); |
1345 if ( is_wp_error( $term_info ) ) |
1550 if ( is_wp_error( $term_info ) ) |
1346 return new IXR_Error( 500, $term_info->get_error_message() ); |
1551 return new IXR_Error( 500, $term_info->get_error_message() ); |
1347 |
1552 |
1348 $terms[$taxonomy][] = (int) $term_info['term_id']; |
1553 $terms[$taxonomy][] = (int) $term_info['term_id']; |
1583 |
1801 |
1584 if ( empty( $post['ID'] ) ) |
1802 if ( empty( $post['ID'] ) ) |
1585 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
1803 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
1586 |
1804 |
1587 if ( ! current_user_can( 'edit_post', $post_id ) ) |
1805 if ( ! current_user_can( 'edit_post', $post_id ) ) |
1588 return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) ); |
1806 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
1589 |
1807 |
1590 return $this->_prepare_post( $post, $fields ); |
1808 return $this->_prepare_post( $post, $fields ); |
1591 } |
1809 } |
1592 |
1810 |
1593 /** |
1811 /** |
1594 * Retrieve posts. |
1812 * Retrieve posts. |
1595 * |
1813 * |
1596 * @since 3.4.0 |
1814 * @since 3.4.0 |
1597 * |
1815 * |
1598 * The optional $filter parameter modifies the query used to retrieve posts. |
1816 * @see wp_get_recent_posts() |
1599 * Accepted keys are 'post_type', 'post_status', 'number', 'offset', |
1817 * @see wp_getPost() for more on `$fields` |
1600 * 'orderby', and 'order'. |
1818 * @see get_posts() for more on `$filter` values |
1601 * |
1819 * |
1602 * The optional $fields parameter specifies what fields will be included |
1820 * @param array $args { |
1603 * in the response array. |
1821 * Method arguments. Note: arguments must be ordered as documented. |
1604 * |
1822 * |
1605 * @uses wp_get_recent_posts() |
1823 * @type int $blog_id Blog ID (unused). |
1606 * @see wp_getPost() for more on $fields |
1824 * @type string $username Username. |
1607 * @see get_posts() for more on $filter values |
1825 * @type string $password Password. |
1608 * |
1826 * @type array $filter Optional. Modifies the query used to retrieve posts. Accepts 'post_type', |
1609 * @param array $args Method parameters. Contains: |
1827 * 'post_status', 'number', 'offset', 'orderby', 's', and 'order'. |
1610 * - int $blog_id (unused) |
1828 * Default empty array. |
1611 * - string $username |
1829 * @type array $fields Optional. The subset of post type fields to return in the response array. |
1612 * - string $password |
1830 * } |
1613 * - array $filter optional |
|
1614 * - array $fields optional |
|
1615 * @return array|IXR_Error Array contains a collection of posts. |
1831 * @return array|IXR_Error Array contains a collection of posts. |
1616 */ |
1832 */ |
1617 public function wp_getPosts( $args ) { |
1833 public function wp_getPosts( $args ) { |
1618 if ( ! $this->minimum_args( $args, 3 ) ) |
1834 if ( ! $this->minimum_args( $args, 3 ) ) |
1619 return $this->error; |
1835 return $this->error; |
1620 |
1836 |
1621 $this->escape( $args ); |
1837 $this->escape( $args ); |
1622 |
1838 |
1623 $username = $args[1]; |
1839 $username = $args[1]; |
1624 $password = $args[2]; |
1840 $password = $args[2]; |
1625 $filter = isset( $args[3] ) ? $args[3] : array(); |
1841 $filter = isset( $args[3] ) ? $args[3] : array(); |
1626 |
1842 |
1627 if ( isset( $args[4] ) ) { |
1843 if ( isset( $args[4] ) ) { |
1628 $fields = $args[4]; |
1844 $fields = $args[4]; |
1629 } else { |
1845 } else { |
1630 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1846 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1693 /** |
1909 /** |
1694 * Create a new term. |
1910 * Create a new term. |
1695 * |
1911 * |
1696 * @since 3.4.0 |
1912 * @since 3.4.0 |
1697 * |
1913 * |
1698 * @uses wp_insert_term() |
1914 * @see wp_insert_term() |
1699 * @param array $args Method parameters. Contains: |
1915 * |
1700 * - int $blog_id (unused) |
1916 * @param array $args { |
1701 * - string $username |
1917 * Method arguments. Note: arguments must be ordered as documented. |
1702 * - string $password |
1918 * |
1703 * - array $content_struct |
1919 * @type int $blog_id Blog ID (unused). |
1704 * The $content_struct must contain: |
1920 * @type string $username Username. |
1705 * - 'name' |
1921 * @type string $password Password. |
1706 * - 'taxonomy' |
1922 * @type array $content_struct Content struct for adding a new term. The struct must contain |
1707 * Also, it can optionally contain: |
1923 * the term 'name' and 'taxonomy'. Optional accepted values include |
1708 * - 'parent' |
1924 * 'parent', 'description', and 'slug'. |
1709 * - 'description' |
1925 * } |
1710 * - 'slug' |
1926 * @return int|IXR_Error The term ID on success, or an IXR_Error object on failure. |
1711 * @return string|IXR_Error term_id |
|
1712 */ |
1927 */ |
1713 public function wp_newTerm( $args ) { |
1928 public function wp_newTerm( $args ) { |
1714 if ( ! $this->minimum_args( $args, 4 ) ) |
1929 if ( ! $this->minimum_args( $args, 4 ) ) |
1715 return $this->error; |
1930 return $this->error; |
1716 |
1931 |
1717 $this->escape( $args ); |
1932 $this->escape( $args ); |
1718 |
1933 |
1719 $username = $args[1]; |
1934 $username = $args[1]; |
1720 $password = $args[2]; |
1935 $password = $args[2]; |
1721 $content_struct = $args[3]; |
1936 $content_struct = $args[3]; |
1722 |
1937 |
1723 if ( ! $user = $this->login( $username, $password ) ) |
1938 if ( ! $user = $this->login( $username, $password ) ) |
1724 return $this->error; |
1939 return $this->error; |
1725 |
1940 |
1726 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1941 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1727 do_action( 'xmlrpc_call', 'wp.newTerm' ); |
1942 do_action( 'xmlrpc_call', 'wp.newTerm' ); |
1728 |
1943 |
1729 if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) |
1944 if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) |
1730 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
1945 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
1731 |
1946 |
1732 $taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
1947 $taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
1733 |
1948 |
1734 if ( ! current_user_can( $taxonomy->cap->manage_terms ) ) |
1949 if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) { |
1735 return new IXR_Error( 401, __( 'You are not allowed to create terms in this taxonomy.' ) ); |
1950 return new IXR_Error( 401, __( 'Sorry, you are not allowed to create terms in this taxonomy.' ) ); |
|
1951 } |
1736 |
1952 |
1737 $taxonomy = (array) $taxonomy; |
1953 $taxonomy = (array) $taxonomy; |
1738 |
1954 |
1739 // hold the data of the term |
1955 // hold the data of the term |
1740 $term_data = array(); |
1956 $term_data = array(); |
1769 |
1985 |
1770 if ( is_wp_error( $term ) ) |
1986 if ( is_wp_error( $term ) ) |
1771 return new IXR_Error( 500, $term->get_error_message() ); |
1987 return new IXR_Error( 500, $term->get_error_message() ); |
1772 |
1988 |
1773 if ( ! $term ) |
1989 if ( ! $term ) |
1774 return new IXR_Error( 500, __( 'Sorry, your term could not be created. Something wrong happened.' ) ); |
1990 return new IXR_Error( 500, __( 'Sorry, your term could not be created.' ) ); |
|
1991 |
|
1992 // Add term meta. |
|
1993 if ( isset( $content_struct['custom_fields'] ) ) { |
|
1994 $this->set_term_custom_fields( $term['term_id'], $content_struct['custom_fields'] ); |
|
1995 } |
1775 |
1996 |
1776 return strval( $term['term_id'] ); |
1997 return strval( $term['term_id'] ); |
1777 } |
1998 } |
1778 |
1999 |
1779 /** |
2000 /** |
1780 * Edit a term. |
2001 * Edit a term. |
1781 * |
2002 * |
1782 * @since 3.4.0 |
2003 * @since 3.4.0 |
1783 * |
2004 * |
1784 * @uses wp_update_term() |
2005 * @see wp_update_term() |
1785 * @param array $args Method parameters. Contains: |
2006 * |
1786 * - int $blog_id (unused) |
2007 * @param array $args { |
1787 * - string $username |
2008 * Method arguments. Note: arguments must be ordered as documented. |
1788 * - string $password |
2009 * |
1789 * - string $term_id |
2010 * @type int $blog_id Blog ID (unused). |
1790 * - array $content_struct |
2011 * @type string $username Username. |
1791 * The $content_struct must contain: |
2012 * @type string $password Password. |
1792 * - 'taxonomy' |
2013 * @type int $term_id Term ID. |
1793 * Also, it can optionally contain: |
2014 * @type array $content_struct Content struct for editing a term. The struct must contain the |
1794 * - 'name' |
2015 * term ''taxonomy'. Optional accepted values include 'name', 'parent', |
1795 * - 'parent' |
2016 * 'description', and 'slug'. |
1796 * - 'description' |
2017 * } |
1797 * - 'slug' |
2018 * @return true|IXR_Error True on success, IXR_Error instance on failure. |
1798 * @return bool|IXR_Error True, on success. |
|
1799 */ |
2019 */ |
1800 public function wp_editTerm( $args ) { |
2020 public function wp_editTerm( $args ) { |
1801 if ( ! $this->minimum_args( $args, 5 ) ) |
2021 if ( ! $this->minimum_args( $args, 5 ) ) |
1802 return $this->error; |
2022 return $this->error; |
1803 |
2023 |
1804 $this->escape( $args ); |
2024 $this->escape( $args ); |
1805 |
2025 |
1806 $username = $args[1]; |
2026 $username = $args[1]; |
1807 $password = $args[2]; |
2027 $password = $args[2]; |
1808 $term_id = (int) $args[3]; |
2028 $term_id = (int) $args[3]; |
1809 $content_struct = $args[4]; |
2029 $content_struct = $args[4]; |
1810 |
2030 |
1811 if ( ! $user = $this->login( $username, $password ) ) |
2031 if ( ! $user = $this->login( $username, $password ) ) |
1812 return $this->error; |
2032 return $this->error; |
1813 |
2033 |
1814 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2034 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1815 do_action( 'xmlrpc_call', 'wp.editTerm' ); |
2035 do_action( 'xmlrpc_call', 'wp.editTerm' ); |
1816 |
2036 |
1817 if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) |
2037 if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) |
1818 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
2038 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
1819 |
2039 |
1820 $taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
2040 $taxonomy = get_taxonomy( $content_struct['taxonomy'] ); |
1821 |
|
1822 if ( ! current_user_can( $taxonomy->cap->edit_terms ) ) |
|
1823 return new IXR_Error( 401, __( 'You are not allowed to edit terms in this taxonomy.' ) ); |
|
1824 |
2041 |
1825 $taxonomy = (array) $taxonomy; |
2042 $taxonomy = (array) $taxonomy; |
1826 |
2043 |
1827 // hold the data of the term |
2044 // hold the data of the term |
1828 $term_data = array(); |
2045 $term_data = array(); |
1831 |
2048 |
1832 if ( is_wp_error( $term ) ) |
2049 if ( is_wp_error( $term ) ) |
1833 return new IXR_Error( 500, $term->get_error_message() ); |
2050 return new IXR_Error( 500, $term->get_error_message() ); |
1834 |
2051 |
1835 if ( ! $term ) |
2052 if ( ! $term ) |
1836 return new IXR_Error( 404, __( 'Invalid term ID' ) ); |
2053 return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
|
2054 |
|
2055 if ( ! current_user_can( 'edit_term', $term_id ) ) { |
|
2056 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this term.' ) ); |
|
2057 } |
1837 |
2058 |
1838 if ( isset( $content_struct['name'] ) ) { |
2059 if ( isset( $content_struct['name'] ) ) { |
1839 $term_data['name'] = trim( $content_struct['name'] ); |
2060 $term_data['name'] = trim( $content_struct['name'] ); |
1840 |
2061 |
1841 if ( empty( $term_data['name'] ) ) |
2062 if ( empty( $term_data['name'] ) ) |
1842 return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); |
2063 return new IXR_Error( 403, __( 'The term name cannot be empty.' ) ); |
1843 } |
2064 } |
1844 |
2065 |
1845 if ( isset( $content_struct['parent'] ) ) { |
2066 if ( ! empty( $content_struct['parent'] ) ) { |
1846 if ( ! $taxonomy['hierarchical'] ) |
2067 if ( ! $taxonomy['hierarchical'] ) |
1847 return new IXR_Error( 403, __( "This taxonomy is not hierarchical so you can't set a parent." ) ); |
2068 return new IXR_Error( 403, __( 'Cannot set parent term, taxonomy is not hierarchical.' ) ); |
1848 |
2069 |
1849 $parent_term_id = (int) $content_struct['parent']; |
2070 $parent_term_id = (int) $content_struct['parent']; |
1850 $parent_term = get_term( $parent_term_id , $taxonomy['name'] ); |
2071 $parent_term = get_term( $parent_term_id , $taxonomy['name'] ); |
1851 |
2072 |
1852 if ( is_wp_error( $parent_term ) ) |
2073 if ( is_wp_error( $parent_term ) ) |
1870 return new IXR_Error( 500, $term->get_error_message() ); |
2091 return new IXR_Error( 500, $term->get_error_message() ); |
1871 |
2092 |
1872 if ( ! $term ) |
2093 if ( ! $term ) |
1873 return new IXR_Error( 500, __( 'Sorry, editing the term failed.' ) ); |
2094 return new IXR_Error( 500, __( 'Sorry, editing the term failed.' ) ); |
1874 |
2095 |
|
2096 // Update term meta. |
|
2097 if ( isset( $content_struct['custom_fields'] ) ) { |
|
2098 $this->set_term_custom_fields( $term_id, $content_struct['custom_fields'] ); |
|
2099 } |
|
2100 |
1875 return true; |
2101 return true; |
1876 } |
2102 } |
1877 |
2103 |
1878 /** |
2104 /** |
1879 * Delete a term. |
2105 * Delete a term. |
1880 * |
2106 * |
1881 * @since 3.4.0 |
2107 * @since 3.4.0 |
1882 * |
2108 * |
1883 * @uses wp_delete_term() |
2109 * @see wp_delete_term() |
1884 * @param array $args Method parameters. Contains: |
2110 * |
1885 * - int $blog_id (unused) |
2111 * @param array $args { |
1886 * - string $username |
2112 * Method arguments. Note: arguments must be ordered as documented. |
1887 * - string $password |
2113 * |
1888 * - string $taxnomy_name |
2114 * @type int $blog_id Blog ID (unused). |
1889 * - string $term_id |
2115 * @type string $username Username. |
1890 * @return boolean|IXR_Error If it suceeded true else a reason why not |
2116 * @type string $password Password. |
|
2117 * @type string $taxnomy_name Taxonomy name. |
|
2118 * @type int $term_id Term ID. |
|
2119 * } |
|
2120 * @return bool|IXR_Error True on success, IXR_Error instance on failure. |
1891 */ |
2121 */ |
1892 public function wp_deleteTerm( $args ) { |
2122 public function wp_deleteTerm( $args ) { |
1893 if ( ! $this->minimum_args( $args, 5 ) ) |
2123 if ( ! $this->minimum_args( $args, 5 ) ) |
1894 return $this->error; |
2124 return $this->error; |
1895 |
2125 |
1905 |
2135 |
1906 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2136 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1907 do_action( 'xmlrpc_call', 'wp.deleteTerm' ); |
2137 do_action( 'xmlrpc_call', 'wp.deleteTerm' ); |
1908 |
2138 |
1909 if ( ! taxonomy_exists( $taxonomy ) ) |
2139 if ( ! taxonomy_exists( $taxonomy ) ) |
1910 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
2140 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
1911 |
2141 |
1912 $taxonomy = get_taxonomy( $taxonomy ); |
2142 $taxonomy = get_taxonomy( $taxonomy ); |
1913 |
|
1914 if ( ! current_user_can( $taxonomy->cap->delete_terms ) ) |
|
1915 return new IXR_Error( 401, __( 'You are not allowed to delete terms in this taxonomy.' ) ); |
|
1916 |
|
1917 $term = get_term( $term_id, $taxonomy->name ); |
2143 $term = get_term( $term_id, $taxonomy->name ); |
1918 |
2144 |
1919 if ( is_wp_error( $term ) ) |
2145 if ( is_wp_error( $term ) ) |
1920 return new IXR_Error( 500, $term->get_error_message() ); |
2146 return new IXR_Error( 500, $term->get_error_message() ); |
1921 |
2147 |
1922 if ( ! $term ) |
2148 if ( ! $term ) |
1923 return new IXR_Error( 404, __( 'Invalid term ID' ) ); |
2149 return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
|
2150 |
|
2151 if ( ! current_user_can( 'delete_term', $term_id ) ) { |
|
2152 return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this term.' ) ); |
|
2153 } |
1924 |
2154 |
1925 $result = wp_delete_term( $term_id, $taxonomy->name ); |
2155 $result = wp_delete_term( $term_id, $taxonomy->name ); |
1926 |
2156 |
1927 if ( is_wp_error( $result ) ) |
2157 if ( is_wp_error( $result ) ) |
1928 return new IXR_Error( 500, $term->get_error_message() ); |
2158 return new IXR_Error( 500, $term->get_error_message() ); |
1972 |
2206 |
1973 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2207 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1974 do_action( 'xmlrpc_call', 'wp.getTerm' ); |
2208 do_action( 'xmlrpc_call', 'wp.getTerm' ); |
1975 |
2209 |
1976 if ( ! taxonomy_exists( $taxonomy ) ) |
2210 if ( ! taxonomy_exists( $taxonomy ) ) |
1977 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
2211 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
1978 |
2212 |
1979 $taxonomy = get_taxonomy( $taxonomy ); |
2213 $taxonomy = get_taxonomy( $taxonomy ); |
1980 |
|
1981 if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) |
|
1982 return new IXR_Error( 401, __( 'You are not allowed to assign terms in this taxonomy.' ) ); |
|
1983 |
2214 |
1984 $term = get_term( $term_id , $taxonomy->name, ARRAY_A ); |
2215 $term = get_term( $term_id , $taxonomy->name, ARRAY_A ); |
1985 |
2216 |
1986 if ( is_wp_error( $term ) ) |
2217 if ( is_wp_error( $term ) ) |
1987 return new IXR_Error( 500, $term->get_error_message() ); |
2218 return new IXR_Error( 500, $term->get_error_message() ); |
1988 |
2219 |
1989 if ( ! $term ) |
2220 if ( ! $term ) |
1990 return new IXR_Error( 404, __( 'Invalid term ID' ) ); |
2221 return new IXR_Error( 404, __( 'Invalid term ID.' ) ); |
|
2222 |
|
2223 if ( ! current_user_can( 'assign_term', $term_id ) ) { |
|
2224 return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign this term.' ) ); |
|
2225 } |
1991 |
2226 |
1992 return $this->_prepare_term( $term ); |
2227 return $this->_prepare_term( $term ); |
1993 } |
2228 } |
1994 |
2229 |
1995 /** |
2230 /** |
1998 * @since 3.4.0 |
2233 * @since 3.4.0 |
1999 * |
2234 * |
2000 * The optional $filter parameter modifies the query used to retrieve terms. |
2235 * The optional $filter parameter modifies the query used to retrieve terms. |
2001 * Accepted keys are 'number', 'offset', 'orderby', 'order', 'hide_empty', and 'search'. |
2236 * Accepted keys are 'number', 'offset', 'orderby', 'order', 'hide_empty', and 'search'. |
2002 * |
2237 * |
2003 * @uses get_terms() |
2238 * @see get_terms() |
2004 * @param array $args Method parameters. Contains: |
2239 * |
2005 * - int $blog_id (unused) |
2240 * @param array $args { |
2006 * - string $username |
2241 * Method arguments. Note: arguments must be ordered as documented. |
2007 * - string $password |
2242 * |
2008 * - string $taxonomy |
2243 * @type int $blog_id Blog ID (unused). |
2009 * - array $filter optional |
2244 * @type string $username Username. |
2010 * @return array|IXR_Error terms |
2245 * @type string $password Password. |
|
2246 * @type string $taxnomy Taxonomy name. |
|
2247 * @type array $filter Optional. Modifies the query used to retrieve posts. Accepts 'number', |
|
2248 * 'offset', 'orderby', 'order', 'hide_empty', and 'search'. Default empty array. |
|
2249 * } |
|
2250 * @return array|IXR_Error An associative array of terms data on success, IXR_Error instance otherwise. |
2011 */ |
2251 */ |
2012 public function wp_getTerms( $args ) { |
2252 public function wp_getTerms( $args ) { |
2013 if ( ! $this->minimum_args( $args, 4 ) ) |
2253 if ( ! $this->minimum_args( $args, 4 ) ) |
2014 return $this->error; |
2254 return $this->error; |
2015 |
2255 |
2074 /** |
2314 /** |
2075 * Retrieve a taxonomy. |
2315 * Retrieve a taxonomy. |
2076 * |
2316 * |
2077 * @since 3.4.0 |
2317 * @since 3.4.0 |
2078 * |
2318 * |
2079 * @uses get_taxonomy() |
2319 * @see get_taxonomy() |
2080 * @param array $args Method parameters. Contains: |
2320 * |
2081 * - int $blog_id (unused) |
2321 * @param array $args { |
2082 * - string $username |
2322 * Method arguments. Note: arguments must be ordered as documented. |
2083 * - string $password |
2323 * |
2084 * - string $taxonomy |
2324 * @type int $blog_id Blog ID (unused). |
2085 * @return array|IXR_Error (@see get_taxonomy()) |
2325 * @type string $username Username. |
|
2326 * @type string $password Password. |
|
2327 * @type string $taxnomy Taxonomy name. |
|
2328 * @type array $fields Optional. Array of taxonomy fields to limit to in the return. |
|
2329 * Accepts 'labels', 'cap', 'menu', and 'object_type'. |
|
2330 * Default empty array. |
|
2331 * } |
|
2332 * @return array|IXR_Error An array of taxonomy data on success, IXR_Error instance otherwise. |
2086 */ |
2333 */ |
2087 public function wp_getTaxonomy( $args ) { |
2334 public function wp_getTaxonomy( $args ) { |
2088 if ( ! $this->minimum_args( $args, 4 ) ) |
2335 if ( ! $this->minimum_args( $args, 4 ) ) |
2089 return $this->error; |
2336 return $this->error; |
2090 |
2337 |
2091 $this->escape( $args ); |
2338 $this->escape( $args ); |
2092 |
2339 |
2093 $username = $args[1]; |
2340 $username = $args[1]; |
2094 $password = $args[2]; |
2341 $password = $args[2]; |
2095 $taxonomy = $args[3]; |
2342 $taxonomy = $args[3]; |
2096 |
2343 |
2097 if ( isset( $args[4] ) ) { |
2344 if ( isset( $args[4] ) ) { |
2098 $fields = $args[4]; |
2345 $fields = $args[4]; |
2099 } else { |
2346 } else { |
2100 /** |
2347 /** |
2101 * Filter the taxonomy query fields used by the given XML-RPC method. |
2348 * Filters the taxonomy query fields used by the given XML-RPC method. |
2102 * |
2349 * |
2103 * @since 3.4.0 |
2350 * @since 3.4.0 |
2104 * |
2351 * |
2105 * @param array $fields An array of taxonomy fields to retrieve. |
2352 * @param array $fields An array of taxonomy fields to retrieve. |
2106 * @param string $method The method name. |
2353 * @param string $method The method name. |
2113 |
2360 |
2114 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2361 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2115 do_action( 'xmlrpc_call', 'wp.getTaxonomy' ); |
2362 do_action( 'xmlrpc_call', 'wp.getTaxonomy' ); |
2116 |
2363 |
2117 if ( ! taxonomy_exists( $taxonomy ) ) |
2364 if ( ! taxonomy_exists( $taxonomy ) ) |
2118 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
2365 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
2119 |
2366 |
2120 $taxonomy = get_taxonomy( $taxonomy ); |
2367 $taxonomy = get_taxonomy( $taxonomy ); |
2121 |
2368 |
2122 if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) |
2369 if ( ! current_user_can( $taxonomy->cap->assign_terms ) ) |
2123 return new IXR_Error( 401, __( 'You are not allowed to assign terms in this taxonomy.' ) ); |
2370 return new IXR_Error( 401, __( 'Sorry, you are not allowed to assign terms in this taxonomy.' ) ); |
2124 |
2371 |
2125 return $this->_prepare_taxonomy( $taxonomy, $fields ); |
2372 return $this->_prepare_taxonomy( $taxonomy, $fields ); |
2126 } |
2373 } |
2127 |
2374 |
2128 /** |
2375 /** |
2129 * Retrieve all taxonomies. |
2376 * Retrieve all taxonomies. |
2130 * |
2377 * |
2131 * @since 3.4.0 |
2378 * @since 3.4.0 |
2132 * |
2379 * |
2133 * @uses get_taxonomies() |
2380 * @see get_taxonomies() |
2134 * @param array $args Method parameters. Contains: |
2381 * |
2135 * - int $blog_id (unused) |
2382 * @param array $args { |
2136 * - string $username |
2383 * Method arguments. Note: arguments must be ordered as documented. |
2137 * - string $password |
2384 * |
2138 * @return array taxonomies |
2385 * @type int $blog_id Blog ID (unused). |
|
2386 * @type string $username Username. |
|
2387 * @type string $password Password. |
|
2388 * @type array $filter Optional. An array of arguments for retrieving taxonomies. |
|
2389 * @type array $fields Optional. The subset of taxonomy fields to return. |
|
2390 * } |
|
2391 * @return array|IXR_Error An associative array of taxonomy data with returned fields determined |
|
2392 * by `$fields`, or an IXR_Error instance on failure. |
2139 */ |
2393 */ |
2140 public function wp_getTaxonomies( $args ) { |
2394 public function wp_getTaxonomies( $args ) { |
2141 if ( ! $this->minimum_args( $args, 3 ) ) |
2395 if ( ! $this->minimum_args( $args, 3 ) ) |
2142 return $this->error; |
2396 return $this->error; |
2143 |
2397 |
2144 $this->escape( $args ); |
2398 $this->escape( $args ); |
2145 |
2399 |
2146 $username = $args[1]; |
2400 $username = $args[1]; |
2147 $password = $args[2]; |
2401 $password = $args[2]; |
2148 $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
2402 $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
2149 |
2403 |
2150 if ( isset( $args[4] ) ) { |
2404 if ( isset( $args[4] ) ) { |
2151 $fields = $args[4]; |
2405 $fields = $args[4]; |
2152 } else { |
2406 } else { |
2153 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2407 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2260 * in the response array. |
2518 * in the response array. |
2261 * |
2519 * |
2262 * @uses get_users() |
2520 * @uses get_users() |
2263 * @see wp_getUser() for more on $fields and return values |
2521 * @see wp_getUser() for more on $fields and return values |
2264 * |
2522 * |
2265 * @param array $args Method parameters. Contains: |
2523 * @param array $args { |
2266 * - int $blog_id (unused) |
2524 * Method arguments. Note: arguments must be ordered as documented. |
2267 * - string $username |
2525 * |
2268 * - string $password |
2526 * @type int $blog_id (unused) |
2269 * - array $filter optional |
2527 * @type string $username |
2270 * - array $fields optional |
2528 * @type string $password |
|
2529 * @type array $filter (optional) |
|
2530 * @type array $fields (optional) |
|
2531 * } |
2271 * @return array|IXR_Error users data |
2532 * @return array|IXR_Error users data |
2272 */ |
2533 */ |
2273 public function wp_getUsers( $args ) { |
2534 public function wp_getUsers( $args ) { |
2274 if ( ! $this->minimum_args( $args, 3 ) ) |
2535 if ( ! $this->minimum_args( $args, 3 ) ) |
2275 return $this->error; |
2536 return $this->error; |
2276 |
2537 |
2277 $this->escape( $args ); |
2538 $this->escape( $args ); |
2278 |
2539 |
2279 $username = $args[1]; |
2540 $username = $args[1]; |
2280 $password = $args[2]; |
2541 $password = $args[2]; |
2281 $filter = isset( $args[3] ) ? $args[3] : array(); |
2542 $filter = isset( $args[3] ) ? $args[3] : array(); |
2282 |
2543 |
2283 if ( isset( $args[4] ) ) { |
2544 if ( isset( $args[4] ) ) { |
2284 $fields = $args[4]; |
2545 $fields = $args[4]; |
2285 } else { |
2546 } else { |
2286 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2547 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2331 |
2592 |
2332 /** |
2593 /** |
2333 * Retrieve information about the requesting user. |
2594 * Retrieve information about the requesting user. |
2334 * |
2595 * |
2335 * @uses get_userdata() |
2596 * @uses get_userdata() |
2336 * @param array $args Method parameters. Contains: |
2597 * |
2337 * - int $blog_id (unused) |
2598 * @param array $args { |
2338 * - string $username |
2599 * Method arguments. Note: arguments must be ordered as documented. |
2339 * - string $password |
2600 * |
2340 * - array $fields optional |
2601 * @type int $blog_id (unused) |
|
2602 * @type string $username |
|
2603 * @type string $password |
|
2604 * @type array $fields (optional) |
|
2605 * } |
2341 * @return array|IXR_Error (@see wp_getUser) |
2606 * @return array|IXR_Error (@see wp_getUser) |
2342 */ |
2607 */ |
2343 public function wp_getProfile( $args ) { |
2608 public function wp_getProfile( $args ) { |
2344 if ( ! $this->minimum_args( $args, 3 ) ) |
2609 if ( ! $this->minimum_args( $args, 3 ) ) |
2345 return $this->error; |
2610 return $this->error; |
2346 |
2611 |
2347 $this->escape( $args ); |
2612 $this->escape( $args ); |
2348 |
2613 |
2349 $username = $args[1]; |
2614 $username = $args[1]; |
2350 $password = $args[2]; |
2615 $password = $args[2]; |
2351 |
2616 |
2352 if ( isset( $args[3] ) ) { |
2617 if ( isset( $args[3] ) ) { |
2353 $fields = $args[3]; |
2618 $fields = $args[3]; |
2354 } else { |
2619 } else { |
2355 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2620 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2361 |
2626 |
2362 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2627 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2363 do_action( 'xmlrpc_call', 'wp.getProfile' ); |
2628 do_action( 'xmlrpc_call', 'wp.getProfile' ); |
2364 |
2629 |
2365 if ( ! current_user_can( 'edit_user', $user->ID ) ) |
2630 if ( ! current_user_can( 'edit_user', $user->ID ) ) |
2366 return new IXR_Error( 401, __( 'Sorry, you cannot edit your profile.' ) ); |
2631 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) ); |
2367 |
2632 |
2368 $user_data = get_userdata( $user->ID ); |
2633 $user_data = get_userdata( $user->ID ); |
2369 |
2634 |
2370 return $this->_prepare_user( $user_data, $fields ); |
2635 return $this->_prepare_user( $user_data, $fields ); |
2371 } |
2636 } |
2372 |
2637 |
2373 /** |
2638 /** |
2374 * Edit user's profile. |
2639 * Edit user's profile. |
2375 * |
2640 * |
2376 * @uses wp_update_user() |
2641 * @uses wp_update_user() |
2377 * @param array $args Method parameters. Contains: |
2642 * |
2378 * - int $blog_id (unused) |
2643 * @param array $args { |
2379 * - string $username |
2644 * Method arguments. Note: arguments must be ordered as documented. |
2380 * - string $password |
2645 * |
2381 * - array $content_struct |
2646 * @type int $blog_id (unused) |
2382 * It can optionally contain: |
2647 * @type string $username |
|
2648 * @type string $password |
|
2649 * @type array $content_struct It can optionally contain: |
2383 * - 'first_name' |
2650 * - 'first_name' |
2384 * - 'last_name' |
2651 * - 'last_name' |
2385 * - 'website' |
2652 * - 'website' |
2386 * - 'display_name' |
2653 * - 'display_name' |
2387 * - 'nickname' |
2654 * - 'nickname' |
2388 * - 'nicename' |
2655 * - 'nicename' |
2389 * - 'bio' |
2656 * - 'bio' |
2390 * @return bool|IXR_Error True, on success. |
2657 * } |
|
2658 * @return true|IXR_Error True, on success. |
2391 */ |
2659 */ |
2392 public function wp_editProfile( $args ) { |
2660 public function wp_editProfile( $args ) { |
2393 if ( ! $this->minimum_args( $args, 4 ) ) |
2661 if ( ! $this->minimum_args( $args, 4 ) ) |
2394 return $this->error; |
2662 return $this->error; |
2395 |
2663 |
2448 /** |
2716 /** |
2449 * Retrieve page. |
2717 * Retrieve page. |
2450 * |
2718 * |
2451 * @since 2.2.0 |
2719 * @since 2.2.0 |
2452 * |
2720 * |
2453 * @param array $args Method parameters. Contains: |
2721 * @param array $args { |
2454 * - blog_id (unused) |
2722 * Method arguments. Note: arguments must be ordered as documented. |
2455 * - page_id |
2723 * |
2456 * - username |
2724 * @type int $blog_id (unused) |
2457 * - password |
2725 * @type int $page_id |
|
2726 * @type string $username |
|
2727 * @type string $password |
|
2728 * } |
2458 * @return array|IXR_Error |
2729 * @return array|IXR_Error |
2459 */ |
2730 */ |
2460 public function wp_getPage($args) { |
2731 public function wp_getPage( $args ) { |
2461 $this->escape($args); |
2732 $this->escape( $args ); |
2462 |
2733 |
2463 $page_id = (int) $args[1]; |
2734 $page_id = (int) $args[1]; |
2464 $username = $args[2]; |
2735 $username = $args[2]; |
2465 $password = $args[3]; |
2736 $password = $args[3]; |
2466 |
2737 |
2467 if ( !$user = $this->login($username, $password) ) { |
2738 if ( !$user = $this->login($username, $password) ) { |
2468 return $this->error; |
2739 return $this->error; |
2469 } |
2740 } |
2470 |
2741 |
2471 $page = get_post($page_id); |
2742 $page = get_post($page_id); |
2472 if ( ! $page ) |
2743 if ( ! $page ) |
2473 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
2744 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
2474 |
2745 |
2475 if ( !current_user_can( 'edit_page', $page_id ) ) |
2746 if ( !current_user_can( 'edit_page', $page_id ) ) |
2476 return new IXR_Error( 401, __( 'Sorry, you cannot edit this page.' ) ); |
2747 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) ); |
2477 |
2748 |
2478 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2749 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2479 do_action( 'xmlrpc_call', 'wp.getPage' ); |
2750 do_action( 'xmlrpc_call', 'wp.getPage' ); |
2480 |
2751 |
2481 // If we found the page then format the data. |
2752 // If we found the page then format the data. |
2491 /** |
2762 /** |
2492 * Retrieve Pages. |
2763 * Retrieve Pages. |
2493 * |
2764 * |
2494 * @since 2.2.0 |
2765 * @since 2.2.0 |
2495 * |
2766 * |
2496 * @param array $args Method parameters. Contains: |
2767 * @param array $args { |
2497 * - blog_id (unused) |
2768 * Method arguments. Note: arguments must be ordered as documented. |
2498 * - username |
2769 * |
2499 * - password |
2770 * @type int $blog_id (unused) |
2500 * - num_pages |
2771 * @type string $username |
|
2772 * @type string $password |
|
2773 * @type int $num_pages |
|
2774 * } |
2501 * @return array|IXR_Error |
2775 * @return array|IXR_Error |
2502 */ |
2776 */ |
2503 public function wp_getPages($args) { |
2777 public function wp_getPages( $args ) { |
2504 $this->escape($args); |
2778 $this->escape( $args ); |
2505 |
2779 |
2506 $username = $args[1]; |
2780 $username = $args[1]; |
2507 $password = $args[2]; |
2781 $password = $args[2]; |
2508 $num_pages = isset($args[3]) ? (int) $args[3] : 10; |
2782 $num_pages = isset($args[3]) ? (int) $args[3] : 10; |
2509 |
2783 |
2510 if ( !$user = $this->login($username, $password) ) |
2784 if ( !$user = $this->login($username, $password) ) |
2511 return $this->error; |
2785 return $this->error; |
2512 |
2786 |
2513 if ( !current_user_can( 'edit_pages' ) ) |
2787 if ( !current_user_can( 'edit_pages' ) ) |
2514 return new IXR_Error( 401, __( 'Sorry, you cannot edit pages.' ) ); |
2788 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
2515 |
2789 |
2516 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2790 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2517 do_action( 'xmlrpc_call', 'wp.getPages' ); |
2791 do_action( 'xmlrpc_call', 'wp.getPages' ); |
2518 |
2792 |
2519 $pages = get_posts( array('post_type' => 'page', 'post_status' => 'any', 'numberposts' => $num_pages) ); |
2793 $pages = get_posts( array('post_type' => 'page', 'post_status' => 'any', 'numberposts' => $num_pages) ); |
2612 /** |
2902 /** |
2613 * Edit page. |
2903 * Edit page. |
2614 * |
2904 * |
2615 * @since 2.2.0 |
2905 * @since 2.2.0 |
2616 * |
2906 * |
2617 * @param array $args Method parameters. |
2907 * @param array $args { |
|
2908 * Method arguments. Note: arguments must be ordered as documented. |
|
2909 * |
|
2910 * @type int $blog_id (unused) |
|
2911 * @type int $page_id |
|
2912 * @type string $username |
|
2913 * @type string $password |
|
2914 * @type string $content |
|
2915 * @type string $publish |
|
2916 * } |
2618 * @return array|IXR_Error |
2917 * @return array|IXR_Error |
2619 */ |
2918 */ |
2620 public function wp_editPage($args) { |
2919 public function wp_editPage( $args ) { |
2621 // Items not escaped here will be escaped in editPost. |
2920 // Items will be escaped in mw_editPost. |
2622 $page_id = (int) $this->escape($args[1]); |
2921 $page_id = (int) $args[1]; |
2623 $username = $this->escape($args[2]); |
2922 $username = $args[2]; |
2624 $password = $this->escape($args[3]); |
2923 $password = $args[3]; |
2625 $content = $args[4]; |
2924 $content = $args[4]; |
2626 $publish = $args[5]; |
2925 $publish = $args[5]; |
2627 |
2926 |
2628 if ( !$user = $this->login($username, $password) ) |
2927 $escaped_username = $this->escape( $username ); |
2629 return $this->error; |
2928 $escaped_password = $this->escape( $password ); |
|
2929 |
|
2930 if ( !$user = $this->login( $escaped_username, $escaped_password ) ) { |
|
2931 return $this->error; |
|
2932 } |
2630 |
2933 |
2631 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2934 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2632 do_action( 'xmlrpc_call', 'wp.editPage' ); |
2935 do_action( 'xmlrpc_call', 'wp.editPage' ); |
2633 |
2936 |
2634 // Get the page data and make sure it is a page. |
2937 // Get the page data and make sure it is a page. |
2659 /** |
2962 /** |
2660 * Retrieve page list. |
2963 * Retrieve page list. |
2661 * |
2964 * |
2662 * @since 2.2.0 |
2965 * @since 2.2.0 |
2663 * |
2966 * |
2664 * @param array $args Method parameters. |
2967 * @global wpdb $wpdb WordPress database abstraction object. |
|
2968 * |
|
2969 * @param array $args { |
|
2970 * Method arguments. Note: arguments must be ordered as documented. |
|
2971 * |
|
2972 * @type int $blog_id (unused) |
|
2973 * @type string $username |
|
2974 * @type string $password |
|
2975 * } |
2665 * @return array|IXR_Error |
2976 * @return array|IXR_Error |
2666 */ |
2977 */ |
2667 public function wp_getPageList($args) { |
2978 public function wp_getPageList( $args ) { |
2668 global $wpdb; |
2979 global $wpdb; |
2669 |
2980 |
2670 $this->escape($args); |
2981 $this->escape( $args ); |
2671 |
2982 |
2672 $username = $args[1]; |
2983 $username = $args[1]; |
2673 $password = $args[2]; |
2984 $password = $args[2]; |
2674 |
2985 |
2675 if ( !$user = $this->login($username, $password) ) |
2986 if ( !$user = $this->login($username, $password) ) |
2676 return $this->error; |
2987 return $this->error; |
2677 |
2988 |
2678 if ( !current_user_can( 'edit_pages' ) ) |
2989 if ( !current_user_can( 'edit_pages' ) ) |
2679 return new IXR_Error( 401, __( 'Sorry, you cannot edit pages.' ) ); |
2990 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
2680 |
2991 |
2681 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2992 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2682 do_action( 'xmlrpc_call', 'wp.getPageList' ); |
2993 do_action( 'xmlrpc_call', 'wp.getPageList' ); |
2683 |
2994 |
2684 // Get list of pages ids and titles |
2995 // Get list of pages ids and titles |
2711 /** |
3022 /** |
2712 * Retrieve authors list. |
3023 * Retrieve authors list. |
2713 * |
3024 * |
2714 * @since 2.2.0 |
3025 * @since 2.2.0 |
2715 * |
3026 * |
2716 * @param array $args Method parameters. |
3027 * @param array $args { |
|
3028 * Method arguments. Note: arguments must be ordered as documented. |
|
3029 * |
|
3030 * @type int $blog_id (unused) |
|
3031 * @type string $username |
|
3032 * @type string $password |
|
3033 * } |
2717 * @return array|IXR_Error |
3034 * @return array|IXR_Error |
2718 */ |
3035 */ |
2719 public function wp_getAuthors($args) { |
3036 public function wp_getAuthors( $args ) { |
2720 |
3037 $this->escape( $args ); |
2721 $this->escape($args); |
3038 |
2722 |
3039 $username = $args[1]; |
2723 $username = $args[1]; |
3040 $password = $args[2]; |
2724 $password = $args[2]; |
|
2725 |
3041 |
2726 if ( !$user = $this->login($username, $password) ) |
3042 if ( !$user = $this->login($username, $password) ) |
2727 return $this->error; |
3043 return $this->error; |
2728 |
3044 |
2729 if ( !current_user_can('edit_posts') ) |
3045 if ( !current_user_can('edit_posts') ) |
2730 return new IXR_Error( 401, __( 'Sorry, you cannot edit posts on this site.' ) ); |
3046 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
2731 |
3047 |
2732 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3048 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2733 do_action( 'xmlrpc_call', 'wp.getAuthors' ); |
3049 do_action( 'xmlrpc_call', 'wp.getAuthors' ); |
2734 |
3050 |
2735 $authors = array(); |
3051 $authors = array(); |
2789 /** |
3111 /** |
2790 * Create new category. |
3112 * Create new category. |
2791 * |
3113 * |
2792 * @since 2.2.0 |
3114 * @since 2.2.0 |
2793 * |
3115 * |
2794 * @param array $args Method parameters. |
3116 * @param array $args { |
|
3117 * Method arguments. Note: arguments must be ordered as documented. |
|
3118 * |
|
3119 * @type int $blog_id (unused) |
|
3120 * @type string $username |
|
3121 * @type string $password |
|
3122 * @type array $category |
|
3123 * } |
2795 * @return int|IXR_Error Category ID. |
3124 * @return int|IXR_Error Category ID. |
2796 */ |
3125 */ |
2797 public function wp_newCategory($args) { |
3126 public function wp_newCategory( $args ) { |
2798 $this->escape($args); |
3127 $this->escape( $args ); |
2799 |
3128 |
2800 $username = $args[1]; |
3129 $username = $args[1]; |
2801 $password = $args[2]; |
3130 $password = $args[2]; |
2802 $category = $args[3]; |
3131 $category = $args[3]; |
2803 |
3132 |
2804 if ( !$user = $this->login($username, $password) ) |
3133 if ( !$user = $this->login($username, $password) ) |
2805 return $this->error; |
3134 return $this->error; |
2806 |
3135 |
2807 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3136 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2808 do_action( 'xmlrpc_call', 'wp.newCategory' ); |
3137 do_action( 'xmlrpc_call', 'wp.newCategory' ); |
2809 |
3138 |
2810 // Make sure the user is allowed to add a category. |
3139 // Make sure the user is allowed to add a category. |
2811 if ( !current_user_can('manage_categories') ) |
3140 if ( ! current_user_can( 'manage_categories' ) ) { |
2812 return new IXR_Error(401, __('Sorry, you do not have the right to add a category.')); |
3141 return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a category.' ) ); |
|
3142 } |
2813 |
3143 |
2814 // If no slug was provided make it empty so that |
3144 // If no slug was provided make it empty so that |
2815 // WordPress will generate one. |
3145 // WordPress will generate one. |
2816 if ( empty($category['slug']) ) |
3146 if ( empty($category['slug']) ) |
2817 $category['slug'] = ''; |
3147 $category['slug'] = ''; |
2858 /** |
3188 /** |
2859 * Remove category. |
3189 * Remove category. |
2860 * |
3190 * |
2861 * @since 2.5.0 |
3191 * @since 2.5.0 |
2862 * |
3192 * |
2863 * @param array $args Method parameters. |
3193 * @param array $args { |
2864 * @return bool|IXR_Error See {@link wp_delete_term()} for return info. |
3194 * Method arguments. Note: arguments must be ordered as documented. |
2865 */ |
3195 * |
2866 public function wp_deleteCategory($args) { |
3196 * @type int $blog_id (unused) |
2867 $this->escape($args); |
3197 * @type string $username |
2868 |
3198 * @type string $password |
2869 $username = $args[1]; |
3199 * @type int $category_id |
2870 $password = $args[2]; |
3200 * } |
2871 $category_id = (int) $args[3]; |
3201 * @return bool|IXR_Error See wp_delete_term() for return info. |
|
3202 */ |
|
3203 public function wp_deleteCategory( $args ) { |
|
3204 $this->escape( $args ); |
|
3205 |
|
3206 $username = $args[1]; |
|
3207 $password = $args[2]; |
|
3208 $category_id = (int) $args[3]; |
2872 |
3209 |
2873 if ( !$user = $this->login($username, $password) ) |
3210 if ( !$user = $this->login($username, $password) ) |
2874 return $this->error; |
3211 return $this->error; |
2875 |
3212 |
2876 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3213 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2877 do_action( 'xmlrpc_call', 'wp.deleteCategory' ); |
3214 do_action( 'xmlrpc_call', 'wp.deleteCategory' ); |
2878 |
3215 |
2879 if ( !current_user_can('manage_categories') ) |
3216 if ( ! current_user_can( 'delete_term', $category_id ) ) { |
2880 return new IXR_Error( 401, __( 'Sorry, you do not have the right to delete a category.' ) ); |
3217 return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this category.' ) ); |
|
3218 } |
2881 |
3219 |
2882 $status = wp_delete_term( $category_id, 'category' ); |
3220 $status = wp_delete_term( $category_id, 'category' ); |
2883 |
3221 |
2884 if ( true == $status ) { |
3222 if ( true == $status ) { |
2885 /** |
3223 /** |
2899 /** |
3237 /** |
2900 * Retrieve category list. |
3238 * Retrieve category list. |
2901 * |
3239 * |
2902 * @since 2.2.0 |
3240 * @since 2.2.0 |
2903 * |
3241 * |
2904 * @param array $args Method parameters. |
3242 * @param array $args { |
|
3243 * Method arguments. Note: arguments must be ordered as documented. |
|
3244 * |
|
3245 * @type int $blog_id (unused) |
|
3246 * @type string $username |
|
3247 * @type string $password |
|
3248 * @type array $category |
|
3249 * @type int $max_results |
|
3250 * } |
2905 * @return array|IXR_Error |
3251 * @return array|IXR_Error |
2906 */ |
3252 */ |
2907 public function wp_suggestCategories($args) { |
3253 public function wp_suggestCategories( $args ) { |
2908 $this->escape($args); |
3254 $this->escape( $args ); |
2909 |
3255 |
2910 $username = $args[1]; |
3256 $username = $args[1]; |
2911 $password = $args[2]; |
3257 $password = $args[2]; |
2912 $category = $args[3]; |
3258 $category = $args[3]; |
2913 $max_results = (int) $args[4]; |
3259 $max_results = (int) $args[4]; |
2914 |
3260 |
2915 if ( !$user = $this->login($username, $password) ) |
3261 if ( !$user = $this->login($username, $password) ) |
2916 return $this->error; |
3262 return $this->error; |
2917 |
3263 |
2918 if ( !current_user_can( 'edit_posts' ) ) |
3264 if ( !current_user_can( 'edit_posts' ) ) |
2936 /** |
3282 /** |
2937 * Retrieve comment. |
3283 * Retrieve comment. |
2938 * |
3284 * |
2939 * @since 2.7.0 |
3285 * @since 2.7.0 |
2940 * |
3286 * |
2941 * @param array $args Method parameters. |
3287 * @param array $args { |
|
3288 * Method arguments. Note: arguments must be ordered as documented. |
|
3289 * |
|
3290 * @type int $blog_id (unused) |
|
3291 * @type string $username |
|
3292 * @type string $password |
|
3293 * @type int $comment_id |
|
3294 * } |
2942 * @return array|IXR_Error |
3295 * @return array|IXR_Error |
2943 */ |
3296 */ |
2944 public function wp_getComment($args) { |
3297 public function wp_getComment($args) { |
2945 $this->escape($args); |
3298 $this->escape($args); |
2946 |
3299 |
2947 $username = $args[1]; |
3300 $username = $args[1]; |
2948 $password = $args[2]; |
3301 $password = $args[2]; |
2949 $comment_id = (int) $args[3]; |
3302 $comment_id = (int) $args[3]; |
2950 |
3303 |
2951 if ( !$user = $this->login($username, $password) ) |
3304 if ( ! $user = $this->login( $username, $password ) ) { |
2952 return $this->error; |
3305 return $this->error; |
2953 |
3306 } |
2954 if ( !current_user_can( 'moderate_comments' ) ) |
|
2955 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this site.' ) ); |
|
2956 |
3307 |
2957 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3308 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2958 do_action( 'xmlrpc_call', 'wp.getComment' ); |
3309 do_action( 'xmlrpc_call', 'wp.getComment' ); |
2959 |
3310 |
2960 if ( ! $comment = get_comment($comment_id) ) |
3311 if ( ! $comment = get_comment( $comment_id ) ) { |
2961 return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
3312 return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
|
3313 } |
|
3314 |
|
3315 if ( ! current_user_can( 'edit_comment', $comment_id ) ) { |
|
3316 return new IXR_Error( 403, __( 'Sorry, you are not allowed to moderate or edit this comment.' ) ); |
|
3317 } |
2962 |
3318 |
2963 return $this->_prepare_comment( $comment ); |
3319 return $this->_prepare_comment( $comment ); |
2964 } |
3320 } |
2965 |
3321 |
2966 /** |
3322 /** |
2973 * |
3329 * |
2974 * The defaults are as follows: |
3330 * The defaults are as follows: |
2975 * - 'status' - Default is ''. Filter by status (e.g., 'approve', 'hold') |
3331 * - 'status' - Default is ''. Filter by status (e.g., 'approve', 'hold') |
2976 * - 'post_id' - Default is ''. The post where the comment is posted. Empty string shows all comments. |
3332 * - 'post_id' - Default is ''. The post where the comment is posted. Empty string shows all comments. |
2977 * - 'number' - Default is 10. Total number of media items to retrieve. |
3333 * - 'number' - Default is 10. Total number of media items to retrieve. |
2978 * - 'offset' - Default is 0. See {@link WP_Query::query()} for more. |
3334 * - 'offset' - Default is 0. See WP_Query::query() for more. |
2979 * |
3335 * |
2980 * @since 2.7.0 |
3336 * @since 2.7.0 |
2981 * |
3337 * |
2982 * @param array $args Method parameters. |
3338 * @param array $args { |
2983 * @return array|IXR_Error Contains a collection of comments. See {@link wp_xmlrpc_server::wp_getComment()} for a description of each item contents |
3339 * Method arguments. Note: arguments must be ordered as documented. |
2984 */ |
3340 * |
2985 public function wp_getComments($args) { |
3341 * @type int $blog_id (unused) |
2986 $this->escape($args); |
3342 * @type string $username |
2987 |
3343 * @type string $password |
2988 $username = $args[1]; |
3344 * @type array $struct |
2989 $password = $args[2]; |
3345 * } |
2990 $struct = isset( $args[3] ) ? $args[3] : array(); |
3346 * @return array|IXR_Error Contains a collection of comments. See wp_xmlrpc_server::wp_getComment() for a description of each item contents |
2991 |
3347 */ |
2992 if ( !$user = $this->login($username, $password) ) |
3348 public function wp_getComments( $args ) { |
2993 return $this->error; |
3349 $this->escape( $args ); |
2994 |
3350 |
2995 if ( !current_user_can( 'moderate_comments' ) ) |
3351 $username = $args[1]; |
2996 return new IXR_Error( 401, __( 'Sorry, you cannot edit comments.' ) ); |
3352 $password = $args[2]; |
|
3353 $struct = isset( $args[3] ) ? $args[3] : array(); |
|
3354 |
|
3355 if ( ! $user = $this->login( $username, $password ) ) { |
|
3356 return $this->error; |
|
3357 } |
2997 |
3358 |
2998 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3359 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2999 do_action( 'xmlrpc_call', 'wp.getComments' ); |
3360 do_action( 'xmlrpc_call', 'wp.getComments' ); |
3000 |
3361 |
3001 if ( isset($struct['status']) ) |
3362 if ( isset( $struct['status'] ) ) { |
3002 $status = $struct['status']; |
3363 $status = $struct['status']; |
3003 else |
3364 } else { |
3004 $status = ''; |
3365 $status = ''; |
|
3366 } |
|
3367 |
|
3368 if ( ! current_user_can( 'moderate_comments' ) && 'approve' !== $status ) { |
|
3369 return new IXR_Error( 401, __( 'Invalid comment status.' ) ); |
|
3370 } |
3005 |
3371 |
3006 $post_id = ''; |
3372 $post_id = ''; |
3007 if ( isset($struct['post_id']) ) |
3373 if ( isset( $struct['post_id'] ) ) { |
3008 $post_id = absint($struct['post_id']); |
3374 $post_id = absint( $struct['post_id'] ); |
|
3375 } |
|
3376 |
|
3377 $post_type = ''; |
|
3378 if ( isset( $struct['post_type'] ) ) { |
|
3379 $post_type_object = get_post_type_object( $struct['post_type'] ); |
|
3380 if ( ! $post_type_object || ! post_type_supports( $post_type_object->name, 'comments' ) ) { |
|
3381 return new IXR_Error( 404, __( 'Invalid post type.' ) ); |
|
3382 } |
|
3383 $post_type = $struct['post_type']; |
|
3384 } |
3009 |
3385 |
3010 $offset = 0; |
3386 $offset = 0; |
3011 if ( isset($struct['offset']) ) |
3387 if ( isset( $struct['offset'] ) ) { |
3012 $offset = absint($struct['offset']); |
3388 $offset = absint( $struct['offset'] ); |
|
3389 } |
3013 |
3390 |
3014 $number = 10; |
3391 $number = 10; |
3015 if ( isset($struct['number']) ) |
3392 if ( isset( $struct['number'] ) ) { |
3016 $number = absint($struct['number']); |
3393 $number = absint( $struct['number'] ); |
3017 |
3394 } |
3018 $comments = get_comments( array('status' => $status, 'post_id' => $post_id, 'offset' => $offset, 'number' => $number ) ); |
3395 |
|
3396 $comments = get_comments( array( |
|
3397 'status' => $status, |
|
3398 'post_id' => $post_id, |
|
3399 'offset' => $offset, |
|
3400 'number' => $number, |
|
3401 'post_type' => $post_type, |
|
3402 ) ); |
3019 |
3403 |
3020 $comments_struct = array(); |
3404 $comments_struct = array(); |
3021 |
3405 if ( is_array( $comments ) ) { |
3022 foreach ( $comments as $comment ) { |
3406 foreach ( $comments as $comment ) { |
3023 $comments_struct[] = $this->_prepare_comment( $comment ); |
3407 $comments_struct[] = $this->_prepare_comment( $comment ); |
|
3408 } |
3024 } |
3409 } |
3025 |
3410 |
3026 return $comments_struct; |
3411 return $comments_struct; |
3027 } |
3412 } |
3028 |
3413 |
3029 /** |
3414 /** |
3030 * Delete a comment. |
3415 * Delete a comment. |
3031 * |
3416 * |
3032 * By default, the comment will be moved to the trash instead of deleted. |
3417 * By default, the comment will be moved to the trash instead of deleted. |
3033 * See {@link wp_delete_comment()} for more information on |
3418 * See wp_delete_comment() for more information on this behavior. |
3034 * this behavior. |
|
3035 * |
3419 * |
3036 * @since 2.7.0 |
3420 * @since 2.7.0 |
3037 * |
3421 * |
3038 * @param array $args Method parameters. Contains: |
3422 * @param array $args { |
3039 * - blog_id (unused) |
3423 * Method arguments. Note: arguments must be ordered as documented. |
3040 * - username |
3424 * |
3041 * - password |
3425 * @type int $blog_id (unused) |
3042 * - comment_id |
3426 * @type string $username |
3043 * @return bool|IXR_Error {@link wp_delete_comment()} |
3427 * @type string $password |
3044 */ |
3428 * @type int $comment_ID |
3045 public function wp_deleteComment($args) { |
3429 * } |
|
3430 * @return bool|IXR_Error See wp_delete_comment(). |
|
3431 */ |
|
3432 public function wp_deleteComment( $args ) { |
3046 $this->escape($args); |
3433 $this->escape($args); |
3047 |
3434 |
3048 $username = $args[1]; |
3435 $username = $args[1]; |
3049 $password = $args[2]; |
3436 $password = $args[2]; |
3050 $comment_ID = (int) $args[3]; |
3437 $comment_ID = (int) $args[3]; |
3051 |
3438 |
3052 if ( !$user = $this->login($username, $password) ) |
3439 if ( ! $user = $this->login( $username, $password ) ) { |
3053 return $this->error; |
3440 return $this->error; |
3054 |
3441 } |
3055 if ( !current_user_can( 'moderate_comments' ) ) |
3442 |
3056 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this site.' ) ); |
3443 if ( ! get_comment( $comment_ID ) ) { |
3057 |
|
3058 if ( ! get_comment($comment_ID) ) |
|
3059 return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
3444 return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
3060 |
3445 } |
3061 if ( !current_user_can( 'edit_comment', $comment_ID ) ) |
3446 |
3062 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this site.' ) ); |
3447 if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { |
|
3448 return new IXR_Error( 403, __( 'Sorry, you are not allowed to delete this comment.' ) ); |
|
3449 } |
3063 |
3450 |
3064 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3451 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3065 do_action( 'xmlrpc_call', 'wp.deleteComment' ); |
3452 do_action( 'xmlrpc_call', 'wp.deleteComment' ); |
3066 |
3453 |
3067 $status = wp_delete_comment( $comment_ID ); |
3454 $status = wp_delete_comment( $comment_ID ); |
3068 |
3455 |
3069 if ( true == $status ) { |
3456 if ( $status ) { |
3070 /** |
3457 /** |
3071 * Fires after a comment has been successfully deleted via XML-RPC. |
3458 * Fires after a comment has been successfully deleted via XML-RPC. |
3072 * |
3459 * |
3073 * @since 3.4.0 |
3460 * @since 3.4.0 |
3074 * |
3461 * |
3091 * - 'author' |
3478 * - 'author' |
3092 * - 'author_url' |
3479 * - 'author_url' |
3093 * - 'author_email' |
3480 * - 'author_email' |
3094 * - 'content' |
3481 * - 'content' |
3095 * - 'date_created_gmt' |
3482 * - 'date_created_gmt' |
3096 * - 'status'. Common statuses are 'approve', 'hold', 'spam'. See {@link get_comment_statuses()} for more details |
3483 * - 'status'. Common statuses are 'approve', 'hold', 'spam'. See get_comment_statuses() for more details |
3097 * |
3484 * |
3098 * @since 2.7.0 |
3485 * @since 2.7.0 |
3099 * |
3486 * |
3100 * @param array $args Contains: |
3487 * @param array $args { |
3101 * - blog_id (unused) |
3488 * Method arguments. Note: arguments must be ordered as documented. |
3102 * - username |
3489 * |
3103 * - password |
3490 * @type int $blog_id (unused) |
3104 * - comment_id |
3491 * @type string $username |
3105 * - content_struct |
3492 * @type string $password |
3106 * @return bool|IXR_Error True, on success. |
3493 * @type int $comment_ID |
3107 */ |
3494 * @type array $content_struct |
3108 public function wp_editComment($args) { |
3495 * } |
3109 $this->escape($args); |
3496 * @return true|IXR_Error True, on success. |
|
3497 */ |
|
3498 public function wp_editComment( $args ) { |
|
3499 $this->escape( $args ); |
3110 |
3500 |
3111 $username = $args[1]; |
3501 $username = $args[1]; |
3112 $password = $args[2]; |
3502 $password = $args[2]; |
3113 $comment_ID = (int) $args[3]; |
3503 $comment_ID = (int) $args[3]; |
3114 $content_struct = $args[4]; |
3504 $content_struct = $args[4]; |
3115 |
3505 |
3116 if ( !$user = $this->login($username, $password) ) |
3506 if ( !$user = $this->login( $username, $password ) ) { |
3117 return $this->error; |
3507 return $this->error; |
3118 |
3508 } |
3119 if ( !current_user_can( 'moderate_comments' ) ) |
3509 |
3120 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this site.' ) ); |
3510 if ( ! get_comment( $comment_ID ) ) { |
3121 |
|
3122 if ( ! get_comment($comment_ID) ) |
|
3123 return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
3511 return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
3124 |
3512 } |
3125 if ( !current_user_can( 'edit_comment', $comment_ID ) ) |
3513 |
3126 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this site.' ) ); |
3514 if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { |
|
3515 return new IXR_Error( 403, __( 'Sorry, you are not allowed to moderate or edit this comment.' ) ); |
|
3516 } |
3127 |
3517 |
3128 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3518 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3129 do_action( 'xmlrpc_call', 'wp.editComment' ); |
3519 do_action( 'xmlrpc_call', 'wp.editComment' ); |
3130 |
3520 |
3131 if ( isset($content_struct['status']) ) { |
3521 if ( isset($content_struct['status']) ) { |
3222 if ( is_numeric($post) ) |
3620 if ( is_numeric($post) ) |
3223 $post_id = absint($post); |
3621 $post_id = absint($post); |
3224 else |
3622 else |
3225 $post_id = url_to_postid($post); |
3623 $post_id = url_to_postid($post); |
3226 |
3624 |
3227 if ( ! $post_id ) |
3625 if ( ! $post_id ) { |
3228 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
3626 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
3229 |
3627 } |
3230 if ( ! get_post($post_id) ) |
3628 |
|
3629 if ( ! get_post( $post_id ) ) { |
3231 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
3630 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
3232 |
3631 } |
3233 $comment = array(); |
3632 |
3234 $comment['comment_post_ID'] = $post_id; |
3633 if ( ! comments_open( $post_id ) ) { |
|
3634 return new IXR_Error( 403, __( 'Sorry, comments are closed for this item.' ) ); |
|
3635 } |
|
3636 |
|
3637 if ( empty( $content_struct['content'] ) ) { |
|
3638 return new IXR_Error( 403, __( 'Comment is required.' ) ); |
|
3639 } |
|
3640 |
|
3641 $comment = array( |
|
3642 'comment_post_ID' => $post_id, |
|
3643 'comment_content' => $content_struct['content'], |
|
3644 ); |
3235 |
3645 |
3236 if ( $logged_in ) { |
3646 if ( $logged_in ) { |
3237 $comment['comment_author'] = $this->escape( $user->display_name ); |
3647 $display_name = $user->display_name; |
3238 $comment['comment_author_email'] = $this->escape( $user->user_email ); |
3648 $user_email = $user->user_email; |
3239 $comment['comment_author_url'] = $this->escape( $user->user_url ); |
3649 $user_url = $user->user_url; |
|
3650 |
|
3651 $comment['comment_author'] = $this->escape( $display_name ); |
|
3652 $comment['comment_author_email'] = $this->escape( $user_email ); |
|
3653 $comment['comment_author_url'] = $this->escape( $user_url ); |
3240 $comment['user_ID'] = $user->ID; |
3654 $comment['user_ID'] = $user->ID; |
3241 } else { |
3655 } else { |
3242 $comment['comment_author'] = ''; |
3656 $comment['comment_author'] = ''; |
3243 if ( isset($content_struct['author']) ) |
3657 if ( isset($content_struct['author']) ) |
3244 $comment['comment_author'] = $content_struct['author']; |
3658 $comment['comment_author'] = $content_struct['author']; |
3253 |
3667 |
3254 $comment['user_ID'] = 0; |
3668 $comment['user_ID'] = 0; |
3255 |
3669 |
3256 if ( get_option('require_name_email') ) { |
3670 if ( get_option('require_name_email') ) { |
3257 if ( 6 > strlen($comment['comment_author_email']) || '' == $comment['comment_author'] ) |
3671 if ( 6 > strlen($comment['comment_author_email']) || '' == $comment['comment_author'] ) |
3258 return new IXR_Error( 403, __( 'Comment author name and email are required' ) ); |
3672 return new IXR_Error( 403, __( 'Comment author name and email are required.' ) ); |
3259 elseif ( !is_email($comment['comment_author_email']) ) |
3673 elseif ( !is_email($comment['comment_author_email']) ) |
3260 return new IXR_Error( 403, __( 'A valid email address is required' ) ); |
3674 return new IXR_Error( 403, __( 'A valid email address is required.' ) ); |
3261 } |
3675 } |
3262 } |
3676 } |
3263 |
3677 |
3264 $comment['comment_parent'] = isset($content_struct['comment_parent']) ? absint($content_struct['comment_parent']) : 0; |
3678 $comment['comment_parent'] = isset($content_struct['comment_parent']) ? absint($content_struct['comment_parent']) : 0; |
3265 |
|
3266 $comment['comment_content'] = isset($content_struct['content']) ? $content_struct['content'] : null; |
|
3267 |
3679 |
3268 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3680 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3269 do_action( 'xmlrpc_call', 'wp.newComment' ); |
3681 do_action( 'xmlrpc_call', 'wp.newComment' ); |
3270 |
3682 |
3271 $comment_ID = wp_new_comment( $comment ); |
3683 $comment_ID = wp_new_comment( $comment, true ); |
|
3684 if ( is_wp_error( $comment_ID ) ) { |
|
3685 return new IXR_Error( 403, $comment_ID->get_error_message() ); |
|
3686 } |
|
3687 |
|
3688 if ( ! $comment_ID ) { |
|
3689 return new IXR_Error( 403, __( 'Something went wrong.' ) ); |
|
3690 } |
3272 |
3691 |
3273 /** |
3692 /** |
3274 * Fires after a new comment has been successfully created via XML-RPC. |
3693 * Fires after a new comment has been successfully created via XML-RPC. |
3275 * |
3694 * |
3276 * @since 3.4.0 |
3695 * @since 3.4.0 |
3286 /** |
3705 /** |
3287 * Retrieve all of the comment status. |
3706 * Retrieve all of the comment status. |
3288 * |
3707 * |
3289 * @since 2.7.0 |
3708 * @since 2.7.0 |
3290 * |
3709 * |
3291 * @param array $args Method parameters. |
3710 * @param array $args { |
|
3711 * Method arguments. Note: arguments must be ordered as documented. |
|
3712 * |
|
3713 * @type int $blog_id (unused) |
|
3714 * @type string $username |
|
3715 * @type string $password |
|
3716 * } |
3292 * @return array|IXR_Error |
3717 * @return array|IXR_Error |
3293 */ |
3718 */ |
3294 public function wp_getCommentStatusList($args) { |
3719 public function wp_getCommentStatusList( $args ) { |
3295 $this->escape( $args ); |
3720 $this->escape( $args ); |
3296 |
3721 |
3297 $username = $args[1]; |
3722 $username = $args[1]; |
3298 $password = $args[2]; |
3723 $password = $args[2]; |
3299 |
3724 |
3300 if ( !$user = $this->login($username, $password) ) |
3725 if ( ! $user = $this->login( $username, $password ) ) { |
3301 return $this->error; |
3726 return $this->error; |
3302 |
3727 } |
3303 if ( !current_user_can( 'moderate_comments' ) ) |
3728 |
3304 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) ); |
3729 if ( ! current_user_can( 'publish_posts' ) ) { |
|
3730 return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details about this site.' ) ); |
|
3731 } |
3305 |
3732 |
3306 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3733 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3307 do_action( 'xmlrpc_call', 'wp.getCommentStatusList' ); |
3734 do_action( 'xmlrpc_call', 'wp.getCommentStatusList' ); |
3308 |
3735 |
3309 return get_comment_statuses(); |
3736 return get_comment_statuses(); |
3312 /** |
3739 /** |
3313 * Retrieve comment count. |
3740 * Retrieve comment count. |
3314 * |
3741 * |
3315 * @since 2.5.0 |
3742 * @since 2.5.0 |
3316 * |
3743 * |
3317 * @param array $args Method parameters. |
3744 * @param array $args { |
|
3745 * Method arguments. Note: arguments must be ordered as documented. |
|
3746 * |
|
3747 * @type int $blog_id (unused) |
|
3748 * @type string $username |
|
3749 * @type string $password |
|
3750 * @type int $post_id |
|
3751 * } |
3318 * @return array|IXR_Error |
3752 * @return array|IXR_Error |
3319 */ |
3753 */ |
3320 public function wp_getCommentCount( $args ) { |
3754 public function wp_getCommentCount( $args ) { |
3321 $this->escape($args); |
3755 $this->escape( $args ); |
3322 |
3756 |
3323 $username = $args[1]; |
3757 $username = $args[1]; |
3324 $password = $args[2]; |
3758 $password = $args[2]; |
3325 $post_id = (int) $args[3]; |
3759 $post_id = (int) $args[3]; |
3326 |
3760 |
3327 if ( !$user = $this->login($username, $password) ) |
3761 if ( ! $user = $this->login( $username, $password ) ) { |
3328 return $this->error; |
3762 return $this->error; |
3329 |
3763 } |
3330 if ( !current_user_can( 'edit_posts' ) ) |
3764 |
3331 return new IXR_Error( 403, __( 'You are not allowed access to details about comments.' ) ); |
3765 $post = get_post( $post_id, ARRAY_A ); |
|
3766 if ( empty( $post['ID'] ) ) { |
|
3767 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
|
3768 } |
|
3769 |
|
3770 if ( ! current_user_can( 'edit_post', $post_id ) ) { |
|
3771 return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details of this post.' ) ); |
|
3772 } |
3332 |
3773 |
3333 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3774 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3334 do_action( 'xmlrpc_call', 'wp.getCommentCount' ); |
3775 do_action( 'xmlrpc_call', 'wp.getCommentCount' ); |
3335 |
3776 |
3336 $count = wp_count_comments( $post_id ); |
3777 $count = wp_count_comments( $post_id ); |
|
3778 |
3337 return array( |
3779 return array( |
3338 'approved' => $count->approved, |
3780 'approved' => $count->approved, |
3339 'awaiting_moderation' => $count->moderated, |
3781 'awaiting_moderation' => $count->moderated, |
3340 'spam' => $count->spam, |
3782 'spam' => $count->spam, |
3341 'total_comments' => $count->total_comments |
3783 'total_comments' => $count->total_comments |
3345 /** |
3787 /** |
3346 * Retrieve post statuses. |
3788 * Retrieve post statuses. |
3347 * |
3789 * |
3348 * @since 2.5.0 |
3790 * @since 2.5.0 |
3349 * |
3791 * |
3350 * @param array $args Method parameters. |
3792 * @param array $args { |
|
3793 * Method arguments. Note: arguments must be ordered as documented. |
|
3794 * |
|
3795 * @type int $blog_id (unused) |
|
3796 * @type string $username |
|
3797 * @type string $password |
|
3798 * } |
3351 * @return array|IXR_Error |
3799 * @return array|IXR_Error |
3352 */ |
3800 */ |
3353 public function wp_getPostStatusList( $args ) { |
3801 public function wp_getPostStatusList( $args ) { |
3354 $this->escape( $args ); |
3802 $this->escape( $args ); |
3355 |
3803 |
3356 $username = $args[1]; |
3804 $username = $args[1]; |
3357 $password = $args[2]; |
3805 $password = $args[2]; |
3358 |
3806 |
3359 if ( !$user = $this->login($username, $password) ) |
3807 if ( !$user = $this->login($username, $password) ) |
3360 return $this->error; |
3808 return $this->error; |
3361 |
3809 |
3362 if ( !current_user_can( 'edit_posts' ) ) |
3810 if ( !current_user_can( 'edit_posts' ) ) |
3363 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) ); |
3811 return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details about this site.' ) ); |
3364 |
3812 |
3365 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3813 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3366 do_action( 'xmlrpc_call', 'wp.getPostStatusList' ); |
3814 do_action( 'xmlrpc_call', 'wp.getPostStatusList' ); |
3367 |
3815 |
3368 return get_post_statuses(); |
3816 return get_post_statuses(); |
3371 /** |
3819 /** |
3372 * Retrieve page statuses. |
3820 * Retrieve page statuses. |
3373 * |
3821 * |
3374 * @since 2.5.0 |
3822 * @since 2.5.0 |
3375 * |
3823 * |
3376 * @param array $args Method parameters. |
3824 * @param array $args { |
|
3825 * Method arguments. Note: arguments must be ordered as documented. |
|
3826 * |
|
3827 * @type int $blog_id (unused) |
|
3828 * @type string $username |
|
3829 * @type string $password |
|
3830 * } |
3377 * @return array|IXR_Error |
3831 * @return array|IXR_Error |
3378 */ |
3832 */ |
3379 public function wp_getPageStatusList( $args ) { |
3833 public function wp_getPageStatusList( $args ) { |
3380 $this->escape( $args ); |
3834 $this->escape( $args ); |
3381 |
3835 |
3382 $username = $args[1]; |
3836 $username = $args[1]; |
3383 $password = $args[2]; |
3837 $password = $args[2]; |
3384 |
3838 |
3385 if ( !$user = $this->login($username, $password) ) |
3839 if ( !$user = $this->login($username, $password) ) |
3386 return $this->error; |
3840 return $this->error; |
3387 |
3841 |
3388 if ( !current_user_can( 'edit_pages' ) ) |
3842 if ( !current_user_can( 'edit_pages' ) ) |
3389 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) ); |
3843 return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details about this site.' ) ); |
3390 |
3844 |
3391 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3845 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3392 do_action( 'xmlrpc_call', 'wp.getPageStatusList' ); |
3846 do_action( 'xmlrpc_call', 'wp.getPageStatusList' ); |
3393 |
3847 |
3394 return get_page_statuses(); |
3848 return get_page_statuses(); |
3397 /** |
3851 /** |
3398 * Retrieve page templates. |
3852 * Retrieve page templates. |
3399 * |
3853 * |
3400 * @since 2.6.0 |
3854 * @since 2.6.0 |
3401 * |
3855 * |
3402 * @param array $args Method parameters. |
3856 * @param array $args { |
|
3857 * Method arguments. Note: arguments must be ordered as documented. |
|
3858 * |
|
3859 * @type int $blog_id (unused) |
|
3860 * @type string $username |
|
3861 * @type string $password |
|
3862 * } |
3403 * @return array|IXR_Error |
3863 * @return array|IXR_Error |
3404 */ |
3864 */ |
3405 public function wp_getPageTemplates( $args ) { |
3865 public function wp_getPageTemplates( $args ) { |
3406 $this->escape( $args ); |
3866 $this->escape( $args ); |
3407 |
3867 |
3408 $username = $args[1]; |
3868 $username = $args[1]; |
3409 $password = $args[2]; |
3869 $password = $args[2]; |
3410 |
3870 |
3411 if ( !$user = $this->login($username, $password) ) |
3871 if ( !$user = $this->login($username, $password) ) |
3412 return $this->error; |
3872 return $this->error; |
3413 |
3873 |
3414 if ( !current_user_can( 'edit_pages' ) ) |
3874 if ( !current_user_can( 'edit_pages' ) ) |
3415 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) ); |
3875 return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details about this site.' ) ); |
3416 |
3876 |
3417 $templates = get_page_templates(); |
3877 $templates = get_page_templates(); |
3418 $templates['Default'] = 'default'; |
3878 $templates['Default'] = 'default'; |
3419 |
3879 |
3420 return $templates; |
3880 return $templates; |
3513 /** |
3987 /** |
3514 * Retrieve a media item by ID |
3988 * Retrieve a media item by ID |
3515 * |
3989 * |
3516 * @since 3.1.0 |
3990 * @since 3.1.0 |
3517 * |
3991 * |
3518 * @param array $args Method parameters. Contains: |
3992 * @param array $args { |
3519 * - blog_id (unused) |
3993 * Method arguments. Note: arguments must be ordered as documented. |
3520 * - username |
3994 * |
3521 * - password |
3995 * @type int $blog_id (unused) |
3522 * - attachment_id |
3996 * @type string $username |
|
3997 * @type string $password |
|
3998 * @type int $attachment_id |
|
3999 * } |
3523 * @return array|IXR_Error Associative array contains: |
4000 * @return array|IXR_Error Associative array contains: |
3524 * - 'date_created_gmt' |
4001 * - 'date_created_gmt' |
3525 * - 'parent' |
4002 * - 'parent' |
3526 * - 'link' |
4003 * - 'link' |
3527 * - 'thumbnail' |
4004 * - 'thumbnail' |
3528 * - 'title' |
4005 * - 'title' |
3529 * - 'caption' |
4006 * - 'caption' |
3530 * - 'description' |
4007 * - 'description' |
3531 * - 'metadata' |
4008 * - 'metadata' |
3532 */ |
4009 */ |
3533 public function wp_getMediaItem($args) { |
4010 public function wp_getMediaItem( $args ) { |
3534 $this->escape($args); |
4011 $this->escape( $args ); |
3535 |
4012 |
3536 $username = $args[1]; |
4013 $username = $args[1]; |
3537 $password = $args[2]; |
4014 $password = $args[2]; |
3538 $attachment_id = (int) $args[3]; |
4015 $attachment_id = (int) $args[3]; |
3539 |
4016 |
3540 if ( !$user = $this->login($username, $password) ) |
4017 if ( !$user = $this->login($username, $password) ) |
3541 return $this->error; |
4018 return $this->error; |
3542 |
4019 |
3543 if ( !current_user_can( 'upload_files' ) ) |
4020 if ( !current_user_can( 'upload_files' ) ) |
3544 return new IXR_Error( 403, __( 'You do not have permission to upload files.' ) ); |
4021 return new IXR_Error( 403, __( 'Sorry, you are not allowed to upload files.' ) ); |
3545 |
4022 |
3546 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4023 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3547 do_action( 'xmlrpc_call', 'wp.getMediaItem' ); |
4024 do_action( 'xmlrpc_call', 'wp.getMediaItem' ); |
3548 |
4025 |
3549 if ( ! $attachment = get_post($attachment_id) ) |
4026 if ( ! $attachment = get_post($attachment_id) ) |
3560 * |
4037 * |
3561 * Accepted 'filter' keys are 'parent_id', 'mime_type', 'offset', and 'number'. |
4038 * Accepted 'filter' keys are 'parent_id', 'mime_type', 'offset', and 'number'. |
3562 * |
4039 * |
3563 * The defaults are as follows: |
4040 * The defaults are as follows: |
3564 * - 'number' - Default is 5. Total number of media items to retrieve. |
4041 * - 'number' - Default is 5. Total number of media items to retrieve. |
3565 * - 'offset' - Default is 0. See {@link WP_Query::query()} for more. |
4042 * - 'offset' - Default is 0. See WP_Query::query() for more. |
3566 * - 'parent_id' - Default is ''. The post where the media item is attached. Empty string shows all media items. 0 shows unattached media items. |
4043 * - 'parent_id' - Default is ''. The post where the media item is attached. Empty string shows all media items. 0 shows unattached media items. |
3567 * - 'mime_type' - Default is ''. Filter by mime type (e.g., 'image/jpeg', 'application/pdf') |
4044 * - 'mime_type' - Default is ''. Filter by mime type (e.g., 'image/jpeg', 'application/pdf') |
3568 * |
4045 * |
3569 * @since 3.1.0 |
4046 * @since 3.1.0 |
3570 * |
4047 * |
3571 * @param array $args Method parameters. Contains: |
4048 * @param array $args { |
3572 * - blog_id (unused) |
4049 * Method arguments. Note: arguments must be ordered as documented. |
3573 * - username |
4050 * |
3574 * - password |
4051 * @type int $blog_id (unused) |
3575 * - filter |
4052 * @type string $username |
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 |
4053 * @type string $password |
|
4054 * @type array $struct |
|
4055 * } |
|
4056 * @return array|IXR_Error Contains a collection of media items. See wp_xmlrpc_server::wp_getMediaItem() for a description of each item contents |
3577 */ |
4057 */ |
3578 public function wp_getMediaLibrary($args) { |
4058 public function wp_getMediaLibrary($args) { |
3579 $this->escape($args); |
4059 $this->escape($args); |
3580 |
4060 |
3581 $username = $args[1]; |
4061 $username = $args[1]; |
3605 |
4085 |
3606 return $attachments_struct; |
4086 return $attachments_struct; |
3607 } |
4087 } |
3608 |
4088 |
3609 /** |
4089 /** |
3610 * Retrieves a list of post formats used by the site |
4090 * Retrieves a list of post formats used by the site. |
3611 * |
4091 * |
3612 * @since 3.1.0 |
4092 * @since 3.1.0 |
3613 * |
4093 * |
3614 * @param array $args Method parameters. Contains: |
4094 * @param array $args { |
3615 * - blog_id (unused) |
4095 * Method arguments. Note: arguments must be ordered as documented. |
3616 * - username |
4096 * |
3617 * - password |
4097 * @type int $blog_id (unused) |
3618 * @return array|IXR_Error |
4098 * @type string $username |
3619 */ |
4099 * @type string $password |
|
4100 * } |
|
4101 * @return array|IXR_Error List of post formats, otherwise IXR_Error object. |
|
4102 */ |
3620 public function wp_getPostFormats( $args ) { |
4103 public function wp_getPostFormats( $args ) { |
3621 $this->escape( $args ); |
4104 $this->escape( $args ); |
3622 |
4105 |
3623 $username = $args[1]; |
4106 $username = $args[1]; |
3624 $password = $args[2]; |
4107 $password = $args[2]; |
3625 |
4108 |
3626 if ( !$user = $this->login( $username, $password ) ) |
4109 if ( !$user = $this->login( $username, $password ) ) |
3627 return $this->error; |
4110 return $this->error; |
3628 |
4111 |
3629 if ( !current_user_can( 'edit_posts' ) ) |
4112 if ( !current_user_can( 'edit_posts' ) ) |
3630 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) ); |
4113 return new IXR_Error( 403, __( 'Sorry, you are not allowed access to details about this site.' ) ); |
3631 |
4114 |
3632 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4115 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3633 do_action( 'xmlrpc_call', 'wp.getPostFormats' ); |
4116 do_action( 'xmlrpc_call', 'wp.getPostFormats' ); |
3634 |
4117 |
3635 $formats = get_post_format_strings(); |
4118 $formats = get_post_format_strings(); |
3703 return $this->error; |
4190 return $this->error; |
3704 |
4191 |
3705 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4192 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3706 do_action( 'xmlrpc_call', 'wp.getPostType' ); |
4193 do_action( 'xmlrpc_call', 'wp.getPostType' ); |
3707 |
4194 |
3708 if( ! post_type_exists( $post_type_name ) ) |
4195 if ( ! post_type_exists( $post_type_name ) ) |
3709 return new IXR_Error( 403, __( 'Invalid post type' ) ); |
4196 return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
3710 |
4197 |
3711 $post_type = get_post_type_object( $post_type_name ); |
4198 $post_type = get_post_type_object( $post_type_name ); |
3712 |
4199 |
3713 if( ! current_user_can( $post_type->cap->edit_posts ) ) |
4200 if ( ! current_user_can( $post_type->cap->edit_posts ) ) |
3714 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post type.' ) ); |
4201 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts in this post type.' ) ); |
3715 |
4202 |
3716 return $this->_prepare_post_type( $post_type, $fields ); |
4203 return $this->_prepare_post_type( $post_type, $fields ); |
3717 } |
4204 } |
3718 |
4205 |
3719 /** |
4206 /** |
3720 * Retrieves a post types |
4207 * Retrieves a post types |
3721 * |
4208 * |
3722 * @since 3.4.0 |
4209 * @since 3.4.0 |
3723 * |
4210 * |
3724 * @uses get_post_types() |
4211 * @see get_post_types() |
3725 * @param array $args Method parameters. Contains: |
4212 * |
3726 * - int $blog_id (unused) |
4213 * @param array $args { |
3727 * - string $username |
4214 * Method arguments. Note: arguments must be ordered as documented. |
3728 * - string $password |
4215 * |
3729 * - array $filter |
4216 * @type int $blog_id (unused) |
3730 * - array $fields |
4217 * @type string $username |
|
4218 * @type string $password |
|
4219 * @type array $filter (optional) |
|
4220 * @type array $fields (optional) |
|
4221 * } |
3731 * @return array|IXR_Error |
4222 * @return array|IXR_Error |
3732 */ |
4223 */ |
3733 public function wp_getPostTypes( $args ) { |
4224 public function wp_getPostTypes( $args ) { |
3734 if ( ! $this->minimum_args( $args, 3 ) ) |
4225 if ( ! $this->minimum_args( $args, 3 ) ) |
3735 return $this->error; |
4226 return $this->error; |
3736 |
4227 |
3737 $this->escape( $args ); |
4228 $this->escape( $args ); |
3738 |
4229 |
3739 $username = $args[1]; |
4230 $username = $args[1]; |
3740 $password = $args[2]; |
4231 $password = $args[2]; |
3741 $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
4232 $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
3742 |
4233 |
3743 if ( isset( $args[4] ) ) { |
4234 if ( isset( $args[4] ) ) { |
3744 $fields = $args[4]; |
4235 $fields = $args[4]; |
3745 } else { |
4236 } else { |
3746 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4237 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3776 * in the response array. |
4267 * in the response array. |
3777 * |
4268 * |
3778 * @uses wp_get_post_revisions() |
4269 * @uses wp_get_post_revisions() |
3779 * @see wp_getPost() for more on $fields |
4270 * @see wp_getPost() for more on $fields |
3780 * |
4271 * |
3781 * @param array $args Method parameters. Contains: |
4272 * @param array $args { |
3782 * - int $blog_id (unused) |
4273 * Method arguments. Note: arguments must be ordered as documented. |
3783 * - string $username |
4274 * |
3784 * - string $password |
4275 * @type int $blog_id (unused) |
3785 * - int $post_id |
4276 * @type string $username |
3786 * - array $fields |
4277 * @type string $password |
|
4278 * @type int $post_id |
|
4279 * @type array $fields (optional) |
|
4280 * } |
3787 * @return array|IXR_Error contains a collection of posts. |
4281 * @return array|IXR_Error contains a collection of posts. |
3788 */ |
4282 */ |
3789 public function wp_getRevisions( $args ) { |
4283 public function wp_getRevisions( $args ) { |
3790 if ( ! $this->minimum_args( $args, 4 ) ) |
4284 if ( ! $this->minimum_args( $args, 4 ) ) |
3791 return $this->error; |
4285 return $this->error; |
3792 |
4286 |
3793 $this->escape( $args ); |
4287 $this->escape( $args ); |
3794 |
4288 |
3795 $username = $args[1]; |
4289 $username = $args[1]; |
3796 $password = $args[2]; |
4290 $password = $args[2]; |
3797 $post_id = (int) $args[3]; |
4291 $post_id = (int) $args[3]; |
3798 |
4292 |
3799 if ( isset( $args[4] ) ) { |
4293 if ( isset( $args[4] ) ) { |
3800 $fields = $args[4]; |
4294 $fields = $args[4]; |
3801 } else { |
4295 } else { |
3802 /** |
4296 /** |
3803 * Filter the default revision query fields used by the given XML-RPC method. |
4297 * Filters the default revision query fields used by the given XML-RPC method. |
3804 * |
4298 * |
3805 * @since 3.5.0 |
4299 * @since 3.5.0 |
3806 * |
4300 * |
3807 * @param array $field An array of revision query fields. |
4301 * @param array $field An array of revision query fields. |
3808 * @param string $method The method name. |
4302 * @param string $method The method name. |
3876 |
4373 |
3877 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4374 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3878 do_action( 'xmlrpc_call', 'wp.restoreRevision' ); |
4375 do_action( 'xmlrpc_call', 'wp.restoreRevision' ); |
3879 |
4376 |
3880 if ( ! $revision = wp_get_post_revision( $revision_id ) ) |
4377 if ( ! $revision = wp_get_post_revision( $revision_id ) ) |
3881 return new IXR_Error( 404, __( 'Invalid post ID' ) ); |
4378 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
3882 |
4379 |
3883 if ( wp_is_post_autosave( $revision ) ) |
4380 if ( wp_is_post_autosave( $revision ) ) |
3884 return new IXR_Error( 404, __( 'Invalid post ID' ) ); |
4381 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
3885 |
4382 |
3886 if ( ! $post = get_post( $revision->post_parent ) ) |
4383 if ( ! $post = get_post( $revision->post_parent ) ) |
3887 return new IXR_Error( 404, __( 'Invalid post ID' ) ); |
4384 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
3888 |
4385 |
3889 if ( ! current_user_can( 'edit_post', $revision->post_parent ) ) |
4386 if ( ! current_user_can( 'edit_post', $revision->post_parent ) ) |
3890 return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) ); |
4387 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
3891 |
4388 |
3892 // Check if revisions are disabled. |
4389 // Check if revisions are disabled. |
3893 if ( ! wp_revisions_enabled( $post ) ) |
4390 if ( ! wp_revisions_enabled( $post ) ) |
3894 return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); |
4391 return new IXR_Error( 401, __( 'Sorry, revisions are disabled.' ) ); |
3895 |
4392 |
3897 |
4394 |
3898 return (bool) $post; |
4395 return (bool) $post; |
3899 } |
4396 } |
3900 |
4397 |
3901 /* Blogger API functions. |
4398 /* Blogger API functions. |
3902 * specs on http://plant.blogger.com/api and http://groups.yahoo.com/group/bloggerDev/ |
4399 * specs on http://plant.blogger.com/api and https://groups.yahoo.com/group/bloggerDev/ |
3903 */ |
4400 */ |
3904 |
4401 |
3905 /** |
4402 /** |
3906 * Retrieve blogs that user owns. |
4403 * Retrieve blogs that user owns. |
3907 * |
4404 * |
3908 * Will make more sense once we support multiple blogs. |
4405 * Will make more sense once we support multiple blogs. |
3909 * |
4406 * |
3910 * @since 1.5.0 |
4407 * @since 1.5.0 |
3911 * |
4408 * |
3912 * @param array $args Method parameters. |
4409 * @param array $args { |
|
4410 * Method arguments. Note: arguments must be ordered as documented. |
|
4411 * |
|
4412 * @type int $blog_id (unused) |
|
4413 * @type string $username |
|
4414 * @type string $password |
|
4415 * } |
3913 * @return array|IXR_Error |
4416 * @return array|IXR_Error |
3914 */ |
4417 */ |
3915 public function blogger_getUsersBlogs($args) { |
4418 public function blogger_getUsersBlogs($args) { |
3916 if ( is_multisite() ) |
4419 if ( ! $this->minimum_args( $args, 3 ) ) { |
|
4420 return $this->error; |
|
4421 } |
|
4422 |
|
4423 if ( is_multisite() ) { |
3917 return $this->_multisite_getUsersBlogs($args); |
4424 return $this->_multisite_getUsersBlogs($args); |
|
4425 } |
3918 |
4426 |
3919 $this->escape($args); |
4427 $this->escape($args); |
3920 |
4428 |
3921 $username = $args[1]; |
4429 $username = $args[1]; |
3922 $password = $args[2]; |
4430 $password = $args[2]; |
3923 |
4431 |
3924 if ( !$user = $this->login($username, $password) ) |
4432 if ( !$user = $this->login($username, $password) ) |
3925 return $this->error; |
4433 return $this->error; |
3926 |
4434 |
3927 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4435 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3976 * |
4490 * |
3977 * Gives your client some info about you, so you don't have to. |
4491 * Gives your client some info about you, so you don't have to. |
3978 * |
4492 * |
3979 * @since 1.5.0 |
4493 * @since 1.5.0 |
3980 * |
4494 * |
3981 * @param array $args Method parameters. |
4495 * @param array $args { |
|
4496 * Method arguments. Note: arguments must be ordered as documented. |
|
4497 * |
|
4498 * @type int $blog_id (unused) |
|
4499 * @type string $username |
|
4500 * @type string $password |
|
4501 * } |
3982 * @return array|IXR_Error |
4502 * @return array|IXR_Error |
3983 */ |
4503 */ |
3984 public function blogger_getUserInfo($args) { |
4504 public function blogger_getUserInfo( $args ) { |
3985 |
4505 $this->escape( $args ); |
3986 $this->escape($args); |
|
3987 |
4506 |
3988 $username = $args[1]; |
4507 $username = $args[1]; |
3989 $password = $args[2]; |
4508 $password = $args[2]; |
3990 |
4509 |
3991 if ( !$user = $this->login($username, $password) ) |
4510 if ( !$user = $this->login($username, $password) ) |
3992 return $this->error; |
4511 return $this->error; |
3993 |
4512 |
3994 if ( !current_user_can( 'edit_posts' ) ) |
4513 if ( !current_user_can( 'edit_posts' ) ) |
3995 return new IXR_Error( 401, __( 'Sorry, you do not have access to user data on this site.' ) ); |
4514 return new IXR_Error( 401, __( 'Sorry, you are not allowed to access user data on this site.' ) ); |
3996 |
4515 |
3997 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4516 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3998 do_action( 'xmlrpc_call', 'blogger.getUserInfo' ); |
4517 do_action( 'xmlrpc_call', 'blogger.getUserInfo' ); |
3999 |
4518 |
4000 $struct = array( |
4519 $struct = array( |
4011 /** |
4530 /** |
4012 * Retrieve post. |
4531 * Retrieve post. |
4013 * |
4532 * |
4014 * @since 1.5.0 |
4533 * @since 1.5.0 |
4015 * |
4534 * |
4016 * @param array $args Method parameters. |
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 * } |
4017 * @return array|IXR_Error |
4543 * @return array|IXR_Error |
4018 */ |
4544 */ |
4019 public function blogger_getPost($args) { |
4545 public function blogger_getPost( $args ) { |
4020 |
4546 $this->escape( $args ); |
4021 $this->escape($args); |
4547 |
4022 |
4548 $post_ID = (int) $args[1]; |
4023 $post_ID = (int) $args[1]; |
|
4024 $username = $args[2]; |
4549 $username = $args[2]; |
4025 $password = $args[3]; |
4550 $password = $args[3]; |
4026 |
4551 |
4027 if ( !$user = $this->login($username, $password) ) |
4552 if ( !$user = $this->login($username, $password) ) |
4028 return $this->error; |
4553 return $this->error; |
4029 |
4554 |
4030 $post_data = get_post($post_ID, ARRAY_A); |
4555 $post_data = get_post($post_ID, ARRAY_A); |
4031 if ( ! $post_data ) |
4556 if ( ! $post_data ) |
4032 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
4557 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
4033 |
4558 |
4034 if ( !current_user_can( 'edit_post', $post_ID ) ) |
4559 if ( !current_user_can( 'edit_post', $post_ID ) ) |
4035 return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) ); |
4560 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
4036 |
4561 |
4037 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4562 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4038 do_action( 'xmlrpc_call', 'blogger.getPost' ); |
4563 do_action( 'xmlrpc_call', 'blogger.getPost' ); |
4039 |
4564 |
4040 $categories = implode(',', wp_get_post_categories($post_ID)); |
4565 $categories = implode(',', wp_get_post_categories($post_ID)); |
4056 /** |
4581 /** |
4057 * Retrieve list of recent posts. |
4582 * Retrieve list of recent posts. |
4058 * |
4583 * |
4059 * @since 1.5.0 |
4584 * @since 1.5.0 |
4060 * |
4585 * |
4061 * @param array $args Method parameters. |
4586 * @param array $args { |
|
4587 * Method arguments. Note: arguments must be ordered as documented. |
|
4588 * |
|
4589 * @type string $appkey (unused) |
|
4590 * @type int $blog_id (unused) |
|
4591 * @type string $username |
|
4592 * @type string $password |
|
4593 * @type int $numberposts (optional) |
|
4594 * } |
4062 * @return array|IXR_Error |
4595 * @return array|IXR_Error |
4063 */ |
4596 */ |
4064 public function blogger_getRecentPosts($args) { |
4597 public function blogger_getRecentPosts( $args ) { |
4065 |
4598 |
4066 $this->escape($args); |
4599 $this->escape($args); |
4067 |
4600 |
4068 // $args[0] = appkey - ignored |
4601 // $args[0] = appkey - ignored |
4069 $username = $args[2]; |
4602 $username = $args[2]; |
4070 $password = $args[3]; |
4603 $password = $args[3]; |
4071 if ( isset( $args[4] ) ) |
4604 if ( isset( $args[4] ) ) |
4072 $query = array( 'numberposts' => absint( $args[4] ) ); |
4605 $query = array( 'numberposts' => absint( $args[4] ) ); |
4073 else |
4606 else |
4074 $query = array(); |
4607 $query = array(); |
4075 |
4608 |
4076 if ( !$user = $this->login($username, $password) ) |
4609 if ( !$user = $this->login($username, $password) ) |
4077 return $this->error; |
4610 return $this->error; |
4078 |
4611 |
4079 if ( ! current_user_can( 'edit_posts' ) ) |
4612 if ( ! current_user_can( 'edit_posts' ) ) |
4080 return new IXR_Error( 401, __( 'Sorry, you cannot edit posts on this site.' ) ); |
4613 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
4081 |
4614 |
4082 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4615 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4083 do_action( 'xmlrpc_call', 'blogger.getRecentPosts' ); |
4616 do_action( 'xmlrpc_call', 'blogger.getRecentPosts' ); |
4084 |
4617 |
4085 $posts_list = wp_get_recent_posts( $query ); |
4618 $posts_list = wp_get_recent_posts( $query ); |
4115 /** |
4648 /** |
4116 * Deprecated. |
4649 * Deprecated. |
4117 * |
4650 * |
4118 * @since 1.5.0 |
4651 * @since 1.5.0 |
4119 * @deprecated 3.5.0 |
4652 * @deprecated 3.5.0 |
4120 * @return IXR_Error |
4653 * |
|
4654 * @param array $args Unused. |
|
4655 * @return IXR_Error Error object. |
4121 */ |
4656 */ |
4122 public function blogger_getTemplate($args) { |
4657 public function blogger_getTemplate($args) { |
4123 return new IXR_Error( 403, __('Sorry, that file cannot be edited.' ) ); |
4658 return new IXR_Error( 403, __('Sorry, that file cannot be edited.' ) ); |
4124 } |
4659 } |
4125 |
4660 |
4126 /** |
4661 /** |
4127 * Deprecated. |
4662 * Deprecated. |
4128 * |
4663 * |
4129 * @since 1.5.0 |
4664 * @since 1.5.0 |
4130 * @deprecated 3.5.0 |
4665 * @deprecated 3.5.0 |
4131 * @return IXR_Error |
4666 * |
|
4667 * @param array $args Unused. |
|
4668 * @return IXR_Error Error object. |
4132 */ |
4669 */ |
4133 public function blogger_setTemplate($args) { |
4670 public function blogger_setTemplate($args) { |
4134 return new IXR_Error( 403, __('Sorry, that file cannot be edited.' ) ); |
4671 return new IXR_Error( 403, __('Sorry, that file cannot be edited.' ) ); |
4135 } |
4672 } |
4136 |
4673 |
4137 /** |
4674 /** |
4138 * Create new post. |
4675 * Creates new post. |
4139 * |
4676 * |
4140 * @since 1.5.0 |
4677 * @since 1.5.0 |
4141 * |
4678 * |
4142 * @param array $args Method parameters. |
4679 * @param array $args { |
|
4680 * Method arguments. Note: arguments must be ordered as documented. |
|
4681 * |
|
4682 * @type string $appkey (unused) |
|
4683 * @type int $blog_id (unused) |
|
4684 * @type string $username |
|
4685 * @type string $password |
|
4686 * @type string $content |
|
4687 * @type string $publish |
|
4688 * } |
4143 * @return int|IXR_Error |
4689 * @return int|IXR_Error |
4144 */ |
4690 */ |
4145 public function blogger_newPost($args) { |
4691 public function blogger_newPost( $args ) { |
4146 |
4692 $this->escape( $args ); |
4147 $this->escape($args); |
|
4148 |
4693 |
4149 $username = $args[2]; |
4694 $username = $args[2]; |
4150 $password = $args[3]; |
4695 $password = $args[3]; |
4151 $content = $args[4]; |
4696 $content = $args[4]; |
4152 $publish = $args[5]; |
4697 $publish = $args[5]; |
4153 |
4698 |
4154 if ( !$user = $this->login($username, $password) ) |
4699 if ( !$user = $this->login($username, $password) ) |
4155 return $this->error; |
4700 return $this->error; |
4156 |
4701 |
4157 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4702 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4227 } |
4782 } |
4228 |
4783 |
4229 $this->escape($actual_post); |
4784 $this->escape($actual_post); |
4230 |
4785 |
4231 if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
4786 if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
4232 return new IXR_Error(401, __('Sorry, you do not have the right to edit this post.')); |
4787 return new IXR_Error(401, __('Sorry, you are not allowed to edit this post.')); |
4233 } |
4788 } |
4234 if ( 'publish' == $actual_post['post_status'] && ! current_user_can( 'publish_posts' ) ) { |
4789 if ( 'publish' == $actual_post['post_status'] && ! current_user_can( 'publish_posts' ) ) { |
4235 return new IXR_Error( 401, __( 'Sorry, you do not have the right to publish this post.' ) ); |
4790 return new IXR_Error( 401, __( 'Sorry, you are not allowed to publish this post.' ) ); |
4236 } |
4791 } |
4237 |
4792 |
4238 $postdata = array(); |
4793 $postdata = array(); |
4239 $postdata['ID'] = $actual_post['ID']; |
4794 $postdata['ID'] = $actual_post['ID']; |
4240 $postdata['post_content'] = xmlrpc_removepostdata( $content ); |
4795 $postdata['post_content'] = xmlrpc_removepostdata( $content ); |
4241 $postdata['post_title'] = xmlrpc_getposttitle( $content ); |
4796 $postdata['post_title'] = xmlrpc_getposttitle( $content ); |
4242 $postdata['post_category'] = xmlrpc_getpostcategory( $content ); |
4797 $postdata['post_category'] = xmlrpc_getpostcategory( $content ); |
4243 $postdata['post_status'] = $actual_post['post_status']; |
4798 $postdata['post_status'] = $actual_post['post_status']; |
4244 $postdata['post_excerpt'] = $actual_post['post_excerpt']; |
4799 $postdata['post_excerpt'] = $actual_post['post_excerpt']; |
|
4800 $postdata['post_status'] = $publish ? 'publish' : 'draft'; |
4245 |
4801 |
4246 $result = wp_update_post( $postdata ); |
4802 $result = wp_update_post( $postdata ); |
4247 |
4803 |
4248 if ( ! $result ) { |
4804 if ( ! $result ) { |
4249 return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be edited.')); |
4805 return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be edited.')); |
4266 /** |
4822 /** |
4267 * Remove a post. |
4823 * Remove a post. |
4268 * |
4824 * |
4269 * @since 1.5.0 |
4825 * @since 1.5.0 |
4270 * |
4826 * |
4271 * @param array $args Method parameters. |
4827 * @param array $args { |
4272 * @return bool|IXR_Error True when post is deleted. |
4828 * Method arguments. Note: arguments must be ordered as documented. |
4273 */ |
4829 * |
4274 public function blogger_deletePost($args) { |
4830 * @type int $blog_id (unused) |
4275 $this->escape($args); |
4831 * @type int $post_ID |
4276 |
4832 * @type string $username |
4277 $post_ID = (int) $args[1]; |
4833 * @type string $password |
4278 $username = $args[2]; |
4834 * } |
4279 $password = $args[3]; |
4835 * @return true|IXR_Error True when post is deleted. |
|
4836 */ |
|
4837 public function blogger_deletePost( $args ) { |
|
4838 $this->escape( $args ); |
|
4839 |
|
4840 $post_ID = (int) $args[1]; |
|
4841 $username = $args[2]; |
|
4842 $password = $args[3]; |
4280 |
4843 |
4281 if ( !$user = $this->login($username, $password) ) |
4844 if ( !$user = $this->login($username, $password) ) |
4282 return $this->error; |
4845 return $this->error; |
4283 |
4846 |
4284 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4847 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4285 do_action( 'xmlrpc_call', 'blogger.deletePost' ); |
4848 do_action( 'xmlrpc_call', 'blogger.deletePost' ); |
4286 |
4849 |
4287 $actual_post = get_post($post_ID,ARRAY_A); |
4850 $actual_post = get_post( $post_ID, ARRAY_A ); |
4288 |
4851 |
4289 if ( !$actual_post || $actual_post['post_type'] != 'post' ) |
4852 if ( ! $actual_post || $actual_post['post_type'] != 'post' ) { |
4290 return new IXR_Error(404, __('Sorry, no such post.')); |
4853 return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
4291 |
4854 } |
4292 if ( !current_user_can('delete_post', $post_ID) ) |
4855 |
4293 return new IXR_Error(401, __('Sorry, you do not have the right to delete this post.')); |
4856 if ( ! current_user_can( 'delete_post', $post_ID ) ) { |
4294 |
4857 return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this post.' ) ); |
4295 $result = wp_delete_post($post_ID); |
4858 } |
4296 |
4859 |
4297 if ( !$result ) |
4860 $result = wp_delete_post( $post_ID ); |
4298 return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be deleted.')); |
4861 |
|
4862 if ( ! $result ) { |
|
4863 return new IXR_Error( 500, __( 'The post cannot be deleted.' ) ); |
|
4864 } |
4299 |
4865 |
4300 /** |
4866 /** |
4301 * Fires after a post has been successfully deleted via the XML-RPC Blogger API. |
4867 * Fires after a post has been successfully deleted via the XML-RPC Blogger API. |
4302 * |
4868 * |
4303 * @since 3.4.0 |
4869 * @since 3.4.0 |
4339 * - dateCreated |
4905 * - dateCreated |
4340 * - wp_post_thumbnail |
4906 * - wp_post_thumbnail |
4341 * |
4907 * |
4342 * @since 1.5.0 |
4908 * @since 1.5.0 |
4343 * |
4909 * |
4344 * @param array $args Method parameters. Contains: |
4910 * @param array $args { |
4345 * - blog_id (unused) |
4911 * Method arguments. Note: arguments must be ordered as documented. |
4346 * - username |
4912 * |
4347 * - password |
4913 * @type int $blog_id (unused) |
4348 * - content_struct |
4914 * @type string $username |
4349 * - publish |
4915 * @type string $password |
|
4916 * @type array $content_struct |
|
4917 * @type int $publish |
|
4918 * } |
4350 * @return int|IXR_Error |
4919 * @return int|IXR_Error |
4351 */ |
4920 */ |
4352 public function mw_newPost($args) { |
4921 public function mw_newPost($args) { |
4353 $this->escape($args); |
4922 $this->escape($args); |
4354 |
4923 |
4355 $username = $args[1]; |
4924 $username = $args[1]; |
4356 $password = $args[2]; |
4925 $password = $args[2]; |
4357 $content_struct = $args[3]; |
4926 $content_struct = $args[3]; |
4358 $publish = isset( $args[4] ) ? $args[4] : 0; |
4927 $publish = isset( $args[4] ) ? $args[4] : 0; |
4359 |
4928 |
4360 if ( !$user = $this->login($username, $password) ) |
4929 if ( !$user = $this->login($username, $password) ) |
4361 return $this->error; |
4930 return $this->error; |
4362 |
4931 |
4363 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4932 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4436 // If an author id was provided then use it instead. |
5005 // If an author id was provided then use it instead. |
4437 if ( isset( $content_struct['wp_author_id'] ) && ( $user->ID != $content_struct['wp_author_id'] ) ) { |
5006 if ( isset( $content_struct['wp_author_id'] ) && ( $user->ID != $content_struct['wp_author_id'] ) ) { |
4438 switch ( $post_type ) { |
5007 switch ( $post_type ) { |
4439 case "post": |
5008 case "post": |
4440 if ( !current_user_can( 'edit_others_posts' ) ) |
5009 if ( !current_user_can( 'edit_others_posts' ) ) |
4441 return new IXR_Error( 401, __( 'You are not allowed to create posts as this user.' ) ); |
5010 return new IXR_Error( 401, __( 'Sorry, you are not allowed to create posts as this user.' ) ); |
4442 break; |
5011 break; |
4443 case "page": |
5012 case "page": |
4444 if ( !current_user_can( 'edit_others_pages' ) ) |
5013 if ( !current_user_can( 'edit_others_pages' ) ) |
4445 return new IXR_Error( 401, __( 'You are not allowed to create pages as this user.' ) ); |
5014 return new IXR_Error( 401, __( 'Sorry, you are not allowed to create pages as this user.' ) ); |
4446 break; |
5015 break; |
4447 default: |
5016 default: |
4448 return new IXR_Error( 401, __( 'Invalid post type' ) ); |
5017 return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
4449 } |
5018 } |
4450 $author = get_userdata( $content_struct['wp_author_id'] ); |
5019 $author = get_userdata( $content_struct['wp_author_id'] ); |
4451 if ( ! $author ) |
5020 if ( ! $author ) |
4452 return new IXR_Error( 404, __( 'Invalid author ID.' ) ); |
5021 return new IXR_Error( 404, __( 'Invalid author ID.' ) ); |
4453 $post_author = $content_struct['wp_author_id']; |
5022 $post_author = $content_struct['wp_author_id']; |
4694 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5278 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4695 do_action( 'xmlrpc_call', 'metaWeblog.editPost' ); |
5279 do_action( 'xmlrpc_call', 'metaWeblog.editPost' ); |
4696 |
5280 |
4697 $postdata = get_post( $post_ID, ARRAY_A ); |
5281 $postdata = get_post( $post_ID, ARRAY_A ); |
4698 |
5282 |
4699 // If there is no post data for the give post id, stop |
5283 /* |
4700 // now and return an error. Other wise a new post will be |
5284 * If there is no post data for the give post id, stop now and return an error. |
4701 // created (which was the old behavior). |
5285 * Otherwise a new post will be created (which was the old behavior). |
|
5286 */ |
4702 if ( ! $postdata || empty( $postdata[ 'ID' ] ) ) |
5287 if ( ! $postdata || empty( $postdata[ 'ID' ] ) ) |
4703 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
5288 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
4704 |
5289 |
4705 if ( ! current_user_can( 'edit_post', $post_ID ) ) |
5290 if ( ! current_user_can( 'edit_post', $post_ID ) ) |
4706 return new IXR_Error( 401, __( 'Sorry, you do not have the right to edit this post.' ) ); |
5291 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
4707 |
5292 |
4708 // Use wp.editPost to edit post types other than post and page. |
5293 // Use wp.editPost to edit post types other than post and page. |
4709 if ( ! in_array( $postdata[ 'post_type' ], array( 'post', 'page' ) ) ) |
5294 if ( ! in_array( $postdata[ 'post_type' ], array( 'post', 'page' ) ) ) |
4710 return new IXR_Error( 401, __( 'Invalid post type' ) ); |
5295 return new IXR_Error( 401, __( 'Invalid post type.' ) ); |
4711 |
5296 |
4712 // Thwart attempt to change the post type. |
5297 // Thwart attempt to change the post type. |
4713 if ( ! empty( $content_struct[ 'post_type' ] ) && ( $content_struct['post_type'] != $postdata[ 'post_type' ] ) ) |
5298 if ( ! empty( $content_struct[ 'post_type' ] ) && ( $content_struct['post_type'] != $postdata[ 'post_type' ] ) ) |
4714 return new IXR_Error( 401, __( 'The post type may not be changed.' ) ); |
5299 return new IXR_Error( 401, __( 'The post type may not be changed.' ) ); |
4715 |
5300 |
4716 // Check for a valid post format if one was given |
5301 // Check for a valid post format if one was given |
4717 if ( isset( $content_struct['wp_post_format'] ) ) { |
5302 if ( isset( $content_struct['wp_post_format'] ) ) { |
4718 $content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] ); |
5303 $content_struct['wp_post_format'] = sanitize_key( $content_struct['wp_post_format'] ); |
4719 if ( !array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) { |
5304 if ( !array_key_exists( $content_struct['wp_post_format'], get_post_format_strings() ) ) { |
4720 return new IXR_Error( 404, __( 'Invalid post format' ) ); |
5305 return new IXR_Error( 404, __( 'Invalid post format.' ) ); |
4721 } |
5306 } |
4722 } |
5307 } |
4723 |
5308 |
4724 $this->escape($postdata); |
5309 $this->escape($postdata); |
4725 |
5310 |
4889 $to_ping = $content_struct['mt_tb_ping_urls']; |
5473 $to_ping = $content_struct['mt_tb_ping_urls']; |
4890 if ( is_array($to_ping) ) |
5474 if ( is_array($to_ping) ) |
4891 $to_ping = implode(' ', $to_ping); |
5475 $to_ping = implode(' ', $to_ping); |
4892 } |
5476 } |
4893 |
5477 |
4894 // Do some timestamp voodoo |
5478 // Do some timestamp voodoo. |
4895 if ( !empty( $content_struct['date_created_gmt'] ) ) |
5479 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 |
5480 // We know this is supposed to be GMT, so we're going to slap that Z on there by force. |
4897 $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
5481 $dateCreated = rtrim( $content_struct['date_created_gmt']->getIso(), 'Z' ) . 'Z'; |
4898 elseif ( !empty( $content_struct['dateCreated']) ) |
5482 elseif ( !empty( $content_struct['dateCreated']) ) |
4899 $dateCreated = $content_struct['dateCreated']->getIso(); |
5483 $dateCreated = $content_struct['dateCreated']->getIso(); |
4900 |
5484 |
|
5485 // Default to not flagging the post date to be edited unless it's intentional. |
|
5486 $edit_date = false; |
|
5487 |
4901 if ( !empty( $dateCreated ) ) { |
5488 if ( !empty( $dateCreated ) ) { |
4902 $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); |
5489 $post_date = get_date_from_gmt(iso8601_to_datetime($dateCreated)); |
4903 $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT'); |
5490 $post_date_gmt = iso8601_to_datetime($dateCreated, 'GMT'); |
|
5491 |
|
5492 // Flag the post date to be edited. |
|
5493 $edit_date = true; |
4904 } else { |
5494 } else { |
4905 $post_date = $postdata['post_date']; |
5495 $post_date = $postdata['post_date']; |
4906 $post_date_gmt = $postdata['post_date_gmt']; |
5496 $post_date_gmt = $postdata['post_date_gmt']; |
4907 } |
5497 } |
4908 |
5498 |
4909 // We've got all the data -- post it: |
5499 // We've got all the data -- post it. |
4910 $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'); |
5500 $newpost = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt', 'comment_status', 'ping_status', 'edit_date', 'post_date', 'post_date_gmt', 'to_ping', 'post_name', 'post_password', 'post_parent', 'menu_order', 'post_author', 'tags_input', 'page_template'); |
4911 |
5501 |
4912 $result = wp_update_post($newpost, true); |
5502 $result = wp_update_post($newpost, true); |
4913 if ( is_wp_error( $result ) ) |
5503 if ( is_wp_error( $result ) ) |
4914 return new IXR_Error(500, $result->get_error_message()); |
5504 return new IXR_Error(500, $result->get_error_message()); |
4915 |
5505 |
4916 if ( !$result ) |
5506 if ( !$result ) |
4917 return new IXR_Error(500, __('Sorry, your entry could not be edited. Something wrong happened.')); |
5507 return new IXR_Error(500, __('Sorry, your entry could not be edited.')); |
4918 |
5508 |
4919 // Only posts can be sticky |
5509 // Only posts can be sticky |
4920 if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) { |
5510 if ( $post_type == 'post' && isset( $content_struct['sticky'] ) ) { |
4921 if ( $content_struct['sticky'] == true ) |
5511 $data = $newpost; |
4922 stick_post( $post_ID ); |
5512 $data['sticky'] = $content_struct['sticky']; |
4923 elseif ( $content_struct['sticky'] == false ) |
5513 $data['post_type'] = 'post'; |
4924 unstick_post( $post_ID ); |
5514 $error = $this->_toggle_sticky( $data, true ); |
|
5515 if ( $error ) { |
|
5516 return $error; |
|
5517 } |
4925 } |
5518 } |
4926 |
5519 |
4927 if ( isset($content_struct['custom_fields']) ) |
5520 if ( isset($content_struct['custom_fields']) ) |
4928 $this->set_custom_fields($post_ID, $content_struct['custom_fields']); |
5521 $this->set_custom_fields($post_ID, $content_struct['custom_fields']); |
4929 |
5522 |
4930 if ( isset ( $content_struct['wp_post_thumbnail'] ) ) { |
5523 if ( isset ( $content_struct['wp_post_thumbnail'] ) ) { |
4931 // empty value deletes, non-empty value adds/updates |
5524 |
|
5525 // Empty value deletes, non-empty value adds/updates. |
4932 if ( empty( $content_struct['wp_post_thumbnail'] ) ) { |
5526 if ( empty( $content_struct['wp_post_thumbnail'] ) ) { |
4933 delete_post_thumbnail( $post_ID ); |
5527 delete_post_thumbnail( $post_ID ); |
4934 } else { |
5528 } else { |
4935 if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false ) |
5529 if ( set_post_thumbnail( $post_ID, $content_struct['wp_post_thumbnail'] ) === false ) |
4936 return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
5530 return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
4937 } |
5531 } |
4938 unset( $content_struct['wp_post_thumbnail'] ); |
5532 unset( $content_struct['wp_post_thumbnail'] ); |
4939 } |
5533 } |
4940 |
5534 |
4941 // Handle enclosures |
5535 // Handle enclosures. |
4942 $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null; |
5536 $thisEnclosure = isset($content_struct['enclosure']) ? $content_struct['enclosure'] : null; |
4943 $this->add_enclosure_if_new($post_ID, $thisEnclosure); |
5537 $this->add_enclosure_if_new($post_ID, $thisEnclosure); |
4944 |
5538 |
4945 $this->attach_uploads( $ID, $post_content ); |
5539 $this->attach_uploads( $ID, $post_content ); |
4946 |
5540 |
4947 // Handle post formats if assigned, validation is handled |
5541 // Handle post formats if assigned, validation is handled earlier in this function. |
4948 // earlier in this function |
|
4949 if ( isset( $content_struct['wp_post_format'] ) ) |
5542 if ( isset( $content_struct['wp_post_format'] ) ) |
4950 set_post_format( $post_ID, $content_struct['wp_post_format'] ); |
5543 set_post_format( $post_ID, $content_struct['wp_post_format'] ); |
4951 |
5544 |
4952 /** |
5545 /** |
4953 * Fires after a post has been successfully updated via the XML-RPC MovableType API. |
5546 * Fires after a post has been successfully updated via the XML-RPC MovableType API. |
4965 /** |
5558 /** |
4966 * Retrieve post. |
5559 * Retrieve post. |
4967 * |
5560 * |
4968 * @since 1.5.0 |
5561 * @since 1.5.0 |
4969 * |
5562 * |
4970 * @param array $args Method parameters. |
5563 * @param array $args { |
|
5564 * Method arguments. Note: arguments must be ordered as documented. |
|
5565 * |
|
5566 * @type int $blog_id (unused) |
|
5567 * @type int $post_ID |
|
5568 * @type string $username |
|
5569 * @type string $password |
|
5570 * } |
4971 * @return array|IXR_Error |
5571 * @return array|IXR_Error |
4972 */ |
5572 */ |
4973 public function mw_getPost($args) { |
5573 public function mw_getPost( $args ) { |
4974 |
5574 $this->escape( $args ); |
4975 $this->escape($args); |
5575 |
4976 |
5576 $post_ID = (int) $args[0]; |
4977 $post_ID = (int) $args[0]; |
5577 $username = $args[1]; |
4978 $username = $args[1]; |
5578 $password = $args[2]; |
4979 $password = $args[2]; |
|
4980 |
5579 |
4981 if ( !$user = $this->login($username, $password) ) |
5580 if ( !$user = $this->login($username, $password) ) |
4982 return $this->error; |
5581 return $this->error; |
4983 |
5582 |
4984 $postdata = get_post($post_ID, ARRAY_A); |
5583 $postdata = get_post($post_ID, ARRAY_A); |
4985 if ( ! $postdata ) |
5584 if ( ! $postdata ) |
4986 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
5585 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
4987 |
5586 |
4988 if ( !current_user_can( 'edit_post', $post_ID ) ) |
5587 if ( !current_user_can( 'edit_post', $post_ID ) ) |
4989 return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) ); |
5588 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
4990 |
5589 |
4991 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5590 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4992 do_action( 'xmlrpc_call', 'metaWeblog.getPost' ); |
5591 do_action( 'xmlrpc_call', 'metaWeblog.getPost' ); |
4993 |
5592 |
4994 if ($postdata['post_date'] != '') { |
5593 if ($postdata['post_date'] != '') { |
5090 /** |
5689 /** |
5091 * Retrieve list of recent posts. |
5690 * Retrieve list of recent posts. |
5092 * |
5691 * |
5093 * @since 1.5.0 |
5692 * @since 1.5.0 |
5094 * |
5693 * |
5095 * @param array $args Method parameters. |
5694 * @param array $args { |
|
5695 * Method arguments. Note: arguments must be ordered as documented. |
|
5696 * |
|
5697 * @type int $blog_id (unused) |
|
5698 * @type string $username |
|
5699 * @type string $password |
|
5700 * @type int $numberposts |
|
5701 * } |
5096 * @return array|IXR_Error |
5702 * @return array|IXR_Error |
5097 */ |
5703 */ |
5098 public function mw_getRecentPosts($args) { |
5704 public function mw_getRecentPosts( $args ) { |
5099 |
5705 $this->escape( $args ); |
5100 $this->escape($args); |
5706 |
5101 |
5707 $username = $args[1]; |
5102 $username = $args[1]; |
5708 $password = $args[2]; |
5103 $password = $args[2]; |
|
5104 if ( isset( $args[3] ) ) |
5709 if ( isset( $args[3] ) ) |
5105 $query = array( 'numberposts' => absint( $args[3] ) ); |
5710 $query = array( 'numberposts' => absint( $args[3] ) ); |
5106 else |
5711 else |
5107 $query = array(); |
5712 $query = array(); |
5108 |
5713 |
5109 if ( !$user = $this->login($username, $password) ) |
5714 if ( !$user = $this->login($username, $password) ) |
5110 return $this->error; |
5715 return $this->error; |
5111 |
5716 |
5112 if ( ! current_user_can( 'edit_posts' ) ) |
5717 if ( ! current_user_can( 'edit_posts' ) ) |
5113 return new IXR_Error( 401, __( 'Sorry, you cannot edit posts on this site.' ) ); |
5718 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
5114 |
5719 |
5115 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5720 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5116 do_action( 'xmlrpc_call', 'metaWeblog.getRecentPosts' ); |
5721 do_action( 'xmlrpc_call', 'metaWeblog.getRecentPosts' ); |
5117 |
5722 |
5118 $posts_list = wp_get_recent_posts( $query ); |
5723 $posts_list = wp_get_recent_posts( $query ); |
5289 */ |
5913 */ |
5290 if ( $upload_err = apply_filters( 'pre_upload_error', false ) ) { |
5914 if ( $upload_err = apply_filters( 'pre_upload_error', false ) ) { |
5291 return new IXR_Error( 500, $upload_err ); |
5915 return new IXR_Error( 500, $upload_err ); |
5292 } |
5916 } |
5293 |
5917 |
5294 if ( !empty($data['overwrite']) && ($data['overwrite'] == true) ) { |
|
5295 // Get postmeta info on the object. |
|
5296 $old_file = $wpdb->get_row(" |
|
5297 SELECT ID |
|
5298 FROM {$wpdb->posts} |
|
5299 WHERE post_title = '{$name}' |
|
5300 AND post_type = 'attachment' |
|
5301 "); |
|
5302 |
|
5303 // Delete previous file. |
|
5304 wp_delete_attachment($old_file->ID); |
|
5305 |
|
5306 // Make sure the new name is different by pre-pending the |
|
5307 // previous post id. |
|
5308 $filename = preg_replace('/^wpid\d+-/', '', $name); |
|
5309 $name = "wpid{$old_file->ID}-{$filename}"; |
|
5310 } |
|
5311 |
|
5312 $upload = wp_upload_bits($name, null, $bits); |
5918 $upload = wp_upload_bits($name, null, $bits); |
5313 if ( ! empty($upload['error']) ) { |
5919 if ( ! empty($upload['error']) ) { |
5314 $errorString = sprintf(__('Could not write file %1$s (%2$s)'), $name, $upload['error']); |
5920 /* translators: 1: file name, 2: error message */ |
5315 return new IXR_Error(500, $errorString); |
5921 $errorString = sprintf( __( 'Could not write file %1$s (%2$s).' ), $name, $upload['error'] ); |
|
5922 return new IXR_Error( 500, $errorString ); |
5316 } |
5923 } |
5317 // Construct the attachment array |
5924 // Construct the attachment array |
5318 $post_id = 0; |
5925 $post_id = 0; |
5319 if ( ! empty( $data['post_id'] ) ) { |
5926 if ( ! empty( $data['post_id'] ) ) { |
5320 $post_id = (int) $data['post_id']; |
5927 $post_id = (int) $data['post_id']; |
5321 |
5928 |
5322 if ( ! current_user_can( 'edit_post', $post_id ) ) |
5929 if ( ! current_user_can( 'edit_post', $post_id ) ) |
5323 return new IXR_Error( 401, __( 'Sorry, you cannot edit this post.' ) ); |
5930 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
5324 } |
5931 } |
5325 $attachment = array( |
5932 $attachment = array( |
5326 'post_title' => $name, |
5933 'post_title' => $name, |
5327 'post_content' => '', |
5934 'post_content' => '', |
5328 'post_type' => 'attachment', |
5935 'post_type' => 'attachment', |
5456 /** |
6073 /** |
5457 * Retrieve post categories. |
6074 * Retrieve post categories. |
5458 * |
6075 * |
5459 * @since 1.5.0 |
6076 * @since 1.5.0 |
5460 * |
6077 * |
5461 * @param array $args Method parameters. |
6078 * @param array $args { |
|
6079 * Method arguments. Note: arguments must be ordered as documented. |
|
6080 * |
|
6081 * @type int $post_ID |
|
6082 * @type string $username |
|
6083 * @type string $password |
|
6084 * } |
5462 * @return array|IXR_Error |
6085 * @return array|IXR_Error |
5463 */ |
6086 */ |
5464 public function mt_getPostCategories($args) { |
6087 public function mt_getPostCategories( $args ) { |
5465 |
6088 $this->escape( $args ); |
5466 $this->escape($args); |
6089 |
5467 |
6090 $post_ID = (int) $args[0]; |
5468 $post_ID = (int) $args[0]; |
6091 $username = $args[1]; |
5469 $username = $args[1]; |
6092 $password = $args[2]; |
5470 $password = $args[2]; |
|
5471 |
6093 |
5472 if ( !$user = $this->login($username, $password) ) |
6094 if ( !$user = $this->login($username, $password) ) |
5473 return $this->error; |
6095 return $this->error; |
5474 |
6096 |
5475 if ( ! get_post( $post_ID ) ) |
6097 if ( ! get_post( $post_ID ) ) |
5476 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
6098 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
5477 |
6099 |
5478 if ( !current_user_can( 'edit_post', $post_ID ) ) |
6100 if ( !current_user_can( 'edit_post', $post_ID ) ) |
5479 return new IXR_Error( 401, __( 'Sorry, you can not edit this post.' ) ); |
6101 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
5480 |
6102 |
5481 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6103 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5482 do_action( 'xmlrpc_call', 'mt.getPostCategories' ); |
6104 do_action( 'xmlrpc_call', 'mt.getPostCategories' ); |
5483 |
6105 |
5484 $categories = array(); |
6106 $categories = array(); |
5539 /** |
6167 /** |
5540 * Retrieve an array of methods supported by this server. |
6168 * Retrieve an array of methods supported by this server. |
5541 * |
6169 * |
5542 * @since 1.5.0 |
6170 * @since 1.5.0 |
5543 * |
6171 * |
5544 * @param array $args Method parameters. |
|
5545 * @return array |
6172 * @return array |
5546 */ |
6173 */ |
5547 public function mt_supportedMethods($args) { |
6174 public function mt_supportedMethods() { |
5548 |
|
5549 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6175 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5550 do_action( 'xmlrpc_call', 'mt.supportedMethods' ); |
6176 do_action( 'xmlrpc_call', 'mt.supportedMethods' ); |
5551 |
6177 |
5552 $supported_methods = array(); |
6178 return array_keys( $this->methods ); |
5553 foreach ( $this->methods as $key => $value ) { |
|
5554 $supported_methods[] = $key; |
|
5555 } |
|
5556 |
|
5557 return $supported_methods; |
|
5558 } |
6179 } |
5559 |
6180 |
5560 /** |
6181 /** |
5561 * Retrieve an empty array because we don't support per-post text filters. |
6182 * Retrieve an empty array because we don't support per-post text filters. |
5562 * |
6183 * |
5563 * @since 1.5.0 |
6184 * @since 1.5.0 |
5564 * |
6185 */ |
5565 * @param array $args Method parameters. |
6186 public function mt_supportedTextFilters() { |
5566 */ |
|
5567 public function mt_supportedTextFilters($args) { |
|
5568 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6187 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5569 do_action( 'xmlrpc_call', 'mt.supportedTextFilters' ); |
6188 do_action( 'xmlrpc_call', 'mt.supportedTextFilters' ); |
5570 |
6189 |
5571 /** |
6190 /** |
5572 * Filter the MoveableType text filters list for XML-RPC. |
6191 * Filters the MoveableType text filters list for XML-RPC. |
5573 * |
6192 * |
5574 * @since 2.2.0 |
6193 * @since 2.2.0 |
5575 * |
6194 * |
5576 * @param array $filters An array of text filters. |
6195 * @param array $filters An array of text filters. |
5577 */ |
6196 */ |
5669 /** |
6290 /** |
5670 * Retrieves a pingback and registers it. |
6291 * Retrieves a pingback and registers it. |
5671 * |
6292 * |
5672 * @since 1.5.0 |
6293 * @since 1.5.0 |
5673 * |
6294 * |
5674 * @param array $args Method parameters. |
6295 * @param array $args { |
|
6296 * Method arguments. Note: arguments must be ordered as documented. |
|
6297 * |
|
6298 * @type string $pagelinkedfrom |
|
6299 * @type string $pagelinkedto |
|
6300 * } |
5675 * @return string|IXR_Error |
6301 * @return string|IXR_Error |
5676 */ |
6302 */ |
5677 public function pingback_ping($args) { |
6303 public function pingback_ping( $args ) { |
5678 global $wpdb; |
6304 global $wpdb; |
5679 |
6305 |
5680 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6306 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5681 do_action( 'xmlrpc_call', 'pingback.ping' ); |
6307 do_action( 'xmlrpc_call', 'pingback.ping' ); |
5682 |
6308 |
5683 $this->escape($args); |
6309 $this->escape( $args ); |
5684 |
6310 |
5685 $pagelinkedfrom = $args[0]; |
6311 $pagelinkedfrom = str_replace( '&', '&', $args[0] ); |
5686 $pagelinkedto = $args[1]; |
6312 $pagelinkedto = str_replace( '&', '&', $args[1] ); |
5687 |
6313 $pagelinkedto = str_replace( '&', '&', $pagelinkedto ); |
5688 $pagelinkedfrom = str_replace('&', '&', $pagelinkedfrom); |
|
5689 $pagelinkedto = str_replace('&', '&', $pagelinkedto); |
|
5690 $pagelinkedto = str_replace('&', '&', $pagelinkedto); |
|
5691 |
6314 |
5692 /** |
6315 /** |
5693 * Filter the pingback source URI. |
6316 * Filters the pingback source URI. |
5694 * |
6317 * |
5695 * @since 3.6.0 |
6318 * @since 3.6.0 |
5696 * |
6319 * |
5697 * @param string $pagelinkedfrom URI of the page linked from. |
6320 * @param string $pagelinkedfrom URI of the page linked from. |
5698 * @param string $pagelinkedto URI of the page linked to. |
6321 * @param string $pagelinkedto URI of the page linked to. |
5776 'user-agent' => "$user_agent; verifying pingback from $remote_ip", |
6399 'user-agent' => "$user_agent; verifying pingback from $remote_ip", |
5777 'headers' => array( |
6400 'headers' => array( |
5778 'X-Pingback-Forwarded-For' => $remote_ip, |
6401 'X-Pingback-Forwarded-For' => $remote_ip, |
5779 ), |
6402 ), |
5780 ); |
6403 ); |
|
6404 |
5781 $request = wp_safe_remote_get( $pagelinkedfrom, $http_api_args ); |
6405 $request = wp_safe_remote_get( $pagelinkedfrom, $http_api_args ); |
5782 $linea = wp_remote_retrieve_body( $request ); |
6406 $remote_source = $remote_source_original = wp_remote_retrieve_body( $request ); |
5783 |
6407 |
5784 if ( !$linea ) |
6408 if ( ! $remote_source ) { |
5785 return $this->pingback_error( 16, __( 'The source URL does not exist.' ) ); |
6409 return $this->pingback_error( 16, __( 'The source URL does not exist.' ) ); |
|
6410 } |
5786 |
6411 |
5787 /** |
6412 /** |
5788 * Filter the pingback remote source. |
6413 * Filters the pingback remote source. |
5789 * |
6414 * |
5790 * @since 2.5.0 |
6415 * @since 2.5.0 |
5791 * |
6416 * |
5792 * @param string $linea Response object for the page linked from. |
6417 * @param string $remote_source Response source for the page linked from. |
5793 * @param string $pagelinkedto URL of the page linked to. |
6418 * @param string $pagelinkedto URL of the page linked to. |
5794 */ |
6419 */ |
5795 $linea = apply_filters( 'pre_remote_source', $linea, $pagelinkedto ); |
6420 $remote_source = apply_filters( 'pre_remote_source', $remote_source, $pagelinkedto ); |
5796 |
6421 |
5797 // Work around bug in strip_tags(): |
6422 // Work around bug in strip_tags(): |
5798 $linea = str_replace('<!DOC', '<DOC', $linea); |
6423 $remote_source = str_replace( '<!DOC', '<DOC', $remote_source ); |
5799 $linea = preg_replace( '/[\r\n\t ]+/', ' ', $linea ); // normalize spaces |
6424 $remote_source = preg_replace( '/[\r\n\t ]+/', ' ', $remote_source ); // normalize spaces |
5800 $linea = preg_replace( "/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/", "\n\n", $linea ); |
6425 $remote_source = preg_replace( "/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/", "\n\n", $remote_source ); |
5801 |
6426 |
5802 preg_match('|<title>([^<]*?)</title>|is', $linea, $matchtitle); |
6427 preg_match( '|<title>([^<]*?)</title>|is', $remote_source, $matchtitle ); |
5803 $title = $matchtitle[1]; |
6428 $title = isset( $matchtitle[1] ) ? $matchtitle[1] : ''; |
5804 if ( empty( $title ) ) |
6429 if ( empty( $title ) ) { |
5805 return $this->pingback_error( 32, __('We cannot find a title on that page.' ) ); |
6430 return $this->pingback_error( 32, __( 'We cannot find a title on that page.' ) ); |
5806 |
6431 } |
5807 $linea = strip_tags( $linea, '<a>' ); // just keep the tag we need |
6432 |
5808 |
6433 $remote_source = strip_tags( $remote_source, '<a>' ); // just keep the tag we need |
5809 $p = explode( "\n\n", $linea ); |
6434 |
|
6435 $p = explode( "\n\n", $remote_source ); |
5810 |
6436 |
5811 $preg_target = preg_quote($pagelinkedto, '|'); |
6437 $preg_target = preg_quote($pagelinkedto, '|'); |
5812 |
6438 |
5813 foreach ( $p as $para ) { |
6439 foreach ( $p as $para ) { |
5814 if ( strpos($para, $pagelinkedto) !== false ) { // it exists, but is it a link? |
6440 if ( strpos($para, $pagelinkedto) !== false ) { // it exists, but is it a link? |
5852 $comment_author_url = $pagelinkedfrom; |
6478 $comment_author_url = $pagelinkedfrom; |
5853 $comment_content = $context; |
6479 $comment_content = $context; |
5854 $this->escape($comment_content); |
6480 $this->escape($comment_content); |
5855 $comment_type = 'pingback'; |
6481 $comment_type = 'pingback'; |
5856 |
6482 |
5857 $commentdata = compact('comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', 'comment_content', 'comment_type'); |
6483 $commentdata = compact( |
|
6484 'comment_post_ID', 'comment_author', 'comment_author_url', 'comment_author_email', |
|
6485 'comment_content', 'comment_type', 'remote_source', 'remote_source_original' |
|
6486 ); |
5858 |
6487 |
5859 $comment_ID = wp_new_comment($commentdata); |
6488 $comment_ID = wp_new_comment($commentdata); |
|
6489 |
|
6490 if ( is_wp_error( $comment_ID ) ) { |
|
6491 return $this->pingback_error( 0, $comment_ID->get_error_message() ); |
|
6492 } |
5860 |
6493 |
5861 /** |
6494 /** |
5862 * Fires after a post pingback has been sent. |
6495 * Fires after a post pingback has been sent. |
5863 * |
6496 * |
5864 * @since 0.71 |
6497 * @since 0.71 |
5865 * |
6498 * |
5866 * @param int $comment_ID Comment ID. |
6499 * @param int $comment_ID Comment ID. |
5867 */ |
6500 */ |
5868 do_action( 'pingback_post', $comment_ID ); |
6501 do_action( 'pingback_post', $comment_ID ); |
5869 |
6502 |
5870 return sprintf(__('Pingback from %1$s to %2$s registered. Keep the web talking! :-)'), $pagelinkedfrom, $pagelinkedto); |
6503 /* translators: 1: URL of the page linked from, 2: URL of the page linked to */ |
|
6504 return sprintf( __( 'Pingback from %1$s to %2$s registered. Keep the web talking! :-)' ), $pagelinkedfrom, $pagelinkedto ); |
5871 } |
6505 } |
5872 |
6506 |
5873 /** |
6507 /** |
5874 * Retrieve array of URLs that pingbacked the given URL. |
6508 * Retrieve array of URLs that pingbacked the given URL. |
5875 * |
6509 * |
5876 * Specs on http://www.aquarionics.com/misc/archives/blogite/0198.html |
6510 * Specs on http://www.aquarionics.com/misc/archives/blogite/0198.html |
5877 * |
6511 * |
5878 * @since 1.5.0 |
6512 * @since 1.5.0 |
5879 * |
6513 * |
5880 * @param array $args Method parameters. |
6514 * @global wpdb $wpdb WordPress database abstraction object. |
|
6515 * |
|
6516 * @param string $url |
5881 * @return array|IXR_Error |
6517 * @return array|IXR_Error |
5882 */ |
6518 */ |
5883 public function pingback_extensions_getPingbacks($args) { |
6519 public function pingback_extensions_getPingbacks( $url ) { |
5884 |
|
5885 global $wpdb; |
6520 global $wpdb; |
5886 |
6521 |
5887 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6522 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5888 do_action( 'xmlrpc_call', 'pingback.extensions.getPingbacks' ); |
6523 do_action( 'xmlrpc_call', 'pingback.extensions.getPingbacks' ); |
5889 |
6524 |
5890 $this->escape($args); |
6525 $url = $this->escape( $url ); |
5891 |
|
5892 $url = $args; |
|
5893 |
6526 |
5894 $post_ID = url_to_postid($url); |
6527 $post_ID = url_to_postid($url); |
5895 if ( !$post_ID ) { |
6528 if ( !$post_ID ) { |
5896 // We aren't sure that the resource is available and/or pingback enabled |
6529 // We aren't sure that the resource is available and/or pingback enabled |
5897 return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.' ) ); |
6530 return $this->pingback_error( 33, __( 'The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.' ) ); |