├── Readme.md └── happyr-employer.php /Readme.md: -------------------------------------------------------------------------------- 1 | # Wordpress plugin for Happyr employers 2 | 3 | This is a small wordpress plugin for Happyr employers. See https://happyr.com/integration/doc 4 | for more information and integration documentation. 5 | 6 | Download here: [Wordpress plugin](https://github.com/Happyr/wordpress-happyr-employer/releases/download/1.0.0/happyr-employer.zip) 7 | 8 | ## Shortcodes 9 | 10 | ### Show jobs 11 | 12 | To show your latest jobs you may use the following shortcode. 13 | 14 | ``` 15 | [happyrjobs id="058c05a4-d26c-4cb5-a796-8371ba6d996e"] 16 | ``` 17 | 18 | ### Job subscription 19 | 20 | To show a link to the subscription page you may write the following. 21 | 22 | ``` 23 | Link 24 | ``` 25 | -------------------------------------------------------------------------------- /happyr-employer.php: -------------------------------------------------------------------------------- 1 | . 25 | */ 26 | 27 | /** 28 | * A small wordpress plugin for Happyr employers 29 | * 30 | * @author Tobias Nyholm 31 | */ 32 | class HappyrEmployer { 33 | 34 | /** 35 | * Get the URL for subscription. 36 | * 37 | * @param array $attributes 38 | * 39 | * @return string 40 | */ 41 | public function subscription($attributes) 42 | { 43 | $attributes = shortcode_atts(array('id' => ''), $attributes, 'happyrsubscription'); 44 | 45 | $id = $attributes['id']; 46 | if (empty($id)) { 47 | return 'You are missing company ID. See https://happyr.com/integration/doc/retrieveId'; 48 | } 49 | 50 | return 'https://happyr.com/user/spontaneous/'.$id.'/start'; 51 | } 52 | 53 | /** 54 | * Show all available jobs. You can group by 'city', 'name' and 'location_name'. 55 | * 56 | * @param array $attributes 57 | * 58 | * @return string 59 | */ 60 | public function jobs($attributes) 61 | { 62 | $attributes = shortcode_atts(array('id' => '', 'groupby'=>'city'), $attributes, 'happyrjobs'); 63 | 64 | $id = $attributes['id']; 65 | if (empty($id)) { 66 | return 'You are missing company ID. See https://happyr.com/integration/doc/retrieveId'; 67 | } 68 | 69 | $url = 'https://happyr.com/integration/v1/company/'.$id.'/adverts?_format=json'; 70 | $content = file_get_contents($url); 71 | $data = json_decode($content, true); 72 | 73 | $groupBy = $attributes['groupby']; 74 | $group = array(); 75 | 76 | switch ($groupBy) { 77 | case 'name': 78 | $link = 'location_name'; 79 | break; 80 | default: 81 | $link = 'name'; 82 | } 83 | 84 | foreach ($data as $advert) { 85 | $group[$advert[$groupBy]][] = $advert; 86 | } 87 | 88 | $content = ''; 89 | foreach ($group as $heading => $adverts) { 90 | $content.='

'.$heading.'

'; 91 | foreach ($adverts as $advert) { 92 | $content.=''.$advert[$link].' | '.$advert['address'].'
'; 93 | } 94 | } 95 | return $content; 96 | } 97 | } 98 | 99 | add_shortcode('happyrsubscription', array('HappyrEmployer', 'subscription')); 100 | add_shortcode('happyrjobs', array('HappyrEmployer', 'jobs')); 101 | --------------------------------------------------------------------------------