Filter
uncanny-automator
uap_option_list_wp_simpay_forms
Filters the list of payment form options for SimPay integrations, allowing customization before display.
add_filter( 'uap_option_list_wp_simpay_forms', $callback, 10, 1 );
Description
Filters the list of options for WP Simple Pay forms, allowing developers to customize the available form titles and IDs. This hook fires when the plugin is preparing the list of options for form selection within automations. Developers can add, remove, or modify form entries to suit specific integration needs.
Usage
add_filter( 'uap_option_list_wp_simpay_forms', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter is the current option value being filtered, which can be of any mixed data type.
Return Value
The filtered value.
Examples
<?php
/**
* Filter the WP Simple Pay form options to add custom data or modify existing data.
*
* This example demonstrates how to conditionally add a new token representing
* a specific attribute of the form, if that attribute is available.
*
* @param array $option The array of options passed to the filter. Expected to contain 'options' and 'relevant_tokens'.
* @return array The modified $option array.
*/
add_filter( 'uap_option_list_wp_simpay_forms', function( $option ) {
// Check if the 'options' key exists and contains form data.
if ( ! isset( $option['options']['forms'] ) || empty( $option['options']['forms'] ) ) {
return $option; // Return original if no forms found.
}
// Assume $option_code is available in the scope where the original filter is applied.
// For demonstration, we'll define a placeholder. In a real scenario, it would be passed or available.
$option_code_placeholder = 'simpay_form';
// Iterate through each form to potentially add custom tokens.
foreach ( $option['options']['forms'] as $form_id => $form_data ) {
// Example: Add a token for the form's payment gateway if it's Stripe.
if ( isset( $form_data['payment_gateway'] ) && 'stripe' === $form_data['payment_gateway'] ) {
$stripe_specific_token_key = $option_code_placeholder . '_' . $form_id . '_stripe_only';
$option['relevant_tokens'][ $stripe_specific_token_key ] = esc_attr_x( 'Form is Stripe Payment Enabled', 'Wp Simple Pay', 'uncanny-automator' );
}
// Example: Add a token for the form's currency if it's USD.
if ( isset( $form_data['currency'] ) && 'USD' === $form_data['currency'] ) {
$usd_specific_token_key = $option_code_placeholder . '_' . $form_id . '_usd_currency';
$option['relevant_tokens'][ $usd_specific_token_key ] = esc_attr_x( 'Form Currency is USD', 'Wp Simple Pay', 'uncanny-automator' );
}
}
return $option;
}, 10, 1 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/integrations/wp-simple-pay/helpers/wpsp-helpers.php:117
public function list_wp_simpay_forms( $label = null, $option_code = 'WPSPFORMS', $args = array() ) {
if ( ! $label ) {
$label = esc_attr_x( 'Form', 'Wp Simple Pay', 'uncanny-automator' );
}
$token = key_exists( 'token', $args ) ? $args['token'] : false;
$is_any = key_exists( 'is_any', $args ) ? $args['is_any'] : false;
$is_subscription = key_exists( 'is_subscription', $args ) ? $args['is_subscription'] : false;
$options = array();
$wpsp_forms = $this->get_forms();
if ( ! empty( $wpsp_forms ) ) {
foreach ( $wpsp_forms as $form_id => $form_title ) {
$form = simpay_get_form( $form_id );
if ( true === $is_subscription && 'disabled' === $form->subscription_type ) {
continue;
}
$options[ $form_id ] = ! empty( $form_title ) ? $form_title : $form->company_name;
}
}
if ( true === $is_any ) {
$options = array( '-1' => esc_html_x( 'Any form', 'Wp Simple Pay', 'uncanny-automator' ) ) + $options;
}
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'supports_tokens' => $token,
'options' => $options,
'relevant_tokens' => array(
$option_code => esc_attr_x( 'Form title', 'Wp Simple Pay', 'uncanny-automator' ),
$option_code . '_ID' => esc_attr_x( 'Form ID', 'Wp Simple Pay', 'uncanny-automator' ),
),
);
return apply_filters( 'uap_option_list_wp_simpay_forms', $option );
}