/**
  * Only accept URIs or local entity IDs.
  * Build new entity if the user inputted a name that is not present in DB.
  */
 public function sanitize_data_filter($value)
 {
     if (empty($value)) {
         return null;
     }
     // Check that the inserted URI, ID or name does not point to a saved entity.
     if (is_numeric($value)) {
         $absent_from_db = is_null(get_post($value));
         // search by ID
     } else {
         $absent_from_db = is_null(wl_get_entity_post_by_uri($value)) && is_null(get_page_by_title($value, OBJECT, Wordlift_Entity_Service::TYPE_NAME));
         // search by name
     }
     // Is it an URI?
     $name_is_uri = strpos($value, 'http') === 0;
     // We create a new entity only if the entity is not present in the DB.
     // In the case of an external uri, we just save the uri.
     if ($absent_from_db && !$name_is_uri) {
         // ...we create a new entity!
         $new_entity_id = wp_insert_post(array('post_status' => 'publish', 'post_type' => Wordlift_Entity_Service::TYPE_NAME, 'post_title' => $value));
         $new_entity = get_post($new_entity_id);
         $type = 'http://schema.org/' . (isset($this->expected_uri_type) ? $this->expected_uri_type[0] : 'Thing');
         wl_set_entity_main_type($new_entity_id, $type);
         // Build uri for this entity
         $new_uri = wl_build_entity_uri($new_entity_id);
         wl_set_entity_uri($new_entity_id, $new_uri);
         wl_push_entity_post_to_redlink($new_entity);
         // Update the value that will be saved as meta
         $value = $new_entity_id;
     }
     return $value;
 }
/**
 * Push the post with the specified ID to Redlink.
 *
 * @since 3.0.0
 *
 * @param int $post_id The post ID.
 */
function wl_linked_data_push_to_redlink($post_id)
{
    // Get the post.
    $post = get_post($post_id);
    wl_write_log("wl_linked_data_push_to_redlink [ post id :: {$post_id} ][ post type :: {$post->post_type} ]");
    // Call the method on behalf of the post type.
    switch ($post->post_type) {
        case 'entity':
            wl_push_entity_post_to_redlink($post);
            break;
        default:
            wl_push_post_to_redlink($post);
    }
    // Reindex the triple store if buffering is turned off.
    if (false === WL_ENABLE_SPARQL_UPDATE_QUERIES_BUFFERING) {
        wordlift_reindex_triple_store();
    }
}