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 {@see 'xmlrpc_enabled'} filter found in wp_xmlrpc_server::login(). |
17 * via the {@see 'xmlrpc_enabled'} filter found in wp_xmlrpc_server::set_is_enabled(). |
18 * |
18 * |
19 * @since 1.5.0 |
19 * @since 1.5.0 |
20 * |
20 * |
21 * @see IXR_Server |
21 * @see IXR_Server |
22 */ |
22 */ |
162 * @since 1.5.0 |
169 * @since 1.5.0 |
163 * |
170 * |
164 * @param string[] $methods An array of XML-RPC methods, keyed by their methodName. |
171 * @param string[] $methods An array of XML-RPC methods, keyed by their methodName. |
165 */ |
172 */ |
166 $this->methods = apply_filters( 'xmlrpc_methods', $this->methods ); |
173 $this->methods = apply_filters( 'xmlrpc_methods', $this->methods ); |
167 } |
174 |
168 |
175 $this->set_is_enabled(); |
169 /** |
176 } |
170 * Make private/protected methods readable for backward compatibility. |
177 |
171 * |
178 /** |
172 * @since 4.0.0 |
179 * Set wp_xmlrpc_server::$is_enabled property. |
173 * |
180 * |
174 * @param string $name Method to call. |
181 * Determine whether the xmlrpc server is enabled on this WordPress install |
175 * @param array $arguments Arguments to pass when calling. |
182 * and set the is_enabled property accordingly. |
176 * @return array|IXR_Error|false Return value of the callback, false otherwise. |
183 * |
177 */ |
184 * @since 5.7.3 |
178 public function __call( $name, $arguments ) { |
185 */ |
179 if ( '_multisite_getUsersBlogs' === $name ) { |
186 private function set_is_enabled() { |
180 return $this->_multisite_getUsersBlogs( ...$arguments ); |
|
181 } |
|
182 return false; |
|
183 } |
|
184 |
|
185 /** |
|
186 * Serves the XML-RPC request. |
|
187 * |
|
188 * @since 2.9.0 |
|
189 */ |
|
190 public function serve_request() { |
|
191 $this->IXR_Server( $this->methods ); |
|
192 } |
|
193 |
|
194 /** |
|
195 * Test XMLRPC API by saying, "Hello!" to client. |
|
196 * |
|
197 * @since 1.5.0 |
|
198 * |
|
199 * @return string Hello string response. |
|
200 */ |
|
201 public function sayHello() { |
|
202 return 'Hello!'; |
|
203 } |
|
204 |
|
205 /** |
|
206 * Test XMLRPC API by adding two numbers for client. |
|
207 * |
|
208 * @since 1.5.0 |
|
209 * |
|
210 * @param array $args { |
|
211 * Method arguments. Note: arguments must be ordered as documented. |
|
212 * |
|
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 ) { |
|
219 $number1 = $args[0]; |
|
220 $number2 = $args[1]; |
|
221 return $number1 + $number2; |
|
222 } |
|
223 |
|
224 /** |
|
225 * Log user in. |
|
226 * |
|
227 * @since 2.8.0 |
|
228 * |
|
229 * @param string $username User's username. |
|
230 * @param string $password User's password. |
|
231 * @return WP_User|bool WP_User object if authentication passed, false otherwise |
|
232 */ |
|
233 public function login( $username, $password ) { |
|
234 /* |
187 /* |
235 * Respect old get_option() filters left for back-compat when the 'enable_xmlrpc' |
188 * Respect old get_option() filters left for back-compat when the 'enable_xmlrpc' |
236 * option was deprecated in 3.5.0. Use the 'xmlrpc_enabled' hook instead. |
189 * option was deprecated in 3.5.0. Use the 'xmlrpc_enabled' hook instead. |
237 */ |
190 */ |
238 $enabled = apply_filters( 'pre_option_enable_xmlrpc', false ); |
191 $is_enabled = apply_filters( 'pre_option_enable_xmlrpc', false ); |
239 if ( false === $enabled ) { |
192 if ( false === $is_enabled ) { |
240 $enabled = apply_filters( 'option_enable_xmlrpc', true ); |
193 $is_enabled = apply_filters( 'option_enable_xmlrpc', true ); |
241 } |
194 } |
242 |
195 |
243 /** |
196 /** |
244 * Filters whether XML-RPC methods requiring authentication are enabled. |
197 * Filters whether XML-RPC methods requiring authentication are enabled. |
245 * |
198 * |
258 * For more granular control over all XML-RPC methods and requests, see the {@see 'xmlrpc_methods'} |
211 * For more granular control over all XML-RPC methods and requests, see the {@see 'xmlrpc_methods'} |
259 * and {@see 'xmlrpc_element_limit'} hooks. |
212 * and {@see 'xmlrpc_element_limit'} hooks. |
260 * |
213 * |
261 * @since 3.5.0 |
214 * @since 3.5.0 |
262 * |
215 * |
263 * @param bool $enabled Whether XML-RPC is enabled. Default true. |
216 * @param bool $is_enabled Whether XML-RPC is enabled. Default true. |
264 */ |
217 */ |
265 $enabled = apply_filters( 'xmlrpc_enabled', $enabled ); |
218 $this->is_enabled = apply_filters( 'xmlrpc_enabled', $is_enabled ); |
266 |
219 } |
267 if ( ! $enabled ) { |
220 |
|
221 /** |
|
222 * Make private/protected methods readable for backward compatibility. |
|
223 * |
|
224 * @since 4.0.0 |
|
225 * |
|
226 * @param string $name Method to call. |
|
227 * @param array $arguments Arguments to pass when calling. |
|
228 * @return array|IXR_Error|false Return value of the callback, false otherwise. |
|
229 */ |
|
230 public function __call( $name, $arguments ) { |
|
231 if ( '_multisite_getUsersBlogs' === $name ) { |
|
232 return $this->_multisite_getUsersBlogs( ...$arguments ); |
|
233 } |
|
234 return false; |
|
235 } |
|
236 |
|
237 /** |
|
238 * Serves the XML-RPC request. |
|
239 * |
|
240 * @since 2.9.0 |
|
241 */ |
|
242 public function serve_request() { |
|
243 $this->IXR_Server( $this->methods ); |
|
244 } |
|
245 |
|
246 /** |
|
247 * Test XMLRPC API by saying, "Hello!" to client. |
|
248 * |
|
249 * @since 1.5.0 |
|
250 * |
|
251 * @return string Hello string response. |
|
252 */ |
|
253 public function sayHello() { |
|
254 return 'Hello!'; |
|
255 } |
|
256 |
|
257 /** |
|
258 * Test XMLRPC API by adding two numbers for client. |
|
259 * |
|
260 * @since 1.5.0 |
|
261 * |
|
262 * @param array $args { |
|
263 * Method arguments. Note: arguments must be ordered as documented. |
|
264 * |
|
265 * @type int $number1 A number to add. |
|
266 * @type int $number2 A second number to add. |
|
267 * } |
|
268 * @return int Sum of the two given numbers. |
|
269 */ |
|
270 public function addTwoNumbers( $args ) { |
|
271 $number1 = $args[0]; |
|
272 $number2 = $args[1]; |
|
273 return $number1 + $number2; |
|
274 } |
|
275 |
|
276 /** |
|
277 * Log user in. |
|
278 * |
|
279 * @since 2.8.0 |
|
280 * |
|
281 * @param string $username User's username. |
|
282 * @param string $password User's password. |
|
283 * @return WP_User|false WP_User object if authentication passed, false otherwise |
|
284 */ |
|
285 public function login( $username, $password ) { |
|
286 if ( ! $this->is_enabled ) { |
268 $this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site.' ) ) ); |
287 $this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site.' ) ) ); |
269 return false; |
288 return false; |
270 } |
289 } |
271 |
290 |
272 if ( $this->auth_failed ) { |
291 if ( $this->auth_failed ) { |
331 $this->escape( $v ); |
350 $this->escape( $v ); |
332 } elseif ( ! is_object( $v ) ) { |
351 } elseif ( ! is_object( $v ) ) { |
333 $v = wp_slash( $v ); |
352 $v = wp_slash( $v ); |
334 } |
353 } |
335 } |
354 } |
|
355 } |
|
356 |
|
357 /** |
|
358 * Send error response to client. |
|
359 * |
|
360 * Send an XML error response to the client. If the endpoint is enabled |
|
361 * an HTTP 200 response is always sent per the XML-RPC specification. |
|
362 * |
|
363 * @since 5.7.3 |
|
364 * |
|
365 * @param IXR_Error|string $error Error code or an error object. |
|
366 * @param false $message Error message. Optional. |
|
367 */ |
|
368 public function error( $error, $message = false ) { |
|
369 // Accepts either an error object or an error code and message |
|
370 if ( $message && ! is_object( $error ) ) { |
|
371 $error = new IXR_Error( $error, $message ); |
|
372 } |
|
373 |
|
374 if ( ! $this->is_enabled ) { |
|
375 status_header( $error->code ); |
|
376 } |
|
377 |
|
378 $this->output( $error->getXml() ); |
336 } |
379 } |
337 |
380 |
338 /** |
381 /** |
339 * Retrieve custom fields for post. |
382 * Retrieve custom fields for post. |
340 * |
383 * |
679 * |
722 * |
680 * All built-in XML-RPC methods use the action xmlrpc_call, with a parameter |
723 * All built-in XML-RPC methods use the action xmlrpc_call, with a parameter |
681 * equal to the method's name, e.g., wp.getUsersBlogs, wp.newPost, etc. |
724 * equal to the method's name, e.g., wp.getUsersBlogs, wp.newPost, etc. |
682 * |
725 * |
683 * @since 2.5.0 |
726 * @since 2.5.0 |
|
727 * @since 5.7.0 Added the `$args` and `$server` parameters. |
684 * |
728 * |
685 * @param string $name The method name. |
729 * @param string $name The method name. |
|
730 * @param array|string $args The escaped arguments passed to the method. |
|
731 * @param wp_xmlrpc_server $server The XML-RPC server instance. |
686 */ |
732 */ |
687 do_action( 'xmlrpc_call', 'wp.getUsersBlogs' ); |
733 do_action( 'xmlrpc_call', 'wp.getUsersBlogs', $args, $this ); |
688 |
734 |
689 $blogs = (array) get_blogs_of_user( $user->ID ); |
735 $blogs = (array) get_blogs_of_user( $user->ID ); |
690 $struct = array(); |
736 $struct = array(); |
691 $primary_blog_id = 0; |
737 $primary_blog_id = 0; |
692 $active_blog = get_active_blog_for_user( $user->ID ); |
738 $active_blog = get_active_blog_for_user( $user->ID ); |
741 } |
787 } |
742 |
788 |
743 /** |
789 /** |
744 * Prepares taxonomy data for return in an XML-RPC object. |
790 * Prepares taxonomy data for return in an XML-RPC object. |
745 * |
791 * |
746 * @param object $taxonomy The unprepared taxonomy data. |
792 * @param WP_Taxonomy $taxonomy The unprepared taxonomy data. |
747 * @param array $fields The subset of taxonomy fields to return. |
793 * @param array $fields The subset of taxonomy fields to return. |
748 * @return array The prepared taxonomy data. |
794 * @return array The prepared taxonomy data. |
749 */ |
795 */ |
750 protected function _prepare_taxonomy( $taxonomy, $fields ) { |
796 protected function _prepare_taxonomy( $taxonomy, $fields ) { |
751 $_taxonomy = array( |
797 $_taxonomy = array( |
752 'name' => $taxonomy->name, |
798 'name' => $taxonomy->name, |
764 if ( in_array( 'cap', $fields, true ) ) { |
810 if ( in_array( 'cap', $fields, true ) ) { |
765 $_taxonomy['cap'] = (array) $taxonomy->cap; |
811 $_taxonomy['cap'] = (array) $taxonomy->cap; |
766 } |
812 } |
767 |
813 |
768 if ( in_array( 'menu', $fields, true ) ) { |
814 if ( in_array( 'menu', $fields, true ) ) { |
769 $_taxonomy['show_in_menu'] = (bool) $_taxonomy->show_in_menu; |
815 $_taxonomy['show_in_menu'] = (bool) $taxonomy->show_in_menu; |
770 } |
816 } |
771 |
817 |
772 if ( in_array( 'object_type', $fields, true ) ) { |
818 if ( in_array( 'object_type', $fields, true ) ) { |
773 $_taxonomy['object_type'] = array_unique( (array) $taxonomy->object_type ); |
819 $_taxonomy['object_type'] = array_unique( (array) $taxonomy->object_type ); |
774 } |
820 } |
796 if ( ! is_array( $_term ) ) { |
842 if ( ! is_array( $_term ) ) { |
797 $_term = get_object_vars( $_term ); |
843 $_term = get_object_vars( $_term ); |
798 } |
844 } |
799 |
845 |
800 // For integers which may be larger than XML-RPC supports ensure we return strings. |
846 // For integers which may be larger than XML-RPC supports ensure we return strings. |
801 $_term['term_id'] = strval( $_term['term_id'] ); |
847 $_term['term_id'] = (string) $_term['term_id']; |
802 $_term['term_group'] = strval( $_term['term_group'] ); |
848 $_term['term_group'] = (string) $_term['term_group']; |
803 $_term['term_taxonomy_id'] = strval( $_term['term_taxonomy_id'] ); |
849 $_term['term_taxonomy_id'] = (string) $_term['term_taxonomy_id']; |
804 $_term['parent'] = strval( $_term['parent'] ); |
850 $_term['parent'] = (string) $_term['parent']; |
805 |
851 |
806 // Count we are happy to return as an integer because people really shouldn't use terms that much. |
852 // Count we are happy to return as an integer because people really shouldn't use terms that much. |
807 $_term['count'] = intval( $_term['count'] ); |
853 $_term['count'] = (int) $_term['count']; |
808 |
854 |
809 // Get term meta. |
855 // Get term meta. |
810 $_term['custom_fields'] = $this->get_term_custom_fields( $_term['term_id'] ); |
856 $_term['custom_fields'] = $this->get_term_custom_fields( $_term['term_id'] ); |
811 |
857 |
812 /** |
858 /** |
854 * @param array $fields The subset of post type fields to return. |
900 * @param array $fields The subset of post type fields to return. |
855 * @return array The prepared post data. |
901 * @return array The prepared post data. |
856 */ |
902 */ |
857 protected function _prepare_post( $post, $fields ) { |
903 protected function _prepare_post( $post, $fields ) { |
858 // Holds the data for this post. built up based on $fields. |
904 // Holds the data for this post. built up based on $fields. |
859 $_post = array( 'post_id' => strval( $post['ID'] ) ); |
905 $_post = array( 'post_id' => (string) $post['ID'] ); |
860 |
906 |
861 // Prepare common post fields. |
907 // Prepare common post fields. |
862 $post_fields = array( |
908 $post_fields = array( |
863 'post_title' => $post['post_title'], |
909 'post_title' => $post['post_title'], |
864 'post_date' => $this->_convert_date( $post['post_date'] ), |
910 'post_date' => $this->_convert_date( $post['post_date'] ), |
870 'post_name' => $post['post_name'], |
916 'post_name' => $post['post_name'], |
871 'post_author' => $post['post_author'], |
917 'post_author' => $post['post_author'], |
872 'post_password' => $post['post_password'], |
918 'post_password' => $post['post_password'], |
873 'post_excerpt' => $post['post_excerpt'], |
919 'post_excerpt' => $post['post_excerpt'], |
874 'post_content' => $post['post_content'], |
920 'post_content' => $post['post_content'], |
875 'post_parent' => strval( $post['post_parent'] ), |
921 'post_parent' => (string) $post['post_parent'], |
876 'post_mime_type' => $post['post_mime_type'], |
922 'post_mime_type' => $post['post_mime_type'], |
877 'link' => get_permalink( $post['ID'] ), |
923 'link' => get_permalink( $post['ID'] ), |
878 'guid' => $post['guid'], |
924 'guid' => $post['guid'], |
879 'menu_order' => intval( $post['menu_order'] ), |
925 'menu_order' => (int) $post['menu_order'], |
880 'comment_status' => $post['comment_status'], |
926 'comment_status' => $post['comment_status'], |
881 'ping_status' => $post['ping_status'], |
927 'ping_status' => $post['ping_status'], |
882 'sticky' => ( 'post' === $post['post_type'] && is_sticky( $post['ID'] ) ), |
928 'sticky' => ( 'post' === $post['post_type'] && is_sticky( $post['ID'] ) ), |
883 ); |
929 ); |
884 |
930 |
1001 } |
1047 } |
1002 |
1048 |
1003 /** |
1049 /** |
1004 * Prepares media item data for return in an XML-RPC object. |
1050 * Prepares media item data for return in an XML-RPC object. |
1005 * |
1051 * |
1006 * @param object $media_item The unprepared media item data. |
1052 * @param WP_Post $media_item The unprepared media item data. |
1007 * @param string $thumbnail_size The image size to use for the thumbnail URL. |
1053 * @param string $thumbnail_size The image size to use for the thumbnail URL. |
1008 * @return array The prepared media item data. |
1054 * @return array The prepared media item data. |
1009 */ |
1055 */ |
1010 protected function _prepare_media_item( $media_item, $thumbnail_size = 'thumbnail' ) { |
1056 protected function _prepare_media_item( $media_item, $thumbnail_size = 'thumbnail' ) { |
1011 $_media_item = array( |
1057 $_media_item = array( |
1012 'attachment_id' => strval( $media_item->ID ), |
1058 'attachment_id' => (string) $media_item->ID, |
1013 'date_created_gmt' => $this->_convert_date_gmt( $media_item->post_date_gmt, $media_item->post_date ), |
1059 'date_created_gmt' => $this->_convert_date_gmt( $media_item->post_date_gmt, $media_item->post_date ), |
1014 'parent' => $media_item->post_parent, |
1060 'parent' => $media_item->post_parent, |
1015 'link' => wp_get_attachment_url( $media_item->ID ), |
1061 'link' => wp_get_attachment_url( $media_item->ID ), |
1016 'title' => $media_item->post_title, |
1062 'title' => $media_item->post_title, |
1017 'caption' => $media_item->post_excerpt, |
1063 'caption' => $media_item->post_excerpt, |
1030 /** |
1076 /** |
1031 * Filters XML-RPC-prepared data for the given media item. |
1077 * Filters XML-RPC-prepared data for the given media item. |
1032 * |
1078 * |
1033 * @since 3.4.0 |
1079 * @since 3.4.0 |
1034 * |
1080 * |
1035 * @param array $_media_item An array of media item data. |
1081 * @param array $_media_item An array of media item data. |
1036 * @param object $media_item Media item object. |
1082 * @param WP_Post $media_item Media item object. |
1037 * @param string $thumbnail_size Image size. |
1083 * @param string $thumbnail_size Image size. |
1038 */ |
1084 */ |
1039 return apply_filters( 'xmlrpc_prepare_media_item', $_media_item, $media_item, $thumbnail_size ); |
1085 return apply_filters( 'xmlrpc_prepare_media_item', $_media_item, $media_item, $thumbnail_size ); |
1040 } |
1086 } |
1041 |
1087 |
1042 /** |
1088 /** |
1043 * Prepares page data for return in an XML-RPC object. |
1089 * Prepares page data for return in an XML-RPC object. |
1044 * |
1090 * |
1045 * @param object $page The unprepared page data. |
1091 * @param WP_Post $page The unprepared page data. |
1046 * @return array The prepared page data. |
1092 * @return array The prepared page data. |
1047 */ |
1093 */ |
1048 protected function _prepare_page( $page ) { |
1094 protected function _prepare_page( $page ) { |
1049 // Get all of the page content and link. |
1095 // Get all of the page content and link. |
1050 $full_page = get_extended( $page->post_content ); |
1096 $full_page = get_extended( $page->post_content ); |
1120 } |
1166 } |
1121 |
1167 |
1122 /** |
1168 /** |
1123 * Prepares comment data for return in an XML-RPC object. |
1169 * Prepares comment data for return in an XML-RPC object. |
1124 * |
1170 * |
1125 * @param object $comment The unprepared comment data. |
1171 * @param WP_Comment $comment The unprepared comment data. |
1126 * @return array The prepared comment data. |
1172 * @return array The prepared comment data. |
1127 */ |
1173 */ |
1128 protected function _prepare_comment( $comment ) { |
1174 protected function _prepare_comment( $comment ) { |
1129 // Format page date. |
1175 // Format page date. |
1130 $comment_date_gmt = $this->_convert_date_gmt( $comment->comment_date_gmt, $comment->comment_date ); |
1176 $comment_date_gmt = $this->_convert_date_gmt( $comment->comment_date_gmt, $comment->comment_date ); |
1172 * @param WP_User $user The unprepared user object. |
1218 * @param WP_User $user The unprepared user object. |
1173 * @param array $fields The subset of user fields to return. |
1219 * @param array $fields The subset of user fields to return. |
1174 * @return array The prepared user data. |
1220 * @return array The prepared user data. |
1175 */ |
1221 */ |
1176 protected function _prepare_user( $user, $fields ) { |
1222 protected function _prepare_user( $user, $fields ) { |
1177 $_user = array( 'user_id' => strval( $user->ID ) ); |
1223 $_user = array( 'user_id' => (string) $user->ID ); |
1178 |
1224 |
1179 $user_fields = array( |
1225 $user_fields = array( |
1180 'username' => $user->user_login, |
1226 'username' => $user->user_login, |
1181 'first_name' => $user->user_firstname, |
1227 'first_name' => $user->user_firstname, |
1182 'last_name' => $user->user_lastname, |
1228 'last_name' => $user->user_lastname, |
1292 $content_struct['post_date_gmt'] = $this->_convert_date( $content_struct['post_date_gmt'] ); |
1338 $content_struct['post_date_gmt'] = $this->_convert_date( $content_struct['post_date_gmt'] ); |
1293 } |
1339 } |
1294 } |
1340 } |
1295 |
1341 |
1296 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1342 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1297 do_action( 'xmlrpc_call', 'wp.newPost' ); |
1343 do_action( 'xmlrpc_call', 'wp.newPost', $args, $this ); |
1298 |
1344 |
1299 unset( $content_struct['ID'] ); |
1345 unset( $content_struct['ID'] ); |
1300 |
1346 |
1301 return $this->_insert_post( $user, $content_struct ); |
1347 return $this->_insert_post( $user, $content_struct ); |
1302 } |
1348 } |
1684 if ( ! $user ) { |
1731 if ( ! $user ) { |
1685 return $this->error; |
1732 return $this->error; |
1686 } |
1733 } |
1687 |
1734 |
1688 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1735 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1689 do_action( 'xmlrpc_call', 'wp.editPost' ); |
1736 do_action( 'xmlrpc_call', 'wp.editPost', $args, $this ); |
1690 |
1737 |
1691 $post = get_post( $post_id, ARRAY_A ); |
1738 $post = get_post( $post_id, ARRAY_A ); |
1692 |
1739 |
1693 if ( empty( $post['ID'] ) ) { |
1740 if ( empty( $post['ID'] ) ) { |
1694 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
1741 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
1767 if ( ! $user ) { |
1814 if ( ! $user ) { |
1768 return $this->error; |
1815 return $this->error; |
1769 } |
1816 } |
1770 |
1817 |
1771 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1818 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1772 do_action( 'xmlrpc_call', 'wp.deletePost' ); |
1819 do_action( 'xmlrpc_call', 'wp.deletePost', $args, $this ); |
1773 |
1820 |
1774 $post = get_post( $post_id, ARRAY_A ); |
1821 $post = get_post( $post_id, ARRAY_A ); |
1775 if ( empty( $post['ID'] ) ) { |
1822 if ( empty( $post['ID'] ) ) { |
1776 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
1823 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
1777 } |
1824 } |
1867 if ( ! $user ) { |
1914 if ( ! $user ) { |
1868 return $this->error; |
1915 return $this->error; |
1869 } |
1916 } |
1870 |
1917 |
1871 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1918 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1872 do_action( 'xmlrpc_call', 'wp.getPost' ); |
1919 do_action( 'xmlrpc_call', 'wp.getPost', $args, $this ); |
1873 |
1920 |
1874 $post = get_post( $post_id, ARRAY_A ); |
1921 $post = get_post( $post_id, ARRAY_A ); |
1875 |
1922 |
1876 if ( empty( $post['ID'] ) ) { |
1923 if ( empty( $post['ID'] ) ) { |
1877 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
1924 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
1928 if ( ! $user ) { |
1975 if ( ! $user ) { |
1929 return $this->error; |
1976 return $this->error; |
1930 } |
1977 } |
1931 |
1978 |
1932 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1979 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1933 do_action( 'xmlrpc_call', 'wp.getPosts' ); |
1980 do_action( 'xmlrpc_call', 'wp.getPosts', $args, $this ); |
1934 |
1981 |
1935 $query = array(); |
1982 $query = array(); |
1936 |
1983 |
1937 if ( isset( $filter['post_type'] ) ) { |
1984 if ( isset( $filter['post_type'] ) ) { |
1938 $post_type = get_post_type_object( $filter['post_type'] ); |
1985 $post_type = get_post_type_object( $filter['post_type'] ); |
2027 if ( ! $user ) { |
2074 if ( ! $user ) { |
2028 return $this->error; |
2075 return $this->error; |
2029 } |
2076 } |
2030 |
2077 |
2031 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2078 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2032 do_action( 'xmlrpc_call', 'wp.newTerm' ); |
2079 do_action( 'xmlrpc_call', 'wp.newTerm', $args, $this ); |
2033 |
2080 |
2034 if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) { |
2081 if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) { |
2035 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
2082 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
2036 } |
2083 } |
2037 |
2084 |
2132 if ( ! $user ) { |
2179 if ( ! $user ) { |
2133 return $this->error; |
2180 return $this->error; |
2134 } |
2181 } |
2135 |
2182 |
2136 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2183 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2137 do_action( 'xmlrpc_call', 'wp.editTerm' ); |
2184 do_action( 'xmlrpc_call', 'wp.editTerm', $args, $this ); |
2138 |
2185 |
2139 if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) { |
2186 if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) { |
2140 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
2187 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
2141 } |
2188 } |
2142 |
2189 |
2228 * @type string $username Username. |
2275 * @type string $username Username. |
2229 * @type string $password Password. |
2276 * @type string $password Password. |
2230 * @type string $taxnomy_name Taxonomy name. |
2277 * @type string $taxnomy_name Taxonomy name. |
2231 * @type int $term_id Term ID. |
2278 * @type int $term_id Term ID. |
2232 * } |
2279 * } |
2233 * @return bool|IXR_Error True on success, IXR_Error instance on failure. |
2280 * @return true|IXR_Error True on success, IXR_Error instance on failure. |
2234 */ |
2281 */ |
2235 public function wp_deleteTerm( $args ) { |
2282 public function wp_deleteTerm( $args ) { |
2236 if ( ! $this->minimum_args( $args, 5 ) ) { |
2283 if ( ! $this->minimum_args( $args, 5 ) ) { |
2237 return $this->error; |
2284 return $this->error; |
2238 } |
2285 } |
2248 if ( ! $user ) { |
2295 if ( ! $user ) { |
2249 return $this->error; |
2296 return $this->error; |
2250 } |
2297 } |
2251 |
2298 |
2252 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2299 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2253 do_action( 'xmlrpc_call', 'wp.deleteTerm' ); |
2300 do_action( 'xmlrpc_call', 'wp.deleteTerm', $args, $this ); |
2254 |
2301 |
2255 if ( ! taxonomy_exists( $taxonomy ) ) { |
2302 if ( ! taxonomy_exists( $taxonomy ) ) { |
2256 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
2303 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
2257 } |
2304 } |
2258 |
2305 |
2327 if ( ! $user ) { |
2374 if ( ! $user ) { |
2328 return $this->error; |
2375 return $this->error; |
2329 } |
2376 } |
2330 |
2377 |
2331 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2378 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2332 do_action( 'xmlrpc_call', 'wp.getTerm' ); |
2379 do_action( 'xmlrpc_call', 'wp.getTerm', $args, $this ); |
2333 |
2380 |
2334 if ( ! taxonomy_exists( $taxonomy ) ) { |
2381 if ( ! taxonomy_exists( $taxonomy ) ) { |
2335 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
2382 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
2336 } |
2383 } |
2337 |
2384 |
2392 if ( ! $user ) { |
2439 if ( ! $user ) { |
2393 return $this->error; |
2440 return $this->error; |
2394 } |
2441 } |
2395 |
2442 |
2396 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2443 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2397 do_action( 'xmlrpc_call', 'wp.getTerms' ); |
2444 do_action( 'xmlrpc_call', 'wp.getTerms', $args, $this ); |
2398 |
2445 |
2399 if ( ! taxonomy_exists( $taxonomy ) ) { |
2446 if ( ! taxonomy_exists( $taxonomy ) ) { |
2400 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
2447 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
2401 } |
2448 } |
2402 |
2449 |
2498 if ( ! $user ) { |
2545 if ( ! $user ) { |
2499 return $this->error; |
2546 return $this->error; |
2500 } |
2547 } |
2501 |
2548 |
2502 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2549 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2503 do_action( 'xmlrpc_call', 'wp.getTaxonomy' ); |
2550 do_action( 'xmlrpc_call', 'wp.getTaxonomy', $args, $this ); |
2504 |
2551 |
2505 if ( ! taxonomy_exists( $taxonomy ) ) { |
2552 if ( ! taxonomy_exists( $taxonomy ) ) { |
2506 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
2553 return new IXR_Error( 403, __( 'Invalid taxonomy.' ) ); |
2507 } |
2554 } |
2508 |
2555 |
2556 if ( ! $user ) { |
2603 if ( ! $user ) { |
2557 return $this->error; |
2604 return $this->error; |
2558 } |
2605 } |
2559 |
2606 |
2560 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2607 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2561 do_action( 'xmlrpc_call', 'wp.getTaxonomies' ); |
2608 do_action( 'xmlrpc_call', 'wp.getTaxonomies', $args, $this ); |
2562 |
2609 |
2563 $taxonomies = get_taxonomies( $filter, 'objects' ); |
2610 $taxonomies = get_taxonomies( $filter, 'objects' ); |
2564 |
2611 |
2565 // Holds all the taxonomy data. |
2612 // Holds all the taxonomy data. |
2566 $struct = array(); |
2613 $struct = array(); |
2642 if ( ! $user ) { |
2689 if ( ! $user ) { |
2643 return $this->error; |
2690 return $this->error; |
2644 } |
2691 } |
2645 |
2692 |
2646 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2693 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2647 do_action( 'xmlrpc_call', 'wp.getUser' ); |
2694 do_action( 'xmlrpc_call', 'wp.getUser', $args, $this ); |
2648 |
2695 |
2649 if ( ! current_user_can( 'edit_user', $user_id ) ) { |
2696 if ( ! current_user_can( 'edit_user', $user_id ) ) { |
2650 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this user.' ) ); |
2697 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this user.' ) ); |
2651 } |
2698 } |
2652 |
2699 |
2705 if ( ! $user ) { |
2752 if ( ! $user ) { |
2706 return $this->error; |
2753 return $this->error; |
2707 } |
2754 } |
2708 |
2755 |
2709 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2756 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2710 do_action( 'xmlrpc_call', 'wp.getUsers' ); |
2757 do_action( 'xmlrpc_call', 'wp.getUsers', $args, $this ); |
2711 |
2758 |
2712 if ( ! current_user_can( 'list_users' ) ) { |
2759 if ( ! current_user_can( 'list_users' ) ) { |
2713 return new IXR_Error( 401, __( 'Sorry, you are not allowed to list users.' ) ); |
2760 return new IXR_Error( 401, __( 'Sorry, you are not allowed to list users.' ) ); |
2714 } |
2761 } |
2715 |
2762 |
2785 if ( ! $user ) { |
2832 if ( ! $user ) { |
2786 return $this->error; |
2833 return $this->error; |
2787 } |
2834 } |
2788 |
2835 |
2789 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2836 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2790 do_action( 'xmlrpc_call', 'wp.getProfile' ); |
2837 do_action( 'xmlrpc_call', 'wp.getProfile', $args, $this ); |
2791 |
2838 |
2792 if ( ! current_user_can( 'edit_user', $user->ID ) ) { |
2839 if ( ! current_user_can( 'edit_user', $user->ID ) ) { |
2793 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) ); |
2840 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) ); |
2794 } |
2841 } |
2795 |
2842 |
2835 if ( ! $user ) { |
2882 if ( ! $user ) { |
2836 return $this->error; |
2883 return $this->error; |
2837 } |
2884 } |
2838 |
2885 |
2839 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2886 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2840 do_action( 'xmlrpc_call', 'wp.editProfile' ); |
2887 do_action( 'xmlrpc_call', 'wp.editProfile', $args, $this ); |
2841 |
2888 |
2842 if ( ! current_user_can( 'edit_user', $user->ID ) ) { |
2889 if ( ! current_user_can( 'edit_user', $user->ID ) ) { |
2843 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) ); |
2890 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit your profile.' ) ); |
2844 } |
2891 } |
2845 |
2892 |
2924 if ( ! current_user_can( 'edit_page', $page_id ) ) { |
2971 if ( ! current_user_can( 'edit_page', $page_id ) ) { |
2925 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) ); |
2972 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this page.' ) ); |
2926 } |
2973 } |
2927 |
2974 |
2928 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2975 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2929 do_action( 'xmlrpc_call', 'wp.getPage' ); |
2976 do_action( 'xmlrpc_call', 'wp.getPage', $args, $this ); |
2930 |
2977 |
2931 // If we found the page then format the data. |
2978 // If we found the page then format the data. |
2932 if ( $page->ID && ( 'page' === $page->post_type ) ) { |
2979 if ( $page->ID && ( 'page' === $page->post_type ) ) { |
2933 return $this->_prepare_page( $page ); |
2980 return $this->_prepare_page( $page ); |
2934 } else { |
2981 } else { |
2967 if ( ! current_user_can( 'edit_pages' ) ) { |
3014 if ( ! current_user_can( 'edit_pages' ) ) { |
2968 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
3015 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
2969 } |
3016 } |
2970 |
3017 |
2971 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3018 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2972 do_action( 'xmlrpc_call', 'wp.getPages' ); |
3019 do_action( 'xmlrpc_call', 'wp.getPages', $args, $this ); |
2973 |
3020 |
2974 $pages = get_posts( |
3021 $pages = get_posts( |
2975 array( |
3022 array( |
2976 'post_type' => 'page', |
3023 'post_type' => 'page', |
2977 'post_status' => 'any', |
3024 'post_status' => 'any', |
3022 if ( ! $user ) { |
3069 if ( ! $user ) { |
3023 return $this->error; |
3070 return $this->error; |
3024 } |
3071 } |
3025 |
3072 |
3026 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3073 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3027 do_action( 'xmlrpc_call', 'wp.newPage' ); |
3074 do_action( 'xmlrpc_call', 'wp.newPage', $args, $this ); |
3028 |
3075 |
3029 // Mark this as content for a page. |
3076 // Mark this as content for a page. |
3030 $args[3]['post_type'] = 'page'; |
3077 $args[3]['post_type'] = 'page'; |
3031 |
3078 |
3032 // Let mw_newPost() do all of the heavy lifting. |
3079 // Let mw_newPost() do all of the heavy lifting. |
3059 if ( ! $user ) { |
3106 if ( ! $user ) { |
3060 return $this->error; |
3107 return $this->error; |
3061 } |
3108 } |
3062 |
3109 |
3063 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3110 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3064 do_action( 'xmlrpc_call', 'wp.deletePage' ); |
3111 do_action( 'xmlrpc_call', 'wp.deletePage', $args, $this ); |
3065 |
3112 |
3066 // Get the current page based on the 'page_id' and |
3113 // Get the current page based on the 'page_id' and |
3067 // make sure it is a page and not a post. |
3114 // make sure it is a page and not a post. |
3068 $actual_page = get_post( $page_id, ARRAY_A ); |
3115 $actual_page = get_post( $page_id, ARRAY_A ); |
3069 if ( ! $actual_page || ( 'page' !== $actual_page['post_type'] ) ) { |
3116 if ( ! $actual_page || ( 'page' !== $actual_page['post_type'] ) ) { |
3126 if ( ! $user ) { |
3173 if ( ! $user ) { |
3127 return $this->error; |
3174 return $this->error; |
3128 } |
3175 } |
3129 |
3176 |
3130 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3177 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3131 do_action( 'xmlrpc_call', 'wp.editPage' ); |
3178 do_action( 'xmlrpc_call', 'wp.editPage', $args, $this ); |
3132 |
3179 |
3133 // Get the page data and make sure it is a page. |
3180 // Get the page data and make sure it is a page. |
3134 $actual_page = get_post( $page_id, ARRAY_A ); |
3181 $actual_page = get_post( $page_id, ARRAY_A ); |
3135 if ( ! $actual_page || ( 'page' !== $actual_page['post_type'] ) ) { |
3182 if ( ! $actual_page || ( 'page' !== $actual_page['post_type'] ) ) { |
3136 return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
3183 return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
3189 if ( ! current_user_can( 'edit_pages' ) ) { |
3236 if ( ! current_user_can( 'edit_pages' ) ) { |
3190 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
3237 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit pages.' ) ); |
3191 } |
3238 } |
3192 |
3239 |
3193 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3240 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3194 do_action( 'xmlrpc_call', 'wp.getPageList' ); |
3241 do_action( 'xmlrpc_call', 'wp.getPageList', $args, $this ); |
3195 |
3242 |
3196 // Get list of page IDs and titles. |
3243 // Get list of page IDs and titles. |
3197 $page_list = $wpdb->get_results( |
3244 $page_list = $wpdb->get_results( |
3198 " |
3245 " |
3199 SELECT ID page_id, |
3246 SELECT ID page_id, |
3250 if ( ! current_user_can( 'edit_posts' ) ) { |
3297 if ( ! current_user_can( 'edit_posts' ) ) { |
3251 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
3298 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
3252 } |
3299 } |
3253 |
3300 |
3254 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3301 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3255 do_action( 'xmlrpc_call', 'wp.getAuthors' ); |
3302 do_action( 'xmlrpc_call', 'wp.getAuthors', $args, $this ); |
3256 |
3303 |
3257 $authors = array(); |
3304 $authors = array(); |
3258 foreach ( get_users( array( 'fields' => array( 'ID', 'user_login', 'display_name' ) ) ) as $user ) { |
3305 foreach ( get_users( array( 'fields' => array( 'ID', 'user_login', 'display_name' ) ) ) as $user ) { |
3259 $authors[] = array( |
3306 $authors[] = array( |
3260 'user_id' => $user->ID, |
3307 'user_id' => $user->ID, |
3294 if ( ! current_user_can( 'edit_posts' ) ) { |
3341 if ( ! current_user_can( 'edit_posts' ) ) { |
3295 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view tags.' ) ); |
3342 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view tags.' ) ); |
3296 } |
3343 } |
3297 |
3344 |
3298 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3345 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3299 do_action( 'xmlrpc_call', 'wp.getKeywords' ); |
3346 do_action( 'xmlrpc_call', 'wp.getKeywords', $args, $this ); |
3300 |
3347 |
3301 $tags = array(); |
3348 $tags = array(); |
3302 |
3349 |
3303 $all_tags = get_tags(); |
3350 $all_tags = get_tags(); |
3304 if ( $all_tags ) { |
3351 if ( $all_tags ) { |
3344 if ( ! $user ) { |
3391 if ( ! $user ) { |
3345 return $this->error; |
3392 return $this->error; |
3346 } |
3393 } |
3347 |
3394 |
3348 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3395 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3349 do_action( 'xmlrpc_call', 'wp.newCategory' ); |
3396 do_action( 'xmlrpc_call', 'wp.newCategory', $args, $this ); |
3350 |
3397 |
3351 // Make sure the user is allowed to add a category. |
3398 // Make sure the user is allowed to add a category. |
3352 if ( ! current_user_can( 'manage_categories' ) ) { |
3399 if ( ! current_user_can( 'manage_categories' ) ) { |
3353 return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a category.' ) ); |
3400 return new IXR_Error( 401, __( 'Sorry, you are not allowed to add a category.' ) ); |
3354 } |
3401 } |
3427 if ( ! $user ) { |
3474 if ( ! $user ) { |
3428 return $this->error; |
3475 return $this->error; |
3429 } |
3476 } |
3430 |
3477 |
3431 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3478 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3432 do_action( 'xmlrpc_call', 'wp.deleteCategory' ); |
3479 do_action( 'xmlrpc_call', 'wp.deleteCategory', $args, $this ); |
3433 |
3480 |
3434 if ( ! current_user_can( 'delete_term', $category_id ) ) { |
3481 if ( ! current_user_can( 'delete_term', $category_id ) ) { |
3435 return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this category.' ) ); |
3482 return new IXR_Error( 401, __( 'Sorry, you are not allowed to delete this category.' ) ); |
3436 } |
3483 } |
3437 |
3484 |
3484 if ( ! current_user_can( 'edit_posts' ) ) { |
3531 if ( ! current_user_can( 'edit_posts' ) ) { |
3485 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
3532 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
3486 } |
3533 } |
3487 |
3534 |
3488 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3535 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3489 do_action( 'xmlrpc_call', 'wp.suggestCategories' ); |
3536 do_action( 'xmlrpc_call', 'wp.suggestCategories', $args, $this ); |
3490 |
3537 |
3491 $category_suggestions = array(); |
3538 $category_suggestions = array(); |
3492 $args = array( |
3539 $args = array( |
3493 'get' => 'all', |
3540 'get' => 'all', |
3494 'number' => $max_results, |
3541 'number' => $max_results, |
3530 if ( ! $user ) { |
3577 if ( ! $user ) { |
3531 return $this->error; |
3578 return $this->error; |
3532 } |
3579 } |
3533 |
3580 |
3534 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3581 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3535 do_action( 'xmlrpc_call', 'wp.getComment' ); |
3582 do_action( 'xmlrpc_call', 'wp.getComment', $args, $this ); |
3536 |
3583 |
3537 $comment = get_comment( $comment_id ); |
3584 $comment = get_comment( $comment_id ); |
3538 if ( ! $comment ) { |
3585 if ( ! $comment ) { |
3539 return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
3586 return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
3540 } |
3587 } |
3583 if ( ! $user ) { |
3630 if ( ! $user ) { |
3584 return $this->error; |
3631 return $this->error; |
3585 } |
3632 } |
3586 |
3633 |
3587 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3634 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3588 do_action( 'xmlrpc_call', 'wp.getComments' ); |
3635 do_action( 'xmlrpc_call', 'wp.getComments', $args, $this ); |
3589 |
3636 |
3590 if ( isset( $struct['status'] ) ) { |
3637 if ( isset( $struct['status'] ) ) { |
3591 $status = $struct['status']; |
3638 $status = $struct['status']; |
3592 } else { |
3639 } else { |
3593 $status = ''; |
3640 $status = ''; |
3678 if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { |
3725 if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { |
3679 return new IXR_Error( 403, __( 'Sorry, you are not allowed to delete this comment.' ) ); |
3726 return new IXR_Error( 403, __( 'Sorry, you are not allowed to delete this comment.' ) ); |
3680 } |
3727 } |
3681 |
3728 |
3682 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3729 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3683 do_action( 'xmlrpc_call', 'wp.deleteComment' ); |
3730 do_action( 'xmlrpc_call', 'wp.deleteComment', $args, $this ); |
3684 |
3731 |
3685 $status = wp_delete_comment( $comment_ID ); |
3732 $status = wp_delete_comment( $comment_ID ); |
3686 |
3733 |
3687 if ( $status ) { |
3734 if ( $status ) { |
3688 /** |
3735 /** |
3746 if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { |
3793 if ( ! current_user_can( 'edit_comment', $comment_ID ) ) { |
3747 return new IXR_Error( 403, __( 'Sorry, you are not allowed to moderate or edit this comment.' ) ); |
3794 return new IXR_Error( 403, __( 'Sorry, you are not allowed to moderate or edit this comment.' ) ); |
3748 } |
3795 } |
3749 |
3796 |
3750 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3797 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3751 do_action( 'xmlrpc_call', 'wp.editComment' ); |
3798 do_action( 'xmlrpc_call', 'wp.editComment', $args, $this ); |
3752 $comment = array( |
3799 $comment = array( |
3753 'comment_ID' => $comment_ID, |
3800 'comment_ID' => $comment_ID, |
3754 ); |
3801 ); |
3755 |
3802 |
3756 if ( isset( $content_struct['status'] ) ) { |
3803 if ( isset( $content_struct['status'] ) ) { |
3873 |
3920 |
3874 if ( ! comments_open( $post_id ) ) { |
3921 if ( ! comments_open( $post_id ) ) { |
3875 return new IXR_Error( 403, __( 'Sorry, comments are closed for this item.' ) ); |
3922 return new IXR_Error( 403, __( 'Sorry, comments are closed for this item.' ) ); |
3876 } |
3923 } |
3877 |
3924 |
3878 if ( empty( $content_struct['content'] ) ) { |
3925 if ( |
3879 return new IXR_Error( 403, __( 'Comment is required.' ) ); |
3926 'publish' === get_post_status( $post_id ) && |
|
3927 ! current_user_can( 'edit_post', $post_id ) && |
|
3928 post_password_required( $post_id ) |
|
3929 ) { |
|
3930 return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) ); |
|
3931 } |
|
3932 |
|
3933 if ( |
|
3934 'private' === get_post_status( $post_id ) && |
|
3935 ! current_user_can( 'read_post', $post_id ) |
|
3936 ) { |
|
3937 return new IXR_Error( 403, __( 'Sorry, you are not allowed to comment on this post.' ) ); |
3880 } |
3938 } |
3881 |
3939 |
3882 $comment = array( |
3940 $comment = array( |
3883 'comment_post_ID' => $post_id, |
3941 'comment_post_ID' => $post_id, |
3884 'comment_content' => $content_struct['content'], |
3942 'comment_content' => trim( $content_struct['content'] ), |
3885 ); |
3943 ); |
3886 |
3944 |
3887 if ( $logged_in ) { |
3945 if ( $logged_in ) { |
3888 $display_name = $user->display_name; |
3946 $display_name = $user->display_name; |
3889 $user_email = $user->user_email; |
3947 $user_email = $user->user_email; |
3910 } |
3968 } |
3911 |
3969 |
3912 $comment['user_ID'] = 0; |
3970 $comment['user_ID'] = 0; |
3913 |
3971 |
3914 if ( get_option( 'require_name_email' ) ) { |
3972 if ( get_option( 'require_name_email' ) ) { |
3915 if ( strlen( $comment['comment_author_email'] < 6 ) || '' === $comment['comment_author'] ) { |
3973 if ( strlen( $comment['comment_author_email'] ) < 6 || '' === $comment['comment_author'] ) { |
3916 return new IXR_Error( 403, __( 'Comment author name and email are required.' ) ); |
3974 return new IXR_Error( 403, __( 'Comment author name and email are required.' ) ); |
3917 } elseif ( ! is_email( $comment['comment_author_email'] ) ) { |
3975 } elseif ( ! is_email( $comment['comment_author_email'] ) ) { |
3918 return new IXR_Error( 403, __( 'A valid email address is required.' ) ); |
3976 return new IXR_Error( 403, __( 'A valid email address is required.' ) ); |
3919 } |
3977 } |
3920 } |
3978 } |
3921 } |
3979 } |
3922 |
3980 |
3923 $comment['comment_parent'] = isset( $content_struct['comment_parent'] ) ? absint( $content_struct['comment_parent'] ) : 0; |
3981 $comment['comment_parent'] = isset( $content_struct['comment_parent'] ) ? absint( $content_struct['comment_parent'] ) : 0; |
3924 |
3982 |
|
3983 /** This filter is documented in wp-includes/comment.php */ |
|
3984 $allow_empty = apply_filters( 'allow_empty_comment', false, $comment ); |
|
3985 |
|
3986 if ( ! $allow_empty && '' === $comment['comment_content'] ) { |
|
3987 return new IXR_Error( 403, __( 'Comment is required.' ) ); |
|
3988 } |
|
3989 |
3925 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3990 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3926 do_action( 'xmlrpc_call', 'wp.newComment' ); |
3991 do_action( 'xmlrpc_call', 'wp.newComment', $args, $this ); |
3927 |
3992 |
3928 $comment_ID = wp_new_comment( $comment, true ); |
3993 $comment_ID = wp_new_comment( $comment, true ); |
3929 if ( is_wp_error( $comment_ID ) ) { |
3994 if ( is_wp_error( $comment_ID ) ) { |
3930 return new IXR_Error( 403, $comment_ID->get_error_message() ); |
3995 return new IXR_Error( 403, $comment_ID->get_error_message() ); |
3931 } |
3996 } |
3975 if ( ! current_user_can( 'publish_posts' ) ) { |
4040 if ( ! current_user_can( 'publish_posts' ) ) { |
3976 return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
4041 return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
3977 } |
4042 } |
3978 |
4043 |
3979 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4044 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3980 do_action( 'xmlrpc_call', 'wp.getCommentStatusList' ); |
4045 do_action( 'xmlrpc_call', 'wp.getCommentStatusList', $args, $this ); |
3981 |
4046 |
3982 return get_comment_statuses(); |
4047 return get_comment_statuses(); |
3983 } |
4048 } |
3984 |
4049 |
3985 /** |
4050 /** |
4017 if ( ! current_user_can( 'edit_post', $post_id ) ) { |
4082 if ( ! current_user_can( 'edit_post', $post_id ) ) { |
4018 return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details of this post.' ) ); |
4083 return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details of this post.' ) ); |
4019 } |
4084 } |
4020 |
4085 |
4021 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4086 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4022 do_action( 'xmlrpc_call', 'wp.getCommentCount' ); |
4087 do_action( 'xmlrpc_call', 'wp.getCommentCount', $args, $this ); |
4023 |
4088 |
4024 $count = wp_count_comments( $post_id ); |
4089 $count = wp_count_comments( $post_id ); |
4025 |
4090 |
4026 return array( |
4091 return array( |
4027 'approved' => $count->approved, |
4092 'approved' => $count->approved, |
4059 if ( ! current_user_can( 'edit_posts' ) ) { |
4124 if ( ! current_user_can( 'edit_posts' ) ) { |
4060 return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
4125 return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
4061 } |
4126 } |
4062 |
4127 |
4063 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4128 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4064 do_action( 'xmlrpc_call', 'wp.getPostStatusList' ); |
4129 do_action( 'xmlrpc_call', 'wp.getPostStatusList', $args, $this ); |
4065 |
4130 |
4066 return get_post_statuses(); |
4131 return get_post_statuses(); |
4067 } |
4132 } |
4068 |
4133 |
4069 /** |
4134 /** |
4094 if ( ! current_user_can( 'edit_pages' ) ) { |
4159 if ( ! current_user_can( 'edit_pages' ) ) { |
4095 return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
4160 return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
4096 } |
4161 } |
4097 |
4162 |
4098 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4163 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4099 do_action( 'xmlrpc_call', 'wp.getPageStatusList' ); |
4164 do_action( 'xmlrpc_call', 'wp.getPageStatusList', $args, $this ); |
4100 |
4165 |
4101 return get_page_statuses(); |
4166 return get_page_statuses(); |
4102 } |
4167 } |
4103 |
4168 |
4104 /** |
4169 /** |
4287 if ( ! current_user_can( 'upload_files' ) ) { |
4352 if ( ! current_user_can( 'upload_files' ) ) { |
4288 return new IXR_Error( 403, __( 'Sorry, you are not allowed to upload files.' ) ); |
4353 return new IXR_Error( 403, __( 'Sorry, you are not allowed to upload files.' ) ); |
4289 } |
4354 } |
4290 |
4355 |
4291 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4356 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4292 do_action( 'xmlrpc_call', 'wp.getMediaItem' ); |
4357 do_action( 'xmlrpc_call', 'wp.getMediaItem', $args, $this ); |
4293 |
4358 |
4294 $attachment = get_post( $attachment_id ); |
4359 $attachment = get_post( $attachment_id ); |
4295 if ( ! $attachment ) { |
4360 if ( ! $attachment || 'attachment' !== $attachment->post_type ) { |
4296 return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
4361 return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
4297 } |
4362 } |
4298 |
4363 |
4299 return $this->_prepare_media_item( $attachment ); |
4364 return $this->_prepare_media_item( $attachment ); |
4300 } |
4365 } |
4340 if ( ! current_user_can( 'upload_files' ) ) { |
4405 if ( ! current_user_can( 'upload_files' ) ) { |
4341 return new IXR_Error( 401, __( 'Sorry, you are not allowed to upload files.' ) ); |
4406 return new IXR_Error( 401, __( 'Sorry, you are not allowed to upload files.' ) ); |
4342 } |
4407 } |
4343 |
4408 |
4344 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4409 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4345 do_action( 'xmlrpc_call', 'wp.getMediaLibrary' ); |
4410 do_action( 'xmlrpc_call', 'wp.getMediaLibrary', $args, $this ); |
4346 |
4411 |
4347 $parent_id = ( isset( $struct['parent_id'] ) ) ? absint( $struct['parent_id'] ) : ''; |
4412 $parent_id = ( isset( $struct['parent_id'] ) ) ? absint( $struct['parent_id'] ) : ''; |
4348 $mime_type = ( isset( $struct['mime_type'] ) ) ? $struct['mime_type'] : ''; |
4413 $mime_type = ( isset( $struct['mime_type'] ) ) ? $struct['mime_type'] : ''; |
4349 $offset = ( isset( $struct['offset'] ) ) ? absint( $struct['offset'] ) : 0; |
4414 $offset = ( isset( $struct['offset'] ) ) ? absint( $struct['offset'] ) : 0; |
4350 $number = ( isset( $struct['number'] ) ) ? absint( $struct['number'] ) : -1; |
4415 $number = ( isset( $struct['number'] ) ) ? absint( $struct['number'] ) : -1; |
4396 if ( ! current_user_can( 'edit_posts' ) ) { |
4461 if ( ! current_user_can( 'edit_posts' ) ) { |
4397 return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
4462 return new IXR_Error( 403, __( 'Sorry, you are not allowed to access details about this site.' ) ); |
4398 } |
4463 } |
4399 |
4464 |
4400 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4465 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4401 do_action( 'xmlrpc_call', 'wp.getPostFormats' ); |
4466 do_action( 'xmlrpc_call', 'wp.getPostFormats', $args, $this ); |
4402 |
4467 |
4403 $formats = get_post_format_strings(); |
4468 $formats = get_post_format_strings(); |
4404 |
4469 |
4405 // Find out if they want a list of currently supports formats. |
4470 // Find out if they want a list of currently supports formats. |
4406 if ( isset( $args[3] ) && is_array( $args[3] ) ) { |
4471 if ( isset( $args[3] ) && is_array( $args[3] ) ) { |
4476 if ( ! $user ) { |
4541 if ( ! $user ) { |
4477 return $this->error; |
4542 return $this->error; |
4478 } |
4543 } |
4479 |
4544 |
4480 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4545 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4481 do_action( 'xmlrpc_call', 'wp.getPostType' ); |
4546 do_action( 'xmlrpc_call', 'wp.getPostType', $args, $this ); |
4482 |
4547 |
4483 if ( ! post_type_exists( $post_type_name ) ) { |
4548 if ( ! post_type_exists( $post_type_name ) ) { |
4484 return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
4549 return new IXR_Error( 403, __( 'Invalid post type.' ) ); |
4485 } |
4550 } |
4486 |
4551 |
4603 if ( ! $user ) { |
4668 if ( ! $user ) { |
4604 return $this->error; |
4669 return $this->error; |
4605 } |
4670 } |
4606 |
4671 |
4607 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4672 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4608 do_action( 'xmlrpc_call', 'wp.getRevisions' ); |
4673 do_action( 'xmlrpc_call', 'wp.getRevisions', $args, $this ); |
4609 |
4674 |
4610 $post = get_post( $post_id ); |
4675 $post = get_post( $post_id ); |
4611 if ( ! $post ) { |
4676 if ( ! $post ) { |
4612 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
4677 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
4613 } |
4678 } |
4677 if ( ! $user ) { |
4742 if ( ! $user ) { |
4678 return $this->error; |
4743 return $this->error; |
4679 } |
4744 } |
4680 |
4745 |
4681 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4746 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4682 do_action( 'xmlrpc_call', 'wp.restoreRevision' ); |
4747 do_action( 'xmlrpc_call', 'wp.restoreRevision', $args, $this ); |
4683 |
4748 |
4684 $revision = wp_get_post_revision( $revision_id ); |
4749 $revision = wp_get_post_revision( $revision_id ); |
4685 if ( ! $revision ) { |
4750 if ( ! $revision ) { |
4686 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
4751 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
4687 } |
4752 } |
4748 if ( ! $user ) { |
4813 if ( ! $user ) { |
4749 return $this->error; |
4814 return $this->error; |
4750 } |
4815 } |
4751 |
4816 |
4752 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4817 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4753 do_action( 'xmlrpc_call', 'blogger.getUsersBlogs' ); |
4818 do_action( 'xmlrpc_call', 'blogger.getUsersBlogs', $args, $this ); |
4754 |
4819 |
4755 $is_admin = current_user_can( 'manage_options' ); |
4820 $is_admin = current_user_can( 'manage_options' ); |
4756 |
4821 |
4757 $struct = array( |
4822 $struct = array( |
4758 'isAdmin' => $is_admin, |
4823 'isAdmin' => $is_admin, |
4834 if ( ! current_user_can( 'edit_posts' ) ) { |
4899 if ( ! current_user_can( 'edit_posts' ) ) { |
4835 return new IXR_Error( 401, __( 'Sorry, you are not allowed to access user data on this site.' ) ); |
4900 return new IXR_Error( 401, __( 'Sorry, you are not allowed to access user data on this site.' ) ); |
4836 } |
4901 } |
4837 |
4902 |
4838 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4903 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4839 do_action( 'xmlrpc_call', 'blogger.getUserInfo' ); |
4904 do_action( 'xmlrpc_call', 'blogger.getUserInfo', $args, $this ); |
4840 |
4905 |
4841 $struct = array( |
4906 $struct = array( |
4842 'nickname' => $user->nickname, |
4907 'nickname' => $user->nickname, |
4843 'userid' => $user->ID, |
4908 'userid' => $user->ID, |
4844 'url' => $user->user_url, |
4909 'url' => $user->user_url, |
4884 if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
4949 if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
4885 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
4950 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
4886 } |
4951 } |
4887 |
4952 |
4888 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4953 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4889 do_action( 'xmlrpc_call', 'blogger.getPost' ); |
4954 do_action( 'xmlrpc_call', 'blogger.getPost', $args, $this ); |
4890 |
4955 |
4891 $categories = implode( ',', wp_get_post_categories( $post_ID ) ); |
4956 $categories = implode( ',', wp_get_post_categories( $post_ID ) ); |
4892 |
4957 |
4893 $content = '<title>' . wp_unslash( $post_data['post_title'] ) . '</title>'; |
4958 $content = '<title>' . wp_unslash( $post_data['post_title'] ) . '</title>'; |
4894 $content .= '<category>' . $categories . '</category>'; |
4959 $content .= '<category>' . $categories . '</category>'; |
4941 if ( ! current_user_can( 'edit_posts' ) ) { |
5006 if ( ! current_user_can( 'edit_posts' ) ) { |
4942 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
5007 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
4943 } |
5008 } |
4944 |
5009 |
4945 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5010 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
4946 do_action( 'xmlrpc_call', 'blogger.getRecentPosts' ); |
5011 do_action( 'xmlrpc_call', 'blogger.getRecentPosts', $args, $this ); |
4947 |
5012 |
4948 $posts_list = wp_get_recent_posts( $query ); |
5013 $posts_list = wp_get_recent_posts( $query ); |
4949 |
5014 |
4950 if ( ! $posts_list ) { |
5015 if ( ! $posts_list ) { |
4951 $this->error = new IXR_Error( 500, __( 'Either there are no posts, or something went wrong.' ) ); |
5016 $this->error = new IXR_Error( 500, __( 'Either there are no posts, or something went wrong.' ) ); |
5031 if ( ! $user ) { |
5096 if ( ! $user ) { |
5032 return $this->error; |
5097 return $this->error; |
5033 } |
5098 } |
5034 |
5099 |
5035 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5100 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5036 do_action( 'xmlrpc_call', 'blogger.newPost' ); |
5101 do_action( 'xmlrpc_call', 'blogger.newPost', $args, $this ); |
5037 |
5102 |
5038 $cap = ( $publish ) ? 'publish_posts' : 'edit_posts'; |
5103 $cap = ( $publish ) ? 'publish_posts' : 'edit_posts'; |
5039 if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) || ! current_user_can( $cap ) ) { |
5104 if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) || ! current_user_can( $cap ) ) { |
5040 return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) ); |
5105 return new IXR_Error( 401, __( 'Sorry, you are not allowed to post on this site.' ) ); |
5041 } |
5106 } |
5108 if ( ! $user ) { |
5173 if ( ! $user ) { |
5109 return $this->error; |
5174 return $this->error; |
5110 } |
5175 } |
5111 |
5176 |
5112 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5177 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5113 do_action( 'xmlrpc_call', 'blogger.editPost' ); |
5178 do_action( 'xmlrpc_call', 'blogger.editPost', $args, $this ); |
5114 |
5179 |
5115 $actual_post = get_post( $post_ID, ARRAY_A ); |
5180 $actual_post = get_post( $post_ID, ARRAY_A ); |
5116 |
5181 |
5117 if ( ! $actual_post || 'post' !== $actual_post['post_type'] ) { |
5182 if ( ! $actual_post || 'post' !== $actual_post['post_type'] ) { |
5118 return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
5183 return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
5182 if ( ! $user ) { |
5247 if ( ! $user ) { |
5183 return $this->error; |
5248 return $this->error; |
5184 } |
5249 } |
5185 |
5250 |
5186 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5251 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5187 do_action( 'xmlrpc_call', 'blogger.deletePost' ); |
5252 do_action( 'xmlrpc_call', 'blogger.deletePost', $args, $this ); |
5188 |
5253 |
5189 $actual_post = get_post( $post_ID, ARRAY_A ); |
5254 $actual_post = get_post( $post_ID, ARRAY_A ); |
5190 |
5255 |
5191 if ( ! $actual_post || 'post' !== $actual_post['post_type'] ) { |
5256 if ( ! $actual_post || 'post' !== $actual_post['post_type'] ) { |
5192 return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
5257 return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
5270 if ( ! $user ) { |
5335 if ( ! $user ) { |
5271 return $this->error; |
5336 return $this->error; |
5272 } |
5337 } |
5273 |
5338 |
5274 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5339 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5275 do_action( 'xmlrpc_call', 'metaWeblog.newPost' ); |
5340 do_action( 'xmlrpc_call', 'metaWeblog.newPost', $args, $this ); |
5276 |
5341 |
5277 $page_template = ''; |
5342 $page_template = ''; |
5278 if ( ! empty( $content_struct['post_type'] ) ) { |
5343 if ( ! empty( $content_struct['post_type'] ) ) { |
5279 if ( 'page' === $content_struct['post_type'] ) { |
5344 if ( 'page' === $content_struct['post_type'] ) { |
5280 if ( $publish ) { |
5345 if ( $publish ) { |
5563 * @param int $post_ID ID of the new post. |
5628 * @param int $post_ID ID of the new post. |
5564 * @param array $args An array of arguments to create the new post. |
5629 * @param array $args An array of arguments to create the new post. |
5565 */ |
5630 */ |
5566 do_action( 'xmlrpc_call_success_mw_newPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
5631 do_action( 'xmlrpc_call_success_mw_newPost', $post_ID, $args ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.NotLowercase |
5567 |
5632 |
5568 return strval( $post_ID ); |
5633 return (string) $post_ID; |
5569 } |
5634 } |
5570 |
5635 |
5571 /** |
5636 /** |
5572 * Adds an enclosure to a post if it's new. |
5637 * Adds an enclosure to a post if it's new. |
5573 * |
5638 * |
5574 * @since 2.8.0 |
5639 * @since 2.8.0 |
5575 * |
5640 * |
5576 * @param integer $post_ID Post ID. |
5641 * @param int $post_ID Post ID. |
5577 * @param array $enclosure Enclosure data. |
5642 * @param array $enclosure Enclosure data. |
5578 */ |
5643 */ |
5579 public function add_enclosure_if_new( $post_ID, $enclosure ) { |
5644 public function add_enclosure_if_new( $post_ID, $enclosure ) { |
5580 if ( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) { |
5645 if ( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) { |
5581 $encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] . "\n"; |
5646 $encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] . "\n"; |
5582 $found = false; |
5647 $found = false; |
5632 * @type string $username |
5697 * @type string $username |
5633 * @type string $password |
5698 * @type string $password |
5634 * @type array $content_struct |
5699 * @type array $content_struct |
5635 * @type int $publish |
5700 * @type int $publish |
5636 * } |
5701 * } |
5637 * @return bool|IXR_Error True on success. |
5702 * @return true|IXR_Error True on success. |
5638 */ |
5703 */ |
5639 public function mw_editPost( $args ) { |
5704 public function mw_editPost( $args ) { |
5640 $this->escape( $args ); |
5705 $this->escape( $args ); |
5641 |
5706 |
5642 $post_ID = (int) $args[0]; |
5707 $post_ID = (int) $args[0]; |
5649 if ( ! $user ) { |
5714 if ( ! $user ) { |
5650 return $this->error; |
5715 return $this->error; |
5651 } |
5716 } |
5652 |
5717 |
5653 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5718 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5654 do_action( 'xmlrpc_call', 'metaWeblog.editPost' ); |
5719 do_action( 'xmlrpc_call', 'metaWeblog.editPost', $args, $this ); |
5655 |
5720 |
5656 $postdata = get_post( $post_ID, ARRAY_A ); |
5721 $postdata = get_post( $post_ID, ARRAY_A ); |
5657 |
5722 |
5658 /* |
5723 /* |
5659 * If there is no post data for the give post ID, stop now and return an error. |
5724 * If there is no post data for the give post ID, stop now and return an error. |
5987 if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
6052 if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
5988 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
6053 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
5989 } |
6054 } |
5990 |
6055 |
5991 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6056 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5992 do_action( 'xmlrpc_call', 'metaWeblog.getPost' ); |
6057 do_action( 'xmlrpc_call', 'metaWeblog.getPost', $args, $this ); |
5993 |
6058 |
5994 if ( '' !== $postdata['post_date'] ) { |
6059 if ( '' !== $postdata['post_date'] ) { |
5995 $post_date = $this->_convert_date( $postdata['post_date'] ); |
6060 $post_date = $this->_convert_date( $postdata['post_date'] ); |
5996 $post_date_gmt = $this->_convert_date_gmt( $postdata['post_date_gmt'], $postdata['post_date'] ); |
6061 $post_date_gmt = $this->_convert_date_gmt( $postdata['post_date_gmt'], $postdata['post_date'] ); |
5997 $post_modified = $this->_convert_date( $postdata['post_modified'] ); |
6062 $post_modified = $this->_convert_date( $postdata['post_modified'] ); |
6128 if ( ! current_user_can( 'edit_posts' ) ) { |
6193 if ( ! current_user_can( 'edit_posts' ) ) { |
6129 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
6194 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit posts.' ) ); |
6130 } |
6195 } |
6131 |
6196 |
6132 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6197 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6133 do_action( 'xmlrpc_call', 'metaWeblog.getRecentPosts' ); |
6198 do_action( 'xmlrpc_call', 'metaWeblog.getRecentPosts', $args, $this ); |
6134 |
6199 |
6135 $posts_list = wp_get_recent_posts( $query ); |
6200 $posts_list = wp_get_recent_posts( $query ); |
6136 |
6201 |
6137 if ( ! $posts_list ) { |
6202 if ( ! $posts_list ) { |
6138 return array(); |
6203 return array(); |
6249 if ( ! current_user_can( 'edit_posts' ) ) { |
6314 if ( ! current_user_can( 'edit_posts' ) ) { |
6250 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
6315 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
6251 } |
6316 } |
6252 |
6317 |
6253 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6318 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6254 do_action( 'xmlrpc_call', 'metaWeblog.getCategories' ); |
6319 do_action( 'xmlrpc_call', 'metaWeblog.getCategories', $args, $this ); |
6255 |
6320 |
6256 $categories_struct = array(); |
6321 $categories_struct = array(); |
6257 |
6322 |
6258 $cats = get_categories( array( 'get' => 'all' ) ); |
6323 $cats = get_categories( array( 'get' => 'all' ) ); |
6259 if ( $cats ) { |
6324 if ( $cats ) { |
6310 if ( ! $user ) { |
6375 if ( ! $user ) { |
6311 return $this->error; |
6376 return $this->error; |
6312 } |
6377 } |
6313 |
6378 |
6314 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6379 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6315 do_action( 'xmlrpc_call', 'metaWeblog.newMediaObject' ); |
6380 do_action( 'xmlrpc_call', 'metaWeblog.newMediaObject', $args, $this ); |
6316 |
6381 |
6317 if ( ! current_user_can( 'upload_files' ) ) { |
6382 if ( ! current_user_can( 'upload_files' ) ) { |
6318 $this->error = new IXR_Error( 401, __( 'Sorry, you are not allowed to upload files.' ) ); |
6383 $this->error = new IXR_Error( 401, __( 'Sorry, you are not allowed to upload files.' ) ); |
6319 return $this->error; |
6384 return $this->error; |
6320 } |
6385 } |
6429 if ( ! $user ) { |
6494 if ( ! $user ) { |
6430 return $this->error; |
6495 return $this->error; |
6431 } |
6496 } |
6432 |
6497 |
6433 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6498 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6434 do_action( 'xmlrpc_call', 'mt.getRecentPostTitles' ); |
6499 do_action( 'xmlrpc_call', 'mt.getRecentPostTitles', $args, $this ); |
6435 |
6500 |
6436 $posts_list = wp_get_recent_posts( $query ); |
6501 $posts_list = wp_get_recent_posts( $query ); |
6437 |
6502 |
6438 if ( ! $posts_list ) { |
6503 if ( ! $posts_list ) { |
6439 $this->error = new IXR_Error( 500, __( 'Either there are no posts, or something went wrong.' ) ); |
6504 $this->error = new IXR_Error( 500, __( 'Either there are no posts, or something went wrong.' ) ); |
6491 if ( ! current_user_can( 'edit_posts' ) ) { |
6556 if ( ! current_user_can( 'edit_posts' ) ) { |
6492 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
6557 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
6493 } |
6558 } |
6494 |
6559 |
6495 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6560 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6496 do_action( 'xmlrpc_call', 'mt.getCategoryList' ); |
6561 do_action( 'xmlrpc_call', 'mt.getCategoryList', $args, $this ); |
6497 |
6562 |
6498 $categories_struct = array(); |
6563 $categories_struct = array(); |
6499 |
6564 |
6500 $cats = get_categories( |
6565 $cats = get_categories( |
6501 array( |
6566 array( |
6549 if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
6614 if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
6550 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
6615 return new IXR_Error( 401, __( 'Sorry, you are not allowed to edit this post.' ) ); |
6551 } |
6616 } |
6552 |
6617 |
6553 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6618 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6554 do_action( 'xmlrpc_call', 'mt.getPostCategories' ); |
6619 do_action( 'xmlrpc_call', 'mt.getPostCategories', $args, $this ); |
6555 |
6620 |
6556 $categories = array(); |
6621 $categories = array(); |
6557 $catids = wp_get_post_categories( intval( $post_ID ) ); |
6622 $catids = wp_get_post_categories( (int) $post_ID ); |
6558 // First listed category will be the primary category. |
6623 // First listed category will be the primary category. |
6559 $isPrimary = true; |
6624 $isPrimary = true; |
6560 foreach ( $catids as $catid ) { |
6625 foreach ( $catids as $catid ) { |
6561 $categories[] = array( |
6626 $categories[] = array( |
6562 'categoryName' => get_cat_name( $catid ), |
6627 'categoryName' => get_cat_name( $catid ), |
6596 if ( ! $user ) { |
6661 if ( ! $user ) { |
6597 return $this->error; |
6662 return $this->error; |
6598 } |
6663 } |
6599 |
6664 |
6600 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6665 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6601 do_action( 'xmlrpc_call', 'mt.setPostCategories' ); |
6666 do_action( 'xmlrpc_call', 'mt.setPostCategories', $args, $this ); |
6602 |
6667 |
6603 if ( ! get_post( $post_ID ) ) { |
6668 if ( ! get_post( $post_ID ) ) { |
6604 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
6669 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
6605 } |
6670 } |
6606 |
6671 |
6663 */ |
6728 */ |
6664 public function mt_getTrackbackPings( $post_ID ) { |
6729 public function mt_getTrackbackPings( $post_ID ) { |
6665 global $wpdb; |
6730 global $wpdb; |
6666 |
6731 |
6667 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6732 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6668 do_action( 'xmlrpc_call', 'mt.getTrackbackPings' ); |
6733 do_action( 'xmlrpc_call', 'mt.getTrackbackPings', $post_ID, $this ); |
6669 |
6734 |
6670 $actual_post = get_post( $post_ID, ARRAY_A ); |
6735 $actual_post = get_post( $post_ID, ARRAY_A ); |
6671 |
6736 |
6672 if ( ! $actual_post ) { |
6737 if ( ! $actual_post ) { |
6673 return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
6738 return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
6720 if ( ! $user ) { |
6785 if ( ! $user ) { |
6721 return $this->error; |
6786 return $this->error; |
6722 } |
6787 } |
6723 |
6788 |
6724 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6789 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6725 do_action( 'xmlrpc_call', 'mt.publishPost' ); |
6790 do_action( 'xmlrpc_call', 'mt.publishPost', $args, $this ); |
6726 |
6791 |
6727 $postdata = get_post( $post_ID, ARRAY_A ); |
6792 $postdata = get_post( $post_ID, ARRAY_A ); |
6728 if ( ! $postdata ) { |
6793 if ( ! $postdata ) { |
6729 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
6794 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
6730 } |
6795 } |
6762 */ |
6827 */ |
6763 public function pingback_ping( $args ) { |
6828 public function pingback_ping( $args ) { |
6764 global $wpdb; |
6829 global $wpdb; |
6765 |
6830 |
6766 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6831 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
6767 do_action( 'xmlrpc_call', 'pingback.ping' ); |
6832 do_action( 'xmlrpc_call', 'pingback.ping', $args, $this ); |
6768 |
6833 |
6769 $this->escape( $args ); |
6834 $this->escape( $args ); |
6770 |
6835 |
6771 $pagelinkedfrom = str_replace( '&', '&', $args[0] ); |
6836 $pagelinkedfrom = str_replace( '&', '&', $args[0] ); |
6772 $pagelinkedto = str_replace( '&', '&', $args[1] ); |
6837 $pagelinkedto = str_replace( '&', '&', $args[1] ); |
6809 // The query string defines the post_ID (?p=XXXX). |
6874 // The query string defines the post_ID (?p=XXXX). |
6810 $blah = explode( '=', $match[0] ); |
6875 $blah = explode( '=', $match[0] ); |
6811 $post_ID = (int) $blah[1]; |
6876 $post_ID = (int) $blah[1]; |
6812 } elseif ( isset( $urltest['fragment'] ) ) { |
6877 } elseif ( isset( $urltest['fragment'] ) ) { |
6813 // An #anchor is there, it's either... |
6878 // An #anchor is there, it's either... |
6814 if ( intval( $urltest['fragment'] ) ) { |
6879 if ( (int) $urltest['fragment'] ) { |
6815 // ...an integer #XXXX (simplest case), |
6880 // ...an integer #XXXX (simplest case), |
6816 $post_ID = (int) $urltest['fragment']; |
6881 $post_ID = (int) $urltest['fragment']; |
6817 } elseif ( preg_match( '/post-[0-9]+/', $urltest['fragment'] ) ) { |
6882 } elseif ( preg_match( '/post-[0-9]+/', $urltest['fragment'] ) ) { |
6818 // ...a post ID in the form 'post-###', |
6883 // ...a post ID in the form 'post-###', |
6819 $post_ID = preg_replace( '/[^0-9]+/', '', $urltest['fragment'] ); |
6884 $post_ID = preg_replace( '/[^0-9]+/', '', $urltest['fragment'] ); |
7001 */ |
7066 */ |
7002 public function pingback_extensions_getPingbacks( $url ) { |
7067 public function pingback_extensions_getPingbacks( $url ) { |
7003 global $wpdb; |
7068 global $wpdb; |
7004 |
7069 |
7005 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
7070 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
7006 do_action( 'xmlrpc_call', 'pingback.extensions.getPingbacks' ); |
7071 do_action( 'xmlrpc_call', 'pingback.extensions.getPingbacks', $url, $this ); |
7007 |
7072 |
7008 $url = $this->escape( $url ); |
7073 $url = $this->escape( $url ); |
7009 |
7074 |
7010 $post_ID = url_to_postid( $url ); |
7075 $post_ID = url_to_postid( $url ); |
7011 if ( ! $post_ID ) { |
7076 if ( ! $post_ID ) { |