PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.3
Jetpack – WP Security, Backup, Speed, & Growth v16.3
16.3 16.3-beta 16.3-a.5 16.3-a.7 16.3-a.3 16.3-a.1 16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 All 508 releases
← All changes | jetpack_vendor/automattic/jetpack-stats/src/class-xmlrpc-provider.php +125 -0 16.2-beta → 16.3 View file →
@@ -1,0 +1,125 @@
1 +<?php
2 +/**
3 + * The Stats XMLRPC Provider class
4 + *
5 + * @package automattic/jetpack-stats
6 + */
7 +
8 +namespace Automattic\Jetpack\Stats;
9 +
10 +use Automattic\Jetpack\Connection\Manager as Connection_Manager;
11 +use Automattic\Jetpack\Modules;
12 +
13 +/**
14 + * Stats XMLRPC Provider.
15 + *
16 + * Adds additional methods to the WordPress XML-RPC API for handling Stats specific features.
17 + *
18 + * @since 0.1.0
19 + */
20 +class XMLRPC_Provider {
21 +
22 + /**
23 + * Singleton XMLRPC_Provider instance.
24 + *
25 + * @var XMLRPC_Provider
26 + **/
27 + private static $instance = null;
28 +
29 + /**
30 + * Private XMLRPC_Provider constructor.
31 + *
32 + * Use the XMLRPC_Provider::init() method to get an instance.
33 + */
34 + private function __construct() {
35 + add_filter( 'jetpack_xmlrpc_unauthenticated_methods', array( $this, 'xmlrpc_methods' ), 10, 3 );
36 + }
37 +
38 + /**
39 + * Initialize class and get back a singleton instance.
40 + *
41 + * @param bool $new_instance Force create new instance.
42 + *
43 + * @return XMLRPC_Provider
44 + */
45 + public static function init( $new_instance = false ) {
46 + if ( null === self::$instance || $new_instance ) {
47 + self::$instance = new XMLRPC_Provider();
48 + }
49 +
50 + return self::$instance;
51 + }
52 +
53 + /**
54 + * Adds additional methods to the WordPress xmlrpc API for handling Stats specific features.
55 + *
56 + * @param array $methods The Jetpack API methods.
57 + *
58 + * @return array
59 + */
60 + public function xmlrpc_methods( $methods ) {
61 + if ( ! ( new Connection_Manager() )->is_connected() ) {
62 + return $methods;
63 + }
64 +
65 + if ( ! ( new Modules() )->is_active( 'stats' ) ) {
66 + return $methods;
67 + }
68 +
69 + $methods['jetpack.getBlog'] = array( $this, 'get_blog' );
70 +
71 + return $methods;
72 + }
73 +
74 + /**
75 + * Stats Get Blog.
76 + *
77 + * @return array
78 + */
79 + public function get_blog() {
80 + $home = wp_parse_url( trailingslashit( get_option( 'home' ) ) );
81 + $blog = array(
82 + 'host' => $home['host'],
83 + 'path' => $home['path'],
84 + 'blogname' => get_option( 'blogname' ),
85 + 'blogdescription' => get_option( 'blogdescription' ),
86 + 'siteurl' => get_option( 'siteurl' ),
87 + 'gmt_offset' => get_option( 'gmt_offset' ),
88 + 'timezone_string' => get_option( 'timezone_string' ),
89 + 'stats_version' => Main::STATS_VERSION,
90 + 'stats_api' => 'jetpack',
91 + 'page_on_front' => get_option( 'page_on_front' ),
92 + 'permalink_structure' => get_option( 'permalink_structure' ),
93 + 'category_base' => get_option( 'category_base' ),
94 + 'tag_base' => get_option( 'tag_base' ),
95 + );
96 + $blog = array_merge( Options::get_options(), $blog );
97 + unset( $blog['roles'], $blog['blog_id'] );
98 +
99 + $blog = map_deep(
100 + $blog,
101 + function ( $value ) {
102 + return is_string( $value ) ? esc_html( $value ) : $value;
103 + }
104 + );
105 +
106 + return $blog;
107 + }
108 +
109 + /**
110 + * Make sure we are only escaping html if the input is a string.
111 + * Used for `esc_html` filter-hook.
112 + *
113 + * @deprecated since 0.20.3
114 + * @param string $safe_text The output after esc_html has been applied.
115 + * @param mixed $text The initial input.
116 + * @return mixed
117 + */
118 + public function filter_esc_html_check_if_string( $safe_text, $text ) {
119 + if ( is_string( $text ) ) {
120 + return $safe_text;
121 + }
122 +
123 + return $text;
124 + }
125 +}