'object', 'additionalProperties' => false, 'required' => array( 'id' ), 'properties' => array( 'id' => array( 'type' => 'integer', 'description' => __( 'The post id.', 'gripmcp' ), 'minimum' => 1, ), ), ); } protected function required_capability(): string { // Baseline gate; per-object read is checked in run(). return 'edit_posts'; } protected function is_read_only(): bool { return true; } protected function is_idempotent(): bool { return true; } protected function run( array $arguments, Request_Context $context ): Tool_Result { $id = (int) $arguments['id']; $post = get_post( $id ); if ( ! $post instanceof \WP_Post ) { return $this->fail( sprintf( /* translators: %d: post id. */ __( 'No post found with id %d.', 'gripmcp' ), $id ) ); } // Enforce per-object read permission. if ( ! Post_Access::can_see( $post, $context ) && ! $context->user_can( 'edit_post', $id ) ) { return $this->fail( __( 'You do not have permission to read this post.', 'gripmcp' ) ); } // An Elementor page's body is a stale plain-text copy. Handing it over // as the content gets it quoted as the page, or edited to no effect. if ( Elementor_Support::builds( $id ) ) { $data = Post_Presenter::to_array( $post, false ); $data['builder'] = 'elementor'; $data['note'] = Elementor_Support::body_note( $id ); return $this->data( $data, sprintf( Elementor_Support::tools_in_plan() /* translators: %s: post title. */ ? __( 'Post: %s (built with Elementor; read it with wp_elementor_get)', 'gripmcp' ) /* translators: %s: post title. */ : __( 'Post: %s (built with Elementor; its layout is the _elementor_data field)', 'gripmcp' ), Post_Presenter::title( $post ) ) ); } // A password-protected post's body is for those who can edit it, as in // the REST API. if ( ! Post_Access::can_read_body( $post, $context ) ) { $data = Post_Presenter::to_array( $post, false ); $data['excerpt'] = ''; $data['note'] = __( 'This post is password protected, and only accounts that can edit it may read its content.', 'gripmcp' ); return $this->data( $data, sprintf( /* translators: %s: post title. */ __( 'Post: %s (password protected)', 'gripmcp' ), Post_Presenter::title( $post ) ) ); } return $this->data( Post_Presenter::to_array( $post, true ), sprintf( /* translators: %s: post title. */ __( 'Post: %s', 'gripmcp' ), Post_Presenter::title( $post ) ) ); } }