Documentation > Developers

Developers

Available Filters & Snippets

You can use the following snippets in your theme’s functions.php file or even better, create a custom plugin or using the Code Snippets plugin. (The latter two are the better options, as they won’t be overwritten by theme updates!)

You can find all picu filters and how they work below. Also have a look at the filter examples page for more advanced filtering.


picu Core

In the following section you find the filters/hooks that can be used with the free picu plugin you can download from WordPress.org. Below you will soon find more filters/hooks that can be used in conjunction with picu Pro.

Define a custom base slug for collections

This will change the default slug from domain.tld/collections/ak4h38 to domain.tld/my-defined-slug/ak4h38.

Beware, that this changes the URL for all collections – including those you might have sent to clients before.

function my_picu_collection_slug() {
    return 'my-defined-slug';
}

add_filter( 'picu_collection_slug', 'my_picu_collection_slug' );Code language: JavaScript (javascript)

Please note: Make sure to go to “Settings > Permalinks” in your WordPress Admin after you implemented the snippet.


Disable random slug generation for picu collections

picu will then use the collection title to generate the slug, which is the WordPress default.

add_filter( 'picu_collection_do_random_slug', '__return_false' );Code language: JavaScript (javascript)

Set default share method to “Copy link & send manually”

picu will then select the Copy link & share manually tab by default, when you create a new collection.

add_filter( 'picu_default_share_method_is_email', '__return_false' );Code language: JavaScript (javascript)

Define a custom filename separator

This separator is used when you copy the image filenames after your client has approved a collection. This separator is also used in the proof text file that you can download once a collection has been approved. The default is a single space.

The example below will add a comma after each filename.

function my_custom_filename_separator( $divider ) {
    return ', ';
}

add_filter( 'picu_filename_separator', 'my_custom_filename_separator' );Code language: PHP (php)

There is an alternate method of defining a custom filename separator available. Just put the following line in your wp-config.php file:

define( 'PICU_FILENAME_SEPARATOR', "\n" );Code language: JavaScript (javascript)

This will add a new line after each filename, btw.


Define custom filenames when copying approved image names

By default picu will not use a suffix (like .jpg), when you copy the image filenames (or in the proof text file) after your client has approved a collection. With the following filter you can change what is being copied.

In the example below, we change the output to use the whole filenames, including the suffix (like .jpg).

function my_picu_approved_filename( $filename, $attachment_id ) {
    $attachment = wp_get_attachment_image_src( $attachment_id, 'full' );
    return wp_basename( $attachment[0] );
}

add_filter( 'picu_approved_filename', 'my_picu_approved_filename', 10, 2 );Code language: PHP (php)

By using the $attachement_id you can use pretty much any meta data attached to the respective image.


Define custom max width and height values for picu images

Set the maximum height and width with which picu images should be displayed.

function my_picu_large_image_size( $sizes ) {
    return array(
        'width' => 3000,
        'height' => 2000
    );
}

add_filter( 'picu_large_image_size', 'my_picu_large_image_size' );Code language: PHP (php)

Do not generate picu’s custom image sizes

Disable the generation of custom smaller and intermediate image sizes

function my_picu_disable_custom_image_sizes( $sizes ) {
    return array();
}

add_filter( 'picu_intermediate_image_sizes', 'my_picu_disable_custom_image_sizes' );Code language: PHP (php)

Set the default expiration time

Set the default expiration time in days. The default is 30 days. This example will set the duration to five days:

add_filter( 'picu_expiration_length', 5 );Code language: JavaScript (javascript)

Send collection password with the email

By default picu will include the collection password in the email to the client. You can set this in the options, or disable it using this filter:

add_filter( 'picu_send_password_in_email', '__return_false' );Code language: JavaScript (javascript)

Define a custom FROM name for picu emails

Defaults to your Site Title.

function my_picu_email_from_name( $from_name, $mail_context, $collection_id ) {
     return 'Max Mustermann';
}

add_filter( 'picu_email_from_name', 'my_picu_email_from_name', 10, 3 );Code language: PHP (php)

Please note, that using this filter will overwrite your settings under “picu > Settings > General Settings”.


Define a custom FROM address for picu emails

Defaults to no-reply@domain.tld.

function my_picu_email_from_address( $from_address, $mail_context, $collection_id ) {
    return 'my.custum@email.address';
}

add_filter( 'picu_email_from_address', 'my_picu_email_from_address', 10, 3 );Code language: PHP (php)

Please note, that using this filter will overwrite your settings under “picu > Settings > General Settings”.


Define custom CC address(es) for picu emails

You can also define multiple addresses, just seperate them with a comma.

function my_picu_email_cc( $cc_address, $mail_context, $collection_id ) {
	return 'my.cc@email.address';
}

