Skip to content
This repository has been archived by the owner on Aug 12, 2023. It is now read-only.

Actions & Filters

Junaid Bhura edited this page Jun 27, 2020 · 5 revisions

Actions

fly_image_created

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 );

Filters

fly_dir_path

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' );

fly_images_user_capability

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' );

fly_get_attachment_image_attributes

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 );

fly_attached_file

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 );