jetpack
2 years ago
class.wpcom-json-api-add-widget-endpoint.php
2 years ago
class.wpcom-json-api-autosave-post-v1-1-endpoint.php
5 years ago
class.wpcom-json-api-bulk-delete-post-endpoint.php
4 years ago
class.wpcom-json-api-bulk-restore-post-endpoint.php
2 years ago
class.wpcom-json-api-bulk-update-comments-endpoint.php
3 years ago
class.wpcom-json-api-comment-endpoint.php
1 year ago
class.wpcom-json-api-delete-media-endpoint.php
4 years ago
class.wpcom-json-api-delete-media-v1-1-endpoint.php
4 years ago
class.wpcom-json-api-edit-media-v1-2-endpoint.php
2 years ago
class.wpcom-json-api-get-autosave-v1-1-endpoint.php
5 years ago
class.wpcom-json-api-get-comment-counts-endpoint.php
4 years ago
class.wpcom-json-api-get-comment-endpoint.php
4 years ago
class.wpcom-json-api-get-comment-history-endpoint.php
4 years ago
class.wpcom-json-api-get-comments-tree-endpoint.php
4 years ago
class.wpcom-json-api-get-comments-tree-v1-1-endpoint.php
4 years ago
class.wpcom-json-api-get-comments-tree-v1-2-endpoint.php
4 years ago
class.wpcom-json-api-get-customcss.php
2 years ago
class.wpcom-json-api-get-media-endpoint.php
4 years ago
class.wpcom-json-api-get-media-v1-1-endpoint.php
4 years ago
class.wpcom-json-api-get-media-v1-2-endpoint.php
2 years ago
class.wpcom-json-api-get-post-counts-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-get-post-endpoint.php
2 years ago
class.wpcom-json-api-get-post-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-get-site-endpoint.php
1 year ago
class.wpcom-json-api-get-site-v1-2-endpoint.php
1 year ago
class.wpcom-json-api-get-taxonomies-endpoint.php
2 years ago
class.wpcom-json-api-get-taxonomy-endpoint.php
4 years ago
class.wpcom-json-api-get-term-endpoint.php
4 years ago
class.wpcom-json-api-list-comments-endpoint.php
2 years ago
class.wpcom-json-api-list-dropdown-pages-endpoint.php
3 years ago
class.wpcom-json-api-list-embeds-endpoint.php
4 years ago
class.wpcom-json-api-list-media-endpoint.php
2 years ago
class.wpcom-json-api-list-media-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-list-media-v1-2-endpoint.php
2 years ago
class.wpcom-json-api-list-post-type-taxonomies-endpoint.php
4 years ago
class.wpcom-json-api-list-post-types-endpoint.php
3 years ago
class.wpcom-json-api-list-posts-endpoint.php
2 years ago
class.wpcom-json-api-list-posts-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-list-posts-v1-2-endpoint.php
2 years ago
class.wpcom-json-api-list-roles-endpoint.php
2 years ago
class.wpcom-json-api-list-shortcodes-endpoint.php
4 years ago
class.wpcom-json-api-list-terms-endpoint.php
2 years ago
class.wpcom-json-api-list-users-endpoint.php
2 years ago
class.wpcom-json-api-menus-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-post-endpoint.php
2 years ago
class.wpcom-json-api-post-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-render-embed-endpoint.php
2 years ago
class.wpcom-json-api-render-embed-reversal-endpoint.php
2 years ago
class.wpcom-json-api-render-endpoint.php
3 years ago
class.wpcom-json-api-render-shortcode-endpoint.php
3 years ago
class.wpcom-json-api-sharing-buttons-endpoint.php
2 years ago
class.wpcom-json-api-site-settings-endpoint.php
1 year ago
class.wpcom-json-api-site-settings-v1-2-endpoint.php
2 years ago
class.wpcom-json-api-site-settings-v1-3-endpoint.php
1 year ago
class.wpcom-json-api-site-settings-v1-4-endpoint.php
1 year ago
class.wpcom-json-api-site-user-endpoint.php
2 years ago
class.wpcom-json-api-taxonomy-endpoint.php
4 years ago
class.wpcom-json-api-update-comment-endpoint.php
2 years ago
class.wpcom-json-api-update-customcss.php
2 years ago
class.wpcom-json-api-update-media-endpoint.php
4 years ago
class.wpcom-json-api-update-media-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-update-post-endpoint.php
3 years ago
class.wpcom-json-api-update-post-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-update-post-v1-2-endpoint.php
1 year ago
class.wpcom-json-api-update-site-homepage-endpoint.php
4 years ago
class.wpcom-json-api-update-site-logo-endpoint.php
2 years ago
class.wpcom-json-api-update-taxonomy-endpoint.php
4 years ago
class.wpcom-json-api-update-term-endpoint.php
4 years ago
class.wpcom-json-api-update-user-endpoint.php
3 years ago
class.wpcom-json-api-upload-media-endpoint.php
3 years ago
class.wpcom-json-api-upload-media-v1-1-endpoint.php
2 years ago
class.wpcom-json-api-update-site-logo-endpoint.php
118 lines
| 1 | <?php // phpcs:ignore WordPress.Files.FileName.InvalidClassFileName |
| 2 | /** |
| 3 | * Set site logo settings API. |
| 4 | * |
| 5 | * Endpoints: |
| 6 | * Set site logo settings: /sites/%s/logo |
| 7 | * Delete site logo settings: /sites/%s/logo/delete |
| 8 | */ |
| 9 | |
| 10 | new WPCOM_JSON_API_Update_Site_Logo_Endpoint( |
| 11 | array( |
| 12 | 'description' => 'Set site logo settings', |
| 13 | 'group' => '__do_not_document', |
| 14 | 'stat' => 'sites:1:logo', |
| 15 | 'method' => 'POST', |
| 16 | 'min_version' => '1.1', |
| 17 | 'path' => '/sites/%s/logo', |
| 18 | 'path_labels' => array( |
| 19 | '$site' => '(string) Site ID or domain.', |
| 20 | ), |
| 21 | 'request_format' => array( |
| 22 | 'id' => '(int) The ID of the logo post', |
| 23 | 'url' => '(string) The URL of the logo post (deprecated)', |
| 24 | ), |
| 25 | 'response_format' => array( |
| 26 | 'id' => '(int) The ID of the logo post', |
| 27 | 'url' => '(string) The URL of the logo post', |
| 28 | ), |
| 29 | 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/logo', |
| 30 | 'example_request_data' => array( |
| 31 | 'headers' => array( 'authorization' => 'Bearer YOUR_API_TOKEN' ), |
| 32 | 'body' => array( |
| 33 | 'id' => 12345, |
| 34 | ), |
| 35 | ), |
| 36 | 'example_response' => ' |
| 37 | { |
| 38 | "id": 12345, |
| 39 | "url": "https:\/\/s.w.org\/about\/images\/logos\/codeispoetry-rgb.png" |
| 40 | }', |
| 41 | ) |
| 42 | ); |
| 43 | |
| 44 | new WPCOM_JSON_API_Update_Site_Logo_Endpoint( |
| 45 | array( |
| 46 | 'description' => 'Delete site logo settings', |
| 47 | 'group' => '__do_not_document', |
| 48 | 'stat' => 'sites:1:logo:delete', |
| 49 | 'method' => 'POST', |
| 50 | 'min_version' => '1.1', |
| 51 | 'path' => '/sites/%s/logo/delete', |
| 52 | 'path_labels' => array( |
| 53 | '$site' => '(string) Site ID or domain.', |
| 54 | ), |
| 55 | 'example_request' => 'https://public-api.wordpress.com/rest/v1.1/sites/82974409/logo/delete', |
| 56 | 'example_request_data' => array( |
| 57 | 'headers' => array( 'authorization' => 'Bearer YOUR_API_TOKEN' ), |
| 58 | ), |
| 59 | ) |
| 60 | ); |
| 61 | |
| 62 | /** |
| 63 | * Set site logo settings API class. |
| 64 | */ |
| 65 | class WPCOM_JSON_API_Update_Site_Logo_Endpoint extends WPCOM_JSON_API_Endpoint { |
| 66 | /** |
| 67 | * Set site logo settings API callback. |
| 68 | * |
| 69 | * @param string $path API path. |
| 70 | * @param int $site_id Blog ID. |
| 71 | */ |
| 72 | public function callback( $path = '', $site_id = 0 ) { |
| 73 | // Switch to the given blog. |
| 74 | $blog_id = $this->api->switch_to_blog_and_validate_user( $this->api->get_blog_id( $site_id ) ); |
| 75 | if ( is_wp_error( $blog_id ) ) { |
| 76 | return $blog_id; |
| 77 | } |
| 78 | |
| 79 | if ( ! current_user_can( 'edit_theme_options' ) ) { |
| 80 | return new WP_Error( 'unauthorized', 'User is not authorized to access logo settings', 403 ); |
| 81 | } |
| 82 | |
| 83 | if ( strpos( $path, '/delete' ) ) { |
| 84 | delete_option( 'site_logo' ); |
| 85 | return array(); |
| 86 | } |
| 87 | |
| 88 | $args = $this->input(); |
| 89 | $logo_settings = $this->get_current_settings(); |
| 90 | |
| 91 | if ( empty( $args ) || ! is_array( $args ) ) { |
| 92 | return $logo_settings; |
| 93 | } |
| 94 | |
| 95 | if ( isset( $args['id'] ) ) { |
| 96 | update_option( 'site_logo', (int) $args['id'] ); |
| 97 | } |
| 98 | |
| 99 | return $this->get_current_settings(); |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * Get current logo settings. |
| 104 | */ |
| 105 | public function get_current_settings() { |
| 106 | $logo_id = get_option( 'site_logo' ); |
| 107 | |
| 108 | if ( ! $logo_id ) { |
| 109 | return array(); |
| 110 | } |
| 111 | |
| 112 | return array( |
| 113 | 'id' => $logo_id, |
| 114 | 'url' => wp_get_attachment_url( $logo_id ), |
| 115 | ); |
| 116 | } |
| 117 | } |
| 118 |