register_gateway($id, $title, $desc, $class_name, $hidden); } /** * Returns the currently registered gateways. * * @since 2.0.0 * * @return array */ function wu_get_gateways() { return Gateway_Manager::get_instance()->get_registered_gateways(); } /** * Returns the currently registered and active gateways. * * @since 2.0.0 * @return array */ function wu_get_active_gateways() { $gateways = []; $active_gateways = (array) wu_get_setting('active_gateways', []); foreach ($active_gateways as $active_gateway) { if (Gateway_Manager::get_instance()->is_gateway_registered($active_gateway)) { $gateways[ $active_gateway ] = Gateway_Manager::get_instance()->get_gateway($active_gateway); } } return apply_filters('wu_get_active_gateways', $gateways); } /** * Returns a gateway class if it exists. * * @since 2.0.0 * * @param string $id Gateway ID. * @param string $subscription Subscription object to load into the gateway. * @return mixed Gateway class. */ function wu_get_gateway($id, $subscription = null) { $gateway = Gateway_Manager::get_instance()->get_gateway($id); if ( ! $gateway) { return false; } $gateway_class = new $gateway['class_name'](); return $gateway_class; } /** * Returns the list of available gateways as key => name. * * @since 2.0.0 * @return array */ function wu_get_gateway_as_options() { $options = []; foreach (wu_get_gateways() as $gateway_slug => $gateway) { $instance = class_exists($gateway['class_name']) ? new $gateway['class_name']() : false; if ($instance === false || $gateway['hidden']) { continue; } $options[ $gateway_slug ] = $gateway['title']; } return $options; } /** * Get the active gateways. * * @since 2.0.0 * @return array */ function wu_get_active_gateway_as_options() { $options = []; foreach (wu_get_active_gateways() as $gateway_slug => $gateway) { $instance = class_exists($gateway['class_name']) ? new $gateway['class_name']() : false; if ($instance === false || $gateway['hidden']) { continue; } $title = $instance->get_public_title(); $options[ $gateway_slug ] = apply_filters("wu_gateway_{$gateway_slug}_as_option_title", $title, $gateway); } return $options; }