Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions includes/Core/WpMcp.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Automattic\WordpressMcp\Core;

use Automattic\WordpressMcp\Tools\McpCustomPostTypesTools;
use Automattic\WordpressMcp\Tools\McpCustomPostsTools;
use Automattic\WordpressMcp\Tools\McpPostsTools;
use Automattic\WordpressMcp\Resources\McpGeneralSiteInfo;
use Automattic\WordpressMcp\Tools\McpRestApiCrud;
Expand Down Expand Up @@ -189,7 +189,7 @@ private function init_default_tools(): void {
new McpPagesTools();
new McpSettingsTools();
new McpMediaTools();
new McpCustomPostTypesTools();
new McpCustomPostsTools();
new McpRestApiCrud();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use Automattic\WordpressMcp\Core\RegisterMcpTool;

/**
* Class for managing MCP Custom Post Types Tools functionality.
* Class for managing MCP Custom Posts Tools functionality.
*/
class McpCustomPostTypesTools {
class McpCustomPostsTools {

/**
* Constructor.
Expand Down Expand Up @@ -51,10 +51,10 @@ public function register_tools(): void {
new RegisterMcpTool(
array(
'name' => 'wp_cpt_search',
'description' => 'Search and filter WordPress custom post types including ' . $post_types_list . ' with pagination',
'description' => 'Search and filter WordPress custom posts including ' . $post_types_list . ' with pagination',
'type' => 'read',
'callback' => array( $this, 'search_custom_post_types' ),
'permission_callback' => array( $this, 'search_custom_post_types_permission_callback' ),
'callback' => array( $this, 'search_custom_posts' ),
'permission_callback' => array( $this, 'search_custom_posts_permission_callback' ),
'disabled_by_rest_crud' => true,
'inputSchema' => array(
'type' => 'object',
Expand Down Expand Up @@ -91,7 +91,7 @@ public function register_tools(): void {
),
),
'annotations' => array(
'title' => 'Search Custom Post Types',
'title' => 'Search Custom Posts',
'readOnlyHint' => true,
'openWorldHint' => false,
),
Expand All @@ -101,10 +101,10 @@ public function register_tools(): void {
new RegisterMcpTool(
array(
'name' => 'wp_get_cpt',
'description' => 'Get a WordPress custom post type by ID',
'description' => 'Get a WordPress custom post by ID',
'type' => 'read',
'callback' => array( $this, 'get_custom_post_type' ),
'permission_callback' => array( $this, 'get_custom_post_type_permission_callback' ),
'callback' => array( $this, 'get_custom_post' ),
'permission_callback' => array( $this, 'get_custom_post_permission_callback' ),
'disabled_by_rest_crud' => true,
'inputSchema' => array(
'type' => 'object',
Expand All @@ -124,7 +124,7 @@ public function register_tools(): void {
),
),
'annotations' => array(
'title' => 'Get Custom Post Type',
'title' => 'Get Custom Post',
'readOnlyHint' => true,
'openWorldHint' => false,
),
Expand All @@ -134,10 +134,10 @@ public function register_tools(): void {
new RegisterMcpTool(
array(
'name' => 'wp_add_cpt',
'description' => 'Add a new WordPress custom post type',
'description' => 'Add a new WordPress custom post',
'type' => 'create',
'callback' => array( $this, 'add_custom_post_type' ),
'permission_callback' => array( $this, 'add_custom_post_type_permission_callback' ),
'callback' => array( $this, 'add_custom_post' ),
'permission_callback' => array( $this, 'add_custom_post_permission_callback' ),
'disabled_by_rest_crud' => true,
'inputSchema' => array(
'type' => 'object',
Expand Down Expand Up @@ -170,7 +170,7 @@ public function register_tools(): void {
),
),
'annotations' => array(
'title' => 'Add Custom Post Type',
'title' => 'Add Custom Post',
'readOnlyHint' => false,
'destructiveHint' => false,
'idempotentHint' => false,
Expand All @@ -182,10 +182,10 @@ public function register_tools(): void {
new RegisterMcpTool(
array(
'name' => 'wp_update_cpt',
'description' => 'Update a WordPress custom post type by ID',
'description' => 'Update a WordPress custom post by ID',
'type' => 'update',
'callback' => array( $this, 'update_custom_post_type' ),
'permission_callback' => array( $this, 'update_custom_post_type_permission_callback' ),
'callback' => array( $this, 'update_custom_post' ),
'permission_callback' => array( $this, 'update_custom_post_permission_callback' ),
'disabled_by_rest_crud' => true,
'inputSchema' => array(
'type' => 'object',
Expand Down Expand Up @@ -221,7 +221,7 @@ public function register_tools(): void {
),
),
'annotations' => array(
'title' => 'Update Custom Post Type',
'title' => 'Update Custom Post',
'readOnlyHint' => false,
'destructiveHint' => false,
'idempotentHint' => true,
Expand All @@ -233,10 +233,10 @@ public function register_tools(): void {
new RegisterMcpTool(
array(
'name' => 'wp_delete_cpt',
'description' => 'Delete a WordPress custom post type by ID',
'description' => 'Delete a WordPress custom post by ID',
'type' => 'delete',
'callback' => array( $this, 'delete_custom_post_type' ),
'permission_callback' => array( $this, 'delete_custom_post_type_permission_callback' ),
'callback' => array( $this, 'delete_custom_post' ),
'permission_callback' => array( $this, 'delete_custom_post_permission_callback' ),
'disabled_by_rest_crud' => true,
'inputSchema' => array(
'type' => 'object',
Expand All @@ -256,7 +256,7 @@ public function register_tools(): void {
),
),
'annotations' => array(
'title' => 'Delete Custom Post Type',
'title' => 'Delete Custom Post',
'readOnlyHint' => false,
'destructiveHint' => true,
'idempotentHint' => true,
Expand All @@ -267,12 +267,12 @@ public function register_tools(): void {
}

/**
* Search custom post types.
* Search custom posts.
*
* @param array $params The parameters.
* @return array
*/
public function search_custom_post_types( array $params ): array {
public function search_custom_posts( array $params ): array {
$post_type = sanitize_text_field( $params['post_type'] );
$page = isset( $params['page'] ) ? max( 1, intval( $params['page'] ) ) : 1;
$per_page = isset( $params['per_page'] ) ? max( 1, intval( $params['per_page'] ) ) : 10;
Expand Down Expand Up @@ -307,21 +307,21 @@ public function search_custom_post_types( array $params ): array {
}

/**
* Search custom post types permissions callback.
* Search custom posts permissions callback.
*
* @return bool
*/
public function search_custom_post_types_permission_callback(): bool {
public function search_custom_posts_permission_callback(): bool {
return current_user_can( 'edit_posts' );
}

/**
* Get a custom post type by ID.
* Get a custom post by ID.
*
* @param array $params The parameters.
* @return array
*/
public function get_custom_post_type( array $params ): array {
public function get_custom_post( array $params ): array {
$post = get_post( intval( $params['id'] ) );
if ( ! $post || $post->post_type !== $params['post_type'] ) {
return array(
Expand All @@ -335,21 +335,21 @@ public function get_custom_post_type( array $params ): array {
}

/**
* Get custom post type permissions callback.
* Get custom post permissions callback.
*
* @return bool
*/
public function get_custom_post_type_permission_callback(): bool {
public function get_custom_post_permission_callback(): bool {
return current_user_can( 'edit_posts' );
}

/**
* Add a new custom post type.
* Add a new custom post.
*
* @param array $params The parameters.
* @return array
*/
public function add_custom_post_type( array $params ): array {
public function add_custom_post( array $params ): array {
$post_data = array(
'post_type' => sanitize_text_field( $params['post_type'] ),
'post_title' => sanitize_text_field( $params['title'] ),
Expand Down Expand Up @@ -379,21 +379,21 @@ public function add_custom_post_type( array $params ): array {
}

/**
* Add custom post type permissions callback.
* Add custom post permissions callback.
*
* @return bool
*/
public function add_custom_post_type_permission_callback(): bool {
public function add_custom_post_permission_callback(): bool {
return current_user_can( 'edit_posts' );
}

/**
* Update a custom post type.
* Update a custom post.
*
* @param array $params The parameters.
* @return array
*/
public function update_custom_post_type( array $params ): array {
public function update_custom_post( array $params ): array {
$post = get_post( intval( $params['id'] ) );
if ( ! $post || $post->post_type !== $params['post_type'] ) {
return array(
Expand Down Expand Up @@ -438,21 +438,21 @@ public function update_custom_post_type( array $params ): array {
}

/**
* Update custom post type permissions callback.
* Update custom post permissions callback.
*
* @return bool
*/
public function update_custom_post_type_permission_callback(): bool {
public function update_custom_post_permission_callback(): bool {
return current_user_can( 'edit_posts' );
}

/**
* Delete a custom post type.
* Delete a custom post.
*
* @param array $params The parameters.
* @return array
*/
public function delete_custom_post_type( array $params ): array {
public function delete_custom_post( array $params ): array {
$post = get_post( intval( $params['id'] ) );
if ( ! $post || $post->post_type !== $params['post_type'] ) {
return array(
Expand All @@ -477,11 +477,11 @@ public function delete_custom_post_type( array $params ): array {
}

/**
* Delete custom post type permissions callback.
* Delete custom post permissions callback.
*
* @return bool
*/
public function delete_custom_post_type_permission_callback(): bool {
public function delete_custom_post_permission_callback(): bool {
return current_user_can( 'edit_posts' );
}
}
6 changes: 3 additions & 3 deletions tests/phpunit/Tools/McpCustomPostTypeTest.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
<?php
/**
* Test class for McpCustomPostTypesTools
* Test class for McpCustomPostsTools
*
* @package Automattic\WordpressMcp\Tests\Tools
*/

namespace Automattic\WordpressMcp\Tests\Tools;

use Automattic\WordpressMcp\Core\WpMcp;
use Automattic\WordpressMcp\Tools\McpCustomPostTypesTools;
use Automattic\WordpressMcp\Tools\McpCustomPostsTools;
use WP_UnitTestCase;
use WP_REST_Request;
use WP_User;

/**
* Test class for McpCustomPostTypesTools
* Test class for McpCustomPostsTools
*/
final class McpCustomPostTypeTest extends WP_UnitTestCase {

Expand Down