This post describes how to configure WP Job Manager plugin to be able to send a job application as a BuddyPress private message rather than email or a web link.
Needless to say, use at your risk. Don’t blame me if your site goes kaput (it happened to me when I screwed up the spelling of one of the variables). Before implementing it on your production site, please test it on a personal machine.
Only two files need to be changed.
1. JOB-APPLICATION.php
(usually in the directory ../wp-content/plugins/wp-job-manager/templates)
<?php if ( $apply = get_the_job_application_method() ) :
wp_enqueue_script( 'wp-job-manager-job-application' );
?>
<div class="job_application application">
<?php do_action( 'job_application_start', $apply ); ?>
<!---------------------- ADD THIS SECTION -------------->
<?php
if ( ! is_user_logged_in() ) {
?>
<p class="account-sign-in"><?php _e( 'You need to be signed in to apply for this job.', 'wp-job-manager' ); ?>
<a class="button" href="<?php echo apply_filters( 'job_manager_job_dashboard_login_url', wp_login_url( get_permalink() ) ); ?>">
<?php _e( 'Sign in', 'wp-job-manager' ); ?>
</a></p>
<?php
} else {
//show the form if the form has not been submitted.
if ( ! isset($_POST['nb_app_submit']) ): {
?>
<hr><br>
<form action="<?php echo esc_url( $action ); ?>" method="post">
<br>
<p>Please use the area below to write your application.
Your application will be sent as a private message to the person who posted the job. </p>
<textarea name="nb_app_note3" rows="8" cols="40"
placeholder="I would like to apply for..." required></textarea>
<input type="hidden" name="nb_app_rec" value="<?php echo get_user_by('email',$apply->raw_email)->ID; ?>">
<input type="hidden" name="nb_app_jobtitle" value="<?php echo rawurlencode($apply->subject); ?>">
<input type="submit" name="nb_app_submit" value="Apply Job" />
</form>
<?php
} else:
if ( $_POST['nb_app_submit'] == 'Apply Job') {
$msg_cont = $_POST['nb_app_note3'];
if ($msg_cont == '') {$msg_cont = 'The sender did not write any message.';}
$apply->app_note = $msg_cont;
$confirm_msg = '<br>You application has been submitted.<br>';
_e($confirm_msg);
}
else {
_e('Error: No parameters to read.');
}
?>
<!--
when the APPLY JOB button is clicked, the form is submitted.
The form comes back to the same page.
At this point, check if the $_POST['submit'] == 'Apply Job'.
If yes, then send the private msg.
Else, show the same page which is the default situation.
->
<?php
endif;
}
?>
<!---------------------------- ADDITIONS - END --------------------->
<!------ DISABLE THE NEXT LINE SO THAT THIS BUTTON DOES NOT SHOW ---->
<!--input type="button" class="application_button button"
value="<?php //_e( 'Apply for job', 'wp-job-manager' ); ?>" /-->
<!--------- LEAVE THE REST OF THE CODE AS IS. --------------------->
<div class="application_details">
<?php
/**
* job_manager_application_details_email or job_manager_application_details_url hook
*/
do_action( 'job_manager_application_details_' . $apply->type, $apply );
?>
</div>
<?php do_action( 'job_application_end', $apply ); ?>
</div>
<?php endif; ?>
2. JOB-APPLICATION-EMAIL.PHP
(usually in the directory ../wp-content/plugins/wp-job-manager/templates)
Replace the contents of the file with the following.
<p>
<?php
$job_poster = get_user_by('email',$apply->raw_email)->user_login;
$message = $apply->app_note;
$msg_sub = $apply->subject;
$msg_sub = substr($msg_sub,15);
$args = array( 'recipients' => array($job_poster),
'subject' => $msg_sub,
'content' => $message
);
messages_new_message( $args );
?>
</p>
