Filter uncanny-automator

uap_option_all_lf_sections

Filters the array of all LifterLMS sections available for UAP options before they are displayed.

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

Description

Filters the available LifterLMS section options for Uncanny Automator. Developers can use this hook to add custom LifterLMS section fields or modify existing ones before they are displayed in the Automator recipe builder. This filter fires when generating the list of available LifterLMS section tokens.


Usage

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

Parameters

$option (mixed)
This parameter represents the value of a setting, likely related to LifterLMS sections, which can be of mixed data types.

Return Value

The filtered value.


Examples

// Example of how to use the uap_option_all_lf_sections filter to modify LifterLMS section options.
// This example demonstrates adding a new option to include the section's access type.
add_filter( 'uap_option_all_lf_sections', 'my_custom_llms_section_options', 10, 1 );

function my_custom_llms_section_options( $option ) {

	// Assuming $option is an array that contains the existing options structure.
	// We'll add a new key-value pair to the 'options' array.
	// We need to know the current $option_code used in the original function to append to it.
	// For this example, let's assume the original $option_code is 'llms_section'.
	$original_option_code = 'llms_section'; // This is an assumption based on typical plugin naming conventions.

	// Check if the 'options' key exists and is an array before proceeding.
	if ( isset( $option['options'] ) && is_array( $option['options'] ) ) {
		$option['options'][ $original_option_code . '_access_type' ] = esc_attr__( 'Section Access Type', 'uncanny-automator' );
	}

	// The 'custom_value_description' might also need updating if the new option implies a different description.
	// In this case, 'Section ID' is still relevant for the primary custom value, so we'll leave it as is.
	// If the new option was meant to be the primary custom value, we'd adjust this.

	// Always return the modified $option array.
	return $option;
}

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/lifterlms/helpers/lifterlms-helpers.php:177

public function all_lf_sections( $label = null, $option_code = 'LFSECTION', $any_option = true ) {

		if ( ! $label ) {
			$label = esc_attr__( 'Section', 'uncanny-automator' );
		}

		$args = array(
			'post_type'      => 'section',
			'posts_per_page' => 9999,
			'orderby'        => 'title',
			'order'          => 'ASC',
			'post_status'    => 'publish',
		);

		$options = Automator()->helpers->recipe->options->wp_query( $args, $any_option, esc_attr__( 'Any section', 'uncanny-automator' ) );

		$option = array(
			'option_code'              => $option_code,
			'label'                    => $label,
			'input_type'               => 'select',
			'required'                 => true,
			// to setup example, lets define the value the child will be based on
			'current_value'            => false,
			'validation_type'          => 'text',
			'options'                  => $options,
			'relevant_tokens'          => array(
				$option_code          => esc_attr__( 'Section title', 'uncanny-automator' ),
				$option_code . '_ID'  => esc_attr__( 'Section ID', 'uncanny-automator' ),
				$option_code . '_URL' => esc_attr__( 'Section URL', 'uncanny-automator' ),
			),
			'custom_value_description' => esc_attr__( 'Section ID', 'uncanny-automator' ),
		);

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

Scroll to Top