Plugin Directory

Changeset 3787313


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

Improved upgrade button, cleaner error messages, bug fixes

Location:
autocontent
Files:
4 edited
7 copied

Legend:

Unmodified
Added
Removed
  • autocontent/tags/1.39/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}
  • autocontent/tags/1.39/readme.txt

    r3787274 r3787313  
    44Requires at least: 6.5
    55Tested up to: 7.1
    6 Stable tag: 1.38
     6Stable tag: 1.39
    77Requires PHP: 8.2
    88License: GPLv2 or later
    … …  
    7171== Changelog ==
    7272
     73= 1.39 =
     74* New "Upgrade to Premium" button on the Settings page.
     75* Generate Blog Post Now now explains why a post could not be created (for example missing keywords, no credits left, or a temporary service problem) instead of always reporting insufficient credits.
     76* Clear message when an Autocontent Premium subscription has ended, with a reminder to renew.
     77
    7378= 1.38 =
    7479* Redesigned upgrade window: Monthly/Yearly toggle (save 25% yearly), clearer pricing and features, and a "Get Premium" button.
  • autocontent/tags/1.39/script.js

    r3787274 r3787313  
    177177                .catch(error => {
    178178                    console.error("Error verifying activation key:", error);
    179                     showMessageInUpgradeModal("Failed to verify activation key. Please try again.", false);
     179                    showMessageInUpgradeModal(error && error.message === 'Subscription inactive'
     180                        ? "Your Autocontent Premium subscription has ended. Renew at autocontent.com to reactivate this key."
     181                        : "Failed to verify activation key. Please try again.", false);
    180182                    verifyButton.innerHTML = "Verify";
    181183                    verifyButton.disabled = false;
    … …  
    306308                });
    307309            } else {
     310                if (data && data.status === 'Subscription inactive') {
     311                    showMessage('Your Autocontent Premium subscription has ended. Renew at autocontent.com to reactivate this key.', false);
     312                    throw new Error('Subscription inactive');
     313                }
    308314                showMessage('Invalid Key', false);
    309315                // showMessage('Activation Key is Invalid &#10005;', false);
    … …  
    320326        .catch(error => {
    321327            console.error('Error:', error);
     328            if (error && error.message === 'Subscription inactive') {
     329                throw error; // keep the subscription message already shown
     330            }
    322331            showMessage('Invalid Key', false);
    323332            throw new Error('Invalid Activation Key');
    … …  
    417426                document.getElementById('processingContainer').style.display = 'none';
    418427
    419                 if (data.success) {
     428                if (data.success && data.data && data.data.post_url) {
    420429                    showModal(data.data.post_url); // Show success modal with the post URL
    421430                } else {
    422                     showModal(false); // Show failed modal since post generation failed
     431                    showModal(false, data && data.data && data.data.message); // Show the reason it failed
    423432                }
    424433            })
    … …  
    430439    }
    431440
    432     function showModal(postUrl) {
     441    function showModal(postUrl, errorMessage) {
    433442
    434443        // Create the modal HTML
    … …  
    439448        if (!postUrl) {
    440449            // If postUrl is false, show "Failed to Post"
    441             modalHtml += '<p>Failed to generate post: Insufficient WriteNow credits</p>';
     450            var reason = document.createElement('span');
     451            reason.textContent = errorMessage || 'Post generation failed. Please try again in a few minutes.';
     452            modalHtml += '<p>Failed to generate post: ' + reason.innerHTML + '</p>';
    442453        } else {
    443454            // If postUrl is valid, show success message with the link
  • autocontent/tags/1.39/styles.css

    r3787274 r3787313  
    795795    #upgradeModal .ac-upgrade__cta:hover { transform: none; }
    796796}
     797
     798/* Upgrade button on the Settings page (1.38) */
     799#upgrade_button.button {
     800    display: inline-flex;
     801    align-items: center;
     802    gap: 6px;
     803    margin-left: 12px;
     804    padding: 0 18px;
     805    min-height: 36px;
     806    border: 0;
     807    border-radius: 999px;
     808    background: linear-gradient(135deg, #4f97ff 0%, #3d89fb 55%, #2a6fd6 100%);
     809    box-shadow: 0 4px 12px rgba(61, 137, 251, 0.35);
     810    color: #fff;
     811    font-size: 13px;
     812    font-weight: 700;
     813    line-height: 36px;
     814    letter-spacing: 0.01em;
     815    vertical-align: middle;
     816    cursor: pointer;
     817    transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
     818}
     819#upgrade_button.button:hover,
     820#upgrade_button.button:focus-visible {
     821    color: #fff;
     822    filter: brightness(1.05);
     823    box-shadow: 0 6px 16px rgba(61, 137, 251, 0.45);
     824    transform: translateY(-1px);
     825    outline: none;
     826}
     827#upgrade_button.button:focus-visible { box-shadow: 0 0 0 3px rgba(61, 137, 251, 0.35), 0 6px 16px rgba(61, 137, 251, 0.45); }
     828#upgrade_button.button span { transition: transform 0.15s; }
     829#upgrade_button.button:hover span { transform: translateX(2px); }
     830@media (prefers-reduced-motion: reduce) {
     831    #upgrade_button.button, #upgrade_button.button span { transition: none; transform: none; }
     832}
  • 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}
  • autocontent/trunk/readme.txt

    r3787274 r3787313  
    44Requires at least: 6.5
    55Tested up to: 7.1
    6 Stable tag: 1.38
     6Stable tag: 1.39
    77Requires PHP: 8.2
    88License: GPLv2 or later
    … …  
    7171== Changelog ==
    7272
     73= 1.39 =
     74* New "Upgrade to Premium" button on the Settings page.
     75* Generate Blog Post Now now explains why a post could not be created (for example missing keywords, no credits left, or a temporary service problem) instead of always reporting insufficient credits.
     76* Clear message when an Autocontent Premium subscription has ended, with a reminder to renew.
     77
    7378= 1.38 =
    7479* Redesigned upgrade window: Monthly/Yearly toggle (save 25% yearly), clearer pricing and features, and a "Get Premium" button.
  • autocontent/trunk/script.js

    r3787274 r3787313  
    177177                .catch(error => {
    178178                    console.error("Error verifying activation key:", error);
    179                     showMessageInUpgradeModal("Failed to verify activation key. Please try again.", false);
     179                    showMessageInUpgradeModal(error && error.message === 'Subscription inactive'
     180                        ? "Your Autocontent Premium subscription has ended. Renew at autocontent.com to reactivate this key."
     181                        : "Failed to verify activation key. Please try again.", false);
    180182                    verifyButton.innerHTML = "Verify";
    181183                    verifyButton.disabled = false;
    … …  
    306308                });
    307309            } else {
     310                if (data && data.status === 'Subscription inactive') {
     311                    showMessage('Your Autocontent Premium subscription has ended. Renew at autocontent.com to reactivate this key.', false);
     312                    throw new Error('Subscription inactive');
     313                }
    308314                showMessage('Invalid Key', false);
    309315                // showMessage('Activation Key is Invalid &#10005;', false);
    … …  
    320326        .catch(error => {
    321327            console.error('Error:', error);
     328            if (error && error.message === 'Subscription inactive') {
     329                throw error; // keep the subscription message already shown
     330            }
    322331            showMessage('Invalid Key', false);
    323332            throw new Error('Invalid Activation Key');
    … …  
    417426                document.getElementById('processingContainer').style.display = 'none';
    418427
    419                 if (data.success) {
     428                if (data.success && data.data && data.data.post_url) {
    420429                    showModal(data.data.post_url); // Show success modal with the post URL
    421430                } else {
    422                     showModal(false); // Show failed modal since post generation failed
     431                    showModal(false, data && data.data && data.data.message); // Show the reason it failed
    423432                }
    424433            })
    … …  
    430439    }
    431440
    432     function showModal(postUrl) {
     441    function showModal(postUrl, errorMessage) {
    433442
    434443        // Create the modal HTML
    … …  
    439448        if (!postUrl) {
    440449            // If postUrl is false, show "Failed to Post"
    441             modalHtml += '<p>Failed to generate post: Insufficient WriteNow credits</p>';
     450            var reason = document.createElement('span');
     451            reason.textContent = errorMessage || 'Post generation failed. Please try again in a few minutes.';
     452            modalHtml += '<p>Failed to generate post: ' + reason.innerHTML + '</p>';
    442453        } else {
    443454            // If postUrl is valid, show success message with the link
  • autocontent/trunk/styles.css

    r3787274 r3787313  
    795795    #upgradeModal .ac-upgrade__cta:hover { transform: none; }
    796796}
     797
     798/* Upgrade button on the Settings page (1.38) */
     799#upgrade_button.button {
     800    display: inline-flex;
     801    align-items: center;
     802    gap: 6px;
     803    margin-left: 12px;
     804    padding: 0 18px;
     805    min-height: 36px;
     806    border: 0;
     807    border-radius: 999px;
     808    background: linear-gradient(135deg, #4f97ff 0%, #3d89fb 55%, #2a6fd6 100%);
     809    box-shadow: 0 4px 12px rgba(61, 137, 251, 0.35);
     810    color: #fff;
     811    font-size: 13px;
     812    font-weight: 700;
     813    line-height: 36px;
     814    letter-spacing: 0.01em;
     815    vertical-align: middle;
     816    cursor: pointer;
     817    transition: transform 0.15s, box-shadow 0.15s, filter 0.15s;
     818}
     819#upgrade_button.button:hover,
     820#upgrade_button.button:focus-visible {
     821    color: #fff;
     822    filter: brightness(1.05);
     823    box-shadow: 0 6px 16px rgba(61, 137, 251, 0.45);
     824    transform: translateY(-1px);
     825    outline: none;
     826}
     827#upgrade_button.button:focus-visible { box-shadow: 0 0 0 3px rgba(61, 137, 251, 0.35), 0 6px 16px rgba(61, 137, 251, 0.45); }
     828#upgrade_button.button span { transition: transform 0.15s; }
     829#upgrade_button.button:hover span { transform: translateX(2px); }
     830@media (prefers-reduced-motion: reduce) {
     831    #upgrade_button.button, #upgrade_button.button span { transition: none; transform: none; }
     832}
Note: See TracChangeset for help on using the changeset viewer.