Title: MessagePart::__construct
Published: May 20, 2026

---

# MessagePart::__construct( mixed $content, WordPressAiClientMessagesEnumsMessagePartChannelEnum|null $channel = null, string|null $thoughtSignature = null )

## In this article

 * [Parameters](https://developer.wordpress.org/reference/classes/wordpress-aiclient-messages-dto-messagepart/__construct/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-messages-dto-messagepart/__construct/?output_format=md#source)
 * [Related](https://developer.wordpress.org/reference/classes/wordpress-aiclient-messages-dto-messagepart/__construct/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-messages-dto-messagepart/__construct/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/classes/wordpress-aiclient-messages-dto-messagepart/__construct/?output_format=md#wp--skip-link--target)

Constructor that accepts various content types and infers the message part type.

## 󠀁[Parameters](https://developer.wordpress.org/reference/classes/wordpress-aiclient-messages-dto-messagepart/__construct/?output_format=md#parameters)󠁿

 `$content`mixedrequired

The content of this message part.

`$channel`WordPressAiClientMessagesEnumsMessagePartChannelEnum|nulloptional

The channel this part belongs to. Defaults to CONTENT.

Default:`null`

`$thoughtSignature`string|nulloptional

Optional thought signature for extended thinking.

Default:`null`

## 󠀁[Source](https://developer.wordpress.org/reference/classes/wordpress-aiclient-messages-dto-messagepart/__construct/?output_format=md#source)󠁿

    ```php
    public function __construct($content, ?MessagePartChannelEnum $channel = null, ?string $thoughtSignature = null)
    {
        $this->channel = $channel ?? MessagePartChannelEnum::content();
        $this->thoughtSignature = $thoughtSignature;
        if (is_string($content)) {
            $this->type = MessagePartTypeEnum::text();
            $this->text = $content;
        } elseif ($content instanceof File) {
            $this->type = MessagePartTypeEnum::file();
            $this->file = $content;
        } elseif ($content instanceof FunctionCall) {
            $this->type = MessagePartTypeEnum::functionCall();
            $this->functionCall = $content;
        } elseif ($content instanceof FunctionResponse) {
            $this->type = MessagePartTypeEnum::functionResponse();
            $this->functionResponse = $content;
        } else {
            $type = is_object($content) ? get_class($content) : gettype($content);
            throw new InvalidArgumentException(sprintf('Unsupported content type %s. Expected string, File, ' . 'FunctionCall, or FunctionResponse.', $type));
        }
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/php-ai-client/src/messages/dto/messagepart.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.0/src/wp-includes/php-ai-client/src/Messages/DTO/MessagePart.php#L85)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.0/src/wp-includes/php-ai-client/src/Messages/DTO/MessagePart.php#L85-L105)

## 󠀁[Related](https://developer.wordpress.org/reference/classes/wordpress-aiclient-messages-dto-messagepart/__construct/?output_format=md#related)󠁿

| Used by | Description | 
| [MessagePart::fromArray()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-messages-dto-messagepart/fromarray/)`wp-includes/php-ai-client/src/Messages/DTO/MessagePart.php` |

{@inheritDoc}

  | 
| [PromptBuilder::parseMessage()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/parsemessage/)`wp-includes/php-ai-client/src/Builders/PromptBuilder.php` |

Parses various input types into a Message with the given role.

  | 
| [PromptBuilder::withText()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/withtext/)`wp-includes/php-ai-client/src/Builders/PromptBuilder.php` |

Adds text to the current message.

  | 
| [PromptBuilder::withFile()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/withfile/)`wp-includes/php-ai-client/src/Builders/PromptBuilder.php` |

Adds a file to the current message.

  | 
| [PromptBuilder::withFunctionResponse()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-promptbuilder/withfunctionresponse/)`wp-includes/php-ai-client/src/Builders/PromptBuilder.php` |

Adds a function response to the current message.

  | 
| [MessageBuilder::withText()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-messagebuilder/withtext/)`wp-includes/php-ai-client/src/Builders/MessageBuilder.php` |

Adds text content to the message.

  | 
| [MessageBuilder::withFile()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-messagebuilder/withfile/)`wp-includes/php-ai-client/src/Builders/MessageBuilder.php` |

Adds a file to the message.

  | 
| [MessageBuilder::withFunctionCall()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-messagebuilder/withfunctioncall/)`wp-includes/php-ai-client/src/Builders/MessageBuilder.php` |

Adds a function call to the message.

  | 
| [MessageBuilder::withFunctionResponse()](https://developer.wordpress.org/reference/classes/wordpress-aiclient-builders-messagebuilder/withfunctionresponse/)`wp-includes/php-ai-client/src/Builders/MessageBuilder.php` |

Adds a function response to the message.

  | 
| [WP_AI_Client_Ability_Function_Resolver::execute_abilities()](https://developer.wordpress.org/reference/classes/wp_ai_client_ability_function_resolver/execute_abilities/)`wp-includes/ai-client/class-wp-ai-client-ability-function-resolver.php` |

Executes all ability function calls in a message.

  |

[Show 5 more](https://developer.wordpress.org/reference/classes/wordpress-aiclient-messages-dto-messagepart/__construct/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/classes/wordpress-aiclient-messages-dto-messagepart/__construct/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/classes/wordpress-aiclient-messages-dto-messagepart/__construct/?output_format=md#changelog)󠁿

| Version | Description | 
| [0.1.0](https://developer.wordpress.org/reference/since/0.1.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Fclasses%2Fwordpress-aiclient-messages-dto-messagepart%2F__construct%2F)
before being able to contribute a note or feedback.