Auto Populate from User Meta Feature

With the release of version 1.1.12 of WP Job Manager Field Editor, a new feature has been added which is called Auto Populate.  This will allow you to auto populate any of the currently editable fields with a value pulled from a user’s meta.

The auto populate feature now also supports saving to the users meta.  The screenshots below may not show it but there is now a checkbox below Auto Populate which you can select to enable saving the field to the user’s meta.  This will auto populate on the next listing the user submits as long as you have Auto Populate enabled.

As an example, WP Job Manager automatically saves a couple fields to a user’s meta whenever they create their first job, such as company_name.  When that same user goes to post a new job, the Company Name field is auto populated with the value that was saved to the user meta.  This new feature will allow you to auto populate any of the fields (including taxonomies) with items saved in a user’s meta.

A few things to point out:

  • This only works for pulling values from user meta
  • Users must already have an account
  • Version 1.7.6 or newer is required for WP Job Manager Resumes (workaround is available below)

 

WP Job Manager Field Editor Auto Populate

WP Job Manager Field Editor Auto Populate

Overview

To setup auto populate with an existing field (or a new one), you will need to go to the field configuration to make the change.  All auto populate configuration will be done through the modal under the Populate section/tab.

When you click on edit or create a new field when the modal pops up you will see a new tab on the left hand side that should look like the image on the right.

 

 

 

 

WP Job Manager Field Editor Auto Populate Example

WP Job Manager Field Editor Auto Populate Example

Configuration

Currently there are only two configuration settings, enable and meta key.  Enable must be checked in order for auto populate to function correctly.

Meta Key is going to be the field you need to make sure is correct.  This value is just like a meta key for fields (no spaces, etc).

As you can see in the image on the left the meta key entered was candidate_phone, if you look at the image below, you will see that is the value found in my User Meta Display plugin.

 

User Meta Display

User Meta Display

Jobify Theme Auto Populate Example

Jobify Theme Auto Populate Example

 

Determining User Meta Keys

You can inspect any users meta by using my free Open Source plugin called User Meta Display.  This will allow you to add, edit, and view any user’s meta (with a nice intuitive ajax interface).  I recommend using this plugin if you are unsure of what the meta key is for the user meta you want to use.  If the meta key is incorrect, or the meta does not exist for that user, nothing will be populated into the field.

Currently this feature ONLY populates fields from user meta, it does not save to user meta.

Old Versions of WP Job Manager Resumes ( < 1.7.6 )

You must be using WP Job Manager Resumes version 1.7.6 or newer for this feature to function correctly for Resumes.  If you do not have this version (currently not released yet as of 10/27/2014), it is fairly easy to add the functionality.  You will need to add a few lines of code to one of the WP Job Manager Resumes files as directed below.

This is the code we need to add:

// Get user meta
} elseif ( is_user_logged_in() && empty( $_POST ) ) {

	self::$fields = apply_filters( 'submit_resume_form_fields_get_user_data', self::$fields, get_current_user_id() );

}

Which will be replacing the }  from right above the get_job_manager_template( ‘resume-submit.php’, array(  line.

The file you need to edit is

/wp-content/plugins/wp-job-manager-resumes/includes/forms/class-wp-resume-manager-form-submit-resume.php

You will need to look for the submit()  function which should be around line 584

This is the original function below:

/**
 * Submit Step
 */
public static function submit() {
	global $job_manager, $post;

	self::init_fields();

	// Load data if neccessary
	if ( ! empty( $_POST['edit_resume'] ) && self::$resume_id ) {
		$resume = get_post( self::$resume_id );
		foreach ( self::$fields as $group_key => $fields ) {
			foreach ( $fields as $key => $field ) {
				switch ( $key ) {
					case 'candidate_name' :
						self::$fields[ $group_key ][ $key ]['value'] = $resume->post_title;
					break;
					case 'resume_content' :
						self::$fields[ $group_key ][ $key ]['value'] = $resume->post_content;
					break;
					case 'resume_skills' :
						self::$fields[ $group_key ][ $key ]['value'] = implode( ', ', wp_get_object_terms( $resume->ID, 'resume_skill', array( 'fields' => 'names' ) ) );
					break;
					case 'resume_category' :
						self::$fields[ $group_key ][ $key ]['value'] = wp_get_object_terms( $resume->ID, 'resume_category', array( 'fields' => 'ids' ) );
					break;
					default:
						self::$fields[ $group_key ][ $key ]['value'] = get_post_meta( $resume->ID, '_' . $key, true );
					break;
				}
			}
		}
		self::$fields = apply_filters( 'submit_resume_form_fields_get_resume_data', self::$fields, $resume );
	}

	get_job_manager_template( 'resume-submit.php', array(
		'class'              => __CLASS__,
		'form'               => self::$form_name,
		'resume_id'          => self::get_resume_id(),
		'job_id'             => self::get_job_id(),
		'action'             => self::get_action(),
		'resume_fields'      => self::get_fields( 'resume_fields' ),
		'submit_button_text' => __( 'Preview resume &rarr;', 'wp-job-manager-resumes' )
	), 'wp-job-manager-resumes', RESUME_MANAGER_PLUGIN_DIR . '/templates/' );
}

This is how the function should look after being updated:

/**
 * Submit Step
 */
public static function submit() {
	global $job_manager, $post;

	self::init_fields();

	// Load data if neccessary
	if ( ! empty( $_POST['edit_resume'] ) && self::$resume_id ) {
		$resume = get_post( self::$resume_id );
		foreach ( self::$fields as $group_key => $fields ) {
			foreach ( $fields as $key => $field ) {
				switch ( $key ) {
					case 'candidate_name' :
						self::$fields[ $group_key ][ $key ]['value'] = $resume->post_title;
					break;
					case 'resume_content' :
						self::$fields[ $group_key ][ $key ]['value'] = $resume->post_content;
					break;
					case 'resume_skills' :
						self::$fields[ $group_key ][ $key ]['value'] = implode( ', ', wp_get_object_terms( $resume->ID, 'resume_skill', array( 'fields' => 'names' ) ) );
					break;
					case 'resume_category' :
						self::$fields[ $group_key ][ $key ]['value'] = wp_get_object_terms( $resume->ID, 'resume_category', array( 'fields' => 'ids' ) );
					break;
					default:
						self::$fields[ $group_key ][ $key ]['value'] = get_post_meta( $resume->ID, '_' . $key, true );
					break;
				}
			}
		}
		self::$fields = apply_filters( 'submit_resume_form_fields_get_resume_data', self::$fields, $resume );

	// Get user meta
	} elseif ( is_user_logged_in() && empty( $_POST ) ) {

		self::$fields = apply_filters( 'submit_resume_form_fields_get_user_data', self::$fields, get_current_user_id() );

	}

	get_job_manager_template( 'resume-submit.php', array(
		'class'              => __CLASS__,
		'form'               => self::$form_name,
		'resume_id'          => self::get_resume_id(),
		'job_id'             => self::get_job_id(),
		'action'             => self::get_action(),
		'resume_fields'      => self::get_fields( 'resume_fields' ),
		'submit_button_text' => __( 'Preview resume &rarr;', 'wp-job-manager-resumes' )
	), 'wp-job-manager-resumes', RESUME_MANAGER_PLUGIN_DIR . '/templates/' );
}

 

Total 4 Votes

Tell us how can we improve this post?

+ = Verify Human or Spambot ?