Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Introduce minimum_args() method in XML-RPC and leverage it to return …

…errors for insufficient arguments for methods that are new in 3.4.

props maxcutler,  markoheijnen.
fixes #20394.



git-svn-id: http://svn.automattic.com/wordpress/trunk@20636 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information...
commit ae772d38505a936e6caf7561e63801f6c180e5e5 1 parent 1627408
nacin authored
Showing with 60 additions and 0 deletions.
  1. +60 −0 wp-includes/class-wp-xmlrpc-server.php
View
60 wp-includes/class-wp-xmlrpc-server.php
@@ -490,6 +490,24 @@ function wp_getUsersBlogs( $args ) {
return $struct;
}
+ /**
+ * Checks if the method received at least the minimum number of arguments.
+ *
+ * @since 3.4
+ *
+ * @param string|array $args Sanitize single string or array of strings.
+ * @param int $count Minimum number of arguments.
+ * @return boolean if $args contains at least $count arguments.
+ */
+ protected function minimum_args( $args, $count ) {
+ if ( count( $args ) < $count ) {
+ $this->error = new IXR_Error( 400, __( 'Insufficient arguments passed to this XML-RPC method.' ) );
+ return false;
+ }
+
+ return true;
+ }
+
/**
* Prepares taxonomy data for return in an XML-RPC object.
*
@@ -766,6 +784,9 @@ protected function _prepare_media_item( $media_item, $thumbnail_size='thumbnail'
* @return string post_id
*/
function wp_newPost( $args ) {
+ if ( ! $this->minimum_args( $args, 4 ) )
+ return $this->error;
+
$this->escape( $args );
$blog_id = (int) $args[0];
@@ -1038,6 +1059,9 @@ protected function _insert_post( $user, $content_struct ) {
* @return true on success
*/
function wp_editPost( $args ) {
+ if ( ! $this->minimum_args( $args, 5 ) )
+ return $this->error;
+
$this->escape( $args );
$blog_id = (int) $args[0];
@@ -1090,6 +1114,9 @@ function wp_editPost( $args ) {
* @return true on success
*/
function wp_deletePost( $args ) {
+ if ( ! $this->minimum_args( $args, 4 ) )
+ return $this->error;
+
$this->escape( $args );
$blog_id = (int) $args[0];
@@ -1163,6 +1190,9 @@ function wp_deletePost( $args ) {
* - 'enclosure'
*/
function wp_getPost( $args ) {
+ if ( ! $this->minimum_args( $args, 4 ) )
+ return $this->error;
+
$this->escape( $args );
$blog_id = (int) $args[0];
@@ -1217,6 +1247,9 @@ function wp_getPost( $args ) {
* @return array contains a collection of posts.
*/
function wp_getPosts( $args ) {
+ if ( ! $this->minimum_args( $args, 3 ) )
+ return $this->error;
+
$this->escape( $args );
$blog_id = (int) $args[0];
@@ -1303,6 +1336,9 @@ function wp_getPosts( $args ) {
* @return string term_id
*/
function wp_newTerm( $args ) {
+ if ( ! $this->minimum_args( $args, 4 ) )
+ return $this->error;
+
$this->escape( $args );
$blog_id = (int) $args[0];
@@ -1387,6 +1423,9 @@ function wp_newTerm( $args ) {
* @return bool True, on success.
*/
function wp_editTerm( $args ) {
+ if ( ! $this->minimum_args( $args, 5 ) )
+ return $this->error;
+
$this->escape( $args );
$blog_id = (int) $args[0];
@@ -1476,6 +1515,9 @@ function wp_editTerm( $args ) {
* @return boolean|IXR_Error If it suceeded true else a reason why not
*/
function wp_deleteTerm( $args ) {
+ if ( ! $this->minimum_args( $args, 5 ) )
+ return $this->error;
+
$this->escape( $args );
$blog_id = (int) $args[0];
@@ -1540,6 +1582,9 @@ function wp_deleteTerm( $args ) {
* - 'count'
*/
function wp_getTerm( $args ) {
+ if ( ! $this->minimum_args( $args, 5 ) )
+ return $this->error;
+
$this->escape( $args );
$blog_id = (int) $args[0];
@@ -1590,6 +1635,9 @@ function wp_getTerm( $args ) {
* @return array terms
*/
function wp_getTerms( $args ) {
+ if ( ! $this->minimum_args( $args, 4 ) )
+ return $this->error;
+
$this->escape( $args );
$blog_id = (int) $args[0];
@@ -1662,6 +1710,9 @@ function wp_getTerms( $args ) {
* @return array (@see get_taxonomy())
*/
function wp_getTaxonomy( $args ) {
+ if ( ! $this->minimum_args( $args, 4 ) )
+ return $this->error;
+
$this->escape( $args );
$blog_id = (int) $args[0];
@@ -1703,6 +1754,9 @@ function wp_getTaxonomy( $args ) {
* @return array taxonomies
*/
function wp_getTaxonomies( $args ) {
+ if ( ! $this->minimum_args( $args, 3 ) )
+ return $this->error;
+
$this->escape( $args );
$blog_id = (int) $args[0];
@@ -3009,6 +3063,9 @@ function wp_getPostFormats( $args ) {
* - 'supports'
*/
function wp_getPostType( $args ) {
+ if ( ! $this->minimum_args( $args, 4 ) )
+ return $this->error;
+
$this->escape( $args );
$blog_id = (int) $args[0];
@@ -3052,6 +3109,9 @@ function wp_getPostType( $args ) {
* @return array
*/
function wp_getPostTypes( $args ) {
+ if ( ! $this->minimum_args( $args, 3 ) )
+ return $this->error;
+
$this->escape( $args );
$blog_id = (int) $args[0];
Please sign in to comment.
Something went wrong with that request. Please try again.