Created
June 18, 2024 11:42
-
-
Save Nicscott01/e1486952811442b1b0c5c0c160f5d09e to your computer and use it in GitHub Desktop.
Implementing Greenhouse Job Board on Wordpress
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
/** | |
* Greenhouse Job Board loader | |
* | |
* | |
*/ | |
class GreenhouseJobBoard { | |
/** | |
* Instance | |
*/ | |
public static $instance; | |
public $loaded; | |
public $div_id; | |
public $notice; | |
public function __construct() { | |
$this->loaded = false; | |
$this->div_id = ''; | |
add_action( 'wp', [ $this, 'greenhouse_loader' ] ); | |
add_shortcode( 'greenhouse_board', [ $this, 'greenhouse_board_sc' ] ); | |
} | |
public function greenhouse_loader() { | |
global $post; | |
//Check to see if post has shortcode | |
if ( has_shortcode( $post->post_content, 'greenhouse_board' ) ) { | |
do_shortcode( $post->post_content ); | |
$this->loaded = true; | |
} | |
} | |
public function greenhouse_board_sc( $atts, $content ) { | |
$atts = shortcode_atts( [ | |
'script_url' => '', | |
'div_id' => 'grnhse_app' | |
], $atts ); | |
if ( empty( $atts['script_url'] ) ) { | |
return ''; | |
} | |
if ( ! $this->loaded ) { | |
$this->div_id = $atts['div_id']; | |
$this->notice = wpautop( $content ); | |
wp_enqueue_script( 'greenhouse', $atts['script_url'], ['jquery', 'bootstrap'], false, true ); | |
add_filter( 'the_content', [ $this, 'greenhouse_content' ], 10, 1 ); | |
add_filter( 'entry_content_class', [ $this, 'greenhouse_classes' ], 10, 1 ); | |
// remove_shortcode( 'greenhouse_board' ); | |
} else { | |
return ''; | |
} | |
return ''; | |
} | |
function greenhouse_content( $tc ) { | |
if ( isset( $_GET['gh_jid'] ) ) { | |
$notice = ''; | |
if ( !empty( $this->notice ) ) { | |
$notice = sprintf( '<div class="container ghouse-notice small alert alert-secondary">%s</div>', $this->notice ); | |
} | |
return sprintf( '<div id="%s" class="pt-4 carrer-listing"></div>%s', $this->div_id, $notice ); | |
} else { | |
$loading = ' | |
<div class="container d-flex justify-content-center my-4"> | |
<div class="spinner-border" role="status"> | |
<span class="sr-only">Loading...</span> | |
</div> | |
<p class="ml-3">Loading job listings...</p> | |
</div>'; | |
return sprintf( '<div class="container">%s</div><div id="%s" class="pt-4">%s</div><div class="container ghouse-notice small alert alert-secondary">%s</div>', $tc, $this->div_id, $loading, $this->notice ); | |
} | |
return $tc; | |
} | |
function greenhouse_classes( $classes ) { | |
foreach( $classes as $k => $class ) { | |
if( $class == 'container' ) { | |
unset( $classes[$k] ); | |
} | |
} | |
return $classes; | |
} | |
public static function get_instance() { | |
if ( self::$instance == null ) { | |
self::$instance = new self; | |
} | |
return self::$instance; | |
} | |
} | |
GreenhouseJobBoard::get_instance(); | |
add_action( 'wp_enqueue_scripts_d', function() { | |
if ( is_page( 'careers' ) ) { | |
switch( ICL_LANGUAGE_CODE ) { | |
case "en" : | |
wp_enqueue_script( 'greenhouse', 'https://boards.greenhouse.io/embed/job_board/js?for=zenasbio', ['jquery', 'bootstrap'], false, true ); | |
case "zh-hans" : | |
wp_enqueue_script( 'greenhouse', 'https://boards.greenhouse.io/embed/job_board/js?for=zenasbiocn', ['jquery', 'bootstrap'], false, true ); | |
break; | |
} | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment