Inpsyde\MultilingualPress\API\WPDBContentRelations::set_relation PHP Method

set_relation() public method

Set a relation according to the given parameters.
public set_relation ( integer $source_site_id, integer $target_site_id, integer $source_content_id, integer $target_content_id, string $type = 'post' ) : boolean
$source_site_id integer Source blog ID.
$target_site_id integer Target blog ID.
$source_content_id integer Source post ID or term taxonomy ID.
$target_content_id integer Target post ID or term taxonomy ID.
$type string Content type.
return boolean
    public function set_relation($source_site_id, $target_site_id, $source_content_id, $target_content_id, $type = 'post')
    {
        $translation_ids = $this->get_translation_ids($source_site_id, $target_site_id, $source_content_id, $target_content_id, $type);
        $existing = $this->get_relations($source_site_id, $source_content_id, $type);
        if (isset($existing[$target_site_id])) {
            if ($existing[$target_site_id] === $target_content_id) {
                return true;
            }
            $this->delete_relation($translation_ids['ml_source_blogid'], $target_site_id, $translation_ids['ml_source_elementid'], 0, $type);
        }
        $result = (bool) $this->insert_row($translation_ids['ml_source_blogid'], $target_site_id, $translation_ids['ml_source_elementid'], $target_content_id, $type);
        $cache_key = $this->get_cache_key($source_site_id, $source_content_id, $type);
        wp_cache_delete($cache_key, $this->cache_group);
        \Inpsyde\MultilingualPress\debug(current_filter() . '/' . __METHOD__ . '/' . __LINE__ . " - {$this->db->last_query}");
        return $result;
    }