Skip to content

Instantly share code, notes, and snippets.

View dkvadratu's full-sized avatar

Deividas dkvadratu

View GitHub Profile
@dkvadratu
dkvadratu / wp_CF7_disabled_API_refill_call.js
Last active March 30, 2021 09:55
{WP} CF7 disable Refill HTTP call. Add this script to site footer or elsewhere.
<script> wpcf7.cached = 0; </script>
@dkvadratu
dkvadratu / js_disable_website_for_IE.js
Created February 19, 2021 19:14
{JS} trick to disable web for IE browsers
<script>
if (navigator.userAgent.indexOf("MSIE") >= 0) {
document.write("<div style='width: 100%; text-align: center; height: 100%; position: fixed; top:0; left:0; right:0; z-index: 99999; background-color: #ffffff; color: #000000;'>Jūs naudojate pasenusią ir nesaugią Internet Explorer naršyklę. Prašome atsinaujinti į Internet Explorer 11 arba naudoti kitą naršyklę.</div>");
document.execCommand("Stop");
}
</script>
@dkvadratu
dkvadratu / http_headers_security.htaccess
Last active March 7, 2024 21:48
{HTACCESS} HTTP headers for security in .htaccess file
# Check your website headers here: https://www.serpworx.com/check-security-headers/ or https://gf.dev/
# This configuration works for WP, WC on LiteSpeed server. Be careful. Test site after installing. All lines are explained are in serpworx.com tester.
# More docs:
# https://www.netsparker.com/whitepaper-http-security-headers/#XFrameOptionsHTTPHeader
# https://owasp.org/www-project-secure-headers/
# https://www.keycdn.com/blog/http-security-headers
# WordPress plugin for Headers setup https://wordpress.org/plugins/http-headers/
# Main security options in .htaccess file:
@dkvadratu
dkvadratu / wp_ajax_url_call.php
Last active January 7, 2023 10:37
{WP} AJAX call from URL
<?php
//example taken from https://www.smashingmagazine.com/2011/10/how-to-use-ajax-in-wordpress/
//generate link
$nonce = wp_create_nonce("my_user_vote_nonce");
$link = admin_url('admin-ajax.php?action=my_user_vote&post_id='.$post->ID.'&nonce='.$nonce);
echo '<a class="user_vote" data-nonce="' . $nonce . '" data-post_id="' . $post->ID . '" href="' . $link . '">vote for this article</a>';
//accept ajax action
add_action("wp_ajax_my_user_vote", "my_user_vote");
add_action("wp_ajax_nopriv_my_user_vote", "my_must_login");
@dkvadratu
dkvadratu / js_input_validations.js
Last active March 4, 2021 13:49
{JS} Input fields validations and replacements, LT phone number
//phone format for LT countries
var telInput = document.getElementById('billing_phone');
telInput.addEventListener("keyup", function onKeyUp(e){
var input = e.target;
input.style.borderColor = 'initial';
//get country and check if its LT
if( !isCountry("LT") ) return;
//format number
@dkvadratu
dkvadratu / wp_facebook_reviews_show.php
Created February 8, 2021 08:28
{WP} Custom facebook reviews functionality.
<?php
/**
* @purpose Show facebook comments in Cart page, for mobile and desktop
* @pages Cart
* @version 2019.02.14
*/
add_shortcode('dk_fb_comments', 'dk_fb_get_comments_local');
function dk_fb_get_comments_local()
{
$json_file = site_url() . "/_fb/comments.json";
@dkvadratu
dkvadratu / wp_bakery_element_shortcode.php
Created February 8, 2021 07:49
{WP} WPBakery element-shortcode
<?php
//Example how to create WPBaker builder element, which works like shortcodes.
//There is parent holder Buttons, where you can insert as many Button (only our button) as you want.
//Include code or file into functions.php or elsewhere.
// source : https://wpbakery.atlassian.net/wiki/pages/viewpage.action?pageId=524362
if(!function_exists('ef_buttons')){
function ef_buttons( $atts, $content = null ) {
extract(shortcode_atts(array(
@dkvadratu
dkvadratu / wc_loop_products_on_sale.php
Created February 8, 2021 07:41
{WC} query products on sale trough GET
<?php
add_filter('loop_shop_post_in', 'dk_filter_sale_products', 10);
add_filter('woocommerce_widget_get_current_page_url', 'dk_filter_links_with_sale', 10, 2);
function dk_filter_sale_products($array) {
if(isset($_GET['akcija']) && $_GET['akcija']){
$product_ids_on_sale = wc_get_product_ids_on_sale();
$array = array_merge($array, $product_ids_on_sale);
}
@dkvadratu
dkvadratu / wp_shortcode.php
Last active February 8, 2021 07:38
{WP} shortcodes [bartag foo="foo-value"]
<?php
function bartag_func( $atts ) {
$a = shortcode_atts( array(
'foo' => 'something',
'bar' => 'something else',
), $atts );
return "foo = {$a['foo']}";
}
add_shortcode( 'bartag', 'bartag_func' );