-
Notifications
You must be signed in to change notification settings - Fork 803
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add jetpack endpoint for jetpack product data (#33095)
* changelog * Add barebones infrastructure for querying product data in the plugin * changelog * Fix product data api call * Fix incorrect function call * Update api_version * Update version number * Force wpcom endpoint * Update route setup * Remove useless alias * Remove logs * Remove backup specific endpoint * Fixup project versions * Fix composer lock files * changelog * Remove useless comment
- Loading branch information
1 parent
5797577
commit b0c967a
Showing
33 changed files
with
215 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
14 changes: 14 additions & 0 deletions
14
projects/packages/my-jetpack/_inc/hooks/use-product-data/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { useSelect } from '@wordpress/data'; | ||
import { STORE_ID } from '../../state/store'; | ||
|
||
/** | ||
* React custom hook to get the product data | ||
* | ||
* @returns {object} product data | ||
*/ | ||
export default function useProductData() { | ||
return { | ||
productData: useSelect( select => select( STORE_ID ).getProductData() ), | ||
fetchingProductData: useSelect( select => select( STORE_ID ).isFetchingProductData() ), | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
projects/packages/my-jetpack/changelog/add-jetpack-endpoint-for-jetpack-product-data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: minor | ||
Type: added | ||
|
||
Add barebones infrastructure for querying jetpack product data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
projects/packages/my-jetpack/src/class-rest-product-data.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* Sets up the Product Data REST API endpoints. | ||
* | ||
* @package automattic/my-jetpack | ||
*/ | ||
|
||
namespace Automattic\Jetpack\My_Jetpack; | ||
|
||
use Automattic\Jetpack\Connection\Client; | ||
use WP_Error; | ||
|
||
/** | ||
* Registers the REST routes for Product Data | ||
*/ | ||
class REST_Product_Data { | ||
/** | ||
* Constructor. | ||
*/ | ||
public function __construct() { | ||
register_rest_route( | ||
'my-jetpack/v1', | ||
'site/product-data', | ||
array( | ||
'methods' => \WP_REST_Server::READABLE, | ||
'callback' => __CLASS__ . '::get_all_product_data', | ||
'permission_callback' => __CLASS__ . '::permissions_callback', | ||
) | ||
); | ||
} | ||
|
||
/** | ||
* Checks if the user has the correct permissions | ||
*/ | ||
public static function permissions_callback() { | ||
return current_user_can( 'manage_options' ); | ||
} | ||
|
||
/** | ||
* Gets the product data for all products | ||
* | ||
* @return array|WP_Error | ||
*/ | ||
public static function get_all_product_data() { | ||
$site_id = \Jetpack_Options::get_option( 'id' ); | ||
$wpcom_endpoint = sprintf( 'sites/%d/jetpack-product-data?locale=%2$s&force=wpcom', $site_id, get_user_locale() ); | ||
$api_version = '2'; | ||
$response = Client::wpcom_json_api_request_as_blog( $wpcom_endpoint, $api_version, array(), null, 'wpcom' ); | ||
$response_code = wp_remote_retrieve_response_code( $response ); | ||
$body = json_decode( wp_remote_retrieve_body( $response ) ); | ||
|
||
if ( is_wp_error( $response ) || empty( $response['body'] ) || 200 !== $response_code ) { | ||
return new WP_Error( 'site_products_data_fetch_failed', 'Site products data fetch failed', array( 'status' => $response_code ? $response_code : 400 ) ); | ||
} | ||
|
||
return rest_ensure_response( $body, 200 ); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
projects/packages/videopress/changelog/add-bi-yearly-constants-to-videopress-plugin
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: fixed | ||
|
||
Add bi-yearly constants for complete and videopress in config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
projects/plugins/backup/changelog/add-jetpack-endpoint-for-jetpack-product-data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: added | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
projects/plugins/boost/changelog/add-jetpack-endpoint-for-jetpack-product-data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: added | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
projects/plugins/jetpack/changelog/add-jetpack-endpoint-for-jetpack-product-data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Significance: patch | ||
Type: other | ||
|
||
|
Oops, something went wrong.