add_filter( 'picu_email_cc', 'my_picu_email_cc', 10, 3 );Code language: PHP (php)

Define custom BCC address(es) for picu emails

You can also define multiple addresses, just seperate them with a comma.

function my_picu_email_bcc( $bcc_address, $mail_context, $collection_id ) {
	return 'my.bcc@email.address';
}

add_filter( 'picu_email_bcc', 'my_picu_email_bcc', 10, 3 );Code language: PHP (php)

Change the email subject for picu emails

By default, the subject contains the collection title. In the example below we add “Please approve” in front of the collection title, when sending the collection to the client.

function my_picu_mail_subject( $subject, $mail_context, $collection_id ) {

    if ( $mail_context == 'client_collection_new' ) {
        return 'Please approve: ' . $subject;
    }

    return $subject;
}

add_filter( 'picu_mail_subject', 'my_picu_mail_subject', 10, 3 );Code language: PHP (php)

Change the content type for picu emails

Please use with caution, and only adjust if you kow, what you are doing.

function my_picu_email_content_type( $content_type, $mail_context, $collection_id ) {
    return 'text/plain';
}

add_filter( 'picu_email_content_type', 'my_picu_email_content_type', 10, 3 );Code language: PHP (php)

Change headers for picu emails

In this example we add a Reply-To address:

function my_picu_email_headers( $headers, $mail_context, $collection_id, $ident ) {
    $headers .= "Reply-To: my.reply@email.address\r\n";
    return $headers;
}

add_filter( 'picu_email_headers', 'my_picu_email_headers', 10, 4 );Code language: PHP (php)

Define a custom message for picu emails

Change the default message in emails that picu sends out.

function my_picu_email_message( $message ) {
    $message = 'Custom Message';
    return $message;
}

add_filter( 'picu_client_mail_message', 'my_picu_email_message' );Code language: PHP (php)

Please note, that with picu Pro, it is possible to create multiple email templates.


Set customer email reminder time

Define a custom reminder time in seconds, eg. send the reminder after 48 hours (instead of the default 24):

add_filter( 'picu_selection_reminder_time_diff', function( $default ) {
    return 172800;
});Code language: PHP (php)

Define a custom TO address for approval email notifications

By default approval notifications are sent to the email address of the user, who created the collection. With this filter you can overwrite that.

function my_picu_approval_mail_recipient( $collection_id, $recipient_email ) {
	return 'what.ever@you.choose.com';
}

add_filter( 'picu_approval_mail_recipient', 'my_picu_approval_mail_recipient', 10, 2 );Code language: PHP (php)

Please note, that with the example above, all approval notifications will got to the same address.

Please note that you can define this in the picu Email Settings.


Disable saving email history

This filter allows you to prevent picu from remembering the email addresses when sending out collections.

add_filter( 'picu_save_email_history', '__return_false' );Code language: JavaScript (javascript)

Disable using email history

By returning false via this filter, picu will not display the email address suggestions when creating a new collection.

add_filter( 'picu_use_email_history', '__return_false' );Code language: JavaScript (javascript)

Customize the email history list

The following example will add an email address to the top of the list and also display the number of uses per email address.

function my_picu_email_history_list( $datalist, $history ) {
	$datalist = '<datalist id="email-history">';

	// Eg. add an address to the top of the list
	array_unshift( $history, [ 'email' => 'most.important@client.com', 'uses' => '' ] );

	foreach( $history as $entry ) {
		// Eg. display the number of times an address was used
		$datalist .= '<option value="' . $entry['email'] . '">' . $entry['email'];
		if ( ! empty( $entry['uses'] ) ) {
			$datalist .= ' (' . $entry['uses'] . ')';
		}
		$datalist .= '</option>';
	}
	$datalist .= '</datalist>';

	return $datalist;
}

add_filter( 'picu_email_history_list', 'my_picu_email_history_list', 10, 2 )Code language: PHP (php)

Change the approval heading

Adjust the approval modal headline:

add_filter( 'picu_approval_heading', function( $headline ) {
    return 'My custom headline';
});Code language: PHP (php)

Change the approval warning message

Change the content of the message that is displayed above the “Approve Selection” button. Defaults to:

You are about to approve this collection.
Please note, that you won’t be able to make changes to your selection after that.

function my_picu_approval_warning( $message ) {
    return '<p><strong>Thank you for your time.</strong><br />We will get right to work on your images!</p>';
}

add_filter( 'picu_approval_warning', 'my_picu_approval_warning' );Code language: PHP (php)

Change the approval button text

With this filter you can adjust the text for the button below the approval form, which will send the selection – and close the collection for that recipient.

add_filter( 'picu_approval_button_text', function( $button_text ) {
	return 'My custom button text';
});Code language: PHP (php)

