I have created a php class file. I am enqueuing the required CSS and JS files in the class's constructor.
public function __construct() {
add_action('wp_enqueue_scripts', array($this, 'formdb_enqueue_scripts'));
}
Plugin uses a shortcode that outputs the required content. My problem is that if I create the instance of class in the shortcode then it doesn't load the CSS and JS files.
This doesn't work.
add_shortcode('render_form', array($this, 'wp_db_fb_co_form_render'));
public function wp_db_fb_co_form_render($atts)
{
$this->classob = new ClassObj();//class object inside the shortcode
$atts = shortcode_atts(array(
'id' => 0,
), $atts, 'fd-form');
$form_id = $atts["id"];
if($form_id) {
$form_info = $this->get_form_data_by_form_id($form_id);
$form_data = $form_info["form_data"];
echo $this->output_form($form_data, "insertform");
}
}
If I create instance of class before the shortcode, then it works.
Let me know what is correct way to do this.