Completed
Push — add/gutenberg-vr-shortcode ( a89166...c66504 )
by
unknown
10:35
created

Abstract_Jetpack_Site::wp_memory_limit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
require_once dirname( __FILE__ ) . '/class.json-api-site-base.php';
3
4
abstract class Abstract_Jetpack_Site extends SAL_Site {
5
	abstract protected function get_constant( $name );
6
7
	abstract protected function current_theme_supports( $feature_name );
8
9
	abstract protected function get_theme_support( $feature_name );
10
11
	abstract protected function get_mock_option( $name );
12
13
	abstract public function get_jetpack_version();
14
15
	abstract public function get_updates();
16
17
	abstract protected function main_network_site();
18
19
	abstract protected function wp_version();
20
21
	abstract protected function max_upload_size();
22
23
	abstract protected function is_main_network();
24
25
	abstract protected function is_version_controlled();
26
27
	abstract protected function file_system_write_access();
28
29
	function before_render() {
30
	}
31
32
	function after_render( &$response ) {
33
		// Add the updates only make them visible if the user has manage options permission and the site is the main site of the network
34
		if ( current_user_can( 'manage_options' ) && $this->is_main_site( $response ) ) {
35
			$jetpack_update = $this->get_updates();
36
			if ( ! empty( $jetpack_update ) ) {
37
				// In previous version of Jetpack 3.4, 3.5, 3.6 we synced the wp_version into to jetpack_updates
38
				unset( $jetpack_update['wp_version'] );
39
				// In previous version of Jetpack 3.4, 3.5, 3.6 we synced the site_is_version_controlled into to jetpack_updates
40
				unset( $jetpack_update['site_is_version_controlled'] );
41
42
				$response['updates'] = $jetpack_update;
43
			}
44
		}
45
	}
46
47
	function after_render_options( &$options ) {
48
49
		$options['jetpack_version'] = $this->get_jetpack_version();
50
51
		if ( $main_network_site = $this->main_network_site() ) {
52
			$options['main_network_site'] = (string) rtrim( $main_network_site, '/' );
53
		}
54
55
		if ( is_array( $active_modules = Jetpack_Options::get_option( 'active_modules' ) ) ) {
56
			$options['active_modules'] = (array) array_values( $active_modules );
57
		}
58
59
		$options['software_version'] = (string) $this->wp_version();
60
		$options['max_upload_size']  = $this->max_upload_size();
61
		$options['wp_memory_limit']  = $this->wp_memory_limit();
62
		$options['wp_max_memory_limit']  = $this->wp_max_memory_limit();
63
64
		// Sites have to prove that they are not main_network site.
65
		// If the sync happends right then we should be able to see that we are not dealing with a network site
66
		$options['is_multi_network'] = (bool) $this->is_main_network();
67
		$options['is_multi_site']    = (bool) $this->is_multisite();
68
69
		$file_mod_disabled_reasons = array_keys( array_filter( array(
70
			'automatic_updater_disabled'      => (bool) $this->get_constant( 'AUTOMATIC_UPDATER_DISABLED' ),
71
			// WP AUTO UPDATE CORE defaults to minor, '1' if true and '0' if set to false.
72
			'wp_auto_update_core_disabled'    => ! ( (bool)  $this->get_constant( 'WP_AUTO_UPDATE_CORE' ) ),
73
			'is_version_controlled'           => (bool) $this->is_version_controlled(),
74
			// By default we assume that site does have system write access if the value is not set yet.
75
			'has_no_file_system_write_access' => ! (bool) $this->file_system_write_access(),
76
			'disallow_file_mods'              => (bool)  $this->get_constant( 'DISALLOW_FILE_MODS' ),
77
		) ) );
78
79
		$options['file_mod_disabled'] = empty( $file_mod_disabled_reasons ) ? false : $file_mod_disabled_reasons;
80
	}
81
82
	function get_jetpack_modules() {
83
		if ( is_user_member_of_blog() ) {
84
			return array_values( Jetpack_Options::get_option( 'active_modules', array() ) );
85
		}
86
87
		return null;
88
	}
89
90
	function is_vip() {
91
		return false; // this may change for VIP Go sites, which sync using Jetpack
92
	}
93
94
	function featured_images_enabled() {
95
		return $this->current_theme_supports( 'post-thumbnails' );
96
	}
97
98
	function get_post_formats() {
99
		// deprecated - see separate endpoint. get a list of supported post formats
100
		$all_formats = get_post_format_strings();
101
		$supported   = $this->get_theme_support( 'post-formats' );
102
103
		$supported_formats = array();
104
105 View Code Duplication
		if ( isset( $supported[0] ) ) {
106
			foreach ( $supported[0] as $format ) {
107
				$supported_formats[ $format ] = $all_formats[ $format ];
108
			}
109
		}
110
111
		return $supported_formats;
112
	}
113
114
	function get_icon() {
115
		$icon_id = get_option( 'site_icon' );
116
		if ( empty( $icon_id ) ) {
117
			$icon_id = Jetpack_Options::get_option( 'site_icon_id' );
118
		}
119
120
		if ( empty( $icon_id ) ) {
121
			return null;
122
		}
123
124
		$icon = array_filter( array(
125
			'img' => wp_get_attachment_image_url( $icon_id, 'full' ),
126
			'ico' => wp_get_attachment_image_url( $icon_id, array( 16, 16 ) )
127
		) );
128
129
		if ( empty( $icon ) ) {
130
			return null;
131
		}
132
133
		if ( current_user_can( 'edit_posts', $icon_id ) ) {
134
			$icon['media_id'] = (int) $icon_id;
135
		}
136
137
		return $icon;
138
	}
139
140
	/**
141
	 * Private methods
142
	 **/
143
144
	private function is_main_site( $response ) {
145
		if ( isset( $response['options']->main_network_site, $response['options']->unmapped_url ) ) {
146
			$main_network_site_url = set_url_scheme( $response['options']->main_network_site, 'http' );
147
			$unmapped_url          = set_url_scheme( $response['options']->unmapped_url, 'http' );
148
			if ( $unmapped_url === $main_network_site_url ) {
149
				return true;
150
			}
151
		}
152
153
		return false;
154
	}
155
156
	// For Jetpack sites this will always return false
157
	protected function is_a8c_publication( $post_id ) {
158
		return false;
159
	}
160
}
161