Exemple #1
0
 /**
  * Get the organization entered in the Structed data admin if any
  */
 private function getOrganization()
 {
     if (!is_null($this->Org)) {
         return $this->Org;
     }
     $options = get_option('_settingsSettingsStructuredData', true);
     if (isset($options['homepage']) && isset($options['homepage']['Organization']) && isset($options['homepage']['Organization']['legalName']) && isset($options['homepage']['Organization']['url']) && !empty($options['homepage']['Organization']['legalName']) && !empty($options['homepage']['Organization']['url'])) {
         $Org = Schema\OrganizationSchema::factory();
         $add = array('legalName', 'url', 'email', 'telephone', 'faxNumber');
         foreach ($add as $key) {
             if (!empty($options['homepage']['Organization'][$key])) {
                 $func = "set" . ucFirst($key);
                 $Org->{$func}($options['homepage']['Organization'][$key]);
                 // Name is also required in some cases, so duplicate legalName
                 if ($key === 'legalName') {
                     $Org->setName($options['homepage']['Organization'][$key]);
                 }
             }
         }
         if (intval($options['homepage']['Organization']['logo']['id']) > 0) {
             $logo = wp_get_attachment_image_src($options['homepage']['Organization']['logo']['id'], 'full');
             $Org->setLogo($logo[0]);
         }
         // Make Organization available for singular items
         $this->Org = $Org;
     } else {
         $this->Org = false;
     }
     return $this->Org;
 }
<?php

require_once dirname(__DIR__) . '/vendor/autoload.php';
use LengthOfRope\JSONLD;
use LengthOfRope\JSONLD\Schema;
$Create = JSONLD\Create::factory()->add(Schema\BookSchema::factory()->setAuthor(Schema\PersonSchema::factory()->setName("Bas de Kort")->setEmail("*****@*****.**"))->setAbout("PHP")->setName("Superb PHP Book")->setAlternateName("Book one of three"))->add(Schema\OrganizationSchema::factory()->setAddress(Schema\PostalAddressSchema::factory()->setPostalCode("1234 AA")->setStreetAddress("Somewhere 12")->setAddressCountry("NL")->setAddressLocality("Amersfoort")->setEmail("*****@*****.**")->setTelephone("033-1234567")->setAddressRegion("Utrecht"))->setName("LengthOfRope")->setDescription("Just another developer"));
//echo "<pre>";
//print_r($Create->getDataArray());
print_r($Create->getJSONLDScript());