After it’s possible to load site settings into a Yoast function. I want to write a function so you only have to give a type and a key to load data (using a class) but I do not know if its exactly the right way .
I have written a function called getOrganizationData(‘@type’, ‘type’), that I want to set an array like this: $data['@type'] = $this->siteSettings->get('type');
. But with a check the record actual excists
class ChangeSeo
{
public function __construct()
{
}
public function update()
{
add_filter('wpseo_schema_organization', [$this, 'changeOrganizationData']);
}
public function changeOrganizationData($data)
{
$this->getOrganizationData('@type', 'type');
$data['@type'] = $this->siteSettings->get('type');
$data['address'] = [
'@type' => 'PostalAddress',
'addressLocality' =>
'{{ Plaats }} , {{ LAND }}',
'streetAddress' => '{{ Straat }}',
];
$data['sameAs'] = [
"https://www.facebook.com/yoast",
"https://www.linkedin.com/company/yoast-com/",
"https://en.wikipedia.org/wiki/Yoast",
"https://twitter.com/yoast",
];
return $data;
}
public function getOrganizationData($type, $key)
{
if($this->siteSettings->get($key)){
$data[$type] = $this->siteSettings->get($key);
return $data[$type];
}
return false;
}
static function singleton()
{
static $instance = null;
if ($instance === null) {
$instance = new ChangeSeo();
}
return $instance;
}
}