The default setup for Matador Jobs Pro enables you to set different Webhook URLs (and therefore destination channels) for your Jobs and Application Notifications. However, some of our users need to target jobs or applications to specific discord channels according to specific criteria.
This can be achieved by hooking a function to the webhook filter and returning a different webhook according to your required criteria.
The example below shows how this can be achieved to send different jobs to different channels according to the jobs’ category.
/**
* Filter the Discord webhook URL based on the job category.
*
* @param string $webhook The current webhook URL.
* @param object $job The job object.
* @param int $wpid The WordPress ID of the job.
* @return string The filtered webhook URL.
*/
function matador_discord_jobs_webhook( $webhook, $job, $wpid ) {
// Check if the job belongs to the 'Union' category.
foreach ( $job->categories->data as $category ) {
if ( 'Union' === $category->name ) {
return // Insert the Union-specific webhook here
}
}
// Return the original or default webhook if not in the 'Union' category.
return $webhook;
}
// Add the filter with the specific function.
add_filter( 'discord_jobs_webhook', 'matador_discord_jobs_webhook', 10, 3 );