Is it possible to change a blog’s theme through XML-RPC command? (and if so how?)

I can’t seem to find such an option listed here:

http://codex.wordpress.org/XML-RPC_wp#wp.setOptions

Does it exist?

Thanks.

2 Answers
2

No, that option does not currently exist through XML-RPC. However, you can always create your own method in a plugin and hook it up to XML-RPC.


Update

There’s an upcoming Google Summer of Code project that will be extending the XML-RPC interface to allow direct manipulation of themes, so I won’t give away code to implement that here. But keep your ears and eyes open for when new code (core changes and/or plugins) start releasing this summer.

In the meantime, I will provide an alternative. The set of options that you can view and set through XML-RPC is filterable. Basically, you can tell the system to give you more information than it normally would.

What you can already get (bold options are read only … you can’t change them with wp.setOptions but you can retrieve them with wp.getOptions):

  • software_name
  • software_version
  • blog_url
  • content_width
  • time_zone
  • blog_title
  • blog_tagline
  • date_format
  • time_format
  • users_can_register
  • thumbnail_size_w
  • thumbnail_size_h
  • thumbnail_crop
  • medium_size_w
  • medium_size_h
  • large_size_w
  • large_size_h

This list (actually, an array with other settings), is passed through the xmlrpc_blog_options filter, which means you can add and remove to this list all you want. To enable the fetching of the current theme by wp.getOptions and the changing of the theme by wp.setOptions you’d use the following:

function allow_xmlrpc_theme_changes( $xmlrpcoptions ) {
    $xmlrpcoptions['active-theme'] = array(
        'desc'            => __( 'Active site theme' ),
        'readonly'        => false,
        'option'          => 'template'
    );

    $xmlrpcoptions['active-stylesheet'] = array(
        'desc'            => __( 'Active site stylesheet' ),
        'readonly'        => false,
        'option'          => 'stylesheet'
    );

    return $xmlrpcoptions
}

add_filter( 'xmlrpc_blog_options', 'allow_xmlrpc_theme_changes' );

This adds two fields that you can set: “active-theme” and “active-stylesheet”.

Remember, you’ll be setting these options the same way as you would using update_option(), so double check the codex before doing anything.

Leave a Comment