| 1 |
<?php |
| 2 |
/** |
| 3 |
* Requirements |
| 4 |
* |
| 5 |
* @package GamiPress\WP_Job_Manager\Requirements |
| 6 |
* @since 1.0.0 |
| 7 |
*/ |
| 8 |
|
| 9 |
// Exit if accessed directly |
| 10 |
if( !defined( 'ABSPATH' ) ) exit; |
| 11 |
|
| 12 |
/** |
| 13 |
* Add custom fields to the requirement object |
| 14 |
* |
| 15 |
* @since 1.0.0 |
| 16 |
* |
| 17 |
* @param $requirement |
| 18 |
* @param $requirement_id |
| 19 |
* |
| 20 |
* @return array |
| 21 |
*/ |
| 22 |
function gamipress_wp_job_manager_requirement_object( $requirement, $requirement_id ) { |
| 23 |
|
| 24 |
if( isset( $requirement['trigger_type'] ) |
| 25 |
&& in_array( $requirement['trigger_type'], array( |
| 26 |
'gamipress_wp_job_manager_publish_job_specific_type', |
| 27 |
'gamipress_wp_job_manager_mark_filled_specific_type', |
| 28 |
'gamipress_wp_job_manager_mark_not_filled_specific_type', |
| 29 |
// Applications |
| 30 |
'gamipress_wp_job_manager_job_application_specific_type', |
| 31 |
'gamipress_wp_job_manager_get_job_application_specific_type', |
| 32 |
'gamipress_wp_job_manager_job_application_hired_specific_type', |
| 33 |
'gamipress_wp_job_manager_job_application_rejected_specific_type', |
| 34 |
) ) ) { |
| 35 |
// Type |
| 36 |
$requirement['wp_job_manager_type_id'] = gamipress_get_post_meta( $requirement_id, '_gamipress_wp_job_manager_type_id', true ); |
| 37 |
} |
| 38 |
|
| 39 |
return $requirement; |
| 40 |
} |
| 41 |
add_filter( 'gamipress_requirement_object', 'gamipress_wp_job_manager_requirement_object', 10, 2 ); |
| 42 |
|
| 43 |
/** |
| 44 |
* Custom fields on requirements UI |
| 45 |
* |
| 46 |
* @since 1.0.0 |
| 47 |
* |
| 48 |
* @param $requirement_id |
| 49 |
* @param $post_id |
| 50 |
*/ |
| 51 |
function gamipress_wp_job_manager_requirement_ui_fields( $requirement_id, $post_id ) { |
| 52 |
|
| 53 |
// Type select |
| 54 |
$type_id = absint( gamipress_get_post_meta( $requirement_id, '_gamipress_wp_job_manager_type_id', true ) ); |
| 55 |
$types = get_terms( array( |
| 56 |
'taxonomy' => 'job_listing_type', |
| 57 |
'hide_empty' => false, |
| 58 |
) ); |
| 59 |
|
| 60 |
?> |
| 61 |
|
| 62 |
<span class="wp-job-manager-type"> |
| 63 |
<select> |
| 64 |
<?php foreach( $types as $type ) : ?> |
| 65 |
<option value="<?php echo $type->term_id; ?>" <?php selected( $type_id, $type->term_id ); ?>><?php echo $type->name; ?></option> |
| 66 |
<?php endforeach; ?> |
| 67 |
</select> |
| 68 |
</span> |
| 69 |
|
| 70 |
<?php |
| 71 |
} |
| 72 |
add_action( 'gamipress_requirement_ui_html_after_achievement_post', 'gamipress_wp_job_manager_requirement_ui_fields', 10, 2 ); |
| 73 |
|
| 74 |
/** |
| 75 |
* Custom handler to save custom fields on requirements UI |
| 76 |
* |
| 77 |
* @since 1.0.0 |
| 78 |
* |
| 79 |
* @param $requirement_id |
| 80 |
* @param $requirement |
| 81 |
*/ |
| 82 |
function gamipress_wp_job_manager_ajax_update_requirement( $requirement_id, $requirement ) { |
| 83 |
|
| 84 |
if( isset( $requirement['trigger_type'] ) |
| 85 |
&& in_array( $requirement['trigger_type'], array( |
| 86 |
'gamipress_wp_job_manager_publish_job_specific_type', |
| 87 |
'gamipress_wp_job_manager_mark_filled_specific_type', |
| 88 |
'gamipress_wp_job_manager_mark_not_filled_specific_type', |
| 89 |
// Applications |
| 90 |
'gamipress_wp_job_manager_job_application_specific_type', |
| 91 |
'gamipress_wp_job_manager_get_job_application_specific_type', |
| 92 |
'gamipress_wp_job_manager_job_application_hired_specific_type', |
| 93 |
'gamipress_wp_job_manager_job_application_rejected_specific_type', |
| 94 |
) ) ) { |
| 95 |
// Save the type field |
| 96 |
gamipress_update_post_meta( $requirement_id, '_gamipress_wp_job_manager_type_id', $requirement['wp_job_manager_type_id'] ); |
| 97 |
} |
| 98 |
|
| 99 |
} |
| 100 |
add_action( 'gamipress_ajax_update_requirement', 'gamipress_wp_job_manager_ajax_update_requirement', 10, 2 ); |