| @@ -134,9 +134,11 @@ | ||
| 134 | 134 | * @param string $context The context. |
| 135 | 135 | * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure. |
| 136 | 136 | */ |
| 137 | 137 | protected function optimize_media( $media_id, $context ) { |
| 138 | - return imagify_get_optimization_process( $media_id, $context )->optimize(); | |
| 138 | + // A manual click is an explicit, single-image user action: flag it as priority so it | |
| 139 | + // jumps ahead of any bulk optimization queue. | |
| 140 | + return imagify_get_optimization_process( $media_id, $context )->optimize( null, [ 'priority' => true ] ); | |
| 139 | 141 | } |
| 140 | 142 | |
| 141 | 143 | /** |
| 142 | 144 | * Re-optimize a media to a different optimization level. |
| @@ -148,9 +150,11 @@ | ||
| 148 | 150 | * @param int $level The optimization level. |
| 149 | 151 | * @return bool|WP_Error True if successfully launched. A \WP_Error instance on failure. |
| 150 | 152 | */ |
| 151 | 153 | protected function reoptimize_media( $media_id, $context, $level ) { |
| 152 | - return imagify_get_optimization_process( $media_id, $context )->reoptimize( $level ); | |
| 154 | + // A manual click is an explicit, single-image user action: flag it as priority so it | |
| 155 | + // jumps ahead of any bulk optimization queue. | |
| 156 | + return imagify_get_optimization_process( $media_id, $context )->reoptimize( $level, [ 'priority' => true ] ); | |
| 153 | 157 | } |
| 154 | 158 | |
| 155 | 159 | /** |
| 156 | 160 | * Optimize all files from a media, whatever this media’s previous optimization status (will be restored if needed). |
| @@ -824,8 +828,12 @@ | ||
| 824 | 828 | /** |
| 825 | 829 | * Check the API key validity. |
| 826 | 830 | * |
| 827 | 831 | * @since 1.6.11 |
| 832 | + * @since 2.3.1 Ignore user abort while saving the key, so the option and its | |
| 833 | + * related validity cache/notice are never left in a partial state | |
| 834 | + * when the browser cancels the request (e.g. the user clicks away | |
| 835 | + * or navigates while the check is still running). | |
| 828 | 836 | */ |
| 829 | 837 | public function imagify_check_api_key_validity_callback() { |
| 830 | 838 | imagify_check_nonce( 'imagify-check-api-key', 'imagifycheckapikeynonce' ); |
| 831 | 839 | |
| @@ -843,11 +851,25 @@ | ||
| 843 | 851 | if ( is_wp_error( $response ) ) { |
| 844 | 852 | imagify_die( $response ); |
| 845 | 853 | } |
| 846 | 854 | |
| 855 | + /* | |
| 856 | + * From this point, the key is known to be valid. Saving the option triggers | |
| 857 | + * `after_save_options()`, which performs its own request to the Imagify API | |
| 858 | + * to (re)set the "valid key" cache and dismiss/renew the "wrong-api-key" notice. | |
| 859 | + * If the client disconnects (e.g. the user clicks elsewhere or navigates away | |
| 860 | + * while the spinner is still showing), PHP would otherwise abort mid-way, | |
| 861 | + * leaving the key saved but the validity cache/notice stale or missing. | |
| 862 | + * Ignoring user abort for this short, bounded sequence guarantees the option | |
| 863 | + * and its validity state are always saved consistently together. | |
| 864 | + */ | |
| 865 | + $ignore_user_abort = ignore_user_abort( true ); | |
| 866 | + | |
| 847 | 867 | update_imagify_option( 'api_key', $api_key ); |
| 848 | 868 | |
| 849 | 869 | delete_transient( 'imagify_user_cache' ); |
| 870 | + | |
| 871 | + ignore_user_abort( $ignore_user_abort ); | |
| 850 | 872 | |
| 851 | 873 | wp_send_json_success(); |
| 852 | 874 | } |
| 853 | 875 | |