Add a new image validation test
-
I’m running Events Manager 5.6.2 on a WP 4.4.2 install.
I need to extend the validations performed on the images sent via the front-end event submission for used by guest visitors.
Currently, tests are performed for mime type and minimum / maximum width and height; I need to check for things like file size and resolution / ratio.
I skimmed through the code and located the
image_validate()
function on the/classes/em-object.php
file. If I insert my validation code there, it works the way I want:(...) function image_validate(){ $type = $this->get_image_type(); if( $type ){ if ( !empty($_FILES[$type.'_image']) && $_FILES[$type.'_image']['size'] > 0 ) { if (is_uploaded_file($_FILES[$type.'_image']['tmp_name'])) { (...) $proportion = round(($width / $height),2); if ( $proportion != 1.62) { $this->add_error("Wrong proportions!"); } (...)
However, I don’t want to manually edit the plugin files. I want to extend functionality using hooks and filters.
The official site says:
We’re in the process of adding hooks and filters to the plugin in order to make Events Manager as flexible as possible. There are already a few in place, but for now you need to search for them in your editors.
I’ve found the
return apply_filters('em_object_image_validate', count($this->errors) == 0, $this);
in theimage_validate
function, but I’m getting confused on how to implement something around it.
- The topic ‘Add a new image validation test’ is closed to new replies.