-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwp-qjumpers-jobs.php
122 lines (103 loc) · 4.1 KB
/
wp-qjumpers-jobs.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
/**
* Plugin Name: WP QJumpers Jobs
* Plugin URI: https://github.com/qjumpersnz/wp-qjumpers-jobs
* Description: A Wordpress Plugin to embed QJumpers Jobs in your site
* Version: 0.1.0
* Author: Andrew Ford
*
* @package wp-qjumpers-jobs
*/
if (is_admin()) { // admin actions
add_action('admin_menu', 'qj_plugin_menu');
}
function qj_plugin_menu()
{
//create new settings options page
add_options_page('QJumpers Jobs Options', 'QJumpers Jobs', 'manage_options', 'wp-qjumpers-jobs', 'qj_plugin_options_page');
//call register settings function
add_action('admin_init', 'register_qj_jobs_plugin_settings');
}
function register_qj_jobs_plugin_settings()
{
//register our settings
register_setting('qj-jobs-settings-group', 'api_key');
register_setting('qj-jobs-settings-group', 'api_url');
register_setting('qj-jobs-settings-group', 'jobsite_url');
}
function qj_plugin_options_page()
{
?>
<div class="wrap">
<h1>QJumpers Jobs Settings</h1>
<form method="post" action="options.php">
<?php settings_fields('qj-jobs-settings-group'); ?>
<?php do_settings_sections('qj-jobs-settings-group'); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">API Key</th>
<td><input type="text" name="api_key" value="<?php echo esc_attr(get_option('api_key')); ?>" size="30" maxlength="30" placeholder="xxxxxxxxxxxxx" /></td>
</tr>
<tr valign="top">
<th scope="row">API URL</th>
<td><input type="text" name="api_url" value="<?php echo esc_attr(get_option('api_url')); ?>" size="30" maxlength="2000" placeholder="https://qjumpers-api.qjumpers.co" /></td>
</tr>
<tr valign="top">
<th scope="row">Job Site URL</th>
<td><input type="text" name="jobsite_url" value="<?php echo esc_attr(get_option('jobsite_url')); ?>" size="30" maxlength="2000" placeholder="https://qjumpersjobs.co" /></td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php }
// Add your shortcode snippets below.
add_shortcode('qj_jobs', 'qj_jobs_shortcode');
function qj_jobs_shortcode()
{
$apikey = get_option('api_key');
$apiurl = get_option('api_url');
$jobsiteurl = get_option('jobsite_url');
$headers = array(
'Authorization' => 'Basic ' . $apikey,
'Accept' => 'application/json;ver=1.0',
'Content-Type' => 'application/json; charset=UTF-8'
);
$request = array(
'headers' => $headers
);
// Get data for API call
$response = wp_remote_get($apiurl, $request);
try {
$jsonBody = wp_remote_retrieve_body($response);
$data = json_decode($jsonBody, true);
foreach ($data['content'] as $obj) {
$address = $obj['address'];
$jobsite_url = $jobsiteurl ? $jobsiteurl : 'https://qjumpersjobs.co';
$link = $jobsite_url . '/applications/add/' . $obj['id'] . '?jobinvitationid='
?>
<div class="qj-jobs">
<div class="qj-jobs_row">
<div class="qj-jobs_col">
<h4><?php echo esc_attr($obj['title']); ?></h4>
<span class=""><?php echo esc_attr($obj['industory']); ?></span>
</div>
<div class="qj-jobs_col">
<p class=""><?php echo esc_attr($obj['hierarchyName']); ?></p>
<span class=""><?php echo esc_attr($address['state']); ?> <?php echo esc_attr($address['city']); ?></span>
</div>
</div>
<div class="qj-jobs_row qj-jobs_desc">
<?php echo esc_attr($obj['shortDescription']); ?>
</div>
<div>
<a href="<?php echo esc_attr($link); ?>">Apply</a>
</div>
</div>
<?php
}
} catch (Exception $ex) {
echo esc_attr("<p>No jobs available</p>");
} // end try/catch
}
?>