Filter uncanny-automator

uap_option_get_ws_all_forms

Filters the settings for all WS Form Lite forms before they are retrieved by the User Access Manager plugin.

add_filter( 'uap_option_get_ws_all_forms', $callback, 10, 1 );

Description

This filter hook, `uap_option_get_ws_all_forms`, fires after retrieving form options for WS Form Lite. Developers can use it to modify or extend the returned form options array before it's used. This allows for customization of form data or adding new properties.


Usage

add_filter( 'uap_option_get_ws_all_forms', 'your_function_name', 10, 1 );

Parameters

$option (mixed)
This parameter represents the value of the option being filtered, which is typically an array of WS-Form Lite forms.

Return Value

The filtered value.


Examples

<?php
/**
 * Example of how to hook into 'uap_option_get_ws_all_forms' to modify the options
 * passed to WS Forms. This could be used to conditionally add or remove options
 * based on other plugin settings or user roles.
 *
 * @param array $option The original array of options for WS Forms.
 * @return array The modified array of options for WS Forms.
 */
add_filter( 'uap_option_get_ws_all_forms', function( $option ) {

    // Let's say we want to add a custom option only if a specific option
    // in our plugin is enabled.
    if ( class_exists( 'My_Awesome_Plugin' ) && My_Awesome_Plugin()->settings->get( 'enable_ws_form_custom_field' ) ) {
        $option['custom_field_settings'] = array(
            'label'       => __( 'My Custom Field Label', 'my-awesome-plugin' ),
            'description' => __( 'This is a special field for advanced users.', 'my-awesome-plugin' ),
            'type'        => 'text',
            'required'    => false,
        );
    }

    // You could also remove an existing option if needed.
    // For example, if we don't want to support custom values for certain forms:
    if ( isset( $option['supports_custom_value'] ) && ! My_Awesome_Plugin()->settings->get( 'allow_all_custom_values' ) ) {
        $option['supports_custom_value'] = false;
    }

    // Always return the modified (or original) $option array.
    return $option;

}, 10, 1 ); // Priority 10, accepts 1 argument.
?>

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/ws-form-lite/helpers/ws-form-lite-helpers.php:71

public function get_ws_all_forms( $label = null, $option_code = 'WSF_FORMS', $args = array(), $is_any = false, $is_all = false, $tokens = array(), $supports_custom_value = false ) {
		$options = array();

		if ( $is_all ) {
			$options['-1'] = esc_html__( 'All forms', 'uncanny-automator' );
		}

		if ( $is_any ) {
			$options['-1'] = esc_html__( 'Any form', 'uncanny-automator' );
		}

		$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'] : '';
		$ws_form_form = new WS_Form_Form();
		$forms        = $ws_form_form->db_read_all( '', "NOT (status = 'trash')", 'label ASC, id ASC', '', '', false );

		foreach ( $forms as $form ) {
			$title = esc_html( $form['label'] );
			if ( empty( $title ) ) {
				// translators: 1: Form ID
				$title = sprintf( esc_attr__( 'ID: %s (no title)', 'uncanny-automator' ), $form['id'] );
			}
			$options[ $form['id'] ] = $title;
		}

		$option = array(
			'input_type'            => 'select',
			'option_code'           => $option_code,
			/* translators: HTTP request method */
			'label'                 => empty( $label ) ? esc_attr__( 'Form', 'uncanny-automator' ) : $label,
			'required'              => true,
			'is_ajax'               => $is_ajax,
			'fill_values_in'        => $target_field,
			'endpoint'              => $end_point,
			'supports_custom_value' => $supports_custom_value,
			'relevant_tokens'       => $tokens,
			'options'               => $options,
		);

		return apply_filters( 'uap_option_get_ws_all_forms', $option );
	}

Scroll to Top