/*pridat do functions.php*/ /** * Add Custom Admin Bar Menu Link * * @param $admin_bar * * @return void */ if (!function_exists('pac_misc_csc_maybe_admin_bar_link')): function pac_misc_csc_maybe_admin_bar_link($admin_bar) { $admin_bar->add_menu([ 'id' => 'pac_misc_csc', 'title' => '<span class="ab-icon"></span><span class="ab-label">Clear Divi Cache</span>', 'href' => '', 'meta' => [ 'title' => '', ], ]); $admin_bar->add_menu([ 'id' => 'pac_misc_clear_static_css', 'parent' => 'pac_misc_csc', 'title' => sprintf('<span data-wpnonce="%1$s">%2$s</span>', wp_create_nonce('pac_misc_clear_static_css'), esc_html('Clear Static CSS File Generation')), 'href' => 'javascript:void(0)', ]); $admin_bar->add_menu([ 'id' => 'pac_misc_csc_clear_local_storage', 'parent' => 'pac_misc_csc', 'title' => esc_html('Clear Local Storage'), 'href' => 'javascript:void(0)', ]); } add_action('admin_bar_menu', 'pac_misc_csc_maybe_admin_bar_link', 999); endif; /** * Add Javascript In Admin Footer * * @return void */ if (!function_exists('pac_misc_csc_maybe_admin_scripts')): function pac_misc_csc_maybe_admin_scripts() { ?> <script> jQuery(document).ready(function () { var adminAaxURL = '<?php echo admin_url('admin-ajax.php'); ?>'; var isAdmin = '<?php echo is_admin(); ?>'; // Clear Static CSS jQuery("#wp-admin-bar-pac_misc_clear_static_css").click(function (e) { e.preventDefault(); jQuery.ajax({ type: 'post', dataType: 'json', url: adminAaxURL, data: { 'action': 'pac_misc_clear_static_css', '_wpnonce': jQuery(this).find('span').data('wpnonce') }, success: function (response) { if (response.success) { let successData = response.data; if (isAdmin) { let messageHTML = '<div class="notice notice-success pac-misc-message"><p>' + successData + '</p></div>'; if (jQuery('body .wrap h1').length > 0) { jQuery('body .wrap h1').after(messageHTML); } else { jQuery('body #wpbody-content').prepend(messageHTML); } setTimeout(function () { jQuery(".pac-misc-message").remove(); }, 3500); } else { alert(successData); } } }, }); }); // Clear Local Storage jQuery("#wp-admin-bar-pac_misc_csc_clear_local_storage").click(function (e) { e.preventDefault(); let msgText = 'The local storage has been cleared!'; window.localStorage.clear(); if (isAdmin) { let messageHTML = '<div class="notice notice-success pac-misc-message"><p>' + msgText + '</p></div>'; if (jQuery('body .wrap h1').length > 0) { jQuery('body .wrap h1').after(messageHTML); } else { jQuery('body #wpbody-content').prepend(messageHTML); } setTimeout(function () { jQuery(".pac-misc-message").remove(); }, 3500); } else { alert(msgText); } }); }); </script> <?php } add_action('admin_footer', 'pac_misc_csc_maybe_admin_scripts'); add_action('wp_footer', 'pac_misc_csc_maybe_admin_scripts'); endif; /** * Process Ajax Request * * @return void */ if (!function_exists('pac_misc_csc_maybe_ajax_request')): function pac_misc_csc_maybe_ajax_request() { if ((isset($_POST['action']) && 'pac_misc_clear_static_css' === sanitize_text_field($_POST['action'])) && (isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'pac_misc_clear_static_css'))) { ET_Core_PageResource::remove_static_resources('all', 'all'); wp_send_json_success(esc_html('The static CSS file generation has been cleared!'), 200); } } add_action('wp_ajax_pac_misc_clear_static_css', 'pac_misc_csc_maybe_ajax_request'); endif;
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter