2017-04-21 12:05:44 +00:00
|
|
|
<?php
|
|
|
|
if ( ! defined( 'ABSPATH' ) ) {
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2017-04-26 15:50:38 +00:00
|
|
|
/**
|
|
|
|
* WC_Helper_Plugin_Info Class
|
|
|
|
*
|
|
|
|
* Provides the "View Information" core modals with data for WooCommerce.com
|
|
|
|
* hosted extensions.
|
|
|
|
*/
|
2017-04-21 12:05:44 +00:00
|
|
|
class WC_Helper_Plugin_Info {
|
2017-04-26 15:50:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the class, runs on init.
|
|
|
|
*/
|
2017-04-21 12:05:44 +00:00
|
|
|
public static function load() {
|
|
|
|
add_filter( 'plugins_api', array( __CLASS__, 'plugins_api' ), 20, 3 );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin information callback for Woo extensions.
|
|
|
|
*
|
|
|
|
* @param object $response The response core needs to display the modal.
|
|
|
|
* @param string $action The requested plugins_api() action.
|
|
|
|
* @param object $args Arguments passed to plugins_api().
|
|
|
|
*
|
|
|
|
* @return object An updated $response.
|
|
|
|
*/
|
|
|
|
public static function plugins_api( $response, $action, $args ) {
|
2017-04-21 12:35:27 +00:00
|
|
|
if ( 'plugin_information' !== $action ) {
|
2017-04-21 12:05:44 +00:00
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( empty( $args->slug ) ) {
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
2017-07-12 16:14:48 +00:00
|
|
|
// Only for slugs that start with woo-
|
2017-08-29 07:23:34 +00:00
|
|
|
if ( 0 !== strpos( $args->slug, 'woo-' ) ) {
|
2017-07-12 16:14:48 +00:00
|
|
|
return $response;
|
2017-04-21 12:05:44 +00:00
|
|
|
}
|
|
|
|
|
2017-07-12 16:14:48 +00:00
|
|
|
$clean_slug = preg_replace( '#^woo-#', '', $args->slug );
|
|
|
|
|
|
|
|
// Look through update data by slug.
|
|
|
|
$update_data = WC_Helper_Updater::get_update_data();
|
|
|
|
$products = wp_list_filter( $update_data, array( 'slug' => $clean_slug ) );
|
|
|
|
|
|
|
|
if ( empty( $products ) ) {
|
2017-04-21 12:05:44 +00:00
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
|
2017-07-12 16:14:48 +00:00
|
|
|
$product_id = array_keys( $products );
|
|
|
|
$product_id = array_shift( $product_id );
|
|
|
|
|
2017-04-21 12:05:44 +00:00
|
|
|
// Fetch the product information from the Helper API.
|
|
|
|
$request = WC_Helper_API::get( add_query_arg( array(
|
2017-07-12 16:14:48 +00:00
|
|
|
'product_id' => absint( $product_id ),
|
2017-04-21 12:05:44 +00:00
|
|
|
), 'info' ), array( 'authenticated' => true ) );
|
|
|
|
|
|
|
|
$results = json_decode( wp_remote_retrieve_body( $request ), true );
|
|
|
|
if ( ! empty( $results ) ) {
|
|
|
|
$response = (object) $results;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
WC_Helper_Plugin_Info::load();
|