get( $ability_key, 'abilities', true, false ); } public function register_categories( $categories ) { wp_register_ability_category( 'ad-management', array( 'label' => __( 'Ad Management', 'ad-commander' ), 'description' => __( 'Abilities for managing ads.', 'ad-commander' ), ) ); } public function register_abilities( $abilities ) { if ( $this->is_enabled( 'ability_get_ad_stats' ) ) { $this->register_ability_get_ad_stats(); } if ( $this->is_enabled( 'ability_list_ads' ) ) { $this->register_ability_list_ads(); } } private function register_ability_get_ad_stats() { wp_register_ability( 'ad-commander/get-ad-stats', array( 'label' => __( 'Get Ad Statistics', 'ad-commander' ), 'description' => __( 'Retrieves impression and click statistics for a specific ad or all ads within a date range.', 'ad-commander' ), 'category' => 'ad-management', 'input_schema' => array( 'type' => 'object', 'properties' => array( 'period' => array( 'type' => 'string', 'enum' => array( 'today', 'yesterday', 'this_week', 'this_month', 'this_year', 'last_week', 'last_month', 'last_year', 'past_7_days', 'past_14_days', 'past_30_days', 'past_365_days', 'custom' ), 'description' => __( 'The time period for which to retrieve statistics. Defaults to past_7_days. Use custom to specify a custom date range.', 'ad-commander' ), ), 'group_by' => array( 'type' => 'string', 'enum' => array( 'hour', 'day', 'week', 'month' ), 'description' => __( 'How to group the statistics by time period. Defaults to day.', 'ad-commander' ), ), 'start_date' => array( 'type' => 'string', 'description' => __( 'Start date in Y-m-d format. Required when period is custom.', 'ad-commander' ), ), 'end_date' => array( 'type' => 'string', 'description' => __( 'End date in Y-m-d format. Required when period is custom.', 'ad-commander' ), ), 'filter_by_ad_ids' => array( 'type' => 'array', 'items' => array( 'type' => 'integer' ), 'description' => __( 'Optional array of ad post IDs to filter results by.', 'ad-commander' ), ), ), ), 'output_schema' => array( 'type' => 'object', 'properties' => array( 'by_date' => array( 'type' => 'array', 'description' => __( 'Statistics grouped by date.', 'ad-commander' ), 'items' => array( 'type' => 'object', 'properties' => array( 'date' => array( 'type' => 'string', 'description' => __( 'Formatted date label for the item period.', 'ad-commander' ), ), 'date_alt' => array( 'type' => 'string', 'description' => __( 'Alternate shorter date label for the item period.', 'ad-commander' ), ), 'timestamp' => array( 'type' => 'integer', 'description' => __( 'Unix timestamp for the item period. If group_by is week or month, this represents the start of the period.', 'ad-commander' ), ), 'impressions' => array( 'type' => 'integer', 'description' => __( 'The number of impressions for all ads on this item period.', 'ad-commander' ), ), 'clicks' => array( 'type' => 'integer', 'description' => __( 'The number of clicks on all ads on this item period.', 'ad-commander' ), ), 'ctr' => array( 'type' => 'number', 'description' => __( 'Click-through rate as a percentage for all ads on this item period.', 'ad-commander' ), ), ), ), ), 'by_ad' => array( 'type' => 'array', 'description' => __( 'Statistics grouped by ad.', 'ad-commander' ), 'items' => array( 'type' => 'object', 'properties' => array( 'ad_id' => array( 'type' => 'integer', 'description' => __( 'The ad\'s post ID.', 'ad-commander' ), ), 'ad' => array( 'type' => 'string', 'description' => __( 'The ad title.', 'ad-commander' ), ), 'edit_link' => array( 'type' => 'string', 'description' => __( 'URL to edit the ad.', 'ad-commander' ), ), 'impressions' => array( 'type' => 'integer', 'description' => __( 'The number of impressions for the ad in the chosen time period.', 'ad-commander' ), ), 'clicks' => array( 'type' => 'integer', 'description' => __( 'The number of clicks on the ad in the chosen time period.', 'ad-commander' ), ), 'ctr' => array( 'type' => 'number', 'description' => __( 'Click-through rate as a percentage for the ad during the chosen time period.', 'ad-commander' ), ), ), ), ), ), ), 'execute_callback' => 'adcmdr_ability_get_ad_stats', 'permission_callback' => function () { return current_user_can( AdCommander::capability() ); }, 'meta' => array( 'show_in_rest' => true, 'annotations' => array( 'readonly' => true, 'destructive' => false, 'idempotent' => true, ), ), ) ); } private function register_ability_list_ads() { wp_register_ability( 'ad-commander/list-ads', array( 'label' => __( 'List Ads', 'ad-commander' ), 'description' => __( 'Retrieves a list of ads with basic information to help identify them. Only ads with publish or draft status are returned.', 'ad-commander' ), 'category' => 'ad-management', 'input_schema' => array( 'type' => 'object', 'properties' => array( 'ad_ids' => array( 'type' => 'array', 'items' => array( 'type' => 'integer' ), 'description' => __( 'Optional array of ad post IDs to retrieve. If not specified, all ads are returned.', 'ad-commander' ), ), 'post_statuses' => array( 'type' => 'array', 'items' => array( 'type' => 'string', 'enum' => array( 'publish', 'draft' ), ), 'description' => __( 'Optional array of post statuses to filter by. Accepts publish and draft. Defaults to both.', 'ad-commander' ), ), ), ), 'output_schema' => array( 'type' => 'array', 'description' => __( 'A list of ads.', 'ad-commander' ), 'items' => array( 'type' => 'object', 'properties' => array( 'ad_id' => array( 'type' => 'integer', 'description' => __( 'The ad\'s post ID.', 'ad-commander' ), ), 'ad_title' => array( 'type' => 'string', 'description' => __( 'The ad title.', 'ad-commander' ), ), 'ad_status' => array( 'type' => 'string', 'description' => __( 'The ad\'s post status.', 'ad-commander' ), ), ), ), ), 'execute_callback' => 'adcmdr_ability_list_ads', 'permission_callback' => function () { return current_user_can( AdCommander::capability() ); }, 'meta' => array( 'show_in_rest' => true, 'annotations' => array( 'readonly' => true, 'destructive' => false, 'idempotent' => true, ), ), ) ); } }