diff options
Diffstat (limited to 'plugins/jetpack/json-endpoints')
15 files changed, 136 insertions, 64 deletions
diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-comment-counts-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-comment-counts-endpoint.php index 88688e42..705f2e61 100644 --- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-comment-counts-endpoint.php +++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-comment-counts-endpoint.php @@ -55,7 +55,7 @@ class WPCOM_JSON_API_GET_Comment_Counts_Endpoint extends WPCOM_JSON_API_Endpoint return new WP_Error( 'invalid_input', 'Provided post_id does not exist', 400 ); } - $comment_counts = get_object_vars( wp_count_comments( $post_id ) ); + $comment_counts = get_object_vars( $this->api->wp_count_comments( $post_id ) ); // Keys coming from wp_count_comments don't match the ones that we use in // wp-admin and Calypso and are not consistent. Let's normalize the response. diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php index c7dbcb24..a7868dea 100644 --- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php +++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-get-site-endpoint.php @@ -50,6 +50,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint { 'jetpack_modules' => '(array) A list of active Jetpack modules.', 'meta' => '(object) Meta data', 'quota' => '(array) An array describing how much space a user has left for uploads', + 'launch_status' => '(string) A string describing the launch status of a site', ); protected static $no_member_fields = array( @@ -68,6 +69,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint { 'is_private', 'is_following', 'meta', + 'launch_status', ); protected static $site_options_format = array( @@ -125,7 +127,7 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint { 'has_pending_automated_transfer', 'woocommerce_is_active', 'design_type', - 'site_goals' + 'site_goals', ); protected static $jetpack_response_field_additions = array( @@ -353,9 +355,8 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint { $response[ $key ] = $this->site->get_capabilities(); break; case 'jetpack_modules': - $jetpack_modules = $this->site->get_jetpack_modules(); - if ( ! is_null( $jetpack_modules ) ) { - $response[ $key ] = $jetpack_modules; + if ( is_user_member_of_blog() ) { + $response[ $key ] = $this->site->get_jetpack_modules(); } break; case 'plan' : @@ -364,6 +365,9 @@ class WPCOM_JSON_API_GET_Site_Endpoint extends WPCOM_JSON_API_Endpoint { case 'quota' : $response[ $key ] = $this->site->get_quota(); break; + case 'launch_status' : + $response[ $key ] = $this->site->get_launch_status(); + break; } do_action( 'post_render_site_response_key', $key ); diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-comments-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-comments-endpoint.php index 024d1b6b..429e0161 100644 --- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-comments-endpoint.php +++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-list-comments-endpoint.php @@ -165,7 +165,7 @@ class WPCOM_JSON_API_List_Comments_Endpoint extends WPCOM_JSON_API_Comment_Endpo if ( !$comment_id ) { // We can get comment counts for the whole site or for a single post, but only for certain queries if ( 'any' === $args['type'] && !isset( $args['after'] ) && !isset( $args['before'] ) ) { - $count = wp_count_comments( $post_id ); + $count = $this->api->wp_count_comments( $post_id ); } } @@ -194,11 +194,16 @@ class WPCOM_JSON_API_List_Comments_Endpoint extends WPCOM_JSON_API_Comment_Endpo } } + /** This filter is documented in class.json-api.php */ + $exclude = apply_filters( 'jetpack_api_exclude_comment_types', + array( 'order_note', 'webhook_delivery', 'review', 'action_log' ) + ); + $query = array( 'order' => $args['order'], 'type' => 'any' === $args['type'] ? false : $args['type'], 'status' => $status, - 'type__not_in' => array( 'review' ), + 'type__not_in' => $exclude, ); if ( isset( $args['page'] ) ) { diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-post-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-post-endpoint.php index 09d3f50c..713fa68a 100644 --- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-post-endpoint.php +++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-post-endpoint.php @@ -262,11 +262,8 @@ abstract class WPCOM_JSON_API_Post_Endpoint extends WPCOM_JSON_API_Endpoint { case 'likes_enabled' : /** This filter is documented in modules/likes.php */ $sitewide_likes_enabled = (bool) apply_filters( 'wpl_is_enabled_sitewide', ! get_option( 'disabled_likes' ) ); - $post_likes_switched = (bool) get_post_meta( $post->ID, 'switch_like_status', true ); - $post_likes_enabled = $sitewide_likes_enabled; - if ( $post_likes_switched ) { - $post_likes_enabled = ! $post_likes_enabled; - } + $post_likes_switched = get_post_meta( $post->ID, 'switch_like_status', true ); + $post_likes_enabled = $post_likes_switched || ( $sitewide_likes_enabled && $post_likes_switched !== '0' ); $response[$key] = (bool) $post_likes_enabled; break; case 'sharing_enabled' : diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php index 6c293b4d..d55a7e9b 100644 --- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php +++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-endpoint.php @@ -101,7 +101,6 @@ new WPCOM_JSON_API_Site_Settings_Endpoint( array( 'site_icon' => '(int) Media attachment ID to use as site icon. Set to zero or an otherwise empty value to clear', 'api_cache' => '(bool) Turn on/off the Jetpack JSON API cache', 'posts_per_page' => '(int) Number of posts to show on blog pages', - 'net_neutrality' => '(bool) Whether to show the net neutrality modal for a site', 'posts_per_rss' => '(int) Number of posts to show in the RSS feed', 'rss_use_excerpt' => '(bool) Whether the RSS feed will use post excerpts', ), @@ -327,11 +326,6 @@ class WPCOM_JSON_API_Site_Settings_Endpoint extends WPCOM_JSON_API_Endpoint { $api_cache = $is_jetpack ? (bool) get_option( 'jetpack_api_cache_enabled' ) : true; - $net_neutrality_options = get_option( 'net_neutrality_options_2017' ); - $net_neutrality = ( $net_neutrality_options && ! empty( $net_neutrality_options['enabled'] ) ) - ? true - : false; - $response[ $key ] = array( // also exists as "options" @@ -399,7 +393,6 @@ class WPCOM_JSON_API_Site_Settings_Endpoint extends WPCOM_JSON_API_Endpoint { 'amp_is_enabled' => (bool) function_exists( 'wpcom_is_amp_enabled' ) && wpcom_is_amp_enabled( $blog_id ), 'api_cache' => $api_cache, 'posts_per_page' => (int) get_option( 'posts_per_page' ), - 'net_neutrality' => $net_neutrality, 'posts_per_rss' => (int) get_option( 'posts_per_rss' ), 'rss_use_excerpt' => (bool) get_option( 'rss_use_excerpt' ), ); @@ -793,15 +786,6 @@ class WPCOM_JSON_API_Site_Settings_Endpoint extends WPCOM_JSON_API_Endpoint { } break; - case 'net_neutrality': - $original_value = $value; - $value = array( 'enabled' => (bool) $value ); - if ( update_option( 'net_neutrality_options_2017', $value ) ) { - $updated[ $key ] = $original_value; - } - - break; - case 'rss_use_excerpt': update_option( 'rss_use_excerpt', (int)(bool) $value ); break; @@ -820,7 +804,7 @@ class WPCOM_JSON_API_Site_Settings_Endpoint extends WPCOM_JSON_API_Endpoint { */ $value = apply_filters( 'site_settings_endpoint_update_' . $key, $value ); $updated[ $key ] = $value; - continue; + break; } // no worries, we've already whitelisted and casted arguments above diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-2-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-2-endpoint.php index 0613352b..989bba2e 100644 --- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-2-endpoint.php +++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-2-endpoint.php @@ -98,7 +98,6 @@ new WPCOM_JSON_API_Site_Settings_V1_2_Endpoint( array( 'site_icon' => '(int) Media attachment ID to use as site icon. Set to zero or an otherwise empty value to clear', 'api_cache' => '(bool) Turn on/off the Jetpack JSON API cache', 'posts_per_page' => '(int) Number of posts to show on blog pages', - 'net_neutrality' => '(bool) Whether the net neutrality modal is enabled for this site', 'posts_per_rss' => '(int) Number of posts to show in the RSS feed', 'rss_use_excerpt' => '(bool) Whether the RSS feed will use post excerpts', ), diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-3-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-3-endpoint.php index 8287a4b4..52a3a148 100644 --- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-3-endpoint.php +++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-3-endpoint.php @@ -98,7 +98,6 @@ new WPCOM_JSON_API_Site_Settings_V1_3_Endpoint( array( 'site_icon' => '(int) Media attachment ID to use as site icon. Set to zero or an otherwise empty value to clear', 'api_cache' => '(bool) Turn on/off the Jetpack JSON API cache', 'posts_per_page' => '(int) Number of posts to show on blog pages', - 'net_neutrality' => '(bool) Whether the net neutrality modal is enabled for this site', 'posts_per_rss' => '(int) Number of posts to show in the RSS feed', 'rss_use_excerpt' => '(bool) Whether the RSS feed will use post excerpts', ), diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-4-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-4-endpoint.php index f6a4fbee..ab59ebcc 100644 --- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-4-endpoint.php +++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-site-settings-v1-4-endpoint.php @@ -98,7 +98,6 @@ new WPCOM_JSON_API_Site_Settings_V1_4_Endpoint( array( 'site_icon' => '(int) Media attachment ID to use as site icon. Set to zero or an otherwise empty value to clear', 'api_cache' => '(bool) Turn on/off the Jetpack JSON API cache', 'posts_per_page' => '(int) Number of posts to show on blog pages', - 'net_neutrality' => '(bool) Whether the net neutrality modal is enabled for this site', 'posts_per_rss' => '(int) Number of posts to show in the RSS feed', 'rss_use_excerpt' => '(bool) Whether the RSS feed will use post excerpts', ), diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-endpoint.php index bbcdd34e..80dccac6 100644 --- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-endpoint.php +++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-endpoint.php @@ -537,7 +537,7 @@ class WPCOM_JSON_API_Update_Post_Endpoint extends WPCOM_JSON_API_Post_Endpoint { if ( $new ) { if ( $sitewide_likes_enabled ) { if ( false === $likes ) { - update_post_meta( $post_id, 'switch_like_status', 1 ); + update_post_meta( $post_id, 'switch_like_status', 0 ); } else { delete_post_meta( $post_id, 'switch_like_status' ); } @@ -552,7 +552,7 @@ class WPCOM_JSON_API_Update_Post_Endpoint extends WPCOM_JSON_API_Post_Endpoint { if ( isset( $likes ) ) { if ( $sitewide_likes_enabled ) { if ( false === $likes ) { - update_post_meta( $post_id, 'switch_like_status', 1 ); + update_post_meta( $post_id, 'switch_like_status', 0 ); } else { delete_post_meta( $post_id, 'switch_like_status' ); } @@ -759,7 +759,7 @@ class WPCOM_JSON_API_Update_Post_Endpoint extends WPCOM_JSON_API_Post_Endpoint { case 'add': if ( ! empty( $meta->id ) || ! empty( $meta->previous_value ) ) { - continue; + break; } elseif ( ! empty( $meta->key ) && ! empty( $meta->value ) && ( current_user_can( 'add_post_meta', $post_id, $unslashed_meta_key ) ) || WPCOM_JSON_API_Metadata::is_public( $meta->key ) ) { add_post_meta( $post_id, $meta->key, $meta->value ); } @@ -768,7 +768,7 @@ class WPCOM_JSON_API_Update_Post_Endpoint extends WPCOM_JSON_API_Post_Endpoint { case 'update': if ( ! isset( $meta->value ) ) { - continue; + break; } elseif ( ! empty( $meta->id ) && ! empty( $existing_meta_item->meta_key ) && ( current_user_can( 'edit_post_meta', $post_id, $unslashed_existing_meta_key ) || WPCOM_JSON_API_Metadata::is_public( $meta->key ) ) ) { update_metadata_by_mid( 'post', $meta->id, $meta->value ); } elseif ( ! empty( $meta->key ) && ! empty( $meta->previous_value ) && ( current_user_can( 'edit_post_meta', $post_id, $unslashed_meta_key ) || WPCOM_JSON_API_Metadata::is_public( $meta->key ) ) ) { diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-1-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-1-endpoint.php index 1e1a1f1b..3778f16d 100644 --- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-1-endpoint.php +++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-1-endpoint.php @@ -615,7 +615,7 @@ class WPCOM_JSON_API_Update_Post_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1_ if ( $new ) { if ( $sitewide_likes_enabled ) { if ( false === $likes ) { - update_post_meta( $post_id, 'switch_like_status', 1 ); + update_post_meta( $post_id, 'switch_like_status', 0 ); } else { delete_post_meta( $post_id, 'switch_like_status' ); } @@ -630,7 +630,7 @@ class WPCOM_JSON_API_Update_Post_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1_ if ( isset( $likes ) ) { if ( $sitewide_likes_enabled ) { if ( false === $likes ) { - update_post_meta( $post_id, 'switch_like_status', 1 ); + update_post_meta( $post_id, 'switch_like_status', 0 ); } else { delete_post_meta( $post_id, 'switch_like_status' ); } @@ -825,7 +825,6 @@ class WPCOM_JSON_API_Update_Post_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1_ switch ( $meta->operation ) { case 'delete': - if ( ! empty( $meta->id ) && ! empty( $existing_meta_item->meta_key ) && current_user_can( 'delete_post_meta', $post_id, $unslashed_existing_meta_key ) ) { delete_metadata_by_mid( 'post', $meta->id ); } elseif ( ! empty( $meta->key ) && ! empty( $meta->previous_value ) && current_user_can( 'delete_post_meta', $post_id, $unslashed_meta_key ) ) { @@ -836,18 +835,16 @@ class WPCOM_JSON_API_Update_Post_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1_ break; case 'add': - if ( ! empty( $meta->id ) || ! empty( $meta->previous_value ) ) { - continue; + break; } elseif ( ! empty( $meta->key ) && ! empty( $meta->value ) && ( current_user_can( 'add_post_meta', $post_id, $unslashed_meta_key ) ) || WPCOM_JSON_API_Metadata::is_public( $meta->key ) ) { add_post_meta( $post_id, $meta->key, $meta->value ); } break; case 'update': - if ( ! isset( $meta->value ) ) { - continue; + break; } elseif ( ! empty( $meta->id ) && ! empty( $existing_meta_item->meta_key ) && ( current_user_can( 'edit_post_meta', $post_id, $unslashed_existing_meta_key ) || WPCOM_JSON_API_Metadata::is_public( $meta->key ) ) ) { update_metadata_by_mid( 'post', $meta->id, $meta->value ); } elseif ( ! empty( $meta->key ) && ! empty( $meta->previous_value ) && ( current_user_can( 'edit_post_meta', $post_id, $unslashed_meta_key ) || WPCOM_JSON_API_Metadata::is_public( $meta->key ) ) ) { @@ -858,7 +855,6 @@ class WPCOM_JSON_API_Update_Post_v1_1_Endpoint extends WPCOM_JSON_API_Post_v1_1_ break; } - } } diff --git a/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-2-endpoint.php b/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-2-endpoint.php index 4ad5e26c..113766a1 100644 --- a/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-2-endpoint.php +++ b/plugins/jetpack/json-endpoints/class.wpcom-json-api-update-post-v1-2-endpoint.php @@ -518,7 +518,7 @@ class WPCOM_JSON_API_Update_Post_v1_2_Endpoint extends WPCOM_JSON_API_Update_Pos default : // Several images - 3 column gallery $insert['post_content'] = $input['content'] = sprintf( - "[gallery ids='%s']\n\n", + "[gallery ids='%s']\n\n", $media_id_string ) . $input['content']; break; @@ -586,7 +586,7 @@ class WPCOM_JSON_API_Update_Post_v1_2_Endpoint extends WPCOM_JSON_API_Update_Pos if ( $new ) { if ( $sitewide_likes_enabled ) { if ( false === $likes ) { - update_post_meta( $post_id, 'switch_like_status', 1 ); + update_post_meta( $post_id, 'switch_like_status', 0 ); } else { delete_post_meta( $post_id, 'switch_like_status' ); } @@ -601,7 +601,7 @@ class WPCOM_JSON_API_Update_Post_v1_2_Endpoint extends WPCOM_JSON_API_Update_Pos if ( isset( $likes ) ) { if ( $sitewide_likes_enabled ) { if ( false === $likes ) { - update_post_meta( $post_id, 'switch_like_status', 1 ); + update_post_meta( $post_id, 'switch_like_status', 0 ); } else { delete_post_meta( $post_id, 'switch_like_status' ); } @@ -796,7 +796,6 @@ class WPCOM_JSON_API_Update_Post_v1_2_Endpoint extends WPCOM_JSON_API_Update_Pos switch ( $meta->operation ) { case 'delete': - if ( ! empty( $meta->id ) && ! empty( $existing_meta_item->meta_key ) && current_user_can( 'delete_post_meta', $post_id, $unslashed_existing_meta_key ) ) { delete_metadata_by_mid( 'post', $meta->id ); } elseif ( ! empty( $meta->key ) && ! empty( $meta->previous_value ) && current_user_can( 'delete_post_meta', $post_id, $unslashed_meta_key ) ) { @@ -807,18 +806,16 @@ class WPCOM_JSON_API_Update_Post_v1_2_Endpoint extends WPCOM_JSON_API_Update_Pos break; case 'add': - if ( ! empty( $meta->id ) || ! empty( $meta->previous_value ) ) { - continue; + break; } elseif ( ! empty( $meta->key ) && ! empty( $meta->value ) && ( current_user_can( 'add_post_meta', $post_id, $unslashed_meta_key ) ) || WPCOM_JSON_API_Metadata::is_public( $meta->key ) ) { add_post_meta( $post_id, $meta->key, $meta->value ); } break; case 'update': - if ( ! isset( $meta->value ) ) { - continue; + break; } elseif ( ! empty( $meta->id ) && ! empty( $existing_meta_item->meta_key ) && ( current_user_can( 'edit_post_meta', $post_id, $unslashed_existing_meta_key ) || WPCOM_JSON_API_Metadata::is_public( $meta->key ) ) ) { update_metadata_by_mid( 'post', $meta->id, $meta->value ); } elseif ( ! empty( $meta->key ) && ! empty( $meta->previous_value ) && ( current_user_can( 'edit_post_meta', $post_id, $unslashed_meta_key ) || WPCOM_JSON_API_Metadata::is_public( $meta->key ) ) ) { @@ -829,7 +826,6 @@ class WPCOM_JSON_API_Update_Post_v1_2_Endpoint extends WPCOM_JSON_API_Update_Pos break; } - } } diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-cron-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-cron-endpoint.php index f50c38c0..9638c3eb 100644 --- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-cron-endpoint.php +++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-cron-endpoint.php @@ -200,7 +200,12 @@ class Jetpack_JSON_API_Cron_Schedule_Endpoint extends Jetpack_JSON_API_Cron_Endp $lock = $this->lock_cron(); $next = wp_schedule_single_event( $args['timestamp'], $hook, $arguments ); $this->maybe_unlock_cron( $lock ); - return array( 'success' => is_null( $next ) ? true : false ); + /** + * Note: Before WP 5.1, the return value was either `false` or `null`. + * With 5.1 and later, the return value is now `false` or `true`. + * We need to account for both. + */ + return array( 'success' => false !== $next ); } } diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-jps-woocommerce-connect-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-jps-woocommerce-connect-endpoint.php new file mode 100644 index 00000000..75a3b04d --- /dev/null +++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-jps-woocommerce-connect-endpoint.php @@ -0,0 +1,58 @@ +<?php + +class Jetpack_JSON_API_JPS_WooCommerce_Connect_Endpoint extends Jetpack_JSON_API_Endpoint { + + protected $needed_capabilities = 'manage_options'; + + function result() { + $input = $this->input(); + $helper_data = get_option( 'woocommerce_helper_data', array() ); + + if ( ! empty( $helper_data['auth'] ) ) { + return new WP_Error( + 'already_configured', + __( 'WooCommerce auth data is already set.', 'jetpack' ) + ); + } + + // Only update the auth field for `woocommerce_helper_data` instead of blowing out the entire option. + $helper_data['auth'] = array( + 'user_id' => $input['user_id'], + 'site_id' => $input['site_id'], + 'updated' => time(), + 'access_token' => $input['access_token'], + 'access_token_secret' => $input['access_token_secret'], + ); + + $updated = update_option( + 'woocommerce_helper_data', + $helper_data + ); + + return array( + 'success' => $updated, + ); + } + + function validate_input( $object ) { + $input = $this->input(); + + if ( empty( $input['access_token'] ) ) { + return new WP_Error( 'input_error', __( 'access_token is required', 'jetpack' ) ); + } + + if ( empty( $input['access_token_secret'] ) ) { + return new WP_Error( 'input_error', __( 'access_token_secret is required', 'jetpack' ) ); + } + + if ( empty( $input['user_id'] ) ) { + return new WP_Error( 'input_error', __( 'user_id is required', 'jetpack' ) ); + } + + if ( empty( $input['site_id'] ) ) { + return new WP_Error( 'input_error', __( 'site_id is required', 'jetpack' ) ); + } + + return parent::validate_input( $object ); + } +} diff --git a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php index 7b4b854b..49cf43dc 100644 --- a/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php +++ b/plugins/jetpack/json-endpoints/jetpack/class.jetpack-json-api-plugins-modify-endpoint.php @@ -245,18 +245,11 @@ class Jetpack_JSON_API_Plugins_Modify_Endpoint extends Jetpack_JSON_API_Plugins_ } protected function current_user_can( $capability, $plugin = null ) { - global $wp_version; - if ( version_compare( $wp_version, '4.9-beta2' ) >= 0 ) { - if ( $plugin ) { - return current_user_can( $capability, $plugin ); - } - - return current_user_can( $capability ); + if ( $plugin ) { + return current_user_can( $capability, $plugin ); } - // Assume that the user has the activate plugins capability. - return current_user_can( 'activate_plugins' ); - + return current_user_can( $capability ); } protected function deactivate() { diff --git a/plugins/jetpack/json-endpoints/jetpack/json-api-jetpack-endpoints.php b/plugins/jetpack/json-endpoints/jetpack/json-api-jetpack-endpoints.php index e6f25903..9c3f680a 100644 --- a/plugins/jetpack/json-endpoints/jetpack/json-api-jetpack-endpoints.php +++ b/plugins/jetpack/json-endpoints/jetpack/json-api-jetpack-endpoints.php @@ -1193,3 +1193,40 @@ new Jetpack_JSON_API_User_Create_Endpoint( array( 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/users/create' ) ); + +require_once( $json_jetpack_endpoints_dir . 'class.jetpack-json-api-jps-woocommerce-connect-endpoint.php' ); + +// POST /sites/%s/jps/woo-connect +new Jetpack_JSON_API_JPS_WooCommerce_Connect_Endpoint( array( + 'description' => 'Attempts to connect the WooCommerce plugin for this site to WooCommerce.com.', + 'group' => '__do_not_document', + 'method' => 'POST', + 'path' => '/sites/%s/jps/woo-connect', + 'stat' => 'jps:woo-connect', + 'allow_jetpack_site_auth' => true, + 'path_labels' => array( + '$site' => '(int|string) The site ID, The site domain', + ), + 'request_format' => array( + 'access_token' => '(string) The access token for WooCommerce to connect to WooCommerce.com', + 'access_token_secret' => '(string) The access token secret for WooCommerce to connect to WooCommerce.com', + 'user_id' => '(int) The user\'s ID after registering for a host plan', + 'site_id' => '(int) The site\'s ID after registering for a host plan', + ), + 'response_format' => array( + 'success' => '(bool) Setting access token and access token secret successful?', + ), + 'example_request_data' => array( + 'headers' => array( + 'authorization' => 'Bearer YOUR_API_TOKEN', + ), + 'body' => array( + 'access_token' => '123456789', + 'access_token_secret' => 'abcdefghiklmnop', + 'user_id' => 1, + 'site_id' => 2, + ), + ), + 'example_response' => '{ "success": true }', + 'example_request' => 'https://public-api.wordpress.com/rest/v1/sites/example.wordpress.org/jps/woo-connect' +) ); |