Completed
Push — update/dialogue-focus-on-conte... ( 9f1745...fa862f )
by
unknown
80:03 queued 71:18
created

class.wpcom-json-api-update-site-logo-endpoint.php (1 issue)

Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
new WPCOM_JSON_API_Update_Site_Logo_Endpoint( array (
4
	'description'      => 'Set site logo settings',
5
	'group'            => '__do_not_document',
6
	'stat'             => 'sites:1:logo',
7
	'method'           => 'POST',
8
	'min_version'      => '1.1',
9
	'path'             => '/sites/%s/logo',
10
	'path_labels'      => array(
11
		'$site' => '(string) Site ID or domain.',
12
	),
13
	'request_format'  => array(
14
		'id' => '(int) The ID of the logo post',
15
		'url' => '(string) The URL of the logo post',
16
	),
17
	'response_format'  => array(
18
		'id' => '(int) The ID of the logo post',
19
		'url' => '(string) The URL of the logo post',
20
	),
21
	'example_request'  => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/logo',
22
	'example_request_data' => array(
23
		'headers' => array( 'authorization' => 'Bearer YOUR_API_TOKEN' ),
24
		'body' => array(
25
			'id' => 12345,
26
			'url' => 'https://s.w.org/about/images/logos/codeispoetry-rgb.png',
27
		),
28
	),
29
	'example_response' => '
30
	{
31
		"id": 12345,
32
		"url": "https:\/\/s.w.org\/about\/images\/logos\/codeispoetry-rgb.png"
33
	}'
34
) );
35
36
new WPCOM_JSON_API_Update_Site_Logo_Endpoint( array (
37
	'description'      => 'Delete site logo settings',
38
	'group'            => '__do_not_document',
39
	'stat'             => 'sites:1:logo:delete',
40
	'method'           => 'POST',
41
	'min_version'      => '1.1',
42
	'path'             => '/sites/%s/logo/delete',
43
	'path_labels'      => array(
44
		'$site' => '(string) Site ID or domain.',
45
	),
46
	'example_request'  => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/logo/delete',
47
	'example_request_data' => array(
48
		'headers' => array( 'authorization' => 'Bearer YOUR_API_TOKEN' ),
49
	),
50
) );
51
52
class WPCOM_JSON_API_Update_Site_Logo_Endpoint extends WPCOM_JSON_API_Endpoint {
53
	function callback( $path = '', $site_id = 0 ) {
54
		// Switch to the given blog.
55
		$blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $site_id ) );
56
		if ( is_wp_error( $blog_id ) ) {
57
			return $blog_id;
58
		}
59
60
		if ( ! current_user_can( 'edit_theme_options' ) ) {
61
			return new WP_Error( 'unauthorized', 'User is not authorized to access logo settings', 403 );
0 ignored issues
show
The call to WP_Error::__construct() has too many arguments starting with 'unauthorized'.

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.

Loading history...
62
		}
63
64
		if ( strpos( $path, '/delete' ) ) {
65
			delete_option( 'site_logo' );
66
			return array();
67
		}
68
69
		$args = $this->input();
70
		$logo_settings = $this->get_current_settings();
71
		if ( empty( $args ) || ! is_array( $args ) ) {
72
			return $logo_settings;
73
		}
74
75
		if ( isset( $args['id'] ) ) {
76
			$logo_settings['id'] = (int) $args['id'];
77
		}
78
		if ( isset( $args['url'] ) ) {
79
			$logo_settings['url'] = $args['url'];
80
		}
81
		if ( isset( $args['url'] ) || isset( $args['id'] ) ) {
82
			update_option( 'site_logo', $logo_settings );
83
		}
84
85
		return $this->get_current_settings();
86
	}
87
88
	function get_current_settings() {
89
		$logo_settings = get_option( 'site_logo' );
90
		if ( ! is_array( $logo_settings ) ) {
91
			$logo_settings = array();
92
		}
93
		return $logo_settings;
94
	}
95
}
96
97