Plugin Directory

Changeset 3379243


Ignore:
Timestamp:
10/16/2025 06:18:56 AM (5 months ago)
Author:
hmamoun
Message:

Update to version 2.1.2 - Maintenance release with compatibility updates

Location:
ai-story-maker/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • ai-story-maker/trunk/README.txt

    r3379225 r3379243  
    55Tested up to: 6.8
    66Requires PHP: 7.4
    7 Stable tag: 2.1.1
     7Stable tag: 2.1.2
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    331331== Changelog ==
    332332
     333= 2.1.2 =
     334* **Maintenance Release**
     335  * Version bump for WordPress.org deployment
     336  * Ensured compatibility with latest WordPress version
     337  * Minor documentation updates
     338
    333339= 2.1.1 =
    334340* **Security & Code Quality Improvements**
  • ai-story-maker/trunk/admin/class-aistma-admin.php

    r3379225 r3379243  
    11471147                );
    11481148            }
     1149           
     1150            // If subscription check failed but we have an error message, log it for debugging
     1151            if ( isset( $subscription_status['error'] ) ) {
     1152                $this->aistma_log_manager->log( 'warning', 'Subscription validation failed: ' . $subscription_status['error'] );
     1153            }
     1154           
     1155            // Try fallback: check if UI shows active subscription (packages-summary endpoint)
     1156            $fallback_check = $this->check_subscription_via_packages_api();
     1157            if ( $fallback_check['valid'] ) {
     1158                $this->aistma_log_manager->log( 'info', 'Subscription validated via packages API fallback' );
     1159                return array(
     1160                    'valid' => true,
     1161                    'message' => __( 'Valid subscription found (via packages API)', 'ai-story-maker' ),
     1162                    'type' => 'subscription'
     1163                );
     1164            }
     1165           
    11491166        } catch ( \Exception $e ) {
    1150             // Subscription check failed, continue to API key check
     1167            // Subscription check failed, log the exception and continue to API key check
     1168            $this->aistma_log_manager->log( 'warning', 'Subscription check exception: ' . $e->getMessage() );
    11511169        }
    11521170
     
    12511269
    12521270    /**
     1271     * Fallback method to check subscription via packages API (same as UI).
     1272     *
     1273     * @return array Validation result.
     1274     */
     1275    private function check_subscription_via_packages_api() {
     1276        try {
     1277            $settings_page = AISTMA_Settings_Page::get_instance();
     1278            $response_body = $settings_page->aistma_get_available_packages();
     1279           
     1280            // Parse the response similar to how the UI does it
     1281            $decoded_wrapper = json_decode( $response_body, true );
     1282            if ( json_last_error() === JSON_ERROR_NONE && is_array( $decoded_wrapper ) && isset( $decoded_wrapper['body'] ) ) {
     1283                $packages_json = is_string( $decoded_wrapper['body'] ) ? $decoded_wrapper['body'] : json_encode( $decoded_wrapper['body'] );
     1284            } else {
     1285                $packages_json = $response_body;
     1286            }
     1287
     1288            $packages = json_decode( $packages_json, true );
     1289            if ( json_last_error() !== JSON_ERROR_NONE || ! is_array( $packages ) ) {
     1290                return array( 'valid' => false, 'error' => 'Invalid packages response' );
     1291            }
     1292
     1293            // Check if any package shows an active subscription
     1294            foreach ( $packages as $package ) {
     1295                if ( is_array( $package ) && isset( $package['subscription_status'] ) && isset( $package['subscription_info'] ) ) {
     1296                    $subscription_info = $package['subscription_info'];
     1297                    // Check if subscription is active and has credits
     1298                    if ( isset( $subscription_info['credits_total'] ) && isset( $subscription_info['credits_used'] ) ) {
     1299                        $credits_remaining = $subscription_info['credits_total'] - $subscription_info['credits_used'];
     1300                        if ( $credits_remaining > 0 ) {
     1301                            $this->aistma_log_manager->log( 'info', 'Active subscription found via packages API: ' . $credits_remaining . ' credits remaining' );
     1302                            return array( 'valid' => true, 'credits_remaining' => $credits_remaining );
     1303                        }
     1304                    }
     1305                }
     1306            }
     1307           
     1308            return array( 'valid' => false, 'error' => 'No active subscription found in packages API' );
     1309        } catch ( \Exception $e ) {
     1310            $this->aistma_log_manager->log( 'error', 'Error checking subscription via packages API: ' . $e->getMessage() );
     1311            return array( 'valid' => false, 'error' => 'Packages API check failed: ' . $e->getMessage() );
     1312        }
     1313    }
     1314
     1315    /**
    12531316     * Get subscription status (helper method).
    12541317     *
     
    12561319     */
    12571320    private function aistma_get_subscription_status() {
    1258         // This method should be implemented based on your subscription checking logic
    1259         // For now, we'll use a simplified version
    1260         $master_url = defined( 'AISTMA_MASTER_URL' ) ? AISTMA_MASTER_URL : '';
    1261         if ( empty( $master_url ) ) {
    1262             return array( 'valid' => false, 'error' => 'Master URL not configured' );
    1263         }
    1264 
    1265         $current_domain = sanitize_text_field( wp_unslash( $_SERVER['HTTP_HOST'] ?? '' ) );
    1266         if ( empty( $current_domain ) ) {
    1267             return array( 'valid' => false, 'error' => 'Domain not detected' );
    1268         }
    1269 
    1270         // Make API call to check subscription status
    1271         $response = wp_remote_get(
    1272             $master_url . 'wp-json/exaig/v1/verify-subscription?domain=' . urlencode( $current_domain ),
    1273             array( 'timeout' => 10 )
    1274         );
    1275 
    1276         if ( is_wp_error( $response ) ) {
    1277             return array( 'valid' => false, 'error' => 'API request failed: ' . $response->get_error_message() );
    1278         }
    1279 
    1280         $body = wp_remote_retrieve_body( $response );
    1281         $data = json_decode( $body, true );
    1282 
    1283         if ( isset( $data['valid'] ) && $data['valid'] ) {
    1284             return array(
    1285                 'valid' => true,
    1286                 'domain' => $current_domain,
    1287                 'package_name' => $data['package_name'] ?? 'Unknown',
    1288                 'package_id' => $data['package_id'] ?? null
    1289             );
    1290         }
    1291 
    1292         return array( 'valid' => false, 'error' => 'No valid subscription found' );
     1321        // Use the story generator's subscription status method
     1322        $story_generator = new AISTMA_Story_Generator();
     1323        return $story_generator->aistma_get_subscription_status();
    12931324    }
    12941325
  • ai-story-maker/trunk/ai-story-maker.php

    r3379225 r3379243  
    44 * Plugin URI: https://www.storymakerplugin.com/
    55 * Description: AI-powered content generator for WordPress — create engaging stories with a single click.
    6  * Version: 2.1.1
     6 * Version: 2.1.2
    77 * Author: Hayan Mamoun
    88 * Author URI: https://exedotcom.ca
  • ai-story-maker/trunk/includes/class-aistma-story-generator.php

    r3379225 r3379243  
    10081008       
    10091009        if ( empty( $master_url ) ) {
     1010            $this->aistma_log_manager->log( 'error', 'API Gateway URL not configured' );
    10101011            $this->subscription_status = array(
    10111012                'valid' => false,
    10121013                'domain' => $domain,
     1014                'error' => 'API Gateway URL not configured',
    10131015            );
    10141016            return $this->subscription_status;
     
    10171019        // Make API call to master server to check subscription status
    10181020        $api_url = trailingslashit( $master_url ) . 'wp-json/exaig/v1/verify-subscription?domain=' . urlencode( $domain );
     1021       
     1022        $this->aistma_log_manager->log( 'info', 'Checking subscription status for domain: ' . $domain . ' at URL: ' . $api_url );
    10191023       
    10201024        $response = wp_remote_get( $api_url, array(
     
    10221026            'headers' => array(
    10231027                'User-Agent' => 'AI-Story-Maker/1.0',
     1028                'X-Caller-Url' => home_url(),
     1029                'X-Caller-IP' => isset( $_SERVER['SERVER_ADDR'] ) ? sanitize_text_field( wp_unslash( $_SERVER['SERVER_ADDR'] ) ) : '',
    10241030            ),
    10251031        ) );
     
    10381044        $response_code = wp_remote_retrieve_response_code( $response );
    10391045        $response_body = wp_remote_retrieve_body( $response );
     1046       
     1047        $this->aistma_log_manager->log( 'info', 'Subscription API response code: ' . $response_code . ', body: ' . substr( $response_body, 0, 500 ) );
     1048       
    10401049        $data = json_decode( $response_body, true );
    10411050
    10421051        if ( $response_code !== 200 ) {
    1043             $this->aistma_log_manager->log( 'error', 'API error checking subscription status. Response code: ' . $response_code );
     1052            $this->aistma_log_manager->log( 'error', 'API error checking subscription status. Response code: ' . $response_code . ', Body: ' . $response_body );
    10441053            $this->subscription_status = array(
    10451054                'valid' => false,
     
    10511060
    10521061        if ( json_last_error() !== JSON_ERROR_NONE ) {
    1053             $this->aistma_log_manager->log( 'error', 'Invalid JSON response from subscription API' );
     1062            $this->aistma_log_manager->log( 'error', 'Invalid JSON response from subscription API. Body: ' . $response_body );
    10541063            $this->subscription_status = array(
    10551064                'valid' => false,
     
    10611070        // if valid but status is "active_no_credits" then set the status to false and set the message to "No credits remaining"
    10621071        if ( isset( $data['valid'] ) && $data['valid'] && isset( $data['status'] ) && $data['status'] === 'active_no_credits' ) {
     1072            $this->aistma_log_manager->log( 'info', 'Subscription valid but no credits remaining for domain: ' . $domain );
    10631073            $this->subscription_status = array(
    10641074                'valid' => false,
     
    10811091            );
    10821092        } else {
    1083             //$this->aistma_log_manager->log( 'info', 'No active subscription found for domain: ' . $domain );
     1093            $this->aistma_log_manager->log( 'info', 'No active subscription found for domain: ' . $domain . ', message: ' . ( $data['message'] ?? 'No message' ) );
    10841094            $this->subscription_status = array(
    10851095                'valid' => false,
Note: See TracChangeset for help on using the changeset viewer.