__( 'Get Available Locations', 'header-footer-elementor' ), 'description' => __( 'Lists all available targeting locations for display rules.', 'header-footer-elementor' ), 'category' => 'hfe-display-rules', 'permission_callback' => function () { return current_user_can( 'edit_posts' ); }, 'input_schema' => [ 'type' => 'object', 'properties' => (object) [], ], 'output_schema' => [ 'type' => 'object', 'properties' => [ 'groups' => [ 'type' => 'array', 'items' => [ 'type' => 'object', 'properties' => [ 'group' => [ 'type' => 'string' ], 'locations' => [ 'type' => 'array', 'items' => [ 'type' => 'object', 'properties' => [ 'type' => [ 'type' => 'string' ], 'label' => [ 'type' => 'string' ], ], ], ], ], ], ], ], 'required' => [ 'groups' ], ], 'meta' => [ 'annotations' => [ 'readonly' => true, 'destructive' => false, 'idempotent' => true, 'instructions' => 'Use to show available targeting options when setting display rules.', ], 'show_in_rest' => true, 'mcp' => [ 'public' => true ], ], ]; } /** * Execute the ability. * * Transforms the grouped location selections from Astra_Target_Rules_Fields * into a structured array of groups with type/label pairs. * * @since 2.9.0 * * @param array $input Validated input parameters (unused). * @return array Array of location groups. */ public function execute( $input ) { $selections = \HFE\Lib\Astra_Target_Rules_Fields::get_location_selections(); $result = []; foreach ( $selections as $group_key => $group ) { $locations = []; if ( ! empty( $group['value'] ) && is_array( $group['value'] ) ) { foreach ( $group['value'] as $type => $label ) { $locations[] = [ 'type' => $type, 'label' => $label, ]; } } $result[] = [ 'group' => isset( $group['label'] ) ? $group['label'] : $group_key, 'locations' => $locations, ]; } return [ 'groups' => $result, ]; } }