<?php

/**
 * Autoload the different Intense classes as needed
 */
spl_autoload_register(function ($class) {
    global $intense_widgets_list, $intense_shortcode_list, $intense_custom_post_types_list;

    if ( isset( $intense_shortcode_list[ $class ] ) ) {
        include $intense_shortcode_list[ $class ]['path'];        
    }

    if ( isset( $intense_custom_post_types_list[ $class ] ) ) {
        include $intense_custom_post_types_list[ $class ]['path'];
    }

    if ( isset( $intense_widgets_list[ $class ] ) ) {
        include $intense_widgets_list[ $class ]['path'];
    }
});

/**
 * Returns a function that can be used to call the shortcode
 * @param  string $shortcode the shortcode name
 * @return function            a closure function that can be called to run the shortcode
 */
function intense_get_shortcode_closure( $shortcode ) {
    $function = new WrappedClosure( function( $atts, $content ) use ( $shortcode ) {
        return intense_run_shortcode( $shortcode, $atts, $content );
    } );

    return $function;
}