Plugin Directory


Ignore:
Timestamp:
11/06/2026 06:43:40 AM (3 days ago)
Author:
remwes
Message:

Improved upgrade button, cleaner error messages, bug fixes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • autocontent/trunk/autocontent.php

    r3787274 r3787313  
    55 * Plugin URI:  https://autocontent.com/about/
    66 * Description:   The simplest solution for automating content creation on WordPress.
    7  * Version:  1.38
     7 * Version:  1.39
    88 * Requires at least:  6.5
    99 * Requires PHP:  8.2
    … …  
    592592                                        if ($frequency === 'monthly') {
    593593                                            echo '<span id="current-plan-text" style="vertical-align: sub; padding">Free (Monthly Blog Posts)</span>';
    594                                             echo '<button id="upgrade_button" type="button" class="button button-secondary">Upgrade</button>';
     594                                            echo '<button id="upgrade_button" type="button" class="button button-secondary">' . esc_html__('Upgrade to Premium', 'autocontent') . ' <span aria-hidden="true">&rarr;</span></button>';
    595595                                        } elseif ($frequency === 'daily') {
    596596                                            echo esc_html('Autocontent Premium (Daily Blog Posts)');
    … …  
    11271127    if (empty($keywords) || empty($subject)) {
    11281128        autocontent_log_error_message('Keywords and subject are required. Cannot make API call');
    1129         return;
     1129        return new WP_Error('autocontent_settings', __('Add a subject and at least one keyword, then click Save Changes before generating a post.', 'autocontent'));
    11301130    }
    11311131   // Prepare the POST data
    … …  
    11621162    if (is_wp_error($response)) {
    11631163       autocontent_log_error_message('API request error: ' . $response->get_error_message());
    1164        return;
     1164       return new WP_Error('autocontent_unreachable', __('Could not reach the Autocontent service. Please try again in a few minutes.', 'autocontent'));
    11651165    }
    11661166
    … …  
    12221222        }
    12231223    } else {
    1224         // Handle errors
     1224        // Handle errors: turn the API's answer into a message the user can act on.
    12251225        autocontent_log_error_message('API request error: ' . $body);
     1226        return new WP_Error('autocontent_api', autocontent_api_error_message($data));
    12261227    }
    12271228   
    … …  
    13881389
    13891390// Function to hand generating post manually
     1391/**
     1392 * Human-readable message for a failed generate request.
     1393 */
     1394function autocontent_api_error_message($data) {
     1395    $error = is_array($data) && !empty($data['error']) ? (string) $data['error'] : '';
     1396    if (strpos($error, 'doesUserHaveEnoughCredits') !== false) {
     1397        return __('You are out of WriteNow credits. Your scheduled posts will continue as normal.', 'autocontent');
     1398    }
     1399    if (strpos($error, 'subscriptionInactive') !== false) {
     1400        return __('Your Autocontent Premium subscription has ended. Renew at autocontent.com to keep your daily posts and WriteNow credits.', 'autocontent');
     1401    }
     1402    if (strpos($error, 'isValidActivationKey') !== false || strpos($error, 'isValidWebsiteOrigin') !== false) {
     1403        return __('Your activation key could not be verified for this site. Re-enter your key under Upgrade, then try again.', 'autocontent');
     1404    }
     1405    if ($error !== '' && strpos($error, 'Unauthorized') === false) {
     1406        return $error;
     1407    }
     1408    return __('Post generation failed. No credit was used. Please try again in a few minutes.', 'autocontent');
     1409}
     1410
    13901411function autocontent_generate_post_now_callback() {
    13911412    autocontent_log_error_message('AJAX call: autocontent_generate_post_now_callback');
    … …  
    14021423    $post_id = autocontent($callType);
    14031424    // Check if the post was created successfully and get the post URL
    1404     if (!is_wp_error($post_id)) {
     1425    if (is_wp_error($post_id)) {
     1426        autocontent_log_error_message('Error generating post: ' . $post_id->get_error_message());
     1427        wp_send_json_error(array('message' => $post_id->get_error_message()));
     1428    } elseif (empty($post_id)) {
     1429        autocontent_log_error_message('Error generating post: no post created.');
     1430        wp_send_json_error(array('message' => __('Post generation failed. Please try again in a few minutes.', 'autocontent')));
     1431    } else {
    14051432        $post_url = get_permalink($post_id);
     1433        autocontent_log_error_message("Post generated successfully. Post ID: $post_id, Post URL: $post_url");
    14061434        wp_send_json_success(array('post_url' => $post_url));
    1407         autocontent_log_error_message("Post generated successfully. Post ID: $post_id, Post URL: $post_url");
    1408     } else {
    1409         autocontent_log_error_message('Error generating post.');
    1410         wp_send_json_error('Error generating post');
    1411 
    14121435    }
    14131436}
Note: See TracChangeset for help on using the changeset viewer.