// IIFE (Immediately Invoked Function Expression) // Anonymous function (no named function), can be executed only once // Wraps the code so that $ is jQuery inside that closure, even if $ means something else outside of it // Closure. Protect the global scope // If function would be assigned to a var (not IIFE), it is a mean of Namespacing the javascript. var cmb_shortcodes = cmb_shortcodes || {}; //**************************************************************** // ¡¡¡¡ The magic: We are using a .php file as a .js file !!!!!!! /*****************************************************************/ // Javascript Ajax request must be sent to admin-ajax.php for several reasons: // 1. Loads the Wordpress Core. 2. nonces with easy built-in security. 3. "Logged in" status // admin-ajax.php constructs a hook do_action with wp_ajax_nopriv_{name of action} which executes when called // So is needed a previous add_action('wp_ajax_nopriv_{action_name}', handler) to hook in before calling admin-ajax.php via javascript. (function($) { "use strict"; // Throws more exceptions var shortcode = ''; var shortcodeUrl = ''; /* var script_tag = document.getElementById('cmb-shortcode-js'); var query = script_tag.src.replace(/^[^\?]+\??/,''); // Parse the querystring into arguments and parameters var vars = query.split("&"); var args = {}; for (var i=0; i /*************************************************** * End of specific shortcode js ****************************************************/ }); }); })(jQuery);