Plugin Directory

Changeset 3478117


Ignore:
Timestamp:
03/09/2026 12:47:16 PM (3 weeks ago)
Author:
klimentp
Message:

Version 1.1.0 - Replace images for blogs when regenerated images are republished from DraftSEO.ai and deleted old unused images from media folder in Wordpress

Location:
draftseo-ai
Files:
26 added
6 edited

Legend:

Unmodified
Added
Removed
  • draftseo-ai/trunk/README.md

    r3461555 r3478117  
    1 # DraftSEO.AI - WordPress Plugin
    2 
    3 Publish AI-generated blogs from DraftSEO.AI platform directly to WordPress with automatic image import and SEO optimization.
     1# DraftSEO.ai - WordPress Plugin
     2
     3Publish AI-generated blogs from DraftSEO.ai platform directly to WordPress with automatic image import and SEO optimization.
    44
    55## Installation
     
    88
    991. Go to WordPress Admin → Plugins → Add New
    10 2. Search for "DraftSEO.AI"
     102. Search for "DraftSEO.ai"
    11113. Click "Install Now" and then "Activate"
    1212
     
    23232. Copy the `draftseo-ai` directory to `wp-content/plugins/`
    24243. Go to WordPress Admin → Plugins
    25 4. Find "DraftSEO.AI" and click "Activate"
     254. Find "DraftSEO.ai" and click "Activate"
    2626
    2727## Configuration
    2828
    29291. Navigate to WordPress Admin → DraftSEO → Settings
    30 2. Click "Connect with DraftSEO.AI" button
    31    - You'll be automatically redirected to DraftSEO.AI
     302. Click "Connect with DraftSEO.ai" button
     31   - You'll be automatically redirected to DraftSEO.ai
    3232   - Sign in if you're not already logged in
    3333   - Connection completes automatically (OAuth-based, no API key needed)
     
    3636
    3737### Core Features
    38 - ✅ One-click publishing from DraftSEO.AI to WordPress
    39 - ✅ Automatic image import from DraftSEO.AI to WordPress Media Library
     38- ✅ One-click publishing from DraftSEO.ai to WordPress
     39- ✅ Automatic image import from DraftSEO.ai to WordPress Media Library
    4040- ✅ SEO metadata preservation (keywords, meta descriptions)
    4141- ✅ WordPress category sync
     
    5252  - Remaining images processed in background via WordPress Cron
    5353
    54 All images are downloaded directly from DraftSEO.AI to your WordPress Media Library.
     54All images are downloaded directly from DraftSEO.ai to your WordPress Media Library.
    5555
    5656
     
    5959### Publishing a Blog
    6060
    61 1. **Generate Blog on DraftSEO.AI**
    62    - Create your blog using DraftSEO.AI platform
     611. **Generate Blog on DraftSEO.ai**
     62   - Create your blog using DraftSEO.ai platform
    6363   - Configure SEO settings, categories, and tags
    6464
     
    7272### API Endpoints
    7373
    74 The plugin provides REST API endpoints for DraftSEO.AI integration:
     74The plugin provides REST API endpoints for DraftSEO.ai integration:
    7575
    7676- `GET /wp-json/draftseo/v1/users` - Get WordPress users
     
    8080- `POST /wp-json/draftseo/v1/update` - Update/republish existing post
    8181- `GET|POST /wp-json/draftseo/v1/test-connection` - Test API connection
    82 - `POST /wp-json/draftseo/v1/remote-disconnect` - Clear connection (called by DraftSEO.AI)
     82- `POST /wp-json/draftseo/v1/remote-disconnect` - Clear connection (called by DraftSEO.ai)
    8383
    8484All endpoints require Bearer token authentication using your API key.
     
    9090- **MySQL**: 5.6 or higher
    9191- **WordPress Cron**: Enabled (for background image processing)
    92 - **DraftSEO.AI Account**: Active subscription
     92- **DraftSEO.ai Account**: Active subscription
    9393
    9494## File Structure
     
    103103│   └── settings-page.php          # Settings page template
    104104├── includes/                       # Core plugin classes
    105 │   ├── class-api-client.php       # DraftSEO.AI API communication
     105│   ├── class-api-client.php       # DraftSEO.ai API communication
    106106│   ├── class-content-processor.php # HTML cleanup and formatting
    107107│   ├── class-image-handler.php    # Image import strategies
     
    169169## Credits
    170170
    171 Developed by [DraftSEO.AI](https://draftseo.ai)
     171Developed by [DraftSEO.ai](https://draftseo.ai)
    172172
    173173## Changelog
     174
     175### 1.1.0
     176
     177- **Image Replacement** — When a new image is generated and republished from DraftSEO.ai, replace the image inside the blog automatically.
     178- **Assets Cleanup** — The old now-unused image is auto-deleted from the Media folder in Wordpress. Saves storage space, cleans up unused media assets.
    174179
    175180### 1.0.5
     
    232237- **`rest_ensure_response()`** — All success responses now use `rest_ensure_response()` per WordPress REST API Handbook, allowing WordPress filters to process responses through the standard pipeline
    233238- **Input validation arguments** — `/publish` and `/update` routes now define `args` with `validate_callback` and `sanitize_callback` for server-side input validation before the handler runs
    234 - **Remote disconnect endpoint** — `/remote-disconnect` properly clears stored API key and connection settings when triggered from DraftSEO.AI platform
    235 - **Bidirectional disconnect sync** — When a user disconnects from DraftSEO.AI, the platform now calls the plugin's `/remote-disconnect` endpoint before local deletion, keeping both sides in sync
     239- **Remote disconnect endpoint** — `/remote-disconnect` properly clears stored API key and connection settings when triggered from DraftSEO.ai platform
     240- **Bidirectional disconnect sync** — When a user disconnects from DraftSEO.ai, the platform now calls the plugin's `/remote-disconnect` endpoint before local deletion, keeping both sides in sync
    236241
    237242#### Stability & Error Handling (6 improvements)
     
    268273
    269274#### Image Handling
    270 - Direct download from DraftSEO.AI to WordPress Media Library
     275- Direct download from DraftSEO.ai to WordPress Media Library
    271276- Alt text and heading text metadata preserved
    272277- Featured image setting with URL replacement in post content (Nebius URLs → local WordPress URLs)
     
    274279
    275280### 0.2.0 (Initial Beta)
    276 - One-click blog publishing from DraftSEO.AI
    277 - Automatic image import from DraftSEO.AI
     281- One-click blog publishing from DraftSEO.ai
     282- Automatic image import from DraftSEO.ai
    278283- SEO metadata transfer
    279284- WordPress category sync
  • draftseo-ai/trunk/admin/js/admin-scripts.js

    r3423447 r3478117  
    11/**
    2  * Admin JavaScript for DraftSEO.AI
     2 * Admin JavaScript for DraftSEO.ai
    33 *
    44 * @package DraftSEO_Publisher
     
    1212       
    1313        /**
    14          * Disconnect from DraftSEO.AI
     14         * Disconnect from DraftSEO.ai
    1515         */
    1616        $('#disconnect-draftseo').on('click', function(e) {
    1717            e.preventDefault();
    1818           
    19             if (!confirm('Are you sure you want to disconnect from DraftSEO.AI? You will need to reconnect to publish blogs.')) {
     19            if (!confirm('Are you sure you want to disconnect from DraftSEO.ai? You will need to reconnect to publish blogs.')) {
    2020                return;
    2121            }
  • draftseo-ai/trunk/admin/settings-page.php

    r3423447 r3478117  
    152152                                    <ol style="margin: 0; padding-left: 20px; color: #856404; font-size: 13px; line-height: 1.6;">
    153153                                        <li><?php esc_html_e('Log in to your DraftSEO.AI account in another browser tab first', 'draftseo-ai'); ?></li>
    154                                         <li><?php esc_html_e('Make sure the admin email of this WordPress site matches your DraftSEO.AI account email', 'draftseo-ai'); ?></li>
    155154                                        <li><?php esc_html_e('Then click the "Connect with DraftSEO.AI" button below', 'draftseo-ai'); ?></li>
    156155                                    </ol>
  • draftseo-ai/trunk/includes/class-image-handler.php

    r3423447 r3478117  
    9999            }
    100100           
     101            // Store URL hash for future lookup (enables deletion on republish)
     102            self::store_image_hash($attachment_id, $image['url']);
     103           
    101104            // Store URL mapping for replacement
    102105            $wp_url = wp_get_attachment_url($attachment_id);
     
    156159                    update_post_meta($featured_id, 'draftseo_heading_text', sanitize_text_field($featured_image['headingText']));
    157160                }
     161               
     162                // Store URL hash for future lookup (enables deletion on republish)
     163                self::store_image_hash($featured_id, $featured_image['url']);
    158164               
    159165                // Store URL mapping
     
    235241                update_post_meta($attachment_id, 'draftseo_heading_text', sanitize_text_field($image['headingText']));
    236242            }
     243           
     244            // Store URL hash for future lookup (enables deletion on republish)
     245            self::store_image_hash($attachment_id, $image['url']);
    237246           
    238247            // Store URL mapping
     
    308317   
    309318    /**
     319     * Delete WordPress media attachments by their original CDN source URLs
     320     *
     321     * Finds attachments tagged with draftseo_original_url and permanently deletes them.
     322     * Called during republish to clean up old images replaced by regeneration.
     323     *
     324     * @param array $urls Array of CDN URLs to look up and delete
     325     */
     326    public static function delete_images_by_urls($urls) {
     327        if (empty($urls) || !is_array($urls)) {
     328            return;
     329        }
     330       
     331        global $wpdb;
     332       
     333        foreach ($urls as $url) {
     334            if (empty($url)) {
     335                continue;
     336            }
     337           
     338            $url = esc_url_raw($url);
     339           
     340            // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery, WordPress.DB.DirectDatabaseQuery.NoCaching
     341            $attachment_id = $wpdb->get_var(
     342                $wpdb->prepare(
     343                    "SELECT post_id FROM {$wpdb->postmeta}
     344                    WHERE meta_key = 'draftseo_original_url'
     345                    AND meta_value = %s
     346                    LIMIT 1",
     347                    $url
     348                )
     349            );
     350           
     351            if ($attachment_id) {
     352                // Delete attachment and its files from disk
     353                wp_delete_attachment(intval($attachment_id), true);
     354               
     355                // Clear the URL hash cache entry
     356                $cache_key = 'draftseo_img_' . md5($url);
     357                wp_cache_delete($cache_key, 'draftseo_images');
     358            }
     359        }
     360    }
     361   
     362    /**
    310363     * Store image URL hash for duplicate detection
    311364     *
  • draftseo-ai/trunk/includes/class-rest-api.php

    r3461526 r3478117  
    498498        }
    499499       
     500        // Delete replaced images from media library before importing new ones
     501        if (isset($params['images_to_delete']) && is_array($params['images_to_delete']) && !empty($params['images_to_delete'])) {
     502            DraftSEO_Image_Handler::delete_images_by_urls($params['images_to_delete']);
     503        }
     504       
    500505        // Handle images if provided
    501506        $images_imported = 0;
  • draftseo-ai/trunk/readme.txt

    r3461555 r3478117  
    106106
    107107== Changelog ==
     108
     109= 1.1.0 =
     110
     111When a new image is generated and republished from DraftSEO.ai, the old now-unused image is auto-deleted from the Media folder in Wordpress. Saves storage space, cleans up unused media assets.
    108112
    109113= 1.0.5 =
     
    227231== Upgrade Notice ==
    228232
     233= 1.1.0 =
     234When a new image is generated and republished from DraftSEO.ai, the old now-unused image is auto-deleted from the Media folder in Wordpress. Saves storage space, cleans up unused media assets.
     235
     236= 1.0.5 =
     237Youtube Player styles for blogs.
     238
    229239= 1.0.4 =
    230240Fixes YouTube videos not rendering on WordPress by correcting pipeline order and preserving Gutenberg block markers. Also fixes headings appearing as raw markdown after images.
Note: See TracChangeset for help on using the changeset viewer.