Changeset 3478429
- Timestamp:
- 03/09/2026 06:17:21 PM (3 weeks ago)
- Location:
- mediahue-webp-converter
- Files:
-
- 6 added
- 4 edited
-
tags/1.0.2 (added)
-
tags/1.0.2/assets (added)
-
tags/1.0.2/assets/admin-webp.css (added)
-
tags/1.0.2/assets/admin-webp.js (added)
-
tags/1.0.2/mediahue-webp-converter.php (added)
-
tags/1.0.2/readme.txt (added)
-
trunk/assets/admin-webp.css (modified) (1 diff)
-
trunk/assets/admin-webp.js (modified) (5 diffs)
-
trunk/mediahue-webp-converter.php (modified) (17 diffs)
-
trunk/readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mediahue-webp-converter/trunk/assets/admin-webp.css
r3476630 r3478429 412 412 } 413 413 414 /* Progress spinner */ 415 .mhwc-admin .mhwc-progress-spinner { 416 display: inline-block; 417 width: 16px; 418 height: 16px; 419 border: 2px solid rgba(31, 27, 23, 0.3); 420 border-radius: 50%; 421 border-top-color: var(--mhwc-accent); 422 animation: mhwc-spin 1s ease-in-out infinite; 423 margin-right: 8px; 424 } 425 414 426 @keyframes mhwc-spin { 415 427 to { -
mediahue-webp-converter/trunk/assets/admin-webp.js
r3476630 r3478429 13 13 $(document).on('click', '.mhwc-convert-batch-btn', function(e) { 14 14 e.preventDefault(); 15 var $button = $(this); 16 var $container = $button.closest('.mhwc-card'); 17 var limit = $container.find('input[name="limit"]').val(); 18 19 // Store original button text 20 $button.data('original-text', $button.html()); 21 self.startBatchProcess('convert', $container, limit); 15 var limit = $('#convert_limit').val(); 16 limit = parseInt(limit) || 50; 17 self.startBatchProcess('convert', $(this).closest('.mhwc-card'), limit); 22 18 }); 23 19 … … 25 21 $(document).on('click', '.mhwc-delete-batch-btn', function(e) { 26 22 e.preventDefault(); 27 var $button = $(this); 28 var $container = $button.closest('.mhwc-card'); 29 var limit = $container.find('input[name="limit"]').val(); 30 31 // Store original button text 32 $button.data('original-text', $button.html()); 33 self.startBatchProcess('delete', $container, limit); 23 var limit = $('#delete_limit').val(); 24 limit = parseInt(limit) || 50; 25 self.startBatchProcess('delete', $(this).closest('.mhwc-card'), limit); 34 26 }); 35 27 … … 45 37 var $container = $(this).closest('.mhwc-card'); 46 38 var type = $container.find('.mhwc-batch-progress').hasClass('mhwc-error') ? self.type : 'convert'; 47 var limit = $container.find('input[name="limit"]').val(); 39 var limit = type === 'convert' ? $('#convert_limit').val() : $('#delete_limit').val(); 40 limit = parseInt(limit) || 50; 48 41 49 42 // Remove error UI and restart … … 126 119 url: mhwc_ajax.ajax_url, 127 120 type: 'POST', 128 timeout: 30000, // 30 seconds timeout121 timeout: 120000, // 120 seconds timeout 129 122 data: { 130 123 action: 'mhwc_bulk_' + this.type, … … 156 149 157 150 updateProgressDetails: function(message) { 158 this.$container.find('.mhwc-progress-details').html('<span class="mhwc-pro cessing-indicator">⏳</span> ' + message);151 this.$container.find('.mhwc-progress-details').html('<span class="mhwc-progress-spinner"></span> ' + message); 159 152 }, 160 153 -
mediahue-webp-converter/trunk/mediahue-webp-converter.php
r3476630 r3478429 3 3 * Plugin Name: MediaHue – Webp Converter for WordPress 4 4 * Description: Automatically convert WordPress images to WebP format to improve website performance, reduce image size, and boost SEO. 5 * Version: 1.0. 16 * Author: Solanki Software5 * Version: 1.0.2 6 * Author: Kirtikumar Solanki 7 7 * Author URI: https://profiles.wordpress.org/solankisoftware/ 8 8 * License: GPLv2 or later … … 332 332 333 333 public static function mhwc_get_webp_path( $file_path ) { 334 $upload_dir = wp_get_upload_dir(); 335 $base_dir = trailingslashit( $upload_dir['basedir'] ); 336 $webp_base_dir = trailingslashit( $base_dir . 'mediahue-webp-converter-attachments' ); 337 338 // Ensure the directory exists 339 if ( ! file_exists( $webp_base_dir ) ) { 340 wp_mkdir_p( $webp_base_dir ); 341 } 342 343 // Get relative path from uploads 344 if ( strpos( $file_path, $base_dir ) === 0 ) { 345 $relative = substr( $file_path, strlen( $base_dir ) ); 346 $webp_path = $webp_base_dir . preg_replace( '/\.(jpe?g|png)$/i', '.webp', $relative ); 347 348 // Ensure subdirectory exists 349 $webp_dir = dirname( $webp_path ); 350 if ( ! file_exists( $webp_dir ) ) { 351 wp_mkdir_p( $webp_dir ); 352 } 353 354 return $webp_path; 355 } 356 357 // Fallback for files outside uploads 334 358 return preg_replace( '/\.(jpe?g|png)$/i', '.webp', $file_path ); 335 359 } … … 339 363 $base_dir = trailingslashit( $upload_dir['basedir'] ); 340 364 $base_url = trailingslashit( $upload_dir['baseurl'] ); 365 $webp_base_dir = trailingslashit( $base_dir . 'mediahue-webp-converter-attachments' ); 366 $webp_base_url = trailingslashit( $base_url . 'mediahue-webp-converter-attachments' ); 367 368 if ( strpos( $file_path, $webp_base_dir ) === 0 ) { 369 $relative = substr( $file_path, strlen( $webp_base_dir ) ); 370 return $webp_base_url . $relative; 371 } 372 373 // Fallback 341 374 if ( strpos( $file_path, $base_dir ) !== 0 ) return false; 342 375 $relative = ltrim( str_replace( $base_dir, '', $file_path ), '/' ); … … 509 542 <label> 510 543 <?php echo esc_html__( 'Batch size', 'mediahue-webp-converter' ); ?> 511 <input type="number" name="convert_limit" min="1" max="200" value="50" />544 <input type="number" id="convert_limit" name="convert_limit" min="1" max="200" value="50" /> 512 545 </label> 513 546 <button type="button" class="button button-primary mhwc-convert-batch-btn"> … … 526 559 <label> 527 560 <?php echo esc_html__( 'Batch size', 'mediahue-webp-converter' ); ?> 528 <input type="number" name="delete_limit" min="1" max="200" value="50" />561 <input type="number" id="delete_limit" name="delete_limit" min="1" max="200" value="50" /> 529 562 </label> 530 563 <button type="button" class="button button-delete mhwc-delete-batch-btn"> … … 553 586 plugin_dir_url( __FILE__ ) . 'assets/admin-webp.css', 554 587 array(), 555 '1.0. 0'588 '1.0.2' 556 589 ); 557 590 wp_enqueue_script( … … 559 592 plugin_dir_url( __FILE__ ) . 'assets/admin-webp.js', 560 593 array( 'jquery' ), 561 '1.0. 0',594 '1.0.6', 562 595 true 563 596 ); … … 608 641 check_admin_referer( self::mhwc_nonce_action( 'bulk_convert' ) ); 609 642 643 // Prevent PHP timeout for long processes 644 set_time_limit( 600 ); // 10 minutes 645 610 646 $limit = isset( $_POST['limit'] ) ? max( 1, min( 200, intval( $_POST['limit'] ) ) ) : 50; 611 647 $offset = isset( $_POST['offset'] ) ? max( 0, intval( $_POST['offset'] ) ) : 0; 612 648 613 $ ids = get_posts( array(649 $all_ids = get_posts( array( 614 650 'post_type' => 'attachment', 615 651 'post_mime_type' => array( 'image/jpeg', 'image/png' ), 616 652 'fields' => 'ids', 617 'posts_per_page' => $limit, 618 'offset' => $offset, 653 'posts_per_page' => -1, 654 'orderby' => 'ID', 655 'order' => 'ASC', 619 656 ) ); 657 658 $ids = array(); 659 foreach ( $all_ids as $attachment_id ) { 660 $file = get_attached_file( $attachment_id ); 661 if ( $file && ! file_exists( self::mhwc_get_webp_path( $file ) ) ) { 662 $ids[] = $attachment_id; 663 if ( count( $ids ) >= $limit ) { 664 break; 665 } 666 } 667 } 620 668 621 669 $converted = 0; … … 638 686 } 639 687 640 $has_more = ( count( $ids ) === $limit );641 $total_processed = $offset +count( $ids );688 $has_more = false; // Process only one batch of $limit 689 $total_processed = count( $ids ); 642 690 $stats = self::mhwc_get_conversion_stats(); 643 691 $current_percentage = $stats['total'] > 0 ? round( ( $stats['converted'] / $stats['total'] ) * 100, 1 ) : 0; … … 646 694 'page' => self::mhwc_tools_page_slug(), 647 695 'converted' => $converted, 648 'offset' => $offset + $limit,649 'has_more' => $has_more ? 1 :0,696 'offset' => 0, // Reset offset since we process only one batch 697 'has_more' => 0, 650 698 'processed' => $total_processed, 651 699 'percentage' => $current_percentage, … … 670 718 check_admin_referer( self::mhwc_nonce_action( 'bulk_delete' ) ); 671 719 720 // Prevent PHP timeout for long processes 721 set_time_limit( 600 ); // 10 minutes 722 672 723 $limit = isset( $_POST['limit'] ) ? max( 1, min( 200, intval( $_POST['limit'] ) ) ) : 50; 673 724 $offset = isset( $_POST['offset'] ) ? max( 0, intval( $_POST['offset'] ) ) : 0; 674 725 675 $ ids = get_posts( array(726 $all_ids = get_posts( array( 676 727 'post_type' => 'attachment', 677 728 'post_mime_type' => array( 'image/jpeg', 'image/png' ), 678 729 'fields' => 'ids', 679 'posts_per_page' => $limit, 680 'offset' => $offset, 730 'posts_per_page' => -1, 731 'orderby' => 'ID', 732 'order' => 'ASC', 681 733 ) ); 734 735 $ids = array(); 736 foreach ( $all_ids as $attachment_id ) { 737 $file = get_attached_file( $attachment_id ); 738 if ( $file && file_exists( self::mhwc_get_webp_path( $file ) ) ) { 739 $ids[] = $attachment_id; 740 if ( count( $ids ) >= $limit ) { 741 break; 742 } 743 } 744 } 682 745 683 746 $deleted = 0; … … 686 749 } 687 750 688 $has_more = ( count( $ids ) === $limit );751 $has_more = false; // Process only one batch of $limit 689 752 $redirect = add_query_arg( 690 753 array( 691 754 'page' => self::mhwc_tools_page_slug(), 692 755 'deleted' => $deleted, 693 'offset' => $offset + $limit,694 'has_more_delete' => $has_more ? 1 :0,756 'offset' => 0, // Reset offset 757 'has_more_delete' => 0, 695 758 ), 696 759 admin_url( 'upload.php' ) … … 726 789 $offset = isset( $_POST['offset'] ) ? max( 0, intval( $_POST['offset'] ) ) : 0; 727 790 728 $ ids = get_posts( array(791 $all_ids = get_posts( array( 729 792 'post_type' => 'attachment', 730 793 'post_mime_type' => array( 'image/jpeg', 'image/png' ), 731 794 'fields' => 'ids', 732 'posts_per_page' => $limit, 733 'offset' => $offset, 795 'posts_per_page' => -1, 796 'orderby' => 'ID', 797 'order' => 'ASC', 734 798 ) ); 799 800 $ids = array(); 801 foreach ( $all_ids as $attachment_id ) { 802 $file = get_attached_file( $attachment_id ); 803 if ( $file && ! file_exists( self::mhwc_get_webp_path( $file ) ) ) { 804 $ids[] = $attachment_id; 805 if ( count( $ids ) >= $limit ) { 806 break; 807 } 808 } 809 } 735 810 736 811 $converted = 0; … … 753 828 } 754 829 755 $has_more = ( count( $ids ) === $limit );830 $has_more = false; // Process only one batch of $limit 756 831 $stats = self::mhwc_get_conversion_stats(); 757 832 … … 761 836 'failed' => $failed, 762 837 'has_more' => $has_more, 763 'offset' => $offset + $limit,838 'offset' => 0, // Reset offset 764 839 'total_converted' => $stats['converted'], 765 840 'total_images' => $stats['total'], … … 782 857 $offset = isset( $_POST['offset'] ) ? max( 0, intval( $_POST['offset'] ) ) : 0; 783 858 784 $ ids = get_posts( array(859 $all_ids = get_posts( array( 785 860 'post_type' => 'attachment', 786 861 'post_mime_type' => array( 'image/jpeg', 'image/png' ), 787 862 'fields' => 'ids', 788 'posts_per_page' => $limit, 789 'offset' => $offset, 863 'posts_per_page' => -1, 864 'orderby' => 'ID', 865 'order' => 'ASC', 790 866 ) ); 867 868 $ids = array(); 869 foreach ( $all_ids as $attachment_id ) { 870 $file = get_attached_file( $attachment_id ); 871 if ( $file && file_exists( self::mhwc_get_webp_path( $file ) ) ) { 872 $ids[] = $attachment_id; 873 if ( count( $ids ) >= $limit ) { 874 break; 875 } 876 } 877 } 791 878 792 879 $deleted = 0; … … 795 882 } 796 883 797 $has_more = ( count( $ids ) === $limit );884 $has_more = false; // Process only one batch of $limit 798 885 799 886 wp_send_json_success( array( 800 887 'deleted' => $deleted, 801 888 'has_more' => $has_more, 802 'offset' => $offset + $limit,889 'offset' => 0, // Reset offset 803 890 ) ); 804 891 } catch ( Exception $e ) { -
mediahue-webp-converter/trunk/readme.txt
r3476630 r3478429 6 6 Tested up to: 6.9 7 7 Requires PHP: 7.4 8 Stable tag: 1.0. 18 Stable tag: 1.0.2 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 51 51 52 52 == Changelog == 53 = 1.0.2 = 54 * Fixed batch limit input selection issue. 55 * Added input validation with fallback value (50). 56 * Increased AJAX timeout and PHP execution time for large batches. 57 * Ensured consistent batch processing with ID ASC ordering. 58 * Updated batch logic to process one batch per run. 59 * Added loading indicators for convert/delete actions. 60 * Added dedicated folder for WebP files with automatic creation. 61 * Improved file organization and cache busting. 62 53 63 = 1.0.1 54 64 * Improve Design and Set Bacth process using Ajax
Note: See TracChangeset
for help on using the changeset viewer.