WP JSON RPC API

Wow, that’s a lot of acronyms! Here’s my current version of the plugin:

Download

To see what it’s about, please see this WordPress trac ticket..

I’ll add it to the WP plugins repository as soon as I make sure it works with 3.1 and has a sample use case I can release.

A typical call:

// in JS (check that wpJSON is defined somewhere prior)
wpJSON.request(
   'myplugindomain.someRPCMethodNameHere', 
   {parameterName:'parameter value'}, 
   function ( result ) { 
          // handle the successful result object here
   },
   function( code, error, data ) { 
      // handle the error object here
   }
);

On the server side of your plugin, you can do something like this:

class My_Plugin_Control_Class {
   public function __construct()
   {
          add_filter('json_server_classname', array(&$this, 'filter_json_server_classname'), 10, 2);
   }

   public function filter_json_server_classname( $server_class = '', $method = '' )
   {
      switch( $method ) :
         case 'myplugindomain.someRPCMethodNameHere' : 
         case 'myplugindomain.someOtherRPCMethodNameHere' :
            $server_class = 'My_Plugin_JSON_RPC_Server';
         break;
      endswitch;
      return $server_class;
   }
}

// instantiate your control class somewhere

// extend the JSON class

class My_Plugin_JSON_RPC_Server extends WP_JSON_RPC_Server {
    
   public function __construct()
   {
      $this->methods['myplugindomain.someRPCMethodNameHere'] = 'this:someRPCMethodNameHere';
      $this->methods['myplugindomain.someOtherRPCMethodNameHere'] = 'this:someOtherRPCMethodNameHere';
   }

   public function someRPCMethodNameHere( $args )
   {
      if ( isset( $args->{'parameterName'} ) ) {
         // let's do something with this data!

         return array(
            'response-param-name' => __('We did something!', 'my-fancy-plugin'),
         );
      } else {
         return new WP_Error(
            -32602,
            __('Invalid method parameters:  myplugindomain.someRPCMethodNameHere must receive a value in the parameterName parameter.', 'my-fancy-plugin')

         );
      }
   }

   ...
}

9 Comments

  1. Supposing you want to remain buddies with her, you go to your buddy that drawn the vanishing act and say, “Hey, I experience like I never see you anymore. Kamagra Australia

  2. You activate it, and if you allp get attachment image and related functions for an attachment that doesn’t have that size, WordPress will create it on demand

  3. You activate it, and if you allp get attachment image and related functions for an.
    reference link

  4. It has no way of it. But there is another aspect of interest that not only can understand it, but already knows about it. There is a saying in the Zen customized, “Birth and lack of way of life are the outstanding problem. criminal defense lawyer

  5. But there is another aspect of interest that not only can understand it,

  6. The body or framework of a paper is intended to paid essay writers points that make the thesis more convincing. These supporting paragraphs should include the most compelling information from the papers resources.

  7. The item is to block or catch opposite activity items or to catch larger areas the activity panel. Monopoly and pieces are both examples of the technique activity. Strategy alone does not guarantee success. Free Itunes Codes

  8. The most important single ingredient in the formula of success is knowing how to get along with people. National House Buyers

  9. Monopoly and pieces are both examples of the technique activity. Strategy alone does not guarantee success. paragnost

Post a Comment

Your email is never shared. Required fields are marked *

*
*