summaryrefslogtreecommitdiff
blob: 89fa9121de32e5d77bd32b60fbf02bbc0e78b1bd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

class WPCOM_JSON_API_Update_Site_Logo_Endpoint extends WPCOM_JSON_API_Endpoint {
	function callback( $path = '', $site_id = 0 ) {
		// Switch to the given blog.
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $site_id ) );
		if ( is_wp_error( $blog_id ) ) {
			return $blog_id;
		}

		if ( ! current_user_can( 'edit_theme_options' ) ) {
			return new WP_Error( 'unauthorized', 'User is not authorized to access logo settings', 403 );
		}

		if ( strpos( $path, '/delete' ) ) {
			delete_option( 'site_logo' );
			return array();
		}

		$args = $this->input();
		$logo_settings = $this->get_current_settings();
		if ( empty( $args ) || ! is_array( $args ) ) {
			return $logo_settings;
		}

		if ( isset( $args['id'] ) ) {
			$logo_settings['id'] = intval( $args['id'], 10 );
		}
		if ( isset( $args['url'] ) ) {
			$logo_settings['url'] = $args['url'];
		}
		if ( isset( $args['url'] ) || isset( $args['id'] ) ) {
			update_option( 'site_logo', $logo_settings );
		}

		return $this->get_current_settings();
	}

	function get_current_settings() {
		$logo_settings = get_option( 'site_logo' );
		if ( ! is_array( $logo_settings ) ) {
			$logo_settings = array();
		}
		return $logo_settings;
	}
}