* WordPress Pages Adder */
($site_url)
| 48 | * WordPress Pages Adder |
| 49 | */ |
| 50 | function wordpress_site_adder($site_url){ |
| 51 | |
| 52 | // Instantiate Guzzle client - WP API uses JSON. |
| 53 | $options = [ |
| 54 | 'headers' => ['Accept' => 'application/json'], |
| 55 | 'verify' => false, |
| 56 | ]; |
| 57 | $client = new Client($options); |
| 58 | |
| 59 | // The WP API JSON endpoint is always the same. |
| 60 | $wp_json_endpoint = '/wp-json/wp/v2/pages?per_page=100'; |
| 61 | $url = $site_url . $wp_json_endpoint; |
| 62 | |
| 63 | $wp_api_json = json_decode( |
| 64 | $client->get($url)->getBody(), true |
| 65 | ); |
| 66 | |
| 67 | if(empty($wp_api_json[0])) { |
| 68 | throw new Exception( |
| 69 | "$site_url does not include WordPress " . |
| 70 | "functionality that Equalify requires" |
| 71 | ); |
| 72 | } |
| 73 | |
| 74 | // Push JSON to pages array. |
| 75 | $pages = []; |
| 76 | foreach ($wp_api_json as $page): |
| 77 | array_push($pages, $page['link']); |
| 78 | endforeach; |
| 79 | |
| 80 | // We want an array with each page URL. |
| 81 | return $pages; |
| 82 | |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * XML Site Adder |
no outgoing calls
no test coverage detected