getInputs(); $module_key = $inputs['module_key'] ?? '(unknown)'; $action = $inputs['action'] ?? 'enable'; $verb = 'disable' === strtolower( $action ) ? 'Disable' : 'Enable'; $module = wpcafe_extension()->find( $module_key ); $title = $module ? ( $module['title'] ?? $module_key ) : $module_key; return "{$verb} the `{$title}` module"; } /** * Human-readable inputs shown in the approval card table. * * @return array */ public function get_approval_inputs(): array { $inputs = $this->getInputs(); $module_key = $inputs['module_key'] ?? ''; $action = $inputs['action'] ?? 'enable'; $module = wpcafe_extension()->find( $module_key ); $title = $module ? ( $module['title'] ?? $module_key ) : $module_key; return [ 'module' => $title . ' (' . $module_key . ')', 'action' => ucfirst( strtolower( $action ) ), ]; } /** * Execute the module toggle after human approval. * * @param string $module_key Module key to toggle. * @param string $action 'enable' or 'disable'. * @return array */ public function __invoke( string $module_key, string $action ): array { $check = $this->guard( 'manage_options', 'manage_woocommerce' ); if ( $check ) { return $check; } $module_key = sanitize_key( $module_key ); $action = strtolower( trim( $action ) ); if ( ! in_array( $action, [ 'enable', 'disable' ], true ) ) { return [ 'error' => "Invalid action '{$action}'. Accepted values: enable, disable." ]; } $extension = wpcafe_extension(); $module = $extension->find( $module_key ); if ( ! $module ) { return [ 'error' => "Module '{$module_key}' not found. Use wpcafe-list-modules to see available modules." ]; } if ( 'module' !== ( $module['type'] ?? '' ) ) { return [ 'error' => "'{$module_key}' is not a module. Only modules can be toggled with this tool." ]; } $status = 'enable' === $action ? 'on' : 'off'; $updated = $extension->update( $module_key, $status ); if ( ! $updated ) { return [ 'error' => "Failed to update module '{$module_key}'. The option may already be set to the requested state." ]; } $title = $module['title'] ?? $module_key; $verb = 'enable' === $action ? 'enabled' : 'disabled'; return [ 'success' => true, 'module' => $module_key, 'title' => $title, 'status' => $status, 'message' => "Module '{$title}' has been {$verb} successfully.", ]; } }