Advertisement
maximus87

Untitled

Sep 20th, 2023
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Workday Jobs
  4. Description: Display Workday job postings using Recruiting API v3 with a parameter for the number of jobs.
  5. Version: 1.0
  6. */
  7.  
  8. // Define your Workday Recruiting API endpoint and credentials here
  9. $api_endpoint = 'https://api.workday.com/recruiting/v3/jobPostings';
  10. $api_token = 'your_api_token_or_credentials';
  11.  
  12. // Function to fetch and display Workday job postings
  13. function display_workday_job_postings($atts) {
  14. global $api_endpoint, $api_token;
  15.  
  16. // Shortcode attributes (number of jobs to display)
  17. $atts = shortcode_atts(array(
  18. 'count' => 10, // Default number of jobs to display
  19. ), $atts);
  20.  
  21. // Initialize cURL session
  22. $ch = curl_init();
  23.  
  24. // Set cURL options
  25. curl_setopt($ch, CURLOPT_URL, $api_endpoint);
  26. curl_setopt($ch, CURLOPT_HTTPGET, true);
  27. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  28.  
  29. // Set the HTTP headers
  30. $headers = array(
  31. 'Authorization: Bearer ' . $api_token, // Use appropriate authentication method
  32. 'Content-Type: application/json', // Set the content type
  33. // Add any other headers as needed
  34. );
  35. curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  36.  
  37. // Execute the cURL request
  38. $response = curl_exec($ch);
  39.  
  40. // Check for cURL errors
  41. if (curl_errno($ch)) {
  42. echo 'Curl error: ' . curl_error($ch);
  43. }
  44.  
  45. // Close cURL session
  46. curl_close($ch);
  47.  
  48. // Process the API response
  49. if ($response !== false) {
  50. // Decode the JSON response
  51. $data = json_decode($response, true);
  52.  
  53. // Display job postings
  54. if (isset($data['jobPostings']) && is_array($data['jobPostings'])) {
  55. echo '<ul>';
  56. $count = 0;
  57. foreach ($data['jobPostings'] as $posting) {
  58. if ($count < $atts['count']) {
  59. echo '<li>' . $posting['jobPostingID'] . ': ' . $posting['jobPostingTitle'] . '</li>';
  60. $count++;
  61. } else {
  62. break;
  63. }
  64. }
  65. echo '</ul>';
  66. } else {
  67. echo 'No job postings found.';
  68. }
  69. } else {
  70. // Handle the error here
  71. echo 'Error fetching data from Workday API';
  72. }
  73. }
  74.  
  75. // Shortcode to display Workday job postings in WordPress with a count parameter
  76. function workday_job_postings_shortcode($atts) {
  77. ob_start();
  78. display_workday_job_postings($atts);
  79. return ob_get_clean();
  80. }
  81. add_shortcode('workday_job_postings', 'workday_job_postings_shortcode');
  82. ?>
  83.  
  84.  
  85. [workday_job_postings count="X"]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement