I would like to use some of the methods of the XML RPC class, "wp_xmlrpc_server" in my own class. Is this class instantiated already or should I declare it myself? If so how?


So far as I know, the XML RPC class is not instantiated unless needed, which is when the request is to /xmlrpc.php.

You would instantiate the class the same way the Core does:

include_once(ABSPATH . 'wp-admin/includes/admin.php');
include_once(ABSPATH . WPINC . '/class-IXR.php');
include_once(ABSPATH . WPINC . '/class-wp-xmlrpc-server.php');

  * Posts submitted via the XML-RPC interface get that title
  * @name post_default_title
  * @var string
$post_default_title = "";

  * Filter the class used for handling XML-RPC requests.
  * @since 3.1.0
  * @param string The name of the XML-RPC server class.
$wp_xmlrpc_server_class = apply_filters( 'wp_xmlrpc_server_class', 'wp_xmlrpc_server' );
$wp_xmlrpc_server = new $wp_xmlrpc_server_class;

You have two options for doing that:

  1. Create a method inside your class to instantiate the XML RPC class, and save the instance to a class variable.
  2. Instantiate outside of the class and pass the instance to your class. This is something called "dependency injection", which has both pros and cons.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.