Permalink
Switch branches/tags
Stoyan0v-feature/468_add-schema-org-website-markup develop feature-/547_Validate-URIs feature/add-keywords-screen-sagas feature/add-keywords-screen feature/add-woocommerce-plugin-filters feature/fix-failing-tests feature/120_changing-entity-type-from-wp-backend-creates-an-inconsistent-situation feature/125_personalize_the_entity_path feature/212_Adding-support-for-the-Accelerated-Mobile-Pages-(AMP)-on-WordLift-Entity-Pages feature/230_download_your_data_from_wordlift feature/278-when-creating-a-new-entity-the-duplicate-warning-appears-for-entity-that-have-been-trashed feature.291_The-calendar-for-startDate-and-endDate-of-an-event-cannot-be-used-for-historical-events feature/296_cant-create-new-entity-over-existing-annotation feature/305_Entity-Types'-widget-should-be-flat feature/305_entity-types-should-be-flat feature/306-entities-from-the-internal-vocabulary-are-not-properly-detected feature/310_favour-jsonld-in-place-of-microdata feature/323_Content-dynamically-posted-should-follow-both-a-chronological-or-a-relevancy-order feature/339_improving_the_import_export_of_the_user_vocabulary feature/342_data_migration feature/343_disable_wikipedia_images feature/345_entity-suggested-when-analyzing-the-content-entity-itself feature/346_add_two_properties feature/349-remove-all-unsupported-languages-from-the-settings feature/352_improve-design-of-the-timeline-widget feature/354_improve-the-navigator-widget-by-adding-links-to-the-images feature/355_Creating-a-Tag-Like-Widget-for-articles feature/369_remove-the-unused-indepth-file feature/370_upgrade-timelinejs-to-3x feature/371_extending-the-list-of-schema-article-properties feature/372_the-layout-of-the-navigator-messes-up-with-long-entity-titles feature/376_Enable-revisions-for-entities feature/383_chord-overlapping-issue feature/389_remove-jetpacks-related-posts-from-entity-pages feature/395-author-missing-from-entities-edit-pages feature/397-review-wordlifts-setup-process feature/398_SEO-improvement--providing-control-over-title-and-description-of-WordLift-Archive-pages- feature/403_Adding-legalName-for-Organization-and-LocalBusiness feature/404_navigator-widget feature/408-remove-the-caching-module feature/412_add-a-toggle-to-disable-wordlift-analysis-on-certain-pages-posts_switch feature/412_add-a-toggle-to-disable-wordlift-analysis-on-certain-pages-posts feature/417-integrate-e2e-tests-in-wordlift feature/418_Do-not-allow-activating-WordLift-on-incompatible-WP's-versions feature/425-move-the-traslator-server-side feature/426_related-articles-needs-to-be-limited-and-or-paginated feature/427_Add-Publisher-field-to-WordLift-Setting-page feature/432_fix-empty-span-issue feature/437_some-found-entities-lack-the-related-text-annotation feature/438_autocomplete-fails-in-metaboxes feature/440_text-annotations-are-too-invasive feature/442_Enable-WordPress-Category-to-Organise-WordLift-Entities feature/446_return-value-of-wl_schema_get_value-not-always-check-to-not-be-null feature/447_Enqueue-of-styles-and-JS-should-be-more-selective-and-limited-to-content-editing-screens feature/447_enqueue-of-styles-and-js-should-be-more-selective feature/451_improve-schema-article-markup feature/453_Need-to-show-alert-and-have-recovery-plan-when-setting/activation-fail-to-get-dataset-uri feature/457_When-the-plugin-is-installed-in-a-directory-not-named--wordlift--initializaton-hook-ignored feature/467_manually-select-an-entity feature/469_chord-rendering-problem-on-firefox feature/477_preserve-alternative-labels feature/481_Improve-authors feature/482_Global-timeline-doesn't-include-events-bound-to-pages feature/484_Check-compatibility-with-WordPress-Multisite-configurations feature/485_add-the-possibility-to-configure-nolink-by-default feature/487_Adding-support-for-editing-categories-when-using-Quick-Edit-from-the-Vocabulary feature/488_make-download-data-more-user-friendly feature/490_Adding-the--WordLift-Entities-Cloud--as-shortcode feature/501_php7-compatibility-check feature/503_Text-domain-is-missing-in-calls-to-_x-translation-API feature/510_add-support-for-reverse feature/511_add-support-for-the-about-property feature/512_Entity-type-listing-page-shows-an--access-not-allowed--in-wordpress-versions-before-4.7 feature/513_synonyms-in-json-ld feature/514_replace-zero-with-plus feature/516_Visual-Composer-tags-appearing-in-the-article's-description feature/518_add-the-type-when-2-or-more-entities-have-the-same-title-using-react feature/518_add-the-type-when-there-are-two-entities-with-same-title feature/524_Adding-support-for-schema.org/Recipe- feature/525_Content-dynamically-posted-should-follow-a-relevancy-order feature/526_Multisite-network-activation-fails-to-create-the-entity-types-on-newly-created-subsites- feature/531_fix-broken-second-chord-widget feature/533_Add-the-schema-wordCount-property-to-schema-Article feature/534_inform-the-editor-when-a-subscription-is-not-active feature/536_hide-labels-that-do-not-have-associated-entities-in-the-faceted-search-widget feature/537_translate-all-labels-in-plugin-faceted-search feature/541_amp-version-of-a-page-with-a-map-displays-a-gray-box feature/546_extend-the-json-ld-and-allow-customizations feature/550_limit-the-number-of-entities feature/552_make-a-content-data-export-compatible-with-google-analytics feature/552_make-content-data-export-comp-with-google feature/558_Link-to-the-settings-page-in-the-message-about-unset-key feature_561/Add-the-capability-to-create-new-entities-in-the-vocabulary- feature/562_Annotate_archival_content_using_my_vocabulary feature/583_Add-sameAs-to-schema.org/publisher-in-JSON-LD feature/584_Adding-aliases-as-link-TITLE-attributes- feature/586_adding-support-for-the-locationcreated-attribute-on-articles feature/587_Sort-entities-in-the-vocabulary-using-an-alphabetical-order feature/595_import-may-fail-with-many-posts-pages feature/#596_Associate-posts-with-entity-raxonomy/leta-post-to-be-equivalent-to-an-entity feature/597-crop-publisher-logo-to-recommended-dimensions feature/597-crop-publisher-logo feature/599_revising-the-order-of-proposed-entities feature/603_rebuild-the-relations-table feature/606_batch-analysis-on-all-posts feature/607_add-autocomplete-api feature/608_integrate-the-autocomplete-widget_try-react-boilerplate feature/608_integrate-the-autocomplete-widget feature/610_Type-in-xsd-dateTime feature/612_Improve-the-performance-of-the-Content-Filter-and-JSON-LD-Generation feature/617_PHP-Notice--ob_clean()--failed-to-delete-buffer feature/618_limit-faceted-search-results feature/626_Cache-JSON-LD,-introduce-an-explicit-caching-layer feature/627_Set-minimal-supported-wordpress-version-to-4.4 feature/631_fix-weird-occurrences-count-box feature/634_add-bulgarian-translation feature/642_allow-to-disable-json-ld feature/644-entities-not-showing-in-classification-box feature/666_chord-shortcode-uses-a-non-existing-post-status-of--published- feature/681-add-editors-wl-entity-read-permissions feature/681-fix-edit-screen-entity-permalink feature/682_capture-the-web-site-url feature/688_various_unit_test_failures feature/702-update-relation-table-when-post-is-deleted feature/713-allow-to-configure-the-target-country feature/715-add-custom-images-directory feature/716-invalidate-cache-in-batch-analysis feature/717-autofix-interpolation-errors feature/719-set-default-entity-type-in-batch-analysis feature/720-add-batch-analysis-filters feature/721-add-minimum-occurences-filter feature/722-batch-analysis-hook-for-updated-entities feature/724-batch-analysis-updates feature/726-set-post-types-to-batch-analysis feature/728-Gutenberg-Integration feature/729-mark-posts-without-content-as-completed-in-batch-analysis feature/736_add-an-option-to-link-only-the-first-entity-occurrence feature/739_change-the-color-background-of-the-wizards-grab-a-key-button-and-link-it-to-the-pricing-page feature/743-flush-cache-when-permalink-structure-is-changed feature/750-add-filters-to-allow-adding-custom-properties feature/752_2nd-level-properties-not-added-to-the-cloud-dataset feature/757-php-7-2-compatibility feature/759-add-offers-and-performer-for-events feature/760_add-a-reference-to-the-articles-being-annotated feature/761_search-rankings-dashboard-page feature/767-add-feedback-screen feature/768-refactor-core-install feature/769-move-wl-insert-triples-filter feature/772-allow-entity-grouping-by-category-in-vocabulary-widget feature/778-set-entities-order-in-vocabulary-widget feature/779-remove-logs-from-abstract-wordlift-install feature/780-add-missing-colons feature/786-add-name-properties-to-linked-dataset feature/787-add-more-recipe-properties feature/788-add-hook-to-wl-metaboxes-save-form feature/790-allow-multiple-gloassary-widgets-in-one-page feature/790-fix-two-vocabulary-widgets feature/791-add-delete-posts-capability-to-entity-post-type feature/792-remove-wl_admin_inject_chord_dialog_dependencies feature/793-convert-html-entities-in-jsonld feature/794-fix-vocabulary-shortcode-order feature/795_display-latest-blog-posts-from-our-website feature/797-assign-article-term-to-posts feature/800-replace-admin-ajax-with-wl-api feature/801-exclude-the-current-post-type-from-bad-slug-post-types feature/801-prevent-post-types-slug-to-match-the-archive-page-slugs feature/803-revise-recipe-structure feature/806-image-in-jsonld-is-missing feature/815_add-wl-schemas-hook feature/830_improve-image-markup-on-amp-pages-to-enhance-the-appearance-in-google-search-results feature/835_add-the-all-entity-types-metabox feature/842_exclude-wordlift-public-bundle-from-wp-rocket-defer feature/848_add-a-filter-to-allow-3rd-parties-to-change-the-TinyMCE-editor-id feature/850_allow-3rd-parties-to-change-the-site-url-and-post-permalink feature/851_add-a-filter-to-allow-3rd-parties-to-change-the-TinyMCE-editor-id-via-JavaScript feature/852_Post-Type-to-Entity-Type-mapping feature/858_WMT-and-SDTT-complain-about-wrong-type-for-location-bound-Places feature/866-Navigator-AMP feature/867-Faceted-Search-AMP feature/868_Remove-wlSettings-from-WP-Rocket-inline-optimization feature/871_add-wordlift-json-ld-markup-to-amp-pages gh-pages hotfix/add-missing-calendar-to-date-field hotfix/fix-post-status-when-post-is-deleted hotfix/prevent-notice-on-initial-install hotfix/prevent-topic-entities-to-cause-fatal-error hotfix/update-translations hotfix/262_posting_a_site_url_on_googleplus_uses_an_entity_title_instead_of_the_post_title hotfix/265_entity_person_created_before_publishing_organization hotfix/282_wrong_entity_url hotfix/318_faceted_search_not_working_on_entity_pages hotfix/333_germanic_umlaut_causing_troubles_when_saving_sameas_links hotfix/334 hotfix/336_navigator_widget_doesnt_show hotfix/340_incompatible_date_widget hotfix/348_double_link hotfix/351_text-annotations-missing-for-found-entities hotfix/363_synonyms_associated_to_other_entities hotfix/366_text-annotations-not-set-with-fusion-core hotfix/368_adding-unneeded-p-tag-for-entity-properties hotfix/382_analysis-error-on-coffee-brewing-methods-com hotfix/386_linked-data-not-saved hotfix/406_jsonld-response-corrupt hotfix/410_triples-not-working-on-the-wordlift-dashboard hotfix/415-wordlift-not-working-after-updating-to-47 hotfix/418-do-not-allow-activating-wordlift-on-incompatible-wp-versions hotfix/429-german-missing-in-supported-languages-list hotfix/430-analysis-selectors-messed-up-in-wp-45-and-lower hotfix/439_entity-preview-is-redirected-to-post hotfix/443_chord-height-is-fixed-when-global-true hotfix/461_entities-highlighted-in-front-end hotfix/462_find-duplicated-entities hotfix/479_entity-slug-changed-by-the-system hotfix/494_cached-html-templates hotfix/495_additional-left-padding-on-entity-tiles hotfix/496_wl-highlight-classes-conflict-with-themes hotfix/497_aggressive-caching-may-serve-old-files hotfix/500_setup_wiard_long_text hotfix/520_selected-entities-lost-with-ie11-and-edge hotfix/521_performance-issues-on-ajax-end-point hotfix/527_error-fetching-angular-animate hotfix/528_fsockopen-loops-indefinitely hotfix/535_incorrect-text-annotation-styles-in-editor hotfix/543_entities-not-published-to-the-linked-data-store hotfix/549_make-wl-compatible-with-wp-4-8 hotfix/556_sparql-queries-fail hotfix/568_trying-to-get-property-of-non-object hotfix/569_explicitly-enabling-an-entity-link-doesnt-work hotfix/570_access-denied-on-wordlift-configuration-screen hotfix/571_faceted-search-not-displaying-correctly hotfix/575_cron-is-unreliable-on-some-web-sites hotfix/576_error-404-on-a-woocommerce-product-page hotfix/577_faceted-search-posts-list-doesnt-show hotfix/593_recipes-mentioned-in-posts-pages-do-not-appear-in-the-json-ld hotfix/601_improve-the-batch-analysis-service hotfix/611_WordLift-slowing-down-RSS-feed hotfix/615_Faceted-Search-generates-a-SQL-error hotfix/633_colon-in-html-messes-the-analysis hotfix/643_Notices-on-capabilities- hotfix/644-entities-not-showing-in-classification-box hotfix/647-remove-duplicate-related-posts hotfix/654_entity-link-always-returning-the-last-blog-post hotfix/661_Ignore-sticky-posts-when-querying-for-entities hotfix/662_old-articles-appear-in-vocabulary hotfix/663_terms-query-may-slow-down-site hotfix/683_incompatibility-with-formidable-forms hotfix/694_permalinks-on-edit-screen-do-not-work-on-fresh-installs hotfix/699_font-awesome-on-the-front-end-may-conflict-with-themes hotfix/707_performance-degrades-in-combination-with-yoast hotfix/711_performance-issues-with-content-filter hotfix/758_amp_post_template_css-casues-php-warning hotfix/770-autocomplete-issue-with-french-symbols-in-link hotfix/771_issue-with-the-typographical-superscript hotfix/773-move-php72-test-to-allowed-failures hotfix/774-update-entity-author-on-user-author-update hotfix/776-jsonld-generation-raises-warning hotfix/777-exit-after-redirecting-to-edit-entity-page hotfix/785-fix-sameas-field hotfix/789-prevent-entities-from-being-set-to-draft hotfix/794-fit-vocabulary-shortcode-order hotfix/802_fix-locales hotfix/818_deleted-entities-appear-as-numbers-in-metaboxes hotfix/819_when-a-post-is-converted-into-entity hotfix/820_wl-api-lost-when-plugin-deactivated-and-activated-back-again hotfix/823_logo-not-available-in-referenced-publisher hotfix/840_wl-api-referenced-using-siteurl-instead-of-homeurl hotfix/846_on-deactivate-ensure-to-delete-the-wl-api-option hotfix/865_Content-Egg-s-angular-clashes-with-WordLift-s-angular jpmacleure-hotfix/565_allow_empty_vocabulary_path_on_compatible_permalink_configuration markkap-#447_limit_enqueue_to_post_edit master purgatory release/3.1.0 release/3.2 release/3.3 release/3.4 release/3.5 release/3.6 release/3.7.0 release/3.8.0 release/3.9.0 release/3.9.6 release/3.10.0 release/3.11.0 release/3.11.1 release/3.11.2 release/3.11.3 release/3.12.0 release/3.12.1 release/3.12.2 release/3.12.3 release/3.12.4 release/3.13.0 release/3.13.1 release/3.13.2 release/3.13.3 release/3.14.0 release/3.14.1 release/3.14.2 release/3.14.3 release/3.14.4 release/3.14.5 release/3.14.6 release/3.15.0 release/3.15.1 release/3.15.2 release/3.15.3 release/3.15.4 release/3.15.5 release/3.15.6 release/3.16.0 release/3.16.1 release/3.16.2 release/3.16.3 release/3.16.4 release/3.16.5 release/3.17.0 release/3.17.1 release/3.17.2 release/3.17.3 release/3.18.0 release/3.18.1 release/3.18.2 release/3.18.3 release/3.18.4 release/3.18.5 release/3.18.6 release/3.19.0 release/3.19.1 release/3.19.2 release/3.19.3 release/3.19.4 release/3.19.5 release/3.19.6 release/3.20.0 revert-649-hotfix/644-entities-not-showing-in-classification-box svn tmp
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
164 lines (132 sloc) 4.81 KB
<?php
/**
* Schema API functions.
*
* @since 3.0.0
* @package Wordlift
* @subpackage Wordlift/modules/core
*/
/**
* Retrieves the value of the specified property for the entity.
*
* @param int $post_id The numeric post ID.
* @param string $property_name Name of the property (e.g. name, for the http://schema.org/name property).
*
* @return array|null An array of values or NULL in case of no values (or error).
*/
function wl_schema_get_value( $post_id, $property_name ) {
// Property name must be defined.
if ( ! isset( $property_name ) || is_null( $property_name ) ) {
return null;
}
// store eventual schema name in different variable
$property_schema_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
// Establish entity id.
if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) {
$post_id = get_the_ID();
if ( is_null( $post_id ) || ! is_numeric( $post_id ) ) {
return null;
}
}
// Get custom fields.
$term_mapping = wl_entity_taxonomy_get_custom_fields( $post_id );
// Search for the required meta value (by constant name or schema name)
foreach ( $term_mapping as $wl_constant => $property_info ) {
$found_constant = ( $wl_constant == $property_name );
$found_predicate = ( isset( $property_info['predicate'] ) && $property_info['predicate'] == $property_schema_name );
if ( $found_constant || $found_predicate ) {
return get_post_meta( $post_id, $wl_constant );
}
}
return null;
}
/**
* Set the value for the specified property and post ID, deleting what was there before.
*
* @param int $post_id The numeric post ID.
* @param string $property_name Name of the property (e.g. name, for the http://schema.org/name property)
* @param mixed $property_value Value to save into the property.
*
* @return boolean The method returns true if everything went ok, an error string otherwise.
*/
function wl_schema_set_value( $post_id, $property_name, $property_value ) {
// Some checks on the parameters
if ( ! is_numeric( $post_id ) || is_null( $property_name ) || empty( $property_value ) || is_null( $property_value ) ) {
return false;
}
// Build full schema uri if necessary
$property_name = wl_build_full_schema_uri_from_schema_slug( $property_name );
// Get accepted properties
$accepted_fields = wl_entity_taxonomy_get_custom_fields( $post_id );
// Find the name of the custom-field managing the schema property
foreach ( $accepted_fields as $wl_constant => $field ) {
if ( $field['predicate'] == $property_name ) {
// Deal with single values
if ( ! is_array( $property_value ) ) {
$property_value = array( $property_value );
}
// Delete present meta
delete_post_meta( $post_id, $wl_constant );
foreach ( $property_value as $value ) {
add_post_meta( $post_id, $wl_constant, $value );
}
return true;
}
}
return false;
}
/**
* Retrieves the entity types for the specified post ID, where
*
* @param int $post_id The numeric post ID.
*
* @return array Array of type(s) (e.g. Type, for the http://schema.org/Type)
* or NULL in case of no values (or error).
*/
function wl_schema_get_types( $post_id ) {
// Some checks on the parameters
if ( ! is_numeric( $post_id ) ) {
return null;
}
$type = Wordlift_Entity_Type_Service::get_instance()->get( $post_id );
if ( isset( $type['uri'] ) ) {
return array( $type['uri'] );
}
return null;
}
/**
* Sets the entity type(s) for the specified post ID. Support is now for only one type per entity.
*
* @param int $post_id The numeric post ID
* @param array $type_names An array of strings, each defining a type (e.g. Type, for the http://schema.org/Type)
*
* @return boolean True if everything went ok, an error string otherwise.
*/
function wl_schema_set_types( $post_id, $type_names ) {
// Some checks on the parameters
if ( ! is_numeric( $post_id ) || empty( $type_names ) || is_null( $type_names ) ) {
return null;
}
// TODO: support more than one type.
if ( is_array( $type_names ) ) {
$type_names = $type_names[0];
}
// Get the schema URI (e.g. http://schema.org/Thing)
$type_names = wl_build_full_schema_uri_from_schema_slug( $type_names );
// Actually sets the taxonomy type
wl_set_entity_main_type( $post_id, $type_names );
}
/**
* Build full schema uri starting from a slug. If the uri is already correct, nothing is done.
*
* @param string $schema_name Slug or full uri of a schema property or type (es. 'location' or 'http://schema.org/location')
*
* @return string The full schema uri (es. 'latitude' returns 'http://schema.org/latitude')
*/
function wl_build_full_schema_uri_from_schema_slug( $schema_name ) {
$schema_root_address = 'http://schema.org/';
if ( strpos( $schema_name, $schema_root_address ) === false ) { // === necessary
$schema_name = $schema_root_address . $schema_name;
}
return $schema_name;
}