据我所知,除非需要,否则不会实例化XML RPC类,这是在请求/xmlrpc.php
.
您将以与Core相同的方式实例化该类:
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;
您有两种选择:
在类中创建一个方法来实例化XML RPC类,并将实例保存到类变量中在类外实例化并将实例传递给类。这就是所谓的“dependency injection“,这既有优点也有缺点。