This repository has been archived by the owner on Aug 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 26
Actions & Filters
Junaid Bhura edited this page Jun 27, 2020
·
5 revisions
Triggered when a fly image is created for an image. You can use this hook to optimize your images.
Usage:
/**
* New Fly Image created.
*
* @param int $attachment_id
* @param string $fly_file_path
*/
function my_fly_image_created( $attachment_id, $fly_file_path ) {
// Do something
}
add_action( 'fly_image_created', 'my_fly_image_created', 20, 2 );
Allows changing the folder in which all the cached images are stored.
Usage:
/**
* Update Fly Images directory.
*
* @param string $path
* @return string
*/
function my_fly_dir_path( $path = '' ) {
return '/var/www/new-directory';
}
add_filter( 'fly_dir_path', 'my_fly_dir_path' );
Set the capability for a user to delete cached images from the WP Admin. This is manage_options
by default.
Usage:
/**
* Update Fly Images user capability.
*
* @param string $capability
* @return string
*/
function my_fly_images_user_capability( $capability = '' ) {
return 'update_plugins';
}
add_filter( 'fly_images_user_capability', 'my_fly_images_user_capability' );
Use this filter to dynamically update the attributes of an image based on it's object and size.
Usage:
/**
* Update Fly Images attributes.
*
* @param array $attr
* @param object $attachment
* @param mixed $size
* @return array
*/
function my_fly_get_attachment_image_attributes( $attr, $attachment, $size ) {
$attr['alt'] = 'Alt text';
return return $attr;
}
add_filter( 'fly_get_attachment_image_attributes', 'my_fly_get_attachment_image_attributes', 10, 3 );
Use this filter to dynamically change the path of an image before it is cropped.
Usage:
/**
* Fly Attached File.
*
* @param string $attached_file
* @param integer $attachment_id
* @param mixed $size
* @param boolean $crop
* @return void
*/
function different_fly_attached_file( $attached_file, $attachment_id, $size, $crop ) {
return '/path/to/different/file.jpg';
}
add_filter( 'fly_attached_file', 'different_fly_attached_file', 10, 4 );