AutoPurge.php
4 months ago
BeaverBuilder.php
4 months ago
CPTOptimization.php
4 months ago
CacheWarmup.php
4 months ago
CartCache.php
4 months ago
Components.php
4 months ago
EditorClearCache.php
4 months ago
GeneratePreview.php
7 months ago
HTMLCompression.php
4 months ago
Logger.php
4 months ago
OptimizationLevel.php
4 months ago
Optimizations.php
4 months ago
PurgeCache.php
4 months ago
Shortcodes.php
4 months ago
StockRefresh.php
4 months ago
Subscription.php
4 months ago
SystemReport.php
4 months ago
TestMode.php
4 months ago
Subscription.php
100 lines
| 1 | <?php |
| 2 | namespace NitroPack\WordPress\Settings; |
| 3 | |
| 4 | use NitroPack\HttpClient\HttpClient; |
| 5 | |
| 6 | defined( 'ABSPATH' ) || die( 'No script kiddies please!' ); |
| 7 | |
| 8 | /* Subscription class to handle subscription related functionalities */ |
| 9 | class Subscription { |
| 10 | private static $instance = null; |
| 11 | |
| 12 | /** |
| 13 | * Fetch plan details from NitroPack API |
| 14 | */ |
| 15 | public function fetch_plan() { |
| 16 | $planDetailsUrl = get_nitropack_integration_url( "plan_details_json" ); |
| 17 | $quickSetupHTTP = new HttpClient( $planDetailsUrl ); |
| 18 | $quickSetupHTTP->timeout = 30; |
| 19 | $quickSetupHTTP->fetch(); |
| 20 | $resp = $quickSetupHTTP->getStatusCode() == 200 ? json_decode( $quickSetupHTTP->getBody(), true ) : false; |
| 21 | return $resp; |
| 22 | } |
| 23 | public static function getInstance() { |
| 24 | if ( null === self::$instance ) { |
| 25 | self::$instance = new self(); |
| 26 | } |
| 27 | return self::$instance; |
| 28 | } |
| 29 | /** |
| 30 | * Render subscription box in our Dashboard |
| 31 | */ |
| 32 | public function render() { |
| 33 | $cdn_bandwidth_used = 'N/A'; |
| 34 | $max_cdn_bandwidth = 'N/A'; |
| 35 | $page_views = 'N/A'; |
| 36 | $max_page_views = 'N/A'; |
| 37 | $plan = $this->fetch_plan(); |
| 38 | if ( $plan ) { |
| 39 | $plan_title = isset( $plan['plan_title'] ) ? $plan['plan_title'] : 'N/A'; |
| 40 | $next_reset = isset( $plan['next_reset'] ) ? $plan['next_reset'] : 'N/A'; |
| 41 | $next_billing = isset( $plan['next_billing'] ) ? $plan['next_billing'] : 'N/A'; |
| 42 | $page_views = isset( $plan['page_views'] ) ? $plan['page_views'] : 'N/A'; |
| 43 | $max_page_views = isset( $plan['max_page_views'] ) ? $plan['max_page_views'] : 'N/A'; |
| 44 | $cdn_bandwidth_used = isset( $plan['cdn_bandwidth'] ) ? $plan['cdn_bandwidth'] : 'N/A'; |
| 45 | $max_cdn_bandwidth = isset( $plan['max_cdn_bandwidth'] ) ? $plan['max_cdn_bandwidth'] : 'N/A'; |
| 46 | } |
| 47 | ?> |
| 48 | <div class="card card-subscription"> |
| 49 | <div class="card-header"> |
| 50 | <h3><?php esc_html_e( 'Subscription', 'nitropack' ); ?></h3> |
| 51 | </div> |
| 52 | <div class="card-body"> |
| 53 | <div class="flex flex-row items-center"> |
| 54 | <div class="plan-name"><?php echo esc_html( $plan_title ); ?></div> |
| 55 | <?php $components = new Components(); |
| 56 | echo $components->render_button( [ 'text' => 'Manage subscription', 'type' => null, 'classes' => 'btn btn-secondary ml-auto', 'href' => 'https://app.nitropack.io/account/billing', 'attributes' => [ 'id' => 'btn-manage-subscription', 'target' => '_blank' ] ] ); |
| 57 | ?> |
| 58 | </div> |
| 59 | <div class="table-wrapper"> |
| 60 | <table class="w-full"> |
| 61 | <tbody> |
| 62 | <tr> |
| 63 | <td class="key"><?php esc_html_e( 'Next reset', 'nitropack' ); ?></td> |
| 64 | <td class="value" data-next-reset><?php echo esc_html( $next_reset ); ?></td> |
| 65 | </tr> |
| 66 | <tr> |
| 67 | <td class="key"><?php esc_html_e( 'Next billing', 'nitropack' ); ?></td> |
| 68 | <td class="value" data-next-billing><?php echo esc_html( $next_billing ); ?></td> |
| 69 | </tr> |
| 70 | <tr> |
| 71 | <td class="key"><?php esc_html_e( 'Page views', 'nitropack' ); ?></td> |
| 72 | <td class="value" data-page-views> |
| 73 | <?php |
| 74 | /* translators: %1$s: current page views, %2$s: maximum page views */ |
| 75 | printf( esc_html__( '%1$s out of %2$s', 'nitropack' ), $page_views, $max_page_views ); |
| 76 | ?> |
| 77 | </td> |
| 78 | </tr> |
| 79 | <tr> |
| 80 | <td class="key"><?php esc_html_e( 'CDN bandwidth', 'nitropack' ); ?></td> |
| 81 | <td class="value" data-cdn-bandwidth> |
| 82 | <?php |
| 83 | /* translators: %1$s: used CDN bandwidth, %2$s: maximum CDN bandwidth */ |
| 84 | printf( esc_html__( '%1$s out of %2$s', 'nitropack' ), $cdn_bandwidth_used, $max_cdn_bandwidth ); |
| 85 | ?> |
| 86 | </td> |
| 87 | </tr> |
| 88 | </tbody> |
| 89 | </table> |
| 90 | </div> |
| 91 | </div> |
| 92 | <div class="card-footer"> |
| 93 | <p class="text-secondary text-smaller"> |
| 94 | <?php esc_html_e( 'You will be notified by email when your website reaches the subscription resource limits.', 'nitropack' ); ?> |
| 95 | </p> |
| 96 | </div> |
| 97 | </div> |
| 98 | <?php |
| 99 | } |
| 100 | } |