@@ -18,1244 +18,1244 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class Wordlift_Schema_Service { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * The 'location created' field name. |
|
| 23 | - * |
|
| 24 | - * @since 3.5.0 |
|
| 25 | - */ |
|
| 26 | - const FIELD_LOCATION_CREATED = 'wl_location_created'; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * The 'topic' field name. |
|
| 30 | - * |
|
| 31 | - * @since 3.5.0 |
|
| 32 | - */ |
|
| 33 | - const FIELD_TOPIC = 'wl_topic'; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * The 'author' field name. |
|
| 37 | - * |
|
| 38 | - * @since 3.1.0 |
|
| 39 | - */ |
|
| 40 | - const FIELD_AUTHOR = 'wl_author'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * The 'same as' field name. |
|
| 44 | - * |
|
| 45 | - * @since 3.1.0 |
|
| 46 | - */ |
|
| 47 | - const FIELD_SAME_AS = 'entity_same_as'; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * The 'date start' field name. |
|
| 51 | - * |
|
| 52 | - * @since 3.1.0 |
|
| 53 | - */ |
|
| 54 | - const FIELD_DATE_START = 'wl_cal_date_start'; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * The 'date end' field name. |
|
| 58 | - * |
|
| 59 | - * @since 3.1.0 |
|
| 60 | - */ |
|
| 61 | - const FIELD_DATE_END = 'wl_cal_date_end'; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * The 'location' field name. |
|
| 65 | - * |
|
| 66 | - * @since 3.1.0 |
|
| 67 | - */ |
|
| 68 | - const FIELD_LOCATION = 'wl_location'; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * The 'founder' field name. |
|
| 72 | - * |
|
| 73 | - * @since 3.1.0 |
|
| 74 | - */ |
|
| 75 | - const FIELD_FOUNDER = 'wl_founder'; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * The 'knows' field name. |
|
| 79 | - * |
|
| 80 | - * @since 3.1.0 |
|
| 81 | - */ |
|
| 82 | - const FIELD_KNOWS = 'wl_knows'; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * The 'birth date' field name. |
|
| 86 | - * |
|
| 87 | - * @since 3.1.0 |
|
| 88 | - */ |
|
| 89 | - const FIELD_BIRTH_DATE = 'wl_birth_date'; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * The 'birth place' field name. |
|
| 93 | - * |
|
| 94 | - * @since 3.1.0 |
|
| 95 | - */ |
|
| 96 | - const FIELD_BIRTH_PLACE = 'wl_birth_place'; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * The 'latitude' field name. |
|
| 100 | - * |
|
| 101 | - * @since 3.1.0 |
|
| 102 | - */ |
|
| 103 | - const FIELD_GEO_LATITUDE = 'wl_geo_latitude'; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * The 'longitude' field name. |
|
| 107 | - * |
|
| 108 | - * @since 3.1.0 |
|
| 109 | - */ |
|
| 110 | - const FIELD_GEO_LONGITUDE = 'wl_geo_longitude'; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * The 'streetAddress' field name. |
|
| 114 | - * |
|
| 115 | - * @since 3.1.0 |
|
| 116 | - */ |
|
| 117 | - const FIELD_ADDRESS = 'wl_address'; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * The 'postOfficeBoxNumber' field name. |
|
| 121 | - * |
|
| 122 | - * @since 3.3.0 |
|
| 123 | - */ |
|
| 124 | - const FIELD_ADDRESS_PO_BOX = 'wl_address_post_office_box'; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * The 'postalCode' field name. |
|
| 128 | - * |
|
| 129 | - * @since 3.3.0 |
|
| 130 | - */ |
|
| 131 | - const FIELD_ADDRESS_POSTAL_CODE = 'wl_address_postal_code'; |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * The 'addressLocality' field name. |
|
| 135 | - * |
|
| 136 | - * @since 3.3.0 |
|
| 137 | - */ |
|
| 138 | - const FIELD_ADDRESS_LOCALITY = 'wl_address_locality'; |
|
| 139 | - /** |
|
| 140 | - * The 'addressRegion' field name. |
|
| 141 | - * |
|
| 142 | - * @since 3.3.0 |
|
| 143 | - */ |
|
| 144 | - const FIELD_ADDRESS_REGION = 'wl_address_region'; |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * The 'addressCountry' field name. |
|
| 148 | - * |
|
| 149 | - * @since 3.3.0 |
|
| 150 | - */ |
|
| 151 | - const FIELD_ADDRESS_COUNTRY = 'wl_address_country'; |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * The 'entity type' field name. |
|
| 155 | - * |
|
| 156 | - * @since 3.1.0 |
|
| 157 | - */ |
|
| 158 | - const FIELD_ENTITY_TYPE = 'wl_entity_type_uri'; |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * The 'email' field name. |
|
| 162 | - * |
|
| 163 | - * @since 3.2.0 |
|
| 164 | - */ |
|
| 165 | - const FIELD_EMAIL = 'wl_email'; |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * The 'affiliation' field name. |
|
| 169 | - * |
|
| 170 | - * @since 3.2.0 |
|
| 171 | - */ |
|
| 172 | - const FIELD_AFFILIATION = 'wl_affiliation'; |
|
| 173 | - |
|
| 174 | - /** |
|
| 175 | - * The 'telephone' field name. |
|
| 176 | - * |
|
| 177 | - * @since 3.8.0 |
|
| 178 | - */ |
|
| 179 | - const FIELD_TELEPHONE = 'wl_schema_telephone'; |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * The 'legalName' field name. |
|
| 183 | - * |
|
| 184 | - * @since 3.12.0 |
|
| 185 | - */ |
|
| 186 | - const FIELD_LEGAL_NAME = 'wl_schema_legal_name'; |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * The 'recipeCuisine' field name. |
|
| 190 | - * |
|
| 191 | - * @since 3.14.0 |
|
| 192 | - */ |
|
| 193 | - const FIELD_RECIPE_CUISINE = 'wl_schema_recipe_cuisine'; |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * The 'recipeIngredient' field name. |
|
| 197 | - * |
|
| 198 | - * @since 3.14.0 |
|
| 199 | - */ |
|
| 200 | - const FIELD_RECIPE_INGREDIENT = 'wl_schema_recipe_ingredient'; |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * The 'calories' field name. |
|
| 204 | - * |
|
| 205 | - * @since 3.14.0 |
|
| 206 | - */ |
|
| 207 | - const FIELD_NUTRITION_INFO_CALORIES = 'wl_schema_nutrition_information_calories'; |
|
| 208 | - |
|
| 209 | - /** |
|
| 210 | - * The 'recipeInstructions' field name. |
|
| 211 | - * |
|
| 212 | - * @since 3.14.0 |
|
| 213 | - */ |
|
| 214 | - const FIELD_RECIPE_INSTRUCTIONS = 'wl_schema_recipe_instructions'; |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * The 'recipeYield' field name. |
|
| 218 | - * |
|
| 219 | - * @since 3.14.0 |
|
| 220 | - */ |
|
| 221 | - const FIELD_RECIPE_YIELD = 'wl_schema_recipe_yield'; |
|
| 222 | - |
|
| 223 | - /** |
|
| 224 | - * The 'prepTime' field name. |
|
| 225 | - * |
|
| 226 | - * @since 3.14.0 |
|
| 227 | - */ |
|
| 228 | - const FIELD_PREP_TIME = 'wl_schema_prep_time'; |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * The 'cookTime' field name. |
|
| 232 | - * |
|
| 233 | - * @since 3.14.0 |
|
| 234 | - */ |
|
| 235 | - const FIELD_COOK_TIME = 'wl_schema_cook_time'; |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * The 'totalTime' field name. |
|
| 239 | - * |
|
| 240 | - * @since 3.14.0 |
|
| 241 | - */ |
|
| 242 | - const FIELD_TOTAL_TIME = 'wl_schema_total_time'; |
|
| 243 | - |
|
| 244 | - /** |
|
| 245 | - * The 'performer' field name. |
|
| 246 | - * |
|
| 247 | - * @since 3.18.0 |
|
| 248 | - */ |
|
| 249 | - const FIELD_PERFORMER = 'wl_schema_performer'; |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * The 'offers' field name. |
|
| 253 | - * |
|
| 254 | - * @since 3.18.0 |
|
| 255 | - */ |
|
| 256 | - const FIELD_OFFERS = 'wl_schema_offers'; |
|
| 257 | - |
|
| 258 | - /** |
|
| 259 | - * The 'availablity' field name. |
|
| 260 | - * |
|
| 261 | - * @since 3.18.0 |
|
| 262 | - */ |
|
| 263 | - const FIELD_AVAILABILITY = 'wl_schema_availability'; |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * The 'inventoryLevel' field name. |
|
| 267 | - * |
|
| 268 | - * @since 3.18.0 |
|
| 269 | - */ |
|
| 270 | - const FIELD_INVENTORY_LEVEL = 'wl_schema_inventory_level'; |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * The 'price' field name. |
|
| 274 | - * |
|
| 275 | - * @since 3.18.0 |
|
| 276 | - */ |
|
| 277 | - const FIELD_PRICE = 'wl_schema_price'; |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * The 'priceCurrency' field name. |
|
| 281 | - * |
|
| 282 | - * @since 3.18.0 |
|
| 283 | - */ |
|
| 284 | - const FIELD_PRICE_CURRENCY = 'wl_schema_price_currency'; |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * The 'availabilityStarts' field name. |
|
| 288 | - * |
|
| 289 | - * @since 3.18.0 |
|
| 290 | - */ |
|
| 291 | - const FIELD_AVAILABILITY_STARTS = 'wl_schema_availability_starts'; |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * The 'availabilityEnds' field name. |
|
| 295 | - * |
|
| 296 | - * @since 3.18.0 |
|
| 297 | - */ |
|
| 298 | - const FIELD_AVAILABILITY_ENDS = 'wl_schema_availability_ends'; |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * The 'validFrom' field name. |
|
| 302 | - * |
|
| 303 | - * @since 3.18.0 |
|
| 304 | - */ |
|
| 305 | - const FIELD_VALID_FROM = 'wl_schema_valid_from'; |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * The 'priceValidUntil' field name. |
|
| 309 | - * |
|
| 310 | - * @since 3.18.0 |
|
| 311 | - */ |
|
| 312 | - const FIELD_PRICE_VALID_UNTIL = 'wl_schema_valid_until'; |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * The 'itemOffered' field name. |
|
| 316 | - * |
|
| 317 | - * @since 3.18.0 |
|
| 318 | - */ |
|
| 319 | - const FIELD_ITEM_OFFERED = 'wl_schema_item_offered'; |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * The 'URI' data type name. |
|
| 323 | - * |
|
| 324 | - * @since 3.1.0 |
|
| 325 | - */ |
|
| 326 | - const DATA_TYPE_URI = 'uri'; |
|
| 327 | - |
|
| 328 | - /** |
|
| 329 | - * The 'date' data type name. |
|
| 330 | - * |
|
| 331 | - * @since 3.1.0 |
|
| 332 | - */ |
|
| 333 | - const DATA_TYPE_DATE = 'date'; |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * The 'time' data type name. |
|
| 337 | - * |
|
| 338 | - * @since 3.14.0 |
|
| 339 | - */ |
|
| 340 | - const DATA_TYPE_DURATION = 'duration'; |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * The 'double' data type name. |
|
| 344 | - * |
|
| 345 | - * @since 3.1.0 |
|
| 346 | - */ |
|
| 347 | - const DATA_TYPE_DOUBLE = 'double'; |
|
| 348 | - |
|
| 349 | - /** |
|
| 350 | - * The 'string' data type name. |
|
| 351 | - * |
|
| 352 | - * @since 3.1.0 |
|
| 353 | - */ |
|
| 354 | - const DATA_TYPE_STRING = 'string'; |
|
| 355 | - |
|
| 356 | - /** |
|
| 357 | - * The multiline text data type name. |
|
| 358 | - * |
|
| 359 | - * @since 3.14.0 |
|
| 360 | - */ |
|
| 361 | - const DATA_TYPE_MULTILINE = 'multiline'; |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * The schema.org Event type URI. |
|
| 365 | - * |
|
| 366 | - * @since 3.1.0 |
|
| 367 | - */ |
|
| 368 | - const SCHEMA_EVENT_TYPE = 'http://schema.org/Event'; |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * The schema.org Offer type URI. |
|
| 372 | - * |
|
| 373 | - * @since 3.18.0 |
|
| 374 | - */ |
|
| 375 | - const SCHEMA_OFFER_TYPE = 'http://schema.org/Offer'; |
|
| 376 | - |
|
| 377 | - /** |
|
| 378 | - * WordLift's schema. |
|
| 379 | - * |
|
| 380 | - * @since 3.1.0 |
|
| 381 | - * @access private |
|
| 382 | - * @var array $schema WordLift's schema. |
|
| 383 | - */ |
|
| 384 | - private $schema; |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * The Log service. |
|
| 388 | - * |
|
| 389 | - * @since 3.1.0 |
|
| 390 | - * @access private |
|
| 391 | - * @var \Wordlift_Log_Service $log The Log service. |
|
| 392 | - */ |
|
| 393 | - private $log; |
|
| 394 | - |
|
| 395 | - /** |
|
| 396 | - * Wordlift_Schema_Service constructor. |
|
| 397 | - * |
|
| 398 | - * @since 3.1.0 |
|
| 399 | - */ |
|
| 400 | - protected function __construct() { |
|
| 401 | - |
|
| 402 | - $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' ); |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Alter the configured schemas. |
|
| 406 | - * |
|
| 407 | - * Enable 3rd parties to alter WordLift's schemas array. |
|
| 408 | - * |
|
| 409 | - * @param array $schemas The array of schemas. |
|
| 410 | - * |
|
| 411 | - * @since 3.19.1 |
|
| 412 | - */ |
|
| 413 | - $this->schema = apply_filters( |
|
| 414 | - 'wl_schemas', |
|
| 415 | - array( |
|
| 416 | - 'article' => $this->get_article_schema(), |
|
| 417 | - 'thing' => $this->get_thing_schema(), |
|
| 418 | - 'creative-work' => $this->get_creative_work_schema(), |
|
| 419 | - 'event' => $this->get_event_schema(), |
|
| 420 | - 'organization' => $this->get_organization_schema(), |
|
| 421 | - 'person' => $this->get_person_schema(), |
|
| 422 | - 'place' => $this->get_place_schema(), |
|
| 423 | - 'local-business' => $this->get_local_business_schema(), |
|
| 424 | - 'recipe' => $this->get_recipe_schema(), |
|
| 425 | - 'web-page' => $this->get_web_page_schema(), |
|
| 426 | - 'offer' => $this->get_offer_schema(), |
|
| 427 | - ) |
|
| 428 | - ); |
|
| 429 | - |
|
| 430 | - // Create a singleton instance of the Schema service, useful to provide static functions to global functions. |
|
| 431 | - self::$instance = $this; |
|
| 432 | - |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - public function get_all_schema_slugs() { |
|
| 436 | - return array_keys( $this->schema ); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - /** |
|
| 440 | - * The Schema service singleton instance. |
|
| 441 | - * |
|
| 442 | - * @since 3.1.0 |
|
| 443 | - * @access private |
|
| 444 | - * @var Wordlift_Schema_Service $instance The Schema service singleton instance. |
|
| 445 | - */ |
|
| 446 | - private static $instance = null; |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * Get a reference to the Schema service. |
|
| 450 | - * |
|
| 451 | - * @return Wordlift_Schema_Service A reference to the Schema service. |
|
| 452 | - * @since 3.1.0 |
|
| 453 | - */ |
|
| 454 | - public static function get_instance() { |
|
| 455 | - if ( ! isset( self::$instance ) ) { |
|
| 456 | - self::$instance = new self(); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - return self::$instance; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - /** |
|
| 463 | - * Get the properties for a field with the specified key. The key is used as |
|
| 464 | - * meta key when the field's value is stored in WordPress meta data table. |
|
| 465 | - * |
|
| 466 | - * @param string $key The field's key. |
|
| 467 | - * |
|
| 468 | - * @return null|array An array of field's properties or null if the field is not found. |
|
| 469 | - * @since 3.6.0 |
|
| 470 | - */ |
|
| 471 | - public function get_field( $key ) { |
|
| 472 | - |
|
| 473 | - // Parse each schema's fields until we find the one we're looking for, then |
|
| 474 | - // return its properties. |
|
| 475 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
| 476 | - foreach ( $this->schema as $_ => $schema ) { |
|
| 477 | - |
|
| 478 | - if ( ! isset( $schema['custom_fields'] ) ) { |
|
| 479 | - break; |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - foreach ( $schema['custom_fields'] as $field => $props ) { |
|
| 483 | - if ( $key === $field ) { |
|
| 484 | - return $props; |
|
| 485 | - } |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - return null; |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * Get the WordLift's schema. |
|
| 494 | - * |
|
| 495 | - * @param string $name The schema name. |
|
| 496 | - * |
|
| 497 | - * @return array|null An array with the schema configuration or NULL if the schema is not found. |
|
| 498 | - * |
|
| 499 | - * @since 3.1.0 |
|
| 500 | - */ |
|
| 501 | - public function get_schema( $name ) { |
|
| 502 | - // Check if the schema exists and, if not, return NULL. |
|
| 503 | - if ( ! isset( $this->schema[ $name ] ) ) { |
|
| 504 | - return null; |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - // Return the requested schema. |
|
| 508 | - return $this->schema[ $name ]; |
|
| 509 | - } |
|
| 510 | - |
|
| 511 | - /** |
|
| 512 | - * Get the WordLift's schema trough schema type uri. |
|
| 513 | - * |
|
| 514 | - * @param string $uri The schema uri. |
|
| 515 | - * |
|
| 516 | - * @return array|null An array with the schema configuration or NULL if the schema is not found. |
|
| 517 | - * |
|
| 518 | - * @since 3.3.0 |
|
| 519 | - */ |
|
| 520 | - public function get_schema_by_uri( $uri ) { |
|
| 521 | - |
|
| 522 | - // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
| 523 | - foreach ( $this->schema as $name => $schema ) { |
|
| 524 | - if ( $schema['uri'] === $uri ) { |
|
| 525 | - return $schema; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - return null; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * Get the 'thing' schema. |
|
| 534 | - * |
|
| 535 | - * @return array An array with the schema configuration. |
|
| 536 | - * |
|
| 537 | - * @since 3.1.0 |
|
| 538 | - */ |
|
| 539 | - private function get_thing_schema() { |
|
| 540 | - |
|
| 541 | - return array( |
|
| 542 | - 'css_class' => 'wl-thing', |
|
| 543 | - 'uri' => 'http://schema.org/Thing', |
|
| 544 | - 'same_as' => array( '*' ), |
|
| 545 | - // set as default. |
|
| 546 | - 'custom_fields' => array( |
|
| 547 | - self::FIELD_SAME_AS => array( |
|
| 548 | - 'predicate' => 'http://schema.org/sameAs', |
|
| 549 | - 'type' => self::DATA_TYPE_URI, |
|
| 550 | - 'export_type' => 'http://schema.org/Thing', |
|
| 551 | - 'constraints' => array( |
|
| 552 | - 'cardinality' => INF, |
|
| 553 | - ), |
|
| 554 | - // We need a custom metabox. |
|
| 555 | - 'input_field' => 'sameas', |
|
| 556 | - ), |
|
| 557 | - // Add the schema:url property. |
|
| 558 | - Wordlift_Schema_Url_Property_Service::META_KEY => Wordlift_Schema_Url_Property_Service::get_instance() |
|
| 559 | - ->get_compat_definition(), |
|
| 560 | - ), |
|
| 561 | - // {{sameAs}} not present in the microdata template, |
|
| 562 | - // because it is treated separately in *wl_content_embed_item_microdata* |
|
| 563 | - 'templates' => array( |
|
| 564 | - 'subtitle' => '{{id}}', |
|
| 565 | - ), |
|
| 566 | - ); |
|
| 567 | - |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - /** |
|
| 571 | - * Get the 'web-page' schema. |
|
| 572 | - * |
|
| 573 | - * @return array An array with the schema configuration. |
|
| 574 | - * |
|
| 575 | - * @since 3.18.0 |
|
| 576 | - */ |
|
| 577 | - private function get_web_page_schema() { |
|
| 578 | - |
|
| 579 | - return array( |
|
| 580 | - 'css_class' => 'wl-webpage', |
|
| 581 | - 'uri' => 'http://schema.org/WebPage', |
|
| 582 | - ); |
|
| 583 | - |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - /** |
|
| 587 | - * Get the 'creative work' schema. |
|
| 588 | - * |
|
| 589 | - * @return array An array with the schema configuration. |
|
| 590 | - * |
|
| 591 | - * @since 3.1.0 |
|
| 592 | - */ |
|
| 593 | - private function get_creative_work_schema() { |
|
| 594 | - |
|
| 595 | - $schema = array( |
|
| 596 | - 'label' => 'CreativeWork', |
|
| 597 | - 'description' => 'A creative work (or a Music Album).', |
|
| 598 | - 'parents' => array( 'thing' ), |
|
| 599 | - // Give term slug as parent. |
|
| 600 | - 'css_class' => 'wl-creative-work', |
|
| 601 | - 'uri' => 'http://schema.org/CreativeWork', |
|
| 602 | - 'same_as' => array( |
|
| 603 | - 'http://schema.org/MusicAlbum', |
|
| 604 | - 'http://schema.org/Product', |
|
| 605 | - ), |
|
| 606 | - 'custom_fields' => array( |
|
| 607 | - self::FIELD_AUTHOR => array( |
|
| 608 | - 'predicate' => 'http://schema.org/author', |
|
| 609 | - 'type' => self::DATA_TYPE_URI, |
|
| 610 | - 'export_type' => 'http://schema.org/Person', |
|
| 611 | - 'constraints' => array( |
|
| 612 | - 'uri_type' => array( 'Person', 'Organization' ), |
|
| 613 | - 'cardinality' => INF, |
|
| 614 | - ), |
|
| 615 | - ), |
|
| 616 | - ), |
|
| 617 | - 'templates' => array( |
|
| 618 | - 'subtitle' => '{{id}}', |
|
| 619 | - ), |
|
| 620 | - ); |
|
| 621 | - |
|
| 622 | - // Merge the custom fields with those provided by the thing schema. |
|
| 623 | - $parent_schema = $this->get_thing_schema(); |
|
| 624 | - $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] ); |
|
| 625 | - |
|
| 626 | - return $schema; |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - /** |
|
| 630 | - * Get the 'event' schema. |
|
| 631 | - * |
|
| 632 | - * @return array An array with the schema configuration. |
|
| 633 | - * |
|
| 634 | - * @since 3.1.0 |
|
| 635 | - */ |
|
| 636 | - private function get_event_schema() { |
|
| 637 | - |
|
| 638 | - $schema = array( |
|
| 639 | - 'label' => 'Event', |
|
| 640 | - 'description' => 'An event . ', |
|
| 641 | - 'parents' => array( 'thing' ), |
|
| 642 | - 'css_class' => 'wl-event', |
|
| 643 | - 'uri' => self::SCHEMA_EVENT_TYPE, |
|
| 644 | - 'same_as' => array( 'http://dbpedia.org/ontology/Event' ), |
|
| 645 | - 'custom_fields' => array( |
|
| 646 | - self::FIELD_DATE_START => array( |
|
| 647 | - 'predicate' => 'http://schema.org/startDate', |
|
| 648 | - 'type' => self::DATA_TYPE_DATE, |
|
| 649 | - 'export_type' => 'xsd:dateTime', |
|
| 650 | - 'constraints' => '', |
|
| 651 | - ), |
|
| 652 | - self::FIELD_DATE_END => array( |
|
| 653 | - 'predicate' => 'http://schema.org/endDate', |
|
| 654 | - 'type' => self::DATA_TYPE_DATE, |
|
| 655 | - 'export_type' => 'xsd:dateTime', |
|
| 656 | - 'constraints' => '', |
|
| 657 | - ), |
|
| 658 | - self::FIELD_LOCATION => array( |
|
| 659 | - 'predicate' => 'http://schema.org/location', |
|
| 660 | - 'type' => self::DATA_TYPE_URI, |
|
| 661 | - 'export_type' => 'http://schema.org/PostalAddress', |
|
| 662 | - 'constraints' => array( |
|
| 663 | - 'uri_type' => array( 'Place', 'LocalBusiness' ), |
|
| 664 | - 'cardinality' => INF, |
|
| 665 | - ), |
|
| 666 | - ), |
|
| 667 | - self::FIELD_PERFORMER => array( |
|
| 668 | - 'predicate' => 'http://schema.org/performer', |
|
| 669 | - 'type' => self::DATA_TYPE_URI, |
|
| 670 | - 'export_type' => 'http://schema.org/Person', |
|
| 671 | - 'constraints' => array( |
|
| 672 | - 'uri_type' => array( 'Person', 'Organization' ), |
|
| 673 | - 'cardinality' => INF, |
|
| 674 | - ), |
|
| 675 | - ), |
|
| 676 | - self::FIELD_OFFERS => array( |
|
| 677 | - 'predicate' => 'http://schema.org/offers', |
|
| 678 | - 'type' => self::DATA_TYPE_URI, |
|
| 679 | - 'export_type' => 'http://schema.org/Offer', |
|
| 680 | - 'constraints' => array( |
|
| 681 | - 'uri_type' => array( 'Offer' ), |
|
| 682 | - 'cardinality' => INF, |
|
| 683 | - ), |
|
| 684 | - ), |
|
| 685 | - ), |
|
| 686 | - 'templates' => array( |
|
| 687 | - 'subtitle' => '{{id}}', |
|
| 688 | - ), |
|
| 689 | - ); |
|
| 690 | - |
|
| 691 | - // Merge the custom fields with those provided by the thing schema. |
|
| 692 | - $parent_schema = $this->get_thing_schema(); |
|
| 693 | - $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] ); |
|
| 694 | - |
|
| 695 | - return $schema; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * Get the 'organization' schema. |
|
| 700 | - * |
|
| 701 | - * @return array An array with the schema configuration. |
|
| 702 | - * |
|
| 703 | - * @since 3.1.0 |
|
| 704 | - */ |
|
| 705 | - private function get_organization_schema() { |
|
| 706 | - |
|
| 707 | - $schema = array( |
|
| 708 | - 'label' => 'Organization', |
|
| 709 | - 'description' => 'An organization, including a government or a newspaper.', |
|
| 710 | - 'parents' => array( 'thing' ), |
|
| 711 | - 'css_class' => 'wl-organization', |
|
| 712 | - 'uri' => 'http://schema.org/Organization', |
|
| 713 | - 'same_as' => array( |
|
| 714 | - 'http://rdf.freebase.com/ns/organization.organization', |
|
| 715 | - 'http://rdf.freebase.com/ns/government.government', |
|
| 716 | - 'http://schema.org/Newspaper', |
|
| 717 | - ), |
|
| 718 | - 'custom_fields' => array( |
|
| 719 | - self::FIELD_LEGAL_NAME => array( |
|
| 720 | - 'predicate' => 'http://schema.org/legalName', |
|
| 721 | - 'type' => self::DATA_TYPE_STRING, |
|
| 722 | - 'export_type' => 'xsd:string', |
|
| 723 | - 'constraints' => '', |
|
| 724 | - ), |
|
| 725 | - self::FIELD_FOUNDER => array( |
|
| 726 | - 'predicate' => 'http://schema.org/founder', |
|
| 727 | - 'type' => self::DATA_TYPE_URI, |
|
| 728 | - 'export_type' => 'http://schema.org/Person', |
|
| 729 | - 'constraints' => array( |
|
| 730 | - 'uri_type' => 'Person', |
|
| 731 | - 'cardinality' => INF, |
|
| 732 | - ), |
|
| 733 | - ), |
|
| 734 | - self::FIELD_ADDRESS => array( |
|
| 735 | - 'predicate' => 'http://schema.org/streetAddress', |
|
| 736 | - 'type' => self::DATA_TYPE_STRING, |
|
| 737 | - 'export_type' => 'xsd:string', |
|
| 738 | - 'constraints' => '', |
|
| 739 | - // To build custom metabox. |
|
| 740 | - 'input_field' => 'address', |
|
| 741 | - ), |
|
| 742 | - self::FIELD_ADDRESS_PO_BOX => array( |
|
| 743 | - 'predicate' => 'http://schema.org/postOfficeBoxNumber', |
|
| 744 | - 'type' => self::DATA_TYPE_STRING, |
|
| 745 | - 'export_type' => 'xsd:string', |
|
| 746 | - 'constraints' => '', |
|
| 747 | - // To build custom metabox. |
|
| 748 | - 'input_field' => 'address', |
|
| 749 | - ), |
|
| 750 | - self::FIELD_ADDRESS_POSTAL_CODE => array( |
|
| 751 | - 'predicate' => 'http://schema.org/postalCode', |
|
| 752 | - 'type' => self::DATA_TYPE_STRING, |
|
| 753 | - 'export_type' => 'xsd:string', |
|
| 754 | - 'constraints' => '', |
|
| 755 | - // To build custom metabox. |
|
| 756 | - 'input_field' => 'address', |
|
| 757 | - ), |
|
| 758 | - self::FIELD_ADDRESS_LOCALITY => array( |
|
| 759 | - 'predicate' => 'http://schema.org/addressLocality', |
|
| 760 | - 'type' => self::DATA_TYPE_STRING, |
|
| 761 | - 'export_type' => 'xsd:string', |
|
| 762 | - 'constraints' => '', |
|
| 763 | - // To build custom metabox. |
|
| 764 | - 'input_field' => 'address', |
|
| 765 | - ), |
|
| 766 | - self::FIELD_ADDRESS_REGION => array( |
|
| 767 | - 'predicate' => 'http://schema.org/addressRegion', |
|
| 768 | - 'type' => self::DATA_TYPE_STRING, |
|
| 769 | - 'export_type' => 'xsd:string', |
|
| 770 | - 'constraints' => '', |
|
| 771 | - // To build custom metabox. |
|
| 772 | - 'input_field' => 'address', |
|
| 773 | - ), |
|
| 774 | - self::FIELD_ADDRESS_COUNTRY => array( |
|
| 775 | - 'predicate' => 'http://schema.org/addressCountry', |
|
| 776 | - 'type' => self::DATA_TYPE_STRING, |
|
| 777 | - 'export_type' => 'xsd:string', |
|
| 778 | - 'constraints' => '', |
|
| 779 | - // To build custom metabox. |
|
| 780 | - 'input_field' => 'address', |
|
| 781 | - ), |
|
| 782 | - self::FIELD_EMAIL => array( |
|
| 783 | - 'predicate' => 'http://schema.org/email', |
|
| 784 | - 'type' => self::DATA_TYPE_STRING, |
|
| 785 | - 'export_type' => 'xsd:string', |
|
| 786 | - 'constraints' => '', |
|
| 787 | - ), |
|
| 788 | - self::FIELD_TELEPHONE => array( |
|
| 789 | - 'predicate' => 'http://schema.org/telephone', |
|
| 790 | - 'type' => self::DATA_TYPE_STRING, |
|
| 791 | - 'export_type' => 'xsd:string', |
|
| 792 | - 'constraints' => '', |
|
| 793 | - ), |
|
| 794 | - ), |
|
| 795 | - 'templates' => array( |
|
| 796 | - 'subtitle' => '{{id}}', |
|
| 797 | - ), |
|
| 798 | - ); |
|
| 799 | - |
|
| 800 | - // Merge the custom fields with those provided by the thing schema. |
|
| 801 | - $parent_schema = $this->get_thing_schema(); |
|
| 802 | - $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] ); |
|
| 803 | - |
|
| 804 | - return $schema; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - /** |
|
| 808 | - * Get the 'person' schema. |
|
| 809 | - * |
|
| 810 | - * @return array An array with the schema configuration. |
|
| 811 | - * |
|
| 812 | - * @since 3.1.0 |
|
| 813 | - */ |
|
| 814 | - private function get_person_schema() { |
|
| 815 | - |
|
| 816 | - $schema = array( |
|
| 817 | - 'label' => 'Person', |
|
| 818 | - 'description' => 'A person (or a music artist).', |
|
| 819 | - 'parents' => array( 'thing' ), |
|
| 820 | - 'css_class' => 'wl-person', |
|
| 821 | - 'uri' => 'http://schema.org/Person', |
|
| 822 | - 'same_as' => array( |
|
| 823 | - 'http://rdf.freebase.com/ns/people.person', |
|
| 824 | - 'http://rdf.freebase.com/ns/music.artist', |
|
| 825 | - 'http://dbpedia.org/class/yago/LivingPeople', |
|
| 826 | - ), |
|
| 827 | - 'custom_fields' => array( |
|
| 828 | - self::FIELD_KNOWS => array( |
|
| 829 | - 'predicate' => 'http://schema.org/knows', |
|
| 830 | - 'type' => self::DATA_TYPE_URI, |
|
| 831 | - 'export_type' => 'http://schema.org/Person', |
|
| 832 | - 'constraints' => array( |
|
| 833 | - 'uri_type' => 'Person', |
|
| 834 | - 'cardinality' => INF, |
|
| 835 | - ), |
|
| 836 | - ), |
|
| 837 | - self::FIELD_BIRTH_DATE => array( |
|
| 838 | - 'predicate' => 'http://schema.org/birthDate', |
|
| 839 | - 'type' => self::DATA_TYPE_DATE, |
|
| 840 | - 'export_type' => 'xsd:date', |
|
| 841 | - 'constraints' => '', |
|
| 842 | - ), |
|
| 843 | - self::FIELD_BIRTH_PLACE => array( |
|
| 844 | - 'predicate' => 'http://schema.org/birthPlace', |
|
| 845 | - 'type' => self::DATA_TYPE_URI, |
|
| 846 | - 'export_type' => 'http://schema.org/Place', |
|
| 847 | - 'constraints' => array( |
|
| 848 | - 'uri_type' => 'Place', |
|
| 849 | - ), |
|
| 850 | - ), |
|
| 851 | - self::FIELD_AFFILIATION => array( |
|
| 852 | - 'predicate' => 'http://schema.org/affiliation', |
|
| 853 | - 'type' => self::DATA_TYPE_URI, |
|
| 854 | - 'export_type' => 'http://schema.org/Organization', |
|
| 855 | - 'constraints' => array( |
|
| 856 | - 'uri_type' => array( |
|
| 857 | - 'Organization', |
|
| 858 | - 'LocalBusiness', |
|
| 859 | - ), |
|
| 860 | - 'cardinality' => INF, |
|
| 861 | - ), |
|
| 862 | - ), |
|
| 863 | - self::FIELD_EMAIL => array( |
|
| 864 | - 'predicate' => 'http://schema.org/email', |
|
| 865 | - 'type' => self::DATA_TYPE_STRING, |
|
| 866 | - 'export_type' => 'xsd:string', |
|
| 867 | - 'constraints' => array( |
|
| 868 | - 'cardinality' => INF, |
|
| 869 | - ), |
|
| 870 | - ), |
|
| 871 | - ), |
|
| 872 | - 'templates' => array( |
|
| 873 | - 'subtitle' => '{{id}}', |
|
| 874 | - ), |
|
| 875 | - ); |
|
| 876 | - |
|
| 877 | - // Merge the custom fields with those provided by the thing schema. |
|
| 878 | - $parent_schema = $this->get_thing_schema(); |
|
| 879 | - $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] ); |
|
| 880 | - |
|
| 881 | - return $schema; |
|
| 882 | - |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - /** |
|
| 886 | - * Get the 'place' schema. |
|
| 887 | - * |
|
| 888 | - * @return array An array with the schema configuration. |
|
| 889 | - * |
|
| 890 | - * @since 3.1.0 |
|
| 891 | - */ |
|
| 892 | - private function get_place_schema() { |
|
| 893 | - |
|
| 894 | - $schema = array( |
|
| 895 | - 'label' => 'Place', |
|
| 896 | - 'description' => 'A place.', |
|
| 897 | - 'parents' => array( 'thing' ), |
|
| 898 | - 'css_class' => 'wl-place', |
|
| 899 | - 'uri' => 'http://schema.org/Place', |
|
| 900 | - 'same_as' => array( |
|
| 901 | - 'http://rdf.freebase.com/ns/location.location', |
|
| 902 | - 'http://www.opengis.net/gml/_Feature', |
|
| 903 | - ), |
|
| 904 | - 'custom_fields' => array( |
|
| 905 | - self::FIELD_GEO_LATITUDE => array( |
|
| 906 | - 'predicate' => 'http://schema.org/latitude', |
|
| 907 | - 'type' => self::DATA_TYPE_DOUBLE, |
|
| 908 | - 'export_type' => 'xsd:double', |
|
| 909 | - 'constraints' => '', |
|
| 910 | - // To build custom metabox. |
|
| 911 | - 'input_field' => 'coordinates', |
|
| 912 | - ), |
|
| 913 | - self::FIELD_GEO_LONGITUDE => array( |
|
| 914 | - 'predicate' => 'http://schema.org/longitude', |
|
| 915 | - 'type' => self::DATA_TYPE_DOUBLE, |
|
| 916 | - 'export_type' => 'xsd:double', |
|
| 917 | - 'constraints' => '', |
|
| 918 | - // To build custom metabox. |
|
| 919 | - 'input_field' => 'coordinates', |
|
| 920 | - ), |
|
| 921 | - self::FIELD_ADDRESS => array( |
|
| 922 | - 'predicate' => 'http://schema.org/streetAddress', |
|
| 923 | - 'type' => self::DATA_TYPE_STRING, |
|
| 924 | - 'export_type' => 'xsd:string', |
|
| 925 | - 'constraints' => '', |
|
| 926 | - // To build custom metabox. |
|
| 927 | - 'input_field' => 'address', |
|
| 928 | - ), |
|
| 929 | - self::FIELD_ADDRESS_PO_BOX => array( |
|
| 930 | - 'predicate' => 'http://schema.org/postOfficeBoxNumber', |
|
| 931 | - 'type' => self::DATA_TYPE_STRING, |
|
| 932 | - 'export_type' => 'xsd:string', |
|
| 933 | - 'constraints' => '', |
|
| 934 | - // To build custom metabox. |
|
| 935 | - 'input_field' => 'address', |
|
| 936 | - ), |
|
| 937 | - self::FIELD_ADDRESS_POSTAL_CODE => array( |
|
| 938 | - 'predicate' => 'http://schema.org/postalCode', |
|
| 939 | - 'type' => self::DATA_TYPE_STRING, |
|
| 940 | - 'export_type' => 'xsd:string', |
|
| 941 | - 'constraints' => '', |
|
| 942 | - // To build custom metabox. |
|
| 943 | - 'input_field' => 'address', |
|
| 944 | - ), |
|
| 945 | - self::FIELD_ADDRESS_LOCALITY => array( |
|
| 946 | - 'predicate' => 'http://schema.org/addressLocality', |
|
| 947 | - 'type' => self::DATA_TYPE_STRING, |
|
| 948 | - 'export_type' => 'xsd:string', |
|
| 949 | - 'constraints' => '', |
|
| 950 | - // To build custom metabox. |
|
| 951 | - 'input_field' => 'address', |
|
| 952 | - ), |
|
| 953 | - self::FIELD_ADDRESS_REGION => array( |
|
| 954 | - 'predicate' => 'http://schema.org/addressRegion', |
|
| 955 | - 'type' => self::DATA_TYPE_STRING, |
|
| 956 | - 'export_type' => 'xsd:string', |
|
| 957 | - 'constraints' => '', |
|
| 958 | - // To build custom metabox. |
|
| 959 | - 'input_field' => 'address', |
|
| 960 | - ), |
|
| 961 | - self::FIELD_ADDRESS_COUNTRY => array( |
|
| 962 | - 'predicate' => 'http://schema.org/addressCountry', |
|
| 963 | - 'type' => self::DATA_TYPE_STRING, |
|
| 964 | - 'export_type' => 'xsd:string', |
|
| 965 | - 'constraints' => '', |
|
| 966 | - // To build custom metabox. |
|
| 967 | - 'input_field' => 'address', |
|
| 968 | - ), |
|
| 969 | - ), |
|
| 970 | - 'templates' => array( |
|
| 971 | - 'subtitle' => '{{id}}', |
|
| 972 | - ), |
|
| 973 | - ); |
|
| 974 | - |
|
| 975 | - // Merge the custom fields with those provided by the thing schema. |
|
| 976 | - $parent_schema = $this->get_thing_schema(); |
|
| 977 | - $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] ); |
|
| 978 | - |
|
| 979 | - return $schema; |
|
| 980 | - } |
|
| 981 | - |
|
| 982 | - /** |
|
| 983 | - * Get the 'local business' schema. |
|
| 984 | - * |
|
| 985 | - * @return array An array with the schema configuration. |
|
| 986 | - * |
|
| 987 | - * @since 3.1.0 |
|
| 988 | - */ |
|
| 989 | - private function get_local_business_schema() { |
|
| 990 | - |
|
| 991 | - $schema = array( |
|
| 992 | - 'label' => 'LocalBusiness', |
|
| 993 | - 'description' => 'A local business.', |
|
| 994 | - 'parents' => array( 'place', 'organization' ), |
|
| 995 | - 'css_class' => 'wl-local-business', |
|
| 996 | - 'uri' => 'http://schema.org/LocalBusiness', |
|
| 997 | - 'same_as' => array( |
|
| 998 | - 'http://rdf.freebase.com/ns/business/business_location', |
|
| 999 | - 'https://schema.org/Store', |
|
| 1000 | - ), |
|
| 1001 | - 'custom_fields' => array(), |
|
| 1002 | - 'templates' => array( |
|
| 1003 | - 'subtitle' => '{{id}}', |
|
| 1004 | - ), |
|
| 1005 | - ); |
|
| 1006 | - |
|
| 1007 | - // Merge the custom fields with those provided by the place and organization schema. |
|
| 1008 | - $place_schema = $this->get_place_schema(); |
|
| 1009 | - $organization_schema = $this->get_organization_schema(); |
|
| 1010 | - $schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] ); |
|
| 1011 | - |
|
| 1012 | - return $schema; |
|
| 1013 | - } |
|
| 1014 | - |
|
| 1015 | - /** |
|
| 1016 | - * Get the 'recipe' schema. |
|
| 1017 | - * |
|
| 1018 | - * @return array An array with the schema configuration. |
|
| 1019 | - * |
|
| 1020 | - * @since 3.14.0 |
|
| 1021 | - */ |
|
| 1022 | - private function get_recipe_schema() { |
|
| 1023 | - |
|
| 1024 | - $schema = array( |
|
| 1025 | - 'label' => 'Recipe', |
|
| 1026 | - 'description' => 'A Recipe.', |
|
| 1027 | - 'parents' => array( 'CreativeWork' ), |
|
| 1028 | - 'css_class' => 'wl-recipe', |
|
| 1029 | - 'uri' => 'http://schema.org/Recipe', |
|
| 1030 | - 'same_as' => array(), |
|
| 1031 | - 'templates' => array( |
|
| 1032 | - 'subtitle' => '{{id}}', |
|
| 1033 | - ), |
|
| 1034 | - 'custom_fields' => array( |
|
| 1035 | - self::FIELD_RECIPE_CUISINE => array( |
|
| 1036 | - 'predicate' => 'http://schema.org/recipeCuisine', |
|
| 1037 | - 'type' => self::DATA_TYPE_STRING, |
|
| 1038 | - 'export_type' => 'xsd:string', |
|
| 1039 | - 'constraints' => '', |
|
| 1040 | - 'metabox' => array( |
|
| 1041 | - 'label' => __( 'Recipe cuisine', 'wordlift' ), |
|
| 1042 | - ), |
|
| 1043 | - ), |
|
| 1044 | - self::FIELD_RECIPE_INGREDIENT => array( |
|
| 1045 | - 'predicate' => 'http://schema.org/recipeIngredient', |
|
| 1046 | - 'type' => self::DATA_TYPE_STRING, |
|
| 1047 | - 'export_type' => 'xsd:string', |
|
| 1048 | - 'constraints' => array( |
|
| 1049 | - 'cardinality' => INF, |
|
| 1050 | - ), |
|
| 1051 | - 'metabox' => array( |
|
| 1052 | - 'label' => __( 'Recipe ingredient', 'wordlift' ), |
|
| 1053 | - ), |
|
| 1054 | - ), |
|
| 1055 | - self::FIELD_RECIPE_INSTRUCTIONS => array( |
|
| 1056 | - 'predicate' => 'http://schema.org/recipeInstructions', |
|
| 1057 | - 'type' => self::DATA_TYPE_MULTILINE, |
|
| 1058 | - 'export_type' => 'xsd:string', |
|
| 1059 | - 'constraints' => '', |
|
| 1060 | - 'metabox' => array( |
|
| 1061 | - 'class' => 'Wordlift_Metabox_Field_Multiline', |
|
| 1062 | - 'label' => __( 'Recipe instructions', 'wordlift' ), |
|
| 1063 | - ), |
|
| 1064 | - ), |
|
| 1065 | - self::FIELD_RECIPE_YIELD => array( |
|
| 1066 | - 'predicate' => 'http://schema.org/recipeYield', |
|
| 1067 | - 'type' => self::DATA_TYPE_STRING, |
|
| 1068 | - 'export_type' => 'xsd:string', |
|
| 1069 | - 'constraints' => '', |
|
| 1070 | - 'metabox' => array( |
|
| 1071 | - 'label' => __( 'Recipe number of servings', 'wordlift' ), |
|
| 1072 | - ), |
|
| 1073 | - ), |
|
| 1074 | - self::FIELD_RECIPE_INGREDIENT => array( |
|
| 1075 | - 'predicate' => 'http://schema.org/recipeIngredient', |
|
| 1076 | - 'type' => self::DATA_TYPE_STRING, |
|
| 1077 | - 'export_type' => 'xsd:string', |
|
| 1078 | - 'constraints' => array( |
|
| 1079 | - 'cardinality' => INF, |
|
| 1080 | - ), |
|
| 1081 | - 'metabox' => array( |
|
| 1082 | - 'label' => __( 'Recipe ingredient', 'wordlift' ), |
|
| 1083 | - ), |
|
| 1084 | - ), |
|
| 1085 | - self::FIELD_NUTRITION_INFO_CALORIES => array( |
|
| 1086 | - 'predicate' => 'http://schema.org/calories', |
|
| 1087 | - 'type' => self::DATA_TYPE_STRING, |
|
| 1088 | - 'export_type' => 'xsd:string', |
|
| 1089 | - 'constraints' => '', |
|
| 1090 | - 'metabox' => array( |
|
| 1091 | - 'label' => __( 'Calories (e.g. 240 calories)', 'wordlift' ), |
|
| 1092 | - ), |
|
| 1093 | - ), |
|
| 1094 | - self::FIELD_PREP_TIME => array( |
|
| 1095 | - 'predicate' => 'http://schema.org/prepTime', |
|
| 1096 | - 'type' => self::DATA_TYPE_DURATION, |
|
| 1097 | - 'export_type' => 'xsd:time', |
|
| 1098 | - 'constraints' => '', |
|
| 1099 | - 'metabox' => array( |
|
| 1100 | - 'class' => 'Wordlift_Metabox_Field_Duration', |
|
| 1101 | - 'label' => __( 'Recipe preparation time (e.g. 1:30)', 'wordlift' ), |
|
| 1102 | - ), |
|
| 1103 | - ), |
|
| 1104 | - self::FIELD_COOK_TIME => array( |
|
| 1105 | - 'predicate' => 'http://schema.org/cookTime', |
|
| 1106 | - 'type' => self::DATA_TYPE_DURATION, |
|
| 1107 | - 'export_type' => 'xsd:time', |
|
| 1108 | - 'constraints' => '', |
|
| 1109 | - 'metabox' => array( |
|
| 1110 | - 'class' => 'Wordlift_Metabox_Field_Duration', |
|
| 1111 | - 'label' => __( 'Recipe cook time (e.g. 1:30)', 'wordlift' ), |
|
| 1112 | - ), |
|
| 1113 | - ), |
|
| 1114 | - self::FIELD_TOTAL_TIME => array( |
|
| 1115 | - 'predicate' => 'http://schema.org/totalTime', |
|
| 1116 | - 'type' => self::DATA_TYPE_DURATION, |
|
| 1117 | - 'export_type' => 'xsd:time', |
|
| 1118 | - 'constraints' => '', |
|
| 1119 | - 'metabox' => array( |
|
| 1120 | - 'class' => 'Wordlift_Metabox_Field_Duration', |
|
| 1121 | - 'label' => __( 'Recipe total time (e.g. 1:30)', 'wordlift' ), |
|
| 1122 | - ), |
|
| 1123 | - ), |
|
| 1124 | - ), |
|
| 1125 | - ); |
|
| 1126 | - |
|
| 1127 | - // Merge the custom fields with those provided by the parent schema. |
|
| 1128 | - $parent_schema = $this->get_creative_work_schema(); |
|
| 1129 | - $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] ); |
|
| 1130 | - |
|
| 1131 | - return $schema; |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - /** |
|
| 1135 | - * Get the 'offer' schema. |
|
| 1136 | - * |
|
| 1137 | - * @return array An array with the schema configuration. |
|
| 1138 | - * |
|
| 1139 | - * @since 3.18.0 |
|
| 1140 | - */ |
|
| 1141 | - private function get_offer_schema() { |
|
| 1142 | - |
|
| 1143 | - $schema = array( |
|
| 1144 | - 'label' => 'Offer', |
|
| 1145 | - 'description' => 'An offer. ', |
|
| 1146 | - 'parents' => array( 'thing' ), |
|
| 1147 | - 'css_class' => 'wl-offer', |
|
| 1148 | - 'uri' => self::SCHEMA_OFFER_TYPE, |
|
| 1149 | - 'same_as' => array(), |
|
| 1150 | - 'templates' => array( |
|
| 1151 | - 'subtitle' => '{{id}}', |
|
| 1152 | - ), |
|
| 1153 | - 'custom_fields' => array( |
|
| 1154 | - self::FIELD_AVAILABILITY => array( |
|
| 1155 | - 'predicate' => 'http://schema.org/availability', |
|
| 1156 | - 'type' => self::DATA_TYPE_STRING, |
|
| 1157 | - 'export_type' => 'xsd:string', |
|
| 1158 | - 'metabox' => array( |
|
| 1159 | - 'class' => 'Wordlift_Metabox_Field_Select', |
|
| 1160 | - ), |
|
| 1161 | - 'options' => array( |
|
| 1162 | - 'Discontinued' => esc_html__( 'Discontinued', 'wordlift' ), |
|
| 1163 | - 'InStock' => esc_html__( 'In Stock', 'wordlift' ), |
|
| 1164 | - 'InStoreOnly' => esc_html__( 'In Store Only', 'wordlift' ), |
|
| 1165 | - 'LimitedAvailability' => esc_html__( 'Limited Availability', 'wordlift' ), |
|
| 1166 | - 'OnlineOnly' => esc_html__( 'Online Only', 'wordlift' ), |
|
| 1167 | - 'OutOfStock' => esc_html__( 'Out of Stock', 'wordlift' ), |
|
| 1168 | - 'PreOrder' => esc_html__( 'Pre Order', 'wordlift' ), |
|
| 1169 | - 'PreSale' => esc_html__( 'Pre Sale', 'wordlift' ), |
|
| 1170 | - 'SoldOut' => esc_html__( 'Sold Out', 'wordlift' ), |
|
| 1171 | - ), |
|
| 1172 | - ), |
|
| 1173 | - self::FIELD_PRICE => array( |
|
| 1174 | - 'predicate' => 'http://schema.org/price', |
|
| 1175 | - 'type' => self::DATA_TYPE_STRING, |
|
| 1176 | - 'export_type' => 'xsd:integer', |
|
| 1177 | - 'metabox' => array( |
|
| 1178 | - 'class' => 'Wordlift_Metabox_Field_Integer', |
|
| 1179 | - ), |
|
| 1180 | - ), |
|
| 1181 | - self::FIELD_PRICE_CURRENCY => array( |
|
| 1182 | - 'predicate' => 'http://schema.org/priceCurrency', |
|
| 1183 | - 'type' => self::DATA_TYPE_STRING, |
|
| 1184 | - 'export_type' => 'xsd:string', |
|
| 1185 | - ), |
|
| 1186 | - self::FIELD_AVAILABILITY_STARTS => array( |
|
| 1187 | - 'predicate' => 'http://schema.org/availabilityStarts', |
|
| 1188 | - 'type' => self::DATA_TYPE_DATE, |
|
| 1189 | - 'export_type' => 'xsd:dateTime', |
|
| 1190 | - ), |
|
| 1191 | - self::FIELD_AVAILABILITY_ENDS => array( |
|
| 1192 | - 'predicate' => 'http://schema.org/availabilityEnds', |
|
| 1193 | - 'type' => self::DATA_TYPE_DATE, |
|
| 1194 | - 'export_type' => 'xsd:dateTime', |
|
| 1195 | - ), |
|
| 1196 | - self::FIELD_INVENTORY_LEVEL => array( |
|
| 1197 | - 'predicate' => 'http://schema.org/inventoryLevel', |
|
| 1198 | - 'type' => self::DATA_TYPE_STRING, |
|
| 1199 | - 'export_type' => 'xsd:integer', |
|
| 1200 | - 'metabox' => array( |
|
| 1201 | - 'class' => 'Wordlift_Metabox_Field_Integer', |
|
| 1202 | - ), |
|
| 1203 | - ), |
|
| 1204 | - self::FIELD_VALID_FROM => array( |
|
| 1205 | - 'predicate' => 'http://schema.org/validFrom', |
|
| 1206 | - 'type' => self::DATA_TYPE_DATE, |
|
| 1207 | - 'export_type' => 'xsd:dateTime', |
|
| 1208 | - ), |
|
| 1209 | - self::FIELD_PRICE_VALID_UNTIL => array( |
|
| 1210 | - 'predicate' => 'http://schema.org/priceValidUntil', |
|
| 1211 | - 'type' => self::DATA_TYPE_DATE, |
|
| 1212 | - 'export_type' => 'xsd:dateTime', |
|
| 1213 | - ), |
|
| 1214 | - self::FIELD_ITEM_OFFERED => array( |
|
| 1215 | - 'predicate' => 'http://schema.org/itemOffered', |
|
| 1216 | - 'type' => self::DATA_TYPE_URI, |
|
| 1217 | - 'export_type' => 'http://schema.org/Thing', |
|
| 1218 | - 'constraints' => array( |
|
| 1219 | - 'uri_type' => array( |
|
| 1220 | - 'Event', |
|
| 1221 | - 'Thing', |
|
| 1222 | - ), |
|
| 1223 | - 'cardinality' => INF, |
|
| 1224 | - ), |
|
| 1225 | - ), |
|
| 1226 | - ), |
|
| 1227 | - ); |
|
| 1228 | - |
|
| 1229 | - // Merge the custom fields with those provided by the thing schema. |
|
| 1230 | - $parent_schema = $this->get_thing_schema(); |
|
| 1231 | - $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] ); |
|
| 1232 | - |
|
| 1233 | - return $schema; |
|
| 1234 | - } |
|
| 1235 | - |
|
| 1236 | - /** |
|
| 1237 | - * Get the 'article' schema. |
|
| 1238 | - * |
|
| 1239 | - * @return array An array with the schema configuration. |
|
| 1240 | - * |
|
| 1241 | - * @since 3.15.0 |
|
| 1242 | - */ |
|
| 1243 | - private function get_article_schema() { |
|
| 1244 | - |
|
| 1245 | - $schema = array( |
|
| 1246 | - 'label' => 'Article', |
|
| 1247 | - 'description' => 'An Article.', |
|
| 1248 | - 'parents' => array(), |
|
| 1249 | - 'css_class' => 'wl-article', |
|
| 1250 | - 'uri' => 'http://schema.org/Article', |
|
| 1251 | - 'same_as' => array(), |
|
| 1252 | - 'templates' => array( |
|
| 1253 | - 'subtitle' => '{{id}}', |
|
| 1254 | - ), |
|
| 1255 | - 'custom_fields' => array(), |
|
| 1256 | - ); |
|
| 1257 | - |
|
| 1258 | - return $schema; |
|
| 1259 | - } |
|
| 21 | + /** |
|
| 22 | + * The 'location created' field name. |
|
| 23 | + * |
|
| 24 | + * @since 3.5.0 |
|
| 25 | + */ |
|
| 26 | + const FIELD_LOCATION_CREATED = 'wl_location_created'; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * The 'topic' field name. |
|
| 30 | + * |
|
| 31 | + * @since 3.5.0 |
|
| 32 | + */ |
|
| 33 | + const FIELD_TOPIC = 'wl_topic'; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * The 'author' field name. |
|
| 37 | + * |
|
| 38 | + * @since 3.1.0 |
|
| 39 | + */ |
|
| 40 | + const FIELD_AUTHOR = 'wl_author'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * The 'same as' field name. |
|
| 44 | + * |
|
| 45 | + * @since 3.1.0 |
|
| 46 | + */ |
|
| 47 | + const FIELD_SAME_AS = 'entity_same_as'; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * The 'date start' field name. |
|
| 51 | + * |
|
| 52 | + * @since 3.1.0 |
|
| 53 | + */ |
|
| 54 | + const FIELD_DATE_START = 'wl_cal_date_start'; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * The 'date end' field name. |
|
| 58 | + * |
|
| 59 | + * @since 3.1.0 |
|
| 60 | + */ |
|
| 61 | + const FIELD_DATE_END = 'wl_cal_date_end'; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * The 'location' field name. |
|
| 65 | + * |
|
| 66 | + * @since 3.1.0 |
|
| 67 | + */ |
|
| 68 | + const FIELD_LOCATION = 'wl_location'; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * The 'founder' field name. |
|
| 72 | + * |
|
| 73 | + * @since 3.1.0 |
|
| 74 | + */ |
|
| 75 | + const FIELD_FOUNDER = 'wl_founder'; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * The 'knows' field name. |
|
| 79 | + * |
|
| 80 | + * @since 3.1.0 |
|
| 81 | + */ |
|
| 82 | + const FIELD_KNOWS = 'wl_knows'; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * The 'birth date' field name. |
|
| 86 | + * |
|
| 87 | + * @since 3.1.0 |
|
| 88 | + */ |
|
| 89 | + const FIELD_BIRTH_DATE = 'wl_birth_date'; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * The 'birth place' field name. |
|
| 93 | + * |
|
| 94 | + * @since 3.1.0 |
|
| 95 | + */ |
|
| 96 | + const FIELD_BIRTH_PLACE = 'wl_birth_place'; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * The 'latitude' field name. |
|
| 100 | + * |
|
| 101 | + * @since 3.1.0 |
|
| 102 | + */ |
|
| 103 | + const FIELD_GEO_LATITUDE = 'wl_geo_latitude'; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * The 'longitude' field name. |
|
| 107 | + * |
|
| 108 | + * @since 3.1.0 |
|
| 109 | + */ |
|
| 110 | + const FIELD_GEO_LONGITUDE = 'wl_geo_longitude'; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * The 'streetAddress' field name. |
|
| 114 | + * |
|
| 115 | + * @since 3.1.0 |
|
| 116 | + */ |
|
| 117 | + const FIELD_ADDRESS = 'wl_address'; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * The 'postOfficeBoxNumber' field name. |
|
| 121 | + * |
|
| 122 | + * @since 3.3.0 |
|
| 123 | + */ |
|
| 124 | + const FIELD_ADDRESS_PO_BOX = 'wl_address_post_office_box'; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * The 'postalCode' field name. |
|
| 128 | + * |
|
| 129 | + * @since 3.3.0 |
|
| 130 | + */ |
|
| 131 | + const FIELD_ADDRESS_POSTAL_CODE = 'wl_address_postal_code'; |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * The 'addressLocality' field name. |
|
| 135 | + * |
|
| 136 | + * @since 3.3.0 |
|
| 137 | + */ |
|
| 138 | + const FIELD_ADDRESS_LOCALITY = 'wl_address_locality'; |
|
| 139 | + /** |
|
| 140 | + * The 'addressRegion' field name. |
|
| 141 | + * |
|
| 142 | + * @since 3.3.0 |
|
| 143 | + */ |
|
| 144 | + const FIELD_ADDRESS_REGION = 'wl_address_region'; |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * The 'addressCountry' field name. |
|
| 148 | + * |
|
| 149 | + * @since 3.3.0 |
|
| 150 | + */ |
|
| 151 | + const FIELD_ADDRESS_COUNTRY = 'wl_address_country'; |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * The 'entity type' field name. |
|
| 155 | + * |
|
| 156 | + * @since 3.1.0 |
|
| 157 | + */ |
|
| 158 | + const FIELD_ENTITY_TYPE = 'wl_entity_type_uri'; |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * The 'email' field name. |
|
| 162 | + * |
|
| 163 | + * @since 3.2.0 |
|
| 164 | + */ |
|
| 165 | + const FIELD_EMAIL = 'wl_email'; |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * The 'affiliation' field name. |
|
| 169 | + * |
|
| 170 | + * @since 3.2.0 |
|
| 171 | + */ |
|
| 172 | + const FIELD_AFFILIATION = 'wl_affiliation'; |
|
| 173 | + |
|
| 174 | + /** |
|
| 175 | + * The 'telephone' field name. |
|
| 176 | + * |
|
| 177 | + * @since 3.8.0 |
|
| 178 | + */ |
|
| 179 | + const FIELD_TELEPHONE = 'wl_schema_telephone'; |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * The 'legalName' field name. |
|
| 183 | + * |
|
| 184 | + * @since 3.12.0 |
|
| 185 | + */ |
|
| 186 | + const FIELD_LEGAL_NAME = 'wl_schema_legal_name'; |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * The 'recipeCuisine' field name. |
|
| 190 | + * |
|
| 191 | + * @since 3.14.0 |
|
| 192 | + */ |
|
| 193 | + const FIELD_RECIPE_CUISINE = 'wl_schema_recipe_cuisine'; |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * The 'recipeIngredient' field name. |
|
| 197 | + * |
|
| 198 | + * @since 3.14.0 |
|
| 199 | + */ |
|
| 200 | + const FIELD_RECIPE_INGREDIENT = 'wl_schema_recipe_ingredient'; |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * The 'calories' field name. |
|
| 204 | + * |
|
| 205 | + * @since 3.14.0 |
|
| 206 | + */ |
|
| 207 | + const FIELD_NUTRITION_INFO_CALORIES = 'wl_schema_nutrition_information_calories'; |
|
| 208 | + |
|
| 209 | + /** |
|
| 210 | + * The 'recipeInstructions' field name. |
|
| 211 | + * |
|
| 212 | + * @since 3.14.0 |
|
| 213 | + */ |
|
| 214 | + const FIELD_RECIPE_INSTRUCTIONS = 'wl_schema_recipe_instructions'; |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * The 'recipeYield' field name. |
|
| 218 | + * |
|
| 219 | + * @since 3.14.0 |
|
| 220 | + */ |
|
| 221 | + const FIELD_RECIPE_YIELD = 'wl_schema_recipe_yield'; |
|
| 222 | + |
|
| 223 | + /** |
|
| 224 | + * The 'prepTime' field name. |
|
| 225 | + * |
|
| 226 | + * @since 3.14.0 |
|
| 227 | + */ |
|
| 228 | + const FIELD_PREP_TIME = 'wl_schema_prep_time'; |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * The 'cookTime' field name. |
|
| 232 | + * |
|
| 233 | + * @since 3.14.0 |
|
| 234 | + */ |
|
| 235 | + const FIELD_COOK_TIME = 'wl_schema_cook_time'; |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * The 'totalTime' field name. |
|
| 239 | + * |
|
| 240 | + * @since 3.14.0 |
|
| 241 | + */ |
|
| 242 | + const FIELD_TOTAL_TIME = 'wl_schema_total_time'; |
|
| 243 | + |
|
| 244 | + /** |
|
| 245 | + * The 'performer' field name. |
|
| 246 | + * |
|
| 247 | + * @since 3.18.0 |
|
| 248 | + */ |
|
| 249 | + const FIELD_PERFORMER = 'wl_schema_performer'; |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * The 'offers' field name. |
|
| 253 | + * |
|
| 254 | + * @since 3.18.0 |
|
| 255 | + */ |
|
| 256 | + const FIELD_OFFERS = 'wl_schema_offers'; |
|
| 257 | + |
|
| 258 | + /** |
|
| 259 | + * The 'availablity' field name. |
|
| 260 | + * |
|
| 261 | + * @since 3.18.0 |
|
| 262 | + */ |
|
| 263 | + const FIELD_AVAILABILITY = 'wl_schema_availability'; |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * The 'inventoryLevel' field name. |
|
| 267 | + * |
|
| 268 | + * @since 3.18.0 |
|
| 269 | + */ |
|
| 270 | + const FIELD_INVENTORY_LEVEL = 'wl_schema_inventory_level'; |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * The 'price' field name. |
|
| 274 | + * |
|
| 275 | + * @since 3.18.0 |
|
| 276 | + */ |
|
| 277 | + const FIELD_PRICE = 'wl_schema_price'; |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * The 'priceCurrency' field name. |
|
| 281 | + * |
|
| 282 | + * @since 3.18.0 |
|
| 283 | + */ |
|
| 284 | + const FIELD_PRICE_CURRENCY = 'wl_schema_price_currency'; |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * The 'availabilityStarts' field name. |
|
| 288 | + * |
|
| 289 | + * @since 3.18.0 |
|
| 290 | + */ |
|
| 291 | + const FIELD_AVAILABILITY_STARTS = 'wl_schema_availability_starts'; |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * The 'availabilityEnds' field name. |
|
| 295 | + * |
|
| 296 | + * @since 3.18.0 |
|
| 297 | + */ |
|
| 298 | + const FIELD_AVAILABILITY_ENDS = 'wl_schema_availability_ends'; |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * The 'validFrom' field name. |
|
| 302 | + * |
|
| 303 | + * @since 3.18.0 |
|
| 304 | + */ |
|
| 305 | + const FIELD_VALID_FROM = 'wl_schema_valid_from'; |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * The 'priceValidUntil' field name. |
|
| 309 | + * |
|
| 310 | + * @since 3.18.0 |
|
| 311 | + */ |
|
| 312 | + const FIELD_PRICE_VALID_UNTIL = 'wl_schema_valid_until'; |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * The 'itemOffered' field name. |
|
| 316 | + * |
|
| 317 | + * @since 3.18.0 |
|
| 318 | + */ |
|
| 319 | + const FIELD_ITEM_OFFERED = 'wl_schema_item_offered'; |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * The 'URI' data type name. |
|
| 323 | + * |
|
| 324 | + * @since 3.1.0 |
|
| 325 | + */ |
|
| 326 | + const DATA_TYPE_URI = 'uri'; |
|
| 327 | + |
|
| 328 | + /** |
|
| 329 | + * The 'date' data type name. |
|
| 330 | + * |
|
| 331 | + * @since 3.1.0 |
|
| 332 | + */ |
|
| 333 | + const DATA_TYPE_DATE = 'date'; |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * The 'time' data type name. |
|
| 337 | + * |
|
| 338 | + * @since 3.14.0 |
|
| 339 | + */ |
|
| 340 | + const DATA_TYPE_DURATION = 'duration'; |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * The 'double' data type name. |
|
| 344 | + * |
|
| 345 | + * @since 3.1.0 |
|
| 346 | + */ |
|
| 347 | + const DATA_TYPE_DOUBLE = 'double'; |
|
| 348 | + |
|
| 349 | + /** |
|
| 350 | + * The 'string' data type name. |
|
| 351 | + * |
|
| 352 | + * @since 3.1.0 |
|
| 353 | + */ |
|
| 354 | + const DATA_TYPE_STRING = 'string'; |
|
| 355 | + |
|
| 356 | + /** |
|
| 357 | + * The multiline text data type name. |
|
| 358 | + * |
|
| 359 | + * @since 3.14.0 |
|
| 360 | + */ |
|
| 361 | + const DATA_TYPE_MULTILINE = 'multiline'; |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * The schema.org Event type URI. |
|
| 365 | + * |
|
| 366 | + * @since 3.1.0 |
|
| 367 | + */ |
|
| 368 | + const SCHEMA_EVENT_TYPE = 'http://schema.org/Event'; |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * The schema.org Offer type URI. |
|
| 372 | + * |
|
| 373 | + * @since 3.18.0 |
|
| 374 | + */ |
|
| 375 | + const SCHEMA_OFFER_TYPE = 'http://schema.org/Offer'; |
|
| 376 | + |
|
| 377 | + /** |
|
| 378 | + * WordLift's schema. |
|
| 379 | + * |
|
| 380 | + * @since 3.1.0 |
|
| 381 | + * @access private |
|
| 382 | + * @var array $schema WordLift's schema. |
|
| 383 | + */ |
|
| 384 | + private $schema; |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * The Log service. |
|
| 388 | + * |
|
| 389 | + * @since 3.1.0 |
|
| 390 | + * @access private |
|
| 391 | + * @var \Wordlift_Log_Service $log The Log service. |
|
| 392 | + */ |
|
| 393 | + private $log; |
|
| 394 | + |
|
| 395 | + /** |
|
| 396 | + * Wordlift_Schema_Service constructor. |
|
| 397 | + * |
|
| 398 | + * @since 3.1.0 |
|
| 399 | + */ |
|
| 400 | + protected function __construct() { |
|
| 401 | + |
|
| 402 | + $this->log = Wordlift_Log_Service::get_logger( 'Wordlift_Schema_Service' ); |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Alter the configured schemas. |
|
| 406 | + * |
|
| 407 | + * Enable 3rd parties to alter WordLift's schemas array. |
|
| 408 | + * |
|
| 409 | + * @param array $schemas The array of schemas. |
|
| 410 | + * |
|
| 411 | + * @since 3.19.1 |
|
| 412 | + */ |
|
| 413 | + $this->schema = apply_filters( |
|
| 414 | + 'wl_schemas', |
|
| 415 | + array( |
|
| 416 | + 'article' => $this->get_article_schema(), |
|
| 417 | + 'thing' => $this->get_thing_schema(), |
|
| 418 | + 'creative-work' => $this->get_creative_work_schema(), |
|
| 419 | + 'event' => $this->get_event_schema(), |
|
| 420 | + 'organization' => $this->get_organization_schema(), |
|
| 421 | + 'person' => $this->get_person_schema(), |
|
| 422 | + 'place' => $this->get_place_schema(), |
|
| 423 | + 'local-business' => $this->get_local_business_schema(), |
|
| 424 | + 'recipe' => $this->get_recipe_schema(), |
|
| 425 | + 'web-page' => $this->get_web_page_schema(), |
|
| 426 | + 'offer' => $this->get_offer_schema(), |
|
| 427 | + ) |
|
| 428 | + ); |
|
| 429 | + |
|
| 430 | + // Create a singleton instance of the Schema service, useful to provide static functions to global functions. |
|
| 431 | + self::$instance = $this; |
|
| 432 | + |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + public function get_all_schema_slugs() { |
|
| 436 | + return array_keys( $this->schema ); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + /** |
|
| 440 | + * The Schema service singleton instance. |
|
| 441 | + * |
|
| 442 | + * @since 3.1.0 |
|
| 443 | + * @access private |
|
| 444 | + * @var Wordlift_Schema_Service $instance The Schema service singleton instance. |
|
| 445 | + */ |
|
| 446 | + private static $instance = null; |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * Get a reference to the Schema service. |
|
| 450 | + * |
|
| 451 | + * @return Wordlift_Schema_Service A reference to the Schema service. |
|
| 452 | + * @since 3.1.0 |
|
| 453 | + */ |
|
| 454 | + public static function get_instance() { |
|
| 455 | + if ( ! isset( self::$instance ) ) { |
|
| 456 | + self::$instance = new self(); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + return self::$instance; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + /** |
|
| 463 | + * Get the properties for a field with the specified key. The key is used as |
|
| 464 | + * meta key when the field's value is stored in WordPress meta data table. |
|
| 465 | + * |
|
| 466 | + * @param string $key The field's key. |
|
| 467 | + * |
|
| 468 | + * @return null|array An array of field's properties or null if the field is not found. |
|
| 469 | + * @since 3.6.0 |
|
| 470 | + */ |
|
| 471 | + public function get_field( $key ) { |
|
| 472 | + |
|
| 473 | + // Parse each schema's fields until we find the one we're looking for, then |
|
| 474 | + // return its properties. |
|
| 475 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
| 476 | + foreach ( $this->schema as $_ => $schema ) { |
|
| 477 | + |
|
| 478 | + if ( ! isset( $schema['custom_fields'] ) ) { |
|
| 479 | + break; |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + foreach ( $schema['custom_fields'] as $field => $props ) { |
|
| 483 | + if ( $key === $field ) { |
|
| 484 | + return $props; |
|
| 485 | + } |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + return null; |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * Get the WordLift's schema. |
|
| 494 | + * |
|
| 495 | + * @param string $name The schema name. |
|
| 496 | + * |
|
| 497 | + * @return array|null An array with the schema configuration or NULL if the schema is not found. |
|
| 498 | + * |
|
| 499 | + * @since 3.1.0 |
|
| 500 | + */ |
|
| 501 | + public function get_schema( $name ) { |
|
| 502 | + // Check if the schema exists and, if not, return NULL. |
|
| 503 | + if ( ! isset( $this->schema[ $name ] ) ) { |
|
| 504 | + return null; |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + // Return the requested schema. |
|
| 508 | + return $this->schema[ $name ]; |
|
| 509 | + } |
|
| 510 | + |
|
| 511 | + /** |
|
| 512 | + * Get the WordLift's schema trough schema type uri. |
|
| 513 | + * |
|
| 514 | + * @param string $uri The schema uri. |
|
| 515 | + * |
|
| 516 | + * @return array|null An array with the schema configuration or NULL if the schema is not found. |
|
| 517 | + * |
|
| 518 | + * @since 3.3.0 |
|
| 519 | + */ |
|
| 520 | + public function get_schema_by_uri( $uri ) { |
|
| 521 | + |
|
| 522 | + // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
|
| 523 | + foreach ( $this->schema as $name => $schema ) { |
|
| 524 | + if ( $schema['uri'] === $uri ) { |
|
| 525 | + return $schema; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + return null; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Get the 'thing' schema. |
|
| 534 | + * |
|
| 535 | + * @return array An array with the schema configuration. |
|
| 536 | + * |
|
| 537 | + * @since 3.1.0 |
|
| 538 | + */ |
|
| 539 | + private function get_thing_schema() { |
|
| 540 | + |
|
| 541 | + return array( |
|
| 542 | + 'css_class' => 'wl-thing', |
|
| 543 | + 'uri' => 'http://schema.org/Thing', |
|
| 544 | + 'same_as' => array( '*' ), |
|
| 545 | + // set as default. |
|
| 546 | + 'custom_fields' => array( |
|
| 547 | + self::FIELD_SAME_AS => array( |
|
| 548 | + 'predicate' => 'http://schema.org/sameAs', |
|
| 549 | + 'type' => self::DATA_TYPE_URI, |
|
| 550 | + 'export_type' => 'http://schema.org/Thing', |
|
| 551 | + 'constraints' => array( |
|
| 552 | + 'cardinality' => INF, |
|
| 553 | + ), |
|
| 554 | + // We need a custom metabox. |
|
| 555 | + 'input_field' => 'sameas', |
|
| 556 | + ), |
|
| 557 | + // Add the schema:url property. |
|
| 558 | + Wordlift_Schema_Url_Property_Service::META_KEY => Wordlift_Schema_Url_Property_Service::get_instance() |
|
| 559 | + ->get_compat_definition(), |
|
| 560 | + ), |
|
| 561 | + // {{sameAs}} not present in the microdata template, |
|
| 562 | + // because it is treated separately in *wl_content_embed_item_microdata* |
|
| 563 | + 'templates' => array( |
|
| 564 | + 'subtitle' => '{{id}}', |
|
| 565 | + ), |
|
| 566 | + ); |
|
| 567 | + |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + /** |
|
| 571 | + * Get the 'web-page' schema. |
|
| 572 | + * |
|
| 573 | + * @return array An array with the schema configuration. |
|
| 574 | + * |
|
| 575 | + * @since 3.18.0 |
|
| 576 | + */ |
|
| 577 | + private function get_web_page_schema() { |
|
| 578 | + |
|
| 579 | + return array( |
|
| 580 | + 'css_class' => 'wl-webpage', |
|
| 581 | + 'uri' => 'http://schema.org/WebPage', |
|
| 582 | + ); |
|
| 583 | + |
|
| 584 | + } |
|
| 585 | + |
|
| 586 | + /** |
|
| 587 | + * Get the 'creative work' schema. |
|
| 588 | + * |
|
| 589 | + * @return array An array with the schema configuration. |
|
| 590 | + * |
|
| 591 | + * @since 3.1.0 |
|
| 592 | + */ |
|
| 593 | + private function get_creative_work_schema() { |
|
| 594 | + |
|
| 595 | + $schema = array( |
|
| 596 | + 'label' => 'CreativeWork', |
|
| 597 | + 'description' => 'A creative work (or a Music Album).', |
|
| 598 | + 'parents' => array( 'thing' ), |
|
| 599 | + // Give term slug as parent. |
|
| 600 | + 'css_class' => 'wl-creative-work', |
|
| 601 | + 'uri' => 'http://schema.org/CreativeWork', |
|
| 602 | + 'same_as' => array( |
|
| 603 | + 'http://schema.org/MusicAlbum', |
|
| 604 | + 'http://schema.org/Product', |
|
| 605 | + ), |
|
| 606 | + 'custom_fields' => array( |
|
| 607 | + self::FIELD_AUTHOR => array( |
|
| 608 | + 'predicate' => 'http://schema.org/author', |
|
| 609 | + 'type' => self::DATA_TYPE_URI, |
|
| 610 | + 'export_type' => 'http://schema.org/Person', |
|
| 611 | + 'constraints' => array( |
|
| 612 | + 'uri_type' => array( 'Person', 'Organization' ), |
|
| 613 | + 'cardinality' => INF, |
|
| 614 | + ), |
|
| 615 | + ), |
|
| 616 | + ), |
|
| 617 | + 'templates' => array( |
|
| 618 | + 'subtitle' => '{{id}}', |
|
| 619 | + ), |
|
| 620 | + ); |
|
| 621 | + |
|
| 622 | + // Merge the custom fields with those provided by the thing schema. |
|
| 623 | + $parent_schema = $this->get_thing_schema(); |
|
| 624 | + $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] ); |
|
| 625 | + |
|
| 626 | + return $schema; |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + /** |
|
| 630 | + * Get the 'event' schema. |
|
| 631 | + * |
|
| 632 | + * @return array An array with the schema configuration. |
|
| 633 | + * |
|
| 634 | + * @since 3.1.0 |
|
| 635 | + */ |
|
| 636 | + private function get_event_schema() { |
|
| 637 | + |
|
| 638 | + $schema = array( |
|
| 639 | + 'label' => 'Event', |
|
| 640 | + 'description' => 'An event . ', |
|
| 641 | + 'parents' => array( 'thing' ), |
|
| 642 | + 'css_class' => 'wl-event', |
|
| 643 | + 'uri' => self::SCHEMA_EVENT_TYPE, |
|
| 644 | + 'same_as' => array( 'http://dbpedia.org/ontology/Event' ), |
|
| 645 | + 'custom_fields' => array( |
|
| 646 | + self::FIELD_DATE_START => array( |
|
| 647 | + 'predicate' => 'http://schema.org/startDate', |
|
| 648 | + 'type' => self::DATA_TYPE_DATE, |
|
| 649 | + 'export_type' => 'xsd:dateTime', |
|
| 650 | + 'constraints' => '', |
|
| 651 | + ), |
|
| 652 | + self::FIELD_DATE_END => array( |
|
| 653 | + 'predicate' => 'http://schema.org/endDate', |
|
| 654 | + 'type' => self::DATA_TYPE_DATE, |
|
| 655 | + 'export_type' => 'xsd:dateTime', |
|
| 656 | + 'constraints' => '', |
|
| 657 | + ), |
|
| 658 | + self::FIELD_LOCATION => array( |
|
| 659 | + 'predicate' => 'http://schema.org/location', |
|
| 660 | + 'type' => self::DATA_TYPE_URI, |
|
| 661 | + 'export_type' => 'http://schema.org/PostalAddress', |
|
| 662 | + 'constraints' => array( |
|
| 663 | + 'uri_type' => array( 'Place', 'LocalBusiness' ), |
|
| 664 | + 'cardinality' => INF, |
|
| 665 | + ), |
|
| 666 | + ), |
|
| 667 | + self::FIELD_PERFORMER => array( |
|
| 668 | + 'predicate' => 'http://schema.org/performer', |
|
| 669 | + 'type' => self::DATA_TYPE_URI, |
|
| 670 | + 'export_type' => 'http://schema.org/Person', |
|
| 671 | + 'constraints' => array( |
|
| 672 | + 'uri_type' => array( 'Person', 'Organization' ), |
|
| 673 | + 'cardinality' => INF, |
|
| 674 | + ), |
|
| 675 | + ), |
|
| 676 | + self::FIELD_OFFERS => array( |
|
| 677 | + 'predicate' => 'http://schema.org/offers', |
|
| 678 | + 'type' => self::DATA_TYPE_URI, |
|
| 679 | + 'export_type' => 'http://schema.org/Offer', |
|
| 680 | + 'constraints' => array( |
|
| 681 | + 'uri_type' => array( 'Offer' ), |
|
| 682 | + 'cardinality' => INF, |
|
| 683 | + ), |
|
| 684 | + ), |
|
| 685 | + ), |
|
| 686 | + 'templates' => array( |
|
| 687 | + 'subtitle' => '{{id}}', |
|
| 688 | + ), |
|
| 689 | + ); |
|
| 690 | + |
|
| 691 | + // Merge the custom fields with those provided by the thing schema. |
|
| 692 | + $parent_schema = $this->get_thing_schema(); |
|
| 693 | + $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] ); |
|
| 694 | + |
|
| 695 | + return $schema; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * Get the 'organization' schema. |
|
| 700 | + * |
|
| 701 | + * @return array An array with the schema configuration. |
|
| 702 | + * |
|
| 703 | + * @since 3.1.0 |
|
| 704 | + */ |
|
| 705 | + private function get_organization_schema() { |
|
| 706 | + |
|
| 707 | + $schema = array( |
|
| 708 | + 'label' => 'Organization', |
|
| 709 | + 'description' => 'An organization, including a government or a newspaper.', |
|
| 710 | + 'parents' => array( 'thing' ), |
|
| 711 | + 'css_class' => 'wl-organization', |
|
| 712 | + 'uri' => 'http://schema.org/Organization', |
|
| 713 | + 'same_as' => array( |
|
| 714 | + 'http://rdf.freebase.com/ns/organization.organization', |
|
| 715 | + 'http://rdf.freebase.com/ns/government.government', |
|
| 716 | + 'http://schema.org/Newspaper', |
|
| 717 | + ), |
|
| 718 | + 'custom_fields' => array( |
|
| 719 | + self::FIELD_LEGAL_NAME => array( |
|
| 720 | + 'predicate' => 'http://schema.org/legalName', |
|
| 721 | + 'type' => self::DATA_TYPE_STRING, |
|
| 722 | + 'export_type' => 'xsd:string', |
|
| 723 | + 'constraints' => '', |
|
| 724 | + ), |
|
| 725 | + self::FIELD_FOUNDER => array( |
|
| 726 | + 'predicate' => 'http://schema.org/founder', |
|
| 727 | + 'type' => self::DATA_TYPE_URI, |
|
| 728 | + 'export_type' => 'http://schema.org/Person', |
|
| 729 | + 'constraints' => array( |
|
| 730 | + 'uri_type' => 'Person', |
|
| 731 | + 'cardinality' => INF, |
|
| 732 | + ), |
|
| 733 | + ), |
|
| 734 | + self::FIELD_ADDRESS => array( |
|
| 735 | + 'predicate' => 'http://schema.org/streetAddress', |
|
| 736 | + 'type' => self::DATA_TYPE_STRING, |
|
| 737 | + 'export_type' => 'xsd:string', |
|
| 738 | + 'constraints' => '', |
|
| 739 | + // To build custom metabox. |
|
| 740 | + 'input_field' => 'address', |
|
| 741 | + ), |
|
| 742 | + self::FIELD_ADDRESS_PO_BOX => array( |
|
| 743 | + 'predicate' => 'http://schema.org/postOfficeBoxNumber', |
|
| 744 | + 'type' => self::DATA_TYPE_STRING, |
|
| 745 | + 'export_type' => 'xsd:string', |
|
| 746 | + 'constraints' => '', |
|
| 747 | + // To build custom metabox. |
|
| 748 | + 'input_field' => 'address', |
|
| 749 | + ), |
|
| 750 | + self::FIELD_ADDRESS_POSTAL_CODE => array( |
|
| 751 | + 'predicate' => 'http://schema.org/postalCode', |
|
| 752 | + 'type' => self::DATA_TYPE_STRING, |
|
| 753 | + 'export_type' => 'xsd:string', |
|
| 754 | + 'constraints' => '', |
|
| 755 | + // To build custom metabox. |
|
| 756 | + 'input_field' => 'address', |
|
| 757 | + ), |
|
| 758 | + self::FIELD_ADDRESS_LOCALITY => array( |
|
| 759 | + 'predicate' => 'http://schema.org/addressLocality', |
|
| 760 | + 'type' => self::DATA_TYPE_STRING, |
|
| 761 | + 'export_type' => 'xsd:string', |
|
| 762 | + 'constraints' => '', |
|
| 763 | + // To build custom metabox. |
|
| 764 | + 'input_field' => 'address', |
|
| 765 | + ), |
|
| 766 | + self::FIELD_ADDRESS_REGION => array( |
|
| 767 | + 'predicate' => 'http://schema.org/addressRegion', |
|
| 768 | + 'type' => self::DATA_TYPE_STRING, |
|
| 769 | + 'export_type' => 'xsd:string', |
|
| 770 | + 'constraints' => '', |
|
| 771 | + // To build custom metabox. |
|
| 772 | + 'input_field' => 'address', |
|
| 773 | + ), |
|
| 774 | + self::FIELD_ADDRESS_COUNTRY => array( |
|
| 775 | + 'predicate' => 'http://schema.org/addressCountry', |
|
| 776 | + 'type' => self::DATA_TYPE_STRING, |
|
| 777 | + 'export_type' => 'xsd:string', |
|
| 778 | + 'constraints' => '', |
|
| 779 | + // To build custom metabox. |
|
| 780 | + 'input_field' => 'address', |
|
| 781 | + ), |
|
| 782 | + self::FIELD_EMAIL => array( |
|
| 783 | + 'predicate' => 'http://schema.org/email', |
|
| 784 | + 'type' => self::DATA_TYPE_STRING, |
|
| 785 | + 'export_type' => 'xsd:string', |
|
| 786 | + 'constraints' => '', |
|
| 787 | + ), |
|
| 788 | + self::FIELD_TELEPHONE => array( |
|
| 789 | + 'predicate' => 'http://schema.org/telephone', |
|
| 790 | + 'type' => self::DATA_TYPE_STRING, |
|
| 791 | + 'export_type' => 'xsd:string', |
|
| 792 | + 'constraints' => '', |
|
| 793 | + ), |
|
| 794 | + ), |
|
| 795 | + 'templates' => array( |
|
| 796 | + 'subtitle' => '{{id}}', |
|
| 797 | + ), |
|
| 798 | + ); |
|
| 799 | + |
|
| 800 | + // Merge the custom fields with those provided by the thing schema. |
|
| 801 | + $parent_schema = $this->get_thing_schema(); |
|
| 802 | + $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] ); |
|
| 803 | + |
|
| 804 | + return $schema; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + /** |
|
| 808 | + * Get the 'person' schema. |
|
| 809 | + * |
|
| 810 | + * @return array An array with the schema configuration. |
|
| 811 | + * |
|
| 812 | + * @since 3.1.0 |
|
| 813 | + */ |
|
| 814 | + private function get_person_schema() { |
|
| 815 | + |
|
| 816 | + $schema = array( |
|
| 817 | + 'label' => 'Person', |
|
| 818 | + 'description' => 'A person (or a music artist).', |
|
| 819 | + 'parents' => array( 'thing' ), |
|
| 820 | + 'css_class' => 'wl-person', |
|
| 821 | + 'uri' => 'http://schema.org/Person', |
|
| 822 | + 'same_as' => array( |
|
| 823 | + 'http://rdf.freebase.com/ns/people.person', |
|
| 824 | + 'http://rdf.freebase.com/ns/music.artist', |
|
| 825 | + 'http://dbpedia.org/class/yago/LivingPeople', |
|
| 826 | + ), |
|
| 827 | + 'custom_fields' => array( |
|
| 828 | + self::FIELD_KNOWS => array( |
|
| 829 | + 'predicate' => 'http://schema.org/knows', |
|
| 830 | + 'type' => self::DATA_TYPE_URI, |
|
| 831 | + 'export_type' => 'http://schema.org/Person', |
|
| 832 | + 'constraints' => array( |
|
| 833 | + 'uri_type' => 'Person', |
|
| 834 | + 'cardinality' => INF, |
|
| 835 | + ), |
|
| 836 | + ), |
|
| 837 | + self::FIELD_BIRTH_DATE => array( |
|
| 838 | + 'predicate' => 'http://schema.org/birthDate', |
|
| 839 | + 'type' => self::DATA_TYPE_DATE, |
|
| 840 | + 'export_type' => 'xsd:date', |
|
| 841 | + 'constraints' => '', |
|
| 842 | + ), |
|
| 843 | + self::FIELD_BIRTH_PLACE => array( |
|
| 844 | + 'predicate' => 'http://schema.org/birthPlace', |
|
| 845 | + 'type' => self::DATA_TYPE_URI, |
|
| 846 | + 'export_type' => 'http://schema.org/Place', |
|
| 847 | + 'constraints' => array( |
|
| 848 | + 'uri_type' => 'Place', |
|
| 849 | + ), |
|
| 850 | + ), |
|
| 851 | + self::FIELD_AFFILIATION => array( |
|
| 852 | + 'predicate' => 'http://schema.org/affiliation', |
|
| 853 | + 'type' => self::DATA_TYPE_URI, |
|
| 854 | + 'export_type' => 'http://schema.org/Organization', |
|
| 855 | + 'constraints' => array( |
|
| 856 | + 'uri_type' => array( |
|
| 857 | + 'Organization', |
|
| 858 | + 'LocalBusiness', |
|
| 859 | + ), |
|
| 860 | + 'cardinality' => INF, |
|
| 861 | + ), |
|
| 862 | + ), |
|
| 863 | + self::FIELD_EMAIL => array( |
|
| 864 | + 'predicate' => 'http://schema.org/email', |
|
| 865 | + 'type' => self::DATA_TYPE_STRING, |
|
| 866 | + 'export_type' => 'xsd:string', |
|
| 867 | + 'constraints' => array( |
|
| 868 | + 'cardinality' => INF, |
|
| 869 | + ), |
|
| 870 | + ), |
|
| 871 | + ), |
|
| 872 | + 'templates' => array( |
|
| 873 | + 'subtitle' => '{{id}}', |
|
| 874 | + ), |
|
| 875 | + ); |
|
| 876 | + |
|
| 877 | + // Merge the custom fields with those provided by the thing schema. |
|
| 878 | + $parent_schema = $this->get_thing_schema(); |
|
| 879 | + $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] ); |
|
| 880 | + |
|
| 881 | + return $schema; |
|
| 882 | + |
|
| 883 | + } |
|
| 884 | + |
|
| 885 | + /** |
|
| 886 | + * Get the 'place' schema. |
|
| 887 | + * |
|
| 888 | + * @return array An array with the schema configuration. |
|
| 889 | + * |
|
| 890 | + * @since 3.1.0 |
|
| 891 | + */ |
|
| 892 | + private function get_place_schema() { |
|
| 893 | + |
|
| 894 | + $schema = array( |
|
| 895 | + 'label' => 'Place', |
|
| 896 | + 'description' => 'A place.', |
|
| 897 | + 'parents' => array( 'thing' ), |
|
| 898 | + 'css_class' => 'wl-place', |
|
| 899 | + 'uri' => 'http://schema.org/Place', |
|
| 900 | + 'same_as' => array( |
|
| 901 | + 'http://rdf.freebase.com/ns/location.location', |
|
| 902 | + 'http://www.opengis.net/gml/_Feature', |
|
| 903 | + ), |
|
| 904 | + 'custom_fields' => array( |
|
| 905 | + self::FIELD_GEO_LATITUDE => array( |
|
| 906 | + 'predicate' => 'http://schema.org/latitude', |
|
| 907 | + 'type' => self::DATA_TYPE_DOUBLE, |
|
| 908 | + 'export_type' => 'xsd:double', |
|
| 909 | + 'constraints' => '', |
|
| 910 | + // To build custom metabox. |
|
| 911 | + 'input_field' => 'coordinates', |
|
| 912 | + ), |
|
| 913 | + self::FIELD_GEO_LONGITUDE => array( |
|
| 914 | + 'predicate' => 'http://schema.org/longitude', |
|
| 915 | + 'type' => self::DATA_TYPE_DOUBLE, |
|
| 916 | + 'export_type' => 'xsd:double', |
|
| 917 | + 'constraints' => '', |
|
| 918 | + // To build custom metabox. |
|
| 919 | + 'input_field' => 'coordinates', |
|
| 920 | + ), |
|
| 921 | + self::FIELD_ADDRESS => array( |
|
| 922 | + 'predicate' => 'http://schema.org/streetAddress', |
|
| 923 | + 'type' => self::DATA_TYPE_STRING, |
|
| 924 | + 'export_type' => 'xsd:string', |
|
| 925 | + 'constraints' => '', |
|
| 926 | + // To build custom metabox. |
|
| 927 | + 'input_field' => 'address', |
|
| 928 | + ), |
|
| 929 | + self::FIELD_ADDRESS_PO_BOX => array( |
|
| 930 | + 'predicate' => 'http://schema.org/postOfficeBoxNumber', |
|
| 931 | + 'type' => self::DATA_TYPE_STRING, |
|
| 932 | + 'export_type' => 'xsd:string', |
|
| 933 | + 'constraints' => '', |
|
| 934 | + // To build custom metabox. |
|
| 935 | + 'input_field' => 'address', |
|
| 936 | + ), |
|
| 937 | + self::FIELD_ADDRESS_POSTAL_CODE => array( |
|
| 938 | + 'predicate' => 'http://schema.org/postalCode', |
|
| 939 | + 'type' => self::DATA_TYPE_STRING, |
|
| 940 | + 'export_type' => 'xsd:string', |
|
| 941 | + 'constraints' => '', |
|
| 942 | + // To build custom metabox. |
|
| 943 | + 'input_field' => 'address', |
|
| 944 | + ), |
|
| 945 | + self::FIELD_ADDRESS_LOCALITY => array( |
|
| 946 | + 'predicate' => 'http://schema.org/addressLocality', |
|
| 947 | + 'type' => self::DATA_TYPE_STRING, |
|
| 948 | + 'export_type' => 'xsd:string', |
|
| 949 | + 'constraints' => '', |
|
| 950 | + // To build custom metabox. |
|
| 951 | + 'input_field' => 'address', |
|
| 952 | + ), |
|
| 953 | + self::FIELD_ADDRESS_REGION => array( |
|
| 954 | + 'predicate' => 'http://schema.org/addressRegion', |
|
| 955 | + 'type' => self::DATA_TYPE_STRING, |
|
| 956 | + 'export_type' => 'xsd:string', |
|
| 957 | + 'constraints' => '', |
|
| 958 | + // To build custom metabox. |
|
| 959 | + 'input_field' => 'address', |
|
| 960 | + ), |
|
| 961 | + self::FIELD_ADDRESS_COUNTRY => array( |
|
| 962 | + 'predicate' => 'http://schema.org/addressCountry', |
|
| 963 | + 'type' => self::DATA_TYPE_STRING, |
|
| 964 | + 'export_type' => 'xsd:string', |
|
| 965 | + 'constraints' => '', |
|
| 966 | + // To build custom metabox. |
|
| 967 | + 'input_field' => 'address', |
|
| 968 | + ), |
|
| 969 | + ), |
|
| 970 | + 'templates' => array( |
|
| 971 | + 'subtitle' => '{{id}}', |
|
| 972 | + ), |
|
| 973 | + ); |
|
| 974 | + |
|
| 975 | + // Merge the custom fields with those provided by the thing schema. |
|
| 976 | + $parent_schema = $this->get_thing_schema(); |
|
| 977 | + $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] ); |
|
| 978 | + |
|
| 979 | + return $schema; |
|
| 980 | + } |
|
| 981 | + |
|
| 982 | + /** |
|
| 983 | + * Get the 'local business' schema. |
|
| 984 | + * |
|
| 985 | + * @return array An array with the schema configuration. |
|
| 986 | + * |
|
| 987 | + * @since 3.1.0 |
|
| 988 | + */ |
|
| 989 | + private function get_local_business_schema() { |
|
| 990 | + |
|
| 991 | + $schema = array( |
|
| 992 | + 'label' => 'LocalBusiness', |
|
| 993 | + 'description' => 'A local business.', |
|
| 994 | + 'parents' => array( 'place', 'organization' ), |
|
| 995 | + 'css_class' => 'wl-local-business', |
|
| 996 | + 'uri' => 'http://schema.org/LocalBusiness', |
|
| 997 | + 'same_as' => array( |
|
| 998 | + 'http://rdf.freebase.com/ns/business/business_location', |
|
| 999 | + 'https://schema.org/Store', |
|
| 1000 | + ), |
|
| 1001 | + 'custom_fields' => array(), |
|
| 1002 | + 'templates' => array( |
|
| 1003 | + 'subtitle' => '{{id}}', |
|
| 1004 | + ), |
|
| 1005 | + ); |
|
| 1006 | + |
|
| 1007 | + // Merge the custom fields with those provided by the place and organization schema. |
|
| 1008 | + $place_schema = $this->get_place_schema(); |
|
| 1009 | + $organization_schema = $this->get_organization_schema(); |
|
| 1010 | + $schema['custom_fields'] = array_merge( $schema['custom_fields'], $place_schema['custom_fields'], $organization_schema['custom_fields'] ); |
|
| 1011 | + |
|
| 1012 | + return $schema; |
|
| 1013 | + } |
|
| 1014 | + |
|
| 1015 | + /** |
|
| 1016 | + * Get the 'recipe' schema. |
|
| 1017 | + * |
|
| 1018 | + * @return array An array with the schema configuration. |
|
| 1019 | + * |
|
| 1020 | + * @since 3.14.0 |
|
| 1021 | + */ |
|
| 1022 | + private function get_recipe_schema() { |
|
| 1023 | + |
|
| 1024 | + $schema = array( |
|
| 1025 | + 'label' => 'Recipe', |
|
| 1026 | + 'description' => 'A Recipe.', |
|
| 1027 | + 'parents' => array( 'CreativeWork' ), |
|
| 1028 | + 'css_class' => 'wl-recipe', |
|
| 1029 | + 'uri' => 'http://schema.org/Recipe', |
|
| 1030 | + 'same_as' => array(), |
|
| 1031 | + 'templates' => array( |
|
| 1032 | + 'subtitle' => '{{id}}', |
|
| 1033 | + ), |
|
| 1034 | + 'custom_fields' => array( |
|
| 1035 | + self::FIELD_RECIPE_CUISINE => array( |
|
| 1036 | + 'predicate' => 'http://schema.org/recipeCuisine', |
|
| 1037 | + 'type' => self::DATA_TYPE_STRING, |
|
| 1038 | + 'export_type' => 'xsd:string', |
|
| 1039 | + 'constraints' => '', |
|
| 1040 | + 'metabox' => array( |
|
| 1041 | + 'label' => __( 'Recipe cuisine', 'wordlift' ), |
|
| 1042 | + ), |
|
| 1043 | + ), |
|
| 1044 | + self::FIELD_RECIPE_INGREDIENT => array( |
|
| 1045 | + 'predicate' => 'http://schema.org/recipeIngredient', |
|
| 1046 | + 'type' => self::DATA_TYPE_STRING, |
|
| 1047 | + 'export_type' => 'xsd:string', |
|
| 1048 | + 'constraints' => array( |
|
| 1049 | + 'cardinality' => INF, |
|
| 1050 | + ), |
|
| 1051 | + 'metabox' => array( |
|
| 1052 | + 'label' => __( 'Recipe ingredient', 'wordlift' ), |
|
| 1053 | + ), |
|
| 1054 | + ), |
|
| 1055 | + self::FIELD_RECIPE_INSTRUCTIONS => array( |
|
| 1056 | + 'predicate' => 'http://schema.org/recipeInstructions', |
|
| 1057 | + 'type' => self::DATA_TYPE_MULTILINE, |
|
| 1058 | + 'export_type' => 'xsd:string', |
|
| 1059 | + 'constraints' => '', |
|
| 1060 | + 'metabox' => array( |
|
| 1061 | + 'class' => 'Wordlift_Metabox_Field_Multiline', |
|
| 1062 | + 'label' => __( 'Recipe instructions', 'wordlift' ), |
|
| 1063 | + ), |
|
| 1064 | + ), |
|
| 1065 | + self::FIELD_RECIPE_YIELD => array( |
|
| 1066 | + 'predicate' => 'http://schema.org/recipeYield', |
|
| 1067 | + 'type' => self::DATA_TYPE_STRING, |
|
| 1068 | + 'export_type' => 'xsd:string', |
|
| 1069 | + 'constraints' => '', |
|
| 1070 | + 'metabox' => array( |
|
| 1071 | + 'label' => __( 'Recipe number of servings', 'wordlift' ), |
|
| 1072 | + ), |
|
| 1073 | + ), |
|
| 1074 | + self::FIELD_RECIPE_INGREDIENT => array( |
|
| 1075 | + 'predicate' => 'http://schema.org/recipeIngredient', |
|
| 1076 | + 'type' => self::DATA_TYPE_STRING, |
|
| 1077 | + 'export_type' => 'xsd:string', |
|
| 1078 | + 'constraints' => array( |
|
| 1079 | + 'cardinality' => INF, |
|
| 1080 | + ), |
|
| 1081 | + 'metabox' => array( |
|
| 1082 | + 'label' => __( 'Recipe ingredient', 'wordlift' ), |
|
| 1083 | + ), |
|
| 1084 | + ), |
|
| 1085 | + self::FIELD_NUTRITION_INFO_CALORIES => array( |
|
| 1086 | + 'predicate' => 'http://schema.org/calories', |
|
| 1087 | + 'type' => self::DATA_TYPE_STRING, |
|
| 1088 | + 'export_type' => 'xsd:string', |
|
| 1089 | + 'constraints' => '', |
|
| 1090 | + 'metabox' => array( |
|
| 1091 | + 'label' => __( 'Calories (e.g. 240 calories)', 'wordlift' ), |
|
| 1092 | + ), |
|
| 1093 | + ), |
|
| 1094 | + self::FIELD_PREP_TIME => array( |
|
| 1095 | + 'predicate' => 'http://schema.org/prepTime', |
|
| 1096 | + 'type' => self::DATA_TYPE_DURATION, |
|
| 1097 | + 'export_type' => 'xsd:time', |
|
| 1098 | + 'constraints' => '', |
|
| 1099 | + 'metabox' => array( |
|
| 1100 | + 'class' => 'Wordlift_Metabox_Field_Duration', |
|
| 1101 | + 'label' => __( 'Recipe preparation time (e.g. 1:30)', 'wordlift' ), |
|
| 1102 | + ), |
|
| 1103 | + ), |
|
| 1104 | + self::FIELD_COOK_TIME => array( |
|
| 1105 | + 'predicate' => 'http://schema.org/cookTime', |
|
| 1106 | + 'type' => self::DATA_TYPE_DURATION, |
|
| 1107 | + 'export_type' => 'xsd:time', |
|
| 1108 | + 'constraints' => '', |
|
| 1109 | + 'metabox' => array( |
|
| 1110 | + 'class' => 'Wordlift_Metabox_Field_Duration', |
|
| 1111 | + 'label' => __( 'Recipe cook time (e.g. 1:30)', 'wordlift' ), |
|
| 1112 | + ), |
|
| 1113 | + ), |
|
| 1114 | + self::FIELD_TOTAL_TIME => array( |
|
| 1115 | + 'predicate' => 'http://schema.org/totalTime', |
|
| 1116 | + 'type' => self::DATA_TYPE_DURATION, |
|
| 1117 | + 'export_type' => 'xsd:time', |
|
| 1118 | + 'constraints' => '', |
|
| 1119 | + 'metabox' => array( |
|
| 1120 | + 'class' => 'Wordlift_Metabox_Field_Duration', |
|
| 1121 | + 'label' => __( 'Recipe total time (e.g. 1:30)', 'wordlift' ), |
|
| 1122 | + ), |
|
| 1123 | + ), |
|
| 1124 | + ), |
|
| 1125 | + ); |
|
| 1126 | + |
|
| 1127 | + // Merge the custom fields with those provided by the parent schema. |
|
| 1128 | + $parent_schema = $this->get_creative_work_schema(); |
|
| 1129 | + $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] ); |
|
| 1130 | + |
|
| 1131 | + return $schema; |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + /** |
|
| 1135 | + * Get the 'offer' schema. |
|
| 1136 | + * |
|
| 1137 | + * @return array An array with the schema configuration. |
|
| 1138 | + * |
|
| 1139 | + * @since 3.18.0 |
|
| 1140 | + */ |
|
| 1141 | + private function get_offer_schema() { |
|
| 1142 | + |
|
| 1143 | + $schema = array( |
|
| 1144 | + 'label' => 'Offer', |
|
| 1145 | + 'description' => 'An offer. ', |
|
| 1146 | + 'parents' => array( 'thing' ), |
|
| 1147 | + 'css_class' => 'wl-offer', |
|
| 1148 | + 'uri' => self::SCHEMA_OFFER_TYPE, |
|
| 1149 | + 'same_as' => array(), |
|
| 1150 | + 'templates' => array( |
|
| 1151 | + 'subtitle' => '{{id}}', |
|
| 1152 | + ), |
|
| 1153 | + 'custom_fields' => array( |
|
| 1154 | + self::FIELD_AVAILABILITY => array( |
|
| 1155 | + 'predicate' => 'http://schema.org/availability', |
|
| 1156 | + 'type' => self::DATA_TYPE_STRING, |
|
| 1157 | + 'export_type' => 'xsd:string', |
|
| 1158 | + 'metabox' => array( |
|
| 1159 | + 'class' => 'Wordlift_Metabox_Field_Select', |
|
| 1160 | + ), |
|
| 1161 | + 'options' => array( |
|
| 1162 | + 'Discontinued' => esc_html__( 'Discontinued', 'wordlift' ), |
|
| 1163 | + 'InStock' => esc_html__( 'In Stock', 'wordlift' ), |
|
| 1164 | + 'InStoreOnly' => esc_html__( 'In Store Only', 'wordlift' ), |
|
| 1165 | + 'LimitedAvailability' => esc_html__( 'Limited Availability', 'wordlift' ), |
|
| 1166 | + 'OnlineOnly' => esc_html__( 'Online Only', 'wordlift' ), |
|
| 1167 | + 'OutOfStock' => esc_html__( 'Out of Stock', 'wordlift' ), |
|
| 1168 | + 'PreOrder' => esc_html__( 'Pre Order', 'wordlift' ), |
|
| 1169 | + 'PreSale' => esc_html__( 'Pre Sale', 'wordlift' ), |
|
| 1170 | + 'SoldOut' => esc_html__( 'Sold Out', 'wordlift' ), |
|
| 1171 | + ), |
|
| 1172 | + ), |
|
| 1173 | + self::FIELD_PRICE => array( |
|
| 1174 | + 'predicate' => 'http://schema.org/price', |
|
| 1175 | + 'type' => self::DATA_TYPE_STRING, |
|
| 1176 | + 'export_type' => 'xsd:integer', |
|
| 1177 | + 'metabox' => array( |
|
| 1178 | + 'class' => 'Wordlift_Metabox_Field_Integer', |
|
| 1179 | + ), |
|
| 1180 | + ), |
|
| 1181 | + self::FIELD_PRICE_CURRENCY => array( |
|
| 1182 | + 'predicate' => 'http://schema.org/priceCurrency', |
|
| 1183 | + 'type' => self::DATA_TYPE_STRING, |
|
| 1184 | + 'export_type' => 'xsd:string', |
|
| 1185 | + ), |
|
| 1186 | + self::FIELD_AVAILABILITY_STARTS => array( |
|
| 1187 | + 'predicate' => 'http://schema.org/availabilityStarts', |
|
| 1188 | + 'type' => self::DATA_TYPE_DATE, |
|
| 1189 | + 'export_type' => 'xsd:dateTime', |
|
| 1190 | + ), |
|
| 1191 | + self::FIELD_AVAILABILITY_ENDS => array( |
|
| 1192 | + 'predicate' => 'http://schema.org/availabilityEnds', |
|
| 1193 | + 'type' => self::DATA_TYPE_DATE, |
|
| 1194 | + 'export_type' => 'xsd:dateTime', |
|
| 1195 | + ), |
|
| 1196 | + self::FIELD_INVENTORY_LEVEL => array( |
|
| 1197 | + 'predicate' => 'http://schema.org/inventoryLevel', |
|
| 1198 | + 'type' => self::DATA_TYPE_STRING, |
|
| 1199 | + 'export_type' => 'xsd:integer', |
|
| 1200 | + 'metabox' => array( |
|
| 1201 | + 'class' => 'Wordlift_Metabox_Field_Integer', |
|
| 1202 | + ), |
|
| 1203 | + ), |
|
| 1204 | + self::FIELD_VALID_FROM => array( |
|
| 1205 | + 'predicate' => 'http://schema.org/validFrom', |
|
| 1206 | + 'type' => self::DATA_TYPE_DATE, |
|
| 1207 | + 'export_type' => 'xsd:dateTime', |
|
| 1208 | + ), |
|
| 1209 | + self::FIELD_PRICE_VALID_UNTIL => array( |
|
| 1210 | + 'predicate' => 'http://schema.org/priceValidUntil', |
|
| 1211 | + 'type' => self::DATA_TYPE_DATE, |
|
| 1212 | + 'export_type' => 'xsd:dateTime', |
|
| 1213 | + ), |
|
| 1214 | + self::FIELD_ITEM_OFFERED => array( |
|
| 1215 | + 'predicate' => 'http://schema.org/itemOffered', |
|
| 1216 | + 'type' => self::DATA_TYPE_URI, |
|
| 1217 | + 'export_type' => 'http://schema.org/Thing', |
|
| 1218 | + 'constraints' => array( |
|
| 1219 | + 'uri_type' => array( |
|
| 1220 | + 'Event', |
|
| 1221 | + 'Thing', |
|
| 1222 | + ), |
|
| 1223 | + 'cardinality' => INF, |
|
| 1224 | + ), |
|
| 1225 | + ), |
|
| 1226 | + ), |
|
| 1227 | + ); |
|
| 1228 | + |
|
| 1229 | + // Merge the custom fields with those provided by the thing schema. |
|
| 1230 | + $parent_schema = $this->get_thing_schema(); |
|
| 1231 | + $schema['custom_fields'] = array_merge( $schema['custom_fields'], $parent_schema['custom_fields'] ); |
|
| 1232 | + |
|
| 1233 | + return $schema; |
|
| 1234 | + } |
|
| 1235 | + |
|
| 1236 | + /** |
|
| 1237 | + * Get the 'article' schema. |
|
| 1238 | + * |
|
| 1239 | + * @return array An array with the schema configuration. |
|
| 1240 | + * |
|
| 1241 | + * @since 3.15.0 |
|
| 1242 | + */ |
|
| 1243 | + private function get_article_schema() { |
|
| 1244 | + |
|
| 1245 | + $schema = array( |
|
| 1246 | + 'label' => 'Article', |
|
| 1247 | + 'description' => 'An Article.', |
|
| 1248 | + 'parents' => array(), |
|
| 1249 | + 'css_class' => 'wl-article', |
|
| 1250 | + 'uri' => 'http://schema.org/Article', |
|
| 1251 | + 'same_as' => array(), |
|
| 1252 | + 'templates' => array( |
|
| 1253 | + 'subtitle' => '{{id}}', |
|
| 1254 | + ), |
|
| 1255 | + 'custom_fields' => array(), |
|
| 1256 | + ); |
|
| 1257 | + |
|
| 1258 | + return $schema; |
|
| 1259 | + } |
|
| 1260 | 1260 | |
| 1261 | 1261 | } |
@@ -14,114 +14,114 @@ |
||
| 14 | 14 | |
| 15 | 15 | class Entity_Type { |
| 16 | 16 | |
| 17 | - public function __construct() { |
|
| 18 | - |
|
| 19 | - $that = $this; |
|
| 20 | - |
|
| 21 | - add_action( |
|
| 22 | - 'init', |
|
| 23 | - function () use ( $that ) { |
|
| 24 | - $that->init_ui_and_save_handlers(); |
|
| 25 | - } |
|
| 26 | - ); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @param $term \WP_Term |
|
| 31 | - */ |
|
| 32 | - public function render_ui( $term ) { |
|
| 33 | - |
|
| 34 | - $selected_entity_types = get_term_meta( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Thing should be the default selected entity type |
|
| 38 | - * when this feature is activated. |
|
| 39 | - */ |
|
| 40 | - if ( count( $selected_entity_types ) === 0 ) { |
|
| 41 | - $selected_entity_types[] = 'thing'; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $entity_type_taxonomy = Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME; |
|
| 45 | - $types = Terms_Compat::get_terms( |
|
| 46 | - $entity_type_taxonomy, |
|
| 47 | - array( |
|
| 48 | - 'taxonomy' => $entity_type_taxonomy, |
|
| 49 | - 'parent' => 0, |
|
| 50 | - 'hide_empty' => false, |
|
| 51 | - ) |
|
| 52 | - ); |
|
| 53 | - ?> |
|
| 17 | + public function __construct() { |
|
| 18 | + |
|
| 19 | + $that = $this; |
|
| 20 | + |
|
| 21 | + add_action( |
|
| 22 | + 'init', |
|
| 23 | + function () use ( $that ) { |
|
| 24 | + $that->init_ui_and_save_handlers(); |
|
| 25 | + } |
|
| 26 | + ); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @param $term \WP_Term |
|
| 31 | + */ |
|
| 32 | + public function render_ui( $term ) { |
|
| 33 | + |
|
| 34 | + $selected_entity_types = get_term_meta( $term->term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Thing should be the default selected entity type |
|
| 38 | + * when this feature is activated. |
|
| 39 | + */ |
|
| 40 | + if ( count( $selected_entity_types ) === 0 ) { |
|
| 41 | + $selected_entity_types[] = 'thing'; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $entity_type_taxonomy = Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME; |
|
| 45 | + $types = Terms_Compat::get_terms( |
|
| 46 | + $entity_type_taxonomy, |
|
| 47 | + array( |
|
| 48 | + 'taxonomy' => $entity_type_taxonomy, |
|
| 49 | + 'parent' => 0, |
|
| 50 | + 'hide_empty' => false, |
|
| 51 | + ) |
|
| 52 | + ); |
|
| 53 | + ?> |
|
| 54 | 54 | <?php wp_nonce_field( 'wordlift_vocabulary_terms_entity_type', 'wordlift_vocabulary_terms_entity_type_nonce' ); ?> |
| 55 | 55 | <tr class="form-field term-name-wrap"> |
| 56 | 56 | <th scope="row"><label for="wl-entity-type__checklist"><?php esc_html_e( 'Entity Types', 'wordlift' ); ?></label></th> |
| 57 | 57 | <td> |
| 58 | 58 | <div id="wl-entity-type__checklist"> |
| 59 | 59 | <?php |
| 60 | - echo wp_kses( |
|
| 61 | - Term_Checklist::render( 'tax_input[wl_entity_type]', $types, $selected_entity_types ), |
|
| 62 | - array( |
|
| 63 | - 'li' => array( 'id' => array() ), |
|
| 64 | - 'ul' => array( 'id' => array() ), |
|
| 65 | - 'label' => array( 'class' => array() ), |
|
| 66 | - 'input' => array( |
|
| 67 | - 'value' => array(), |
|
| 68 | - 'type' => array(), |
|
| 69 | - 'name' => array(), |
|
| 70 | - 'id' => array(), |
|
| 71 | - 'placeholder' => array(), |
|
| 72 | - 'checked' => array(), |
|
| 73 | - ), |
|
| 74 | - ) |
|
| 75 | - ); |
|
| 76 | - ?> |
|
| 60 | + echo wp_kses( |
|
| 61 | + Term_Checklist::render( 'tax_input[wl_entity_type]', $types, $selected_entity_types ), |
|
| 62 | + array( |
|
| 63 | + 'li' => array( 'id' => array() ), |
|
| 64 | + 'ul' => array( 'id' => array() ), |
|
| 65 | + 'label' => array( 'class' => array() ), |
|
| 66 | + 'input' => array( |
|
| 67 | + 'value' => array(), |
|
| 68 | + 'type' => array(), |
|
| 69 | + 'name' => array(), |
|
| 70 | + 'id' => array(), |
|
| 71 | + 'placeholder' => array(), |
|
| 72 | + 'checked' => array(), |
|
| 73 | + ), |
|
| 74 | + ) |
|
| 75 | + ); |
|
| 76 | + ?> |
|
| 77 | 77 | </div> |
| 78 | 78 | </td> |
| 79 | 79 | </tr> |
| 80 | 80 | <?php |
| 81 | - $this->enqueue_script_and_style(); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - public function save_field( $term_id ) { |
|
| 85 | - |
|
| 86 | - if ( ! isset( $_REQUEST['tax_input'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 87 | - return; |
|
| 88 | - } |
|
| 89 | - $entity_types = array(); |
|
| 90 | - if ( isset( $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 91 | - $entity_types_data = filter_var_array( $_REQUEST, array( 'tax_input' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 92 | - $entity_types = $entity_types_data['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ]; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - if ( isset( $entity_types ) && is_array( $entity_types ) ) { |
|
| 96 | - // Save the taxonomies. |
|
| 97 | - delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 98 | - foreach ( $entity_types as $entity_type ) { |
|
| 99 | - add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type ); |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - public function init_ui_and_save_handlers() { |
|
| 105 | - $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
| 106 | - foreach ( $taxonomies as $taxonomy ) { |
|
| 107 | - add_action( "${taxonomy}_edit_form_fields", array( $this, 'render_ui' ), 1 ); |
|
| 108 | - add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - private function enqueue_script_and_style() { |
|
| 113 | - |
|
| 114 | - Scripts_Helper::enqueue_based_on_wordpress_version( |
|
| 115 | - 'wl-vocabulary-term', |
|
| 116 | - plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term', |
|
| 117 | - array( 'wp-polyfill' ) |
|
| 118 | - ); |
|
| 119 | - wp_enqueue_style( |
|
| 120 | - 'wl-vocabulary-term', |
|
| 121 | - plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term.css', |
|
| 122 | - array(), |
|
| 123 | - WORDLIFT_VERSION |
|
| 124 | - ); |
|
| 125 | - } |
|
| 81 | + $this->enqueue_script_and_style(); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + public function save_field( $term_id ) { |
|
| 85 | + |
|
| 86 | + if ( ! isset( $_REQUEST['tax_input'] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 87 | + return; |
|
| 88 | + } |
|
| 89 | + $entity_types = array(); |
|
| 90 | + if ( isset( $_REQUEST['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ] ) ) { //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 91 | + $entity_types_data = filter_var_array( $_REQUEST, array( 'tax_input' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); //phpcs:ignore WordPress.Security.NonceVerification.Recommended |
|
| 92 | + $entity_types = $entity_types_data['tax_input'][ Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ]; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + if ( isset( $entity_types ) && is_array( $entity_types ) ) { |
|
| 96 | + // Save the taxonomies. |
|
| 97 | + delete_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 98 | + foreach ( $entity_types as $entity_type ) { |
|
| 99 | + add_term_meta( $term_id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, (string) $entity_type ); |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + public function init_ui_and_save_handlers() { |
|
| 105 | + $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
| 106 | + foreach ( $taxonomies as $taxonomy ) { |
|
| 107 | + add_action( "${taxonomy}_edit_form_fields", array( $this, 'render_ui' ), 1 ); |
|
| 108 | + add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + private function enqueue_script_and_style() { |
|
| 113 | + |
|
| 114 | + Scripts_Helper::enqueue_based_on_wordpress_version( |
|
| 115 | + 'wl-vocabulary-term', |
|
| 116 | + plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term', |
|
| 117 | + array( 'wp-polyfill' ) |
|
| 118 | + ); |
|
| 119 | + wp_enqueue_style( |
|
| 120 | + 'wl-vocabulary-term', |
|
| 121 | + plugin_dir_url( dirname( __DIR__ ) ) . '/js/dist/vocabulary-term.css', |
|
| 122 | + array(), |
|
| 123 | + WORDLIFT_VERSION |
|
| 124 | + ); |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | 127 | } |
@@ -4,14 +4,14 @@ |
||
| 4 | 4 | |
| 5 | 5 | class PostTypeDefinition extends AbstractFieldDefiniton { |
| 6 | 6 | |
| 7 | - public function register() { |
|
| 8 | - $that = $this; |
|
| 9 | - add_action( |
|
| 10 | - 'init', |
|
| 11 | - function () use ( $that ) { |
|
| 12 | - $context = $that->schema->get(); |
|
| 13 | - $that->register_pod( $context->get_pod_name(), $context->get_pod_type(), $context ); |
|
| 14 | - } |
|
| 15 | - ); |
|
| 16 | - } |
|
| 7 | + public function register() { |
|
| 8 | + $that = $this; |
|
| 9 | + add_action( |
|
| 10 | + 'init', |
|
| 11 | + function () use ( $that ) { |
|
| 12 | + $context = $that->schema->get(); |
|
| 13 | + $that->register_pod( $context->get_pod_name(), $context->get_pod_type(), $context ); |
|
| 14 | + } |
|
| 15 | + ); |
|
| 16 | + } |
|
| 17 | 17 | } |
@@ -4,14 +4,14 @@ |
||
| 4 | 4 | |
| 5 | 5 | class TaxonomyDefinition extends AbstractFieldDefiniton { |
| 6 | 6 | |
| 7 | - public function register() { |
|
| 8 | - $that = $this; |
|
| 9 | - add_action( |
|
| 10 | - 'setup_theme', |
|
| 11 | - function () use ( $that ) { |
|
| 12 | - $context = $that->schema->get(); |
|
| 13 | - $that->register_pod( $context->get_pod_name(), $context->get_pod_type(), $context ); |
|
| 14 | - } |
|
| 15 | - ); |
|
| 16 | - } |
|
| 7 | + public function register() { |
|
| 8 | + $that = $this; |
|
| 9 | + add_action( |
|
| 10 | + 'setup_theme', |
|
| 11 | + function () use ( $that ) { |
|
| 12 | + $context = $that->schema->get(); |
|
| 13 | + $that->register_pod( $context->get_pod_name(), $context->get_pod_type(), $context ); |
|
| 14 | + } |
|
| 15 | + ); |
|
| 16 | + } |
|
| 17 | 17 | } |
@@ -16,385 +16,385 @@ |
||
| 16 | 16 | * @subpackage Wordlift/admin/WL_Metabox |
| 17 | 17 | */ |
| 18 | 18 | class Wl_Abstract_Metabox { |
| 19 | - /** |
|
| 20 | - * The metabox custom fields for the current {@link WP_Post}. |
|
| 21 | - * |
|
| 22 | - * @since 3.1.0 |
|
| 23 | - * @access public |
|
| 24 | - * @var array $fields The metabox custom fields. |
|
| 25 | - */ |
|
| 26 | - public $fields; |
|
| 27 | - |
|
| 28 | - /** |
|
| 29 | - * A {@link Wordlift_Log_Service} instance. |
|
| 30 | - * |
|
| 31 | - * @since 3.15.4 |
|
| 32 | - * |
|
| 33 | - * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 34 | - */ |
|
| 35 | - private $log; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * WL_Metabox constructor. |
|
| 39 | - * |
|
| 40 | - * @since 3.1.0 |
|
| 41 | - */ |
|
| 42 | - public function __construct() { |
|
| 43 | - |
|
| 44 | - $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Add a callback to print the metabox in page. |
|
| 49 | - * WordPress will fire the $this->html() callback at the right time. |
|
| 50 | - */ |
|
| 51 | - public function add_main_metabox() { |
|
| 52 | - |
|
| 53 | - // Build the fields we need to print. |
|
| 54 | - $this->instantiate_fields( get_the_ID(), Object_Type_Enum::POST ); |
|
| 55 | - |
|
| 56 | - // Bailout if there are no actual fields, we do not need a metabox in that case. |
|
| 57 | - if ( empty( $this->fields ) ) { |
|
| 58 | - return; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - // Add main metabox (will print also the inner fields). |
|
| 62 | - $id = uniqid( 'wl-metabox-' ); |
|
| 63 | - $title = get_the_title() . ' ' . __( 'properties', 'wordlift' ); |
|
| 64 | - |
|
| 65 | - // WordPress 4.2 do not accept an array of screens as parameter, have to do be explicit. |
|
| 66 | - foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $screen ) { |
|
| 67 | - add_meta_box( |
|
| 68 | - $id, |
|
| 69 | - esc_html( $title ), |
|
| 70 | - array( |
|
| 71 | - $this, |
|
| 72 | - 'html', |
|
| 73 | - ), |
|
| 74 | - $screen, |
|
| 75 | - 'normal', |
|
| 76 | - 'high' |
|
| 77 | - ); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // Add filter to change the metabox CSS class. |
|
| 81 | - // |
|
| 82 | - // @since 3.20.0 Since we support post types other than `entity` for entities, we need to set the `screen` |
|
| 83 | - // dynamically according to the `get_current_screen()` function. |
|
| 84 | - $current_screen = get_current_screen(); |
|
| 85 | - $screen = $current_screen ? $current_screen->post_type : 'entity'; |
|
| 86 | - add_filter( "postbox_classes_{$screen}_$id", 'wl_admin_metaboxes_add_css_class' ); |
|
| 87 | - |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Render the metabox html. |
|
| 92 | - * |
|
| 93 | - * @since 3.1.0 |
|
| 94 | - */ |
|
| 95 | - public function html() { |
|
| 96 | - |
|
| 97 | - // HTML Code Before MetaBox Content. |
|
| 98 | - do_action( 'wl_metabox_before_html' ); |
|
| 99 | - |
|
| 100 | - // Loop over the fields. |
|
| 101 | - foreach ( $this->fields as $field ) { |
|
| 102 | - |
|
| 103 | - // load data from DB (values will be available in $field->data). |
|
| 104 | - $field->get_data(); |
|
| 105 | - |
|
| 106 | - // print field HTML (nonce included). |
|
| 107 | - echo $field->html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaping happens in `$field->html()`. |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Read the WL <-> Schema mapping and build the Fields for the entity being edited. |
|
| 114 | - * |
|
| 115 | - * Note: the first function that calls this method will instantiate the fields. |
|
| 116 | - * Why it isn't called from the constructor? Because we need to hook this process as late as possible. |
|
| 117 | - * |
|
| 118 | - * @param int $id | $term_id The post id or term id. |
|
| 119 | - * |
|
| 120 | - * @param $type int Post or Term |
|
| 121 | - * |
|
| 122 | - * @since 3.1.0 |
|
| 123 | - */ |
|
| 124 | - public function instantiate_fields( $id, $type ) { |
|
| 125 | - |
|
| 126 | - $this->log->trace( "Instantiating fields for entity post $id..." ); |
|
| 127 | - |
|
| 128 | - // This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering. |
|
| 129 | - if ( isset( $this->fields ) ) { |
|
| 130 | - return; |
|
| 131 | - } |
|
| 132 | - if ( Object_Type_Enum::POST === $type ) { |
|
| 133 | - $entity_type = wl_entity_taxonomy_get_custom_fields( $id ); |
|
| 134 | - } elseif ( Object_Type_Enum::TERM === $type ) { |
|
| 135 | - $term_entity_types = get_term_meta( $id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 136 | - $term_entity_types = array_map( |
|
| 137 | - function ( $term ) { |
|
| 138 | - return get_term_by( |
|
| 139 | - 'slug', |
|
| 140 | - $term, |
|
| 141 | - Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME |
|
| 142 | - ); |
|
| 143 | - }, |
|
| 144 | - $term_entity_types |
|
| 145 | - ); |
|
| 146 | - $entity_type = wl_get_custom_fields_by_entity_type( $term_entity_types ); |
|
| 147 | - } |
|
| 148 | - if ( isset( $entity_type ) ) { |
|
| 149 | - |
|
| 150 | - /* |
|
| 19 | + /** |
|
| 20 | + * The metabox custom fields for the current {@link WP_Post}. |
|
| 21 | + * |
|
| 22 | + * @since 3.1.0 |
|
| 23 | + * @access public |
|
| 24 | + * @var array $fields The metabox custom fields. |
|
| 25 | + */ |
|
| 26 | + public $fields; |
|
| 27 | + |
|
| 28 | + /** |
|
| 29 | + * A {@link Wordlift_Log_Service} instance. |
|
| 30 | + * |
|
| 31 | + * @since 3.15.4 |
|
| 32 | + * |
|
| 33 | + * @var \Wordlift_Log_Service $log A {@link Wordlift_Log_Service} instance. |
|
| 34 | + */ |
|
| 35 | + private $log; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * WL_Metabox constructor. |
|
| 39 | + * |
|
| 40 | + * @since 3.1.0 |
|
| 41 | + */ |
|
| 42 | + public function __construct() { |
|
| 43 | + |
|
| 44 | + $this->log = Wordlift_Log_Service::get_logger( get_class() ); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Add a callback to print the metabox in page. |
|
| 49 | + * WordPress will fire the $this->html() callback at the right time. |
|
| 50 | + */ |
|
| 51 | + public function add_main_metabox() { |
|
| 52 | + |
|
| 53 | + // Build the fields we need to print. |
|
| 54 | + $this->instantiate_fields( get_the_ID(), Object_Type_Enum::POST ); |
|
| 55 | + |
|
| 56 | + // Bailout if there are no actual fields, we do not need a metabox in that case. |
|
| 57 | + if ( empty( $this->fields ) ) { |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + // Add main metabox (will print also the inner fields). |
|
| 62 | + $id = uniqid( 'wl-metabox-' ); |
|
| 63 | + $title = get_the_title() . ' ' . __( 'properties', 'wordlift' ); |
|
| 64 | + |
|
| 65 | + // WordPress 4.2 do not accept an array of screens as parameter, have to do be explicit. |
|
| 66 | + foreach ( Wordlift_Entity_Service::valid_entity_post_types() as $screen ) { |
|
| 67 | + add_meta_box( |
|
| 68 | + $id, |
|
| 69 | + esc_html( $title ), |
|
| 70 | + array( |
|
| 71 | + $this, |
|
| 72 | + 'html', |
|
| 73 | + ), |
|
| 74 | + $screen, |
|
| 75 | + 'normal', |
|
| 76 | + 'high' |
|
| 77 | + ); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // Add filter to change the metabox CSS class. |
|
| 81 | + // |
|
| 82 | + // @since 3.20.0 Since we support post types other than `entity` for entities, we need to set the `screen` |
|
| 83 | + // dynamically according to the `get_current_screen()` function. |
|
| 84 | + $current_screen = get_current_screen(); |
|
| 85 | + $screen = $current_screen ? $current_screen->post_type : 'entity'; |
|
| 86 | + add_filter( "postbox_classes_{$screen}_$id", 'wl_admin_metaboxes_add_css_class' ); |
|
| 87 | + |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Render the metabox html. |
|
| 92 | + * |
|
| 93 | + * @since 3.1.0 |
|
| 94 | + */ |
|
| 95 | + public function html() { |
|
| 96 | + |
|
| 97 | + // HTML Code Before MetaBox Content. |
|
| 98 | + do_action( 'wl_metabox_before_html' ); |
|
| 99 | + |
|
| 100 | + // Loop over the fields. |
|
| 101 | + foreach ( $this->fields as $field ) { |
|
| 102 | + |
|
| 103 | + // load data from DB (values will be available in $field->data). |
|
| 104 | + $field->get_data(); |
|
| 105 | + |
|
| 106 | + // print field HTML (nonce included). |
|
| 107 | + echo $field->html(); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaping happens in `$field->html()`. |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Read the WL <-> Schema mapping and build the Fields for the entity being edited. |
|
| 114 | + * |
|
| 115 | + * Note: the first function that calls this method will instantiate the fields. |
|
| 116 | + * Why it isn't called from the constructor? Because we need to hook this process as late as possible. |
|
| 117 | + * |
|
| 118 | + * @param int $id | $term_id The post id or term id. |
|
| 119 | + * |
|
| 120 | + * @param $type int Post or Term |
|
| 121 | + * |
|
| 122 | + * @since 3.1.0 |
|
| 123 | + */ |
|
| 124 | + public function instantiate_fields( $id, $type ) { |
|
| 125 | + |
|
| 126 | + $this->log->trace( "Instantiating fields for entity post $id..." ); |
|
| 127 | + |
|
| 128 | + // This function must be called only once. Not called from the constructor because WP hooks have a rococo ordering. |
|
| 129 | + if ( isset( $this->fields ) ) { |
|
| 130 | + return; |
|
| 131 | + } |
|
| 132 | + if ( Object_Type_Enum::POST === $type ) { |
|
| 133 | + $entity_type = wl_entity_taxonomy_get_custom_fields( $id ); |
|
| 134 | + } elseif ( Object_Type_Enum::TERM === $type ) { |
|
| 135 | + $term_entity_types = get_term_meta( $id, Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME ); |
|
| 136 | + $term_entity_types = array_map( |
|
| 137 | + function ( $term ) { |
|
| 138 | + return get_term_by( |
|
| 139 | + 'slug', |
|
| 140 | + $term, |
|
| 141 | + Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME |
|
| 142 | + ); |
|
| 143 | + }, |
|
| 144 | + $term_entity_types |
|
| 145 | + ); |
|
| 146 | + $entity_type = wl_get_custom_fields_by_entity_type( $term_entity_types ); |
|
| 147 | + } |
|
| 148 | + if ( isset( $entity_type ) ) { |
|
| 149 | + |
|
| 150 | + /* |
|
| 151 | 151 | * Might not have any relevant meta box field, for example for articles, |
| 152 | 152 | * therefor make sure fields are at least an empty array to help the considered |
| 153 | 153 | * in other functions using it. |
| 154 | 154 | */ |
| 155 | - $this->fields = array(); |
|
| 155 | + $this->fields = array(); |
|
| 156 | 156 | |
| 157 | - /** |
|
| 158 | - * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods. |
|
| 159 | - * We must divide fields in two groups: |
|
| 160 | - * - simple: accept values for one property |
|
| 161 | - * - grouped: accept values for more properties, or for one property that needs a specific metabox. |
|
| 162 | - */ |
|
| 163 | - $metaboxes = $this->group_properties_by_input_field( $entity_type ); |
|
| 164 | - $simple_metaboxes = $metaboxes[0]; |
|
| 165 | - $grouped_metaboxes = $metaboxes[1]; |
|
| 166 | - |
|
| 167 | - // Loop over simple entity properties. |
|
| 168 | - foreach ( $simple_metaboxes as $key => $property ) { |
|
| 169 | - |
|
| 170 | - // Info passed to the metabox. |
|
| 171 | - $info = array(); |
|
| 172 | - $info[ $key ] = $property; |
|
| 157 | + /** |
|
| 158 | + * In some special case, properties must be grouped in one field (e.g. coordinates) or dealed with custom methods. |
|
| 159 | + * We must divide fields in two groups: |
|
| 160 | + * - simple: accept values for one property |
|
| 161 | + * - grouped: accept values for more properties, or for one property that needs a specific metabox. |
|
| 162 | + */ |
|
| 163 | + $metaboxes = $this->group_properties_by_input_field( $entity_type ); |
|
| 164 | + $simple_metaboxes = $metaboxes[0]; |
|
| 165 | + $grouped_metaboxes = $metaboxes[1]; |
|
| 173 | 166 | |
| 174 | - // Build the requested field as WL_Metabox_Field_ object. |
|
| 175 | - $this->add_field( $info, false, $type, $id ); |
|
| 167 | + // Loop over simple entity properties. |
|
| 168 | + foreach ( $simple_metaboxes as $key => $property ) { |
|
| 176 | 169 | |
| 177 | - } |
|
| 170 | + // Info passed to the metabox. |
|
| 171 | + $info = array(); |
|
| 172 | + $info[ $key ] = $property; |
|
| 178 | 173 | |
| 179 | - // Loop over grouped properties. |
|
| 180 | - foreach ( $grouped_metaboxes as $key => $property ) { |
|
| 174 | + // Build the requested field as WL_Metabox_Field_ object. |
|
| 175 | + $this->add_field( $info, false, $type, $id ); |
|
| 181 | 176 | |
| 182 | - // Info passed to the metabox. |
|
| 183 | - $info = array(); |
|
| 184 | - $info[ $key ] = $property; |
|
| 177 | + } |
|
| 185 | 178 | |
| 186 | - // Build the requested field group as WL_Metabox_Field_ object. |
|
| 187 | - $this->add_field( $info, true, $type, $id ); |
|
| 179 | + // Loop over grouped properties. |
|
| 180 | + foreach ( $grouped_metaboxes as $key => $property ) { |
|
| 188 | 181 | |
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - } |
|
| 182 | + // Info passed to the metabox. |
|
| 183 | + $info = array(); |
|
| 184 | + $info[ $key ] = $property; |
|
| 193 | 185 | |
| 194 | - /** |
|
| 195 | - * Separates metaboxes in simple and grouped. |
|
| 196 | - * |
|
| 197 | - * @param array $custom_fields Information on the entity type. |
|
| 198 | - * |
|
| 199 | - * @return array |
|
| 200 | - */ |
|
| 201 | - public function group_properties_by_input_field( $custom_fields ) { |
|
| 202 | - |
|
| 203 | - $simple_properties = array(); |
|
| 204 | - $grouped_properties = array(); |
|
| 205 | - |
|
| 206 | - // Loop over possible entity properties. |
|
| 207 | - foreach ( $custom_fields as $key => $property ) { |
|
| 208 | - |
|
| 209 | - // Check presence of predicate and type. |
|
| 210 | - if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) { |
|
| 211 | - |
|
| 212 | - // Check if input_field is defined. |
|
| 213 | - if ( isset( $property['input_field'] ) && '' !== $property['input_field'] ) { |
|
| 214 | - |
|
| 215 | - $grouped_key = $property['input_field']; |
|
| 216 | - |
|
| 217 | - // Update list of grouped properties. |
|
| 218 | - $grouped_properties[ $grouped_key ][ $key ] = $property; |
|
| 219 | - |
|
| 220 | - } else { |
|
| 221 | - |
|
| 222 | - // input_field not defined, add simple metabox. |
|
| 223 | - $simple_properties[ $key ] = $property; |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - return array( $simple_properties, $grouped_properties ); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Add a Field to the current Metabox, based on the description of the Field. |
|
| 233 | - * This method is a rude factory for Field objects. |
|
| 234 | - * |
|
| 235 | - * @param array $args The field's information. |
|
| 236 | - * @param bool $grouped Flag to distinguish between simple and grouped fields. |
|
| 237 | - * @param int $type Post or Term, based on the correct decorator would be selected. |
|
| 238 | - * @param int $id Identifier for the type. |
|
| 239 | - */ |
|
| 240 | - public function add_field( $args, $grouped, $type, $id ) { |
|
| 241 | - |
|
| 242 | - if ( $grouped ) { |
|
| 243 | - |
|
| 244 | - // Special fields (sameas, coordinates, etc.). |
|
| 245 | - // |
|
| 246 | - // Build Field with a custom class (e.g. WL_Metabox_Field_date). |
|
| 247 | - $field_class = 'Wl_Metabox_Field_' . key( $args ); |
|
| 248 | - |
|
| 249 | - } else { |
|
| 250 | - |
|
| 251 | - // Simple fields (string, uri, boolean, etc.). |
|
| 252 | - // |
|
| 253 | - // Which field? We want to use the class that is specific for the field. |
|
| 254 | - $meta = key( $args ); |
|
| 255 | - $this_meta = $args[ $meta ]; |
|
| 256 | - |
|
| 257 | - // If the field declares what metabox it wants, use that one. |
|
| 258 | - if ( isset( $this_meta['metabox']['class'] ) ) { |
|
| 259 | - |
|
| 260 | - $field_class = $this_meta['metabox']['class']; |
|
| 261 | - |
|
| 262 | - } elseif ( ! isset( $this_meta['type'] ) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type'] ) { |
|
| 263 | - |
|
| 264 | - // TODO: all fields should explicitly declare the required WL_Metabox. |
|
| 265 | - // When they will remove this. |
|
| 266 | - // |
|
| 267 | - // Use default Wl_Metabox_Field (manages strings). |
|
| 268 | - $field_class = 'Wl_Metabox_Field'; |
|
| 269 | - |
|
| 270 | - } else { |
|
| 271 | - |
|
| 272 | - // TODO: all fields should explicitly declare the required WL_Metabox. |
|
| 273 | - // When they will remove this. |
|
| 274 | - // |
|
| 275 | - // Build Field with a custom class (e.g. Wl_Metabox_Field_date). |
|
| 276 | - $field_class = 'Wl_Metabox_Field_' . $this_meta['type']; |
|
| 277 | - |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - /** |
|
| 281 | - * @since 3.31.6 |
|
| 282 | - * Add namespace to initialize class. |
|
| 283 | - */ |
|
| 284 | - /** |
|
| 285 | - * @since 3.31.6 |
|
| 286 | - * Add namespace to initialize class. |
|
| 287 | - */ |
|
| 288 | - if ( substr( $field_class, 0, 1 ) !== '\\' ) { |
|
| 289 | - $field_class = 'Wordlift\Metabox\Field\\' . $field_class; |
|
| 290 | - // End if(). |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - if ( class_exists( $field_class ) ) { |
|
| 294 | - // Get decorator and use it as wrapper for save_data and get_data methods. |
|
| 295 | - $instance = new $field_class( $args, $id, $type ); |
|
| 296 | - // Call apropriate constructor (e.g. Wl_Metabox_Field... ). |
|
| 297 | - $this->fields[] = $instance; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Save the form data for the specified entity {@link WP_Post}'s id. |
|
| 304 | - * |
|
| 305 | - * @param int $id The entity's {@link WP_Post}'s id. |
|
| 306 | - * |
|
| 307 | - * We're being called from WP `save_post` hook, we don't need to check the nonce. |
|
| 308 | - * |
|
| 309 | - * @param $type int Post or term |
|
| 310 | - * |
|
| 311 | - * @since 3.5.4 |
|
| 312 | - */ |
|
| 313 | - public function save_form_data( $id, $type ) { |
|
| 314 | - |
|
| 315 | - $this->log->trace( "Saving form data for entity post $id..." ); |
|
| 316 | - |
|
| 317 | - // Skip saving if the save is called for a different post. |
|
| 318 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 319 | - if ( isset( $_POST['post_ID'] ) && (int) $_POST['post_ID'] !== $id && Object_Type_Enum::POST === $type ) { |
|
| 320 | - $this->log->debug( '`wl_metaboxes`, skipping because the post id from request doesnt match the id from filter.' ); |
|
| 321 | - return; |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - // Build Field objects. |
|
| 325 | - $this->instantiate_fields( $id, $type ); |
|
| 326 | - |
|
| 327 | - // Check if WL metabox form was posted. |
|
| 328 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 329 | - if ( ! isset( $_POST['wl_metaboxes'] ) ) { |
|
| 330 | - $this->log->debug( '`wl_metaboxes`, skipping...' ); |
|
| 331 | - |
|
| 332 | - return; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 336 | - $posted_data = filter_var_array( $_POST, array( 'wl_metaboxes' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); |
|
| 337 | - $posted_data = $posted_data['wl_metaboxes']; |
|
| 338 | - foreach ( $this->fields as $field ) { |
|
| 339 | - |
|
| 340 | - // Verify nonce. |
|
| 341 | - $valid_nonce = $field->verify_nonce(); |
|
| 342 | - |
|
| 343 | - if ( $valid_nonce ) { |
|
| 344 | - $field_name = $field->meta_name; |
|
| 345 | - // Each Filed only deals with its values. |
|
| 346 | - if ( isset( $posted_data[ $field_name ] ) ) { |
|
| 347 | - |
|
| 348 | - $values = $posted_data[ $field_name ]; |
|
| 349 | - if ( ! is_array( $values ) ) { |
|
| 350 | - $values = array( $values ); |
|
| 351 | - } |
|
| 352 | - // Save data permanently |
|
| 353 | - $field->save_data( $values ); |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - /** |
|
| 359 | - * Filter: 'wl_save_form_pre_push_entity' - Allow to hook right |
|
| 360 | - * before the triples are pushed to the linked dataset. |
|
| 361 | - * |
|
| 362 | - * @param int $id The entity id. |
|
| 363 | - * @param int $id The post data. |
|
| 364 | - * |
|
| 365 | - * @since 3.18.2 |
|
| 366 | - */ |
|
| 367 | - // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 368 | - do_action( 'wl_save_form_pre_push_entity', $id, $_POST ); |
|
| 369 | - |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * Enqueue scripts and styles. |
|
| 374 | - * |
|
| 375 | - * @since 3.0.0 |
|
| 376 | - */ |
|
| 377 | - public function enqueue_scripts_and_styles() { |
|
| 378 | - |
|
| 379 | - // Use the minified version if PW_DEBUG isn't set. |
|
| 380 | - $min = ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ? '.min' : ''; |
|
| 381 | - |
|
| 382 | - // Load the jquery-ui-timepicker-addon library. |
|
| 383 | - wp_enqueue_style( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.css", array(), '3.0.6' ); |
|
| 384 | - wp_enqueue_script( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.js", array( 'jquery' ), '3.0.6', true ); |
|
| 385 | - |
|
| 386 | - wl_enqueue_leaflet(); |
|
| 387 | - |
|
| 388 | - // Add AJAX autocomplete to facilitate metabox editing. |
|
| 389 | - wp_enqueue_script( 'wl-entity-metabox-utility', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/admin/js/wl_entity_metabox_utilities.js', array(), WORDLIFT_VERSION, false ); |
|
| 390 | - wp_localize_script( |
|
| 391 | - 'wl-entity-metabox-utility', |
|
| 392 | - 'wlEntityMetaboxParams', |
|
| 393 | - array( |
|
| 394 | - 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 395 | - 'action' => 'entity_by_title', |
|
| 396 | - ) |
|
| 397 | - ); |
|
| 398 | - |
|
| 399 | - } |
|
| 186 | + // Build the requested field group as WL_Metabox_Field_ object. |
|
| 187 | + $this->add_field( $info, true, $type, $id ); |
|
| 188 | + |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Separates metaboxes in simple and grouped. |
|
| 196 | + * |
|
| 197 | + * @param array $custom_fields Information on the entity type. |
|
| 198 | + * |
|
| 199 | + * @return array |
|
| 200 | + */ |
|
| 201 | + public function group_properties_by_input_field( $custom_fields ) { |
|
| 202 | + |
|
| 203 | + $simple_properties = array(); |
|
| 204 | + $grouped_properties = array(); |
|
| 205 | + |
|
| 206 | + // Loop over possible entity properties. |
|
| 207 | + foreach ( $custom_fields as $key => $property ) { |
|
| 208 | + |
|
| 209 | + // Check presence of predicate and type. |
|
| 210 | + if ( isset( $property['predicate'] ) && isset( $property['type'] ) ) { |
|
| 211 | + |
|
| 212 | + // Check if input_field is defined. |
|
| 213 | + if ( isset( $property['input_field'] ) && '' !== $property['input_field'] ) { |
|
| 214 | + |
|
| 215 | + $grouped_key = $property['input_field']; |
|
| 216 | + |
|
| 217 | + // Update list of grouped properties. |
|
| 218 | + $grouped_properties[ $grouped_key ][ $key ] = $property; |
|
| 219 | + |
|
| 220 | + } else { |
|
| 221 | + |
|
| 222 | + // input_field not defined, add simple metabox. |
|
| 223 | + $simple_properties[ $key ] = $property; |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + return array( $simple_properties, $grouped_properties ); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Add a Field to the current Metabox, based on the description of the Field. |
|
| 233 | + * This method is a rude factory for Field objects. |
|
| 234 | + * |
|
| 235 | + * @param array $args The field's information. |
|
| 236 | + * @param bool $grouped Flag to distinguish between simple and grouped fields. |
|
| 237 | + * @param int $type Post or Term, based on the correct decorator would be selected. |
|
| 238 | + * @param int $id Identifier for the type. |
|
| 239 | + */ |
|
| 240 | + public function add_field( $args, $grouped, $type, $id ) { |
|
| 241 | + |
|
| 242 | + if ( $grouped ) { |
|
| 243 | + |
|
| 244 | + // Special fields (sameas, coordinates, etc.). |
|
| 245 | + // |
|
| 246 | + // Build Field with a custom class (e.g. WL_Metabox_Field_date). |
|
| 247 | + $field_class = 'Wl_Metabox_Field_' . key( $args ); |
|
| 248 | + |
|
| 249 | + } else { |
|
| 250 | + |
|
| 251 | + // Simple fields (string, uri, boolean, etc.). |
|
| 252 | + // |
|
| 253 | + // Which field? We want to use the class that is specific for the field. |
|
| 254 | + $meta = key( $args ); |
|
| 255 | + $this_meta = $args[ $meta ]; |
|
| 256 | + |
|
| 257 | + // If the field declares what metabox it wants, use that one. |
|
| 258 | + if ( isset( $this_meta['metabox']['class'] ) ) { |
|
| 259 | + |
|
| 260 | + $field_class = $this_meta['metabox']['class']; |
|
| 261 | + |
|
| 262 | + } elseif ( ! isset( $this_meta['type'] ) || Wordlift_Schema_Service::DATA_TYPE_STRING === $this_meta['type'] ) { |
|
| 263 | + |
|
| 264 | + // TODO: all fields should explicitly declare the required WL_Metabox. |
|
| 265 | + // When they will remove this. |
|
| 266 | + // |
|
| 267 | + // Use default Wl_Metabox_Field (manages strings). |
|
| 268 | + $field_class = 'Wl_Metabox_Field'; |
|
| 269 | + |
|
| 270 | + } else { |
|
| 271 | + |
|
| 272 | + // TODO: all fields should explicitly declare the required WL_Metabox. |
|
| 273 | + // When they will remove this. |
|
| 274 | + // |
|
| 275 | + // Build Field with a custom class (e.g. Wl_Metabox_Field_date). |
|
| 276 | + $field_class = 'Wl_Metabox_Field_' . $this_meta['type']; |
|
| 277 | + |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + /** |
|
| 281 | + * @since 3.31.6 |
|
| 282 | + * Add namespace to initialize class. |
|
| 283 | + */ |
|
| 284 | + /** |
|
| 285 | + * @since 3.31.6 |
|
| 286 | + * Add namespace to initialize class. |
|
| 287 | + */ |
|
| 288 | + if ( substr( $field_class, 0, 1 ) !== '\\' ) { |
|
| 289 | + $field_class = 'Wordlift\Metabox\Field\\' . $field_class; |
|
| 290 | + // End if(). |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + if ( class_exists( $field_class ) ) { |
|
| 294 | + // Get decorator and use it as wrapper for save_data and get_data methods. |
|
| 295 | + $instance = new $field_class( $args, $id, $type ); |
|
| 296 | + // Call apropriate constructor (e.g. Wl_Metabox_Field... ). |
|
| 297 | + $this->fields[] = $instance; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Save the form data for the specified entity {@link WP_Post}'s id. |
|
| 304 | + * |
|
| 305 | + * @param int $id The entity's {@link WP_Post}'s id. |
|
| 306 | + * |
|
| 307 | + * We're being called from WP `save_post` hook, we don't need to check the nonce. |
|
| 308 | + * |
|
| 309 | + * @param $type int Post or term |
|
| 310 | + * |
|
| 311 | + * @since 3.5.4 |
|
| 312 | + */ |
|
| 313 | + public function save_form_data( $id, $type ) { |
|
| 314 | + |
|
| 315 | + $this->log->trace( "Saving form data for entity post $id..." ); |
|
| 316 | + |
|
| 317 | + // Skip saving if the save is called for a different post. |
|
| 318 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 319 | + if ( isset( $_POST['post_ID'] ) && (int) $_POST['post_ID'] !== $id && Object_Type_Enum::POST === $type ) { |
|
| 320 | + $this->log->debug( '`wl_metaboxes`, skipping because the post id from request doesnt match the id from filter.' ); |
|
| 321 | + return; |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + // Build Field objects. |
|
| 325 | + $this->instantiate_fields( $id, $type ); |
|
| 326 | + |
|
| 327 | + // Check if WL metabox form was posted. |
|
| 328 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 329 | + if ( ! isset( $_POST['wl_metaboxes'] ) ) { |
|
| 330 | + $this->log->debug( '`wl_metaboxes`, skipping...' ); |
|
| 331 | + |
|
| 332 | + return; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 336 | + $posted_data = filter_var_array( $_POST, array( 'wl_metaboxes' => array( 'flags' => FILTER_REQUIRE_ARRAY ) ) ); |
|
| 337 | + $posted_data = $posted_data['wl_metaboxes']; |
|
| 338 | + foreach ( $this->fields as $field ) { |
|
| 339 | + |
|
| 340 | + // Verify nonce. |
|
| 341 | + $valid_nonce = $field->verify_nonce(); |
|
| 342 | + |
|
| 343 | + if ( $valid_nonce ) { |
|
| 344 | + $field_name = $field->meta_name; |
|
| 345 | + // Each Filed only deals with its values. |
|
| 346 | + if ( isset( $posted_data[ $field_name ] ) ) { |
|
| 347 | + |
|
| 348 | + $values = $posted_data[ $field_name ]; |
|
| 349 | + if ( ! is_array( $values ) ) { |
|
| 350 | + $values = array( $values ); |
|
| 351 | + } |
|
| 352 | + // Save data permanently |
|
| 353 | + $field->save_data( $values ); |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + /** |
|
| 359 | + * Filter: 'wl_save_form_pre_push_entity' - Allow to hook right |
|
| 360 | + * before the triples are pushed to the linked dataset. |
|
| 361 | + * |
|
| 362 | + * @param int $id The entity id. |
|
| 363 | + * @param int $id The post data. |
|
| 364 | + * |
|
| 365 | + * @since 3.18.2 |
|
| 366 | + */ |
|
| 367 | + // phpcs:ignore WordPress.Security.NonceVerification.Missing |
|
| 368 | + do_action( 'wl_save_form_pre_push_entity', $id, $_POST ); |
|
| 369 | + |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * Enqueue scripts and styles. |
|
| 374 | + * |
|
| 375 | + * @since 3.0.0 |
|
| 376 | + */ |
|
| 377 | + public function enqueue_scripts_and_styles() { |
|
| 378 | + |
|
| 379 | + // Use the minified version if PW_DEBUG isn't set. |
|
| 380 | + $min = ! defined( 'WP_DEBUG' ) || ! WP_DEBUG ? '.min' : ''; |
|
| 381 | + |
|
| 382 | + // Load the jquery-ui-timepicker-addon library. |
|
| 383 | + wp_enqueue_style( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.css", array(), '3.0.6' ); |
|
| 384 | + wp_enqueue_script( 'wl-flatpickr', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . "/admin/js/flatpickr/flatpickr$min.js", array( 'jquery' ), '3.0.6', true ); |
|
| 385 | + |
|
| 386 | + wl_enqueue_leaflet(); |
|
| 387 | + |
|
| 388 | + // Add AJAX autocomplete to facilitate metabox editing. |
|
| 389 | + wp_enqueue_script( 'wl-entity-metabox-utility', dirname( dirname( plugin_dir_url( __FILE__ ) ) ) . '/admin/js/wl_entity_metabox_utilities.js', array(), WORDLIFT_VERSION, false ); |
|
| 390 | + wp_localize_script( |
|
| 391 | + 'wl-entity-metabox-utility', |
|
| 392 | + 'wlEntityMetaboxParams', |
|
| 393 | + array( |
|
| 394 | + 'ajax_url' => admin_url( 'admin-ajax.php' ), |
|
| 395 | + 'action' => 'entity_by_title', |
|
| 396 | + ) |
|
| 397 | + ); |
|
| 398 | + |
|
| 399 | + } |
|
| 400 | 400 | } |
@@ -14,114 +14,114 @@ |
||
| 14 | 14 | |
| 15 | 15 | class Entity_Query_Service { |
| 16 | 16 | |
| 17 | - private static $instance = null; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * The singleton instance. |
|
| 21 | - * |
|
| 22 | - * @return Entity_Query_Service |
|
| 23 | - */ |
|
| 24 | - public static function get_instance() { |
|
| 25 | - if ( ! isset( self::$instance ) ) { |
|
| 26 | - self::$instance = new self(); |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - return self::$instance; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - private function query_posts( $query, $schema_types, $limit ) { |
|
| 33 | - return wl_entity_get_by_title( $query, true, true, $limit, $schema_types ); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - private function query_terms( $query, $schema_types, $limit ) { |
|
| 37 | - global $wpdb; |
|
| 38 | - $schema_types = join( |
|
| 39 | - ',', |
|
| 40 | - array_map( |
|
| 41 | - function ( $schema_type ) { |
|
| 42 | - return "'" . esc_sql( strtolower( $schema_type ) ) . "'"; |
|
| 43 | - }, |
|
| 44 | - $schema_types |
|
| 45 | - ) |
|
| 46 | - ); |
|
| 47 | - |
|
| 48 | - return $wpdb->get_results( |
|
| 49 | - $wpdb->prepare( |
|
| 50 | - "SELECT DISTINCT t.term_id as id, t.name as title, tm.meta_value as schema_type_name FROM $wpdb->terms t INNER JOIN $wpdb->termmeta tm |
|
| 17 | + private static $instance = null; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * The singleton instance. |
|
| 21 | + * |
|
| 22 | + * @return Entity_Query_Service |
|
| 23 | + */ |
|
| 24 | + public static function get_instance() { |
|
| 25 | + if ( ! isset( self::$instance ) ) { |
|
| 26 | + self::$instance = new self(); |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + return self::$instance; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + private function query_posts( $query, $schema_types, $limit ) { |
|
| 33 | + return wl_entity_get_by_title( $query, true, true, $limit, $schema_types ); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + private function query_terms( $query, $schema_types, $limit ) { |
|
| 37 | + global $wpdb; |
|
| 38 | + $schema_types = join( |
|
| 39 | + ',', |
|
| 40 | + array_map( |
|
| 41 | + function ( $schema_type ) { |
|
| 42 | + return "'" . esc_sql( strtolower( $schema_type ) ) . "'"; |
|
| 43 | + }, |
|
| 44 | + $schema_types |
|
| 45 | + ) |
|
| 46 | + ); |
|
| 47 | + |
|
| 48 | + return $wpdb->get_results( |
|
| 49 | + $wpdb->prepare( |
|
| 50 | + "SELECT DISTINCT t.term_id as id, t.name as title, tm.meta_value as schema_type_name FROM $wpdb->terms t INNER JOIN $wpdb->termmeta tm |
|
| 51 | 51 | ON t.term_id=tm.term_id WHERE t.name LIKE %s AND (tm.meta_key = %s AND tm.meta_value IN ($schema_types)) LIMIT %d", // phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared |
| 52 | - '%' . $wpdb->esc_like( $query ) . '%', |
|
| 53 | - \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 54 | - $limit |
|
| 55 | - ) |
|
| 56 | - ); |
|
| 57 | - |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @param $results |
|
| 62 | - * @param $object_type |
|
| 63 | - * |
|
| 64 | - * @return Entity[] |
|
| 65 | - */ |
|
| 66 | - private function transform_posts( $results ) { |
|
| 67 | - return array_map( |
|
| 68 | - function ( $item ) { |
|
| 69 | - return new Entity( $item->schema_type_name, new Wordpress_Content( get_post( $item->id ) ) ); |
|
| 70 | - }, |
|
| 71 | - $results |
|
| 72 | - ); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - private function transform_terms( $results ) { |
|
| 76 | - return array_map( |
|
| 77 | - function ( $item ) { |
|
| 78 | - return new Entity( $item->schema_type_name, new Wordpress_Content( get_term( $item->id ) ) ); |
|
| 79 | - }, |
|
| 80 | - $results |
|
| 81 | - ); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @param $query |
|
| 86 | - * @param $schema_types |
|
| 87 | - * @param $limit |
|
| 88 | - * |
|
| 89 | - * @return Entity[] |
|
| 90 | - */ |
|
| 91 | - public function query( $query, $schema_types = array(), $limit = 10 ) { |
|
| 92 | - |
|
| 93 | - $results = $this->transform_posts( $this->query_posts( $query, $schema_types, $limit ) ); |
|
| 94 | - |
|
| 95 | - if ( count( $results ) >= $limit ) { |
|
| 96 | - return $results; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $results = array_merge( $results, $this->transform_terms( $this->query_terms( $query, $schema_types, $limit ) ) ); |
|
| 100 | - |
|
| 101 | - return $results; |
|
| 102 | - |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - public function get( $linked_entities ) { |
|
| 106 | - return array_filter( |
|
| 107 | - array_map( |
|
| 108 | - function ( $item ) { |
|
| 109 | - $parts = explode( '_', $item ); |
|
| 110 | - $type = Object_Type_Enum::from_string( $parts[0] ); |
|
| 111 | - $identifier = $parts[1]; |
|
| 112 | - |
|
| 113 | - if ( $type === Object_Type_Enum::POST ) { |
|
| 114 | - return new Entity( 'Thing', new Wordpress_Content( get_post( $identifier ) ) ); |
|
| 115 | - } elseif ( $type === Object_Type_Enum::TERM ) { |
|
| 116 | - return new Entity( 'Thing', new Wordpress_Content( get_term( $identifier ) ) ); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - // return new Entity( $item->schema_type_name, new Wordpress_Content( get_term( $item->id ) ) ); |
|
| 120 | - }, |
|
| 121 | - $linked_entities |
|
| 122 | - ) |
|
| 123 | - ); |
|
| 124 | - |
|
| 125 | - } |
|
| 52 | + '%' . $wpdb->esc_like( $query ) . '%', |
|
| 53 | + \Wordlift_Entity_Type_Taxonomy_Service::TAXONOMY_NAME, |
|
| 54 | + $limit |
|
| 55 | + ) |
|
| 56 | + ); |
|
| 57 | + |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @param $results |
|
| 62 | + * @param $object_type |
|
| 63 | + * |
|
| 64 | + * @return Entity[] |
|
| 65 | + */ |
|
| 66 | + private function transform_posts( $results ) { |
|
| 67 | + return array_map( |
|
| 68 | + function ( $item ) { |
|
| 69 | + return new Entity( $item->schema_type_name, new Wordpress_Content( get_post( $item->id ) ) ); |
|
| 70 | + }, |
|
| 71 | + $results |
|
| 72 | + ); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + private function transform_terms( $results ) { |
|
| 76 | + return array_map( |
|
| 77 | + function ( $item ) { |
|
| 78 | + return new Entity( $item->schema_type_name, new Wordpress_Content( get_term( $item->id ) ) ); |
|
| 79 | + }, |
|
| 80 | + $results |
|
| 81 | + ); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @param $query |
|
| 86 | + * @param $schema_types |
|
| 87 | + * @param $limit |
|
| 88 | + * |
|
| 89 | + * @return Entity[] |
|
| 90 | + */ |
|
| 91 | + public function query( $query, $schema_types = array(), $limit = 10 ) { |
|
| 92 | + |
|
| 93 | + $results = $this->transform_posts( $this->query_posts( $query, $schema_types, $limit ) ); |
|
| 94 | + |
|
| 95 | + if ( count( $results ) >= $limit ) { |
|
| 96 | + return $results; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $results = array_merge( $results, $this->transform_terms( $this->query_terms( $query, $schema_types, $limit ) ) ); |
|
| 100 | + |
|
| 101 | + return $results; |
|
| 102 | + |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + public function get( $linked_entities ) { |
|
| 106 | + return array_filter( |
|
| 107 | + array_map( |
|
| 108 | + function ( $item ) { |
|
| 109 | + $parts = explode( '_', $item ); |
|
| 110 | + $type = Object_Type_Enum::from_string( $parts[0] ); |
|
| 111 | + $identifier = $parts[1]; |
|
| 112 | + |
|
| 113 | + if ( $type === Object_Type_Enum::POST ) { |
|
| 114 | + return new Entity( 'Thing', new Wordpress_Content( get_post( $identifier ) ) ); |
|
| 115 | + } elseif ( $type === Object_Type_Enum::TERM ) { |
|
| 116 | + return new Entity( 'Thing', new Wordpress_Content( get_term( $identifier ) ) ); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + // return new Entity( $item->schema_type_name, new Wordpress_Content( get_term( $item->id ) ) ); |
|
| 120 | + }, |
|
| 121 | + $linked_entities |
|
| 122 | + ) |
|
| 123 | + ); |
|
| 124 | + |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | 127 | } |
@@ -7,40 +7,40 @@ |
||
| 7 | 7 | |
| 8 | 8 | class Entity { |
| 9 | 9 | |
| 10 | - private $schema_type; |
|
| 11 | - /** |
|
| 12 | - * @var Wordpress_Content |
|
| 13 | - */ |
|
| 14 | - private $content; |
|
| 15 | - |
|
| 16 | - /** |
|
| 17 | - * @param $schema_type |
|
| 18 | - * @param $content Wordpress_Content |
|
| 19 | - */ |
|
| 20 | - public function __construct( $schema_type, $content ) { |
|
| 21 | - $this->schema_type = $schema_type; |
|
| 22 | - $this->content = $content; |
|
| 23 | - } |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @return Wordpress_Content |
|
| 27 | - */ |
|
| 28 | - public function get_content() { |
|
| 29 | - return $this->content; |
|
| 30 | - } |
|
| 31 | - |
|
| 32 | - public function get_schema_type() { |
|
| 33 | - return $this->schema_type; |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - public function get_title() { |
|
| 37 | - if ( Object_Type_Enum::POST === $this->content->get_object_type_enum() ) { |
|
| 38 | - return $this->content->get_bag()->post_title; |
|
| 39 | - } |
|
| 40 | - if ( Object_Type_Enum::TERM === $this->content->get_object_type_enum() ) { |
|
| 41 | - return $this->content->get_bag()->name; |
|
| 42 | - } |
|
| 43 | - return ''; |
|
| 44 | - } |
|
| 10 | + private $schema_type; |
|
| 11 | + /** |
|
| 12 | + * @var Wordpress_Content |
|
| 13 | + */ |
|
| 14 | + private $content; |
|
| 15 | + |
|
| 16 | + /** |
|
| 17 | + * @param $schema_type |
|
| 18 | + * @param $content Wordpress_Content |
|
| 19 | + */ |
|
| 20 | + public function __construct( $schema_type, $content ) { |
|
| 21 | + $this->schema_type = $schema_type; |
|
| 22 | + $this->content = $content; |
|
| 23 | + } |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @return Wordpress_Content |
|
| 27 | + */ |
|
| 28 | + public function get_content() { |
|
| 29 | + return $this->content; |
|
| 30 | + } |
|
| 31 | + |
|
| 32 | + public function get_schema_type() { |
|
| 33 | + return $this->schema_type; |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + public function get_title() { |
|
| 37 | + if ( Object_Type_Enum::POST === $this->content->get_object_type_enum() ) { |
|
| 38 | + return $this->content->get_bag()->post_title; |
|
| 39 | + } |
|
| 40 | + if ( Object_Type_Enum::TERM === $this->content->get_object_type_enum() ) { |
|
| 41 | + return $this->content->get_bag()->name; |
|
| 42 | + } |
|
| 43 | + return ''; |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | 46 | } |
@@ -21,36 +21,36 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class Wl_Metabox extends Wl_Abstract_Metabox { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * WL_Metabox constructor. |
|
| 26 | - * |
|
| 27 | - * @since 3.1.0 |
|
| 28 | - */ |
|
| 29 | - public function __construct() { |
|
| 30 | - parent::__construct(); |
|
| 31 | - /** |
|
| 32 | - * Filter: wl_feature__enable__metabox. |
|
| 33 | - * |
|
| 34 | - * @param bool whether the metabox should be shown, defaults to true. |
|
| 35 | - * |
|
| 36 | - * @return bool |
|
| 37 | - * @since 3.28.1 |
|
| 38 | - */ |
|
| 39 | - if ( apply_filters( 'wl_feature__enable__metabox', true ) && ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 40 | - |
|
| 41 | - // Add hooks to print metaboxes and save submitted data. |
|
| 42 | - add_action( 'add_meta_boxes', array( $this, 'add_main_metabox' ) ); |
|
| 43 | - add_action( 'wl_linked_data_save_post', array( $this, 'save_form' ) ); |
|
| 44 | - |
|
| 45 | - // Enqueue js and css. |
|
| 46 | - $this->enqueue_scripts_and_styles(); |
|
| 47 | - |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - public function save_form( $post_id ) { |
|
| 53 | - $this->save_form_data( $post_id, Object_Type_Enum::POST ); |
|
| 54 | - } |
|
| 24 | + /** |
|
| 25 | + * WL_Metabox constructor. |
|
| 26 | + * |
|
| 27 | + * @since 3.1.0 |
|
| 28 | + */ |
|
| 29 | + public function __construct() { |
|
| 30 | + parent::__construct(); |
|
| 31 | + /** |
|
| 32 | + * Filter: wl_feature__enable__metabox. |
|
| 33 | + * |
|
| 34 | + * @param bool whether the metabox should be shown, defaults to true. |
|
| 35 | + * |
|
| 36 | + * @return bool |
|
| 37 | + * @since 3.28.1 |
|
| 38 | + */ |
|
| 39 | + if ( apply_filters( 'wl_feature__enable__metabox', true ) && ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 40 | + |
|
| 41 | + // Add hooks to print metaboxes and save submitted data. |
|
| 42 | + add_action( 'add_meta_boxes', array( $this, 'add_main_metabox' ) ); |
|
| 43 | + add_action( 'wl_linked_data_save_post', array( $this, 'save_form' ) ); |
|
| 44 | + |
|
| 45 | + // Enqueue js and css. |
|
| 46 | + $this->enqueue_scripts_and_styles(); |
|
| 47 | + |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + public function save_form( $post_id ) { |
|
| 53 | + $this->save_form_data( $post_id, Object_Type_Enum::POST ); |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | } |
@@ -12,51 +12,51 @@ |
||
| 12 | 12 | |
| 13 | 13 | class Term_Metabox extends Wl_Abstract_Metabox { |
| 14 | 14 | |
| 15 | - public function __construct() { |
|
| 16 | - parent::__construct(); |
|
| 17 | - if ( ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 18 | - add_action( 'init', array( $this, 'init_all_custom_fields' ) ); |
|
| 19 | - } |
|
| 20 | - |
|
| 21 | - } |
|
| 22 | - |
|
| 23 | - /** |
|
| 24 | - * @param $term \WP_Term |
|
| 25 | - */ |
|
| 26 | - public function render_ui( $term ) { |
|
| 27 | - |
|
| 28 | - $this->instantiate_fields( $term->term_id, Object_Type_Enum::TERM ); |
|
| 29 | - $this->html(); |
|
| 30 | - $this->enqueue_scripts_and_styles(); |
|
| 31 | - $plugin = \Wordlift::get_instance(); |
|
| 32 | - |
|
| 33 | - // Enqueue this scripts for sameas fields. |
|
| 34 | - wp_enqueue_script( |
|
| 35 | - 'wl-autocomplete-select', |
|
| 36 | - plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/autocomplete-select.js', |
|
| 37 | - array(), |
|
| 38 | - $plugin->get_version(), |
|
| 39 | - true |
|
| 40 | - ); |
|
| 41 | - |
|
| 42 | - wp_enqueue_style( |
|
| 43 | - 'wl-autocomplete-select', |
|
| 44 | - plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/autocomplete-select.css', |
|
| 45 | - array(), |
|
| 46 | - $plugin->get_version() |
|
| 47 | - ); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - public function save_field( $term_id ) { |
|
| 51 | - $this->save_form_data( $term_id, Object_Type_Enum::TERM ); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - public function init_all_custom_fields() { |
|
| 55 | - $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
| 56 | - foreach ( $taxonomies as $taxonomy ) { |
|
| 57 | - add_action( "${taxonomy}_edit_form", array( $this, 'render_ui' ), 1 ); |
|
| 58 | - add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
| 59 | - } |
|
| 60 | - } |
|
| 15 | + public function __construct() { |
|
| 16 | + parent::__construct(); |
|
| 17 | + if ( ! apply_filters( 'wl_feature__enable__pods-integration', false ) ) { //phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores |
|
| 18 | + add_action( 'init', array( $this, 'init_all_custom_fields' ) ); |
|
| 19 | + } |
|
| 20 | + |
|
| 21 | + } |
|
| 22 | + |
|
| 23 | + /** |
|
| 24 | + * @param $term \WP_Term |
|
| 25 | + */ |
|
| 26 | + public function render_ui( $term ) { |
|
| 27 | + |
|
| 28 | + $this->instantiate_fields( $term->term_id, Object_Type_Enum::TERM ); |
|
| 29 | + $this->html(); |
|
| 30 | + $this->enqueue_scripts_and_styles(); |
|
| 31 | + $plugin = \Wordlift::get_instance(); |
|
| 32 | + |
|
| 33 | + // Enqueue this scripts for sameas fields. |
|
| 34 | + wp_enqueue_script( |
|
| 35 | + 'wl-autocomplete-select', |
|
| 36 | + plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/autocomplete-select.js', |
|
| 37 | + array(), |
|
| 38 | + $plugin->get_version(), |
|
| 39 | + true |
|
| 40 | + ); |
|
| 41 | + |
|
| 42 | + wp_enqueue_style( |
|
| 43 | + 'wl-autocomplete-select', |
|
| 44 | + plugin_dir_url( dirname( __DIR__ ) ) . 'js/dist/autocomplete-select.css', |
|
| 45 | + array(), |
|
| 46 | + $plugin->get_version() |
|
| 47 | + ); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + public function save_field( $term_id ) { |
|
| 51 | + $this->save_form_data( $term_id, Object_Type_Enum::TERM ); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + public function init_all_custom_fields() { |
|
| 55 | + $taxonomies = Terms_Compat::get_public_taxonomies(); |
|
| 56 | + foreach ( $taxonomies as $taxonomy ) { |
|
| 57 | + add_action( "${taxonomy}_edit_form", array( $this, 'render_ui' ), 1 ); |
|
| 58 | + add_action( "edited_${taxonomy}", array( $this, 'save_field' ) ); |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | } |