-
Notifications
You must be signed in to change notification settings - Fork 1
/
wp-job-manager-template.php
527 lines (440 loc) · 12.8 KB
/
wp-job-manager-template.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
<?php
/**
* Template Functions
*
* Template functions specifically created for job listings
*
* @author Mike Jolley
* @category Core
* @package Job Manager/Template
* @version 1.0.0
*/
/**
* Get and include template files.
*
* @param mixed $template_name
* @param array $args (default: array())
* @param string $template_path (default: '')
* @param string $default_path (default: '')
* @return void
*/
function get_job_manager_template( $template_name, $args = array(), $template_path = '', $default_path = '' ) {
if ( $args && is_array($args) )
extract( $args );
include( locate_job_manager_template( $template_name, $template_path, $default_path ) );
}
/**
* Locate a template and return the path for inclusion.
*
* This is the load order:
*
* yourtheme / $template_path / $template_name
* yourtheme / $template_name
* $default_path / $template_name
*
* @param mixed $template_name
* @param string $template_path (default: '')
* @param string $default_path (default: '')
* @return string
*/
function locate_job_manager_template( $template_name, $template_path = '', $default_path = '' ) {
if ( ! $template_path )
$template_path = 'job_manager';
if ( ! $default_path )
$default_path = JOB_MANAGER_PLUGIN_DIR . '/templates/';
// Look within passed path within the theme - this is priority
$template = locate_template(
array(
trailingslashit( $template_path ) . $template_name,
$template_name
)
);
// Get default template
if ( ! $template )
$template = $default_path . $template_name;
// Return what we found
return apply_filters( 'job_manager_locate_template', $template, $template_name, $template_path );
}
/**
* Get template part (for templates in loops).
*
* @param mixed $slug
* @param string $name (default: '')
* @return void
*/
function get_job_manager_template_part( $slug, $name = '', $template_path = '', $default_path = '' ) {
if ( ! $template_path )
$template_path = 'job_manager';
if ( ! $default_path )
$default_path = JOB_MANAGER_PLUGIN_DIR . '/templates/';
$template = '';
// Look in yourtheme/slug-name.php and yourtheme/job_manager/slug-name.php
if ( $name )
$template = locate_template( array ( "{$slug}-{$name}.php", "{$template_path}/{$slug}-{$name}.php" ) );
// Get default slug-name.php
if ( ! $template && $name && file_exists( $default_path . "{$slug}-{$name}.php" ) )
$template = $default_path . "{$slug}-{$name}.php";
// If template file doesn't exist, look in yourtheme/slug.php and yourtheme/job_manager/slug.php
if ( ! $template )
$template = locate_template( array( "{$slug}.php", "{$template_path}/{$slug}.php" ) );
if ( $template )
load_template( $template, false );
}
/**
* Outputs the jobs status
*
* @return void
*/
function the_job_status( $post = null ) {
echo get_the_job_status( $post );
}
/**
* Gets the jobs status
*
* @return string
*/
function get_the_job_status( $post = null ) {
$post = get_post( $post );
$status = $post->post_status;
if ( $status == 'publish' )
$status = __( 'Active', 'job_manager' );
elseif ( $status == 'expired' )
$status = __( 'Expired', 'job_manager' );
elseif ( $status == 'pending' )
$status = __( 'Pending Review', 'job_manager' );
else
$status = __( 'Inactive', 'job_manager' );
return apply_filters( 'the_job_status', $status, $post );
}
/**
* Return whether or not the position has been marked as filled
*
* @param object $post
* @return boolean
*/
function is_position_filled( $post = null ) {
$post = get_post( $post );
return $post->_filled ? true : false;
}
/**
* Return whether or not the position has been featured
*
* @param object $post
* @return boolean
*/
function is_position_featured( $post = null ) {
$post = get_post( $post );
return $post->_featured ? true : false;
}
/**
* the_job_permalink function.
*
* @access public
* @return void
*/
function the_job_permalink( $post = null ) {
echo get_the_job_permalink( $post );
}
/**
* get_the_job_permalink function.
*
* @access public
* @param mixed $post (default: null)
* @return string
*/
function get_the_job_permalink( $post = null ) {
$post = get_post( $post );
$link = get_permalink( $post );
return apply_filters( 'the_job_permalink', $link, $post );
}
/**
* get_the_job_application_method function.
*
* @access public
* @param mixed $post (default: null)
* @return object
*/
function get_the_job_application_method( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'job_listing' )
return;
$method = new stdClass();
$apply = $post->_application;
if ( empty( $apply ) )
return false;
if ( strstr( $apply, '@' ) && is_email( $apply ) ) {
$method->type = 'email';
$method->raw_email = $apply;
$method->email = antispambot( $apply );
$method->subject = 'Job Application via "' . $post->post_title . '" listing on ' . home_url();
} else {
if ( strpos( $apply, 'http' ) !== 0 )
$apply = 'http://' . $apply;
$method->type = 'url';
$method->url = $apply;
}
return apply_filters( 'the_job_application_method', $method, $post );
}
/**
* the_job_type function.
*
* @access public
* @return void
*/
function the_job_type( $post = null ) {
if ( $job_type = get_the_job_type( $post ) )
echo $job_type->name;
}
/**
* get_the_job_type function.
*
* @access public
* @param mixed $post (default: null)
* @return void
*/
function get_the_job_type( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'job_listing' )
return;
$types = wp_get_post_terms( $post->ID, 'job_listing_type' );
if ( $types )
$type = current( $types );
else
$type = false;
return apply_filters( 'the_job_type', $type, $post );
}
/**
* the_job_location function.
* @param boolean $map_link whether or not to link to the map on google maps
* @return [type]
*/
function the_job_location( $map_link = true, $post = null ) {
$location = get_the_job_location( $post );
if ( $location ) {
if ( $map_link )
echo apply_filters( 'the_job_location_map_link', '<a class="google_map_link" href="http://maps.google.com/maps?q=' . urlencode( $location ) . '&zoom=14&size=512x512&maptype=roadmap&sensor=false">' . $location . '</a>', $location, $post );
else
echo $location;
} else {
echo apply_filters( 'the_job_location_anywhere_text', __( 'Anywhere', 'job_manager' ) );
}
}
/**
* get_the_job_location function.
*
* @access public
* @param mixed $post (default: null)
* @return void
*/
function get_the_job_location( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'job_listing' )
return;
return apply_filters( 'the_job_location', $post->_job_location, $post );
}
/**
* the_company_logo function.
*
* @access public
* @param string $size (default: 'full')
* @param mixed $default (default: null)
* @return void
*/
function the_company_logo( $size = 'full', $default = null, $post = null ) {
global $job_manager;
$logo = get_the_company_logo( $post );
if ( ! empty( $logo ) && ( strstr( $logo, 'http' ) || file_exists( $logo ) ) ) {
if ( $size !== 'full' )
$logo = job_manager_get_resized_image( $logo, $size );
echo '<img src="' . $logo . '" alt="Logo" />';
} elseif ( $default )
echo '<img src="' . $default . '" alt="Logo" />';
else
echo '<img src="' . JOB_MANAGER_PLUGIN_URL . '/assets/images/company.png' . '" alt="Logo" />';
}
/**
* get_the_company_logo function.
*
* @access public
* @param mixed $post (default: null)
* @return string
*/
function get_the_company_logo( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'job_listing' )
return;
return apply_filters( 'the_company_logo', $post->_company_logo, $post );
}
/**
* Resize and get url of the image
*
* @param string $logo
* @param string $size
* @return string
*/
function job_manager_get_resized_image( $logo, $size ) {
global $_wp_additional_image_sizes;
if ( $size !== 'full' && isset( $_wp_additional_image_sizes[ $size ] ) ) {
$img_width = $_wp_additional_image_sizes[ $size ]['width'];
$img_height = $_wp_additional_image_sizes[ $size ]['height'];
$logo_path = str_replace( home_url('/'), ABSPATH, $logo );
$path_parts = pathinfo( $logo_path );
$resized_logo_path = str_replace( '.' . $path_parts['extension'], '-' . $size . '.' . $path_parts['extension'], $logo_path );
if ( ! file_exists( $resized_logo_path ) ) {
// Generate size
$image = wp_get_image_editor( $logo_path );
if ( ! is_wp_error( $image ) ) {
$image->resize( $_wp_additional_image_sizes[ $size ]['width'], $_wp_additional_image_sizes[ $size ]['height'], $_wp_additional_image_sizes[ $size ]['crop'] );
$image->save( $resized_logo_path );
$logo = dirname( $logo ) . '/' . basename( $resized_logo_path );
}
} else {
$logo = dirname( $logo ) . '/' . basename( $resized_logo_path );
}
}
return $logo;
}
/**
* Display or retrieve the current company name with optional content.
*
* @access public
* @param mixed $id (default: null)
* @return void
*/
function the_company_name( $before = '', $after = '', $echo = true, $post = null ) {
$company_name = get_the_company_name( $post );
if ( strlen( $company_name ) == 0 )
return;
$company_name = esc_attr( strip_tags( $company_name ) );
$company_name = $before . $company_name . $after;
if ( $echo )
echo $company_name;
else
return $company_name;
}
/**
* get_the_company_name function.
*
* @access public
* @param int $post (default: null)
* @return void
*/
function get_the_company_name( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'job_listing' )
return;
return apply_filters( 'the_company_name', $post->_company_name, $post );
}
/**
* get_the_company_website function.
*
* @access public
* @param int $post (default: null)
* @return void
*/
function get_the_company_website( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'job_listing' )
return;
return apply_filters( 'the_company_website', $post->_company_website, $post );
}
/**
* Display or retrieve the current company tagline with optional content.
*
* @access public
* @param mixed $id (default: null)
* @return void
*/
function the_company_tagline( $before = '', $after = '', $echo = true, $post = null ) {
$company_tagline = get_the_company_tagline( $post );
if ( strlen( $company_tagline ) == 0 )
return;
$company_tagline = esc_attr( strip_tags( $company_tagline ) );
$company_tagline = $before . $company_tagline . $after;
if ( $echo )
echo $company_tagline;
else
return $company_tagline;
}
/**
* get_the_company_tagline function.
*
* @access public
* @param int $post (default: 0)
* @return void
*/
function get_the_company_tagline( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'job_listing' )
return;
return apply_filters( 'the_company_tagline', $post->_company_tagline, $post );
}
/**
* Display or retrieve the current company twitter link with optional content.
*
* @access public
* @param mixed $id (default: null)
* @return void
*/
function the_company_twitter( $before = '', $after = '', $echo = true, $post = null ) {
$company_twitter = get_the_company_twitter( $post );
if ( strlen( $company_twitter ) == 0 )
return;
$company_twitter = esc_attr( strip_tags( $company_twitter ) );
$company_twitter = $before . '<a href="http://twitter.com/' . $company_twitter . '" class="company_twitter">' . $company_twitter . '</a>' . $after;
if ( $echo )
echo $company_twitter;
else
return $company_twitter;
}
/**
* get_the_company_twitter function.
*
* @access public
* @param int $post (default: 0)
* @return void
*/
function get_the_company_twitter( $post = null ) {
$post = get_post( $post );
if ( $post->post_type !== 'job_listing' )
return;
$company_twitter = $post->_company_twitter;
if ( strlen( $company_twitter ) == 0 )
return;
if ( strpos( $company_twitter, '@' ) === 0 )
$company_twitter = substr( $company_twitter, 1 );
return apply_filters( 'the_company_twitter', $company_twitter, $post );
}
/**
* job_listing_class function.
*
* @access public
* @param string $class (default: '')
* @param mixed $post_id (default: null)
* @return void
*/
function job_listing_class( $class = '', $post_id = null ) {
// Separates classes with a single space, collates classes for post DIV
echo 'class="' . join( ' ', get_job_listing_class( $class, $post_id ) ) . '"';
}
/**
* get_job_listing_class function.
*
* @access public
* @return array
*/
function get_job_listing_class( $class = '', $post_id = null ) {
$post = get_post( $post_id );
if ( $post->post_type !== 'job_listing' )
return array();
$classes = array();
if ( empty( $post ) )
return $classes;
$classes[] = 'job_listing';
$classes[] = 'job-type-' . sanitize_title( get_the_job_type()->name );
if ( is_position_filled( $post ) )
$classes[] = 'job_position_filled';
if ( is_position_featured( $post ) )
$classes[] = 'job_position_featured';
return get_post_class( $classes, $post->ID );
}