• Resolved njesson

    (@njesson)


    I thought that I had already posted this issue. Apparently I forgot to click SUBMIT, so here goes again.

    I have recently installed this plugin and I like it. However, I notice that the plugin inserts the current time rather than the original posted time of the blog entry. This shouldn’t be a concern if all Bsky posts are created immediately after the WP post is published. However, if there is a delay, then Bsky posts may be out of order. (I have also been posting older WP posts to my Bsky feed, so I would like them to show the older date.)

    To make this change, I edited the code with the following (edits shown in bold):

    <code>
    // Fetch OpenGraph data
    $og_data = $this->get_og_data($permalink);
    if (isset ( $og_data['published_time'] ) ){ $createdAt = $og_data['published_time']; } // timestamp scraped from post at $permalink
    else { $createdAt = date('c'); }
    // default timestamp

    $post_data = [
    'repo' => $did,
    'collection' => 'app.bsky.feed.post',
    'record' => [
    'text' => '', // Empty text field
    'createdAt' => $createdAt
    ]
    ];
    </code>

    Open Graph recognizes the article:published_time meta property. It calls for the time in UTC, so the default time should probably be date(‘c’). gmdate() gives GMT, which has daylight savings, date() gives UTC, which does not.

    The published time is scraped with the other og_data from the page at $permalink. This required a further edit of the get_og_data() function as follows:

    <code>
    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>

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)

The topic ‘Posting with the article:published_time’ is closed to new replies.