KanbanPress provides two custom hooks to allow developers to add functionality when a post is marked as complete or incomplete. These hooks can be used to extend the behavior of the plugin without modifying its core code.
Available Hooks
kanbanpress_post_completed
This hook is triggered when a post is marked as completed.
Usage:
PHP
add_action('kanbanpress_post_completed', 'my_custom_function_when_completed');
function my_custom_function_when_completed($post_id) {
// Custom code to execute when a post is marked as completed
}
Parameters:
$post_id
(int): The ID of the post that has been marked as completed.
kanbanpress_post_incomplete
This hook is triggered when a post is marked as incomplete.
Usage:
PHP
add_action('kanbanpress_post_incomplete', 'my_custom_function_when_incomplete');
function my_custom_function_when_incomplete($post_id) {
// Custom code to execute when a post is marked as incomplete
}
Parameters:
$post_id
(int): The ID of the post that has been marked as incomplete.
Example
Here’s an example of how you can use these hooks in your code:
PHP
add_action('kanbanpress_post_completed', 'notify_user_on_completion');
function notify_user_on_completion($post_id) {
$user_id = get_post_field('post_author', $post_id);
$user_info = get_userdata($user_id);
$email = $user_info->user_email;
$subject = 'Your post has been marked as completed';
$message = 'Congratulations! Your post (ID: ' . $post_id . ') has been marked as completed.';
wp_mail($email, $subject, $message);
}
add_action('kanbanpress_post_incomplete', 'log_incomplete_status');
function log_incomplete_status($post_id) {
error_log('Post ID ' . $post_id . ' has been marked as incomplete.');
}
In this example, when a post is marked as completed, the notify_user_on_completion
function sends an email notification to the post’s author. When a post is marked as incomplete, the log_incomplete_status
function logs this event.