Last active
September 11, 2020 22:05
-
-
Save tripflex/1a89f84568f179335e1acec2b1e9a137 to your computer and use it in GitHub Desktop.
Move specific company fields into Job Fields section below a specific Job Field
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 | |
/** | |
* Content for job submission (`[submit_job_form]`) shortcode. | |
* | |
* This template can be overridden by copying it to yourtheme/job_manager/job-submit.php. | |
* | |
* @see https://wpjobmanager.com/document/template-overrides/ | |
* @author Automattic | |
* @package wp-job-manager | |
* @category Template | |
* @version 1.33.1 | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; // Exit if accessed directly. | |
} | |
if ( ! function_exists( 'smyles_array_insert_after' ) ) { | |
function smyles_array_insert_after( &$array, $after_key, $key, $value ) { | |
$pos = array_search( $after_key, array_keys( $array ) ); | |
$pos++; | |
$array = array_merge( | |
array_slice( $array, 0, $pos, $preserve_keys = true ), | |
array( $key => $value ), | |
array_slice( $array, $pos ) | |
); | |
} | |
} | |
if ( ! function_exists( 'smyles_move_company_to_job_field' ) ) { | |
function smyles_move_company_to_job_field( $after_job_meta_key, $company_meta_key, &$job_fields, &$company_fields ) { | |
if ( ! array_key_exists( $company_meta_key, $company_fields ) ) { | |
return; | |
} | |
// First add company field after specific job field meta key in $job_fields | |
smyles_array_insert_after( $job_fields, $after_job_meta_key, $company_meta_key, $company_fields[ $company_meta_key ] ); | |
// Then remove it from company fields | |
unset( $company_fields[ $company_meta_key ] ); | |
} | |
} | |
smyles_move_company_to_job_field( 'job_location', 'company_name', $job_fields, $company_fields ); | |
global $job_manager; | |
?> | |
<form action="<?php echo esc_url( $action ); ?>" method="post" id="submit-job-form" class="job-manager-form" enctype="multipart/form-data"> | |
<?php | |
if ( isset( $resume_edit ) && $resume_edit ) { | |
printf( '<p><strong>' . esc_html__( "You are editing an existing job. %s", 'wp-job-manager' ) . '</strong></p>', '<a href="?new=1&key=' . esc_attr( $resume_edit ) . '">' . esc_html__( 'Create A New Job', 'wp-job-manager' ) . '</a>' ); | |
} | |
?> | |
<?php do_action( 'submit_job_form_start' ); ?> | |
<?php if ( apply_filters( 'submit_job_form_show_signin', true ) ) : ?> | |
<?php get_job_manager_template( 'account-signin.php' ); ?> | |
<?php endif; ?> | |
<?php if ( job_manager_user_can_post_job() || job_manager_user_can_edit_job( $job_id ) ) : ?> | |
<!-- Job Information Fields --> | |
<?php do_action( 'submit_job_form_job_fields_start' ); ?> | |
<?php foreach ( $job_fields as $key => $field ) : ?> | |
<?php | |
?> | |
<fieldset class="fieldset-<?php echo esc_attr( $key ); ?> fieldset-type-<?php echo esc_attr( $field['type'] ); ?>"> | |
<label for="<?php echo esc_attr( $key ); ?>"><?php echo wp_kses_post( $field['label'] ) . wp_kses_post( apply_filters( 'submit_job_form_required_label', $field['required'] ? '' : ' <small>' . __( '(optional)', 'wp-job-manager' ) . '</small>', $field ) ); ?></label> | |
<div class="field <?php echo $field['required'] ? 'required-field' : ''; ?>"> | |
<?php get_job_manager_template( 'form-fields/' . $field['type'] . '-field.php', [ 'key' => $key, 'field' => $field ] ); ?> | |
</div> | |
</fieldset> | |
<?php endforeach; ?> | |
<?php do_action( 'submit_job_form_job_fields_end' ); ?> | |
<!-- Company Information Fields --> | |
<?php if ( $company_fields ) : ?> | |
<h2><?php esc_html_e( 'Company Details', 'wp-job-manager' ); ?></h2> | |
<?php do_action( 'submit_job_form_company_fields_start' ); ?> | |
<?php foreach ( $company_fields as $key => $field ) : ?> | |
<fieldset class="fieldset-<?php echo esc_attr( $key ); ?> fieldset-type-<?php echo esc_attr( $field['type'] ); ?>"> | |
<label for="<?php echo esc_attr( $key ); ?>"><?php echo wp_kses_post( $field['label'] ) . wp_kses_post( apply_filters( 'submit_job_form_required_label', $field['required'] ? '' : ' <small>' . __( '(optional)', 'wp-job-manager' ) . '</small>', $field ) ); ?></label> | |
<div class="field <?php echo $field['required'] ? 'required-field' : ''; ?>"> | |
<?php get_job_manager_template( 'form-fields/' . $field['type'] . '-field.php', [ 'key' => $key, 'field' => $field ] ); ?> | |
</div> | |
</fieldset> | |
<?php endforeach; ?> | |
<?php do_action( 'submit_job_form_company_fields_end' ); ?> | |
<?php endif; ?> | |
<?php do_action( 'submit_job_form_end' ); ?> | |
<p> | |
<input type="hidden" name="job_manager_form" value="<?php echo esc_attr( $form ); ?>" /> | |
<input type="hidden" name="job_id" value="<?php echo esc_attr( $job_id ); ?>" /> | |
<input type="hidden" name="step" value="<?php echo esc_attr( $step ); ?>" /> | |
<input type="submit" name="submit_job" class="button" value="<?php echo esc_attr( $submit_button_text ); ?>" /> | |
<?php | |
if ( isset( $can_continue_later ) && $can_continue_later ) { | |
echo '<input type="submit" name="save_draft" class="button secondary save_draft" value="' . esc_attr__( 'Save Draft', 'wp-job-manager' ) . '" formnovalidate />'; | |
} | |
?> | |
<span class="spinner" style="background-image: url(<?php echo esc_url( includes_url( 'images/spinner.gif' ) ); ?>);"></span> | |
</p> | |
<?php else : ?> | |
<?php do_action( 'submit_job_form_disabled' ); ?> | |
<?php endif; ?> | |
</form> |
hey@ tripflex,
thanks for sharing this, but for some reason the function is not working on my staging enviroment. Any ideas about that?
@Braehler sorry about that, there was a bug in the code, I updated this example code with a fix for it. Give it a try now with the updated code above
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The main handling here is in this function call:
If you wanted to add something after the
company_name
field specifically, you must add another function call below that one, like this: