This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Why AI can discover and understand your abilities | |
| 'meta' => array( | |
| 'annotations' => array( | |
| 'readonly' => true, | |
| 'destructive' => false, | |
| 'idempotent' => true, | |
| ), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // example of registering an ability | |
| wp_register_ability( | |
| 'content-strategist/get-top-posts', | |
| array( | |
| 'label' => __( 'Get Top Posts', 'ai-content-strategist' ), | |
| 'description' => __( 'Returns the site\'s top performing posts by views. Useful for understanding what content resonates with your audience.', 'ai-content-strategist' ), | |
| 'category' => 'content', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // AI reads this to understand how to call your ability | |
| 'input_schema' => array( | |
| 'type' => 'object', | |
| 'additionalProperties' => false, | |
| 'properties' => array( | |
| 'days' => array( | |
| 'type' => 'integer', |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Fetching data from Jetpack Stats and enriching with WordPress | |
| public function execute_get_top_posts( array $input ): array|\WP_Error { | |
| // Verify Jetpack is connected. | |
| if ( ! Plugin::is_jetpack_connected() || ! Plugin::is_stats_available() ) { | |
| return Plugin::get_jetpack_not_connected_error(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Combining Jetpack views with WordPress post metadata | |
| private function process_top_posts( array $top_posts_data, int $limit ): array { | |
| $result = array(); | |
| // The data structure varies based on the Jetpack Stats response. | |
| $posts = $top_posts_data['summary']['postviews'] ?? $top_posts_data['posts'] ?? array(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Draft posts have zeroed GMT dates until published | |
| private function get_post_timestamp( \WP_Post $post, string $type = 'date' ): int { | |
| $gmt_field = 'modified' === $type ? 'post_modified_gmt' : 'post_date_gmt'; | |
| $local_field = 'modified' === $type ? 'post_modified' : 'post_date'; | |
| // Check if GMT date is valid (not zeroed). | |
| $gmt_date = $post->$gmt_field; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Plugin works partially even without Jetpack | |
| public static function is_jetpack_connected(): bool { | |
| if ( ! class_exists( 'Automattic\Jetpack\Connection\Manager' ) ) { | |
| return false; | |
| } | |
| $connection_manager = new \Automattic\Jetpack\Connection\Manager(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| // Extending the Abilities API with a content category | |
| public function register_ability_category(): void { | |
| wp_register_ability_category( | |
| 'content', | |
| array( | |
| 'label' => __( 'Content', 'ai-content-strategist' ), | |
| 'description' => __( 'Abilities for content analysis, auditing, and strategy.', 'ai-content-strategist' ), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| //One line to expose all abilities via MCP | |
| private function init_mcp_adapter(): void { | |
| if ( class_exists( \WP\MCP\Core\McpAdapter::class ) ) { | |
| \WP\MCP\Core\McpAdapter::instance(); | |
| } | |
| } |