63 'wp.getTags' => 'this:wp_getTags', |
73 'wp.getTags' => 'this:wp_getTags', |
64 'wp.newCategory' => 'this:wp_newCategory', |
74 'wp.newCategory' => 'this:wp_newCategory', |
65 'wp.deleteCategory' => 'this:wp_deleteCategory', |
75 'wp.deleteCategory' => 'this:wp_deleteCategory', |
66 'wp.suggestCategories' => 'this:wp_suggestCategories', |
76 'wp.suggestCategories' => 'this:wp_suggestCategories', |
67 'wp.uploadFile' => 'this:mw_newMediaObject', // Alias |
77 'wp.uploadFile' => 'this:mw_newMediaObject', // Alias |
|
78 'wp.deleteFile' => 'this:wp_deletePost', // Alias |
68 'wp.getCommentCount' => 'this:wp_getCommentCount', |
79 'wp.getCommentCount' => 'this:wp_getCommentCount', |
69 'wp.getPostStatusList' => 'this:wp_getPostStatusList', |
80 'wp.getPostStatusList' => 'this:wp_getPostStatusList', |
70 'wp.getPageStatusList' => 'this:wp_getPageStatusList', |
81 'wp.getPageStatusList' => 'this:wp_getPageStatusList', |
71 'wp.getPageTemplates' => 'this:wp_getPageTemplates', |
82 'wp.getPageTemplates' => 'this:wp_getPageTemplates', |
72 'wp.getOptions' => 'this:wp_getOptions', |
83 'wp.getOptions' => 'this:wp_getOptions', |
164 * |
202 * |
165 * @since 2.8.0 |
203 * @since 2.8.0 |
166 * |
204 * |
167 * @param string $username User's username. |
205 * @param string $username User's username. |
168 * @param string $password User's password. |
206 * @param string $password User's password. |
169 * @return mixed WP_User object if authentication passed, false otherwise |
207 * @return WP_User|bool WP_User object if authentication passed, false otherwise |
170 */ |
208 */ |
171 function login( $username, $password ) { |
209 public function login( $username, $password ) { |
172 // Respect any old filters against get_option() for 'enable_xmlrpc'. |
210 /* |
173 $enabled = apply_filters( 'pre_option_enable_xmlrpc', false ); // Deprecated |
211 * Respect old get_option() filters left for back-compat when the 'enable_xmlrpc' |
174 if ( false === $enabled ) |
212 * option was deprecated in 3.5.0. Use the 'xmlrpc_enabled' hook instead. |
175 $enabled = apply_filters( 'option_enable_xmlrpc', true ); // Deprecated |
213 */ |
176 |
214 $enabled = apply_filters( 'pre_option_enable_xmlrpc', false ); |
177 // Proper filter for turning off XML-RPC. It is on by default. |
215 if ( false === $enabled ) { |
|
216 $enabled = apply_filters( 'option_enable_xmlrpc', true ); |
|
217 } |
|
218 |
|
219 /** |
|
220 * Filter whether XML-RPC is enabled. |
|
221 * |
|
222 * This is the proper filter for turning off XML-RPC. |
|
223 * |
|
224 * @since 3.5.0 |
|
225 * |
|
226 * @param bool $enabled Whether XML-RPC is enabled. Default true. |
|
227 */ |
178 $enabled = apply_filters( 'xmlrpc_enabled', $enabled ); |
228 $enabled = apply_filters( 'xmlrpc_enabled', $enabled ); |
179 |
229 |
180 if ( ! $enabled ) { |
230 if ( ! $enabled ) { |
181 $this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site.' ) ) ); |
231 $this->error = new IXR_Error( 405, sprintf( __( 'XML-RPC services are disabled on this site.' ) ) ); |
182 return false; |
232 return false; |
853 * @param object $comment The unprepared comment data |
982 * @param object $comment The unprepared comment data |
854 * @return array The prepared comment data |
983 * @return array The prepared comment data |
855 */ |
984 */ |
856 protected function _prepare_comment( $comment ) { |
985 protected function _prepare_comment( $comment ) { |
857 // Format page date. |
986 // Format page date. |
858 $comment_date = $this->_convert_date( $comment->comment_date ); |
|
859 $comment_date_gmt = $this->_convert_date_gmt( $comment->comment_date_gmt, $comment->comment_date ); |
987 $comment_date_gmt = $this->_convert_date_gmt( $comment->comment_date_gmt, $comment->comment_date ); |
860 |
988 |
861 if ( '0' == $comment->comment_approved ) |
989 if ( '0' == $comment->comment_approved ) { |
862 $comment_status = 'hold'; |
990 $comment_status = 'hold'; |
863 else if ( 'spam' == $comment->comment_approved ) |
991 } elseif ( 'spam' == $comment->comment_approved ) { |
864 $comment_status = 'spam'; |
992 $comment_status = 'spam'; |
865 else if ( '1' == $comment->comment_approved ) |
993 } elseif ( '1' == $comment->comment_approved ) { |
866 $comment_status = 'approve'; |
994 $comment_status = 'approve'; |
867 else |
995 } else { |
868 $comment_status = $comment->comment_approved; |
996 $comment_status = $comment->comment_approved; |
869 |
997 } |
870 $_comment = array( |
998 $_comment = array( |
871 'date_created_gmt' => $comment_date_gmt, |
999 'date_created_gmt' => $comment_date_gmt, |
872 'user_id' => $comment->user_id, |
1000 'user_id' => $comment->user_id, |
873 'comment_id' => $comment->comment_ID, |
1001 'comment_id' => $comment->comment_ID, |
874 'parent' => $comment->comment_parent, |
1002 'parent' => $comment->comment_parent, |
954 * - custom_fields - array, with each element containing 'key' and 'value' |
1099 * - custom_fields - array, with each element containing 'key' and 'value' |
955 * - terms - array, with taxonomy names as keys and arrays of term IDs as values |
1100 * - terms - array, with taxonomy names as keys and arrays of term IDs as values |
956 * - terms_names - array, with taxonomy names as keys and arrays of term names as values |
1101 * - terms_names - array, with taxonomy names as keys and arrays of term names as values |
957 * - enclosure |
1102 * - enclosure |
958 * - any other fields supported by wp_insert_post() |
1103 * - any other fields supported by wp_insert_post() |
959 * @return string post_id |
1104 * @return string|IXR_Error post_id |
960 */ |
1105 */ |
961 function wp_newPost( $args ) { |
1106 public function wp_newPost( $args ) { |
962 if ( ! $this->minimum_args( $args, 4 ) ) |
1107 if ( ! $this->minimum_args( $args, 4 ) ) |
963 return $this->error; |
1108 return $this->error; |
964 |
1109 |
965 $this->escape( $args ); |
1110 $this->escape( $args ); |
966 |
1111 |
967 $blog_id = (int) $args[0]; |
|
968 $username = $args[1]; |
1112 $username = $args[1]; |
969 $password = $args[2]; |
1113 $password = $args[2]; |
970 $content_struct = $args[3]; |
1114 $content_struct = $args[3]; |
971 |
1115 |
972 if ( ! $user = $this->login( $username, $password ) ) |
1116 if ( ! $user = $this->login( $username, $password ) ) |
973 return $this->error; |
1117 return $this->error; |
974 |
1118 |
|
1119 // convert the date field back to IXR form |
|
1120 if ( isset( $content_struct['post_date'] ) && ! ( $content_struct['post_date'] instanceof IXR_Date ) ) { |
|
1121 $content_struct['post_date'] = $this->_convert_date( $content_struct['post_date'] ); |
|
1122 } |
|
1123 |
|
1124 // ignore the existing GMT date if it is empty or a non-GMT date was supplied in $content_struct, |
|
1125 // since _insert_post will ignore the non-GMT date if the GMT date is set |
|
1126 if ( isset( $content_struct['post_date_gmt'] ) && ! ( $content_struct['post_date_gmt'] instanceof IXR_Date ) ) { |
|
1127 if ( $content_struct['post_date_gmt'] == '0000-00-00 00:00:00' || isset( $content_struct['post_date'] ) ) { |
|
1128 unset( $content_struct['post_date_gmt'] ); |
|
1129 } else { |
|
1130 $content_struct['post_date_gmt'] = $this->_convert_date( $content_struct['post_date_gmt'] ); |
|
1131 } |
|
1132 } |
|
1133 |
|
1134 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
975 do_action( 'xmlrpc_call', 'wp.newPost' ); |
1135 do_action( 'xmlrpc_call', 'wp.newPost' ); |
976 |
1136 |
977 unset( $content_struct['ID'] ); |
1137 unset( $content_struct['ID'] ); |
978 |
1138 |
979 return $this->_insert_post( $user, $content_struct ); |
1139 return $this->_insert_post( $user, $content_struct ); |
1233 * should be changed. All other fields will retain their existing values. |
1402 * should be changed. All other fields will retain their existing values. |
1234 * |
1403 * |
1235 * @since 3.4.0 |
1404 * @since 3.4.0 |
1236 * |
1405 * |
1237 * @param array $args Method parameters. Contains: |
1406 * @param array $args Method parameters. Contains: |
1238 * - int $blog_id |
1407 * - int $blog_id (unused) |
1239 * - string $username |
1408 * - string $username |
1240 * - string $password |
1409 * - string $password |
1241 * - int $post_id |
1410 * - int $post_id |
1242 * - array $content_struct |
1411 * - array $content_struct |
1243 * @return true on success |
1412 * @return bool|IXR_Error true on success |
1244 */ |
1413 */ |
1245 function wp_editPost( $args ) { |
1414 public function wp_editPost( $args ) { |
1246 if ( ! $this->minimum_args( $args, 5 ) ) |
1415 if ( ! $this->minimum_args( $args, 5 ) ) |
1247 return $this->error; |
1416 return $this->error; |
1248 |
1417 |
1249 $this->escape( $args ); |
1418 $this->escape( $args ); |
1250 |
1419 |
1251 $blog_id = (int) $args[0]; |
|
1252 $username = $args[1]; |
1420 $username = $args[1]; |
1253 $password = $args[2]; |
1421 $password = $args[2]; |
1254 $post_id = (int) $args[3]; |
1422 $post_id = (int) $args[3]; |
1255 $content_struct = $args[4]; |
1423 $content_struct = $args[4]; |
1256 |
1424 |
1257 if ( ! $user = $this->login( $username, $password ) ) |
1425 if ( ! $user = $this->login( $username, $password ) ) |
1258 return $this->error; |
1426 return $this->error; |
1259 |
1427 |
|
1428 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1260 do_action( 'xmlrpc_call', 'wp.editPost' ); |
1429 do_action( 'xmlrpc_call', 'wp.editPost' ); |
1261 |
1430 |
1262 $post = get_post( $post_id, ARRAY_A ); |
1431 $post = get_post( $post_id, ARRAY_A ); |
1263 |
1432 |
1264 if ( empty( $post['ID'] ) ) |
1433 if ( empty( $post['ID'] ) ) |
1296 * |
1465 * |
1297 * @since 3.4.0 |
1466 * @since 3.4.0 |
1298 * |
1467 * |
1299 * @uses wp_delete_post() |
1468 * @uses wp_delete_post() |
1300 * @param array $args Method parameters. Contains: |
1469 * @param array $args Method parameters. Contains: |
1301 * - int $blog_id |
1470 * - int $blog_id (unused) |
1302 * - string $username |
1471 * - string $username |
1303 * - string $password |
1472 * - string $password |
1304 * - int $post_id |
1473 * - int $post_id |
1305 * @return true on success |
1474 * @return bool|IXR_Error true on success |
1306 */ |
1475 */ |
1307 function wp_deletePost( $args ) { |
1476 public function wp_deletePost( $args ) { |
1308 if ( ! $this->minimum_args( $args, 4 ) ) |
1477 if ( ! $this->minimum_args( $args, 4 ) ) |
1309 return $this->error; |
1478 return $this->error; |
1310 |
1479 |
1311 $this->escape( $args ); |
1480 $this->escape( $args ); |
1312 |
1481 |
1313 $blog_id = (int) $args[0]; |
|
1314 $username = $args[1]; |
1482 $username = $args[1]; |
1315 $password = $args[2]; |
1483 $password = $args[2]; |
1316 $post_id = (int) $args[3]; |
1484 $post_id = (int) $args[3]; |
1317 |
1485 |
1318 if ( ! $user = $this->login( $username, $password ) ) |
1486 if ( ! $user = $this->login( $username, $password ) ) |
1319 return $this->error; |
1487 return $this->error; |
1320 |
1488 |
|
1489 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1321 do_action( 'xmlrpc_call', 'wp.deletePost' ); |
1490 do_action( 'xmlrpc_call', 'wp.deletePost' ); |
1322 |
1491 |
1323 $post = get_post( $post_id, ARRAY_A ); |
1492 $post = get_post( $post_id, ARRAY_A ); |
1324 if ( empty( $post['ID'] ) ) |
1493 if ( empty( $post['ID'] ) ) |
1325 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
1494 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
1377 * - 'terms' |
1547 * - 'terms' |
1378 * - 'categories' |
1548 * - 'categories' |
1379 * - 'tags' |
1549 * - 'tags' |
1380 * - 'enclosure' |
1550 * - 'enclosure' |
1381 */ |
1551 */ |
1382 function wp_getPost( $args ) { |
1552 public function wp_getPost( $args ) { |
1383 if ( ! $this->minimum_args( $args, 4 ) ) |
1553 if ( ! $this->minimum_args( $args, 4 ) ) |
1384 return $this->error; |
1554 return $this->error; |
1385 |
1555 |
1386 $this->escape( $args ); |
1556 $this->escape( $args ); |
1387 |
1557 |
1388 $blog_id = (int) $args[0]; |
|
1389 $username = $args[1]; |
1558 $username = $args[1]; |
1390 $password = $args[2]; |
1559 $password = $args[2]; |
1391 $post_id = (int) $args[3]; |
1560 $post_id = (int) $args[3]; |
1392 |
1561 |
1393 if ( isset( $args[4] ) ) |
1562 if ( isset( $args[4] ) ) { |
1394 $fields = $args[4]; |
1563 $fields = $args[4]; |
1395 else |
1564 } else { |
|
1565 /** |
|
1566 * Filter the list of post query fields used by the given XML-RPC method. |
|
1567 * |
|
1568 * @since 3.4.0 |
|
1569 * |
|
1570 * @param array $fields Array of post fields. |
|
1571 * @param string $method Method name. |
|
1572 */ |
1396 $fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPost' ); |
1573 $fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPost' ); |
|
1574 } |
1397 |
1575 |
1398 if ( ! $user = $this->login( $username, $password ) ) |
1576 if ( ! $user = $this->login( $username, $password ) ) |
1399 return $this->error; |
1577 return $this->error; |
1400 |
1578 |
|
1579 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1401 do_action( 'xmlrpc_call', 'wp.getPost' ); |
1580 do_action( 'xmlrpc_call', 'wp.getPost' ); |
1402 |
1581 |
1403 $post = get_post( $post_id, ARRAY_A ); |
1582 $post = get_post( $post_id, ARRAY_A ); |
1404 |
1583 |
1405 if ( empty( $post['ID'] ) ) |
1584 if ( empty( $post['ID'] ) ) |
1426 * @uses wp_get_recent_posts() |
1605 * @uses wp_get_recent_posts() |
1427 * @see wp_getPost() for more on $fields |
1606 * @see wp_getPost() for more on $fields |
1428 * @see get_posts() for more on $filter values |
1607 * @see get_posts() for more on $filter values |
1429 * |
1608 * |
1430 * @param array $args Method parameters. Contains: |
1609 * @param array $args Method parameters. Contains: |
1431 * - int $blog_id |
1610 * - int $blog_id (unused) |
1432 * - string $username |
1611 * - string $username |
1433 * - string $password |
1612 * - string $password |
1434 * - array $filter optional |
1613 * - array $filter optional |
1435 * - array $fields optional |
1614 * - array $fields optional |
1436 * @return array contains a collection of posts. |
1615 * @return array|IXR_Error Array contains a collection of posts. |
1437 */ |
1616 */ |
1438 function wp_getPosts( $args ) { |
1617 public function wp_getPosts( $args ) { |
1439 if ( ! $this->minimum_args( $args, 3 ) ) |
1618 if ( ! $this->minimum_args( $args, 3 ) ) |
1440 return $this->error; |
1619 return $this->error; |
1441 |
1620 |
1442 $this->escape( $args ); |
1621 $this->escape( $args ); |
1443 |
1622 |
1444 $blog_id = (int) $args[0]; |
|
1445 $username = $args[1]; |
1623 $username = $args[1]; |
1446 $password = $args[2]; |
1624 $password = $args[2]; |
1447 $filter = isset( $args[3] ) ? $args[3] : array(); |
1625 $filter = isset( $args[3] ) ? $args[3] : array(); |
1448 |
1626 |
1449 if ( isset( $args[4] ) ) |
1627 if ( isset( $args[4] ) ) { |
1450 $fields = $args[4]; |
1628 $fields = $args[4]; |
1451 else |
1629 } else { |
|
1630 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1452 $fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPosts' ); |
1631 $fields = apply_filters( 'xmlrpc_default_post_fields', array( 'post', 'terms', 'custom_fields' ), 'wp.getPosts' ); |
|
1632 } |
1453 |
1633 |
1454 if ( ! $user = $this->login( $username, $password ) ) |
1634 if ( ! $user = $this->login( $username, $password ) ) |
1455 return $this->error; |
1635 return $this->error; |
1456 |
1636 |
|
1637 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1457 do_action( 'xmlrpc_call', 'wp.getPosts' ); |
1638 do_action( 'xmlrpc_call', 'wp.getPosts' ); |
1458 |
1639 |
1459 $query = array(); |
1640 $query = array(); |
1460 |
1641 |
1461 if ( isset( $filter['post_type'] ) ) { |
1642 if ( isset( $filter['post_type'] ) ) { |
1514 * |
1695 * |
1515 * @since 3.4.0 |
1696 * @since 3.4.0 |
1516 * |
1697 * |
1517 * @uses wp_insert_term() |
1698 * @uses wp_insert_term() |
1518 * @param array $args Method parameters. Contains: |
1699 * @param array $args Method parameters. Contains: |
1519 * - int $blog_id |
1700 * - int $blog_id (unused) |
1520 * - string $username |
1701 * - string $username |
1521 * - string $password |
1702 * - string $password |
1522 * - array $content_struct |
1703 * - array $content_struct |
1523 * The $content_struct must contain: |
1704 * The $content_struct must contain: |
1524 * - 'name' |
1705 * - 'name' |
1525 * - 'taxonomy' |
1706 * - 'taxonomy' |
1526 * Also, it can optionally contain: |
1707 * Also, it can optionally contain: |
1527 * - 'parent' |
1708 * - 'parent' |
1528 * - 'description' |
1709 * - 'description' |
1529 * - 'slug' |
1710 * - 'slug' |
1530 * @return string term_id |
1711 * @return string|IXR_Error term_id |
1531 */ |
1712 */ |
1532 function wp_newTerm( $args ) { |
1713 public function wp_newTerm( $args ) { |
1533 if ( ! $this->minimum_args( $args, 4 ) ) |
1714 if ( ! $this->minimum_args( $args, 4 ) ) |
1534 return $this->error; |
1715 return $this->error; |
1535 |
1716 |
1536 $this->escape( $args ); |
1717 $this->escape( $args ); |
1537 |
1718 |
1538 $blog_id = (int) $args[0]; |
|
1539 $username = $args[1]; |
1719 $username = $args[1]; |
1540 $password = $args[2]; |
1720 $password = $args[2]; |
1541 $content_struct = $args[3]; |
1721 $content_struct = $args[3]; |
1542 |
1722 |
1543 if ( ! $user = $this->login( $username, $password ) ) |
1723 if ( ! $user = $this->login( $username, $password ) ) |
1544 return $this->error; |
1724 return $this->error; |
1545 |
1725 |
|
1726 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1546 do_action( 'xmlrpc_call', 'wp.newTerm' ); |
1727 do_action( 'xmlrpc_call', 'wp.newTerm' ); |
1547 |
1728 |
1548 if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) |
1729 if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) |
1549 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
1730 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
1550 |
1731 |
1612 * Also, it can optionally contain: |
1793 * Also, it can optionally contain: |
1613 * - 'name' |
1794 * - 'name' |
1614 * - 'parent' |
1795 * - 'parent' |
1615 * - 'description' |
1796 * - 'description' |
1616 * - 'slug' |
1797 * - 'slug' |
1617 * @return bool True, on success. |
1798 * @return bool|IXR_Error True, on success. |
1618 */ |
1799 */ |
1619 function wp_editTerm( $args ) { |
1800 public function wp_editTerm( $args ) { |
1620 if ( ! $this->minimum_args( $args, 5 ) ) |
1801 if ( ! $this->minimum_args( $args, 5 ) ) |
1621 return $this->error; |
1802 return $this->error; |
1622 |
1803 |
1623 $this->escape( $args ); |
1804 $this->escape( $args ); |
1624 |
1805 |
1625 $blog_id = (int) $args[0]; |
|
1626 $username = $args[1]; |
1806 $username = $args[1]; |
1627 $password = $args[2]; |
1807 $password = $args[2]; |
1628 $term_id = (int) $args[3]; |
1808 $term_id = (int) $args[3]; |
1629 $content_struct = $args[4]; |
1809 $content_struct = $args[4]; |
1630 |
1810 |
1631 if ( ! $user = $this->login( $username, $password ) ) |
1811 if ( ! $user = $this->login( $username, $password ) ) |
1632 return $this->error; |
1812 return $this->error; |
1633 |
1813 |
|
1814 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1634 do_action( 'xmlrpc_call', 'wp.editTerm' ); |
1815 do_action( 'xmlrpc_call', 'wp.editTerm' ); |
1635 |
1816 |
1636 if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) |
1817 if ( ! taxonomy_exists( $content_struct['taxonomy'] ) ) |
1637 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
1818 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
1638 |
1819 |
1699 * |
1880 * |
1700 * @since 3.4.0 |
1881 * @since 3.4.0 |
1701 * |
1882 * |
1702 * @uses wp_delete_term() |
1883 * @uses wp_delete_term() |
1703 * @param array $args Method parameters. Contains: |
1884 * @param array $args Method parameters. Contains: |
1704 * - int $blog_id |
1885 * - int $blog_id (unused) |
1705 * - string $username |
1886 * - string $username |
1706 * - string $password |
1887 * - string $password |
1707 * - string $taxnomy_name |
1888 * - string $taxnomy_name |
1708 * - string $term_id |
1889 * - string $term_id |
1709 * @return boolean|IXR_Error If it suceeded true else a reason why not |
1890 * @return boolean|IXR_Error If it suceeded true else a reason why not |
1710 */ |
1891 */ |
1711 function wp_deleteTerm( $args ) { |
1892 public function wp_deleteTerm( $args ) { |
1712 if ( ! $this->minimum_args( $args, 5 ) ) |
1893 if ( ! $this->minimum_args( $args, 5 ) ) |
1713 return $this->error; |
1894 return $this->error; |
1714 |
1895 |
1715 $this->escape( $args ); |
1896 $this->escape( $args ); |
1716 |
1897 |
1717 $blog_id = (int) $args[0]; |
|
1718 $username = $args[1]; |
1898 $username = $args[1]; |
1719 $password = $args[2]; |
1899 $password = $args[2]; |
1720 $taxonomy = $args[3]; |
1900 $taxonomy = $args[3]; |
1721 $term_id = (int) $args[4]; |
1901 $term_id = (int) $args[4]; |
1722 |
1902 |
1723 if ( ! $user = $this->login( $username, $password ) ) |
1903 if ( ! $user = $this->login( $username, $password ) ) |
1724 return $this->error; |
1904 return $this->error; |
1725 |
1905 |
|
1906 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1726 do_action( 'xmlrpc_call', 'wp.deleteTerm' ); |
1907 do_action( 'xmlrpc_call', 'wp.deleteTerm' ); |
1727 |
1908 |
1728 if ( ! taxonomy_exists( $taxonomy ) ) |
1909 if ( ! taxonomy_exists( $taxonomy ) ) |
1729 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
1910 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
1730 |
1911 |
1757 * |
1938 * |
1758 * @since 3.4.0 |
1939 * @since 3.4.0 |
1759 * |
1940 * |
1760 * @uses get_term() |
1941 * @uses get_term() |
1761 * @param array $args Method parameters. Contains: |
1942 * @param array $args Method parameters. Contains: |
1762 * - int $blog_id |
1943 * - int $blog_id (unused) |
1763 * - string $username |
1944 * - string $username |
1764 * - string $password |
1945 * - string $password |
1765 * - string $taxonomy |
1946 * - string $taxonomy |
1766 * - string $term_id |
1947 * - string $term_id |
1767 * @return array contains: |
1948 * @return array|IXR_Error Array contains: |
1768 * - 'term_id' |
1949 * - 'term_id' |
1769 * - 'name' |
1950 * - 'name' |
1770 * - 'slug' |
1951 * - 'slug' |
1771 * - 'term_group' |
1952 * - 'term_group' |
1772 * - 'term_taxonomy_id' |
1953 * - 'term_taxonomy_id' |
1773 * - 'taxonomy' |
1954 * - 'taxonomy' |
1774 * - 'description' |
1955 * - 'description' |
1775 * - 'parent' |
1956 * - 'parent' |
1776 * - 'count' |
1957 * - 'count' |
1777 */ |
1958 */ |
1778 function wp_getTerm( $args ) { |
1959 public function wp_getTerm( $args ) { |
1779 if ( ! $this->minimum_args( $args, 5 ) ) |
1960 if ( ! $this->minimum_args( $args, 5 ) ) |
1780 return $this->error; |
1961 return $this->error; |
1781 |
1962 |
1782 $this->escape( $args ); |
1963 $this->escape( $args ); |
1783 |
1964 |
1784 $blog_id = (int) $args[0]; |
|
1785 $username = $args[1]; |
1965 $username = $args[1]; |
1786 $password = $args[2]; |
1966 $password = $args[2]; |
1787 $taxonomy = $args[3]; |
1967 $taxonomy = $args[3]; |
1788 $term_id = (int) $args[4]; |
1968 $term_id = (int) $args[4]; |
1789 |
1969 |
1790 if ( ! $user = $this->login( $username, $password ) ) |
1970 if ( ! $user = $this->login( $username, $password ) ) |
1791 return $this->error; |
1971 return $this->error; |
1792 |
1972 |
|
1973 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1793 do_action( 'xmlrpc_call', 'wp.getTerm' ); |
1974 do_action( 'xmlrpc_call', 'wp.getTerm' ); |
1794 |
1975 |
1795 if ( ! taxonomy_exists( $taxonomy ) ) |
1976 if ( ! taxonomy_exists( $taxonomy ) ) |
1796 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
1977 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
1797 |
1978 |
1819 * The optional $filter parameter modifies the query used to retrieve terms. |
2000 * The optional $filter parameter modifies the query used to retrieve terms. |
1820 * Accepted keys are 'number', 'offset', 'orderby', 'order', 'hide_empty', and 'search'. |
2001 * Accepted keys are 'number', 'offset', 'orderby', 'order', 'hide_empty', and 'search'. |
1821 * |
2002 * |
1822 * @uses get_terms() |
2003 * @uses get_terms() |
1823 * @param array $args Method parameters. Contains: |
2004 * @param array $args Method parameters. Contains: |
1824 * - int $blog_id |
2005 * - int $blog_id (unused) |
1825 * - string $username |
2006 * - string $username |
1826 * - string $password |
2007 * - string $password |
1827 * - string $taxonomy |
2008 * - string $taxonomy |
1828 * - array $filter optional |
2009 * - array $filter optional |
1829 * @return array terms |
2010 * @return array|IXR_Error terms |
1830 */ |
2011 */ |
1831 function wp_getTerms( $args ) { |
2012 public function wp_getTerms( $args ) { |
1832 if ( ! $this->minimum_args( $args, 4 ) ) |
2013 if ( ! $this->minimum_args( $args, 4 ) ) |
1833 return $this->error; |
2014 return $this->error; |
1834 |
2015 |
1835 $this->escape( $args ); |
2016 $this->escape( $args ); |
1836 |
2017 |
1837 $blog_id = (int) $args[0]; |
|
1838 $username = $args[1]; |
2018 $username = $args[1]; |
1839 $password = $args[2]; |
2019 $password = $args[2]; |
1840 $taxonomy = $args[3]; |
2020 $taxonomy = $args[3]; |
1841 $filter = isset( $args[4] ) ? $args[4] : array(); |
2021 $filter = isset( $args[4] ) ? $args[4] : array(); |
1842 |
2022 |
1843 if ( ! $user = $this->login( $username, $password ) ) |
2023 if ( ! $user = $this->login( $username, $password ) ) |
1844 return $this->error; |
2024 return $this->error; |
1845 |
2025 |
|
2026 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1846 do_action( 'xmlrpc_call', 'wp.getTerms' ); |
2027 do_action( 'xmlrpc_call', 'wp.getTerms' ); |
1847 |
2028 |
1848 if ( ! taxonomy_exists( $taxonomy ) ) |
2029 if ( ! taxonomy_exists( $taxonomy ) ) |
1849 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
2030 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
1850 |
2031 |
1895 * |
2076 * |
1896 * @since 3.4.0 |
2077 * @since 3.4.0 |
1897 * |
2078 * |
1898 * @uses get_taxonomy() |
2079 * @uses get_taxonomy() |
1899 * @param array $args Method parameters. Contains: |
2080 * @param array $args Method parameters. Contains: |
1900 * - int $blog_id |
2081 * - int $blog_id (unused) |
1901 * - string $username |
2082 * - string $username |
1902 * - string $password |
2083 * - string $password |
1903 * - string $taxonomy |
2084 * - string $taxonomy |
1904 * @return array (@see get_taxonomy()) |
2085 * @return array|IXR_Error (@see get_taxonomy()) |
1905 */ |
2086 */ |
1906 function wp_getTaxonomy( $args ) { |
2087 public function wp_getTaxonomy( $args ) { |
1907 if ( ! $this->minimum_args( $args, 4 ) ) |
2088 if ( ! $this->minimum_args( $args, 4 ) ) |
1908 return $this->error; |
2089 return $this->error; |
1909 |
2090 |
1910 $this->escape( $args ); |
2091 $this->escape( $args ); |
1911 |
2092 |
1912 $blog_id = (int) $args[0]; |
|
1913 $username = $args[1]; |
2093 $username = $args[1]; |
1914 $password = $args[2]; |
2094 $password = $args[2]; |
1915 $taxonomy = $args[3]; |
2095 $taxonomy = $args[3]; |
1916 |
2096 |
1917 if ( isset( $args[4] ) ) |
2097 if ( isset( $args[4] ) ) { |
1918 $fields = $args[4]; |
2098 $fields = $args[4]; |
1919 else |
2099 } else { |
|
2100 /** |
|
2101 * Filter the taxonomy query fields used by the given XML-RPC method. |
|
2102 * |
|
2103 * @since 3.4.0 |
|
2104 * |
|
2105 * @param array $fields An array of taxonomy fields to retrieve. |
|
2106 * @param string $method The method name. |
|
2107 */ |
1920 $fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomy' ); |
2108 $fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomy' ); |
|
2109 } |
1921 |
2110 |
1922 if ( ! $user = $this->login( $username, $password ) ) |
2111 if ( ! $user = $this->login( $username, $password ) ) |
1923 return $this->error; |
2112 return $this->error; |
1924 |
2113 |
|
2114 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1925 do_action( 'xmlrpc_call', 'wp.getTaxonomy' ); |
2115 do_action( 'xmlrpc_call', 'wp.getTaxonomy' ); |
1926 |
2116 |
1927 if ( ! taxonomy_exists( $taxonomy ) ) |
2117 if ( ! taxonomy_exists( $taxonomy ) ) |
1928 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
2118 return new IXR_Error( 403, __( 'Invalid taxonomy' ) ); |
1929 |
2119 |
1940 * |
2130 * |
1941 * @since 3.4.0 |
2131 * @since 3.4.0 |
1942 * |
2132 * |
1943 * @uses get_taxonomies() |
2133 * @uses get_taxonomies() |
1944 * @param array $args Method parameters. Contains: |
2134 * @param array $args Method parameters. Contains: |
1945 * - int $blog_id |
2135 * - int $blog_id (unused) |
1946 * - string $username |
2136 * - string $username |
1947 * - string $password |
2137 * - string $password |
1948 * @return array taxonomies |
2138 * @return array taxonomies |
1949 */ |
2139 */ |
1950 function wp_getTaxonomies( $args ) { |
2140 public function wp_getTaxonomies( $args ) { |
1951 if ( ! $this->minimum_args( $args, 3 ) ) |
2141 if ( ! $this->minimum_args( $args, 3 ) ) |
1952 return $this->error; |
2142 return $this->error; |
1953 |
2143 |
1954 $this->escape( $args ); |
2144 $this->escape( $args ); |
1955 |
2145 |
1956 $blog_id = (int) $args[0]; |
|
1957 $username = $args[1]; |
2146 $username = $args[1]; |
1958 $password = $args[2]; |
2147 $password = $args[2]; |
1959 $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
2148 $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
1960 |
2149 |
1961 if ( isset( $args[4] ) ) |
2150 if ( isset( $args[4] ) ) { |
1962 $fields = $args[4]; |
2151 $fields = $args[4]; |
1963 else |
2152 } else { |
|
2153 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1964 $fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomies' ); |
2154 $fields = apply_filters( 'xmlrpc_default_taxonomy_fields', array( 'labels', 'cap', 'object_type' ), 'wp.getTaxonomies' ); |
|
2155 } |
1965 |
2156 |
1966 if ( ! $user = $this->login( $username, $password ) ) |
2157 if ( ! $user = $this->login( $username, $password ) ) |
1967 return $this->error; |
2158 return $this->error; |
1968 |
2159 |
|
2160 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
1969 do_action( 'xmlrpc_call', 'wp.getTaxonomies' ); |
2161 do_action( 'xmlrpc_call', 'wp.getTaxonomies' ); |
1970 |
2162 |
1971 $taxonomies = get_taxonomies( $filter, 'objects' ); |
2163 $taxonomies = get_taxonomies( $filter, 'objects' ); |
1972 |
2164 |
1973 // holds all the taxonomy data |
2165 // holds all the taxonomy data |
2014 * - 'nicename' |
2206 * - 'nicename' |
2015 * - 'url' |
2207 * - 'url' |
2016 * - 'display_name' |
2208 * - 'display_name' |
2017 * - 'roles' |
2209 * - 'roles' |
2018 */ |
2210 */ |
2019 function wp_getUser( $args ) { |
2211 public function wp_getUser( $args ) { |
2020 if ( ! $this->minimum_args( $args, 4 ) ) |
2212 if ( ! $this->minimum_args( $args, 4 ) ) |
2021 return $this->error; |
2213 return $this->error; |
2022 |
2214 |
2023 $this->escape( $args ); |
2215 $this->escape( $args ); |
2024 |
2216 |
2025 $blog_id = (int) $args[0]; |
|
2026 $username = $args[1]; |
2217 $username = $args[1]; |
2027 $password = $args[2]; |
2218 $password = $args[2]; |
2028 $user_id = (int) $args[3]; |
2219 $user_id = (int) $args[3]; |
2029 |
2220 |
2030 if ( isset( $args[4] ) ) |
2221 if ( isset( $args[4] ) ) { |
2031 $fields = $args[4]; |
2222 $fields = $args[4]; |
2032 else |
2223 } else { |
|
2224 /** |
|
2225 * Filter the default user query fields used by the given XML-RPC method. |
|
2226 * |
|
2227 * @since 3.5.0 |
|
2228 * |
|
2229 * @param array $fields User query fields for given method. Default 'all'. |
|
2230 * @param string $method The method name. |
|
2231 */ |
2033 $fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUser' ); |
2232 $fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUser' ); |
|
2233 } |
2034 |
2234 |
2035 if ( ! $user = $this->login( $username, $password ) ) |
2235 if ( ! $user = $this->login( $username, $password ) ) |
2036 return $this->error; |
2236 return $this->error; |
2037 |
2237 |
|
2238 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2038 do_action( 'xmlrpc_call', 'wp.getUser' ); |
2239 do_action( 'xmlrpc_call', 'wp.getUser' ); |
2039 |
2240 |
2040 if ( ! current_user_can( 'edit_user', $user_id ) ) |
2241 if ( ! current_user_can( 'edit_user', $user_id ) ) |
2041 return new IXR_Error( 401, __( 'Sorry, you cannot edit users.' ) ); |
2242 return new IXR_Error( 401, __( 'Sorry, you cannot edit users.' ) ); |
2042 |
2243 |
2060 * |
2261 * |
2061 * @uses get_users() |
2262 * @uses get_users() |
2062 * @see wp_getUser() for more on $fields and return values |
2263 * @see wp_getUser() for more on $fields and return values |
2063 * |
2264 * |
2064 * @param array $args Method parameters. Contains: |
2265 * @param array $args Method parameters. Contains: |
2065 * - int $blog_id |
2266 * - int $blog_id (unused) |
2066 * - string $username |
2267 * - string $username |
2067 * - string $password |
2268 * - string $password |
2068 * - array $filter optional |
2269 * - array $filter optional |
2069 * - array $fields optional |
2270 * - array $fields optional |
2070 * @return array users data |
2271 * @return array|IXR_Error users data |
2071 */ |
2272 */ |
2072 function wp_getUsers( $args ) { |
2273 public function wp_getUsers( $args ) { |
2073 if ( ! $this->minimum_args( $args, 3 ) ) |
2274 if ( ! $this->minimum_args( $args, 3 ) ) |
2074 return $this->error; |
2275 return $this->error; |
2075 |
2276 |
2076 $this->escape( $args ); |
2277 $this->escape( $args ); |
2077 |
2278 |
2078 $blog_id = (int) $args[0]; |
|
2079 $username = $args[1]; |
2279 $username = $args[1]; |
2080 $password = $args[2]; |
2280 $password = $args[2]; |
2081 $filter = isset( $args[3] ) ? $args[3] : array(); |
2281 $filter = isset( $args[3] ) ? $args[3] : array(); |
2082 |
2282 |
2083 if ( isset( $args[4] ) ) |
2283 if ( isset( $args[4] ) ) { |
2084 $fields = $args[4]; |
2284 $fields = $args[4]; |
2085 else |
2285 } else { |
|
2286 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2086 $fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUsers' ); |
2287 $fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getUsers' ); |
|
2288 } |
2087 |
2289 |
2088 if ( ! $user = $this->login( $username, $password ) ) |
2290 if ( ! $user = $this->login( $username, $password ) ) |
2089 return $this->error; |
2291 return $this->error; |
2090 |
2292 |
|
2293 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2091 do_action( 'xmlrpc_call', 'wp.getUsers' ); |
2294 do_action( 'xmlrpc_call', 'wp.getUsers' ); |
2092 |
2295 |
2093 if ( ! current_user_can( 'list_users' ) ) |
2296 if ( ! current_user_can( 'list_users' ) ) |
2094 return new IXR_Error( 401, __( 'Sorry, you cannot list users.' ) ); |
2297 return new IXR_Error( 401, __( 'Sorry, you cannot list users.' ) ); |
2095 |
2298 |
2129 /** |
2332 /** |
2130 * Retrieve information about the requesting user. |
2333 * Retrieve information about the requesting user. |
2131 * |
2334 * |
2132 * @uses get_userdata() |
2335 * @uses get_userdata() |
2133 * @param array $args Method parameters. Contains: |
2336 * @param array $args Method parameters. Contains: |
2134 * - int $blog_id |
2337 * - int $blog_id (unused) |
2135 * - string $username |
2338 * - string $username |
2136 * - string $password |
2339 * - string $password |
2137 * - array $fields optional |
2340 * - array $fields optional |
2138 * @return array (@see wp_getUser) |
2341 * @return array|IXR_Error (@see wp_getUser) |
2139 */ |
2342 */ |
2140 function wp_getProfile( $args ) { |
2343 public function wp_getProfile( $args ) { |
2141 if ( ! $this->minimum_args( $args, 3 ) ) |
2344 if ( ! $this->minimum_args( $args, 3 ) ) |
2142 return $this->error; |
2345 return $this->error; |
2143 |
2346 |
2144 $this->escape( $args ); |
2347 $this->escape( $args ); |
2145 |
2348 |
2146 $blog_id = (int) $args[0]; |
|
2147 $username = $args[1]; |
2349 $username = $args[1]; |
2148 $password = $args[2]; |
2350 $password = $args[2]; |
2149 |
2351 |
2150 if ( isset( $args[3] ) ) |
2352 if ( isset( $args[3] ) ) { |
2151 $fields = $args[3]; |
2353 $fields = $args[3]; |
2152 else |
2354 } else { |
|
2355 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2153 $fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getProfile' ); |
2356 $fields = apply_filters( 'xmlrpc_default_user_fields', array( 'all' ), 'wp.getProfile' ); |
|
2357 } |
2154 |
2358 |
2155 if ( ! $user = $this->login( $username, $password ) ) |
2359 if ( ! $user = $this->login( $username, $password ) ) |
2156 return $this->error; |
2360 return $this->error; |
2157 |
2361 |
|
2362 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2158 do_action( 'xmlrpc_call', 'wp.getProfile' ); |
2363 do_action( 'xmlrpc_call', 'wp.getProfile' ); |
2159 |
2364 |
2160 if ( ! current_user_can( 'edit_user', $user->ID ) ) |
2365 if ( ! current_user_can( 'edit_user', $user->ID ) ) |
2161 return new IXR_Error( 401, __( 'Sorry, you cannot edit your profile.' ) ); |
2366 return new IXR_Error( 401, __( 'Sorry, you cannot edit your profile.' ) ); |
2162 |
2367 |
2180 * - 'website' |
2385 * - 'website' |
2181 * - 'display_name' |
2386 * - 'display_name' |
2182 * - 'nickname' |
2387 * - 'nickname' |
2183 * - 'nicename' |
2388 * - 'nicename' |
2184 * - 'bio' |
2389 * - 'bio' |
2185 * @return bool True, on success. |
2390 * @return bool|IXR_Error True, on success. |
2186 */ |
2391 */ |
2187 function wp_editProfile( $args ) { |
2392 public function wp_editProfile( $args ) { |
2188 if ( ! $this->minimum_args( $args, 4 ) ) |
2393 if ( ! $this->minimum_args( $args, 4 ) ) |
2189 return $this->error; |
2394 return $this->error; |
2190 |
2395 |
2191 $this->escape( $args ); |
2396 $this->escape( $args ); |
2192 |
2397 |
2193 $blog_id = (int) $args[0]; |
|
2194 $username = $args[1]; |
2398 $username = $args[1]; |
2195 $password = $args[2]; |
2399 $password = $args[2]; |
2196 $content_struct = $args[3]; |
2400 $content_struct = $args[3]; |
2197 |
2401 |
2198 if ( ! $user = $this->login( $username, $password ) ) |
2402 if ( ! $user = $this->login( $username, $password ) ) |
2199 return $this->error; |
2403 return $this->error; |
2200 |
2404 |
|
2405 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2201 do_action( 'xmlrpc_call', 'wp.editProfile' ); |
2406 do_action( 'xmlrpc_call', 'wp.editProfile' ); |
2202 |
2407 |
2203 if ( ! current_user_can( 'edit_user', $user->ID ) ) |
2408 if ( ! current_user_can( 'edit_user', $user->ID ) ) |
2204 return new IXR_Error( 401, __( 'Sorry, you cannot edit your profile.' ) ); |
2409 return new IXR_Error( 401, __( 'Sorry, you cannot edit your profile.' ) ); |
2205 |
2410 |
2269 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
2473 return new IXR_Error( 404, __( 'Invalid post ID.' ) ); |
2270 |
2474 |
2271 if ( !current_user_can( 'edit_page', $page_id ) ) |
2475 if ( !current_user_can( 'edit_page', $page_id ) ) |
2272 return new IXR_Error( 401, __( 'Sorry, you cannot edit this page.' ) ); |
2476 return new IXR_Error( 401, __( 'Sorry, you cannot edit this page.' ) ); |
2273 |
2477 |
2274 do_action('xmlrpc_call', 'wp.getPage'); |
2478 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
2479 do_action( 'xmlrpc_call', 'wp.getPage' ); |
2275 |
2480 |
2276 // If we found the page then format the data. |
2481 // If we found the page then format the data. |
2277 if ( $page->ID && ($page->post_type == 'page') ) { |
2482 if ( $page->ID && ($page->post_type == 'page') ) { |
2278 return $this->_prepare_page( $page ); |
2483 return $this->_prepare_page( $page ); |
2279 } |
2484 } |
2280 // If the page doesn't exist indicate that. |
2485 // If the page doesn't exist indicate that. |
2281 else { |
2486 else { |
2282 return(new IXR_Error(404, __('Sorry, no such page.'))); |
2487 return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
2283 } |
2488 } |
2284 } |
2489 } |
2285 |
2490 |
2286 /** |
2491 /** |
2287 * Retrieve Pages. |
2492 * Retrieve Pages. |
2288 * |
2493 * |
2289 * @since 2.2.0 |
2494 * @since 2.2.0 |
2290 * |
2495 * |
2291 * @param array $args Method parameters. Contains: |
2496 * @param array $args Method parameters. Contains: |
2292 * - blog_id |
2497 * - blog_id (unused) |
2293 * - username |
2498 * - username |
2294 * - password |
2499 * - password |
2295 * - num_pages |
2500 * - num_pages |
2296 * @return array |
2501 * @return array|IXR_Error |
2297 */ |
2502 */ |
2298 function wp_getPages($args) { |
2503 public function wp_getPages($args) { |
2299 $this->escape($args); |
2504 $this->escape($args); |
2300 |
2505 |
2301 $blog_id = (int) $args[0]; |
|
2302 $username = $args[1]; |
2506 $username = $args[1]; |
2303 $password = $args[2]; |
2507 $password = $args[2]; |
2304 $num_pages = isset($args[3]) ? (int) $args[3] : 10; |
2508 $num_pages = isset($args[3]) ? (int) $args[3] : 10; |
2305 |
2509 |
2306 if ( !$user = $this->login($username, $password) ) |
2510 if ( !$user = $this->login($username, $password) ) |
2307 return $this->error; |
2511 return $this->error; |
2308 |
2512 |
2309 if ( !current_user_can( 'edit_pages' ) ) |
2513 if ( !current_user_can( 'edit_pages' ) ) |
2310 return new IXR_Error( 401, __( 'Sorry, you cannot edit pages.' ) ); |
2514 return new IXR_Error( 401, __( 'Sorry, you cannot edit pages.' ) ); |
2311 |
2515 |
2312 do_action('xmlrpc_call', 'wp.getPages'); |
2516 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
2517 do_action( 'xmlrpc_call', 'wp.getPages' ); |
2313 |
2518 |
2314 $pages = get_posts( array('post_type' => 'page', 'post_status' => 'any', 'numberposts' => $num_pages) ); |
2519 $pages = get_posts( array('post_type' => 'page', 'post_status' => 'any', 'numberposts' => $num_pages) ); |
2315 $num_pages = count($pages); |
2520 $num_pages = count($pages); |
2316 |
2521 |
2317 // If we have pages, put together their info. |
2522 // If we have pages, put together their info. |
2321 foreach ($pages as $page) { |
2526 foreach ($pages as $page) { |
2322 if ( current_user_can( 'edit_page', $page->ID ) ) |
2527 if ( current_user_can( 'edit_page', $page->ID ) ) |
2323 $pages_struct[] = $this->_prepare_page( $page ); |
2528 $pages_struct[] = $this->_prepare_page( $page ); |
2324 } |
2529 } |
2325 |
2530 |
2326 return($pages_struct); |
2531 return $pages_struct; |
2327 } |
2532 } |
2328 // If no pages were found return an error. |
2533 |
2329 else { |
2534 return array(); |
2330 return(array()); |
|
2331 } |
|
2332 } |
2535 } |
2333 |
2536 |
2334 /** |
2537 /** |
2335 * Create new page. |
2538 * Create new page. |
2336 * |
2539 * |
2337 * @since 2.2.0 |
2540 * @since 2.2.0 |
2338 * |
2541 * |
2339 * @param array $args Method parameters. See {@link wp_xmlrpc_server::mw_newPost()} |
2542 * @param array $args Method parameters. See {@link wp_xmlrpc_server::mw_newPost()} |
2340 * @return unknown |
2543 * @return int|IXR_Error |
2341 */ |
2544 */ |
2342 function wp_newPage($args) { |
2545 public function wp_newPage($args) { |
2343 // Items not escaped here will be escaped in newPost. |
2546 // Items not escaped here will be escaped in newPost. |
2344 $username = $this->escape($args[1]); |
2547 $username = $this->escape($args[1]); |
2345 $password = $this->escape($args[2]); |
2548 $password = $this->escape($args[2]); |
2346 $page = $args[3]; |
|
2347 $publish = $args[4]; |
|
2348 |
2549 |
2349 if ( !$user = $this->login($username, $password) ) |
2550 if ( !$user = $this->login($username, $password) ) |
2350 return $this->error; |
2551 return $this->error; |
2351 |
2552 |
2352 do_action('xmlrpc_call', 'wp.newPage'); |
2553 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
2554 do_action( 'xmlrpc_call', 'wp.newPage' ); |
2353 |
2555 |
2354 // Mark this as content for a page. |
2556 // Mark this as content for a page. |
2355 $args[3]["post_type"] = 'page'; |
2557 $args[3]["post_type"] = 'page'; |
2356 |
2558 |
2357 // Let mw_newPost do all of the heavy lifting. |
2559 // Let mw_newPost do all of the heavy lifting. |
2358 return($this->mw_newPost($args)); |
2560 return $this->mw_newPost( $args ); |
2359 } |
2561 } |
2360 |
2562 |
2361 /** |
2563 /** |
2362 * Delete page. |
2564 * Delete page. |
2363 * |
2565 * |
2364 * @since 2.2.0 |
2566 * @since 2.2.0 |
2365 * |
2567 * |
2366 * @param array $args Method parameters. |
2568 * @param array $args Method parameters. |
2367 * @return bool True, if success. |
2569 * @return bool|IXR_Error True, if success. |
2368 */ |
2570 */ |
2369 function wp_deletePage($args) { |
2571 public function wp_deletePage($args) { |
2370 $this->escape($args); |
2572 $this->escape($args); |
2371 |
2573 |
2372 $blog_id = (int) $args[0]; |
|
2373 $username = $args[1]; |
2574 $username = $args[1]; |
2374 $password = $args[2]; |
2575 $password = $args[2]; |
2375 $page_id = (int) $args[3]; |
2576 $page_id = (int) $args[3]; |
2376 |
2577 |
2377 if ( !$user = $this->login($username, $password) ) |
2578 if ( !$user = $this->login($username, $password) ) |
2378 return $this->error; |
2579 return $this->error; |
2379 |
2580 |
2380 do_action('xmlrpc_call', 'wp.deletePage'); |
2581 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
2582 do_action( 'xmlrpc_call', 'wp.deletePage' ); |
2381 |
2583 |
2382 // Get the current page based on the page_id and |
2584 // Get the current page based on the page_id and |
2383 // make sure it is a page and not a post. |
2585 // make sure it is a page and not a post. |
2384 $actual_page = get_post($page_id, ARRAY_A); |
2586 $actual_page = get_post($page_id, ARRAY_A); |
2385 if ( !$actual_page || ($actual_page['post_type'] != 'page') ) |
2587 if ( !$actual_page || ($actual_page['post_type'] != 'page') ) |
2386 return(new IXR_Error(404, __('Sorry, no such page.'))); |
2588 return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
2387 |
2589 |
2388 // Make sure the user can delete pages. |
2590 // Make sure the user can delete pages. |
2389 if ( !current_user_can('delete_page', $page_id) ) |
2591 if ( !current_user_can('delete_page', $page_id) ) |
2390 return(new IXR_Error(401, __('Sorry, you do not have the right to delete this page.'))); |
2592 return new IXR_Error( 401, __( 'Sorry, you do not have the right to delete this page.' ) ); |
2391 |
2593 |
2392 // Attempt to delete the page. |
2594 // Attempt to delete the page. |
2393 $result = wp_delete_post($page_id); |
2595 $result = wp_delete_post($page_id); |
2394 if ( !$result ) |
2596 if ( !$result ) |
2395 return(new IXR_Error(500, __('Failed to delete the page.'))); |
2597 return new IXR_Error( 500, __( 'Failed to delete the page.' ) ); |
2396 |
2598 |
|
2599 /** |
|
2600 * Fires after a page has been successfully deleted via XML-RPC. |
|
2601 * |
|
2602 * @since 3.4.0 |
|
2603 * |
|
2604 * @param int $page_id ID of the deleted page. |
|
2605 * @param array $args An array of arguments to delete the page. |
|
2606 */ |
2397 do_action( 'xmlrpc_call_success_wp_deletePage', $page_id, $args ); |
2607 do_action( 'xmlrpc_call_success_wp_deletePage', $page_id, $args ); |
2398 |
2608 |
2399 return(true); |
2609 return true; |
2400 } |
2610 } |
2401 |
2611 |
2402 /** |
2612 /** |
2403 * Edit page. |
2613 * Edit page. |
2404 * |
2614 * |
2405 * @since 2.2.0 |
2615 * @since 2.2.0 |
2406 * |
2616 * |
2407 * @param array $args Method parameters. |
2617 * @param array $args Method parameters. |
2408 * @return unknown |
2618 * @return array|IXR_Error |
2409 */ |
2619 */ |
2410 function wp_editPage($args) { |
2620 public function wp_editPage($args) { |
2411 // Items not escaped here will be escaped in editPost. |
2621 // Items not escaped here will be escaped in editPost. |
2412 $blog_id = (int) $args[0]; |
|
2413 $page_id = (int) $this->escape($args[1]); |
2622 $page_id = (int) $this->escape($args[1]); |
2414 $username = $this->escape($args[2]); |
2623 $username = $this->escape($args[2]); |
2415 $password = $this->escape($args[3]); |
2624 $password = $this->escape($args[3]); |
2416 $content = $args[4]; |
2625 $content = $args[4]; |
2417 $publish = $args[5]; |
2626 $publish = $args[5]; |
2418 |
2627 |
2419 if ( !$user = $this->login($username, $password) ) |
2628 if ( !$user = $this->login($username, $password) ) |
2420 return $this->error; |
2629 return $this->error; |
2421 |
2630 |
2422 do_action('xmlrpc_call', 'wp.editPage'); |
2631 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
2632 do_action( 'xmlrpc_call', 'wp.editPage' ); |
2423 |
2633 |
2424 // Get the page data and make sure it is a page. |
2634 // Get the page data and make sure it is a page. |
2425 $actual_page = get_post($page_id, ARRAY_A); |
2635 $actual_page = get_post($page_id, ARRAY_A); |
2426 if ( !$actual_page || ($actual_page['post_type'] != 'page') ) |
2636 if ( !$actual_page || ($actual_page['post_type'] != 'page') ) |
2427 return(new IXR_Error(404, __('Sorry, no such page.'))); |
2637 return new IXR_Error( 404, __( 'Sorry, no such page.' ) ); |
2428 |
2638 |
2429 // Make sure the user is allowed to edit pages. |
2639 // Make sure the user is allowed to edit pages. |
2430 if ( !current_user_can('edit_page', $page_id) ) |
2640 if ( !current_user_can('edit_page', $page_id) ) |
2431 return(new IXR_Error(401, __('Sorry, you do not have the right to edit this page.'))); |
2641 return new IXR_Error( 401, __( 'Sorry, you do not have the right to edit this page.' ) ); |
2432 |
2642 |
2433 // Mark this as content for a page. |
2643 // Mark this as content for a page. |
2434 $content['post_type'] = 'page'; |
2644 $content['post_type'] = 'page'; |
2435 |
2645 |
2436 // Arrange args in the way mw_editPost understands. |
2646 // Arrange args in the way mw_editPost understands. |
2441 $content, |
2651 $content, |
2442 $publish |
2652 $publish |
2443 ); |
2653 ); |
2444 |
2654 |
2445 // Let mw_editPost do all of the heavy lifting. |
2655 // Let mw_editPost do all of the heavy lifting. |
2446 return($this->mw_editPost($args)); |
2656 return $this->mw_editPost( $args ); |
2447 } |
2657 } |
2448 |
2658 |
2449 /** |
2659 /** |
2450 * Retrieve page list. |
2660 * Retrieve page list. |
2451 * |
2661 * |
2452 * @since 2.2.0 |
2662 * @since 2.2.0 |
2453 * |
2663 * |
2454 * @param array $args Method parameters. |
2664 * @param array $args Method parameters. |
2455 * @return unknown |
2665 * @return array|IXR_Error |
2456 */ |
2666 */ |
2457 function wp_getPageList($args) { |
2667 public function wp_getPageList($args) { |
2458 global $wpdb; |
2668 global $wpdb; |
2459 |
2669 |
2460 $this->escape($args); |
2670 $this->escape($args); |
2461 |
2671 |
2462 $blog_id = (int) $args[0]; |
|
2463 $username = $args[1]; |
2672 $username = $args[1]; |
2464 $password = $args[2]; |
2673 $password = $args[2]; |
2465 |
2674 |
2466 if ( !$user = $this->login($username, $password) ) |
2675 if ( !$user = $this->login($username, $password) ) |
2467 return $this->error; |
2676 return $this->error; |
2468 |
2677 |
2469 if ( !current_user_can( 'edit_pages' ) ) |
2678 if ( !current_user_can( 'edit_pages' ) ) |
2470 return new IXR_Error( 401, __( 'Sorry, you cannot edit pages.' ) ); |
2679 return new IXR_Error( 401, __( 'Sorry, you cannot edit pages.' ) ); |
2471 |
2680 |
2472 do_action('xmlrpc_call', 'wp.getPageList'); |
2681 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
2682 do_action( 'xmlrpc_call', 'wp.getPageList' ); |
2473 |
2683 |
2474 // Get list of pages ids and titles |
2684 // Get list of pages ids and titles |
2475 $page_list = $wpdb->get_results(" |
2685 $page_list = $wpdb->get_results(" |
2476 SELECT ID page_id, |
2686 SELECT ID page_id, |
2477 post_title page_title, |
2687 post_title page_title, |
2493 unset($page_list[$i]->post_date_gmt); |
2703 unset($page_list[$i]->post_date_gmt); |
2494 unset($page_list[$i]->post_date); |
2704 unset($page_list[$i]->post_date); |
2495 unset($page_list[$i]->post_status); |
2705 unset($page_list[$i]->post_status); |
2496 } |
2706 } |
2497 |
2707 |
2498 return($page_list); |
2708 return $page_list; |
2499 } |
2709 } |
2500 |
2710 |
2501 /** |
2711 /** |
2502 * Retrieve authors list. |
2712 * Retrieve authors list. |
2503 * |
2713 * |
2504 * @since 2.2.0 |
2714 * @since 2.2.0 |
2505 * |
2715 * |
2506 * @param array $args Method parameters. |
2716 * @param array $args Method parameters. |
2507 * @return array |
2717 * @return array|IXR_Error |
2508 */ |
2718 */ |
2509 function wp_getAuthors($args) { |
2719 public function wp_getAuthors($args) { |
2510 |
2720 |
2511 $this->escape($args); |
2721 $this->escape($args); |
2512 |
2722 |
2513 $blog_id = (int) $args[0]; |
|
2514 $username = $args[1]; |
2723 $username = $args[1]; |
2515 $password = $args[2]; |
2724 $password = $args[2]; |
2516 |
2725 |
2517 if ( !$user = $this->login($username, $password) ) |
2726 if ( !$user = $this->login($username, $password) ) |
2518 return $this->error; |
2727 return $this->error; |
2519 |
2728 |
2520 if ( !current_user_can('edit_posts') ) |
2729 if ( !current_user_can('edit_posts') ) |
2521 return(new IXR_Error(401, __('Sorry, you cannot edit posts on this site.'))); |
2730 return new IXR_Error( 401, __( 'Sorry, you cannot edit posts on this site.' ) ); |
2522 |
2731 |
2523 do_action('xmlrpc_call', 'wp.getAuthors'); |
2732 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
2733 do_action( 'xmlrpc_call', 'wp.getAuthors' ); |
2524 |
2734 |
2525 $authors = array(); |
2735 $authors = array(); |
2526 foreach ( get_users( array( 'fields' => array('ID','user_login','display_name') ) ) as $user ) { |
2736 foreach ( get_users( array( 'fields' => array('ID','user_login','display_name') ) ) as $user ) { |
2527 $authors[] = array( |
2737 $authors[] = array( |
2528 'user_id' => $user->ID, |
2738 'user_id' => $user->ID, |
2538 * Get list of all tags |
2748 * Get list of all tags |
2539 * |
2749 * |
2540 * @since 2.7.0 |
2750 * @since 2.7.0 |
2541 * |
2751 * |
2542 * @param array $args Method parameters. |
2752 * @param array $args Method parameters. |
2543 * @return array |
2753 * @return array|IXR_Error |
2544 */ |
2754 */ |
2545 function wp_getTags( $args ) { |
2755 public function wp_getTags( $args ) { |
2546 $this->escape( $args ); |
2756 $this->escape( $args ); |
2547 |
2757 |
2548 $blog_id = (int) $args[0]; |
|
2549 $username = $args[1]; |
2758 $username = $args[1]; |
2550 $password = $args[2]; |
2759 $password = $args[2]; |
2551 |
2760 |
2552 if ( !$user = $this->login($username, $password) ) |
2761 if ( !$user = $this->login($username, $password) ) |
2553 return $this->error; |
2762 return $this->error; |
2554 |
2763 |
2555 if ( !current_user_can( 'edit_posts' ) ) |
2764 if ( !current_user_can( 'edit_posts' ) ) |
2556 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view tags.' ) ); |
2765 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view tags.' ) ); |
2557 |
2766 |
|
2767 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
2558 do_action( 'xmlrpc_call', 'wp.getKeywords' ); |
2768 do_action( 'xmlrpc_call', 'wp.getKeywords' ); |
2559 |
2769 |
2560 $tags = array(); |
2770 $tags = array(); |
2561 |
2771 |
2562 if ( $all_tags = get_tags() ) { |
2772 if ( $all_tags = get_tags() ) { |
2563 foreach( (array) $all_tags as $tag ) { |
2773 foreach( (array) $all_tags as $tag ) { |
|
2774 $struct = array(); |
2564 $struct['tag_id'] = $tag->term_id; |
2775 $struct['tag_id'] = $tag->term_id; |
2565 $struct['name'] = $tag->name; |
2776 $struct['name'] = $tag->name; |
2566 $struct['count'] = $tag->count; |
2777 $struct['count'] = $tag->count; |
2567 $struct['slug'] = $tag->slug; |
2778 $struct['slug'] = $tag->slug; |
2568 $struct['html_url'] = esc_html( get_tag_link( $tag->term_id ) ); |
2779 $struct['html_url'] = esc_html( get_tag_link( $tag->term_id ) ); |
2579 * Create new category. |
2790 * Create new category. |
2580 * |
2791 * |
2581 * @since 2.2.0 |
2792 * @since 2.2.0 |
2582 * |
2793 * |
2583 * @param array $args Method parameters. |
2794 * @param array $args Method parameters. |
2584 * @return int Category ID. |
2795 * @return int|IXR_Error Category ID. |
2585 */ |
2796 */ |
2586 function wp_newCategory($args) { |
2797 public function wp_newCategory($args) { |
2587 $this->escape($args); |
2798 $this->escape($args); |
2588 |
2799 |
2589 $blog_id = (int) $args[0]; |
|
2590 $username = $args[1]; |
2800 $username = $args[1]; |
2591 $password = $args[2]; |
2801 $password = $args[2]; |
2592 $category = $args[3]; |
2802 $category = $args[3]; |
2593 |
2803 |
2594 if ( !$user = $this->login($username, $password) ) |
2804 if ( !$user = $this->login($username, $password) ) |
2595 return $this->error; |
2805 return $this->error; |
2596 |
2806 |
2597 do_action('xmlrpc_call', 'wp.newCategory'); |
2807 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
2808 do_action( 'xmlrpc_call', 'wp.newCategory' ); |
2598 |
2809 |
2599 // Make sure the user is allowed to add a category. |
2810 // Make sure the user is allowed to add a category. |
2600 if ( !current_user_can('manage_categories') ) |
2811 if ( !current_user_can('manage_categories') ) |
2601 return(new IXR_Error(401, __('Sorry, you do not have the right to add a category.'))); |
2812 return new IXR_Error(401, __('Sorry, you do not have the right to add a category.')); |
2602 |
2813 |
2603 // If no slug was provided make it empty so that |
2814 // If no slug was provided make it empty so that |
2604 // WordPress will generate one. |
2815 // WordPress will generate one. |
2605 if ( empty($category['slug']) ) |
2816 if ( empty($category['slug']) ) |
2606 $category['slug'] = ''; |
2817 $category['slug'] = ''; |
2640 * Remove category. |
2859 * Remove category. |
2641 * |
2860 * |
2642 * @since 2.5.0 |
2861 * @since 2.5.0 |
2643 * |
2862 * |
2644 * @param array $args Method parameters. |
2863 * @param array $args Method parameters. |
2645 * @return mixed See {@link wp_delete_term()} for return info. |
2864 * @return bool|IXR_Error See {@link wp_delete_term()} for return info. |
2646 */ |
2865 */ |
2647 function wp_deleteCategory($args) { |
2866 public function wp_deleteCategory($args) { |
2648 $this->escape($args); |
2867 $this->escape($args); |
2649 |
2868 |
2650 $blog_id = (int) $args[0]; |
|
2651 $username = $args[1]; |
2869 $username = $args[1]; |
2652 $password = $args[2]; |
2870 $password = $args[2]; |
2653 $category_id = (int) $args[3]; |
2871 $category_id = (int) $args[3]; |
2654 |
2872 |
2655 if ( !$user = $this->login($username, $password) ) |
2873 if ( !$user = $this->login($username, $password) ) |
2656 return $this->error; |
2874 return $this->error; |
2657 |
2875 |
2658 do_action('xmlrpc_call', 'wp.deleteCategory'); |
2876 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
2877 do_action( 'xmlrpc_call', 'wp.deleteCategory' ); |
2659 |
2878 |
2660 if ( !current_user_can('manage_categories') ) |
2879 if ( !current_user_can('manage_categories') ) |
2661 return new IXR_Error( 401, __( 'Sorry, you do not have the right to delete a category.' ) ); |
2880 return new IXR_Error( 401, __( 'Sorry, you do not have the right to delete a category.' ) ); |
2662 |
2881 |
2663 $status = wp_delete_term( $category_id, 'category' ); |
2882 $status = wp_delete_term( $category_id, 'category' ); |
2664 |
2883 |
2665 if( true == $status ) |
2884 if ( true == $status ) { |
|
2885 /** |
|
2886 * Fires after a category has been successfully deleted via XML-RPC. |
|
2887 * |
|
2888 * @since 3.4.0 |
|
2889 * |
|
2890 * @param int $category_id ID of the deleted category. |
|
2891 * @param array $args An array of arguments to delete the category. |
|
2892 */ |
2666 do_action( 'xmlrpc_call_success_wp_deleteCategory', $category_id, $args ); |
2893 do_action( 'xmlrpc_call_success_wp_deleteCategory', $category_id, $args ); |
|
2894 } |
2667 |
2895 |
2668 return $status; |
2896 return $status; |
2669 } |
2897 } |
2670 |
2898 |
2671 /** |
2899 /** |
2672 * Retrieve category list. |
2900 * Retrieve category list. |
2673 * |
2901 * |
2674 * @since 2.2.0 |
2902 * @since 2.2.0 |
2675 * |
2903 * |
2676 * @param array $args Method parameters. |
2904 * @param array $args Method parameters. |
2677 * @return array |
2905 * @return array|IXR_Error |
2678 */ |
2906 */ |
2679 function wp_suggestCategories($args) { |
2907 public function wp_suggestCategories($args) { |
2680 $this->escape($args); |
2908 $this->escape($args); |
2681 |
2909 |
2682 $blog_id = (int) $args[0]; |
|
2683 $username = $args[1]; |
2910 $username = $args[1]; |
2684 $password = $args[2]; |
2911 $password = $args[2]; |
2685 $category = $args[3]; |
2912 $category = $args[3]; |
2686 $max_results = (int) $args[4]; |
2913 $max_results = (int) $args[4]; |
2687 |
2914 |
2688 if ( !$user = $this->login($username, $password) ) |
2915 if ( !$user = $this->login($username, $password) ) |
2689 return $this->error; |
2916 return $this->error; |
2690 |
2917 |
2691 if ( !current_user_can( 'edit_posts' ) ) |
2918 if ( !current_user_can( 'edit_posts' ) ) |
2692 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts to this site in order to view categories.' ) ); |
2919 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
2693 |
2920 |
2694 do_action('xmlrpc_call', 'wp.suggestCategories'); |
2921 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
2922 do_action( 'xmlrpc_call', 'wp.suggestCategories' ); |
2695 |
2923 |
2696 $category_suggestions = array(); |
2924 $category_suggestions = array(); |
2697 $args = array('get' => 'all', 'number' => $max_results, 'name__like' => $category); |
2925 $args = array('get' => 'all', 'number' => $max_results, 'name__like' => $category); |
2698 foreach ( (array) get_categories($args) as $cat ) { |
2926 foreach ( (array) get_categories($args) as $cat ) { |
2699 $category_suggestions[] = array( |
2927 $category_suggestions[] = array( |
2700 'category_id' => $cat->term_id, |
2928 'category_id' => $cat->term_id, |
2701 'category_name' => $cat->name |
2929 'category_name' => $cat->name |
2702 ); |
2930 ); |
2703 } |
2931 } |
2704 |
2932 |
2705 return($category_suggestions); |
2933 return $category_suggestions; |
2706 } |
2934 } |
2707 |
2935 |
2708 /** |
2936 /** |
2709 * Retrieve comment. |
2937 * Retrieve comment. |
2710 * |
2938 * |
2711 * @since 2.7.0 |
2939 * @since 2.7.0 |
2712 * |
2940 * |
2713 * @param array $args Method parameters. |
2941 * @param array $args Method parameters. |
2714 * @return array |
2942 * @return array|IXR_Error |
2715 */ |
2943 */ |
2716 function wp_getComment($args) { |
2944 public function wp_getComment($args) { |
2717 $this->escape($args); |
2945 $this->escape($args); |
2718 |
2946 |
2719 $blog_id = (int) $args[0]; |
|
2720 $username = $args[1]; |
2947 $username = $args[1]; |
2721 $password = $args[2]; |
2948 $password = $args[2]; |
2722 $comment_id = (int) $args[3]; |
2949 $comment_id = (int) $args[3]; |
2723 |
2950 |
2724 if ( !$user = $this->login($username, $password) ) |
2951 if ( !$user = $this->login($username, $password) ) |
2725 return $this->error; |
2952 return $this->error; |
2726 |
2953 |
2727 if ( !current_user_can( 'moderate_comments' ) ) |
2954 if ( !current_user_can( 'moderate_comments' ) ) |
2728 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this site.' ) ); |
2955 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this site.' ) ); |
2729 |
2956 |
2730 do_action('xmlrpc_call', 'wp.getComment'); |
2957 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
2958 do_action( 'xmlrpc_call', 'wp.getComment' ); |
2731 |
2959 |
2732 if ( ! $comment = get_comment($comment_id) ) |
2960 if ( ! $comment = get_comment($comment_id) ) |
2733 return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
2961 return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
2734 |
2962 |
2735 return $this->_prepare_comment( $comment ); |
2963 return $this->_prepare_comment( $comment ); |
2736 } |
2964 } |
2737 |
2965 |
2738 /** |
2966 /** |
2739 * Retrieve comments. |
2967 * Retrieve comments. |
2740 * |
2968 * |
2741 * Besides the common blog_id, username, and password arguments, it takes a filter |
2969 * Besides the common blog_id (unused), username, and password arguments, it takes a filter |
2742 * array as last argument. |
2970 * array as last argument. |
2743 * |
2971 * |
2744 * Accepted 'filter' keys are 'status', 'post_id', 'offset', and 'number'. |
2972 * Accepted 'filter' keys are 'status', 'post_id', 'offset', and 'number'. |
2745 * |
2973 * |
2746 * The defaults are as follows: |
2974 * The defaults are as follows: |
2750 * - 'offset' - Default is 0. See {@link WP_Query::query()} for more. |
2978 * - 'offset' - Default is 0. See {@link WP_Query::query()} for more. |
2751 * |
2979 * |
2752 * @since 2.7.0 |
2980 * @since 2.7.0 |
2753 * |
2981 * |
2754 * @param array $args Method parameters. |
2982 * @param array $args Method parameters. |
2755 * @return array. Contains a collection of comments. See {@link wp_xmlrpc_server::wp_getComment()} for a description of each item contents |
2983 * @return array|IXR_Error Contains a collection of comments. See {@link wp_xmlrpc_server::wp_getComment()} for a description of each item contents |
2756 */ |
2984 */ |
2757 function wp_getComments($args) { |
2985 public function wp_getComments($args) { |
2758 $this->escape($args); |
2986 $this->escape($args); |
2759 |
2987 |
2760 $blog_id = (int) $args[0]; |
|
2761 $username = $args[1]; |
2988 $username = $args[1]; |
2762 $password = $args[2]; |
2989 $password = $args[2]; |
2763 $struct = isset( $args[3] ) ? $args[3] : array(); |
2990 $struct = isset( $args[3] ) ? $args[3] : array(); |
2764 |
2991 |
2765 if ( !$user = $this->login($username, $password) ) |
2992 if ( !$user = $this->login($username, $password) ) |
2766 return $this->error; |
2993 return $this->error; |
2767 |
2994 |
2768 if ( !current_user_can( 'moderate_comments' ) ) |
2995 if ( !current_user_can( 'moderate_comments' ) ) |
2769 return new IXR_Error( 401, __( 'Sorry, you cannot edit comments.' ) ); |
2996 return new IXR_Error( 401, __( 'Sorry, you cannot edit comments.' ) ); |
2770 |
2997 |
2771 do_action('xmlrpc_call', 'wp.getComments'); |
2998 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
2999 do_action( 'xmlrpc_call', 'wp.getComments' ); |
2772 |
3000 |
2773 if ( isset($struct['status']) ) |
3001 if ( isset($struct['status']) ) |
2774 $status = $struct['status']; |
3002 $status = $struct['status']; |
2775 else |
3003 else |
2776 $status = ''; |
3004 $status = ''; |
2832 return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
3059 return new IXR_Error( 404, __( 'Invalid comment ID.' ) ); |
2833 |
3060 |
2834 if ( !current_user_can( 'edit_comment', $comment_ID ) ) |
3061 if ( !current_user_can( 'edit_comment', $comment_ID ) ) |
2835 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this site.' ) ); |
3062 return new IXR_Error( 403, __( 'You are not allowed to moderate comments on this site.' ) ); |
2836 |
3063 |
2837 do_action('xmlrpc_call', 'wp.deleteComment'); |
3064 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
3065 do_action( 'xmlrpc_call', 'wp.deleteComment' ); |
2838 |
3066 |
2839 $status = wp_delete_comment( $comment_ID ); |
3067 $status = wp_delete_comment( $comment_ID ); |
2840 |
3068 |
2841 if( true == $status ) |
3069 if ( true == $status ) { |
|
3070 /** |
|
3071 * Fires after a comment has been successfully deleted via XML-RPC. |
|
3072 * |
|
3073 * @since 3.4.0 |
|
3074 * |
|
3075 * @param int $comment_ID ID of the deleted comment. |
|
3076 * @param array $args An array of arguments to delete the comment. |
|
3077 */ |
2842 do_action( 'xmlrpc_call_success_wp_deleteComment', $comment_ID, $args ); |
3078 do_action( 'xmlrpc_call_success_wp_deleteComment', $comment_ID, $args ); |
|
3079 } |
2843 |
3080 |
2844 return $status; |
3081 return $status; |
2845 } |
3082 } |
2846 |
3083 |
2847 /** |
3084 /** |
2848 * Edit comment. |
3085 * Edit comment. |
2849 * |
3086 * |
2850 * Besides the common blog_id, username, and password arguments, it takes a |
3087 * Besides the common blog_id (unused), username, and password arguments, it takes a |
2851 * comment_id integer and a content_struct array as last argument. |
3088 * comment_id integer and a content_struct array as last argument. |
2852 * |
3089 * |
2853 * The allowed keys in the content_struct array are: |
3090 * The allowed keys in the content_struct array are: |
2854 * - 'author' |
3091 * - 'author' |
2855 * - 'author_url' |
3092 * - 'author_url' |
2939 * Create new comment. |
3184 * Create new comment. |
2940 * |
3185 * |
2941 * @since 2.7.0 |
3186 * @since 2.7.0 |
2942 * |
3187 * |
2943 * @param array $args Method parameters. |
3188 * @param array $args Method parameters. |
2944 * @return mixed {@link wp_new_comment()} |
3189 * @return int|IXR_Error {@link wp_new_comment()} |
2945 */ |
3190 */ |
2946 function wp_newComment($args) { |
3191 public function wp_newComment($args) { |
2947 global $wpdb; |
|
2948 |
|
2949 $this->escape($args); |
3192 $this->escape($args); |
2950 |
3193 |
2951 $blog_id = (int) $args[0]; |
|
2952 $username = $args[1]; |
3194 $username = $args[1]; |
2953 $password = $args[2]; |
3195 $password = $args[2]; |
2954 $post = $args[3]; |
3196 $post = $args[3]; |
2955 $content_struct = $args[4]; |
3197 $content_struct = $args[4]; |
2956 |
3198 |
2957 $allow_anon = apply_filters('xmlrpc_allow_anonymous_comments', false); |
3199 /** |
|
3200 * Filter whether to allow anonymous comments over XML-RPC. |
|
3201 * |
|
3202 * @since 2.7.0 |
|
3203 * |
|
3204 * @param bool $allow Whether to allow anonymous commenting via XML-RPC. |
|
3205 * Default false. |
|
3206 */ |
|
3207 $allow_anon = apply_filters( 'xmlrpc_allow_anonymous_comments', false ); |
2958 |
3208 |
2959 $user = $this->login($username, $password); |
3209 $user = $this->login($username, $password); |
2960 |
3210 |
2961 if ( !$user ) { |
3211 if ( !$user ) { |
2962 $logged_in = false; |
3212 $logged_in = false; |
2963 if ( $allow_anon && get_option('comment_registration') ) |
3213 if ( $allow_anon && get_option('comment_registration') ) { |
2964 return new IXR_Error( 403, __( 'You must be registered to comment' ) ); |
3214 return new IXR_Error( 403, __( 'You must be registered to comment' ) ); |
2965 else if ( !$allow_anon ) |
3215 } elseif ( ! $allow_anon ) { |
2966 return $this->error; |
3216 return $this->error; |
|
3217 } |
2967 } else { |
3218 } else { |
2968 $logged_in = true; |
3219 $logged_in = true; |
2969 } |
3220 } |
2970 |
3221 |
2971 if ( is_numeric($post) ) |
3222 if ( is_numeric($post) ) |
3026 * Retrieve all of the comment status. |
3287 * Retrieve all of the comment status. |
3027 * |
3288 * |
3028 * @since 2.7.0 |
3289 * @since 2.7.0 |
3029 * |
3290 * |
3030 * @param array $args Method parameters. |
3291 * @param array $args Method parameters. |
3031 * @return array |
3292 * @return array|IXR_Error |
3032 */ |
3293 */ |
3033 function wp_getCommentStatusList($args) { |
3294 public function wp_getCommentStatusList($args) { |
3034 $this->escape( $args ); |
3295 $this->escape( $args ); |
3035 |
3296 |
3036 $blog_id = (int) $args[0]; |
|
3037 $username = $args[1]; |
3297 $username = $args[1]; |
3038 $password = $args[2]; |
3298 $password = $args[2]; |
3039 |
3299 |
3040 if ( !$user = $this->login($username, $password) ) |
3300 if ( !$user = $this->login($username, $password) ) |
3041 return $this->error; |
3301 return $this->error; |
3042 |
3302 |
3043 if ( !current_user_can( 'moderate_comments' ) ) |
3303 if ( !current_user_can( 'moderate_comments' ) ) |
3044 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) ); |
3304 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) ); |
3045 |
3305 |
3046 do_action('xmlrpc_call', 'wp.getCommentStatusList'); |
3306 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
3307 do_action( 'xmlrpc_call', 'wp.getCommentStatusList' ); |
3047 |
3308 |
3048 return get_comment_statuses(); |
3309 return get_comment_statuses(); |
3049 } |
3310 } |
3050 |
3311 |
3051 /** |
3312 /** |
3052 * Retrieve comment count. |
3313 * Retrieve comment count. |
3053 * |
3314 * |
3054 * @since 2.5.0 |
3315 * @since 2.5.0 |
3055 * |
3316 * |
3056 * @param array $args Method parameters. |
3317 * @param array $args Method parameters. |
3057 * @return array |
3318 * @return array|IXR_Error |
3058 */ |
3319 */ |
3059 function wp_getCommentCount( $args ) { |
3320 public function wp_getCommentCount( $args ) { |
3060 $this->escape($args); |
3321 $this->escape($args); |
3061 |
3322 |
3062 $blog_id = (int) $args[0]; |
|
3063 $username = $args[1]; |
3323 $username = $args[1]; |
3064 $password = $args[2]; |
3324 $password = $args[2]; |
3065 $post_id = (int) $args[3]; |
3325 $post_id = (int) $args[3]; |
3066 |
3326 |
3067 if ( !$user = $this->login($username, $password) ) |
3327 if ( !$user = $this->login($username, $password) ) |
3068 return $this->error; |
3328 return $this->error; |
3069 |
3329 |
3070 if ( !current_user_can( 'edit_posts' ) ) |
3330 if ( !current_user_can( 'edit_posts' ) ) |
3071 return new IXR_Error( 403, __( 'You are not allowed access to details about comments.' ) ); |
3331 return new IXR_Error( 403, __( 'You are not allowed access to details about comments.' ) ); |
3072 |
3332 |
3073 do_action('xmlrpc_call', 'wp.getCommentCount'); |
3333 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
3334 do_action( 'xmlrpc_call', 'wp.getCommentCount' ); |
3074 |
3335 |
3075 $count = wp_count_comments( $post_id ); |
3336 $count = wp_count_comments( $post_id ); |
3076 return array( |
3337 return array( |
3077 'approved' => $count->approved, |
3338 'approved' => $count->approved, |
3078 'awaiting_moderation' => $count->moderated, |
3339 'awaiting_moderation' => $count->moderated, |
3085 * Retrieve post statuses. |
3346 * Retrieve post statuses. |
3086 * |
3347 * |
3087 * @since 2.5.0 |
3348 * @since 2.5.0 |
3088 * |
3349 * |
3089 * @param array $args Method parameters. |
3350 * @param array $args Method parameters. |
3090 * @return array |
3351 * @return array|IXR_Error |
3091 */ |
3352 */ |
3092 function wp_getPostStatusList( $args ) { |
3353 public function wp_getPostStatusList( $args ) { |
3093 $this->escape( $args ); |
3354 $this->escape( $args ); |
3094 |
3355 |
3095 $blog_id = (int) $args[0]; |
|
3096 $username = $args[1]; |
3356 $username = $args[1]; |
3097 $password = $args[2]; |
3357 $password = $args[2]; |
3098 |
3358 |
3099 if ( !$user = $this->login($username, $password) ) |
3359 if ( !$user = $this->login($username, $password) ) |
3100 return $this->error; |
3360 return $this->error; |
3101 |
3361 |
3102 if ( !current_user_can( 'edit_posts' ) ) |
3362 if ( !current_user_can( 'edit_posts' ) ) |
3103 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) ); |
3363 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) ); |
3104 |
3364 |
3105 do_action('xmlrpc_call', 'wp.getPostStatusList'); |
3365 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
3366 do_action( 'xmlrpc_call', 'wp.getPostStatusList' ); |
3106 |
3367 |
3107 return get_post_statuses(); |
3368 return get_post_statuses(); |
3108 } |
3369 } |
3109 |
3370 |
3110 /** |
3371 /** |
3111 * Retrieve page statuses. |
3372 * Retrieve page statuses. |
3112 * |
3373 * |
3113 * @since 2.5.0 |
3374 * @since 2.5.0 |
3114 * |
3375 * |
3115 * @param array $args Method parameters. |
3376 * @param array $args Method parameters. |
3116 * @return array |
3377 * @return array|IXR_Error |
3117 */ |
3378 */ |
3118 function wp_getPageStatusList( $args ) { |
3379 public function wp_getPageStatusList( $args ) { |
3119 $this->escape( $args ); |
3380 $this->escape( $args ); |
3120 |
3381 |
3121 $blog_id = (int) $args[0]; |
|
3122 $username = $args[1]; |
3382 $username = $args[1]; |
3123 $password = $args[2]; |
3383 $password = $args[2]; |
3124 |
3384 |
3125 if ( !$user = $this->login($username, $password) ) |
3385 if ( !$user = $this->login($username, $password) ) |
3126 return $this->error; |
3386 return $this->error; |
3127 |
3387 |
3128 if ( !current_user_can( 'edit_pages' ) ) |
3388 if ( !current_user_can( 'edit_pages' ) ) |
3129 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) ); |
3389 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) ); |
3130 |
3390 |
3131 do_action('xmlrpc_call', 'wp.getPageStatusList'); |
3391 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
3392 do_action( 'xmlrpc_call', 'wp.getPageStatusList' ); |
3132 |
3393 |
3133 return get_page_statuses(); |
3394 return get_page_statuses(); |
3134 } |
3395 } |
3135 |
3396 |
3136 /** |
3397 /** |
3137 * Retrieve page templates. |
3398 * Retrieve page templates. |
3138 * |
3399 * |
3139 * @since 2.6.0 |
3400 * @since 2.6.0 |
3140 * |
3401 * |
3141 * @param array $args Method parameters. |
3402 * @param array $args Method parameters. |
3142 * @return array |
3403 * @return array|IXR_Error |
3143 */ |
3404 */ |
3144 function wp_getPageTemplates( $args ) { |
3405 public function wp_getPageTemplates( $args ) { |
3145 $this->escape( $args ); |
3406 $this->escape( $args ); |
3146 |
3407 |
3147 $blog_id = (int) $args[0]; |
|
3148 $username = $args[1]; |
3408 $username = $args[1]; |
3149 $password = $args[2]; |
3409 $password = $args[2]; |
3150 |
3410 |
3151 if ( !$user = $this->login($username, $password) ) |
3411 if ( !$user = $this->login($username, $password) ) |
3152 return $this->error; |
3412 return $this->error; |
3218 * Update blog options. |
3477 * Update blog options. |
3219 * |
3478 * |
3220 * @since 2.6.0 |
3479 * @since 2.6.0 |
3221 * |
3480 * |
3222 * @param array $args Method parameters. |
3481 * @param array $args Method parameters. |
3223 * @return unknown |
3482 * @return array|IXR_Error |
3224 */ |
3483 */ |
3225 function wp_setOptions( $args ) { |
3484 public function wp_setOptions( $args ) { |
3226 $this->escape( $args ); |
3485 $this->escape( $args ); |
3227 |
3486 |
3228 $blog_id = (int) $args[0]; |
|
3229 $username = $args[1]; |
3487 $username = $args[1]; |
3230 $password = $args[2]; |
3488 $password = $args[2]; |
3231 $options = (array) $args[3]; |
3489 $options = (array) $args[3]; |
3232 |
3490 |
3233 if ( !$user = $this->login($username, $password) ) |
3491 if ( !$user = $this->login($username, $password) ) |
3234 return $this->error; |
3492 return $this->error; |
3235 |
3493 |
3236 if ( !current_user_can( 'manage_options' ) ) |
3494 if ( !current_user_can( 'manage_options' ) ) |
3237 return new IXR_Error( 403, __( 'You are not allowed to update options.' ) ); |
3495 return new IXR_Error( 403, __( 'You are not allowed to update options.' ) ); |
3238 |
3496 |
|
3497 $option_names = array(); |
3239 foreach ( $options as $o_name => $o_value ) { |
3498 foreach ( $options as $o_name => $o_value ) { |
3240 $option_names[] = $o_name; |
3499 $option_names[] = $o_name; |
3241 if ( !array_key_exists( $o_name, $this->blog_options ) ) |
3500 if ( !array_key_exists( $o_name, $this->blog_options ) ) |
3242 continue; |
3501 continue; |
3243 |
3502 |
3244 if ( $this->blog_options[$o_name]['readonly'] == true ) |
3503 if ( $this->blog_options[$o_name]['readonly'] == true ) |
3245 continue; |
3504 continue; |
3246 |
3505 |
3247 update_option( $this->blog_options[$o_name]['option'], $o_value ); |
3506 update_option( $this->blog_options[$o_name]['option'], wp_unslash( $o_value ) ); |
3248 } |
3507 } |
3249 |
3508 |
3250 //Now return the updated values |
3509 //Now return the updated values |
3251 return $this->_getOptions($option_names); |
3510 return $this->_getOptions($option_names); |
3252 } |
3511 } |
3255 * Retrieve a media item by ID |
3514 * Retrieve a media item by ID |
3256 * |
3515 * |
3257 * @since 3.1.0 |
3516 * @since 3.1.0 |
3258 * |
3517 * |
3259 * @param array $args Method parameters. Contains: |
3518 * @param array $args Method parameters. Contains: |
3260 * - blog_id |
3519 * - blog_id (unused) |
3261 * - username |
3520 * - username |
3262 * - password |
3521 * - password |
3263 * - attachment_id |
3522 * - attachment_id |
3264 * @return array. Associative array containing: |
3523 * @return array|IXR_Error Associative array contains: |
3265 * - 'date_created_gmt' |
3524 * - 'date_created_gmt' |
3266 * - 'parent' |
3525 * - 'parent' |
3267 * - 'link' |
3526 * - 'link' |
3268 * - 'thumbnail' |
3527 * - 'thumbnail' |
3269 * - 'title' |
3528 * - 'title' |
3270 * - 'caption' |
3529 * - 'caption' |
3271 * - 'description' |
3530 * - 'description' |
3272 * - 'metadata' |
3531 * - 'metadata' |
3273 */ |
3532 */ |
3274 function wp_getMediaItem($args) { |
3533 public function wp_getMediaItem($args) { |
3275 $this->escape($args); |
3534 $this->escape($args); |
3276 |
3535 |
3277 $blog_id = (int) $args[0]; |
|
3278 $username = $args[1]; |
3536 $username = $args[1]; |
3279 $password = $args[2]; |
3537 $password = $args[2]; |
3280 $attachment_id = (int) $args[3]; |
3538 $attachment_id = (int) $args[3]; |
3281 |
3539 |
3282 if ( !$user = $this->login($username, $password) ) |
3540 if ( !$user = $this->login($username, $password) ) |
3283 return $this->error; |
3541 return $this->error; |
3284 |
3542 |
3285 if ( !current_user_can( 'upload_files' ) ) |
3543 if ( !current_user_can( 'upload_files' ) ) |
3286 return new IXR_Error( 403, __( 'You do not have permission to upload files.' ) ); |
3544 return new IXR_Error( 403, __( 'You do not have permission to upload files.' ) ); |
3287 |
3545 |
3288 do_action('xmlrpc_call', 'wp.getMediaItem'); |
3546 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
3547 do_action( 'xmlrpc_call', 'wp.getMediaItem' ); |
3289 |
3548 |
3290 if ( ! $attachment = get_post($attachment_id) ) |
3549 if ( ! $attachment = get_post($attachment_id) ) |
3291 return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
3550 return new IXR_Error( 404, __( 'Invalid attachment ID.' ) ); |
3292 |
3551 |
3293 return $this->_prepare_media_item( $attachment ); |
3552 return $this->_prepare_media_item( $attachment ); |
3294 } |
3553 } |
3295 |
3554 |
3296 /** |
3555 /** |
3297 * Retrieves a collection of media library items (or attachments) |
3556 * Retrieves a collection of media library items (or attachments) |
3298 * |
3557 * |
3299 * Besides the common blog_id, username, and password arguments, it takes a filter |
3558 * Besides the common blog_id (unused), username, and password arguments, it takes a filter |
3300 * array as last argument. |
3559 * array as last argument. |
3301 * |
3560 * |
3302 * Accepted 'filter' keys are 'parent_id', 'mime_type', 'offset', and 'number'. |
3561 * Accepted 'filter' keys are 'parent_id', 'mime_type', 'offset', and 'number'. |
3303 * |
3562 * |
3304 * The defaults are as follows: |
3563 * The defaults are as follows: |
3308 * - 'mime_type' - Default is ''. Filter by mime type (e.g., 'image/jpeg', 'application/pdf') |
3567 * - 'mime_type' - Default is ''. Filter by mime type (e.g., 'image/jpeg', 'application/pdf') |
3309 * |
3568 * |
3310 * @since 3.1.0 |
3569 * @since 3.1.0 |
3311 * |
3570 * |
3312 * @param array $args Method parameters. Contains: |
3571 * @param array $args Method parameters. Contains: |
3313 * - blog_id |
3572 * - blog_id (unused) |
3314 * - username |
3573 * - username |
3315 * - password |
3574 * - password |
3316 * - filter |
3575 * - filter |
3317 * @return array. Contains a collection of media items. See {@link wp_xmlrpc_server::wp_getMediaItem()} for a description of each item contents |
3576 * @return array|IXR_Error Contains a collection of media items. See {@link wp_xmlrpc_server::wp_getMediaItem()} for a description of each item contents |
3318 */ |
3577 */ |
3319 function wp_getMediaLibrary($args) { |
3578 public function wp_getMediaLibrary($args) { |
3320 $this->escape($args); |
3579 $this->escape($args); |
3321 |
3580 |
3322 $blog_id = (int) $args[0]; |
|
3323 $username = $args[1]; |
3581 $username = $args[1]; |
3324 $password = $args[2]; |
3582 $password = $args[2]; |
3325 $struct = isset( $args[3] ) ? $args[3] : array() ; |
3583 $struct = isset( $args[3] ) ? $args[3] : array() ; |
3326 |
3584 |
3327 if ( !$user = $this->login($username, $password) ) |
3585 if ( !$user = $this->login($username, $password) ) |
3328 return $this->error; |
3586 return $this->error; |
3329 |
3587 |
3330 if ( !current_user_can( 'upload_files' ) ) |
3588 if ( !current_user_can( 'upload_files' ) ) |
3331 return new IXR_Error( 401, __( 'You do not have permission to upload files.' ) ); |
3589 return new IXR_Error( 401, __( 'You do not have permission to upload files.' ) ); |
3332 |
3590 |
3333 do_action('xmlrpc_call', 'wp.getMediaLibrary'); |
3591 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
3592 do_action( 'xmlrpc_call', 'wp.getMediaLibrary' ); |
3334 |
3593 |
3335 $parent_id = ( isset($struct['parent_id']) ) ? absint($struct['parent_id']) : '' ; |
3594 $parent_id = ( isset($struct['parent_id']) ) ? absint($struct['parent_id']) : '' ; |
3336 $mime_type = ( isset($struct['mime_type']) ) ? $struct['mime_type'] : '' ; |
3595 $mime_type = ( isset($struct['mime_type']) ) ? $struct['mime_type'] : '' ; |
3337 $offset = ( isset($struct['offset']) ) ? absint($struct['offset']) : 0 ; |
3596 $offset = ( isset($struct['offset']) ) ? absint($struct['offset']) : 0 ; |
3338 $number = ( isset($struct['number']) ) ? absint($struct['number']) : -1 ; |
3597 $number = ( isset($struct['number']) ) ? absint($struct['number']) : -1 ; |
3348 } |
3607 } |
3349 |
3608 |
3350 /** |
3609 /** |
3351 * Retrieves a list of post formats used by the site |
3610 * Retrieves a list of post formats used by the site |
3352 * |
3611 * |
3353 * @since 3.1 |
3612 * @since 3.1.0 |
3354 * |
3613 * |
3355 * @param array $args Method parameters. Contains: |
3614 * @param array $args Method parameters. Contains: |
3356 * - blog_id |
3615 * - blog_id (unused) |
3357 * - username |
3616 * - username |
3358 * - password |
3617 * - password |
3359 * @return array |
3618 * @return array|IXR_Error |
3360 */ |
3619 */ |
3361 function wp_getPostFormats( $args ) { |
3620 public function wp_getPostFormats( $args ) { |
3362 $this->escape( $args ); |
3621 $this->escape( $args ); |
3363 |
3622 |
3364 $blog_id = (int) $args[0]; |
|
3365 $username = $args[1]; |
3623 $username = $args[1]; |
3366 $password = $args[2]; |
3624 $password = $args[2]; |
3367 |
3625 |
3368 if ( !$user = $this->login( $username, $password ) ) |
3626 if ( !$user = $this->login( $username, $password ) ) |
3369 return $this->error; |
3627 return $this->error; |
3370 |
3628 |
3371 if ( !current_user_can( 'edit_posts' ) ) |
3629 if ( !current_user_can( 'edit_posts' ) ) |
3372 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) ); |
3630 return new IXR_Error( 403, __( 'You are not allowed access to details about this site.' ) ); |
3373 |
3631 |
|
3632 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3374 do_action( 'xmlrpc_call', 'wp.getPostFormats' ); |
3633 do_action( 'xmlrpc_call', 'wp.getPostFormats' ); |
3375 |
3634 |
3376 $formats = get_post_format_strings(); |
3635 $formats = get_post_format_strings(); |
3377 |
3636 |
3378 # find out if they want a list of currently supports formats |
3637 // find out if they want a list of currently supports formats |
3379 if ( isset( $args[3] ) && is_array( $args[3] ) ) { |
3638 if ( isset( $args[3] ) && is_array( $args[3] ) ) { |
3380 if ( $args[3]['show-supported'] ) { |
3639 if ( $args[3]['show-supported'] ) { |
3381 if ( current_theme_supports( 'post-formats' ) ) { |
3640 if ( current_theme_supports( 'post-formats' ) ) { |
3382 $supported = get_theme_support( 'post-formats' ); |
3641 $supported = get_theme_support( 'post-formats' ); |
3383 |
3642 |
|
3643 $data = array(); |
3384 $data['all'] = $formats; |
3644 $data['all'] = $formats; |
3385 $data['supported'] = $supported[0]; |
3645 $data['supported'] = $supported[0]; |
3386 |
3646 |
3387 $formats = $data; |
3647 $formats = $data; |
3388 } |
3648 } |
3397 * |
3657 * |
3398 * @since 3.4.0 |
3658 * @since 3.4.0 |
3399 * |
3659 * |
3400 * @uses get_post_type_object() |
3660 * @uses get_post_type_object() |
3401 * @param array $args Method parameters. Contains: |
3661 * @param array $args Method parameters. Contains: |
3402 * - int $blog_id |
3662 * - int $blog_id (unused) |
3403 * - string $username |
3663 * - string $username |
3404 * - string $password |
3664 * - string $password |
3405 * - string $post_type_name |
3665 * - string $post_type_name |
3406 * - array $fields |
3666 * - array $fields |
3407 * @return array contains: |
3667 * @return array|IXR_Error Array contains: |
3408 * - 'labels' |
3668 * - 'labels' |
3409 * - 'description' |
3669 * - 'description' |
3410 * - 'capability_type' |
3670 * - 'capability_type' |
3411 * - 'cap' |
3671 * - 'cap' |
3412 * - 'map_meta_cap' |
3672 * - 'map_meta_cap' |
3413 * - 'hierarchical' |
3673 * - 'hierarchical' |
3414 * - 'menu_position' |
3674 * - 'menu_position' |
3415 * - 'taxonomies' |
3675 * - 'taxonomies' |
3416 * - 'supports' |
3676 * - 'supports' |
3417 */ |
3677 */ |
3418 function wp_getPostType( $args ) { |
3678 public function wp_getPostType( $args ) { |
3419 if ( ! $this->minimum_args( $args, 4 ) ) |
3679 if ( ! $this->minimum_args( $args, 4 ) ) |
3420 return $this->error; |
3680 return $this->error; |
3421 |
3681 |
3422 $this->escape( $args ); |
3682 $this->escape( $args ); |
3423 |
3683 |
3424 $blog_id = (int) $args[0]; |
|
3425 $username = $args[1]; |
3684 $username = $args[1]; |
3426 $password = $args[2]; |
3685 $password = $args[2]; |
3427 $post_type_name = $args[3]; |
3686 $post_type_name = $args[3]; |
3428 |
3687 |
3429 if ( isset( $args[4] ) ) |
3688 if ( isset( $args[4] ) ) { |
3430 $fields = $args[4]; |
3689 $fields = $args[4]; |
3431 else |
3690 } else { |
|
3691 /** |
|
3692 * Filter the default query fields used by the given XML-RPC method. |
|
3693 * |
|
3694 * @since 3.4.0 |
|
3695 * |
|
3696 * @param array $fields An array of post type query fields for the given method. |
|
3697 * @param string $method The method name. |
|
3698 */ |
3432 $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostType' ); |
3699 $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostType' ); |
|
3700 } |
3433 |
3701 |
3434 if ( !$user = $this->login( $username, $password ) ) |
3702 if ( !$user = $this->login( $username, $password ) ) |
3435 return $this->error; |
3703 return $this->error; |
3436 |
3704 |
|
3705 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3437 do_action( 'xmlrpc_call', 'wp.getPostType' ); |
3706 do_action( 'xmlrpc_call', 'wp.getPostType' ); |
3438 |
3707 |
3439 if( ! post_type_exists( $post_type_name ) ) |
3708 if( ! post_type_exists( $post_type_name ) ) |
3440 return new IXR_Error( 403, __( 'Invalid post type' ) ); |
3709 return new IXR_Error( 403, __( 'Invalid post type' ) ); |
3441 |
3710 |
3452 * |
3721 * |
3453 * @since 3.4.0 |
3722 * @since 3.4.0 |
3454 * |
3723 * |
3455 * @uses get_post_types() |
3724 * @uses get_post_types() |
3456 * @param array $args Method parameters. Contains: |
3725 * @param array $args Method parameters. Contains: |
3457 * - int $blog_id |
3726 * - int $blog_id (unused) |
3458 * - string $username |
3727 * - string $username |
3459 * - string $password |
3728 * - string $password |
3460 * - array $filter |
3729 * - array $filter |
3461 * - array $fields |
3730 * - array $fields |
3462 * @return array |
3731 * @return array|IXR_Error |
3463 */ |
3732 */ |
3464 function wp_getPostTypes( $args ) { |
3733 public function wp_getPostTypes( $args ) { |
3465 if ( ! $this->minimum_args( $args, 3 ) ) |
3734 if ( ! $this->minimum_args( $args, 3 ) ) |
3466 return $this->error; |
3735 return $this->error; |
3467 |
3736 |
3468 $this->escape( $args ); |
3737 $this->escape( $args ); |
3469 |
3738 |
3470 $blog_id = (int) $args[0]; |
|
3471 $username = $args[1]; |
3739 $username = $args[1]; |
3472 $password = $args[2]; |
3740 $password = $args[2]; |
3473 $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
3741 $filter = isset( $args[3] ) ? $args[3] : array( 'public' => true ); |
3474 |
3742 |
3475 if ( isset( $args[4] ) ) |
3743 if ( isset( $args[4] ) ) { |
3476 $fields = $args[4]; |
3744 $fields = $args[4]; |
3477 else |
3745 } else { |
|
3746 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3478 $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostTypes' ); |
3747 $fields = apply_filters( 'xmlrpc_default_posttype_fields', array( 'labels', 'cap', 'taxonomies' ), 'wp.getPostTypes' ); |
|
3748 } |
3479 |
3749 |
3480 if ( ! $user = $this->login( $username, $password ) ) |
3750 if ( ! $user = $this->login( $username, $password ) ) |
3481 return $this->error; |
3751 return $this->error; |
3482 |
3752 |
|
3753 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3483 do_action( 'xmlrpc_call', 'wp.getPostTypes' ); |
3754 do_action( 'xmlrpc_call', 'wp.getPostTypes' ); |
3484 |
3755 |
3485 $post_types = get_post_types( $filter, 'objects' ); |
3756 $post_types = get_post_types( $filter, 'objects' ); |
3486 |
3757 |
3487 $struct = array(); |
3758 $struct = array(); |
3506 * |
3777 * |
3507 * @uses wp_get_post_revisions() |
3778 * @uses wp_get_post_revisions() |
3508 * @see wp_getPost() for more on $fields |
3779 * @see wp_getPost() for more on $fields |
3509 * |
3780 * |
3510 * @param array $args Method parameters. Contains: |
3781 * @param array $args Method parameters. Contains: |
3511 * - int $blog_id |
3782 * - int $blog_id (unused) |
3512 * - string $username |
3783 * - string $username |
3513 * - string $password |
3784 * - string $password |
3514 * - int $post_id |
3785 * - int $post_id |
3515 * - array $fields |
3786 * - array $fields |
3516 * @return array contains a collection of posts. |
3787 * @return array|IXR_Error contains a collection of posts. |
3517 */ |
3788 */ |
3518 function wp_getRevisions( $args ) { |
3789 public function wp_getRevisions( $args ) { |
3519 if ( ! $this->minimum_args( $args, 4 ) ) |
3790 if ( ! $this->minimum_args( $args, 4 ) ) |
3520 return $this->error; |
3791 return $this->error; |
3521 |
3792 |
3522 $this->escape( $args ); |
3793 $this->escape( $args ); |
3523 |
3794 |
3524 $blog_id = (int) $args[0]; |
|
3525 $username = $args[1]; |
3795 $username = $args[1]; |
3526 $password = $args[2]; |
3796 $password = $args[2]; |
3527 $post_id = (int) $args[3]; |
3797 $post_id = (int) $args[3]; |
3528 |
3798 |
3529 if ( isset( $args[4] ) ) |
3799 if ( isset( $args[4] ) ) { |
3530 $fields = $args[4]; |
3800 $fields = $args[4]; |
3531 else |
3801 } else { |
|
3802 /** |
|
3803 * Filter the default revision query fields used by the given XML-RPC method. |
|
3804 * |
|
3805 * @since 3.5.0 |
|
3806 * |
|
3807 * @param array $field An array of revision query fields. |
|
3808 * @param string $method The method name. |
|
3809 */ |
3532 $fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' ); |
3810 $fields = apply_filters( 'xmlrpc_default_revision_fields', array( 'post_date', 'post_date_gmt' ), 'wp.getRevisions' ); |
|
3811 } |
3533 |
3812 |
3534 if ( ! $user = $this->login( $username, $password ) ) |
3813 if ( ! $user = $this->login( $username, $password ) ) |
3535 return $this->error; |
3814 return $this->error; |
3536 |
3815 |
|
3816 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3537 do_action( 'xmlrpc_call', 'wp.getRevisions' ); |
3817 do_action( 'xmlrpc_call', 'wp.getRevisions' ); |
3538 |
3818 |
3539 if ( ! $post = get_post( $post_id ) ) |
3819 if ( ! $post = get_post( $post_id ) ) |
3540 return new IXR_Error( 404, __( 'Invalid post ID' ) ); |
3820 return new IXR_Error( 404, __( 'Invalid post ID' ) ); |
3541 |
3821 |
3573 * @since 3.5.0 |
3853 * @since 3.5.0 |
3574 * |
3854 * |
3575 * @uses wp_restore_post_revision() |
3855 * @uses wp_restore_post_revision() |
3576 * |
3856 * |
3577 * @param array $args Method parameters. Contains: |
3857 * @param array $args Method parameters. Contains: |
3578 * - int $blog_id |
3858 * - int $blog_id (unused) |
3579 * - string $username |
3859 * - string $username |
3580 * - string $password |
3860 * - string $password |
3581 * - int $post_id |
3861 * - int $post_id |
3582 * @return bool false if there was an error restoring, true if success. |
3862 * @return bool|IXR_Error false if there was an error restoring, true if success. |
3583 */ |
3863 */ |
3584 function wp_restoreRevision( $args ) { |
3864 public function wp_restoreRevision( $args ) { |
3585 if ( ! $this->minimum_args( $args, 3 ) ) |
3865 if ( ! $this->minimum_args( $args, 3 ) ) |
3586 return $this->error; |
3866 return $this->error; |
3587 |
3867 |
3588 $this->escape( $args ); |
3868 $this->escape( $args ); |
3589 |
3869 |
3590 $blog_id = (int) $args[0]; |
|
3591 $username = $args[1]; |
3870 $username = $args[1]; |
3592 $password = $args[2]; |
3871 $password = $args[2]; |
3593 $revision_id = (int) $args[3]; |
3872 $revision_id = (int) $args[3]; |
3594 |
3873 |
3595 if ( ! $user = $this->login( $username, $password ) ) |
3874 if ( ! $user = $this->login( $username, $password ) ) |
3596 return $this->error; |
3875 return $this->error; |
3597 |
3876 |
|
3877 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3598 do_action( 'xmlrpc_call', 'wp.restoreRevision' ); |
3878 do_action( 'xmlrpc_call', 'wp.restoreRevision' ); |
3599 |
3879 |
3600 if ( ! $revision = wp_get_post_revision( $revision_id ) ) |
3880 if ( ! $revision = wp_get_post_revision( $revision_id ) ) |
3601 return new IXR_Error( 404, __( 'Invalid post ID' ) ); |
3881 return new IXR_Error( 404, __( 'Invalid post ID' ) ); |
3602 |
3882 |
3793 return $this->error; |
4077 return $this->error; |
3794 |
4078 |
3795 if ( ! current_user_can( 'edit_posts' ) ) |
4079 if ( ! current_user_can( 'edit_posts' ) ) |
3796 return new IXR_Error( 401, __( 'Sorry, you cannot edit posts on this site.' ) ); |
4080 return new IXR_Error( 401, __( 'Sorry, you cannot edit posts on this site.' ) ); |
3797 |
4081 |
3798 do_action('xmlrpc_call', 'blogger.getRecentPosts'); |
4082 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
4083 do_action( 'xmlrpc_call', 'blogger.getRecentPosts' ); |
3799 |
4084 |
3800 $posts_list = wp_get_recent_posts( $query ); |
4085 $posts_list = wp_get_recent_posts( $query ); |
3801 |
4086 |
3802 if ( !$posts_list ) { |
4087 if ( !$posts_list ) { |
3803 $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.')); |
4088 $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.')); |
3804 return $this->error; |
4089 return $this->error; |
3805 } |
4090 } |
3806 |
4091 |
|
4092 $recent_posts = array(); |
3807 foreach ($posts_list as $entry) { |
4093 foreach ($posts_list as $entry) { |
3808 if ( !current_user_can( 'edit_post', $entry['ID'] ) ) |
4094 if ( !current_user_can( 'edit_post', $entry['ID'] ) ) |
3809 continue; |
4095 continue; |
3810 |
4096 |
3811 $post_date = $this->_convert_date( $entry['post_date'] ); |
4097 $post_date = $this->_convert_date( $entry['post_date'] ); |
3813 |
4099 |
3814 $content = '<title>'.wp_unslash($entry['post_title']).'</title>'; |
4100 $content = '<title>'.wp_unslash($entry['post_title']).'</title>'; |
3815 $content .= '<category>'.$categories.'</category>'; |
4101 $content .= '<category>'.$categories.'</category>'; |
3816 $content .= wp_unslash($entry['post_content']); |
4102 $content .= wp_unslash($entry['post_content']); |
3817 |
4103 |
3818 $struct[] = array( |
4104 $recent_posts[] = array( |
3819 'userid' => $entry['post_author'], |
4105 'userid' => $entry['post_author'], |
3820 'dateCreated' => $post_date, |
4106 'dateCreated' => $post_date, |
3821 'content' => $content, |
4107 'content' => $content, |
3822 'postid' => (string) $entry['ID'], |
4108 'postid' => (string) $entry['ID'], |
3823 ); |
4109 ); |
3824 |
|
3825 } |
|
3826 |
|
3827 $recent_posts = array(); |
|
3828 for ( $j=0; $j<count($struct); $j++ ) { |
|
3829 array_push($recent_posts, $struct[$j]); |
|
3830 } |
4110 } |
3831 |
4111 |
3832 return $recent_posts; |
4112 return $recent_posts; |
3833 } |
4113 } |
3834 |
4114 |
3835 /** |
4115 /** |
3836 * Deprecated. |
4116 * Deprecated. |
3837 * |
4117 * |
3838 * @since 1.5.0 |
4118 * @since 1.5.0 |
3839 * @deprecated 3.5.0 |
4119 * @deprecated 3.5.0 |
3840 */ |
4120 * @return IXR_Error |
3841 function blogger_getTemplate($args) { |
4121 */ |
|
4122 public function blogger_getTemplate($args) { |
3842 return new IXR_Error( 403, __('Sorry, that file cannot be edited.' ) ); |
4123 return new IXR_Error( 403, __('Sorry, that file cannot be edited.' ) ); |
3843 } |
4124 } |
3844 |
4125 |
3845 /** |
4126 /** |
3846 * Deprecated. |
4127 * Deprecated. |
3847 * |
4128 * |
3848 * @since 1.5.0 |
4129 * @since 1.5.0 |
3849 * @deprecated 3.5.0 |
4130 * @deprecated 3.5.0 |
3850 */ |
4131 * @return IXR_Error |
3851 function blogger_setTemplate($args) { |
4132 */ |
|
4133 public function blogger_setTemplate($args) { |
3852 return new IXR_Error( 403, __('Sorry, that file cannot be edited.' ) ); |
4134 return new IXR_Error( 403, __('Sorry, that file cannot be edited.' ) ); |
3853 } |
4135 } |
3854 |
4136 |
3855 /** |
4137 /** |
3856 * Create new post. |
4138 * Create new post. |
3857 * |
4139 * |
3858 * @since 1.5.0 |
4140 * @since 1.5.0 |
3859 * |
4141 * |
3860 * @param array $args Method parameters. |
4142 * @param array $args Method parameters. |
3861 * @return int |
4143 * @return int|IXR_Error |
3862 */ |
4144 */ |
3863 function blogger_newPost($args) { |
4145 public function blogger_newPost($args) { |
3864 |
4146 |
3865 $this->escape($args); |
4147 $this->escape($args); |
3866 |
4148 |
3867 $blog_ID = (int) $args[1]; /* though we don't use it yet */ |
|
3868 $username = $args[2]; |
4149 $username = $args[2]; |
3869 $password = $args[3]; |
4150 $password = $args[3]; |
3870 $content = $args[4]; |
4151 $content = $args[4]; |
3871 $publish = $args[5]; |
4152 $publish = $args[5]; |
3872 |
4153 |
3873 if ( !$user = $this->login($username, $password) ) |
4154 if ( !$user = $this->login($username, $password) ) |
3874 return $this->error; |
4155 return $this->error; |
3875 |
4156 |
3876 do_action('xmlrpc_call', 'blogger.newPost'); |
4157 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
4158 do_action( 'xmlrpc_call', 'blogger.newPost' ); |
3877 |
4159 |
3878 $cap = ($publish) ? 'publish_posts' : 'edit_posts'; |
4160 $cap = ($publish) ? 'publish_posts' : 'edit_posts'; |
3879 if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) || !current_user_can($cap) ) |
4161 if ( ! current_user_can( get_post_type_object( 'post' )->cap->create_posts ) || !current_user_can($cap) ) |
3880 return new IXR_Error(401, __('Sorry, you are not allowed to post on this site.')); |
4162 return new IXR_Error(401, __('Sorry, you are not allowed to post on this site.')); |
3881 |
4163 |
3888 $post_content = xmlrpc_removepostdata($content); |
4170 $post_content = xmlrpc_removepostdata($content); |
3889 |
4171 |
3890 $post_date = current_time('mysql'); |
4172 $post_date = current_time('mysql'); |
3891 $post_date_gmt = current_time('mysql', 1); |
4173 $post_date_gmt = current_time('mysql', 1); |
3892 |
4174 |
3893 $post_data = compact('blog_ID', 'post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status'); |
4175 $post_data = compact('post_author', 'post_date', 'post_date_gmt', 'post_content', 'post_title', 'post_category', 'post_status'); |
3894 |
4176 |
3895 $post_ID = wp_insert_post($post_data); |
4177 $post_ID = wp_insert_post($post_data); |
3896 if ( is_wp_error( $post_ID ) ) |
4178 if ( is_wp_error( $post_ID ) ) |
3897 return new IXR_Error(500, $post_ID->get_error_message()); |
4179 return new IXR_Error(500, $post_ID->get_error_message()); |
3898 |
4180 |
3899 if ( !$post_ID ) |
4181 if ( !$post_ID ) |
3900 return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.')); |
4182 return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.')); |
3901 |
4183 |
3902 $this->attach_uploads( $post_ID, $post_content ); |
4184 $this->attach_uploads( $post_ID, $post_content ); |
3903 |
4185 |
|
4186 /** |
|
4187 * Fires after a new post has been successfully created via the XML-RPC Blogger API. |
|
4188 * |
|
4189 * @since 3.4.0 |
|
4190 * |
|
4191 * @param int $post_ID ID of the new post. |
|
4192 * @param array $args An array of new post arguments. |
|
4193 */ |
3904 do_action( 'xmlrpc_call_success_blogger_newPost', $post_ID, $args ); |
4194 do_action( 'xmlrpc_call_success_blogger_newPost', $post_ID, $args ); |
3905 |
4195 |
3906 return $post_ID; |
4196 return $post_ID; |
3907 } |
4197 } |
3908 |
4198 |
3910 * Edit a post. |
4200 * Edit a post. |
3911 * |
4201 * |
3912 * @since 1.5.0 |
4202 * @since 1.5.0 |
3913 * |
4203 * |
3914 * @param array $args Method parameters. |
4204 * @param array $args Method parameters. |
3915 * @return bool true when done. |
4205 * @return bool|IXR_Error true when done. |
3916 */ |
4206 */ |
3917 function blogger_editPost($args) { |
4207 public function blogger_editPost( $args ) { |
3918 |
4208 |
3919 $this->escape($args); |
4209 $this->escape($args); |
3920 |
4210 |
3921 $post_ID = (int) $args[1]; |
4211 $post_ID = (int) $args[1]; |
3922 $username = $args[2]; |
4212 $username = $args[2]; |
3923 $password = $args[3]; |
4213 $password = $args[3]; |
3924 $content = $args[4]; |
4214 $content = $args[4]; |
3925 $publish = $args[5]; |
4215 |
3926 |
4216 if ( ! $user = $this->login( $username, $password ) ) { |
3927 if ( !$user = $this->login($username, $password) ) |
4217 return $this->error; |
3928 return $this->error; |
4218 } |
3929 |
4219 |
3930 do_action('xmlrpc_call', 'blogger.editPost'); |
4220 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
3931 |
4221 do_action( 'xmlrpc_call', 'blogger.editPost' ); |
3932 $actual_post = get_post($post_ID,ARRAY_A); |
4222 |
3933 |
4223 $actual_post = get_post( $post_ID, ARRAY_A ); |
3934 if ( !$actual_post || $actual_post['post_type'] != 'post' ) |
4224 |
3935 return new IXR_Error(404, __('Sorry, no such post.')); |
4225 if ( ! $actual_post || $actual_post['post_type'] != 'post' ) { |
|
4226 return new IXR_Error( 404, __( 'Sorry, no such post.' ) ); |
|
4227 } |
3936 |
4228 |
3937 $this->escape($actual_post); |
4229 $this->escape($actual_post); |
3938 |
4230 |
3939 if ( !current_user_can('edit_post', $post_ID) ) |
4231 if ( ! current_user_can( 'edit_post', $post_ID ) ) { |
3940 return new IXR_Error(401, __('Sorry, you do not have the right to edit this post.')); |
4232 return new IXR_Error(401, __('Sorry, you do not have the right to edit this post.')); |
3941 |
4233 } |
3942 extract($actual_post, EXTR_SKIP); |
4234 if ( 'publish' == $actual_post['post_status'] && ! current_user_can( 'publish_posts' ) ) { |
3943 |
4235 return new IXR_Error( 401, __( 'Sorry, you do not have the right to publish this post.' ) ); |
3944 if ( ('publish' == $post_status) && !current_user_can('publish_posts') ) |
4236 } |
3945 return new IXR_Error(401, __('Sorry, you do not have the right to publish this post.')); |
4237 |
3946 |
4238 $postdata = array(); |
3947 $post_title = xmlrpc_getposttitle($content); |
4239 $postdata['ID'] = $actual_post['ID']; |
3948 $post_category = xmlrpc_getpostcategory($content); |
4240 $postdata['post_content'] = xmlrpc_removepostdata( $content ); |
3949 $post_content = xmlrpc_removepostdata($content); |
4241 $postdata['post_title'] = xmlrpc_getposttitle( $content ); |
3950 |
4242 $postdata['post_category'] = xmlrpc_getpostcategory( $content ); |
3951 $postdata = compact('ID', 'post_content', 'post_title', 'post_category', 'post_status', 'post_excerpt'); |
4243 $postdata['post_status'] = $actual_post['post_status']; |
3952 |
4244 $postdata['post_excerpt'] = $actual_post['post_excerpt']; |
3953 $result = wp_update_post($postdata); |
4245 |
3954 |
4246 $result = wp_update_post( $postdata ); |
3955 if ( !$result ) |
4247 |
|
4248 if ( ! $result ) { |
3956 return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be edited.')); |
4249 return new IXR_Error(500, __('For some strange yet very annoying reason, this post could not be edited.')); |
3957 |
4250 } |
3958 $this->attach_uploads( $ID, $post_content ); |
4251 $this->attach_uploads( $actual_post['ID'], $postdata['post_content'] ); |
3959 |
4252 |
|
4253 /** |
|
4254 * Fires after a post has been successfully updated via the XML-RPC Blogger API. |
|
4255 * |
|
4256 * @since 3.4.0 |
|
4257 * |
|
4258 * @param int $post_ID ID of the updated post. |
|
4259 * @param array $args An array of arguments for the post to edit. |
|
4260 */ |
3960 do_action( 'xmlrpc_call_success_blogger_editPost', $post_ID, $args ); |
4261 do_action( 'xmlrpc_call_success_blogger_editPost', $post_ID, $args ); |
3961 |
4262 |
3962 return true; |
4263 return true; |
3963 } |
4264 } |
3964 |
4265 |
3966 * Remove a post. |
4267 * Remove a post. |
3967 * |
4268 * |
3968 * @since 1.5.0 |
4269 * @since 1.5.0 |
3969 * |
4270 * |
3970 * @param array $args Method parameters. |
4271 * @param array $args Method parameters. |
3971 * @return bool True when post is deleted. |
4272 * @return bool|IXR_Error True when post is deleted. |
3972 */ |
4273 */ |
3973 function blogger_deletePost($args) { |
4274 public function blogger_deletePost($args) { |
3974 $this->escape($args); |
4275 $this->escape($args); |
3975 |
4276 |
3976 $post_ID = (int) $args[1]; |
4277 $post_ID = (int) $args[1]; |
3977 $username = $args[2]; |
4278 $username = $args[2]; |
3978 $password = $args[3]; |
4279 $password = $args[3]; |
3979 $publish = $args[4]; |
|
3980 |
4280 |
3981 if ( !$user = $this->login($username, $password) ) |
4281 if ( !$user = $this->login($username, $password) ) |
3982 return $this->error; |
4282 return $this->error; |
3983 |
4283 |
3984 do_action('xmlrpc_call', 'blogger.deletePost'); |
4284 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
4285 do_action( 'xmlrpc_call', 'blogger.deletePost' ); |
3985 |
4286 |
3986 $actual_post = get_post($post_ID,ARRAY_A); |
4287 $actual_post = get_post($post_ID,ARRAY_A); |
3987 |
4288 |
3988 if ( !$actual_post || $actual_post['post_type'] != 'post' ) |
4289 if ( !$actual_post || $actual_post['post_type'] != 'post' ) |
3989 return new IXR_Error(404, __('Sorry, no such post.')); |
4290 return new IXR_Error(404, __('Sorry, no such post.')); |
4031 * - wp_post_thumbnail |
4340 * - wp_post_thumbnail |
4032 * |
4341 * |
4033 * @since 1.5.0 |
4342 * @since 1.5.0 |
4034 * |
4343 * |
4035 * @param array $args Method parameters. Contains: |
4344 * @param array $args Method parameters. Contains: |
4036 * - blog_id |
4345 * - blog_id (unused) |
4037 * - username |
4346 * - username |
4038 * - password |
4347 * - password |
4039 * - content_struct |
4348 * - content_struct |
4040 * - publish |
4349 * - publish |
4041 * @return int |
4350 * @return int|IXR_Error |
4042 */ |
4351 */ |
4043 function mw_newPost($args) { |
4352 public function mw_newPost($args) { |
4044 $this->escape($args); |
4353 $this->escape($args); |
4045 |
4354 |
4046 $blog_ID = (int) $args[0]; |
|
4047 $username = $args[1]; |
4355 $username = $args[1]; |
4048 $password = $args[2]; |
4356 $password = $args[2]; |
4049 $content_struct = $args[3]; |
4357 $content_struct = $args[3]; |
4050 $publish = isset( $args[4] ) ? $args[4] : 0; |
4358 $publish = isset( $args[4] ) ? $args[4] : 0; |
4051 |
4359 |
4052 if ( !$user = $this->login($username, $password) ) |
4360 if ( !$user = $this->login($username, $password) ) |
4053 return $this->error; |
4361 return $this->error; |
4054 |
4362 |
4055 do_action('xmlrpc_call', 'metaWeblog.newPost'); |
4363 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
4364 do_action( 'xmlrpc_call', 'metaWeblog.newPost' ); |
4056 |
4365 |
4057 $page_template = ''; |
4366 $page_template = ''; |
4058 if ( !empty( $content_struct['post_type'] ) ) { |
4367 if ( !empty( $content_struct['post_type'] ) ) { |
4059 if ( $content_struct['post_type'] == 'page' ) { |
4368 if ( $content_struct['post_type'] == 'page' ) { |
4060 if ( $publish ) |
4369 if ( $publish ) |
4304 return new IXR_Error(500, $post_ID->get_error_message()); |
4612 return new IXR_Error(500, $post_ID->get_error_message()); |
4305 |
4613 |
4306 if ( !$post_ID ) |
4614 if ( !$post_ID ) |
4307 return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.')); |
4615 return new IXR_Error(500, __('Sorry, your entry could not be posted. Something wrong happened.')); |
4308 |
4616 |
|
4617 /** |
|
4618 * Fires after a new post has been successfully created via the XML-RPC MovableType API. |
|
4619 * |
|
4620 * @since 3.4.0 |
|
4621 * |
|
4622 * @param int $post_ID ID of the new post. |
|
4623 * @param array $args An array of arguments to create the new post. |
|
4624 */ |
4309 do_action( 'xmlrpc_call_success_mw_newPost', $post_ID, $args ); |
4625 do_action( 'xmlrpc_call_success_mw_newPost', $post_ID, $args ); |
4310 |
4626 |
4311 return strval($post_ID); |
4627 return strval($post_ID); |
4312 } |
4628 } |
4313 |
4629 |
4314 function add_enclosure_if_new( $post_ID, $enclosure ) { |
4630 /** |
|
4631 * @param integer $post_ID |
|
4632 * @param array $enclosure |
|
4633 */ |
|
4634 public function add_enclosure_if_new( $post_ID, $enclosure ) { |
4315 if ( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) { |
4635 if ( is_array( $enclosure ) && isset( $enclosure['url'] ) && isset( $enclosure['length'] ) && isset( $enclosure['type'] ) ) { |
4316 $encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] . "\n"; |
4636 $encstring = $enclosure['url'] . "\n" . $enclosure['length'] . "\n" . $enclosure['type'] . "\n"; |
4317 $found = false; |
4637 $found = false; |
4318 if ( $enclosures = get_post_meta( $post_ID, 'enclosure' ) ) { |
4638 if ( $enclosures = get_post_meta( $post_ID, 'enclosure' ) ) { |
4319 foreach ( $enclosures as $enc ) { |
4639 foreach ( $enclosures as $enc ) { |
4419 |
4747 |
4420 // Only set the menu_order if it was given. |
4748 // Only set the menu_order if it was given. |
4421 if ( isset($content_struct['wp_page_order']) ) |
4749 if ( isset($content_struct['wp_page_order']) ) |
4422 $menu_order = $content_struct['wp_page_order']; |
4750 $menu_order = $content_struct['wp_page_order']; |
4423 |
4751 |
|
4752 $page_template = null; |
4424 if ( ! empty( $content_struct['wp_page_template'] ) && 'page' == $post_type ) |
4753 if ( ! empty( $content_struct['wp_page_template'] ) && 'page' == $post_type ) |
4425 $page_template = $content_struct['wp_page_template']; |
4754 $page_template = $content_struct['wp_page_template']; |
4426 |
4755 |
4427 $post_author = $postdata['post_author']; |
4756 $post_author = $postdata['post_author']; |
4428 |
4757 |
4429 // Only set the post_author if one is set. |
4758 // Only set the post_author if one is set. |
4430 if ( isset($content_struct['wp_author_id']) && ($user->ID != $content_struct['wp_author_id']) ) { |
4759 if ( isset( $content_struct['wp_author_id'] ) ) { |
4431 switch ( $post_type ) { |
4760 // Check permissions if attempting to switch author to or from another user. |
4432 case 'post': |
4761 if ( $user->ID != $content_struct['wp_author_id'] || $user->ID != $post_author ) { |
4433 if ( !current_user_can('edit_others_posts') ) |
4762 switch ( $post_type ) { |
4434 return(new IXR_Error(401, __('You are not allowed to change the post author as this user.'))); |
4763 case 'post': |
4435 break; |
4764 if ( ! current_user_can( 'edit_others_posts' ) ) { |
4436 case 'page': |
4765 return new IXR_Error( 401, __( 'You are not allowed to change the post author as this user.' ) ); |
4437 if ( !current_user_can('edit_others_pages') ) |
4766 } |
4438 return(new IXR_Error(401, __('You are not allowed to change the page author as this user.'))); |
4767 break; |
4439 break; |
4768 case 'page': |
4440 default: |
4769 if ( ! current_user_can( 'edit_others_pages' ) ) { |
4441 return(new IXR_Error(401, __('Invalid post type'))); |
4770 return new IXR_Error( 401, __( 'You are not allowed to change the page author as this user.' ) ); |
4442 break; |
4771 } |
|
4772 break; |
|
4773 default: |
|
4774 return new IXR_Error( 401, __( 'Invalid post type' ) ); |
|
4775 break; |
|
4776 } |
|
4777 $post_author = $content_struct['wp_author_id']; |
4443 } |
4778 } |
4444 $post_author = $content_struct['wp_author_id']; |
|
4445 } |
4779 } |
4446 |
4780 |
4447 if ( isset($content_struct['mt_allow_comments']) ) { |
4781 if ( isset($content_struct['mt_allow_comments']) ) { |
4448 if ( !is_numeric($content_struct['mt_allow_comments']) ) { |
4782 if ( !is_numeric($content_struct['mt_allow_comments']) ) { |
4449 switch ( $content_struct['mt_allow_comments'] ) { |
4783 switch ( $content_struct['mt_allow_comments'] ) { |
4865 * Retrieve the list of categories on a given blog. |
5203 * Retrieve the list of categories on a given blog. |
4866 * |
5204 * |
4867 * @since 1.5.0 |
5205 * @since 1.5.0 |
4868 * |
5206 * |
4869 * @param array $args Method parameters. |
5207 * @param array $args Method parameters. |
4870 * @return array |
5208 * @return array|IXR_Error |
4871 */ |
5209 */ |
4872 function mw_getCategories($args) { |
5210 public function mw_getCategories($args) { |
4873 |
5211 |
4874 $this->escape($args); |
5212 $this->escape($args); |
4875 |
5213 |
4876 $blog_ID = (int) $args[0]; |
|
4877 $username = $args[1]; |
5214 $username = $args[1]; |
4878 $password = $args[2]; |
5215 $password = $args[2]; |
4879 |
5216 |
4880 if ( !$user = $this->login($username, $password) ) |
5217 if ( !$user = $this->login($username, $password) ) |
4881 return $this->error; |
5218 return $this->error; |
4882 |
5219 |
4883 if ( !current_user_can( 'edit_posts' ) ) |
5220 if ( !current_user_can( 'edit_posts' ) ) |
4884 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
5221 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
4885 |
5222 |
4886 do_action('xmlrpc_call', 'metaWeblog.getCategories'); |
5223 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
5224 do_action( 'xmlrpc_call', 'metaWeblog.getCategories' ); |
4887 |
5225 |
4888 $categories_struct = array(); |
5226 $categories_struct = array(); |
4889 |
5227 |
4890 if ( $cats = get_categories(array('get' => 'all')) ) { |
5228 if ( $cats = get_categories(array('get' => 'all')) ) { |
4891 foreach ( $cats as $cat ) { |
5229 foreach ( $cats as $cat ) { |
|
5230 $struct = array(); |
4892 $struct['categoryId'] = $cat->term_id; |
5231 $struct['categoryId'] = $cat->term_id; |
4893 $struct['parentId'] = $cat->parent; |
5232 $struct['parentId'] = $cat->parent; |
4894 $struct['description'] = $cat->name; |
5233 $struct['description'] = $cat->name; |
4895 $struct['categoryDescription'] = $cat->description; |
5234 $struct['categoryDescription'] = $cat->description; |
4896 $struct['categoryName'] = $cat->name; |
5235 $struct['categoryName'] = $cat->name; |
4929 $bits = $data['bits']; |
5267 $bits = $data['bits']; |
4930 |
5268 |
4931 if ( !$user = $this->login($username, $password) ) |
5269 if ( !$user = $this->login($username, $password) ) |
4932 return $this->error; |
5270 return $this->error; |
4933 |
5271 |
4934 do_action('xmlrpc_call', 'metaWeblog.newMediaObject'); |
5272 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
5273 do_action( 'xmlrpc_call', 'metaWeblog.newMediaObject' ); |
4935 |
5274 |
4936 if ( !current_user_can('upload_files') ) { |
5275 if ( !current_user_can('upload_files') ) { |
4937 $this->error = new IXR_Error( 401, __( 'You do not have permission to upload files.' ) ); |
5276 $this->error = new IXR_Error( 401, __( 'You do not have permission to upload files.' ) ); |
4938 return $this->error; |
5277 return $this->error; |
4939 } |
5278 } |
4940 |
5279 |
4941 if ( $upload_err = apply_filters( 'pre_upload_error', false ) ) |
5280 /** |
4942 return new IXR_Error(500, $upload_err); |
5281 * Filter whether to preempt the XML-RPC media upload. |
|
5282 * |
|
5283 * Passing a truthy value will effectively short-circuit the media upload, |
|
5284 * returning that value as a 500 error instead. |
|
5285 * |
|
5286 * @since 2.1.0 |
|
5287 * |
|
5288 * @param bool $error Whether to pre-empt the media upload. Default false. |
|
5289 */ |
|
5290 if ( $upload_err = apply_filters( 'pre_upload_error', false ) ) { |
|
5291 return new IXR_Error( 500, $upload_err ); |
|
5292 } |
4943 |
5293 |
4944 if ( !empty($data['overwrite']) && ($data['overwrite'] == true) ) { |
5294 if ( !empty($data['overwrite']) && ($data['overwrite'] == true) ) { |
4945 // Get postmeta info on the object. |
5295 // Get postmeta info on the object. |
4946 $old_file = $wpdb->get_row(" |
5296 $old_file = $wpdb->get_row(" |
4947 SELECT ID |
5297 SELECT ID |
5004 * Retrieve the post titles of recent posts. |
5364 * Retrieve the post titles of recent posts. |
5005 * |
5365 * |
5006 * @since 1.5.0 |
5366 * @since 1.5.0 |
5007 * |
5367 * |
5008 * @param array $args Method parameters. |
5368 * @param array $args Method parameters. |
5009 * @return array |
5369 * @return array|IXR_Error |
5010 */ |
5370 */ |
5011 function mt_getRecentPostTitles($args) { |
5371 public function mt_getRecentPostTitles($args) { |
5012 |
5372 |
5013 $this->escape($args); |
5373 $this->escape($args); |
5014 |
5374 |
5015 $blog_ID = (int) $args[0]; |
|
5016 $username = $args[1]; |
5375 $username = $args[1]; |
5017 $password = $args[2]; |
5376 $password = $args[2]; |
5018 if ( isset( $args[3] ) ) |
5377 if ( isset( $args[3] ) ) |
5019 $query = array( 'numberposts' => absint( $args[3] ) ); |
5378 $query = array( 'numberposts' => absint( $args[3] ) ); |
5020 else |
5379 else |
5021 $query = array(); |
5380 $query = array(); |
5022 |
5381 |
5023 if ( !$user = $this->login($username, $password) ) |
5382 if ( !$user = $this->login($username, $password) ) |
5024 return $this->error; |
5383 return $this->error; |
5025 |
5384 |
5026 do_action('xmlrpc_call', 'mt.getRecentPostTitles'); |
5385 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
5386 do_action( 'xmlrpc_call', 'mt.getRecentPostTitles' ); |
5027 |
5387 |
5028 $posts_list = wp_get_recent_posts( $query ); |
5388 $posts_list = wp_get_recent_posts( $query ); |
5029 |
5389 |
5030 if ( !$posts_list ) { |
5390 if ( !$posts_list ) { |
5031 $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.')); |
5391 $this->error = new IXR_Error(500, __('Either there are no posts, or something went wrong.')); |
5032 return $this->error; |
5392 return $this->error; |
5033 } |
5393 } |
5034 |
5394 |
5035 $struct = array(); |
5395 $recent_posts = array(); |
5036 |
5396 |
5037 foreach ($posts_list as $entry) { |
5397 foreach ($posts_list as $entry) { |
5038 if ( !current_user_can( 'edit_post', $entry['ID'] ) ) |
5398 if ( !current_user_can( 'edit_post', $entry['ID'] ) ) |
5039 continue; |
5399 continue; |
5040 |
5400 |
5041 $post_date = $this->_convert_date( $entry['post_date'] ); |
5401 $post_date = $this->_convert_date( $entry['post_date'] ); |
5042 $post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] ); |
5402 $post_date_gmt = $this->_convert_date_gmt( $entry['post_date_gmt'], $entry['post_date'] ); |
5043 |
5403 |
5044 $struct[] = array( |
5404 $recent_posts[] = array( |
5045 'dateCreated' => $post_date, |
5405 'dateCreated' => $post_date, |
5046 'userid' => $entry['post_author'], |
5406 'userid' => $entry['post_author'], |
5047 'postid' => (string) $entry['ID'], |
5407 'postid' => (string) $entry['ID'], |
5048 'title' => $entry['post_title'], |
5408 'title' => $entry['post_title'], |
5049 'post_status' => $entry['post_status'], |
5409 'post_status' => $entry['post_status'], |
5050 'date_created_gmt' => $post_date_gmt |
5410 'date_created_gmt' => $post_date_gmt |
5051 ); |
5411 ); |
5052 |
|
5053 } |
|
5054 |
|
5055 $recent_posts = array(); |
|
5056 for ( $j=0; $j<count($struct); $j++ ) { |
|
5057 array_push($recent_posts, $struct[$j]); |
|
5058 } |
5412 } |
5059 |
5413 |
5060 return $recent_posts; |
5414 return $recent_posts; |
5061 } |
5415 } |
5062 |
5416 |
5064 * Retrieve list of all categories on blog. |
5418 * Retrieve list of all categories on blog. |
5065 * |
5419 * |
5066 * @since 1.5.0 |
5420 * @since 1.5.0 |
5067 * |
5421 * |
5068 * @param array $args Method parameters. |
5422 * @param array $args Method parameters. |
5069 * @return array |
5423 * @return array|IXR_Error |
5070 */ |
5424 */ |
5071 function mt_getCategoryList($args) { |
5425 public function mt_getCategoryList($args) { |
5072 |
5426 |
5073 $this->escape($args); |
5427 $this->escape($args); |
5074 |
5428 |
5075 $blog_ID = (int) $args[0]; |
|
5076 $username = $args[1]; |
5429 $username = $args[1]; |
5077 $password = $args[2]; |
5430 $password = $args[2]; |
5078 |
5431 |
5079 if ( !$user = $this->login($username, $password) ) |
5432 if ( !$user = $this->login($username, $password) ) |
5080 return $this->error; |
5433 return $this->error; |
5081 |
5434 |
5082 if ( !current_user_can( 'edit_posts' ) ) |
5435 if ( !current_user_can( 'edit_posts' ) ) |
5083 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
5436 return new IXR_Error( 401, __( 'Sorry, you must be able to edit posts on this site in order to view categories.' ) ); |
5084 |
5437 |
5085 do_action('xmlrpc_call', 'mt.getCategoryList'); |
5438 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
5439 do_action( 'xmlrpc_call', 'mt.getCategoryList' ); |
5086 |
5440 |
5087 $categories_struct = array(); |
5441 $categories_struct = array(); |
5088 |
5442 |
5089 if ( $cats = get_categories(array('hide_empty' => 0, 'hierarchical' => 0)) ) { |
5443 if ( $cats = get_categories(array('hide_empty' => 0, 'hierarchical' => 0)) ) { |
5090 foreach ( $cats as $cat ) { |
5444 foreach ( $cats as $cat ) { |
|
5445 $struct = array(); |
5091 $struct['categoryId'] = $cat->term_id; |
5446 $struct['categoryId'] = $cat->term_id; |
5092 $struct['categoryName'] = $cat->name; |
5447 $struct['categoryName'] = $cat->name; |
5093 |
5448 |
5094 $categories_struct[] = $struct; |
5449 $categories_struct[] = $struct; |
5095 } |
5450 } |
5204 * |
5562 * |
5205 * @since 1.5.0 |
5563 * @since 1.5.0 |
5206 * |
5564 * |
5207 * @param array $args Method parameters. |
5565 * @param array $args Method parameters. |
5208 */ |
5566 */ |
5209 function mt_supportedTextFilters($args) { |
5567 public function mt_supportedTextFilters($args) { |
5210 do_action('xmlrpc_call', 'mt.supportedTextFilters'); |
5568 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
5211 return apply_filters('xmlrpc_text_filters', array()); |
5569 do_action( 'xmlrpc_call', 'mt.supportedTextFilters' ); |
|
5570 |
|
5571 /** |
|
5572 * Filter the MoveableType text filters list for XML-RPC. |
|
5573 * |
|
5574 * @since 2.2.0 |
|
5575 * |
|
5576 * @param array $filters An array of text filters. |
|
5577 */ |
|
5578 return apply_filters( 'xmlrpc_text_filters', array() ); |
5212 } |
5579 } |
5213 |
5580 |
5214 /** |
5581 /** |
5215 * Retrieve trackbacks sent to a given post. |
5582 * Retrieve trackbacks sent to a given post. |
5216 * |
5583 * |
5217 * @since 1.5.0 |
5584 * @since 1.5.0 |
5218 * |
5585 * |
5219 * @param array $args Method parameters. |
5586 * @param array $args Method parameters. |
5220 * @return mixed |
5587 * @return array|IXR_Error |
5221 */ |
5588 */ |
5222 function mt_getTrackbackPings($args) { |
5589 public function mt_getTrackbackPings($args) { |
5223 |
5590 |
5224 global $wpdb; |
5591 global $wpdb; |
5225 |
5592 |
5226 $post_ID = intval($args); |
5593 $post_ID = intval($args); |
5227 |
5594 |
5228 do_action('xmlrpc_call', 'mt.getTrackbackPings'); |
5595 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
5596 do_action( 'xmlrpc_call', 'mt.getTrackbackPings' ); |
5229 |
5597 |
5230 $actual_post = get_post($post_ID, ARRAY_A); |
5598 $actual_post = get_post($post_ID, ARRAY_A); |
5231 |
5599 |
5232 if ( !$actual_post ) |
5600 if ( !$actual_post ) |
5233 return new IXR_Error(404, __('Sorry, no such post.')); |
5601 return new IXR_Error(404, __('Sorry, no such post.')); |
5301 * Retrieves a pingback and registers it. |
5670 * Retrieves a pingback and registers it. |
5302 * |
5671 * |
5303 * @since 1.5.0 |
5672 * @since 1.5.0 |
5304 * |
5673 * |
5305 * @param array $args Method parameters. |
5674 * @param array $args Method parameters. |
5306 * @return array |
5675 * @return string|IXR_Error |
5307 */ |
5676 */ |
5308 function pingback_ping($args) { |
5677 public function pingback_ping($args) { |
5309 global $wpdb; |
5678 global $wpdb; |
5310 |
5679 |
5311 do_action('xmlrpc_call', 'pingback.ping'); |
5680 /** This action is documented in wp-includes/class-wp-xmlrpc-server.php */ |
|
5681 do_action( 'xmlrpc_call', 'pingback.ping' ); |
5312 |
5682 |
5313 $this->escape($args); |
5683 $this->escape($args); |
5314 |
5684 |
5315 $pagelinkedfrom = $args[0]; |
5685 $pagelinkedfrom = $args[0]; |
5316 $pagelinkedto = $args[1]; |
5686 $pagelinkedto = $args[1]; |
5317 |
|
5318 $title = ''; |
|
5319 |
5687 |
5320 $pagelinkedfrom = str_replace('&', '&', $pagelinkedfrom); |
5688 $pagelinkedfrom = str_replace('&', '&', $pagelinkedfrom); |
5321 $pagelinkedto = str_replace('&', '&', $pagelinkedto); |
5689 $pagelinkedto = str_replace('&', '&', $pagelinkedto); |
5322 $pagelinkedto = str_replace('&', '&', $pagelinkedto); |
5690 $pagelinkedto = str_replace('&', '&', $pagelinkedto); |
5323 |
5691 |
|
5692 /** |
|
5693 * Filter the pingback source URI. |
|
5694 * |
|
5695 * @since 3.6.0 |
|
5696 * |
|
5697 * @param string $pagelinkedfrom URI of the page linked from. |
|
5698 * @param string $pagelinkedto URI of the page linked to. |
|
5699 */ |
5324 $pagelinkedfrom = apply_filters( 'pingback_ping_source_uri', $pagelinkedfrom, $pagelinkedto ); |
5700 $pagelinkedfrom = apply_filters( 'pingback_ping_source_uri', $pagelinkedfrom, $pagelinkedto ); |
|
5701 |
5325 if ( ! $pagelinkedfrom ) |
5702 if ( ! $pagelinkedfrom ) |
5326 return $this->pingback_error( 0, __( 'A valid URL was not provided.' ) ); |
5703 return $this->pingback_error( 0, __( 'A valid URL was not provided.' ) ); |
5327 |
5704 |
5328 // Check if the page linked to is in our site |
5705 // Check if the page linked to is in our site |
5329 $pos1 = strpos($pagelinkedto, str_replace(array('http://www.','http://','https://www.','https://'), '', get_option('home'))); |
5706 $pos1 = strpos($pagelinkedto, str_replace(array('http://www.','http://','https://www.','https://'), '', get_option('home'))); |
5333 // let's find which post is linked to |
5710 // let's find which post is linked to |
5334 // FIXME: does url_to_postid() cover all these cases already? |
5711 // FIXME: does url_to_postid() cover all these cases already? |
5335 // if so, then let's use it and drop the old code. |
5712 // if so, then let's use it and drop the old code. |
5336 $urltest = parse_url($pagelinkedto); |
5713 $urltest = parse_url($pagelinkedto); |
5337 if ( $post_ID = url_to_postid($pagelinkedto) ) { |
5714 if ( $post_ID = url_to_postid($pagelinkedto) ) { |
5338 $way = 'url_to_postid()'; |
5715 // $way |
5339 } elseif ( preg_match('#p/[0-9]{1,}#', $urltest['path'], $match) ) { |
5716 } elseif ( isset( $urltest['path'] ) && preg_match('#p/[0-9]{1,}#', $urltest['path'], $match) ) { |
5340 // the path defines the post_ID (archives/p/XXXX) |
5717 // the path defines the post_ID (archives/p/XXXX) |
5341 $blah = explode('/', $match[0]); |
5718 $blah = explode('/', $match[0]); |
5342 $post_ID = (int) $blah[1]; |
5719 $post_ID = (int) $blah[1]; |
5343 $way = 'from the path'; |
|
5344 } elseif ( isset( $urltest['query'] ) && preg_match('#p=[0-9]{1,}#', $urltest['query'], $match) ) { |
5720 } elseif ( isset( $urltest['query'] ) && preg_match('#p=[0-9]{1,}#', $urltest['query'], $match) ) { |
5345 // the querystring defines the post_ID (?p=XXXX) |
5721 // the querystring defines the post_ID (?p=XXXX) |
5346 $blah = explode('=', $match[0]); |
5722 $blah = explode('=', $match[0]); |
5347 $post_ID = (int) $blah[1]; |
5723 $post_ID = (int) $blah[1]; |
5348 $way = 'from the querystring'; |
|
5349 } elseif ( isset($urltest['fragment']) ) { |
5724 } elseif ( isset($urltest['fragment']) ) { |
5350 // an #anchor is there, it's either... |
5725 // an #anchor is there, it's either... |
5351 if ( intval($urltest['fragment']) ) { |
5726 if ( intval($urltest['fragment']) ) { |
5352 // ...an integer #XXXX (simplest case) |
5727 // ...an integer #XXXX (simplest case) |
5353 $post_ID = (int) $urltest['fragment']; |
5728 $post_ID = (int) $urltest['fragment']; |
5354 $way = 'from the fragment (numeric)'; |
|
5355 } elseif ( preg_match('/post-[0-9]+/',$urltest['fragment']) ) { |
5729 } elseif ( preg_match('/post-[0-9]+/',$urltest['fragment']) ) { |
5356 // ...a post id in the form 'post-###' |
5730 // ...a post id in the form 'post-###' |
5357 $post_ID = preg_replace('/[^0-9]+/', '', $urltest['fragment']); |
5731 $post_ID = preg_replace('/[^0-9]+/', '', $urltest['fragment']); |
5358 $way = 'from the fragment (post-###)'; |
|
5359 } elseif ( is_string($urltest['fragment']) ) { |
5732 } elseif ( is_string($urltest['fragment']) ) { |
5360 // ...or a string #title, a little more complicated |
5733 // ...or a string #title, a little more complicated |
5361 $title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']); |
5734 $title = preg_replace('/[^a-z0-9]/i', '.', $urltest['fragment']); |
5362 $sql = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", like_escape( $title ) ); |
5735 $sql = $wpdb->prepare("SELECT ID FROM $wpdb->posts WHERE post_title RLIKE %s", $title ); |
5363 if (! ($post_ID = $wpdb->get_var($sql)) ) { |
5736 if (! ($post_ID = $wpdb->get_var($sql)) ) { |
5364 // returning unknown error '0' is better than die()ing |
5737 // returning unknown error '0' is better than die()ing |
5365 return $this->pingback_error( 0, '' ); |
5738 return $this->pingback_error( 0, '' ); |
5366 } |
5739 } |
5367 $way = 'from the fragment (title)'; |
|
5368 } |
5740 } |
5369 } else { |
5741 } else { |
5370 // TODO: Attempt to extract a post ID from the given URL |
5742 // TODO: Attempt to extract a post ID from the given URL |
5371 return $this->pingback_error( 33, __('The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.' ) ); |
5743 return $this->pingback_error( 33, __('The specified target URL cannot be used as a target. It either doesn’t exist, or it is not a pingback-enabled resource.' ) ); |
5372 } |
5744 } |
5388 if ( $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom) ) ) |
5760 if ( $wpdb->get_results( $wpdb->prepare("SELECT * FROM $wpdb->comments WHERE comment_post_ID = %d AND comment_author_url = %s", $post_ID, $pagelinkedfrom) ) ) |
5389 return $this->pingback_error( 48, __( 'The pingback has already been registered.' ) ); |
5761 return $this->pingback_error( 48, __( 'The pingback has already been registered.' ) ); |
5390 |
5762 |
5391 // very stupid, but gives time to the 'from' server to publish ! |
5763 // very stupid, but gives time to the 'from' server to publish ! |
5392 sleep(1); |
5764 sleep(1); |
|
5765 |
|
5766 $remote_ip = preg_replace( '/[^0-9a-fA-F:., ]/', '', $_SERVER['REMOTE_ADDR'] ); |
|
5767 |
|
5768 /** This filter is documented in wp-includes/class-http.php */ |
|
5769 $user_agent = apply_filters( 'http_headers_useragent', 'WordPress/' . $GLOBALS['wp_version'] . '; ' . get_bloginfo( 'url' ) ); |
5393 |
5770 |
5394 // Let's check the remote site |
5771 // Let's check the remote site |
5395 $http_api_args = array( |
5772 $http_api_args = array( |
5396 'timeout' => 10, |
5773 'timeout' => 10, |
5397 'redirection' => 0, |
5774 'redirection' => 0, |
5398 'limit_response_size' => 153600, // 150 KB |
5775 'limit_response_size' => 153600, // 150 KB |
|
5776 'user-agent' => "$user_agent; verifying pingback from $remote_ip", |
|
5777 'headers' => array( |
|
5778 'X-Pingback-Forwarded-For' => $remote_ip, |
|
5779 ), |
5399 ); |
5780 ); |
5400 $linea = wp_remote_retrieve_body( wp_safe_remote_get( $pagelinkedfrom, $http_api_args ) ); |
5781 $request = wp_safe_remote_get( $pagelinkedfrom, $http_api_args ); |
|
5782 $linea = wp_remote_retrieve_body( $request ); |
5401 |
5783 |
5402 if ( !$linea ) |
5784 if ( !$linea ) |
5403 return $this->pingback_error( 16, __( 'The source URL does not exist.' ) ); |
5785 return $this->pingback_error( 16, __( 'The source URL does not exist.' ) ); |
5404 |
5786 |
5405 $linea = apply_filters('pre_remote_source', $linea, $pagelinkedto); |
5787 /** |
|
5788 * Filter the pingback remote source. |
|
5789 * |
|
5790 * @since 2.5.0 |
|
5791 * |
|
5792 * @param string $linea Response object for the page linked from. |
|
5793 * @param string $pagelinkedto URL of the page linked to. |
|
5794 */ |
|
5795 $linea = apply_filters( 'pre_remote_source', $linea, $pagelinkedto ); |
5406 |
5796 |
5407 // Work around bug in strip_tags(): |
5797 // Work around bug in strip_tags(): |
5408 $linea = str_replace('<!DOC', '<DOC', $linea); |
5798 $linea = str_replace('<!DOC', '<DOC', $linea); |
5409 $linea = preg_replace( '/[\r\n\t ]+/', ' ', $linea ); // normalize spaces |
5799 $linea = preg_replace( '/[\r\n\t ]+/', ' ', $linea ); // normalize spaces |
5410 $linea = preg_replace( "/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/", "\n\n", $linea ); |
5800 $linea = preg_replace( "/<\/*(h1|h2|h3|h4|h5|h6|p|th|td|li|dt|dd|pre|caption|input|textarea|button|body)[^>]*>/", "\n\n", $linea ); |