Change the send selection button text

With this filter you can adjust the text for the button below the gallery view, which leads to the approval form.

add_filter( 'picu_send_selection_button_text', function( $button_text ) {
	return 'My custom button text';
});Code language: PHP (php)

Add custom content above the collection images

Add/display custom elements/content above the images in a collection.

function my_picu_before_collection_images() {
    echo '<div style="margin: 0 1rem;">My custom content above the collection images</div>';
}

add_action( 'picu_before_collection_images', 'my_picu_before_collection_images' );Code language: PHP (php)

See an extended example on how to add content above the collection images.


Add Custom JavaScript

Add custom scripts, eg. for tracking or analytics, to your picu collections.

function my_picu_custom_scripts( $custom_scripts ) {
    $custom_scripts .= '<!-- YOUR ANALYTICS JS CODE -->';

    return $custom_scripts;
}

add_filter( 'picu_custom_scripts', 'my_picu_custom_scripts' );Code language: HTML, XML (xml)

Warning: Make sure, to add your custom code to the $custom_scripts string. Do not just overwrite the variable.


Define who can use picu

Define a capability, which a user/role must have, to access picu. The default is manage_options.

function my_picu_custom_capability() {
    return 'edit_posts';
}

add_filter( 'picu_capability', 'my_picu_custom_capability' );Code language: JavaScript (javascript)

Have a look at the full list of capabilities – and especially which roles usually have which capabilities.


Adjust the collection post type settings

Allows you to adjust the custom post type arguments. The example below adds author support to picu collections:

function my_picu_cpt_collection_args( $args ) {
    array_push( $args['supports'], 'author' );
    return $args;
}

add_filter( '<span style="font-family: inherit; font-size: inherit;">picu_cpt_collection_args</span>', 'my_<span style="font-family: inherit; font-size: inherit;">picu_cpt_collection_args</span>' );Code language: PHP (php)

Please be extra careful when using this filter and check out all of the available post type parameters in the WordPress Code Reference, before making any changes.


Pro

Use custom styles

Change the appearance of your collections by adding custom css.

function my_custom_picu_styles( $custom_styles ) {
    $custom_styles .= 'body { background-color: pink; }';
    return $custom_styles;
}

add_filter( 'picu_brand_customize_styles', 'my_custom_picu_styles' );Code language: PHP (php)

Warning: Make sure, to add your custom code to the $custom_styles string. Do not overwrite the variable!


Customize the Approval Form

Define custom fields for the approval form. The filter accepts an array of fields. Check out the field parameters below.

add_filter( 'picu_approval_fields', 'my_picu_approval_fields' );Code language: JavaScript (javascript)

The following field parameters are supported:

$type
(string, required) Possible values are paragraph, select, text, textarea.
$label
(string, required) The Label that is displayed before the input field – or the text for a paragraph field.
$placeholder
(string, optional) Placeholder text that is displayed when a field is empty.
$width
(integer, optional) Define field width; fields will wrap automatically.
Allowed values are 20, 25, 30, 50, 60, 75, 100; default: 100
$break
(bool, optional) Whether the the field should start a new line.
$required
(bool, optional) Whether the field is required.
$value
(string, optional) Predefine a default value.
$validation
(string, optional) Use a regex pattern which the input will be validated against.
$options
(array, optional, only available for a select field) Define the options as an array of choices; separate values from display text by using the | character.

Take a look at this snippet for a more detailed example on how to customize the approval form.


Define filename prefix in .zip file when using the Download function

By default picu adds numbers (with leading zeros) in front of the file name, when creating the .zip file. We do this to preserve the order in which the photos are displayed in the collection. You can change the prefix using this filter. To disable the prefix, just return an emptry string like so:

function my_picu_download_file_name_prefix( $prefix, $img_num, $images ) {
	return '';
}

add_filter( 'picu_download_file_name_prefix', 'my_picu_download_file_name_prefix', 10, 3 );Code language: PHP (php)

Change the Delivery box title

You can change the delivery box title by using the picu_delivery_box_title filter.

add_filter( 'picu_delivery_box_title', function( $title ) {
    return 'My custom delivery box title';
});Code language: PHP (php)

Expand the image list by default

To expand the image list by default you can use to following filter/snippet:

add_filter( 'picu_delivery_show_images_by_default', '__return_true' );Code language: JavaScript (javascript)

Change the delivery box message

You can use the delivery box message by using the picu_delivery_box_message filter.

add_filter( 'picu_delivery_box_message', function( $message ) {
    return 'My custom delivery box message';
});Code language: PHP (php)

Need help?

If you couldn’t find what you were looking for and need more assistance, please get in touch with us directly and we’re happy to help.