array( 'type' => 'boolean', 'default' => false, 'description' => __( 'Return only modules that are switched on.', 'acrossai-abilities-manager' ), ), 'only_connected' => array( 'type' => 'boolean', 'default' => false, 'description' => __( 'Return only modules that are both active and fully configured, which is the set that can actually return data.', 'acrossai-abilities-manager' ), ), ); } protected function output_properties(): array { return array( 'modules' => array( 'type' => 'array' ), 'total' => array( 'type' => 'integer' ), 'active_count' => array( 'type' => 'integer' ), 'connected_count' => array( 'type' => 'integer' ), ); } protected function required_input(): array { return array(); } protected function annotations(): array { return array( 'readonly' => true, 'destructive' => false, 'idempotent' => true ); } /** * @param array $input * @return array|WP_Error */ protected function run( array $input ) { $modules = Module_Repository::list_modules(); if ( is_wp_error( $modules ) ) { return $modules; } // Counted before filtering: "3 of 9 connected" is the useful summary, and it // would be wrong if the counts described the filtered subset. $active = count( array_filter( $modules, static fn( array $m ): bool => (bool) $m['active'] ) ); $connected = count( array_filter( $modules, static fn( array $m ): bool => (bool) $m['connected'] ) ); $total = count( $modules ); if ( ! empty( $input['only_connected'] ) ) { $modules = array_filter( $modules, static fn( array $m ): bool => (bool) $m['connected'] ); } elseif ( ! empty( $input['only_active'] ) ) { $modules = array_filter( $modules, static fn( array $m ): bool => (bool) $m['active'] ); } return array( 'modules' => array_values( $modules ), 'total' => $total, 'active_count' => $active, 'connected_count' => $connected, 'message' => sprintf( /* translators: 1: total modules, 2: active count, 3: connected count */ __( 'Site Kit has %1$d modules: %2$d active, %3$d fully connected.', 'acrossai-abilities-manager' ), $total, $active, $connected ), ); } }