wp_lib_loan_created - roberts-sandbox/create-repo GitHub Wiki

###Description

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

###Context This filter 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.

###Parameters

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

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

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

###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.

⚠️ **GitHub.com Fallback** ⚠️