Completed
Push — add/alternative-xmlrpc-transpo... ( cc1c51...391502 )
by
unknown
15:08 queued 07:15
created

Jetpack_XMLRPC_Fallback::xmlrpc_fallback()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
1
<?php 
2
3
/**
4
 * A bridge between WP's built-in REST and Jetpack's XMLRPC server
5
 */
6
class Jetpack_XMLRPC_Fallback {
7
    private $xmlrpc_server;
8
9
    function init() {
10
        register_rest_route( 'jetpack/v1', '/verify_registration', array(
11
			'methods' => 'POST',
12
			'callback' => array( $this, 'verify_registration' ),
13
		) );
14
15
        // fallback for anything not yet converted
16
        register_rest_route( 'jetpack/v1', '/xmlrpc', array(
17
			'methods' => 'POST',
18
			'callback' => array( $this, 'xmlrpc_fallback' ),
19
		) );
20
    }
21
22
    function verify_registration( $request ) {
23
        $this->load_xmlrpc();
24
		return $this->xmlrpc_server->verify_registration( array( $request['secret_1'], $request['state'] ) );
25
	}
26
27
    // allow invocation of Jetpack XMLRPC, and a handful of core XMLRPC methods, over REST
28
    // does NOT allow random XMLRPC requests
29
    function xmlrpc_fallback( $request ) {
30
        $this->load_xmlrpc();
31
        $methods = $this->xmlrpc->xmlrpc_methods();
0 ignored issues
show
Bug introduced by
The property xmlrpc does not seem to exist. Did you mean xmlrpc_server?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
32
        error_log("xmlrpc fallback");
33
        error_log(print_r($methods,1));
34
    }
35
36
    private function load_xmlrpc() {
37
        if ( ! $this->xmlrpc_server ) {
38
            require_once JETPACK__PLUGIN_DIR . 'class.jetpack-xmlrpc-server.php';
39
            $this->xmlrpc_server = new Jetpack_XMLRPC_Server();
40
        }
41
    }
42
}