承接 madeitbelgium/wordpress-php-sdk 相关项目开发

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

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

madeitbelgium/wordpress-php-sdk

最新稳定版本:1.7.0

Composer 安装命令:

composer require madeitbelgium/wordpress-php-sdk

包简介

WordPress Laravel PHP SDK

README 文档

README

Build Status Coverage Status Latest Stable Version Latest Unstable Version Total Downloads License

Installation

Require this package in your composer.json and update composer.

composer require madeitbelgium/wordpress-php-sdk

After updating composer, add the ServiceProvider to the providers array in config/app.php

MadeITBelgium\WordPress\WordPressServiceProvider::class,

You can use the facade for shorter code. Add this to your aliases:

'WP' => MadeITBelgium\WordPress\WordPressFacade::class,

Add the config files

php artisan vendor:publish --provider="MadeITBelgium\WordPress\WordPressServiceProvider"

Documentation

Authentication

To use authenticated requests you have to sign in to the WordPress website to generate a JWT token. WordPress doesn't support this by default, you have to install a JWT compatible plugin. This package is tested with: https://nl.wordpress.org/plugins/jwt-authentication-for-wp-rest-api/

use MadeITBelgium\WordPress\WordPressFacade as WordPress;
$token = WordPress::login($request->get('email'), $request->get('password'));
// {'token': '...'}

Now you can save the $token->token to your database.

use MadeITBelgium\WordPress\WordPressFacade as WordPress;
WordPress::setAccessToken($token);

Application Password

You can use the newly introduced Application Password (in WordPress 5.6).

$wp = WordPress::setServer('https://www.example.com')
    ->setUsername('username')
    ->setApplicationPassword('application password');

Interact with objects

User

WordPress Rest API documentation: https://developer.wordpress.org/rest-api/reference/users/

use MadeITBelgium\WordPress\WordPressFacade as WordPress;
$users = WordPress::user()->list();
$result = WordPress::user()->create($data);
$user = WordPress::user()->get($id);
$result = WordPress::user()->update($id, $data);
$result = WordPress::user()->delete($id);

Post

WordPress Rest API documentation: https://developer.wordpress.org/rest-api/reference/posts/

use MadeITBelgium\WordPress\WordPressFacade as WordPress;
$users = WordPress::post()->list();
$result = WordPress::post()->create($data);
$user = WordPress::post()->get($id);
$result = WordPress::post()->update($id, $data);
$result = WordPress::post()->delete($id);

Post from custom post type

WordPress Rest API documentation: https://developer.wordpress.org/rest-api/reference/posts/

use MadeITBelgium\WordPress\WordPressFacade as WordPress;
$users = WordPress::customPost('custom_post_type')->list();
$result = WordPress::customPost('custom_post_type')->create($data);
$user = WordPress::customPost('custom_post_type')->get($id);
$result = WordPress::customPost('custom_post_type')->update($id, $data);
$result = WordPress::customPost('custom_post_type')->delete($id);

Tags

WordPress Rest API documentation: https://developer.wordpress.org/rest-api/reference/tags/

use MadeITBelgium\WordPress\WordPressFacade as WordPress;
$users = WordPress::tag()->list();
$result = WordPress::tag()->create($data);
$user = WordPress::tag()->get($id);
$result = WordPress::tag()->update($id, $data);
$result = WordPress::tag()->delete($id);

Create new post

$data = [
    'title' => 'title',
    'parent' => 0,
    'slug' => Str::slug('title', '-'),
    'content' => 'content',
];
$post = WordPress::post()->create($data);
// {'id': ...}

Uploading media

use Illuminate\Support\Facades\Storage;
use MadeITBelgium\WordPress\WordPressFacade as WordPress;

$media = WordPress::postCall('/wp-json/wp/v2/media', [
    'multipart' => [
        [
            'name' => 'file',
            'contents' => Storage::disk('local')->get($fileLocation),
            'filename' => 'filename.jpg',
        ],
        [
            'name' => 'title',
            'contents' => 'Title of attachment',
        ],
        [
            'name' => 'alt_text',
            'contents' => 'Alt text',
        ],
    ],
]);

Execute any request

Read more about the WordPress rest API: https://developer.wordpress.org/rest-api/

Get

$url = "";
$result = WordPress::getCall('/wp-json'.$url);

Put

$result = WordPress::putCall('/wp-json'.$url, $data);

Post

$result = WordPress::postCall('/wp-json'.$url, $data);

Delete

$result = WordPress::deleteCall('/wp-json'.$url);

The complete documentation can be found at: https://www.tpweb.org/my-projects/wordpress-php-sdk/

Support

Support github or mail: tjebbe.lievens@madeit.be

Contributing

Please try to follow the psr-2 coding style guide. http://www.php-fig.org/psr/psr-2/

License

This package is licensed under LGPL. You are free to use it in personal and commercial projects. The code can be forked and modified, but the original copyright author should always be included!

统计信息

  • 总下载量: 18.62k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 42
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 42
  • Watchers: 1
  • Forks: 8
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2019-05-22