<?php
[add_filter](http://codex.wordpress.org/Function_Reference/add_filter)("wp_image_editors", "my_wp_image_editors");
function my_wp_image_editors($editors) {
array_unshift($editors, "WP_Image_Editor_Custom");
return $editors;
}
// Include the existing classes first in order to extend them.
require_once ABSPATH.WPINC."/class-[wp](http://codex.wordpress.org/Plugin_API/Action_Reference/wp)-image-editor.php";
require_once ABSPATH.WPINC."/class-[wp](http://codex.wordpress.org/Plugin_API/Action_Reference/wp)-image-editor-gd.php";
class WP_Image_Editor_Custom extends WP_Image_Editor_GD {
public function get_suffix() {
if ( ! $this->get_size() )
return false;
$size = array('large', 'medium', 'thumbnail');
foreach($size as $element) {
if( $this->size['width'] == intval([get_option](http://codex.wordpress.org/Function_Reference/get_option)($element.'_size_w')) || $this->size['height'] == intval([get_option](http://codex.wordpress.org/Function_Reference/get_option)($element.'_size_h')) )
return $element;
}
// return "{$this->size['width']}x{$this->size['height']}.other";
}
public function generate_filename($prefix = NULL, $dest_path = NULL, $extension = NULL) {
// If empty, generate a prefix with the parent method get_suffix().
if(!$element){
$element = $this->get_suffix();
}
// Determine extension and directory based on file path.
$info = pathinfo($this->file);
$dir = $info['dirname'];
$ext = $info['extension'];
$oldfile = $this->file;
$filesize = str_replace('large', '', $element);
// Determine image name.
$name = wp_basename($this->file, ".$ext");
// Allow extension to be changed via method argument.
$new_ext = strtolower($extension ? $extension : $ext);
// Default to $_dest_path if method argument is not set or invalid.
if(!is_null($dest_path) && $_dest_path = realpath($dest_path))
$dir = $_dest_path;
// Return our new prefixed filename.
return [trailingslashit](http://codex.wordpress.org/Function_Reference/trailingslashit)($dir)."{$filesize}/{$name}.{$new_ext}";
}
}