diff --git a/includes/classes/class-directorist-api.php b/includes/classes/class-directorist-api.php
new file mode 100644
index 0000000000..87f1f14112
--- /dev/null
+++ b/includes/classes/class-directorist-api.php
@@ -0,0 +1,100 @@
+promo_end_date ) ) ||
+ ( is_array( $promotion ) && empty( $promotion['promo_end_date'] ) ) ) {
+ return ( 3 * DAY_IN_SECONDS );
+ }
+
+ $promotion = (object) $promotion;
+ $end_time = is_numeric( $promotion->promo_end_date ) ? (int) $promotion->promo_end_date : strtotime( $promotion->promo_end_date );
+ $end_time = $end_time - time();
+
+ return $end_time;
+ }
+
+ /**
+ * @return object
+ */
+ public static function get_products() {
+ $products = get_transient( 'directorist_products' );
+
+ if ( ! empty( $products ) ) {
+ return $products;
+ }
+
+ $products = static::get( 'v1/get-remote-products' );
+
+ if ( empty( $products ) ) {
+ return array(
+ 'themes' => array(),
+ 'extensions' => array(),
+ );
+ }
+
+ $products = json_decode( $products, true );
+
+ set_transient( 'directorist_products', $products, 30 * DAY_IN_SECONDS );
+
+ return $products;
+ }
+
+ /**
+ * @return array
+ */
+ protected static function get_request_args() {
+ return array(
+ 'method' => 'GET',
+ 'timeout' => 30,
+ 'redirection' => 5,
+ 'headers' => array(
+ 'user-agent' => 'Directorist/' . ATBDP_VERSION,
+ 'Accept' => 'application/json',
+ ),
+ 'cookies' => array(),
+ );
+ }
+
+ /**
+ *
+ * @return string
+ */
+ public static function get( $endpoint = '' ) {
+ $url = static::URL . $endpoint;
+ $response = wp_remote_get( $url, static::get_request_args() );
+
+ return wp_remote_retrieve_body( $response );
+ }
+}
diff --git a/includes/classes/class-extension.php b/includes/classes/class-extension.php
index 13e2533f2d..90bb9cd907 100644
--- a/includes/classes/class-extension.php
+++ b/includes/classes/class-extension.php
@@ -20,6 +20,8 @@
return;
}
+use Directorist\Core\API;
+
if ( ! class_exists( 'ATBDP_Extensions' ) ) {
/**
@@ -209,38 +211,10 @@ public function has_match_in_active_plugins( $plugin_name = '' ) {
// get_the_products_list
public function setup_products_list() {
+ $products = API::get_products();
- $url = 'https://app.directorist.com/wp-json/directorist/v1/get-remote-products?' . ATBDP_VERSION;
- $headers = array(
- 'user-agent' => 'Directorist/' . md5( esc_url( home_url() ) ) . ';',
- 'Accept' => 'application/json',
- );
-
- $config = array(
- 'method' => 'GET',
- 'timeout' => 30,
- 'redirection' => 5,
- 'httpversion' => '1.0',
- 'headers' => $headers,
- 'cookies' => array(),
- );
-
- $response_body = array();
-
- try {
- $response = wp_remote_get( $url, $config );
-
- if ( ! is_wp_error( $response ) ) {
- $response_body = is_string( $response['body'] ) ? json_decode( $response['body'], true ) : $response['body'];
- $extensions = $response_body['extensions'];
- $themes = $response_body['themes'];
-
- $this->extensions = apply_filters( 'atbdp_extension_list', $extensions );
- $this->themes = apply_filters( 'atbdp_theme_list', $themes );
- }
- } catch ( Exception $e ) {
-
- }
+ $this->extensions = apply_filters( 'atbdp_extension_list', $products['extensions'] );
+ $this->themes = apply_filters( 'atbdp_theme_list', $products['themes'] );
}
// exclude_purchased_extensions
@@ -319,13 +293,12 @@ public function exclude_purchased_themes( $themes ) {
public function get_active_extensions() {
$active_extensions = array();
- foreach ( $this->extensions as $extension_key => $extension_args ) {
-
- if ( empty( $extension_args['active'] ) ) {
+ foreach ( $this->extensions as $extension_slug => $extension ) {
+ if ( empty( $extension['active'] ) ) {
continue;
}
- $active_extensions[ $extension_key ] = $extension_args;
+ $active_extensions[ $extension_slug ] = $extension;
}
return $active_extensions;
@@ -335,13 +308,12 @@ public function get_active_extensions() {
public function get_active_themes() {
$active_themes = array();
- foreach ( $this->themes as $theme_key => $theme_args ) {
-
- if ( empty( $theme_args['active'] ) ) {
+ foreach ( $this->themes as $theme_slug => $theme ) {
+ if ( empty( $theme['active'] ) ) {
continue;
}
- $active_themes[ $theme_key ] = $theme_args;
+ $active_themes[ $theme_slug ] = $theme;
}
return $active_themes;
diff --git a/includes/classes/class-upgrade.php b/includes/classes/class-upgrade.php
index 34edb90643..eedbf83de4 100644
--- a/includes/classes/class-upgrade.php
+++ b/includes/classes/class-upgrade.php
@@ -1,5 +1,7 @@
'Directorist/' . md5( esc_url( home_url() ) ) . ';',
- 'Accept' => 'application/json',
- ];
-
- $config = [
- 'method' => 'GET',
- 'timeout' => 30,
- 'redirection' => 5,
- 'httpversion' => '1.0',
- 'headers' => $headers,
- 'cookies' => [],
- ];
-
- $response_body = [];
-
- $cached_response = get_transient( 'directorist_get_promo_banner' );
-
- if( $cached_response ) {
- $response_body = $cached_response;
- } else {
- try {
- $response = wp_remote_get( $url, $config );
- $response_body = ! is_wp_error( $response ) ? wp_remote_retrieve_body( $response ) : [];
- set_transient( 'directorist_get_promo_banner', $response_body, 24 * HOUR_IN_SECONDS );
- } catch ( Exception $e ) {
- return $response_body;
- }
- }
-
- $response_body = is_string( $response_body ) ? json_decode( $response_body ) : $response_body;
-
- return $response_body;
+ return API::get_promotion();
}
public function upgrade_notice() {
@@ -192,4 +161,4 @@ public static function promo_link( $link ) {
return $link;
}
-}
\ No newline at end of file
+}
diff --git a/views/admin-templates/theme-extensions/all-themes-extensions.php b/views/admin-templates/theme-extensions/all-themes-extensions.php
index c900ddd841..0a64b46a94 100644
--- a/views/admin-templates/theme-extensions/all-themes-extensions.php
+++ b/views/admin-templates/theme-extensions/all-themes-extensions.php
@@ -1,11 +1,12 @@