optimize_action_columns( $id ); } } public function optimize_action_columns($id) { $allowed_mime_types = CompressX_Image_Opt_Method::supported_mime_types_ex(); if ( ! wp_attachment_is_image( $id ) || ! in_array( get_post_mime_type( $id ),$allowed_mime_types ) ) { return __('Not support','compressx'); } $html=$this->output_item($id); return $html; } public function submitbox() { global $post; $id=$post->ID; $allowed_mime_types = CompressX_Image_Method::supported_mime_types_ex(); if ( ! wp_attachment_is_image( $post->ID ) || ! in_array( get_post_mime_type( $post->ID ),$allowed_mime_types ) ) { echo esc_html__('Not support','compressx'); return; } if($this->is_skipped($id)) { echo esc_html__('Skipped','compressx'); return; } $html=$this->output_item_edit($id); echo $html; } public function attachment_fields_to_edit(array $response, \WP_Post $attachment) { $source_post_id = (string) isset( $_REQUEST['post_id'])?$_REQUEST['post_id']:''; if ( $source_post_id !== '0' ) { return $response; } $allowed_mime_types = CompressX_Image_Method::supported_mime_types_ex(); if ( ! wp_attachment_is_image( $attachment->ID ) || ! in_array( get_post_mime_type( $attachment->ID ),$allowed_mime_types ) ) { return $response; } $html=$this->output_item_attachment($attachment->ID); $response['compat']['meta'] .=$html; return $response; } public function output_item($id) { if($this->is_skipped($id)) { return __('Skipped','compressx'); } $html='
'; $html.=''; $html.='
'; return $html; } public function output_item_edit($id) { if($this->is_skipped($id)) { return __('Skipped','compressx'); } $html='

' . esc_html__('CompressX','compressx') . '

'; $html.=''; $html.='
'; return $html; } public function output_item_attachment($id) { $html='

' . esc_html__('CompressX','compressx') . '

'; $html.=''; $html.='
'; return $html; } public function output_item_detail($id) { $html=''; $og_size=CompressX_Image_Meta_V2::get_og_size($id); if(empty($og_size)) { $file_path = get_attached_file( $id ); if(file_exists($file_path)) $og_size=filesize($file_path); else $og_size=0; } $html.='
  • Original : '.esc_html(size_format($og_size,2)).'
  • '; $webp_size=CompressX_Image_Meta_V2::get_webp_converted_size($id); if($webp_size>0&&$og_size>$webp_size) { $webp_percent = round(100 - ($webp_size / $og_size) * 100, 2); } else { $webp_percent=0; } $html.='
  • Webp : '.esc_html(size_format($webp_size,2)).' Saved : '.esc_html($webp_percent).'%
  • '; $avif_size=CompressX_Image_Meta_V2::get_avif_converted_size($id); if($avif_size>0&&$og_size>$avif_size) { $avif_percent = round(100 - ($avif_size / $og_size) * 100, 2); } else { $avif_percent=0; } $html.='
  • AVIF : '.esc_html(size_format($avif_size,2)).' Saved : '.esc_html($avif_percent).'%
  • '; $meta=CompressX_Image_Meta_V2::get_image_meta($id); if(isset($meta['size'])&&!empty($meta['size'])) { $thumbnail_counts=count($meta['size']); } else { $thumbnail_counts=0; } $html.='
  • Thumbnails generated : '.esc_html($thumbnail_counts).'
  • '; return $html; } public function output_item_action($id) { $html='
  • '; $html.=''; if($this->is_image_progressing($id)) { $html.='Progressing'; } else { $html.='Apply'; } $html.='
  • '; return $html; } public function is_skipped($image_id) { if(CompressX_Image_Meta_V2::get_image_meta_status($image_id)==='skip') { return true; } else { return false; } } public function is_image_progressing($post_id) { $progressing=CompressX_Image_Meta_V2::get_image_progressing($post_id); if(empty($progressing)) { return false; } else { $current_time=time(); if(($current_time-$progressing)>180) { return false; } else { return true; } } } public function get_opt_single_image_progress() { global $compressx; $compressx->ajax_check_security('compressx-can-convert'); if(!isset($_POST['ids'])||!is_string($_POST['ids'])) { die(); } $ids=sanitize_text_field($_POST['ids']); $ids=json_decode($ids,true); $running=false; if(isset($_POST['page'])) { $page=sanitize_text_field($_POST['page']); } else { $page='media'; } foreach ($ids as $id) { if(!CompressX_Image_Meta_V2::is_image_optimized($id)) { if($this->is_image_progressing($id)) { $running=true; break; } } } $ret['result']='success'; if($running) { $ret['continue']=1; $ret['finished']=0; } else { $ret['continue']=0; $ret['finished']=1; } foreach ($ids as $id) { if($page=='edit') { $html=$this->output_item_edit($id); } else { $html=$this->output_item($id); } $ret[$id]['html']=$html; } echo wp_json_encode($ret); die(); } }