ak86/wp-auto-post
Composer 安装命令:
composer require ak86/wp-auto-post
包简介
A simple PHP library for programatically creating Wordpress posts.
README 文档
README
WP Auto Post Client is a simple API client library written in PHP which allows creating new posts programatically by using Wordpress REST API, without the need to login to the dashboard.
Requirements
- Nginx/Apache server configured with PHP 7.4 or higher
- Composer package manager
- Working installation of Wordpress 5.6 or later with the support for Application Passwords. Follow this link to learn how to obtain an application password. If you can't see the application passwords section at the bottom of your wordpress user profile, you may have to enable it manually.
Installation
composer require ak86/wp-auto-post
Basic Usage
// Require composer autoloader
require_once '/path/to/vendor/autoload.php';
// Import the library
use Ak86\WPAutoPost;
// Set required config vars
$wp_post_endpoint = 'http://yourwordpresssite/wp-json/wp/v2/posts';
$wp_media_endpoint = 'http://yourwordpresssite/wp-json/wp/v2/media';
$wp_auth_username = 'your_wordpress_username';
$wp_auth_password = 'your_wordpress_application_password';
// Initialize the client instance
$wpap_client = new WPAutoPost($wp_post_endpoint, $wp_media_endpoint, $wp_auth_username, $wp_auth_password);
// creating a new post: set post image url
$imageUrl = 'http://url/to/image.jpg';
// creating a new post: upload the image
$uploaded_image = $wpap_client->upload_image($imageUrl);
// creating a new post: set post data
$postData = array(
"title" => 'Sample Post Title',
"content" => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit ...',
"status" => "publish"
);
// creating a new post: submit post data
$wpap_client->add_wp_post($postData, $uploaded_image->id);
Example App
Please checkout below repository for a functional demo project showing how to use this library.
https://github.com/amilak86/wp-auto-post-demo
License
Author
References
统计信息
- 总下载量: 10
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-04-21