MCPcopy Create free account
hub / github.com/EqualifyEverything/equalify / wordpress_site_adder

Function wordpress_site_adder

models/adders.php:50–83  ·  view source on GitHub ↗

* WordPress Pages Adder */

($site_url)

Source from the content-addressed store, hash-verified

48 * WordPress Pages Adder
49 */
50function 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

Callers 2

add_site.phpFile · 0.85
process_sitesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected