Filter
uncanny-automator
uap_option_list_webhook_triggers
Filters the list of available webhook trigger options for user actions.
add_filter( 'uap_option_list_webhook_triggers', $callback, 10, 1 );
Description
This filter hook, `uap_option_list_webhook_triggers`, allows developers to modify the list of available webhook triggers for User Action Protector. It fires when constructing the trigger options for the WP Webhooks integration, enabling customization of trigger names, endpoint details, or additional options. Use this hook to add custom triggers or alter existing ones before they are presented to the user.
Usage
add_filter( 'uap_option_list_webhook_triggers', 'your_function_name', 10, 1 );
Parameters
-
$option(mixed) - This parameter contains the current value of the webhook trigger option being filtered.
Return Value
The filtered value.
Examples
/**
* Example function to modify the webhook trigger options.
*
* This function might be used to dynamically enable or disable certain webhook
* triggers based on other plugin settings or the current context.
*
* @param array $option The original array of webhook trigger options.
* @return array The modified array of webhook trigger options.
*/
function my_custom_uap_webhook_triggers( $option ) {
// Example: If a specific setting is enabled, let's ensure the 'user_login' trigger is available.
// In a real scenario, you'd likely check against a WordPress option or a global variable.
$is_premium_feature_enabled = get_option( 'my_plugin_premium_feature_enabled', false );
if ( $is_premium_feature_enabled && ! isset( $option['triggers']['user_login'] ) ) {
$option['triggers']['user_login'] = array(
'label' => __( 'User Logged In', 'my-text-domain' ),
'is_ajax' => true,
'fill_values_in' => 'user_data',
'endpoint' => esc_url_raw( admin_url( 'admin-ajax.php' ) ),
'options' => array(
'user_id' => array( 'label' => __( 'User ID', 'my-text-domain' ) ),
'username' => array( 'label' => __( 'Username', 'my-text-domain' ) ),
),
'relevant_tokens' => array( 'user_id', 'username', 'user_email' ),
);
}
// Example: If another specific setting is disabled, let's remove a trigger.
$disable_specific_trigger = get_option( 'my_plugin_disable_registration_webhook', false );
if ( $disable_specific_trigger && isset( $option['triggers']['user_registered'] ) ) {
unset( $option['triggers']['user_registered'] );
}
return $option;
}
add_filter( 'uap_option_list_webhook_triggers', 'my_custom_uap_webhook_triggers', 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-webhooks/helpers/wpwh-helpers.php:96
public function list_webhook_triggers( $label = null, $option_code = 'WPWHTRIGGER', $args = array() ) {
if ( ! $label ) {
$label = esc_html__( 'Webhook triggers', 'uncanny-automator' );
}
$token = key_exists( 'token', $args ) ? $args['token'] : false;
$is_ajax = key_exists( 'is_ajax', $args ) ? $args['is_ajax'] : false;
$target_field = key_exists( 'target_field', $args ) ? $args['target_field'] : '';
$end_point = key_exists( 'endpoint', $args ) ? $args['endpoint'] : '';
$options = array();
$options['-1'] = esc_html__( 'Any trigger', 'uncanny-automator' );
$triggers = WPWHPRO()->webhook->get_triggers();
$active_webhooks = WPWHPRO()->settings->get_active_webhooks( 'all' );
foreach ( $triggers as $trigger ) {
if ( isset( $active_webhooks['triggers'][ $trigger['trigger'] ] ) ) {
$options[ $trigger['trigger'] ] = $trigger['name'];
}
}
$option = array(
'option_code' => $option_code,
'label' => $label,
'input_type' => 'select',
'required' => true,
'supports_tokens' => $token,
'is_ajax' => $is_ajax,
'fill_values_in' => $target_field,
'endpoint' => $end_point,
'options' => $options,
'relevant_tokens' => array(),
);
return apply_filters( 'uap_option_list_webhook_triggers', $option );
}