static function wp_ajax_spacker_inc_script() { // ----------------------------- Add JS -------------------------------- if ($_POST['mode'] == 'add-js') { if (!is_array(evScriptOptimizer::$options['inc-js'])) { evScriptOptimizer::$options['inc-js'] = array(); } $name = trim($_POST['name']); $url = trim($_POST['url']); $error_message = ''; // Validate if (empty($name) || empty($url)) { $error_message = __('Fields "Name" and "URL" cannot be empty.', 'spacker'); } elseif (isset(evScriptOptimizer::$options['inc-js'][$name])) { $error_message = __('This name is already used.', 'spacker'); } else { // Add script evScriptOptimizer::$options['inc-js'][$name] = array('name' => $name, 'url' => $url); evScriptOptimizer::save_options(); } // Output if ($error_message) { ?> <div class="error settings-error"> <p><strong><?php echo $error_message; ?> </strong></p> </div> <?php } else { ?> <div class="updated"> <p><strong><?php _e('Script has been added.', 'spacker'); ?> </strong></p> </div> <?php } self::get_spacker_inc_js_table(); } elseif ($_POST['mode'] == 'delete-js') { $name = $_POST['name']; if (!isset(evScriptOptimizer::$options['inc-js'][$name])) { $error_message = __('Cannot find this script.', 'spacker'); } else { // Delete script unset(evScriptOptimizer::$options['inc-js'][$name]); evScriptOptimizer::save_options(); } // Output if ($error_message) { ?> <div class="error settings-error"> <p><strong><?php echo $error_message; ?> </strong></p> </div> <?php } else { ?> <div class="updated"> <p><strong><?php _e('Script has been deleted.', 'spacker'); ?> </strong></p> </div> <?php } self::get_spacker_inc_js_table(); } elseif ($_POST['mode'] == 'add-css') { if (!is_array(evScriptOptimizer::$options['inc-css'])) { evScriptOptimizer::$options['inc-css'] = array(); } $name = trim($_POST['name']); $url = trim($_POST['url']); $media = trim($_POST['media']); $loggedIn = $_POST['loggedIn'] ? 1 : 0; $error_message = ''; // Validate if (empty($name) || empty($url)) { $error_message = __('Fields "Name" and "URL" cannot be empty.', 'spacker'); } elseif (isset(evScriptOptimizer::$options['inc-css'][$name])) { $error_message = __('This Name is already used.', 'spacker'); } else { // Add script evScriptOptimizer::$options['inc-css'][$name] = array('name' => $name, 'url' => $url, 'media' => $media, 'loggedIn' => $loggedIn); evScriptOptimizer::save_options(); } // Output if ($error_message) { ?> <div class="error settings-error"> <p><strong><?php echo $error_message; ?> </strong></p> </div> <?php } else { ?> <div class="updated"> <p><strong><?php _e('Script has been added.', 'spacker'); ?> </strong></p> </div> <?php } self::get_spacker_inc_css_table(); } elseif ($_POST['mode'] == 'delete-css') { $name = $_POST['name']; if (!isset(evScriptOptimizer::$options['inc-css'][$name])) { $error_message = __('Cannot find this script.', 'spacker'); } else { // Delete script unset(evScriptOptimizer::$options['inc-css'][$name]); evScriptOptimizer::save_options(); } // Output if ($error_message) { ?> <div class="error settings-error"> <p><strong><?php echo $error_message; ?> </strong></p> </div> <?php } else { ?> <div class="updated"> <p><strong><?php _e('Script has been deleted.', 'spacker'); ?> </strong></p> </div> <?php } self::get_spacker_inc_css_table(); } die; }
static function ordering_stop() { if (!self::$ordering_started) { return; } self::$ordering_started = false; $html = ob_get_contents(); ob_end_clean(); $html = self::order_scripts($html); echo $html; }