williamsdb/php2micropost 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

williamsdb/php2micropost

Composer 安装命令:

composer require williamsdb/php2micropost

包简介

A library that makes posting to Wordpress Microposts from PHP simple.

README 文档

README


php2Micropost

A simple library that allows posting to WordPress Microposts via the API.

Table of Contents
  1. About The Project
  2. Getting Started
  3. Usage
  4. Roadmap
  5. Contributing
  6. License
  7. Contact
  8. Acknowledgments

About The Project

I have accounts on plenty of microblogging sites (Twitter, Mastodon, Bluesky and even Threads) but they are all owned and controlled by someone else. I decided that I wanted something that I could use and manage, and a quick search came up with Michael Gbadebo's WordPress plugin called Microposts.

I installed this and after playing around for a while, I decided that it was just what I was looking for. However, it was quite cumbersome to make a post from a mobile device when I was out and about. What I wanted was a simple page from which I could post including an image so I built this connector.

Very much inspired by my php2Micropost project this package will allow you to easily integrate creating Microposts from your own code.

Buy Me a Coffee at ko-fi.com

(back to top)

Built With

(back to top)

Getting Started

Running the script is very straightforward:

  1. install composer

  2. add php2Micropost

composer.phar require williamsdb/php2micropost

You can read more about how this all works in these blog posts.

Prerequisites

Requirements are very simple; it requires the following:

  1. PHP (I tested on v8.1.13)
  2. WordPress (I tested on 6.9.4)
  3. Michael Gbadebo's Micropost plugin
  4. a WordPress blog and an Application Password (see this post for details of how to do that).

Installation

  1. As above

(back to top)

Usage

Here's a few examples to get you started.

Setup and connect to WordPress

require __DIR__ . '/vendor/autoload.php';

use williamsdb\php2micropost\php2Micropost;

$base_url = 'https://www.your-domain.com/wp-json/wp/v2';
$username = 'WordPress username with write permissions';
$password = 'Your 24-character Application Password';
$parseURL = false;

$php2Micropost = new php2Micropost(
    base_url: $base_url,
    username: $username,
    password: $password,
    parseUrls: false,
    autoRotate: false
);
$connection = $php2Micropost->wordpress_connect();

Sending post with only text

Text sent can either be plain text or HTML. If you send plain text and $parseURLs is TRUE then the text will be checked for URLs and if any found they will be wrapped in <a href="URL">URL</a>. If you are passing HTML then $parseURLs should be set to FALSE to retain the HTML.

$text = "This is a test post from php2Micropost. " . date('Y-m-d H:i:s');

// post with text and nothing else
$response = $php2Micropost->post_to_wordpress(
    connection: $connection,
    text: $text,
    title: '',
    media: '',
);

Uploading a post with a single image

Microposts only accepts a single image so that's all that is allowed here.

$image = "/Users/neilthompson/Downloads/IMG_9547.jpeg";

$text = "This is a test post from php2Micropost. " . date('Y-m-d H:i:s');

// post with text and nothing else
$response = $php2Micropost->post_to_wordpress(
    connection: $connection,
    text: $text,
    title: '',
    media: $image,
);

Adding tags to a post

If the tag already exists, it will be associated with the post; otherwise, it will be created.

$tags = ['test', 'php2Micropost', 'reading'];

$text = "This is a test post from php2Micropost. " . date('Y-m-d H:i:s');

// post with text and nothing else
$response = $php2Micropost->post_to_wordpress(
    connection: $connection,
    text: $text,
    title: '',
    media: $image,
    tags: $tags,
);

(back to top)

Known Issues

See the open issues for a full list of proposed features (and known issues).

(back to top)

Contributing

Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the GNU General Public License v3.0. See LICENSE for more information.

(back to top)

Contact

Bluesky - @spokenlikeageek.com

Mastodon - @spokenlikeageek

X - @spokenlikeageek

Website - https://spokenlikeageek.com

Project link - Github

(back to top)

Acknowledgments

(back to top)

williamsdb/php2micropost 适用场景与选型建议

williamsdb/php2micropost 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「wordpress」 「Microposts」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 williamsdb/php2micropost 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 williamsdb/php2micropost 我们能提供哪些服务?
定制开发 / 二次开发

基于 williamsdb/php2micropost 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 21
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: GPL-3.0-or-later
  • 更新时间: 2026-03-21