diff --git a/src/Basic_Requirement_Checker.php b/src/Basic_Requirement_Checker.php index c259647bb2eb53fcbe7f0bc242f056f87500c8f0..6b37a644c8fb212e7468c4629a661d79f90c8fbd 100644 --- a/src/Basic_Requirement_Checker.php +++ b/src/Basic_Requirement_Checker.php @@ -51,8 +51,6 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { * @param string $text_domain * @param string $php_version * @param string $wp_version - * @param string $minimum_required_plugin_version - * @param bool $force_plugin_update */ public function __construct( $plugin_file, $plugin_name, $text_domain, $php_version, $wp_version ) { $this->plugin_file = $plugin_file; @@ -221,7 +219,7 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { } if ( true == $this->is_required_minimum_version && false !== $this->check_minimum_required_plugin_version( $this->slug ) ) { - $notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin requires at least %s version to work correctly with WooCommerce. Please update it', $this->get_text_domain() ), esc_html( $this->plugin_name ), $this->get_plugin_version_request( $this->slug ) ) ); + $notices[] = $this->prepare_notice_message( sprintf( __( 'The “%s” plugin requires at least %s version to work correctly with WooCommerce. Please update it', $this->get_text_domain() ), esc_html( $this->plugin_name ), $this->get_plugin_version( $this->slug ) ) ); } $notices = $this->append_plugin_require_notices( $notices ); @@ -342,35 +340,32 @@ if ( ! class_exists( 'WPDesk_Basic_Requirement_Checker' ) ) { /** * Plugin slug * - * @param string $slug + * @param string $slug . * * @return mixed */ - public function create_request( $slug ) { - $args = (object) array( 'slug' => $slug ); - $request = array( - 'action' => 'plugin_information', - 'timeout' => self::REQUEST_TIMEOUT, - 'request' => serialize( $args ) - ); - - $url = 'http://api.wordpress.org/plugins/info/1.0/'; - $response = wp_remote_post( $url, array( 'body' => $request ) ); + public function get_plugin_info_from_plugins_api( $slug ) { - return $response; + $transient_version = get_transient( $slug ); + $plugin_info = null; + if (false === $transient_version) { + require_once ABSPATH . 'wp-admin/includes/plugin-install.php'; + $plugin_info = plugins_api( 'plugin_information', array( 'slug' => $slug ) ); + + set_transient( $slug, $plugin_info, WEEK_IN_SECONDS ); + } + return $transient_version; } /** - * @param string $slug + * @param $slug * * @return bool */ - public function get_plugin_version_request( $slug ) { - - $response = $this->create_request( $slug ); - $plugin_info = unserialize( $response['body'] ); + public function get_plugin_version( $slug ) { + $plugin_info = $this->get_plugin_info_from_plugins_api( $slug ); if ( ! empty( $plugin_info ) ) { return $plugin_info->version; }