Skip to content

Filters

Junaid Bhura edited this page Oct 26, 2018 · 12 revisions

cloudinary_url

Filter the Cloudinary URL.

Example:

add_filter( 'cloudinary_url', function( $url, $identifier, $args ) {
	return str_replace( 'https://', 'http://', $url );
}, 10, 3 );

cloudinary_default_crop

Filter the default crop used for content images. This is fill by default.

Example:

add_filter( 'cloudinary_default_crop', function( $crop ) {
	return 'crop';
}, 10, 1 );

cloudinary_default_soft_crop

Filter the default crop used for content images which are "soft cropped". This inherits the value of cloudinary_default_crop, and the default value is set in the WP admin.

Example:

add_filter( 'cloudinary_default_soft_crop, function() {
	return 'fit';
} );

cloudinary_default_hard_crop

Filter the default crop used for content images which are "hard cropped". This inherits the value of cloudinary_default_crop, and the default value is set in the WP admin.

Example:

add_filter( 'cloudinary_default_hard_crop, function() {
	return 'fit';
} );

cloudinary_default_args

Filter the default args that get used for all Cloudinary URLs.

Example:

add_filter( 'cloudinary_default_args', function( $args ) {
	$args['transform']['crop'] = 'fill';
	return $args;
} );

cloudinary_args

Filter the Cloudinary args before it gets processed.

Example:

add_filter( 'cloudinary_args', function( $args, $identifier ) {
	if ( is_page_template( 'home-page.php' ) ) {
		$args['file_name'] = 'custom-file-name';
	}
	return $args;
}, 10, 2 );

cloudinary_user_capability

Filter the user capability needed to update the options in the WP admin. Defaults to manage_options.

Example:

add_filter( 'cloudinary_user_capability', function( $capability ) {
	return 'edit_posts';
} );

cloudinary_cloud_name

Filter the Cloud Name option.

Example:

add_filter( 'cloudinary_cloud_name', function( $cloud_name ) {
	if ( is_page_template( 'home-page.php' ) ) {
		return 'special-cloud';
	}
	return $cloud_name;
} );

cloudinary_auto_mapping_folder

Filter the Auto Mapping Folder option.

Example:

add_filter( 'cloudinary_auto_mapping_folder', function( $auto_mapping_folder ) {
	if ( is_page_template( 'home-page.php' ) ) {
		return 'special-auto-mapping-folder';
	}
	return $auto_mapping_folder;
} );

cloudinary_urls

Filter the URLs option.

Example:

add_filter( 'cloudinary_urls', function( $urls ) {
	$urls[] = 'https://my-custom.domain.com';
	return $urls;
} );

cloudinary_content_images

Filter the Content Images option.

Example:

add_filter( 'cloudinary_content_images', function( $content_images ) {
	if ( is_page_template( 'home-page.php' ) ) {
		return false;
	}
	return $content_images;
} );

cloudinary_upload_url

Use this filter to change the URL path to your images folder.

Example:

add_filter( 'cloudinary_upload_url', function( $content_url ) {
	return 'https://some-other-site.com/wp-content/uploads';
} );

cloudinary_content_image

Use this filter to manipulate an image tag in content entered from the WP Admin, when Cloudinary tries to replace it's URL. This is used in cloudinary_update_content_images().

Example:

add_filter( 'cloudinary_content_image', function( $image_tag, $attachment_id, $src, $width, $height ) {
	str_replace( '<img', '<img data-custom="my-custom-image-' . $attachment_id, $image_tag );
	return $image_tag;
}, 10, 5 );

cloudinary_filter_the_content

Use this to turn Cloudinary's the_content filter on or off.

Examples:

// On
add_filter( 'cloudinary_filter_the_content', '__return_true' );

// Off
add_filter( 'cloudinary_filter_the_content', '__return_false' );

cloudinary_filter_image_downsize

Use this to turn Cloudinary's image_downsize filter on or off.

Examples:

// On
add_filter( 'cloudinary_filter_image_downsize', '__return_true' );

// Off
add_filter( 'cloudinary_filter_image_downsize', '__return_false' );

cloudinary_filter_wp_calculate_image_srcset

Use this to turn Cloudinary's wp_calculate_image_srcset filter on or off.

Examples:

// On
add_filter( 'cloudinary_filter_wp_calculate_image_srcset', '__return_true' );

// Off
add_filter( 'cloudinary_filter_wp_calculate_image_srcset', '__return_false' );

cloudinary_image_srcset_transform

Filter the Cloudinary transform options for an SRCSET URL.

Examples:

add_filter( 'cloudinary_image_srcset_transform', function( $transform, $width, $original_url, $attachment_id ) {
	$transform['file_name'] = 'dynamic-file-name';
	return $transform;
}, 10, 4 );