Changeset 3476630
- Timestamp:
- 03/06/2026 06:31:43 PM (3 weeks ago)
- Location:
- mediahue-webp-converter
- Files:
-
- 7 added
- 4 edited
-
assets/screenshot-1.png (modified) (previous)
-
tags/1.0.1 (added)
-
tags/1.0.1/assets (added)
-
tags/1.0.1/assets/admin-webp.css (added)
-
tags/1.0.1/assets/admin-webp.js (added)
-
tags/1.0.1/mediahue-webp-converter.php (added)
-
tags/1.0.1/readme.txt (added)
-
trunk/assets/admin-webp.css (modified) (1 diff)
-
trunk/assets/admin-webp.js (added)
-
trunk/mediahue-webp-converter.php (modified) (15 diffs)
-
trunk/readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
mediahue-webp-converter/trunk/assets/admin-webp.css
r3463707 r3476630 81 81 } 82 82 83 .mhwc-admin .mhwc-badge.is-neutral { 84 background: rgba(31, 27, 23, 0.08); 85 color: var(--mhwc-muted); 83 .mhwc-admin .mhwc-badge.is-info { 84 background: rgba(47, 143, 123, 0.12); 85 color: #135546; 86 } 87 88 .mhwc-admin .mhwc-progress-bar { 89 width: 100%; 90 height: 8px; 91 background: rgba(31, 27, 23, 0.12); 92 border-radius: 4px; 93 margin: 12px 0 8px; 94 overflow: hidden; 95 } 96 97 .mhwc-admin .mhwc-progress-fill { 98 height: 100%; 99 background: linear-gradient(90deg, var(--mhwc-accent) 0%, var(--mhwc-mint) 100%); 100 border-radius: 4px; 101 transition: width 0.3s ease; 102 } 103 104 .mhwc-admin .mhwc-hero__panel p { 105 margin: 8px 0 12px; 106 font-weight: 600; 107 color: var(--mhwc-ink); 108 } 109 110 .mhwc-admin .mhwc-note--success { 111 color: var(--mhwc-mint); 112 font-weight: 600; 113 } 114 115 .mhwc-admin .mhwc-batch-progress { 116 background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%); 117 border: 2px solid #e2e8f0; 118 border-radius: 16px; 119 padding: 24px; 120 margin: 20px 0; 121 position: relative; 122 overflow: hidden; 123 box-shadow: 0 10px 25px rgba(0, 0, 0, 0.1), 0 4px 10px rgba(0, 0, 0, 0.05); 124 animation: mhwc-slide-in 0.4s ease-out; 125 } 126 127 .mhwc-admin .mhwc-batch-progress::before { 128 content: ''; 129 position: absolute; 130 top: 0; 131 left: 0; 132 right: 0; 133 height: 4px; 134 background: linear-gradient(90deg, var(--mhwc-accent) 0%, var(--mhwc-mint) 50%, var(--mhwc-accent) 100%); 135 background-size: 200% 100%; 136 animation: mhwc-progress-shine 2s infinite linear; 137 } 138 139 .mhwc-admin .mhwc-progress-header { 140 display: flex; 141 justify-content: space-between; 142 align-items: center; 143 margin-bottom: 20px; 144 position: relative; 145 z-index: 2; 146 } 147 148 .mhwc-admin .mhwc-progress-title { 149 font-weight: 700; 150 font-size: 16px; 151 color: #1a202c; 152 display: flex; 153 align-items: center; 154 gap: 8px; 155 } 156 157 .mhwc-admin .mhwc-progress-title::before { 158 content: '⚡'; 159 font-size: 18px; 160 animation: mhwc-pulse 1.5s infinite; 161 } 162 163 .mhwc-admin .mhwc-progress-title.mhwc-complete::before { 164 content: '✅'; 165 animation: none; 166 } 167 168 .mhwc-admin .mhwc-progress-title.mhwc-error::before { 169 content: '❌'; 170 animation: none; 171 } 172 173 .mhwc-admin .mhwc-cancel-batch { 174 background: linear-gradient(135deg, #e53e3e 0%, #c53030 100%); 175 border: none; 176 color: white; 177 padding: 8px 16px; 178 border-radius: 8px; 179 font-size: 13px; 180 font-weight: 600; 181 cursor: pointer; 182 transition: all 0.2s ease; 183 box-shadow: 0 2px 4px rgba(197, 48, 48, 0.2); 184 } 185 186 .mhwc-admin .mhwc-cancel-batch:hover { 187 background: linear-gradient(135deg, #c53030 0%, #9b2c2c 100%); 188 transform: translateY(-1px); 189 box-shadow: 0 4px 8px rgba(197, 48, 48, 0.3); 190 } 191 192 .mhwc-admin .mhwc-progress-bar-container { 193 width: 100%; 194 height: 16px; 195 background: #edf2f7; 196 border-radius: 8px; 197 overflow: hidden; 198 margin-bottom: 16px; 199 position: relative; 200 box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1); 201 } 202 203 .mhwc-admin .mhwc-progress-bar-fill { 204 height: 100%; 205 background: linear-gradient(90deg, var(--mhwc-accent) 0%, var(--mhwc-mint) 50%, var(--mhwc-accent) 100%); 206 background-size: 200% 100%; 207 border-radius: 8px; 208 transition: width 0.8s cubic-bezier(0.4, 0, 0.2, 1); 209 position: relative; 210 animation: mhwc-progress-fill 0.8s ease-out; 211 box-shadow: 0 0 10px rgba(255, 122, 61, 0.3); 212 } 213 214 .mhwc-admin .mhwc-progress-bar-fill::after { 215 content: ''; 216 position: absolute; 217 top: 0; 218 left: 0; 219 right: 0; 220 bottom: 0; 221 background: linear-gradient( 222 90deg, 223 transparent 0%, 224 rgba(255, 255, 255, 0.4) 50%, 225 transparent 100% 226 ); 227 animation: mhwc-shimmer 2s infinite; 228 } 229 230 .mhwc-admin .mhwc-progress-text { 231 text-align: center; 232 font-weight: 700; 233 font-size: 18px; 234 color: #2d3748; 235 margin-bottom: 8px; 236 text-shadow: 0 1px 2px rgba(0, 0, 0, 0.1); 237 } 238 239 .mhwc-admin .mhwc-progress-details { 240 text-align: center; 241 color: #718096; 242 font-size: 14px; 243 line-height: 1.5; 244 background: rgba(255, 255, 255, 0.8); 245 padding: 12px 16px; 246 border-radius: 8px; 247 border: 1px solid #e2e8f0; 248 position: relative; 249 z-index: 2; 250 } 251 252 .mhwc-admin .mhwc-progress-details strong { 253 color: #2d3748; 254 font-weight: 600; 255 } 256 257 .mhwc-admin .mhwc-batch-progress.mhwc-error { 258 border-color: #e53e3e; 259 background: linear-gradient(135deg, #fed7d7 0%, #feb2b2 100%); 260 } 261 262 .mhwc-admin .mhwc-batch-progress.mhwc-error .mhwc-progress-bar-container { 263 background: #fed7d7; 264 } 265 266 .mhwc-admin .mhwc-batch-progress.mhwc-complete { 267 border-color: var(--mhwc-mint); 268 background: linear-gradient(135deg, #c6f6d5 0%, #9ae6b4 100%); 269 } 270 271 .mhwc-admin .mhwc-batch-progress.mhwc-complete .mhwc-progress-bar-fill { 272 background: linear-gradient(90deg, var(--mhwc-mint) 0%, #38a169 100%); 273 box-shadow: 0 0 15px rgba(72, 187, 120, 0.4); 274 } 275 276 @keyframes mhwc-fade-in { 277 from { 278 opacity: 0; 279 transform: translateY(-10px); 280 } 281 to { 282 opacity: 1; 283 transform: translateY(0); 284 } 285 } 286 287 @keyframes mhwc-slide-in { 288 from { 289 opacity: 0; 290 transform: translateY(-20px) scale(0.95); 291 } 292 to { 293 opacity: 1; 294 transform: translateY(0) scale(1); 295 } 296 } 297 298 @keyframes mhwc-progress-shine { 299 0% { 300 background-position: -200% 0; 301 } 302 100% { 303 background-position: 200% 0; 304 } 305 } 306 307 @keyframes mhwc-pulse { 308 0%, 100% { 309 transform: scale(1); 310 opacity: 1; 311 } 312 50% { 313 transform: scale(1.1); 314 opacity: 0.8; 315 } 316 } 317 318 @keyframes mhwc-progress-fill { 319 from { 320 transform: scaleX(0); 321 } 322 to { 323 transform: scaleX(1); 324 } 325 } 326 327 @keyframes mhwc-shimmer { 328 0% { 329 transform: translateX(-100%); 330 } 331 100% { 332 transform: translateX(100%); 333 } 334 } 335 336 @keyframes mhwc-bounce-in { 337 0% { 338 transform: scale(0.3); 339 opacity: 0; 340 } 341 50% { 342 transform: scale(1.05); 343 } 344 70% { 345 transform: scale(0.9); 346 } 347 100% { 348 transform: scale(1); 349 opacity: 1; 350 } 351 } 352 353 /* Enhanced button styles */ 354 .mhwc-admin .mhwc-convert-batch-btn, 355 .mhwc-admin .mhwc-delete-batch-btn { 356 background: linear-gradient(135deg, var(--mhwc-accent) 0%, var(--mhwc-accent-deep) 100%); 357 border: none; 358 color: white; 359 padding: 12px 24px; 360 border-radius: 10px; 361 font-size: 14px; 362 font-weight: 600; 363 cursor: pointer; 364 transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1); 365 box-shadow: 0 4px 12px rgba(255, 122, 61, 0.3); 366 position: relative; 367 overflow: hidden; 368 } 369 370 .mhwc-admin .mhwc-convert-batch-btn::before, 371 .mhwc-admin .mhwc-delete-batch-btn::before { 372 content: ''; 373 position: absolute; 374 top: 0; 375 left: -100%; 376 width: 100%; 377 height: 100%; 378 background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.2), transparent); 379 transition: left 0.5s; 380 } 381 382 .mhwc-admin .mhwc-convert-batch-btn:hover, 383 .mhwc-admin .mhwc-delete-batch-btn:hover { 384 transform: translateY(-2px); 385 box-shadow: 0 8px 20px rgba(255, 122, 61, 0.4); 386 } 387 388 .mhwc-admin .mhwc-convert-batch-btn:hover::before, 389 .mhwc-admin .mhwc-delete-batch-btn:hover::before { 390 left: 100%; 391 } 392 393 .mhwc-admin .mhwc-delete-batch-btn { 394 background: linear-gradient(135deg, #e53e3e 0%, #c53030 100%); 395 box-shadow: 0 4px 12px rgba(229, 62, 62, 0.3); 396 } 397 398 .mhwc-admin .mhwc-delete-batch-btn:hover { 399 box-shadow: 0 8px 20px rgba(229, 62, 62, 0.4); 400 } 401 402 /* Loading spinner */ 403 .mhwc-admin .mhwc-loading-spinner { 404 display: inline-block; 405 width: 16px; 406 height: 16px; 407 border: 2px solid rgba(255, 255, 255, 0.3); 408 border-radius: 50%; 409 border-top-color: white; 410 animation: mhwc-spin 1s ease-in-out infinite; 411 margin-right: 8px; 412 } 413 414 @keyframes mhwc-spin { 415 to { 416 transform: rotate(360deg); 417 } 418 } 419 420 /* Success animation */ 421 .mhwc-admin .mhwc-success-checkmark { 422 display: inline-block; 423 width: 20px; 424 height: 20px; 425 border-radius: 50%; 426 background: #38a169; 427 position: relative; 428 animation: mhwc-bounce-in 0.6s ease-out; 429 margin-right: 8px; 430 } 431 432 .mhwc-admin .mhwc-success-checkmark::after { 433 content: '✓'; 434 position: absolute; 435 top: 50%; 436 left: 50%; 437 transform: translate(-50%, -50%); 438 color: white; 439 font-weight: bold; 440 font-size: 12px; 441 } 442 443 /* Responsive improvements */ 444 @media (max-width: 782px) { 445 .mhwc-admin .mhwc-batch-progress { 446 padding: 16px; 447 margin: 16px 0; 448 } 449 450 .mhwc-admin .mhwc-progress-header { 451 flex-direction: column; 452 gap: 12px; 453 align-items: flex-start; 454 } 455 456 .mhwc-admin .mhwc-cancel-batch { 457 align-self: flex-end; 458 } 459 460 .mhwc-admin .mhwc-convert-batch-btn, 461 .mhwc-admin .mhwc-delete-batch-btn { 462 width: 100%; 463 margin-bottom: 8px; 464 } 465 } 466 467 @keyframes mhwc-shimmer { 468 0% { 469 transform: translateX(-100%); 470 } 471 100% { 472 transform: translateX(100%); 473 } 86 474 } 87 475 -
mediahue-webp-converter/trunk/mediahue-webp-converter.php
r3463707 r3476630 1 1 <?php 2 2 /** 3 * Plugin Name: MediaHue – Image To Webp Converter3 * 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. 05 * Version: 1.0.1 6 6 * Author: Solanki Software 7 7 * Author URI: https://profiles.wordpress.org/solankisoftware/ … … 37 37 add_action( 'admin_post_' . self::mhwc_action_name( 'bulk_delete' ), array( __CLASS__, 'mhwc_handle_bulk_delete' ) ); 38 38 add_action( 'admin_post_' . self::mhwc_action_name( 'convert_single' ), array( __CLASS__, 'mhwc_handle_single_convert' ) ); 39 40 add_action( 'wp_ajax_' . self::mhwc_action_name( 'bulk_convert' ), array( __CLASS__, 'mhwc_ajax_bulk_convert' ) ); 41 add_action( 'wp_ajax_' . self::mhwc_action_name( 'bulk_delete' ), array( __CLASS__, 'mhwc_ajax_bulk_delete' ) ); 39 42 40 43 add_action( 'delete_attachment', array( __CLASS__, 'mhwc_delete_webp_on_attachment_delete' ), 20 ); … … 317 320 public static function mhwc_create_webp_from_file( $file_path, $quality ) { 318 321 $webp_path = self::mhwc_get_webp_path( $file_path ); 319 if ( file_exists( $webp_path ) ) return $webp_path;322 if ( file_exists( $webp_path ) ) return false; // Already exists, no conversion needed 320 323 321 324 $editor = wp_get_image_editor( $file_path ); … … 438 441 if ( ! current_user_can( 'manage_options' ) ) return; 439 442 $converted = isset( $_GET['converted'] ) ? intval( $_GET['converted'] ) : 0; 443 $already_converted = isset( $_GET['already_converted'] ) ? intval( $_GET['already_converted'] ) : 0; 444 $failed = isset( $_GET['failed'] ) ? intval( $_GET['failed'] ) : 0; 440 445 $deleted = isset( $_GET['deleted'] ) ? intval( $_GET['deleted'] ) : 0; 441 446 $offset = isset( $_GET['offset'] ) ? intval( $_GET['offset'] ) : 0; … … 444 449 $options = self::mhwc_get_options(); 445 450 $is_supported = self::mhwc_is_webp_supported(); 451 $stats = self::mhwc_get_conversion_stats(); 446 452 ?> 447 453 <div class="wrap mhwc-admin"> … … 460 466 <?php echo esc_html( sprintf( __( 'Quality %d', 'mediahue-webp-converter' ), intval( $options['quality'] ) ) ); ?> 461 467 </span> 468 <span class="mhwc-badge is-info"> 469 <?php echo esc_html( sprintf( __( 'Converted: %d/%d (%s%%)', 'mediahue-webp-converter' ), $stats['converted'], $stats['total'], $stats['percentage'] ) ); ?> 470 </span> 462 471 </div> 463 472 </div> 464 473 <div class="mhwc-hero__panel"> 465 <div class="mhwc-panel__title"><?php echo esc_html__( 'Quick Tips', 'mediahue-webp-converter' ); ?></div> 474 <div class="mhwc-panel__title"><?php echo esc_html__( 'Conversion Progress', 'mediahue-webp-converter' ); ?></div> 475 <div class="mhwc-progress-bar"> 476 <div class="mhwc-progress-fill" style="width: <?php echo esc_attr( $stats['percentage'] ); ?>%"></div> 477 </div> 478 <p><?php echo esc_html( sprintf( __( '%d of %d images converted to WebP', 'mediahue-webp-converter' ), $stats['converted'], $stats['total'] ) ); ?></p> 466 479 <ul> 467 480 <li><?php echo esc_html__( 'Keep quality between 75 and 85 for best balance.', 'mediahue-webp-converter' ); ?></li> … … 493 506 </header> 494 507 495 <?php if ( $converted ) : ?> 496 <div class="notice notice-success inline"><p><?php echo esc_html( sprintf( __( 'Converted %d attachments in the last batch.', 'mediahue-webp-converter' ), $converted ) ); ?></p></div> 497 <?php endif; ?> 498 499 <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>"> 500 <?php wp_nonce_field( self::mhwc_nonce_action( 'bulk_convert' ) ); ?> 501 <input type="hidden" name="action" value="<?php echo esc_attr( self::mhwc_action_name( 'bulk_convert' ) ); ?>" /> 502 <input type="hidden" name="offset" value="<?php echo esc_attr( $offset ); ?>" /> 503 <div class="mhwc-actions"> 504 <label> 505 <?php echo esc_html__( 'Batch size', 'mediahue-webp-converter' ); ?> 506 <input type="number" name="limit" min="1" max="200" value="50" /> 507 </label> 508 <?php submit_button( __( 'Run Batch', 'mediahue-webp-converter' ), 'primary', 'submit', false ); ?> 509 </div> 510 <?php if ( $has_more ) : ?> 511 <p class="mhwc-note"><?php echo esc_html__( 'More attachments remaining. Run again to continue.', 'mediahue-webp-converter' ); ?></p> 512 <?php endif; ?> 513 </form> 508 <div class="mhwc-actions"> 509 <label> 510 <?php echo esc_html__( 'Batch size', 'mediahue-webp-converter' ); ?> 511 <input type="number" name="convert_limit" min="1" max="200" value="50" /> 512 </label> 513 <button type="button" class="button button-primary mhwc-convert-batch-btn"> 514 <?php echo esc_html__( 'Start Batch Conversion', 'mediahue-webp-converter' ); ?> 515 </button> 516 </div> 514 517 </section> 515 518 … … 520 523 </header> 521 524 522 <?php if ( $deleted ) : ?> 523 <div class="notice notice-success inline"><p><?php echo esc_html( sprintf( __( 'Deleted %d WebP files in the last batch.', 'mediahue-webp-converter' ), $deleted ) ); ?></p></div> 524 <?php endif; ?> 525 526 <form method="post" action="<?php echo esc_url( admin_url( 'admin-post.php' ) ); ?>"> 527 <?php wp_nonce_field( self::mhwc_nonce_action( 'bulk_delete' ) ); ?> 528 <input type="hidden" name="action" value="<?php echo esc_attr( self::mhwc_action_name( 'bulk_delete' ) ); ?>" /> 529 <input type="hidden" name="offset" value="<?php echo esc_attr( $offset ); ?>" /> 530 <div class="mhwc-actions"> 531 <label> 532 <?php echo esc_html__( 'Batch size', 'mediahue-webp-converter' ); ?> 533 <input type="number" name="limit" min="1" max="200" value="50" /> 534 </label> 535 <?php submit_button( __( 'Delete Batch', 'mediahue-webp-converter' ), 'delete', 'submit', false ); ?> 536 </div> 537 <?php if ( $has_more_delete ) : ?> 538 <p class="mhwc-note"><?php echo esc_html__( 'More attachments remaining. Run again to continue.', 'mediahue-webp-converter' ); ?></p> 539 <?php endif; ?> 540 </form> 525 <div class="mhwc-actions"> 526 <label> 527 <?php echo esc_html__( 'Batch size', 'mediahue-webp-converter' ); ?> 528 <input type="number" name="delete_limit" min="1" max="200" value="50" /> 529 </label> 530 <button type="button" class="button button-delete mhwc-delete-batch-btn"> 531 <?php echo esc_html__( 'Start Batch Deletion', 'mediahue-webp-converter' ); ?> 532 </button> 533 </div> 541 534 </section> 542 535 </div> … … 562 555 '1.0.0' 563 556 ); 557 wp_enqueue_script( 558 'mhwc-admin-js', 559 plugin_dir_url( __FILE__ ) . 'assets/admin-webp.js', 560 array( 'jquery' ), 561 '1.0.0', 562 true 563 ); 564 wp_localize_script( 'mhwc-admin-js', 'mhwc_ajax', array( 565 'ajax_url' => admin_url( 'admin-ajax.php' ), 566 'nonce' => wp_create_nonce( 'mhwc_ajax_nonce' ), 567 'strings' => array( 568 'converting' => __( 'Converting Images...', 'mediahue-webp-converter' ), 569 'deleting' => __( 'Deleting WebP Files...', 'mediahue-webp-converter' ), 570 'complete' => __( 'Process Complete!', 'mediahue-webp-converter' ), 571 'error' => __( 'An error occurred', 'mediahue-webp-converter' ), 572 'error_occurred' => __( 'Error Occurred', 'mediahue-webp-converter' ), 573 'cancel' => __( 'Cancel', 'mediahue-webp-converter' ), 574 'retry' => __( 'Retry', 'mediahue-webp-converter' ), 575 'close' => __( 'Close', 'mediahue-webp-converter' ), 576 'processing' => __( 'Processing...', 'mediahue-webp-converter' ), 577 'initializing' => __( 'Initializing batch process...', 'mediahue-webp-converter' ), 578 'processing_batch' => __( 'Processing batch...', 'mediahue-webp-converter' ), 579 'timeout_error' => __( 'Request timed out. Please try again.', 'mediahue-webp-converter' ), 580 'network_error' => __( 'Network error. Please check your connection.', 'mediahue-webp-converter' ), 581 'converted_singular' => __( '%d image converted', 'mediahue-webp-converter' ), 582 'converted_plural' => __( '%d images converted', 'mediahue-webp-converter' ), 583 'already_converted_singular' => __( '%d already converted', 'mediahue-webp-converter' ), 584 'already_converted_plural' => __( '%d already converted', 'mediahue-webp-converter' ), 585 'failed_singular' => __( '%d failed', 'mediahue-webp-converter' ), 586 'failed_plural' => __( '%d failed', 'mediahue-webp-converter' ), 587 'deleted_singular' => __( '%d WebP file deleted', 'mediahue-webp-converter' ), 588 'deleted_plural' => __( '%d WebP files deleted', 'mediahue-webp-converter' ), 589 'processed_in' => __( 'Processed in %s (%d/sec)', 'mediahue-webp-converter' ), 590 'conversion_complete' => __( 'Successfully converted %d images in %s!', 'mediahue-webp-converter' ), 591 'deletion_complete' => __( 'Successfully deleted %d WebP files in %s!', 'mediahue-webp-converter' ), 592 'completed' => __( 'Completed', 'mediahue-webp-converter' ), 593 ), 594 ) ); 595 } 596 597 public static function mhwc_redirect_settings_page() { 598 if ( ! current_user_can( 'manage_options' ) ) return; 599 if ( empty( $_GET['page'] ) ) return; 600 if ( self::mhwc_settings_page_slug() !== $_GET['page'] ) return; 601 602 wp_safe_redirect( admin_url( 'upload.php?page=' . self::mhwc_tools_page_slug() ) ); 603 exit; 564 604 } 565 605 … … 580 620 581 621 $converted = 0; 622 $already_converted = 0; 623 $failed = 0; 624 582 625 foreach ( $ids as $attachment_id ) { 583 if ( self::mhwc_convert_attachment_id( $attachment_id ) ) { 626 $result = self::mhwc_convert_attachment_id( $attachment_id ); 627 if ( $result === true ) { 584 628 $converted++; 629 } elseif ( $result === false ) { 630 // Check if it's already converted or failed 631 $file = get_attached_file( $attachment_id ); 632 if ( $file && file_exists( self::mhwc_get_webp_path( $file ) ) ) { 633 $already_converted++; 634 } else { 635 $failed++; 636 } 585 637 } 586 638 } 587 639 588 640 $has_more = ( count( $ids ) === $limit ); 589 $redirect = add_query_arg( 590 array( 591 'page' => self::mhwc_tools_page_slug(), 592 'converted' => $converted, 593 'offset' => $offset + $limit, 594 'has_more' => $has_more ? 1 : 0, 595 ), 596 admin_url( 'upload.php' ) 597 ); 641 $total_processed = $offset + count( $ids ); 642 $stats = self::mhwc_get_conversion_stats(); 643 $current_percentage = $stats['total'] > 0 ? round( ( $stats['converted'] / $stats['total'] ) * 100, 1 ) : 0; 644 645 $redirect_args = array( 646 'page' => self::mhwc_tools_page_slug(), 647 'converted' => $converted, 648 'offset' => $offset + $limit, 649 'has_more' => $has_more ? 1 : 0, 650 'processed' => $total_processed, 651 'percentage' => $current_percentage, 652 ); 653 654 if ( $already_converted > 0 ) { 655 $redirect_args['already_converted'] = $already_converted; 656 } 657 658 if ( $failed > 0 ) { 659 $redirect_args['failed'] = $failed; 660 } 661 662 $redirect = add_query_arg( $redirect_args, admin_url( 'upload.php' ) ); 598 663 599 664 wp_safe_redirect( $redirect ); … … 650 715 } 651 716 717 public static function mhwc_ajax_bulk_convert() { 718 try { 719 check_ajax_referer( 'mhwc_ajax_nonce', 'nonce' ); 720 721 if ( ! current_user_can( 'manage_options' ) ) { 722 wp_send_json_error( array( 'message' => __( 'Access denied.', 'mediahue-webp-converter' ) ) ); 723 } 724 725 $limit = isset( $_POST['limit'] ) ? max( 1, min( 200, intval( $_POST['limit'] ) ) ) : 50; 726 $offset = isset( $_POST['offset'] ) ? max( 0, intval( $_POST['offset'] ) ) : 0; 727 728 $ids = get_posts( array( 729 'post_type' => 'attachment', 730 'post_mime_type' => array( 'image/jpeg', 'image/png' ), 731 'fields' => 'ids', 732 'posts_per_page' => $limit, 733 'offset' => $offset, 734 ) ); 735 736 $converted = 0; 737 $already_converted = 0; 738 $failed = 0; 739 740 foreach ( $ids as $attachment_id ) { 741 $result = self::mhwc_convert_attachment_id( $attachment_id ); 742 if ( $result === true ) { 743 $converted++; 744 } elseif ( $result === false ) { 745 // Check if it's already converted or failed 746 $file = get_attached_file( $attachment_id ); 747 if ( $file && file_exists( self::mhwc_get_webp_path( $file ) ) ) { 748 $already_converted++; 749 } else { 750 $failed++; 751 } 752 } 753 } 754 755 $has_more = ( count( $ids ) === $limit ); 756 $stats = self::mhwc_get_conversion_stats(); 757 758 wp_send_json_success( array( 759 'converted' => $converted, 760 'already_converted' => $already_converted, 761 'failed' => $failed, 762 'has_more' => $has_more, 763 'offset' => $offset + $limit, 764 'total_converted' => $stats['converted'], 765 'total_images' => $stats['total'], 766 'percentage' => $stats['percentage'], 767 ) ); 768 } catch ( Exception $e ) { 769 wp_send_json_error( array( 'message' => $e->getMessage() ) ); 770 } 771 } 772 773 public static function mhwc_ajax_bulk_delete() { 774 try { 775 check_ajax_referer( 'mhwc_ajax_nonce', 'nonce' ); 776 777 if ( ! current_user_can( 'manage_options' ) ) { 778 wp_send_json_error( array( 'message' => __( 'Access denied.', 'mediahue-webp-converter' ) ) ); 779 } 780 781 $limit = isset( $_POST['limit'] ) ? max( 1, min( 200, intval( $_POST['limit'] ) ) ) : 50; 782 $offset = isset( $_POST['offset'] ) ? max( 0, intval( $_POST['offset'] ) ) : 0; 783 784 $ids = get_posts( array( 785 'post_type' => 'attachment', 786 'post_mime_type' => array( 'image/jpeg', 'image/png' ), 787 'fields' => 'ids', 788 'posts_per_page' => $limit, 789 'offset' => $offset, 790 ) ); 791 792 $deleted = 0; 793 foreach ( $ids as $attachment_id ) { 794 $deleted += self::mhwc_delete_webp_for_attachment( $attachment_id ); 795 } 796 797 $has_more = ( count( $ids ) === $limit ); 798 799 wp_send_json_success( array( 800 'deleted' => $deleted, 801 'has_more' => $has_more, 802 'offset' => $offset + $limit, 803 ) ); 804 } catch ( Exception $e ) { 805 wp_send_json_error( array( 'message' => $e->getMessage() ) ); 806 } 807 } 808 652 809 public static function mhwc_convert_attachment_id( $attachment_id ) { 653 810 if ( ! self::mhwc_is_webp_supported() ) return false; … … 665 822 $quality = intval( $options['quality'] ); 666 823 824 $converted = false; 825 667 826 if ( ! empty( $options['convert_original'] ) ) { 668 self::mhwc_create_webp_from_file( $file, $quality ); 827 $webp_path = self::mhwc_create_webp_from_file( $file, $quality ); 828 if ( $webp_path && file_exists( $webp_path ) ) { 829 $converted = true; 830 } 669 831 } 670 832 … … 679 841 $size_file = $size_dir . $size['file']; 680 842 if ( file_exists( $size_file ) ) { 681 self::mhwc_create_webp_from_file( $size_file, $quality ); 843 $webp_path = self::mhwc_create_webp_from_file( $size_file, $quality ); 844 if ( $webp_path && file_exists( $webp_path ) ) { 845 $converted = true; 846 } 682 847 } 683 848 } 684 849 } 685 850 686 return true;851 return $converted; 687 852 } 688 853 … … 768 933 } 769 934 935 public static function mhwc_get_conversion_stats() { 936 $total_images = wp_count_posts( 'attachment' )->inherit; 937 if ( ! $total_images ) { 938 $total_images = 0; 939 } 940 941 $converted_count = 0; 942 $image_posts = get_posts( array( 943 'post_type' => 'attachment', 944 'post_mime_type' => array( 'image/jpeg', 'image/png' ), 945 'posts_per_page' => -1, 946 'fields' => 'ids', 947 ) ); 948 949 foreach ( $image_posts as $attachment_id ) { 950 $file = get_attached_file( $attachment_id ); 951 if ( $file && file_exists( self::mhwc_get_webp_path( $file ) ) ) { 952 $converted_count++; 953 } 954 } 955 956 return array( 957 'total' => count( $image_posts ), 958 'converted' => $converted_count, 959 'percentage' => count( $image_posts ) > 0 ? round( ( $converted_count / count( $image_posts ) ) * 100, 1 ) : 0, 960 ); 961 } 962 770 963 public static function mhwc_add_settings_link( $links ) { 771 964 $settings_url = admin_url( 'upload.php?page=' . self::mhwc_tools_page_slug() ); … … 774 967 return $links; 775 968 } 776 777 public static function mhwc_redirect_settings_page() {778 if ( ! current_user_can( 'manage_options' ) ) return;779 if ( empty( $_GET['page'] ) ) return;780 if ( self::mhwc_settings_page_slug() !== $_GET['page'] ) return;781 782 wp_safe_redirect( admin_url( 'upload.php?page=' . self::mhwc_tools_page_slug() ) );783 exit;784 }785 969 } 786 970 -
mediahue-webp-converter/trunk/readme.txt
r3463707 r3476630 1 === MediaHue – Image To Webp Converter===1 === MediaHue – Webp Converter For WordPress === 2 2 Contributors: solankisoftware 3 3 Donate link: https://paypal.me/kirtikumar89 … … 6 6 Tested up to: 6.9 7 7 Requires PHP: 7.4 8 Stable tag: 1.0. 08 Stable tag: 1.0.1 9 9 License: GPLv2 or later 10 10 License URI: https://www.gnu.org/licenses/gpl-2.0.html 11 11 12 Simple MediaHue – Image ToWebp Converter for WordPress. Convert JPG/PNG on upload, serve WebP on frontend, and bulk convert existing media easily.12 Simple MediaHue – Webp Converter for WordPress. Convert JPG/PNG on upload, serve WebP on frontend, and bulk convert existing media easily. 13 13 14 14 == Description == 15 15 16 MediaHue – Image To Webp Converterautomatically generates WebP versions of your JPG/PNG images during upload and serves them on the frontend when available. It also includes Media Library tools for bulk conversion and cleanup.16 MediaHue – Webp Converter for WordPress automatically generates WebP versions of your JPG/PNG images during upload and serves them on the frontend when available. It also includes Media Library tools for bulk conversion and cleanup. 17 17 18 18 **Key features** … … 51 51 52 52 == Changelog == 53 = 1.0.1 54 * Improve Design and Set Bacth process using Ajax 55 * Added Progressbar in the webp process 53 56 54 57 = 1.0.0 =
Note: See TracChangeset
for help on using the changeset viewer.