Make WordPress Core

Opened 15 years ago

Closed 14 years ago

#14868 closed defect (bug) (worksforme)

Inconsistent return type calling wp.newCategory method via XML-RPC

Reported by: mwidmann's profile mwidmann Owned by:
Milestone: Priority: normal
Severity: normal Version: 3.0.1
Component: XML-RPC Keywords:
Focuses: Cc:

Description

Calling the XML-RPC method wp.newCategory doesn't always return int as described in the Codex or the inline documentation, but also returns string values with the new ids.

Example call:

<?xml version="1.0"?>
<methodCall>
  <methodName>wp.newCategory</methodName>
  <params>
    <param>
      <value>
        <string>1</string>
      </value>
    </param>
    <param>
      <value>
        <string>USERNAME</string>
      </value>
    </param>
    <param>
      <value>
        <string>PASSWORD</string>
      </value>
    </param>
    <param>
      <value>
        <struct>
          <member>
            <name>name</name>
            <value>
              <string>vol</string>
            </value>
          </member>
          <member>
            <name>parent_id</name>
            <value>
              <string>0</string>
            </value>
          </member>
          <member>
            <name>description</name>
            <value>
              <string />
            </value>
          </member>
        </struct>
      </value>
    </param>
  </params>
</methodCall>

You can call it using wget on the shell like this:

 $ wget -S -O - --post-file=/tmp/post-body.txt http://URL_TO_YOUR_3.0.1_INSTALLATION/xmlrpc.php

The Response will look like this:

<?xml version="1.0"?>
<methodResponse>
  <params>
    <param>
      <value>
        <string>7</string>
      </value>
    </param>
  </params>
</methodResponse>

If you call it a second time it will return the category id for the existing category in this form:

<?xml version="1.0"?>
<methodResponse>
  <params>
    <param>
      <value>
        <int>7</int>
      </value>
    </param>
  </params>
</methodResponse>

I'm trying to write an import application using C# using xml-rpc.net to migrate ~1k categories and ~800k contents to WordPress and this is a bit of a blocker for me.

The easiest fix could be to just replace line 946 in xmlrpc.php with

return (int) $cat_id;

In order to always return int

In the meanwhile I'll extend xmlrpc_methods with a copy of the method and the fix.

Change History (3)

#1 @redsweater
15 years ago

It's worth considering that changing the return type could cause problems for existing clients that expect the returned value to be a string.

I just tested with my client, MarsEdit, and it's fine either way. But before changing it, you might consider whether clients such as Windows Live Writer, Blogo, ecto, and the official WordPress clients continue to work as expected.

#2 @mwidmann
15 years ago

Sure, but those clients must accept either int or string as well as the method returns an int with the ID if the category you want to create already exists for the given parent.

It would be interesting to see how those clients behave if a category is created in the web administration interface and the same category is created using one of those clients. It could also be that this type inconsistency has been created with the fix for #14067

#3 @westi
14 years ago

  • Milestone Awaiting Review deleted
  • Resolution set to worksforme
  • Status changed from new to closed

Tested on trunk and it returns an int every time.

Note: See TracTickets for help on using tickets.