Dynamic select list option

Hi,

I’ve 2 problems related to dynamic select list options, trying to add them to the settings of our custom module.

  1. Fetch options from db, inserted into array and add to options list:
                    'font_list'   => array(
                        'type'          => 'select',
                        'label'         => __('Dynamic Fonts', 'fl-builder'),
                        'default'       => '',
                        'options'       => DBUtils::get_fonts_array(),
                    ),

How is this possible to do it, if say, I need the $wp_query to read from DB?

  1. In one of the themes function.php files, we have this function:
function get_theme_test_options() {
	 $styles = array(
		  'option1'  => __( 'Option 1', 'fl-builder' ),
		  'option2' => __( 'Option 2', 'fl-builder' ),
	  );

   	return apply_filters( 'theme_test_options', $styles );
}

But when calling it from the register_module 2nd parameter:

                    'font_list'   => array(
                        'type'          => 'select',
                        'label'         => __('Dynamic Fonts', 'fl-builder'),
                        'default'       => '',
                        'options'       => get_theme_test_options(),
                    ),

I get ‘Call to undefined function theme_test_options’.

This is not our theme, obviously this is a 3rd party. Using require_once will break it, the theme does not use function_exist() on some of the functions.

Any solution?

Thanks in advance.

Hey Elemento IP,

I’ve already assigned another member of the team to assist you with you inquiry.

Ben

Hey Elemento,

It sounds like your register_module call is coming before that function is loaded. Are you loading your modules within an action? That was the old way, the new way is to do it in an action to make sure everything is loaded…

function fl_load_module_examples() {
    if ( class_exists( 'FLBuilder' ) ) {
	        require_once 'basic-example/basic-example.php';
	        require_once 'example/example.php';
    	}
}
add_action( 'init', 'fl_load_module_examples' );

Let me know.

Justin

It was actually a non related Beaver error, works like charm. Thanks

Great! Thanks for the update.

Justin