Skip to content

Instantly share code, notes, and snippets.

@vodanh1213
Created July 28, 2015 08:36
Show Gist options
  • Save vodanh1213/055480922b949ae6d80f to your computer and use it in GitHub Desktop.
Save vodanh1213/055480922b949ae6d80f to your computer and use it in GitHub Desktop.
<?php /*
Plugin Name: Jobs & Experts Custom Job Fields
Author: Hoang Ngo
Version: 1.0
*/
add_filter( 'je_job_additions_field', 'job_add_extra_field' );
function job_add_extra_field( $fields ) {
$fields = array_merge( $fields, array(
'selected_office',
'employees_required',
'level_of_staff',
'custom_job_status'
) );
return $fields;
}
//add_filter('je_job_validation_rules', 'job_add_location_validation_rule');
function job_add_location_validation_rule( $rules ) {
$rules = array_merge( $rules, array(
'job_location' => 'required',
) );
return $rules;
}
add_filter( 'je_job_field_name', 'job_extra_field_name' );
function job_extra_field_name( $names ) {
$names = array_merge( $names, array(
'selected_office' => __( "Location", je()->domain ),
'employees_required' => "Employees Required",
'level_of_staff' => "Level of Staff",
'custom_job_status' => "Custom Job Status"
) );
return $names;
}
add_filter( 'je_job_relations', 'job_extra_relations' );
function job_extra_relations( $relations ) {
$relations = array_merge( $relations, array(
array(
'type' => 'meta',
'key' => 'selected_office',
'map' => 'selected_office'
),
array(
'type' => 'meta',
'key' => 'employees_required',
'map' => 'employees_required'
),
array(
'type' => 'meta',
'key' => 'level_of_staff',
'map' => 'level_of_staff'
),
array(
'type' => 'meta',
'key' => 'custom_job_status',
'map' => 'custom_job_status'
),
) );
return $relations;
}
add_action( 'je_job_after_form', 'add_extra_form_fields', 10, 2 );
function add_extra_form_fields( JE_Job_Model $model, IG_Active_Form $form ) {
if ( is_admin() ) {
?>
<div class="form-group <?php echo $model->has_error( "selected_office" ) ? "has-error" : null ?>">
<?php $form->label( "selected_office", array(
"text" => __( "Location", je()->domain ),
"attributes" => array( "class" => "col-lg-3 control-label" )
) ) ?>
<div class="col-lg-9">
<?php $form->text( "selected_office", array( "attributes" => array( "class" => "form-control" ) ) ) ?>
<span class="help-block m-b-none error-job_title"><?php $form->error( "selected_office" ) ?></span>
</div>
<div class="clearfix"></div>
</div>
<div class="form-group <?php echo $model->has_error( "employees_required" ) ? "has-error" : null ?>">
<?php $form->label( "employees_required", array(
"text" => __( "Employees Required", je()->domain ),
"attributes" => array( "class" => "col-lg-3 control-label" )
) ) ?>
<div class="col-lg-9">
<?php $form->select( "employees_required", array( "attributes" => array( "class" => "form-control" ) ) ) ?>
<span class="help-block m-b-none error-job_title"><?php $form->error( "employees_required" ) ?></span>
</div>
<div class="clearfix"></div>
</div>
<div class="form-group <?php echo $model->has_error( "level_of_staff" ) ? "has-error" : null ?>">
<?php $form->label( "level_of_staff", array(
"text" => __( "Level of Staff", je()->domain ),
"attributes" => array( "class" => "col-lg-3 control-label" )
) ) ?>
<div class="col-lg-9">
<?php $form->select( "level_of_staff", array(
"attributes" => array(
"class" => "form-control",
"multiple" => "multiple"
)
) ) ?>
<span class="help-block m-b-none error-job_title"><?php $form->error( "level_of_staff" ) ?></span>
</div>
<div class="form-group <?php echo $model->has_error( "custom_job_status" ) ? "has-error" : null ?>">
<?php $form->label( "custom_job_status", array(
"text" => __( "Custom Job Status", je()->domain ),
"attributes" => array( "class" => "col-lg-3 control-label" )
) ) ?>
<div class="col-lg-9">
<?php $form->select( "custom_job_status", array(
"attributes" => array(
"class" => "form-control",
"multiple" => "multiple"
)
) ) ?>
<span class="help-block m-b-none error-job_title"><?php $form->error( "custom_job_status" ) ?></span>
</div>
<div class="clearfix"></div>
</div>
<?php
} else {
?>
<div class="form-group <?php echo $model->has_error( "selected_office" ) ? "has-error" : null ?>">
<?php $form->label( "selected_office", array(
"text" => __( "Location", je()->domain ),
"attributes" => array( "class" => "col-lg-3 control-label" )
) ) ?>
<div class="col-lg-9">
<?php $form->text( "selected_office", array( "attributes" => array( "class" => "form-control" ) ) ) ?>
<span class="help-block m-b-none error-job_title"><?php $form->error( "selected_office" ) ?></span>
</div>
<div class="clearfix"></div>
</div>
<div class="form-group <?php echo $model->has_error( "employees_required" ) ? "has-error" : null ?>">
<?php $form->label( "employees_required", array(
"text" => __( "Employees Required", je()->domain ),
"attributes" => array( "class" => "col-lg-3 control-label" )
) ) ?>
<div class="col-lg-9">
<?php $form->select( "employees_required", array(
"attributes" => array( "class" => "form-control" ),
"data" => get_employees_required_list()
) ) ?>
<span class="help-block m-b-none error-job_title"><?php $form->error( "employees_required" ) ?></span>
</div>
<div class="clearfix"></div>
</div>
<div class="form-group <?php echo $model->has_error( "level_of_staff" ) ? "has-error" : null ?>">
<?php $form->label( "level_of_staff", array(
"text" => __( "Level of Staff", je()->domain ),
"attributes" => array( "class" => "col-lg-3 control-label" )
) ) ?>
<div class="col-lg-9">
<?php $form->select( "level_of_staff", array(
"attributes" => array( "class" => "form-control", "multiple" => "multiple" ),
"data" => get_level_list()
) ) ?>
<span class="help-block m-b-none error-job_title"><?php $form->error( "level_of_staff" ) ?></span>
</div>
<div class="clearfix"></div>
</div>
<div class="form-group <?php echo $model->has_error( "custom_job_status" ) ? "has-error" : null ?>">
<?php $form->label( "custom_job_status", array(
"text" => __( "Custom Job Status", je()->domain ),
"attributes" => array( "class" => "col-lg-3 control-label" )
) ) ?>
<div class="col-lg-9">
<?php $form->select( "custom_job_status", array(
"attributes" => array( "class" => "form-control", "multiple" => "multiple" ),
"data" => get_level_list()
) ) ?>
<span class="help-block m-b-none error-job_title"><?php $form->error( "custom_job_status" ) ?></span>
</div>
<div class="clearfix"></div>
</div>
<?php
}
}
function get_employees_required_list() {
return array(
'list_1' => '1',
'list_2' => '2',
'list_3' => '3',
'list_4' => '4',
'list_5' => '5'
);
}
function get_level_list() {
return array(
'skill_1' => 'All',
'skill_2' => 'Office',
'skill_3' => 'Management',
'skill_4' => 'Senior'
);
}
function get_status_list() {
return array(
'skill_1' => 'Open',
'skill_2' => 'Pending',
'skill_3' => 'In Progress',
'skill_4' => 'Completed'
);
}
add_action( 'je_job_single_before_attachments', 'job_display_location_single' );
function job_display_location_single( $model ) {
if ( $model->selected_office ) {
?>
<div class="row">
<div class="col-md-12">
<?php _e( "Selected Offices", je()->domain ) ?>:
<?php echo $model->selected_office ?>
</div>
</div>
<?php
}
if ( $model->employees_required ) {
$data = get_employees_required_list();
?>
<div class="row">
<div class="col-md-12">
<?php _e( "Employees Required", je()->domain ) ?>:
<?php echo $data[ $model->employees_required ] ?>
</div>
</div>
<?php
}
if ( $model->level_of_staff ) {
$data = get_level_list();
$texts = array_intersect_key( $data, array_combine( $model->level_of_staff, $model->level_of_staff ) );
?>
<div class="row">
<div class="col-md-12">
<?php _e( "Level Of Staff", je()->domain ) ?>:
<?php echo implode( ', ', $texts ) ?>
</div>
</div>
<?php
}
if ( $model->custom_job_status ) {
$data = get_status_list();
$texts = array_intersect_key( $data, array_combine( $model->custom_job_status, $model->custom_job_status ) );
?>
<div class="row">
<div class="col-md-12">
<?php _e( "Custom Job Status", je()->domain ) ?>:
<?php echo implode( ', ', $texts ) ?>
</div>
</div>
<?php
}
}
add_action( 'jbp_job_list_content', 'jbp_job_archive_after_content', 10, 4 );
function jbp_job_archive_after_content( $result, $content, $charlength, $job ) {
$model = JE_Job_Model::model()->find( $job->id );
if ( $model->selected_office ) {
$result .= '<div class="jbp_extra_fields"><strong>' . __( "Selected Offices", je()->domain ) . '</strong>: ' . $model->selected_office . '</div>';
}
if ( $model->employees_required ) {
$data = get_employees_required_list();
$result .= '<div class="jbp_extra_fields"><strong>' . __( "Employees Required", je()->domain ) . '</strong>: ' . $data[ $model->employees_required ] . '</div>';
}
if ( $model->level_of_staff ) {
$data = get_level_list();
$texts = array_intersect_key( $data, array_combine( $model->level_of_staff, $model->level_of_staff ) );
$result .= '<div class="jbp_extra_fields"><strong>' . __( "Level Of Staff", je()->domain ) . '</strong>: ' . implode( ', ', $texts ) . '</div>';
}
if ( $model->custom_job_status ) {
$data = get_status_list();
$texts = array_intersect_key( $data, array_combine( $model->custom_job_status, $model->custom_job_status ) );
$result .= '<div class="jbp_extra_fields"><strong>' . __( "Custom Jobs Status", je()->domain ) . '</strong>: ' . implode( ', ', $texts ) . '</div>';
}
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment