dshanske / bridgy-publish

Bridgy for WordPress ( Functionality now in Syndication Links Plugin. This is being deprecated)
https://wordpress.org/plugins/bridgy-publish
8 stars 6 forks source link

Oembed Tweet HTML doesn't include `u-url` #29

Closed miklb closed 6 years ago

miklb commented 7 years ago

If you are using oembed Tweets, and do a reply to a tweet, the embedded HTML (which I learned is stored in the postmeta) doesn't include u-urlon the link to the tweet. Thus, if attempting a reply kind to a Tweet, bridgy will throw an error "no link could be found".

So far, and only looking specifically at stored tweet embed code, I have come up with this in my kind.php template to add the u-url.

$embed_html = self::get_embed( $meta->get_url() );
$dom = new DOMDocument;
$dom->loadHTML($embed_html, LIBXML_HTML_NOIMPLIED);

$nodelinks = $dom->getElementsByTagName('a');
$links = iterator_to_array($nodelinks);
$count = count( $links );
$i = 0;

foreach ( $links as $link ) $i++; {
    if( $i == $count ) {
        $link->setAttribute("class", "u-url");
    }
};

$embed_html = $dom->saveHTML();

I have started looking at the WP function oembed_result to possibly add the class when WP stores the HTML from Twitter, rather than doing it on the fly in the template. Would love some other perspective.

dshanske commented 6 years ago

I've solved this in Post Kinds by adding a hidden link with the u-url, But that wouldn't work for a shortcode embed. Why not add the hidden link in the filter, rather than adding u-url

miklb commented 6 years ago

I don't follow what you mean by hidden link.

dshanske commented 6 years ago

I just add an empty link that can't be seen

dshanske commented 6 years ago

Since I am planning on deprecating the plugin, marking these.