Skip to content

wp_lib_loan_created

Kit edited this page Jan 8, 2016 · 1 revision

###Description

This action hook allows developers to perform additional actions after a Loan has been created.

###Context This hook is called after the WordPress post that represents the loan has been created and after the post meta for it (start date/Item ID/Member ID/etc.) has been added. This action is called when scheduling or loaning an Item but not when giving an Item. This is because only scheduling and loaning an item involve creating a loan. When giving an Item the loan already exists. Check the Glossary to clarify what these terms mean.

If this hook is called when loaning an Item the hook is called after the Loan has been scheduled but before the Item has been given. This will affect the meta values of the associated Item/Loan.

###Parameters

$loan_id
The WordPress Post ID of the loan that has just been created.

$item
The instance of the current Item, from the class WP_Lib_Item.

$member_id
The WordPress Post ID of the member for which the loan has been created.

###Example

Suppose I'm building a notification system that warns someone via email when specially marked items are loaned. The following code warns the president if someone is trying to loan the Declaration of Independence to Nicolas Cage.


add_action('wp_lib_loan_created', 'warn_declaration_theft');

function warn_declaration_theft($loan_id, $member_id, $item) {
	if (get_the_title($member_id) === 'Nicolas Cage' && get_the_title($item->ID) === 'Declaration of Independence') {
		wp_mail('the_president@the_government.gov', 'OH NOES', 'NICOLAS CAGE IS TRYING TO STEAL THE DECLARATION OF INDEPEDENCE!');
	}
}

It is worth noting that hardcoding the names of items/members into a filter is a terrible idea. As is trying to stop Nicolas Cage.

Clone this wiki locally