Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 3430 lines (2799 sloc) 93.476 kb
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
1 <?php
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
2 /**
3 * XML-RPC protocol support for WordPress
4 *
5 * @license GPL v2 <./license.txt>
6 * @package WordPress
7 */
8
9 /**
10 * Whether this is a XMLRPC Request
11 *
12 * @var bool
13 */
cb09336 Make the xmlrpc user the current user. fixes #2273
ryan authored
14 define('XMLRPC_REQUEST', true);
15
16 // Some browser-embedded clients send cookies. We don't want them.
17 $_COOKIE = array();
18
321c310 Remove trailing whitespace
ryan authored
19 // A bug in PHP < 5.2.2 makes $HTTP_RAW_POST_DATA not set by default,
f432ed6 Fix for PHP version 5.2.2 where $HTTP_RAW_POST_DATA isn't set. fixes #42...
rob1n authored
20 // but we can do it ourself.
21 if ( !isset( $HTTP_RAW_POST_DATA ) ) {
22 $HTTP_RAW_POST_DATA = file_get_contents( 'php://input' );
23 }
24
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
25 // fix for mozBlog and other cases where '<?xml' isn't on the very first line
60ccea9 Check if HTTP_RAW_POST_DATA is set to avoid undefined var warning. Prop...
ryan authored
26 if ( isset($HTTP_RAW_POST_DATA) )
27 $HTTP_RAW_POST_DATA = trim($HTTP_RAW_POST_DATA);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
28
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
29 /** Include the bootstrap for setting up WordPress environment */
5b81135 Allow wp-config.php to exist one level up from WordPress root directory....
ryan authored
30 include('./wp-load.php');
af8c37f Add RSD support. See http://archipelago.phrasewise.com/rsd
matt authored
31
321c310 Remove trailing whitespace
ryan authored
32 if ( isset( $_GET['rsd'] ) ) { // http://archipelago.phrasewise.com/rsd
9ce729e Content-Type, not Content-type, as headers are case sensitive. Props foo...
rob1n authored
33 header('Content-Type: text/xml; charset=' . get_option('blog_charset'), true);
af8c37f Add RSD support. See http://archipelago.phrasewise.com/rsd
matt authored
34 ?>
849a0d2 Use get_option instead of get_settings. Just 'cause.
ryan authored
35 <?php echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>
af8c37f Add RSD support. See http://archipelago.phrasewise.com/rsd
matt authored
36 <rsd version="1.0" xmlns="http://archipelago.phrasewise.com/rsd">
37 <service>
38 <engineName>WordPress</engineName>
39 <engineLink>http://wordpress.org/</engineLink>
40 <homePageLink><?php bloginfo_rss('url') ?></homePageLink>
41 <apis>
509df64 Add 'rpc' context to siteurl which obeys ADMIN and LOGIN forced SSL. see...
ryan authored
42 <api name="WordPress" blogID="1" preferred="true" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" />
43 <api name="Movable Type" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" />
44 <api name="MetaWeblog" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" />
45 <api name="Blogger" blogID="1" preferred="false" apiLink="<?php echo site_url('xmlrpc.php', 'rpc') ?>" />
46 <api name="Atom" blogID="" preferred="false" apiLink="<?php echo apply_filters('atom_service_url', site_url('wp-app.php/service', 'rpc') ) ?>" />
af8c37f Add RSD support. See http://archipelago.phrasewise.com/rsd
matt authored
47 </apis>
48 </service>
49 </rsd>
50 <?php
51 exit;
52 }
53
770613e Admin includes reorg. see #4334
ryan authored
54 include_once(ABSPATH . 'wp-admin/includes/admin.php');
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
55 include_once(ABSPATH . WPINC . '/class-IXR.php');
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
56
57 // Turn off all warnings and errors.
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
58 // error_reporting(0);
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
59
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
60 /**
61 * Posts submitted via the xmlrpc interface get that title
62 * @name post_default_title
63 * @var string
64 */
65 $post_default_title = "";
66
67 /**
68 * Whether to enable XMLRPC Logging.
69 *
70 * @name xmlrpc_logging
71 * @var int|bool
72 */
80b3445 fixed comment_status screwup, removed debug stuff, screwed up big time, ...
michelvaldrighi authored
73 $xmlrpc_logging = 0;
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
74
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
75 /**
76 * logIO() - Writes logging info to a file.
77 *
78 * @uses $xmlrpc_logging
79 * @package WordPress
80 * @subpackage Logging
81 *
82 * @param string $io Whether input or output
83 * @param string $msg Information describing logging reason.
84 * @return bool Always return true
85 */
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
86 function logIO($io,$msg) {
87 global $xmlrpc_logging;
88 if ($xmlrpc_logging) {
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
89 $fp = fopen("../xmlrpc.log","a+");
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
90 $date = gmdate("Y-m-d H:i:s ");
91 $iot = ($io == "I") ? " Input: " : " Output: ";
92 fwrite($fp, "\n\n".$date.$iot.$msg);
93 fclose($fp);
94 }
95 return true;
96 }
97
75ec542 avoid $HTTP_RAW_POST_DATA notices. props mgeisler and Nazgul. fixes #14...
markjaquith authored
98 if ( isset($HTTP_RAW_POST_DATA) )
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
99 logIO("I", $HTTP_RAW_POST_DATA);
100
101 /**
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
102 * WordPress XMLRPC server implementation.
103 *
104 * Implements compatability for Blogger API, MetaWeblog API, MovableType, and
105 * pingback. Additional WordPress API for managing comments, pages, posts,
106 * options, etc.
107 *
108 * Since WordPress 2.6.0, WordPress XMLRPC server can be disabled in the
109 * administration panels.
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
110 *
111 * @package WordPress
112 * @subpackage Publishing
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
113 * @since 1.5.0
a6a1522 File file level phpdoc from jacobsantos. see #7037
ryan authored
114 */
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
115 class wp_xmlrpc_server extends IXR_Server {
116
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
117 /**
118 * Register all of the XMLRPC methods that XMLRPC server understands.
119 *
120 * PHP4 constructor and sets up server and method property. Passes XMLRPC
121 * methods through the 'xmlrpc_methods' filter to allow plugins to extend
122 * or replace XMLRPC methods.
123 *
124 * @since 1.5.0
125 *
126 * @return wp_xmlrpc_server
127 */
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
128 function wp_xmlrpc_server() {
3f90dc2 More informative error message when remote publishing is disabled. Don'...
ryan authored
129 $this->methods = array(
9af6317 WP XML-RPC API
ryan authored
130 // WordPress API
94eea94 wp.getUsersBlogs from josephscott. fixes #7130
ryan authored
131 'wp.getUsersBlogs' => 'this:wp_getUsersBlogs',
9af6317 WP XML-RPC API
ryan authored
132 'wp.getPage' => 'this:wp_getPage',
133 'wp.getPages' => 'this:wp_getPages',
134 'wp.newPage' => 'this:wp_newPage',
135 'wp.deletePage' => 'this:wp_deletePage',
136 'wp.editPage' => 'this:wp_editPage',
137 'wp.getPageList' => 'this:wp_getPageList',
138 'wp.getAuthors' => 'this:wp_getAuthors',
139 'wp.getCategories' => 'this:mw_getCategories', // Alias
e89192b Strip trailing whitespace
ryan authored
140 'wp.getTags' => 'this:wp_getTags',
9af6317 WP XML-RPC API
ryan authored
141 'wp.newCategory' => 'this:wp_newCategory',
00d334c wp.deleteCategory xmlrpc method from josephscott. fixes #4599
ryan authored
142 'wp.deleteCategory' => 'this:wp_deleteCategory',
9af6317 WP XML-RPC API
ryan authored
143 'wp.suggestCategories' => 'this:wp_suggestCategories',
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
144 'wp.uploadFile' => 'this:mw_newMediaObject', // Alias
99b6eff wp.getCommentCount from josephscott. fixes #5463
ryan authored
145 'wp.getCommentCount' => 'this:wp_getCommentCount',
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See #55...
westi authored
146 'wp.getPostStatusList' => 'this:wp_getPostStatusList',
147 'wp.getPageStatusList' => 'this:wp_getPageStatusList',
5d69e51 Expose page template functionality via XML-RPC. Props josephscott. fixes...
ryan authored
148 'wp.getPageTemplates' => 'this:wp_getPageTemplates',
c678502 Add XMLRPC options api. See #7123 props josephscott.
westi authored
149 'wp.getOptions' => 'this:wp_getOptions',
150 'wp.setOptions' => 'this:wp_setOptions',
1b0bfce XML-RPC comments API. see #7446
ryan authored
151 'wp.getComment' => 'this:wp_getComment',
152 'wp.getComments' => 'this:wp_getComments',
153 'wp.deleteComment' => 'this:wp_deleteComment',
154 'wp.editComment' => 'this:wp_editComment',
155 'wp.newComment' => 'this:wp_newComment',
156 'wp.getCommentStatusList' => 'this:wp_getCommentStatusList',
9af6317 WP XML-RPC API
ryan authored
157
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
158 // Blogger API
159 'blogger.getUsersBlogs' => 'this:blogger_getUsersBlogs',
160 'blogger.getUserInfo' => 'this:blogger_getUserInfo',
161 'blogger.getPost' => 'this:blogger_getPost',
162 'blogger.getRecentPosts' => 'this:blogger_getRecentPosts',
163 'blogger.getTemplate' => 'this:blogger_getTemplate',
164 'blogger.setTemplate' => 'this:blogger_setTemplate',
165 'blogger.newPost' => 'this:blogger_newPost',
166 'blogger.editPost' => 'this:blogger_editPost',
167 'blogger.deletePost' => 'this:blogger_deletePost',
168
169 // MetaWeblog API (with MT extensions to structs)
170 'metaWeblog.newPost' => 'this:mw_newPost',
171 'metaWeblog.editPost' => 'this:mw_editPost',
172 'metaWeblog.getPost' => 'this:mw_getPost',
173 'metaWeblog.getRecentPosts' => 'this:mw_getRecentPosts',
174 'metaWeblog.getCategories' => 'this:mw_getCategories',
175 'metaWeblog.newMediaObject' => 'this:mw_newMediaObject',
176
177 // MetaWeblog API aliases for Blogger API
178 // see http://www.xmlrpc.com/stories/storyReader$2460
179 'metaWeblog.deletePost' => 'this:blogger_deletePost',
180 'metaWeblog.getTemplate' => 'this:blogger_getTemplate',
181 'metaWeblog.setTemplate' => 'this:blogger_setTemplate',
182 'metaWeblog.getUsersBlogs' => 'this:blogger_getUsersBlogs',
183
184 // MovableType API
185 'mt.getCategoryList' => 'this:mt_getCategoryList',
186 'mt.getRecentPostTitles' => 'this:mt_getRecentPostTitles',
187 'mt.getPostCategories' => 'this:mt_getPostCategories',
188 'mt.setPostCategories' => 'this:mt_setPostCategories',
189 'mt.supportedMethods' => 'this:mt_supportedMethods',
190 'mt.supportedTextFilters' => 'this:mt_supportedTextFilters',
191 'mt.getTrackbackPings' => 'this:mt_getTrackbackPings',
3f90dc2 More informative error message when remote publishing is disabled. Don'...
ryan authored
192 'mt.publishPost' => 'this:mt_publishPost',
193
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
194 // PingBack
195 'pingback.ping' => 'this:pingback_ping',
196 'pingback.extensions.getPingbacks' => 'this:pingback_extensions_getPingbacks',
197
198 'demo.sayHello' => 'this:sayHello',
199 'demo.addTwoNumbers' => 'this:addTwoNumbers'
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
200 );
c678502 Add XMLRPC options api. See #7123 props josephscott.
westi authored
201
202 $this->initialise_blog_option_info( );
087df40 Allow plugins to hook into XML-RPC server.
saxmatt authored
203 $this->methods = apply_filters('xmlrpc_methods', $this->methods);
461f029 Seperate out the XML-RPC server active behaviour from object constructio...
westi authored
204 }
205
206 function serve_request() {
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
207 $this->IXR_Server($this->methods);
208 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
209
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
210 /**
211 * Test XMLRPC API by saying, "Hello!" to client.
212 *
213 * @since 1.5.0
214 *
215 * @param array $args Method Parameters.
216 * @return string
217 */
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
218 function sayHello($args) {
219 return 'Hello!';
220 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
221
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
222 /**
223 * Test XMLRPC API by adding two numbers for client.
224 *
225 * @since 1.5.0
226 *
227 * @param array $args Method Parameters.
228 * @return int
229 */
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
230 function addTwoNumbers($args) {
231 $number1 = $args[0];
232 $number2 = $args[1];
233 return $number1 + $number2;
234 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
235
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
236 /**
237 * Check user's credentials.
238 *
239 * @since 1.5.0
240 *
241 * @param string $user_login User's username.
242 * @param string $user_pass User's password.
243 * @return bool Whether authentication passed.
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
244 * @deprecated use wp_xmlrpc_server::login
245 * @see wp_xmlrpc_server::login
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
246 */
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
247 function login_pass_ok($user_login, $user_pass) {
3f90dc2 More informative error message when remote publishing is disabled. Don'...
ryan authored
248 if ( !get_option( 'enable_xmlrpc' ) ) {
249 $this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this blog. An admin user can enable them at %s'), admin_url('options-writing.php') ) );
250 return false;
251 }
252
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
253 if (!user_pass_ok($user_login, $user_pass)) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
254 $this->error = new IXR_Error(403, __('Bad login/pass combination.'));
9f534eb Remove trailing spaces and convert spaces to tabs. Props Nazgul. fixes ...
ryan authored
255 return false;
256 }
257 return true;
a7322e8 big oopsie related to moving the xmlrpc.php file: somehow it got replace...
michelvaldrighi authored
258 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
259
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
260 /**
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
261 * Log user in.
262 *
263 * @since 2.8
264 *
265 * @param string $username User's username.
266 * @param string $password User's password.
267 * @return mixed WP_User object if authentication passed, false otherwise
268 */
269 function login($username, $password) {
270 if ( !get_option( 'enable_xmlrpc' ) ) {
271 $this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this blog. An admin user can enable them at %s'), admin_url('options-writing.php') ) );
272 return false;
273 }
274
275 $user = wp_authenticate($username, $password);
276
277 if (is_wp_error($user)) {
278 $this->error = new IXR_Error(403, __('Bad login/pass combination.'));
279 return false;
280 }
281
282 set_current_user( $user->ID );
283 return $user;
284 }
285
286 /**
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
287 * Sanitize string or array of strings for database.
288 *
289 * @since 1.5.2
290 *
291 * @param string|array $array Sanitize single string or array of strings.
292 * @return string|array Type matches $array and sanitized for the database.
293 */
9c9ba0a Escape XMLRPC args.
ryan authored
294 function escape(&$array) {
295 global $wpdb;
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
296
7f1945b xmlrpc updates from Joseph Scott.
ryan authored
297 if(!is_array($array)) {
715ea73 editPage and newPage escaping fixes from Joseph.
ryan authored
298 return($wpdb->escape($array));
299 }
300 else {
301 foreach ( (array) $array as $k => $v ) {
302 if (is_array($v)) {
303 $this->escape($array[$k]);
304 } else if (is_object($v)) {
305 //skip
306 } else {
307 $array[$k] = $wpdb->escape($v);
308 }
9c9ba0a Escape XMLRPC args.
ryan authored
309 }
310 }
311 }
e61a7ce work in progress: replacement for xmlrpc.php, using IXR
michelvaldrighi authored
312
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
313 /**
314 * Retrieve custom fields for post.
315 *
316 * @since 2.5.0
317 *
318 * @param int $post_id Post ID.
319 * @return array Custom fields, if exist.
320 */
d889837 Trailing whitespace cleanup
ryan authored
321 function get_custom_fields($post_id) {
322 $post_id = (int) $post_id;
323
324 $custom_fields = array();
325
326 foreach ( (array) has_meta($post_id) as $meta ) {
327 // Don't expose protected fields.
328 if ( strpos($meta['meta_key'], '_wp_') === 0 ) {
329 continue;
330 }
331
332 $custom_fields[] = array(
333 "id" => $meta['meta_id'],
334 "key" => $meta['meta_key'],
335 "value" => $meta['meta_value']
336 );
337 }
338
339 return $custom_fields;
340 }
341
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
342 /**
343 * Set custom fields for post.
344 *
345 * @since 2.5.0
346 *
347 * @param int $post_id Post ID.
348 * @param array $fields Custom fields.
349 */
d889837 Trailing whitespace cleanup
ryan authored
350 function set_custom_fields($post_id, $fields) {
351 $post_id = (int) $post_id;
352
353 foreach ( (array) $fields as $meta ) {
354 if ( isset($meta['id']) ) {
355 $meta['id'] = (int) $meta['id'];
356
357 if ( isset($meta['key']) ) {
358 update_meta($meta['id'], $meta['key'], $meta['value']);
359 }
360 else {
361 delete_meta($meta['id']);
362 }
363 }
364 else {
365 $_POST['metakeyinput'] = $meta['key'];
366 $_POST['metavalue'] = $meta['value'];
367 add_meta($post_id);
368 }
369 }
370 }
630cd82 Custom fields support for xmlrpc from josephscott. fixes #5148
ryan authored
371
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
372 /**
373 * Setup blog options property.
374 *
375 * Passes property through 'xmlrpc_blog_options' filter.
376 *
377 * @since 2.6.0
378 */
c678502 Add XMLRPC options api. See #7123 props josephscott.
westi authored
379 function initialise_blog_option_info( ) {
380 global $wp_version;
381
382 $this->blog_options = array(
383 // Read only options
384 'software_name' => array(
385 'desc' => __( 'Software Name' ),
386 'readonly' => true,
387 'value' => 'WordPress'
388 ),
389 'software_version' => array(
390 'desc' => __( 'Software Version' ),
391 'readonly' => true,
392 'value' => $wp_version
393 ),
394 'blog_url' => array(
395 'desc' => __( 'Blog URL' ),
396 'readonly' => true,
397 'option' => 'siteurl'
398 ),
399
400 // Updatable options
401 'time_zone' => array(
402 'desc' => __( 'Time Zone' ),
403 'readonly' => false,
404 'option' => 'gmt_offset'
405 ),
406 'blog_title' => array(
407 'desc' => __( 'Blog Title' ),
408 'readonly' => false,
409 'option' => 'blogname'
410 ),
411 'blog_tagline' => array(
412 'desc' => __( 'Blog Tagline' ),
413 'readonly' => false,
414 'option' => 'blogdescription'
415 ),
416 'date_format' => array(
417 'desc' => __( 'Date Format' ),
418 'readonly' => false,
419 'option' => 'date_format'
420 ),
421 'time_format' => array(
422 'desc' => __( 'Time Format' ),
423 'readonly' => false,
424 'option' => 'time_format'
d26e048 Allow user registration to be enabled by an XMLRPC client. Fixes #10454 ...
westi authored
425 ),
426 'users_can_register' => array(
427 'desc' => __( 'Allow new users to sign up' ),
428 'readonly' => false,
429 'option' => 'users_can_register'
c678502 Add XMLRPC options api. See #7123 props josephscott.
westi authored
430 )
431 );
432
433 $this->blog_options = apply_filters( 'xmlrpc_blog_options', $this->blog_options );
434 }
435
9af6317 WP XML-RPC API
ryan authored
436 /**
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
437 * Retrieve the blogs of the user.
438 *
439 * @since 2.6.0
440 *
441 * @param array $args Method parameters.
442 * @return array
94eea94 wp.getUsersBlogs from josephscott. fixes #7130
ryan authored
443 */
444 function wp_getUsersBlogs( $args ) {
445 // If this isn't on WPMU then just use blogger_getUsersBlogs
446 if( !function_exists( 'is_site_admin' ) ) {
447 array_unshift( $args, 1 );
448 return $this->blogger_getUsersBlogs( $args );
449 }
450
451 $this->escape( $args );
452
453 $username = $args[0];
454 $password = $args[1];
455
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
456 if ( !$user = $this->login($username, $password) ) {
94eea94 wp.getUsersBlogs from josephscott. fixes #7130
ryan authored
457 return $this->error;
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
458 }
94eea94 wp.getUsersBlogs from josephscott. fixes #7130
ryan authored
459
460 do_action( 'xmlrpc_call', 'wp.getUsersBlogs' );
461
462 $blogs = (array) get_blogs_of_user( $user->ID );
463 $struct = array( );
464
465 foreach( $blogs as $blog ) {
466 // Don't include blogs that aren't hosted at this site
bdde119 wp_getUsersBlogs() fix from josephscott. fixes #8255
ryan authored
467 if( $blog->site_id != $current_site->id )
94eea94 wp.getUsersBlogs from josephscott. fixes #7130
ryan authored
468 continue;
469
470 $blog_id = $blog->userblog_id;
471 switch_to_blog($blog_id);
472 $is_admin = current_user_can('level_8');
473
474 $struct[] = array(
475 'isAdmin' => $is_admin,
476 'url' => get_option( 'home' ) . '/',
477 'blogid' => $blog_id,
478 'blogName' => get_option( 'blogname' ),
70fa2b1 Fix path to xmlrpc. Props MidnighToker. fixes #9516
ryan authored
479 'xmlrpc' => site_url( 'xmlrpc.php' )
94eea94 wp.getUsersBlogs from josephscott. fixes #7130
ryan authored
480 );
bdde119 wp_getUsersBlogs() fix from josephscott. fixes #8255
ryan authored
481
482 restore_current_blog( );
94eea94 wp.getUsersBlogs from josephscott. fixes #7130
ryan authored
483 }
484
485 return $struct;
486 }
487
488 /**
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
489 * Retrieve page.
490 *
491 * @since 2.2.0
492 *
493 * @param array $args Method parameters.
494 * @return array
9af6317 WP XML-RPC API
ryan authored
495 */
496 function wp_getPage($args) {
497 $this->escape($args);
498
7602d17 (int)er the dragon.
matt authored
499 $blog_id = (int) $args[0];
500 $page_id = (int) $args[1];
9af6317 WP XML-RPC API
ryan authored
501 $username = $args[2];
502 $password = $args[3];
503
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
504 if ( !$user = $this->login($username, $password) ) {
505 return $this->error;
9af6317 WP XML-RPC API
ryan authored
506 }
507
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
508 if( !current_user_can( 'edit_page', $page_id ) )
83f674b Banishing ASCII quotes and apostrophes, props demetris, fixes #9655
azaozz authored
509 return new IXR_Error( 401, __( 'Sorry, you cannot edit this page.' ) );
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
510
3177977 '>"
westi authored
511 do_action('xmlrpc_call', 'wp.getPage');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
512
9af6317 WP XML-RPC API
ryan authored
513 // Lookup page info.
514 $page = get_page($page_id);
515
516 // If we found the page then format the data.
517 if($page->ID && ($page->post_type == "page")) {
518 // Get all of the page content and link.
519 $full_page = get_extended($page->post_content);
520 $link = post_permalink($page->ID);
521
d162935 WP XML-RPC API enhancements.
ryan authored
522 // Get info the page parent if there is one.
523 $parent_title = "";
524 if(!empty($page->post_parent)) {
525 $parent = get_page($page->post_parent);
526 $parent_title = $parent->post_title;
527 }
528
9af6317 WP XML-RPC API
ryan authored
529 // Determine comment and ping settings.
4754d22 Use comments_open() and pings_open(). Props coffee2code. fixes #9557
ryan authored
530 $allow_comments = comments_open($page->ID) ? 1 : 0;
531 $allow_pings = pings_open($page->ID) ? 1 : 0;
9af6317 WP XML-RPC API
ryan authored
532
533 // Format page date.
1354d06 Don't localize dates where not appropriate. Props Denis-de-Bernardy, hak...
ryan authored
534 $page_date = mysql2date("Ymd\TH:i:s", $page->post_date, false);
535 $page_date_gmt = mysql2date("Ymd\TH:i:s", $page->post_date_gmt, false);
9af6317 WP XML-RPC API
ryan authored
536
f9aff17 Ensure that drafts viewed over XMLRPC have a correct gmt date set. Fixes...
westi authored
537 // For drafts use the GMT version of the date
538 if ( $page->post_status == 'draft' ) {
539 $page_date_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $page->post_date ), 'Ymd\TH:i:s' );
540 }
541
9af6317 WP XML-RPC API
ryan authored
542 // Pull the categories info together.
543 $categories = array();
544 foreach(wp_get_post_categories($page->ID) as $cat_id) {
545 $categories[] = get_cat_name($cat_id);
546 }
547
d162935 WP XML-RPC API enhancements.
ryan authored
548 // Get the author info.
549 $author = get_userdata($page->post_author);
9af6317 WP XML-RPC API
ryan authored
550
5d69e51 Expose page template functionality via XML-RPC. Props josephscott. fixes...
ryan authored
551 $page_template = get_post_meta( $page->ID, '_wp_page_template', true );
552 if( empty( $page_template ) )
553 $page_template = 'default';
554
9af6317 WP XML-RPC API
ryan authored
555 $page_struct = array(
d162935 WP XML-RPC API enhancements.
ryan authored
556 "dateCreated" => new IXR_Date($page_date),
557 "userid" => $page->post_author,
558 "page_id" => $page->ID,
559 "page_status" => $page->post_status,
560 "description" => $full_page["main"],
561 "title" => $page->post_title,
562 "link" => $link,
563 "permaLink" => $link,
564 "categories" => $categories,
565 "excerpt" => $page->post_excerpt,
566 "text_more" => $full_page["extended"],
567 "mt_allow_comments" => $allow_comments,
568 "mt_allow_pings" => $allow_pings,
569 "wp_slug" => $page->post_name,
570 "wp_password" => $page->post_password,
e71e25d XMLRPC API updates.
ryan authored
571 "wp_author" => $author->display_name,
d162935 WP XML-RPC API enhancements.
ryan authored
572 "wp_page_parent_id" => $page->post_parent,
573 "wp_page_parent_title" => $parent_title,
574 "wp_page_order" => $page->menu_order,
16c4e7b More XMLRPC updates from Joseph Scott.
ryan authored
575 "wp_author_id" => $author->ID,
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT value...
markjaquith authored
576 "wp_author_display_name" => $author->display_name,
630cd82 Custom fields support for xmlrpc from josephscott. fixes #5148
ryan authored
577 "date_created_gmt" => new IXR_Date($page_date_gmt),
5d69e51 Expose page template functionality via XML-RPC. Props josephscott. fixes...
ryan authored
578 "custom_fields" => $this->get_custom_fields($page_id),
579 "wp_page_template" => $page_template
9af6317 WP XML-RPC API
ryan authored
580 );
581
582 return($page_struct);
583 }
584 // If the page doesn't exist indicate that.
585 else {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
586 return(new IXR_Error(404, __("Sorry, no such page.")));
9af6317 WP XML-RPC API
ryan authored
587 }
588 }
589
590 /**
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
591 * Retrieve Pages.
592 *
593 * @since 2.2.0
594 *
595 * @param array $args Method parameters.
596 * @return array
9af6317 WP XML-RPC API
ryan authored
597 */
598 function wp_getPages($args) {
599 $this->escape($args);
600
7602d17 (int)er the dragon.
matt authored
601 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
602 $username = $args[1];
603 $password = $args[2];
3553ccd Make the number of pages argument to wp.getPages properly optional. See ...
westi authored
604 $num_pages = isset($args[3]) ? (int) $args[3] : 10;
9af6317 WP XML-RPC API
ryan authored
605
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
606 if ( !$user = $this->login($username, $password) ) {
607 return $this->error;
9af6317 WP XML-RPC API
ryan authored
608 }
609
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
610 if( !current_user_can( 'edit_pages' ) )
83f674b Banishing ASCII quotes and apostrophes, props demetris, fixes #9655
azaozz authored
611 return new IXR_Error( 401, __( 'Sorry, you cannot edit pages.' ) );
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
612
3177977 '>"
westi authored
613 do_action('xmlrpc_call', 'wp.getPages');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
614
37bcca4 Don't show deleted Pages in wp.getPages results, props ryan, props Denis...
azaozz authored
615 $pages = get_posts( array('post_type' => 'page', 'post_status' => 'any', 'numberposts' => $num_pages) );
9af6317 WP XML-RPC API
ryan authored
616 $num_pages = count($pages);
617
618 // If we have pages, put together their info.
619 if($num_pages >= 1) {
620 $pages_struct = array();
621
622 for($i = 0; $i < $num_pages; $i++) {
623 $page = wp_xmlrpc_server::wp_getPage(array(
624 $blog_id, $pages[$i]->ID, $username, $password
625 ));
626 $pages_struct[] = $page;
627 }
628
629 return($pages_struct);
630 }
631 // If no pages were found return an error.
632 else {
84cda2c XMLRPC fixes from Joseph Scott. 404 for invalid post ids. Return empty ...
ryan authored
633 return(array());
9af6317 WP XML-RPC API
ryan authored
634 }
635 }
636
637 /**
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
638 * Create new page.
639 *
640 * @since 2.2.0
641 *
642 * @param array $args Method parameters.
643 * @return unknown
9af6317 WP XML-RPC API
ryan authored
644 */
645 function wp_newPage($args) {
715ea73 editPage and newPage escaping fixes from Joseph.
ryan authored
646 // Items not escaped here will be escaped in newPost.
647 $username = $this->escape($args[1]);
648 $password = $this->escape($args[2]);
9af6317 WP XML-RPC API
ryan authored
649 $page = $args[3];
650 $publish = $args[4];
651
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
652 if ( !$user = $this->login($username, $password) ) {
653 return $this->error;
9af6317 WP XML-RPC API
ryan authored
654 }
655
3177977 '>"
westi authored
656 do_action('xmlrpc_call', 'wp.newPage');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
657
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
658 // Make sure the user is allowed to add new pages.
9af6317 WP XML-RPC API
ryan authored
659 if(!current_user_can("publish_pages")) {
83f674b Banishing ASCII quotes and apostrophes, props demetris, fixes #9655
azaozz authored
660 return(new IXR_Error(401, __("Sorry, you cannot add new pages.")));
9af6317 WP XML-RPC API
ryan authored
661 }
662
663 // Mark this as content for a page.
664 $args[3]["post_type"] = "page";
665
666 // Let mw_newPost do all of the heavy lifting.
667 return($this->mw_newPost($args));
668 }
669
670 /**
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
671 * Delete page.
672 *
673 * @since 2.2.0
674 *
675 * @param array $args Method parameters.
676 * @return bool True, if success.
9af6317 WP XML-RPC API
ryan authored
677 */
678 function wp_deletePage($args) {
679 $this->escape($args);
680
7602d17 (int)er the dragon.
matt authored
681 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
682 $username = $args[1];
683 $password = $args[2];
7602d17 (int)er the dragon.
matt authored
684 $page_id = (int) $args[3];
9af6317 WP XML-RPC API
ryan authored
685
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
686 if ( !$user = $this->login($username, $password) ) {
687 return $this->error;
9af6317 WP XML-RPC API
ryan authored
688 }
689
3177977 '>"
westi authored
690 do_action('xmlrpc_call', 'wp.deletePage');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
691
9af6317 WP XML-RPC API
ryan authored
692 // Get the current page based on the page_id and
693 // make sure it is a page and not a post.
694 $actual_page = wp_get_single_post($page_id, ARRAY_A);
695 if(
696 !$actual_page
697 || ($actual_page["post_type"] != "page")
698 ) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
699 return(new IXR_Error(404, __("Sorry, no such page.")));
9af6317 WP XML-RPC API
ryan authored
700 }
701
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
702 // Make sure the user can delete pages.
9af6317 WP XML-RPC API
ryan authored
703 if(!current_user_can("delete_page", $page_id)) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
704 return(new IXR_Error(401, __("Sorry, you do not have the right to delete this page.")));
9af6317 WP XML-RPC API
ryan authored
705 }
706
707 // Attempt to delete the page.
708 $result = wp_delete_post($page_id);
709 if(!$result) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
710 return(new IXR_Error(500, __("Failed to delete the page.")));
9af6317 WP XML-RPC API
ryan authored
711 }
712
713 return(true);
714 }
715
716 /**
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
717 * Edit page.
718 *
719 * @since 2.2.0
720 *
721 * @param array $args Method parameters.
722 * @return unknown
9af6317 WP XML-RPC API
ryan authored
723 */
724 function wp_editPage($args) {
715ea73 editPage and newPage escaping fixes from Joseph.
ryan authored
725 // Items not escaped here will be escaped in editPost.
7602d17 (int)er the dragon.
matt authored
726 $blog_id = (int) $args[0];
ae7fa6c Cast to int after escaping. Props Joseph Scott.
ryan authored
727 $page_id = (int) $this->escape($args[1]);
715ea73 editPage and newPage escaping fixes from Joseph.
ryan authored
728 $username = $this->escape($args[2]);
729 $password = $this->escape($args[3]);
9af6317 WP XML-RPC API
ryan authored
730 $content = $args[4];
731 $publish = $args[5];
732
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
733 if ( !$user = $this->login($username, $password) ) {
734 return $this->error;
9af6317 WP XML-RPC API
ryan authored
735 }
736
3177977 '>"
westi authored
737 do_action('xmlrpc_call', 'wp.editPage');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
738
9af6317 WP XML-RPC API
ryan authored
739 // Get the page data and make sure it is a page.
740 $actual_page = wp_get_single_post($page_id, ARRAY_A);
741 if(
742 !$actual_page
743 || ($actual_page["post_type"] != "page")
744 ) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
745 return(new IXR_Error(404, __("Sorry, no such page.")));
9af6317 WP XML-RPC API
ryan authored
746 }
747
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
748 // Make sure the user is allowed to edit pages.
9af6317 WP XML-RPC API
ryan authored
749 if(!current_user_can("edit_page", $page_id)) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
750 return(new IXR_Error(401, __("Sorry, you do not have the right to edit this page.")));
9af6317 WP XML-RPC API
ryan authored
751 }
752
753 // Mark this as content for a page.
754 $content["post_type"] = "page";
755
756 // Arrange args in the way mw_editPost understands.
757 $args = array(
758 $page_id,
759 $username,
760 $password,
761 $content,
762 $publish
763 );
764
765 // Let mw_editPost do all of the heavy lifting.
766 return($this->mw_editPost($args));
767 }
768
769 /**
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
770 * Retrieve page list.
771 *
772 * @since 2.2.0
773 *
774 * @param array $args Method parameters.
775 * @return unknown
9af6317 WP XML-RPC API
ryan authored
776 */
777 function wp_getPageList($args) {
778 global $wpdb;
779
780 $this->escape($args);
781
7602d17 (int)er the dragon.
matt authored
782 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
783 $username = $args[1];
784 $password = $args[2];
785
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
786 if ( !$user = $this->login($username, $password) ) {
787 return $this->error;
9af6317 WP XML-RPC API
ryan authored
788 }
789
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
790 if( !current_user_can( 'edit_pages' ) )
83f674b Banishing ASCII quotes and apostrophes, props demetris, fixes #9655
azaozz authored
791 return new IXR_Error( 401, __( 'Sorry, you cannot edit pages.' ) );
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
792
3177977 '>"
westi authored
793 do_action('xmlrpc_call', 'wp.getPageList');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
794
9af6317 WP XML-RPC API
ryan authored
795 // Get list of pages ids and titles
796 $page_list = $wpdb->get_results("
797 SELECT ID page_id,
d162935 WP XML-RPC API enhancements.
ryan authored
798 post_title page_title,
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
799 post_parent page_parent_id,
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT value...
markjaquith authored
800 post_date_gmt,
f9aff17 Ensure that drafts viewed over XMLRPC have a correct gmt date set. Fixes...
westi authored
801 post_date,
802 post_status
9af6317 WP XML-RPC API
ryan authored
803 FROM {$wpdb->posts}
804 WHERE post_type = 'page'
805 ORDER BY ID
806 ");
807
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
808 // The date needs to be formated properly.
809 $num_pages = count($page_list);
810 for($i = 0; $i < $num_pages; $i++) {
1354d06 Don't localize dates where not appropriate. Props Denis-de-Bernardy, hak...
ryan authored
811 $post_date = mysql2date("Ymd\TH:i:s", $page_list[$i]->post_date, false);
812 $post_date_gmt = mysql2date("Ymd\TH:i:s", $page_list[$i]->post_date_gmt, false);
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT value...
markjaquith authored
813
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
814 $page_list[$i]->dateCreated = new IXR_Date($post_date);
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT value...
markjaquith authored
815 $page_list[$i]->date_created_gmt = new IXR_Date($post_date_gmt);
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
816
f9aff17 Ensure that drafts viewed over XMLRPC have a correct gmt date set. Fixes...
westi authored
817 // For drafts use the GMT version of the date
818 if ( $page_list[$i]->post_status == 'draft' ) {
819 $page_list[$i]->date_created_gmt = get_gmt_from_date( mysql2date( 'Y-m-d H:i:s', $page_list[$i]->post_date ), 'Ymd\TH:i:s' );
820 $page_list[$i]->date_created_gmt = new IXR_Date( $page_list[$i]->date_created_gmt );
821 }
822
be8f80d Use GMT in XML-RPC dateCreated fields. Props Joseph Scott. fixes #4158 ...
ryan authored
823 unset($page_list[$i]->post_date_gmt);
d55ac97 Send dateCreated as local blog time, add date_created_gmt with GMT value...
markjaquith authored
824 unset($page_list[$i]->post_date);
f9aff17 Ensure that drafts viewed over XMLRPC have a correct gmt date set. Fixes...
westi authored
825 unset($page_list[$i]->post_status);
fea2a6e xmlrpc updates from Joseph Scott.
ryan authored
826 }
827
9af6317 WP XML-RPC API
ryan authored
828 return($page_list);
829 }
830
831 /**
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
832 * Retrieve authors list.
833 *
834 * @since 2.2.0
835 *
836 * @param array $args Method parameters.
837 * @return array
9af6317 WP XML-RPC API
ryan authored
838 */
839 function wp_getAuthors($args) {
840
841 $this->escape($args);
842
7602d17 (int)er the dragon.
matt authored
843 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
844 $username = $args[1];
845 $password = $args[2];
846
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
847 if ( !$user = $this->login($username, $password) ) {
848 return $this->error;
9af6317 WP XML-RPC API
ryan authored
849 }
850
2490ec4 Limit what getAuthors exposes. Props josephscott for the patch and xknow...
ryan authored
851 if(!current_user_can("edit_posts")) {
83f674b Banishing ASCII quotes and apostrophes, props demetris, fixes #9655
azaozz authored
852 return(new IXR_Error(401, __("Sorry, you cannot edit posts on this blog.")));
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
853 }
2490ec4 Limit what getAuthors exposes. Props josephscott for the patch and xknow...
ryan authored
854
3177977 '>"
westi authored
855 do_action('xmlrpc_call', 'wp.getAuthors');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
856
2490ec4 Limit what getAuthors exposes. Props josephscott for the patch and xknow...
ryan authored
857 $authors = array();
858 foreach( (array) get_users_of_blog() as $row ) {
859 $authors[] = array(
860 "user_id" => $row->user_id,
861 "user_login" => $row->user_login,
862 "display_name" => $row->display_name
863 );
864 }
865
866 return($authors);
9af6317 WP XML-RPC API
ryan authored
867 }
868
869 /**
f72a4ce List post tags via XMLRPC. Props josephscott. fixes #7744
ryan authored
870 * Get list of all tags
871 *
872 * @since 2.7
873 *
874 * @param array $args Method parameters.
875 * @return array
876 */
877 function wp_getTags( $args ) {
878 $this->escape( $args );
879
880 $blog_id = (int) $args[0];
881 $username = $args[1];
882 $password = $args[2];
883
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
884 if ( !$user = $this->login($username, $password) ) {
f72a4ce List post tags via XMLRPC. Props josephscott. fixes #7744
ryan authored
885 return $this->error;
886 }
887
888 if( !current_user_can( 'edit_posts' ) ) {
889 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this blog in order to view tags.' ) );
890 }
891
892 do_action( 'xmlrpc_call', 'wp.getKeywords' );
893
894 $tags = array( );
895
896 if( $all_tags = get_tags( ) ) {
897 foreach( (array) $all_tags as $tag ) {
898 $struct['tag_id'] = $tag->term_id;
899 $struct['name'] = $tag->name;
900 $struct['count'] = $tag->count;
901 $struct['slug'] = $tag->slug;
119b39c deprecate wp_specialchars() in favor of esc_html(). Encode quotes for es...
markjaquith authored
902 $struct['html_url'] = esc_html( get_tag_link( $tag->term_id ) );
903 $struct['rss_url'] = esc_html( get_tag_feed_link( $tag->term_id ) );
f72a4ce List post tags via XMLRPC. Props josephscott. fixes #7744
ryan authored
904
905 $tags[] = $struct;
906 }
907 }
908
909 return $tags;
910 }
911
912 /**
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
913 * Create new category.
914 *
915 * @since 2.2.0
916 *
917 * @param array $args Method parameters.
918 * @return int Category ID.
9af6317 WP XML-RPC API
ryan authored
919 */
920 function wp_newCategory($args) {
921 $this->escape($args);
922
7602d17 (int)er the dragon.
matt authored
923 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
924 $username = $args[1];
925 $password = $args[2];
926 $category = $args[3];
927
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
928 if ( !$user = $this->login($username, $password) ) {
929 return $this->error;
9af6317 WP XML-RPC API
ryan authored
930 }
931
3177977 '>"
westi authored
932 do_action('xmlrpc_call', 'wp.newCategory');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
933
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
934 // Make sure the user is allowed to add a category.
00d334c wp.deleteCategory xmlrpc method from josephscott. fixes #4599
ryan authored
935 if(!current_user_can("manage_categories")) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
936 return(new IXR_Error(401, __("Sorry, you do not have the right to add a category.")));
9af6317 WP XML-RPC API
ryan authored
937 }
938
939 // If no slug was provided make it empty so that
940 // WordPress will generate one.
941 if(empty($category["slug"])) {
942 $category["slug"] = "";
943 }
944
945 // If no parent_id was provided make it empty
946 // so that it will be a top level page (no parent).
c8997ff Reverse logic.
ryan authored
947 if ( !isset($category["parent_id"]) )
9af6317 WP XML-RPC API
ryan authored
948 $category["parent_id"] = "";
949
950 // If no description was provided make it empty.
951 if(empty($category["description"])) {
952 $category["description"] = "";
953 }
2f09416 Trim empty lines. Nothing but newline.
ryan authored
954
9af6317 WP XML-RPC API
ryan authored
955 $new_category = array(
956 "cat_name" => $category["name"],
957 "category_nicename" => $category["slug"],
958 "category_parent" => $category["parent_id"],
959 "category_description" => $category["description"]
960 );
961
3d21925 Ryan slays the dragon. (Some of these return WP_Error objects.)
matt authored
962 $cat_id = wp_insert_category($new_category);
9af6317 WP XML-RPC API
ryan authored
963 if(!$cat_id) {
e273f11 Translate APP and XMLRPC errors. Props nbachiyski. fixes #3997
ryan authored
964 return(new IXR_Error(500, __("Sorry, the new category failed.")));
9af6317 WP XML-RPC API
ryan authored
965 }
966
967 return($cat_id);
968 }
969
970 /**
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
971 * Remove category.
972 *
973 * @since 2.5.0
974 *
975 * @param array $args Method parameters.
976 * @return mixed See {@link wp_delete_category()} for return info.
00d334c wp.deleteCategory xmlrpc method from josephscott. fixes #4599
ryan authored
977 */
978 function wp_deleteCategory($args) {
979 $this->escape($args);
980
981 $blog_id = (int) $args[0];
982 $username = $args[1];
983 $password = $args[2];
984 $category_id = (int) $args[3];
985
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
986 if ( !$user = $this->login($username, $password) ) {
00d334c wp.deleteCategory xmlrpc method from josephscott. fixes #4599
ryan authored
987 return $this->error;
988 }
989
3177977 '>"
westi authored
990 do_action('xmlrpc_call', 'wp.deleteCategory');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
991
00d334c wp.deleteCategory xmlrpc method from josephscott. fixes #4599
ryan authored
992 if( !current_user_can("manage_categories") ) {
fc943e2 Grammar fixes from takayukister and thenlich. fixes #5992
ryan authored
993 return new IXR_Error( 401, __( "Sorry, you do not have the right to delete a category." ) );
00d334c wp.deleteCategory xmlrpc method from josephscott. fixes #4599
ryan authored
994 }
995
996 return wp_delete_category( $category_id );
997 }
998
999 /**
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
1000 * Retrieve category list.
1001 *
1002 * @since 2.2.0
1003 *
1004 * @param array $args Method parameters.
1005 * @return array
9af6317 WP XML-RPC API
ryan authored
1006 */
1007 function wp_suggestCategories($args) {
1008 $this->escape($args);
1009
7602d17 (int)er the dragon.
matt authored
1010 $blog_id = (int) $args[0];
9af6317 WP XML-RPC API
ryan authored
1011 $username = $args[1];
1012 $password = $args[2];
1013 $category = $args[3];
070d2fd Int cast. Props to Alexander Concha for the find, Joseph Scott for the ...
markjaquith authored
1014 $max_results = (int) $args[4];
9af6317 WP XML-RPC API
ryan authored
1015
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1016 if ( !$user = $this->login($username, $password) ) {
1017 return $this->error;
9af6317 WP XML-RPC API
ryan authored
1018 }
1019
d889837 Trailing whitespace cleanup
ryan authored
1020 if( !current_user_can( 'edit_posts' ) )
9f9769b Add some more actions to xmlrpc. Fixes #5686 props joesephscott.
westi authored
1021 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts to this blog in order to view categories.' ) );
c36d1c9 Some xmlrpc cap checks from josephscott.
ryan authored
1022
3177977 '>"
westi authored
1023 do_action('xmlrpc_call', 'wp.suggestCategories');
53db776 Add xmlrpc_call actions. Cleanup some whitespace.
ryan authored
1024
fc8d883 Fix wp.suggestCategories return values. Props josephscott. fixes #5406
ryan authored
1025 $category_suggestions = array();
7217266 AND get_terms() field queries
ryan authored
1026 $args = array('get' => 'all', 'number' => $max_results, 'name__like' => $category);
fc8d883 Fix wp.suggestCategories return values. Props josephscott. fixes #5406
ryan authored
1027 foreach ( (array) get_categories($args) as $cat ) {
1028 $category_suggestions[] = array(
1029 "category_id" => $cat->cat_ID,
1030 "category_name" => $cat->cat_name
1031 );
1032 }
9af6317 WP XML-RPC API
ryan authored
1033
1034 return($category_suggestions);
1035 }
1036
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
1037 /**
1038 * Retrieve comment.
1039 *
1040 * @since 2.7.0
1041 *
1042 * @param array $args Method parameters.
1043 * @return array
1044 */
1b0bfce XML-RPC comments API. see #7446
ryan authored
1045 function wp_getComment($args) {
1046 $this->escape($args);
1047
1048 $blog_id = (int) $args[0];
1049 $username = $args[1];
1050 $password = $args[2];
1051 $comment_id = (int) $args[3];
1052
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1053 if ( !$user = $this->login($username, $password) ) {
1b0bfce XML-RPC comments API. see #7446
ryan authored
1054 return $this->error;
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1055 }
1b0bfce XML-RPC comments API. see #7446
ryan authored
1056
1057 if ( !current_user_can( 'moderate_comments' ) )
1058 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) );
1059
1060 do_action('xmlrpc_call', 'wp.getComment');
1061
1062 if ( ! $comment = get_comment($comment_id) )
1063 return new IXR_Error( 404, __( 'Invalid comment ID.' ) );
1064
1065 // Format page date.
1354d06 Don't localize dates where not appropriate. Props Denis-de-Bernardy, hak...
ryan authored
1066 $comment_date = mysql2date("Ymd\TH:i:s", $comment->comment_date, false);
1067 $comment_date_gmt = mysql2date("Ymd\TH:i:s", $comment->comment_date_gmt, false);
1b0bfce XML-RPC comments API. see #7446
ryan authored
1068
07c88e5 Ensure that XMLRPC clients can tell the difference between unapproved an...
westi authored
1069 if ( '0' == $comment->comment_approved )
1b0bfce XML-RPC comments API. see #7446
ryan authored
1070 $comment_status = 'hold';
1071 else if ( 'spam' == $comment->comment_approved )
1072 $comment_status = 'spam';
07c88e5 Ensure that XMLRPC clients can tell the difference between unapproved an...
westi authored
1073 else if ( '1' == $comment->comment_approved )
1b0bfce XML-RPC comments API. see #7446
ryan authored
1074 $comment_status = 'approve';
0a37661 Ensure we support custom comment approval statuses over xmlrpc. Fixes #7...
westi authored
1075 else
1076 $comment_status = $comment->comment_approved;
1b0bfce XML-RPC comments API. see #7446
ryan authored
1077
1078 $link = get_comment_link($comment);
1079
1080 $comment_struct = array(
1081 "date_created_gmt" => new IXR_Date($comment_date_gmt),
1082 "user_id" => $comment->user_id,
1083 "comment_id" => $comment->comment_ID,
1084 "parent" => $comment->comment_parent,
1085 "status" => $comment_status,
1086 "content" => $comment->comment_content,
1087 "link" => $link,
1088 "post_id" => $comment->comment_post_ID,
1089 "post_title" => get_the_title($comment->comment_post_ID),
24b304f Typo fix. Props josephscott. see #7446
ryan authored
1090 "author" => $comment->comment_author,
1b0bfce XML-RPC comments API. see #7446
ryan authored
1091 "author_url" => $comment->comment_author_url,
1092 "author_email" => $comment->comment_author_email,
1093 "author_ip" => $comment->comment_author_IP,
1d72687 Add the comment type to the data wp.getComment returns. Fixes #8486 prop...
westi authored
1094 "type" => $comment->comment_type,
1b0bfce XML-RPC comments API. see #7446
ryan authored
1095 );
1096
1097 return $comment_struct;
1098 }
1099
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
1100 /**
1101 * Retrieve comments.
1102 *
1103 * @since 2.7.0
1104 *
1105 * @param array $args Method parameters.
1106 * @return array
1107 */
1b0bfce XML-RPC comments API. see #7446
ryan authored
1108 function wp_getComments($args) {
6ca8efa Fix double escaping in wp_getComments. Props josephscott. fixes #12281 f...
ryan authored
1109 $raw_args = $args;
1b0bfce XML-RPC comments API. see #7446
ryan authored
1110 $this->escape($args);
1111
1112 $blog_id = (int) $args[0];
1113 $username = $args[1];
1114 $password = $args[2];
1115 $struct = $args[3];
1116
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1117 if ( !$user = $this->login($username, $password) ) {
1118 return $this->error;
1119 }
1b0bfce XML-RPC comments API. see #7446
ryan authored
1120
1121 if ( !current_user_can( 'moderate_comments' ) )
83f674b Banishing ASCII quotes and apostrophes, props demetris, fixes #9655
azaozz authored
1122 return new IXR_Error( 401, __( 'Sorry, you cannot edit comments.' ) );
1b0bfce XML-RPC comments API. see #7446
ryan authored
1123
1124 do_action('xmlrpc_call', 'wp.getComments');
1125
1126 if ( isset($struct['status']) )
1127 $status = $struct['status'];
1128 else
1129 $status = '';
1130
1131 $post_id = '';
1132 if ( isset($struct['post_id']) )
1133 $post_id = absint($struct['post_id']);
1134
1135 $offset = 0;
1136 if ( isset($struct['offset']) )
1137 $offset = absint($struct['offset']);
1138
1139 $number = 10;
1140 if ( isset($struct['number']) )
1141 $number = absint($struct['number']);
1142
1143 $comments = get_comments( array('status' => $status, 'post_id' => $post_id, 'offset' => $offset, 'number' => $number ) );
1144 $num_comments = count($comments);
1145
1146 if ( ! $num_comments )
1147 return array();
1148
1149 $comments_struct = array();
1150
1151 for ( $i = 0; $i < $num_comments; $i++ ) {
1152 $comment = wp_xmlrpc_server::wp_getComment(array(
6ca8efa Fix double escaping in wp_getComments. Props josephscott. fixes #12281 f...
ryan authored
1153 $raw_args[0], $raw_args[1], $raw_args[2], $comments[$i]->comment_ID,
1b0bfce XML-RPC comments API. see #7446
ryan authored
1154 ));
1155 $comments_struct[] = $comment;
1156 }
1157
1158 return $comments_struct;
1159 }
1160
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
1161 /**
1162 * Remove comment.
1163 *
1164 * @since 2.7.0
1165 *
1166 * @param array $args Method parameters.
1167 * @return mixed {@link wp_delete_comment()}
1168 */
1b0bfce XML-RPC comments API. see #7446
ryan authored
1169 function wp_deleteComment($args) {
1170 $this->escape($args);
1171
1172 $blog_id = (int) $args[0];
1173 $username = $args[1];
1174 $password = $args[2];
1175 $comment_ID = (int) $args[3];
1176
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1177 if ( !$user = $this->login($username, $password) ) {
1b0bfce XML-RPC comments API. see #7446
ryan authored
1178 return $this->error;
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1179 }
1b0bfce XML-RPC comments API. see #7446
ryan authored
1180
1181 if ( !current_user_can( 'moderate_comments' ) )
1182 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) );
1183
1184 do_action('xmlrpc_call', 'wp.deleteComment');
1185
1186 if ( ! get_comment($comment_ID) )
1187 return new IXR_Error( 404, __( 'Invalid comment ID.' ) );
1188
1189 return wp_delete_comment($comment_ID);
1190 }
1191
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
1192 /**
1193 * Edit comment.
1194 *
1195 * @since 2.7.0
1196 *
1197 * @param array $args Method parameters.
1198 * @return bool True, on success.
1199 */
1b0bfce XML-RPC comments API. see #7446
ryan authored
1200 function wp_editComment($args) {
1201 $this->escape($args);
1202
1203 $blog_id = (int) $args[0];
1204 $username = $args[1];
1205 $password = $args[2];
1206 $comment_ID = (int) $args[3];
1207 $content_struct = $args[4];
1208
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1209 if ( !$user = $this->login($username, $password) ) {
1b0bfce XML-RPC comments API. see #7446
ryan authored
1210 return $this->error;
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1211 }
1b0bfce XML-RPC comments API. see #7446
ryan authored
1212
1213 if ( !current_user_can( 'moderate_comments' ) )
1214 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this blog.' ) );
1215
1216 do_action('xmlrpc_call', 'wp.editComment');
1217
1218 if ( ! get_comment($comment_ID) )
1219 return new IXR_Error( 404, __( 'Invalid comment ID.' ) );
1220
1221 if ( isset($content_struct['status']) ) {
1222 $statuses = get_comment_statuses();
1223 $statuses = array_keys($statuses);
1224
1225 if ( ! in_array($content_struct['status'], $statuses) )
1226 return new IXR_Error( 401, __( 'Invalid comment status.' ) );
1227 $comment_approved = $content_struct['status'];
1228 }
1229
1230 // Do some timestamp voodoo
1231 if ( !empty( $content_struct['date_created_gmt'] ) ) {
1232 $dateCreated = str_replace( 'Z', '', $content_struct['date_created_gmt']->getIso() ) . 'Z'; // We know this is supposed to be GMT, so we're going to slap that Z on there by force
1233 $comment_date = get_date_from_gmt(iso8601_to_datetime($dateCreated));
1234 $comment_date_gmt = iso8601_to_datetime($dateCreated, GMT);
1235 }
1236
1237 if ( isset($content_struct['content']) )
1238 $comment_content = $content_struct['content'];
1239
1240 if ( isset($content_struct['author']) )
1241 $comment_author = $content_struct['author'];
1242
1243 if ( isset($content_struct['author_url']) )
1244 $comment_author_url = $content_struct['author_url'];
1245
1246 if ( isset($content_struct['author_email']) )
1247 $comment_author_email = $content_struct['author_email'];
1248
1249 // We've got all the data -- post it:
1250 $comment = compact('comment_ID', 'comment_content', 'comment_approved', 'comment_date', 'comment_date_gmt', 'comment_author', 'comment_author_email', 'comment_author_url');
35b18e5 Trailing whitespace cleanup
ryan authored
1251
1b0bfce XML-RPC comments API. see #7446
ryan authored
1252 $result = wp_update_comment($comment);
1253 if ( is_wp_error( $result ) )
1254 return new IXR_Error(500, $result->get_error_message());
1255
1256 if ( !$result )
1257 return new IXR_Error(500, __('Sorry, the comment could not be edited. Something wrong happened.'));
1258
1259 return true;
1260 }
1261
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
1262 /**
1263 * Create new comment.
1264 *
1265 * @since 2.7.0
1266 *
1267 * @param array $args Method parameters.
1268 * @return mixed {@link wp_new_comment()}
1269 */
1b0bfce XML-RPC comments API. see #7446
ryan authored
1270 function wp_newComment($args) {
1271 global $wpdb;
1272
1273 $this->escape($args);
1274
1275 $blog_id = (int) $args[0];
1276 $username = $args[1];
1277 $password = $args[2];
1278 $post = $args[3];
1279 $content_struct = $args[4];
1280
1281 $allow_anon = apply_filters('xmlrpc_allow_anonymous_comments', false);
1282
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1283 $user = $this->login($username, $password);
1284
1285 if ( !$user ) {
1b0bfce XML-RPC comments API. see #7446
ryan authored
1286 $logged_in = false;
1287 if ( $allow_anon && get_option('comment_registration') )
1288 return new IXR_Error( 403, __( 'You must be registered to comment' ) );
1289 else if ( !$allow_anon )
1290 return $this->error;
1291 } else {
1292 $logged_in = true;
1293 }
1294
1295 if ( is_numeric($post) )
1296 $post_id = absint($post);
1297 else
1298 $post_id = url_to_postid($post);
1299
1300 if ( ! $post_id )
1301 return new IXR_Error( 404, __( 'Invalid post ID.' ) );
1302
1303 if ( ! get_post($post_id) )
1304 return new IXR_Error( 404, __( 'Invalid post ID.' ) );
1305
1306 $comment['comment_post_ID'] = $post_id;
1307
1308 if ( $logged_in ) {
1309 $comment['comment_author'] = $wpdb->escape( $user->display_name );
1310 $comment['comment_author_email'] = $wpdb->escape( $user->user_email );
1311 $comment['comment_author_url'] = $wpdb->escape( $user->user_url );
1312 $comment['user_ID'] = $user->ID;
1313 } else {
1314 $comment['comment_author'] = '';
1315 if ( isset($content_struct['author']) )
1316 $comment['comment_author'] = $content_struct['author'];
08d1442 XMLRPC wp_newComment() fixes. Props josephscott. fixes #8672 for trunk
ryan authored
1317
1b0bfce XML-RPC comments API. see #7446
ryan authored
1318 $comment['comment_author_email'] = '';
08d1442 XMLRPC wp_newComment() fixes. Props josephscott. fixes #8672 for trunk
ryan authored
1319 if ( isset($content_struct['author_email']) )
1b0bfce XML-RPC comments API. see #7446
ryan authored
1320 $comment['comment_author_email'] = $content_struct['author_email'];
08d1442 XMLRPC wp_newComment() fixes. Props josephscott. fixes #8672 for trunk
ryan authored
1321
1b0bfce XML-RPC comments API. see #7446
ryan authored
1322 $comment['comment_author_url'] = '';
08d1442 XMLRPC wp_newComment() fixes. Props josephscott. fixes #8672 for trunk
ryan authored
1323 if ( isset($content_struct['author_url']) )
1b0bfce XML-RPC comments API. see #7446
ryan authored
1324 $comment['comment_author_url'] = $content_struct['author_url'];
08d1442 XMLRPC wp_newComment() fixes. Props josephscott. fixes #8672 for trunk
ryan authored
1325
1b0bfce XML-RPC comments API. see #7446
ryan authored
1326 $comment['user_ID'] = 0;
1327
1328 if ( get_option('require_name_email') ) {
1329 if ( 6 > strlen($comment['comment_author_email']) || '' == $comment['comment_author'] )
1330 return new IXR_Error( 403, __( 'Comment author name and email are required' ) );
1331 elseif ( !is_email($comment['comment_author_email']) )
1332 return new IXR_Error( 403, __( 'A valid email address is required' ) );
1333 }
1334 }
1335
95fa29a Reply to comments from admin, first run, see #7435
azaozz authored
1336 $comment['comment_parent'] = isset($content_struct['comment_parent']) ? absint($content_struct['comment_parent']) : 0;
1337
1b0bfce XML-RPC comments API. see #7446
ryan authored
1338 $comment['comment_content'] = $content_struct['content'];
1339
1340 do_action('xmlrpc_call', 'wp.newComment');
35b18e5 Trailing whitespace cleanup
ryan authored
1341
1b0bfce XML-RPC comments API. see #7446
ryan authored
1342 return wp_new_comment($comment);
1343 }
1344
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
1345 /**
1346 * Retrieve all of the comment status.
1347 *
1348 * @since 2.7.0
1349 *
1350 * @param array $args Method parameters.
1351 * @return array
1352 */
1b0bfce XML-RPC comments API. see #7446
ryan authored
1353 function wp_getCommentStatusList($args) {
1354 $this->escape( $args );
1355
1356 $blog_id = (int) $args[0];
1357 $username = $args[1];
1358 $password = $args[2];
1359
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1360 if ( !$user = $this->login($username, $password) ) {
1b0bfce XML-RPC comments API. see #7446
ryan authored
1361 return $this->error;
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1362 }
1b0bfce XML-RPC comments API. see #7446
ryan authored
1363
1364 if ( !current_user_can( 'moderate_comments' ) )
1365 return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
1366
1367 do_action('xmlrpc_call', 'wp.getCommentStatusList');
1368
1369 return get_comment_statuses( );
1370 }
1371
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
1372 /**
1373 * Retrieve comment count.
1374 *
1375 * @since 2.5.0
1376 *
1377 * @param array $args Method parameters.
1378 * @return array
1379 */
99b6eff wp.getCommentCount from josephscott. fixes #5463
ryan authored
1380 function wp_getCommentCount( $args ) {
d889837 Trailing whitespace cleanup
ryan authored
1381 $this->escape($args);
99b6eff wp.getCommentCount from josephscott. fixes #5463
ryan authored
1382
d889837 Trailing whitespace cleanup
ryan authored
1383 $blog_id = (int) $args[0];
1384 $username = $args[1];
1385 $password = $args[2];
1386 $post_id = (int) $args[3];
99b6eff wp.getCommentCount from josephscott. fixes #5463
ryan authored
1387
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1388 if ( !$user = $this->login($username, $password) ) {
3f90dc2 More informative error message when remote publishing is disabled. Don'...
ryan authored
1389 return $this->error;
d889837 Trailing whitespace cleanup
ryan authored
1390 }
99b6eff wp.getCommentCount from josephscott. fixes #5463
ryan authored
1391
d889837 Trailing whitespace cleanup
ryan authored
1392 if( !current_user_can( 'edit_posts' ) ) {
428d820 Grammar fix. Props thenlich and hansengel. fixes #5991
ryan authored
1393 return new IXR_Error( 403, __( 'You are not allowed access to details about comments.' ) );
d889837 Trailing whitespace cleanup
ryan authored
1394 }
99b6eff wp.getCommentCount from josephscott. fixes #5463
ryan authored
1395
9f9769b Add some more actions to xmlrpc. Fixes #5686 props joesephscott.
westi authored
1396 do_action('xmlrpc_call', 'wp.getCommentCount');
1397
94eb722 Use wp_count_comments() in wp.getCommentCount. Props josephscott. fixes ...
ryan authored
1398 $count = wp_count_comments( $post_id );
1399 return array(
1400 "approved" => $count->approved,
1401 "awaiting_moderation" => $count->moderated,
1402 "spam" => $count->spam,
1403 "total_comments" => $count->total_comments
1404 );
99b6eff wp.getCommentCount from josephscott. fixes #5463
ryan authored
1405 }
1406
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
1407 /**
1408 * Retrieve post statuses.
1409 *
1410 * @since 2.5.0
1411 *
1412 * @param array $args Method parameters.
1413 * @return array
1414 */
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See #55...
westi authored
1415 function wp_getPostStatusList( $args ) {
1416 $this->escape( $args );
1417
1418 $blog_id = (int) $args[0];
1419 $username = $args[1];
1420 $password = $args[2];
1421
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1422 if ( !$user = $this->login($username, $password) ) {
3f90dc2 More informative error message when remote publishing is disabled. Don'...
ryan authored
1423 return $this->error;
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See #55...
westi authored
1424 }
1425
1426 if( !current_user_can( 'edit_posts' ) ) {
1427 return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
1428 }
1429
9f9769b Add some more actions to xmlrpc. Fixes #5686 props joesephscott.
westi authored
1430 do_action('xmlrpc_call', 'wp.getPostStatusList');
1431
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See #55...
westi authored
1432 return get_post_statuses( );
1433 }
1434
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
1435 /**
1436 * Retrieve page statuses.
1437 *
1438 * @since 2.5.0
1439 *
1440 * @param array $args Method parameters.
1441 * @return array
1442 */
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See #55...
westi authored
1443 function wp_getPageStatusList( $args ) {
1444 $this->escape( $args );
1445
1446 $blog_id = (int) $args[0];
1447 $username = $args[1];
1448 $password = $args[2];
1449
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1450 if ( !$user = $this->login($username, $password) ) {
3f90dc2 More informative error message when remote publishing is disabled. Don'...
ryan authored
1451 return $this->error;
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See #55...
westi authored
1452 }
1453
1454 if( !current_user_can( 'edit_posts' ) ) {
a33b080 Typo fix from rnt. fixes #5700
ryan authored
1455 return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See #55...
westi authored
1456 }
1457
9f9769b Add some more actions to xmlrpc. Fixes #5686 props joesephscott.
westi authored
1458 do_action('xmlrpc_call', 'wp.getPageStatusList');
1459
ac2d661 Add xmlrpc methods to discover the valid post and page statuses. See #55...
westi authored
1460 return get_page_statuses( );
1461 }
1462
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
1463 /**
1464 * Retrieve page templates.
1465 *
1466 * @since 2.6.0
1467 *
1468 * @param array $args Method parameters.
1469 * @return array
1470 */
5d69e51 Expose page template functionality via XML-RPC. Props josephscott. fixes...
ryan authored
1471 function wp_getPageTemplates( $args ) {
1472 $this->escape( $args );
1473
1474 $blog_id = (int) $args[0];
1475 $username = $args[1];
1476 $password = $args[2];
1477
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1478 if ( !$user = $this->login($username, $password) ) {
3f90dc2 More informative error message when remote publishing is disabled. Don'...
ryan authored
1479 return $this->error;
5d69e51 Expose page template functionality via XML-RPC. Props josephscott. fixes...
ryan authored
1480 }
1481
1482 if( !current_user_can( 'edit_pages' ) ) {
1483 return new IXR_Error( 403, __( 'You are not allowed access to details about this blog.' ) );
1484 }
1485
1486 $templates = get_page_templates( );
1487 $templates['Default'] = 'default';
1488
1489 return $templates;
1490 }
1491
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
1492 /**
1493 * Retrieve blog options.
1494 *
1495 * @since 2.6.0
1496 *
1497 * @param array $args Method parameters.
1498 * @return array
1499 */
c678502 Add XMLRPC options api. See #7123 props josephscott.
westi authored
1500 function wp_getOptions( $args ) {
1501 $this->escape( $args );
1502
1503 $blog_id = (int) $args[0];
1504 $username = $args[1];
1505 $password = $args[2];
1506 $options = (array) $args[3];
1507
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1508 if ( !$user = $this->login($username, $password) ) {
3f90dc2 More informative error message when remote publishing is disabled. Don'...
ryan authored
1509 return $this->error;
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored
1510 }
c678502 Add XMLRPC options api. See #7123 props josephscott.
westi authored
1511
1512 // If no specific options where asked for, return all of them
1513 if (count( $options ) == 0 ) {
1514 $options = array_keys($this->blog_options);
1515 }
1516
1517 return $this->_getOptions($options);
1518 }
1519
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
1520 /**
1521 * Retrieve blog options value from list.
1522 *
1523 * @since 2.6.0
1524 *
1525 * @param array $options Options to retrieve.
1526 * @return array
1527 */
c678502 Add XMLRPC options api. See #7123 props josephscott.
westi authored
1528 function _getOptions($options)
1529 {
1530 $data = array( );
1531 foreach( $options as $option ) {
1532 if( array_key_exists( $option, $this->blog_options ) )
1533 {
1534 $data[$option] = $this->blog_options[$option];
1535 //Is the value static or dynamic?
1536 if( isset( $data[$option]['option'] ) ) {
1537 $data[$option]['value'] = get_option( $data[$option]['option'] );
1538 unset($data[$option]['option']);
1539 }
1540 }
1541 }
1542
1543 return $data;
1544 }
1545
eb3e916 Completion and fixes for wp-app, wp-login and xmlrpc inline documentatio...
azaozz authored
1546 /**
1547 * Update blog options.
1548 *
1549 * @since 2.6.0
1550 *
1551 * @param array $args Method parameters.
1552 * @return unknown
1553 */
c678502 Add XMLRPC options api. See #7123 props josephscott.
westi authored
1554 function wp_setOptions( $args ) {
1555 $this->escape( $args );
1556
1557 $blog_id = (int) $args[0];
1558 $username = $args[1];
1559 $password = $args[2];
1560 $options = (array) $args[3];
1561
9ef3298 Use user returned from auth for XML-RPC logins. Props wnorris. fixes #8...
ryan authored