summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/jetpack/json-endpoints/class.wpcom-json-api-update-site-logo-endpoint.php')
-rw-r--r--plugins/jetpack/json-endpoints/class.wpcom-json-api-update-site-logo-endpoint.php47
1 files changed, 47 insertions, 0 deletions
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-site-logo-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-site-logo-endpoint.php
new file mode 100644
index 00000000..89fa9121
--- /dev/null
+++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-site-logo-endpoint.php
@@ -0,0 +1,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;
+ }
+}
+