Possible to filter the posts or categories that XML-RPC users see in their mobile application?

Is it possible to filter the posts or categories that XML-RPC users see in their mobile application?

I have a plugin that hooks into pre_get_posts and list_terms_exclusions to do what I need it to do. I’ve had requests to allow the same functionality on their mobile devices.

Related posts

Leave a Reply

3 comments

  1. This github repo has bdn.getPosts extended XML-RPC function to get category.

    Get 10 most recently modified posts in the sports category ($category can be either a slug or an ID)

       `array( 1, $username, $password, 'post', 'sports', 10, array( 'orderby' => 'modified' ) );`
    
  2. I have not actually experimented with it myself but when I cracked open the xmlrpc.php file I noticed several do actions for xmlrpc_call.

    I suspect that you could add actions based on user type to the xmlrpc call.
    E.g. blogger_getPost() can be hooked with xmlrpc_call when xmlrpc_call == blogger.getPost.

  3. Okay, so I discovered the answer to my question.

    It is possible to filter the posts and categories that users see in their XML-RPC application. The pre_get_posts and list_terms_exclusions filters are called via the blogger.getRecentPosts XML-RPC method. Inside this function, it calls wp_get_recent_posts which uses get_posts. In other words, there’s really nothing special you have to do if you are hooking into the above filters.

    My problem was that for my plugin, I was only filtering while in the admin: if ( is_admin()

    SOLUTION

    In order to make sure it only fires when requested through an XML-RPC application, all you have to do is check for the XMLRPC_REQUEST constant and hook into the xmlrpc_call action.

    if ( defined ( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) {
        add_action( 'xmlrpc_call', array( &$this, 'posts' ) );
    }
    

    Inside your callback, hook into the pre_get_posts and list_terms_exclusions filters.