### Install laravel-wordpress via Composer Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/README.md Install the package via Composer. ```bash composer require jeffersongoncalves/laravel-wordpress ``` -------------------------------- ### WordPress users Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/README.md User operations: list, get, and current user. ```php Wordpress::listUsers(['per_page' => 10]); Wordpress::getUser(1); Wordpress::currentUser(); ``` -------------------------------- ### WordPress media CRUD Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/README.md Media operations: list, get, upload, update, and delete. Upload requires filename, contents, mimeType, and optional attributes. ```php Wordpress::listMedia(['per_page' => 20]); Wordpress::getMedia(42); Wordpress::uploadMedia( filename: 'image.jpg', contents: file_get_contents('/path/to/image.jpg'), mimeType: 'image/jpeg', attributes: ['post' => 123], ); Wordpress::updateMedia(42, ['alt_text' => 'A description']); Wordpress::deleteMedia(42); ``` -------------------------------- ### Filter posts with Wordpress::listPosts Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/resources/boost/skills/laravel-wordpress-development/SKILL.md Filter a collection of posts by passing query parameters to listPosts. The example sets per_page, status, search, and after. ```php Wordpress::listPosts([ 'per_page' => 25, 'status' => 'publish', 'search' => 'laravel', 'after' => '2026-01-01T00:00:00', ]); ``` -------------------------------- ### WordPress pages CRUD Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/README.md Page operations: list, get, create, update, and delete. ```php Wordpress::listPages(['per_page' => 20]); Wordpress::getPage(9); Wordpress::createPage(['title' => 'About', 'content' => '

Hello

', 'status' => 'publish']); Wordpress::updatePage(9, ['title' => 'About us']); Wordpress::deletePage(9); ``` -------------------------------- ### WordPress posts CRUD Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/README.md Post operations: list, get, create, update, and delete. Delete moves to trash unless force: true is passed. Post statuses include publish, draft, pending, private, future, trash. ```php use Jeffersongoncalves\Wordpress\Facades\Wordpress; Wordpress::listPosts(['per_page' => 10, 'status' => 'publish']); Wordpress::getPost(123); Wordpress::createPost([ 'title' => 'Post Title', 'content' => '

Post content here

', 'status' => 'draft', 'categories' => [1], 'tags' => [5, 6], ]); Wordpress::updatePost(123, ['title' => 'Updated Title', 'status' => 'publish']); Wordpress::deletePost(123); // moves to trash Wordpress::deletePost(123, force: true); // deletes permanently ``` -------------------------------- ### WordPress comments CRUD Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/README.md Comment operations: list, get, create, update, and delete. ```php Wordpress::listComments(['post' => 123]); Wordpress::getComment(7); Wordpress::createComment(['post' => 123, 'content' => 'Nice post']); Wordpress::updateComment(7, ['status' => 'approved']); Wordpress::deleteComment(7); ``` -------------------------------- ### WordPress categories and tags CRUD Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/README.md Category and tag operations: list, get, create, update, and delete. ```php Wordpress::listCategories(); Wordpress::getCategory(1); Wordpress::createCategory('Category Name', 'category-name'); Wordpress::updateCategory(1, ['description' => 'Updated']); Wordpress::deleteCategory(1); Wordpress::listTags(); Wordpress::getTag(5); Wordpress::createTag('Tag Name', 'tag-name'); Wordpress::updateTag(5, ['description' => 'Updated']); Wordpress::deleteTag(5); ``` -------------------------------- ### Publish laravel-wordpress config Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/README.md Publish the package's config file. ```bash php artisan vendor:publish --tag="laravel-wordpress-config" ``` -------------------------------- ### Run tests with composer test Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/README.md Runs the test suite for this Laravel package. Use this command to execute all tests defined in the project. ```bash composer test ``` -------------------------------- ### Upload media with Wordpress::uploadMedia Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/resources/boost/skills/laravel-wordpress-development/SKILL.md Upload media with a binary file. Attributes are sent as query parameters because the request body carries the file. ```php Wordpress::uploadMedia( filename: 'image.jpg', contents: file_get_contents(storage_path('app/image.jpg')), mimeType: 'image/jpeg', attributes: ['post' => 123, 'alt_text' => 'A description'], ); ``` -------------------------------- ### Fetch a post with Wordpress::getPost Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/resources/boost/skills/laravel-wordpress-development/SKILL.md Use the Wordpress facade to fetch a post by ID. The response is an Illuminate\Http\Client\Response; check successful() before reading json(). ```php use Jeffersongoncalves\Wordpress\Facades\Wordpress; $response = Wordpress::getPost(123); if ($response->successful()) { $post = $response->json(); } ``` -------------------------------- ### WordPress credentials in .env Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/README.md Environment variables for WordPress credentials. Generate an Application Password in WordPress under Users > Your Profile > Application Passwords. ```plaintext WORDPRESS_BASE_URL=https://example.com WORDPRESS_USERNAME=your-wordpress-username WORDPRESS_APPLICATION_PASSWORD=xxxx xxxx xxxx xxxx xxxx xxxx ``` -------------------------------- ### laravel-wordpress config file Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/README.md Published config file contents. Set the WordPress base URL, username, application password, and optional namespace. ```php return [ 'base_url' => env('WORDPRESS_BASE_URL'), 'username' => env('WORDPRESS_USERNAME'), 'application_password' => env('WORDPRESS_APPLICATION_PASSWORD'), 'namespace' => env('WORDPRESS_NAMESPACE', 'wp-json/wp/v2'), ]; ``` -------------------------------- ### Delete a post (trash vs permanent) Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/resources/boost/skills/laravel-wordpress-development/SKILL.md Delete a post. Without force, the post moves to trash; with force: true it is permanently deleted. Media and terms always force delete. ```php Wordpress::deletePost(123); // status becomes `trash` Wordpress::deletePost(123, force: true); // gone for good ``` -------------------------------- ### Mock WordPress HTTP calls with Http::fake Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/resources/boost/skills/laravel-wordpress-development/SKILL.md Mock WordPress HTTP calls with Http::fake and assert the request URL. The fake pattern matches the posts endpoint and returns a response with id 123. ```php use Illuminate\Support\Facades\Http; use Jeffersongoncalves\Wordpress\Facades\Wordpress; Http::fake(['example.com/wp-json/wp/v2/posts/*' => Http::response(['id' => 123])]); $response = Wordpress::getPost(123); Http::assertSent(fn ($request) => $request->url() === 'https://example.com/wp-json/wp/v2/posts/123'); ``` -------------------------------- ### Check credentials with Wordpress::currentUser Source: https://github.com/jeffersongoncalves/laravel-wordpress/blob/main/resources/boost/skills/laravel-wordpress-development/SKILL.md Diagnose a 401 Unauthorized error by calling currentUser() and inspecting the JSON response. If credentials are correct but requests fail, the host may be stripping the Authorization header. ```php // Confirm the credentials resolve and the token is accepted Wordpress::currentUser()->json(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.