承接 williamsdb/php2micropost 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

williamsdb/php2micropost

最新稳定版本:v1.3.0

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)

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固