• Resolved njesson

    (@njesson)


    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.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Emma Blackwell

    (@lunaraurora)

    gmdate() is required by the wordpress plugin checker .. it does not validate with date()
    said that, you can update to v1.2. Please check if after updating, the date works for your case, and kindly report back.

    Thread Starter njesson

    (@njesson)

    OK, it isn’t really a big problem. I live in a place that doesn’t use daylight savings, so I am careful about using the correct timezones. I am surprised that WP doesn’t validate basic PHP functions.

Viewing 2 replies - 1 through 2 (of 2 total)

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