maneuver/channel
Composer 安装命令:
composer require maneuver/channel
包简介
PHP library for the Wordpress REST API
关键字:
README 文档
README
Currently only supports GET requests.
TABLE OF CONTENTS:
Installation
Install via composer:
composer require maneuver/channel
And include the autoloader:
require('vendor/autoload.php');
Happy times. 🤙
Authentication
Basic Authentication
Make sure the Basic Authentication plugin for Wordpress is installed and activated.
(should only be used for development purposes, as stated by the repository)
$channel = new \Maneuver\Channel([ 'uri' => 'http://example.com/wp-json/wp/v2/', 'username' => 'your-username', 'password' => 'your-password', ]);
API Token
Make sure the Rooftop API Authentication plugin is installed and activated.
$channel = new \Maneuver\Channel([ 'uri' => 'http://example.com/wp-json/wp/v2/', 'token' => 'your-token', ]);
OAuth
Currently not implemented.
Usage
Posts
Retrieve a list of all posts (where post_type = 'post'):
$posts = $channel->getPosts(); echo count($posts);
Retrieve a post by ID:
$post = $channel->getPost(1); echo $post->excerpt;
Using Twig? Fear not:
<h1>{{ post.title }}</h1> <p>{{ post.excerpt|raw }}</p>
Pages
Retrieve a list of all pages:
$pages = $channel->getPages(); foreach ($pages as $page) { echo $page->title; }
Retrieve a page by ID:
$page = $channel->getPage(1); echo $page->content;
Taxonomies & Terms
Retrieve all existing taxonomies:
$taxonomies = $channel->getTaxonomies();
Retrieve one taxonomy by slug:
$taxonomy = $channel->getTaxonomy('category'); // use singular taxonomy name // Then you can retrieve its terms: $terms = $taxonomy->terms();
Or retrieve the terms in one call using the 'get' method:
$terms = $channel->get('categories'); // use plural taxonomy name
Users
Get all users:
$users = $channel->getUsers(); echo $users[0]->name;
Media
Get all media:
$media = $channel->getMedia();
Custom Post Types
When you define a custom post type in your Wordpress installation, make sure you set the show_in_rest option to true. This exposes an endpoint in the REST API to retrieve the posts. Read the docs
add_action('init', function(){ register_post_type('product', [ 'labels' => [ 'name' => 'Products', 'singular_name' => 'Product', ], 'public' => true, 'show_in_rest' => true, 'rest_base' => 'products' // defaults to the post type slug, 'product' in this case ]); });
Then use the general 'get' method:
$products = $channel->get('products'); // Pass in the 'rest_base' of the custom post type.
Slightly more advanced stuff
Endpoints
You can actually call any endpoint using the 'get' method:
$post_types = $channel->get('types'); $latest = $channel->get('posts?per_page=5');
Read more about all endpoints in the REST API Handbook
Guzzle
You can pass in more requestOptions for Guzzle:
$latest = $channel->get('posts?per_page=5', [ 'proxy' => 'tcp://localhost:8125', ]);
Read more about the Guzzle RequestOptions here.
Custom Classes
Every call returns an object (or array of objects) extending the '\Maneuver\Models\Base' class. You can define your own classes if needed.
NOTE: Don't extend the '\Maneuver\Models\Base' class directly, you'll lose some functionality.
class MyPost extends \Maneuver\Models\Post { public function fullTitle() { return 'Post: ' . $this->title; } } class MyPage extends \Maneuver\Models\Page { } $channel->setCustomClasses([ // 'type' => 'ClassName' // eg: 'user' => 'MyUser' // or: 'post' => 'MyPost', 'page' => 'MyPage', 'product' => 'MyPost', // custom post type ]); $post = $channel->getPost(1); echo $post->fullTitle(); echo get_class($post); // => 'MyPost'
Todo:
- More support for ACF fields
- Better support for images
- Add WP_Query-like parameters
- OAuth authentication
maneuver/channel 适用场景与选型建议
maneuver/channel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 448 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 05 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「api」 「wordpress」 「REST API」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 maneuver/channel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 maneuver/channel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 maneuver/channel 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A PSR-7 compatible library for making CRUD API endpoints
Alfabank REST API integration
Must-use plugin integrating WordPress with the Upsun platform: environment awareness, router-cache friendliness, safe preview clones, deploy migrations, Site Health checks, and a wp upsun CLI command.
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
A lightweight plain-PHP framework for database-backed CRUD APIs.
bughq error tracking - PHP SDK
统计信息
- 总下载量: 448
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-05-01