1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
|
4
|
|
|
require_once dirname( __FILE__ ) . '/class.json-api-site-base.php'; |
5
|
|
|
|
6
|
|
|
abstract class Abstract_Jetpack_Site extends SAL_Site { |
7
|
|
|
abstract protected function get_constant( $name ); |
8
|
|
|
|
9
|
|
|
abstract protected function current_theme_supports( $feature_name ); |
10
|
|
|
|
11
|
|
|
abstract protected function get_theme_support( $feature_name ); |
12
|
|
|
|
13
|
|
|
abstract protected function get_mock_option( $name ); |
14
|
|
|
|
15
|
|
|
abstract protected function get_jetpack_version(); |
16
|
|
|
|
17
|
|
|
function before_render() { |
18
|
|
|
} |
19
|
|
|
|
20
|
|
|
function after_render( &$response ) { |
21
|
|
|
// Add the updates only make them visible if the user has manage options permission and the site is the main site of the network |
22
|
|
|
if ( current_user_can( 'manage_options' ) && $this->is_main_site( $response ) ) { |
23
|
|
|
$jetpack_update = (array) get_option( 'jetpack_updates' ); |
24
|
|
|
if ( ! empty( $jetpack_update ) ) { |
25
|
|
|
// In previous version of Jetpack 3.4, 3.5, 3.6 we synced the wp_version into to jetpack_updates |
26
|
|
|
unset( $jetpack_update['wp_version'] ); |
27
|
|
|
// In previous version of Jetpack 3.4, 3.5, 3.6 we synced the site_is_version_controlled into to jetpack_updates |
28
|
|
|
unset( $jetpack_update['site_is_version_controlled'] ); |
29
|
|
|
|
30
|
|
|
$response['updates'] = (array) $jetpack_update; |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
function after_render_options( &$options ) { |
36
|
|
|
$options['jetpack_version'] = $this->get_jetpack_version(); |
37
|
|
|
|
38
|
|
|
if ( $main_network_site = $this->get_mock_option( 'main_network_site' ) ) { |
39
|
|
|
$options['main_network_site'] = (string) rtrim( $main_network_site, '/' ); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if ( is_array( $active_modules = Jetpack_Options::get_option( 'active_modules' ) ) ) { |
43
|
|
|
$options['active_modules'] = (array) array_values( $active_modules ); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$options['software_version'] = (string) $this->get_mock_option( 'wp_version' ); |
47
|
|
|
$options['max_upload_size'] = $this->get_mock_option( 'max_upload_size', false ); |
|
|
|
|
48
|
|
|
|
49
|
|
|
// Sites have to prove that they are not main_network site. |
50
|
|
|
// If the sync happends right then we should be able to see that we are not dealing with a network site |
51
|
|
|
$options['is_multi_network'] = (bool) $this->get_mock_option( 'is_main_network', true ); |
|
|
|
|
52
|
|
|
$options['is_multi_site'] = (bool) $this->get_mock_option( 'is_multi_site', true ); |
|
|
|
|
53
|
|
|
|
54
|
|
|
$file_mod_disabled_reasons = array_keys( array_filter( array( |
55
|
|
|
'automatic_updater_disabled' => (bool) $this->get_constant( 'AUTOMATIC_UPDATER_DISABLED' ), |
56
|
|
|
// WP AUTO UPDATE CORE defaults to minor, '1' if true and '0' if set to false. |
57
|
|
|
'wp_auto_update_core_disabled' => ! ( (bool) $this->get_constant( 'WP_AUTO_UPDATE_CORE' ) ), |
58
|
|
|
'is_version_controlled' => (bool) $this->get_mock_option( 'is_version_controlled' ), |
59
|
|
|
// By default we assume that site does have system write access if the value is not set yet. |
60
|
|
|
'has_no_file_system_write_access' => ! (bool) ( $this->get_mock_option( 'has_file_system_write_access' ) ), |
61
|
|
|
'disallow_file_mods' => (bool) $this->get_constant( 'DISALLOW_FILE_MODS' ), |
62
|
|
|
) ) ); |
63
|
|
|
|
64
|
|
|
$options['file_mod_disabled'] = empty( $file_mod_disabled_reasons ) ? false : $file_mod_disabled_reasons; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
function get_jetpack_modules() { |
68
|
|
|
if ( is_user_member_of_blog() ) { |
69
|
|
|
return array_values( Jetpack_Options::get_option( 'active_modules', array() ) ); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
return null; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
function is_vip() { |
76
|
|
|
return false; // this may change for VIP Go sites, which sync using Jetpack |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
function is_multisite() { |
80
|
|
|
return (bool) $this->get_mock_option( 'is_multi_site' ); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
function is_single_user_site() { |
84
|
|
|
return (bool) $this->get_mock_option( 'single_user_site' ); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
function featured_images_enabled() { |
88
|
|
|
return $this->current_theme_supports( 'post-thumbnails' ); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
function get_post_formats() { |
92
|
|
|
// deprecated - see separate endpoint. get a list of supported post formats |
93
|
|
|
$all_formats = get_post_format_strings(); |
94
|
|
|
$supported = $this->get_theme_support( 'post-formats' ); |
95
|
|
|
|
96
|
|
|
$supported_formats = array(); |
97
|
|
|
|
98
|
|
View Code Duplication |
if ( isset( $supported[0] ) ) { |
99
|
|
|
foreach ( $supported[0] as $format ) { |
100
|
|
|
$supported_formats[ $format ] = $all_formats[ $format ]; |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $supported_formats; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Private methods |
109
|
|
|
**/ |
110
|
|
|
|
111
|
|
|
private function is_main_site( $response ) { |
112
|
|
|
if ( isset( $response['options']['main_network_site'], $response['options']['unmapped_url'] ) ) { |
113
|
|
|
$main_network_site_url = set_url_scheme( $response['options']['main_network_site'], 'http' ); |
114
|
|
|
$unmapped_url = set_url_scheme( $response['options']['unmapped_url'], 'http' ); |
115
|
|
|
if ( $unmapped_url === $main_network_site_url ) { |
116
|
|
|
return true; |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
return false; |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.