| @@ -14,9 +14,12 @@ | ||
| 14 | 14 | $this->get( 'profile/purchased-items', [ $this, 'get_my_purchased_items' ] ); |
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | public function sync() { |
| 18 | - $query = 'status, message, user{ id, name, first_name, last_name, display_name, email, profile_photo, joined, is_verified, api_key, plan, plan_expire_at, my_cloud{ limit, usages, last_pushed }, favourites{ id, type }, show_notice, reviews{ type, type_id, rating } }'; | |
| 18 | + // Keep the `subscription` field set in step with `Login::login()` — the | |
| 19 | + // Subscription screen renders from whichever of the two answered last, so a | |
| 20 | + // field missing here silently degrades the card after a profile sync. | |
| 21 | + $query = 'status, message, user{ id, name, first_name, last_name, display_name, email, profile_photo, joined, is_verified, is_restricted_company_user, api_key, plan, plan_expire_at, my_cloud{ limit, usages, last_pushed }, favourites{ id, type }, show_notice, reviews{ type, type_id, rating }, subscription { id, name, sites, subscription_plan_id, ends_at, plan_type, cancel_at_period_end } }'; | |
| 19 | 22 | |
| 20 | 23 | $funcArgs = [ |
| 21 | 24 | 'api_key' => $this->api_key, |
| 22 | 25 | 'site_url' => home_url( '/' ), |
| @@ -64,8 +67,20 @@ | ||
| 64 | 67 | unset( $response['user']['reviews'] ); |
| 65 | 68 | $meta['reviews'] = $_reviews; |
| 66 | 69 | } |
| 67 | 70 | |
| 71 | + if ( ! empty( $response['user'] ) && is_array( $response['user'] ) ) { | |
| 72 | + /** | |
| 73 | + * The cloud API key must never be persisted here or sent to the client. | |
| 74 | + * Under a global login this key belongs to the admin, while any user with | |
| 75 | + * `delete_posts` can reach this endpoint. Login and SignUp already drop it. | |
| 76 | + */ | |
| 77 | + unset( $response['user']['api_key'] ); | |
| 78 | + | |
| 79 | + $response['user']['site_url'] = base64_encode( home_url( '/' ) ); | |
| 80 | + $response['user']['ip'] = Helper::get_ip(); | |
| 81 | + } | |
| 82 | + | |
| 68 | 83 | $this->utils( 'options' )->set( 'user', $response['user'] ); |
| 69 | 84 | $response['user']['meta'] = Login::get_instance()->user_meta( $meta ); |
| 70 | 85 | |
| 71 | 86 | return $this->success( $response ); |
| @@ -77,9 +92,9 @@ | ||
| 77 | 92 | ]; |
| 78 | 93 | |
| 79 | 94 | $response = $this->http()->query( 'isVerifiedUser', '', $funcArgs )->post(); |
| 80 | 95 | |
| 81 | - if ( $response ) { | |
| 96 | + if ( $response && !is_wp_error( $response ) ) { | |
| 82 | 97 | $user = $this->utils( 'options' )->get( 'user' ); |
| 83 | 98 | |
| 84 | 99 | $user['is_verified'] = true; |
| 85 | 100 | $this->utils( 'options' )->set( 'user', $user ); |
| @@ -98,9 +113,9 @@ | ||
| 98 | 113 | "page" => $page |
| 99 | 114 | ] )->post(); |
| 100 | 115 | |
| 101 | 116 | if ( is_wp_error( $response ) ) { |
| 102 | - return $this->error( 'invalid_download_history_response', __( $response->get_error_message(), 'templately' ), 'profile/download-history', $response->get_error_code() ); | |
| 117 | + return $this->error( 'invalid_download_history_response', __( $response->get_error_message(), 'templately' ), 'profile/download-history' ); | |
| 103 | 118 | } |
| 104 | 119 | |
| 105 | 120 | if ( isset( $response['total'] ) ) { |
| 106 | 121 | $this->utils( 'options' )->set( 'total_download_counts', $response['total'] ); |
| @@ -129,9 +144,9 @@ | ||
| 129 | 144 | |
| 130 | 145 | $response = $this->http()->mutation( 'myFavouriteItem', 'total_page, current_page, data { id, name, rating, type, slug, favourite_count, thumbnail, thumbnail2, thumbnail3, price, author{ display_name, name, joined }, dependencies{ id, name, icon, plugin_file, plugin_original_slug, is_pro, link } }', $funcArgs )->post(); |
| 131 | 146 | |
| 132 | 147 | if ( is_wp_error( $response ) ) { |
| 133 | - return $this->error( 'invalid_my_favourites_response', __( $response->get_error_message(), 'templately' ), 'profile/my-favourites', $response->get_error_code() ); | |
| 148 | + return $this->error( 'invalid_my_favourites_response', __( $response->get_error_message(), 'templately' ), 'profile/my-favourites' ); | |
| 134 | 149 | } |
| 135 | 150 | |
| 136 | 151 | return $response; |
| 137 | 152 | } |
| @@ -139,11 +154,13 @@ | ||
| 139 | 154 | public function get_my_purchased_items() { |
| 140 | 155 | $page = $this->get_param( 'page', 1, 'intval' ); |
| 141 | 156 | $per_page = $this->get_param( 'per_page', 10, 'intval' ); |
| 142 | 157 | $_all = $this->get_param( 'all', false ); |
| 158 | + $platform = $this->get_param( 'platform', 'elementor' ); | |
| 143 | 159 | |
| 144 | 160 | $funcArgs = [ |
| 145 | 161 | 'api_key' => $this->api_key, |
| 162 | + 'platform' => $platform, | |
| 146 | 163 | 'page' => $page, |
| 147 | 164 | 'per_page' => $per_page |
| 148 | 165 | ]; |
| 149 | 166 | |