Last active
June 30, 2020 21:31
-
-
Save tripflex/69560d8507a668733dbfc61ad3a95539 to your computer and use it in GitHub Desktop.
Add a custom shortcode to be available in email templates when using WP Job Manager Emails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// This example below will add the "my_shortcode" shortcode for usage in all email templates | |
// You MUST make sure that you use a unique shortcode that does not match ANY of the meta keys of fields!! | |
// Passed arguments are same as when adding a shortcode like normal (using add_shortcode) | |
// Called from wp-content/plugins/wp-job-manager-emails/includes/class-shortcodes.php around line #648 | |
add_filter( 'job_manager_emails_default_core_shortcodes', 'smyles_add_custom_default_shortcode_wpjm_emails', 9999 ); | |
function smyles_add_custom_default_shortcode_wpjm_emails( $shortcodes ){ | |
$shortcodes['my_shortcode'] = array( | |
'label' => __( 'My Shortcode' ), | |
'description' => __( 'This is my custom shortcode available on all email templates' ), | |
'callback' => 'my_shortcode_function', // <-- this should be a function to call that will return the data to replace the shortcode with | |
// 'callback' => array( $this, 'class_function' ), // You can also specify as an array to call class function | |
'nonmeta' => true | |
); | |
return $shortcodes; | |
} |
There is also filters specifically for
job shortcodes: job_manager_emails_job_shortcodes
resume: job_manager_emails_resume_shortcodes
private messages: job_manager_emails_privatemessages_shortcodes
application: job_manager_emails_application_shortcodes
Hey Myles,
Jason here from Project Pi. FYI, I got this working but I had to change line #17 to the following:
'callback' => 'my_shortcode_function',
@projectpi-ca thanks I updated the code, this was an old example from v1 where in v2 the arg was changed to callback
as you specified
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If in your shortcode you need the ID of one of the listings, you can use the available handling below:
Job Listing ID:
wp_job_manager_emails()->tmp_job_id
Job Alert ID:
wp_job_manager_emails()->tmp_alert_id
Resume ID:
wp_job_manager_emails()->tmp_resume_id
Application ID:
wp_job_manager_emails()->tmp_app_id
These are all temporary variables that the IDs are set in during the shortcode processing and handling.