Posting with the article:published_time
-
Hi, I appreciate your plugin. It is working well. I have just joined Bluesky and I am posting to Bsky a few of my latest blog posts. I’ve discovered that the plugin assigns the a new posting time, rather than scraping the original published time from the page. Perhaps that would work for some users, but it is not what I was intending. I have made a few minor changes to your code to implement my preference. See the following:
<code>
// Fetch OpenGraph data
$og_data = $this->get_og_data($permalink);
if(isset($og_data['published_time'])){$createdAt = $og_data['published_time'];}
else{$createdAt = gmdate('c');}
$post_data = [
'repo' => $did,
'collection' => 'app.bsky.feed.post',
'record' => [
'text' => '', // Empty text field
'createdAt' => $createdAt
]
];
private function get_og_data($url) {
$response = wp_remote_get($url);
$html = wp_remote_retrieve_body($response);
$og_data = [];
if (preg_match('/<meta property="og:title" content="(.*?)"/', $html, $match)) {
$og_data['title'] = $match[1];
}
if (preg_match('/<meta property="og:description" content="(.*?)"/', $html, $match)) {
$og_data['description'] = $match[1];
}
if (preg_match('/<meta property="og:image" content="(.*?)"/', $html, $match)) {
$og_data['image'] = $match[1];
}
if (preg_match('/<meta property="article:published_time" content="(.*?)"/', $html, $match)) {
$og_data['published_time'] = $match[1];
}
return $og_data;
}
</code>I also notice that you use gmdate() which uses GMT, rather than date(). I am not sure which is expected by Bsky, but UTC is default in most cases. GMT uses daylight savings.
The topic ‘Posting with the article:published_time’ is closed to new replies.