This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//if not using rocket_lazyload_excluded_attributes filter, class remove-lazy should be added to WP Rocket settings in admin! | |
// + there is a helper plugin to do so in case we HAVE unique attribute to refer to https://github.com/wp-media/wp-rocket-helpers/blob/master/lazyload/wp-rocket-exclude-x-first-images-by-attribute/p | |
add_filter ('the_content', 'sz_add_class_to_first_img'); | |
function sz_add_class_to_first_img($content){ | |
if (!is_admin() && !is_user_logged_in()){ //do only on frontend for not logged-in | |
if ( is_singular('post') ) { //do on single posts only | |
$content = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8"); | |
$document = new DOMDocument(); | |
libxml_use_internal_errors(true); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//If both changed at the same time - custom field value will be applied as it fires later, set 30 to change it add_action( 'profile_update', array($this, 'update_acf_fields'), 30, 2 ); | |
class Sync_ACF_with_User_Profile_Class { | |
static public $sync_pair = array( | |
array( 'acf' => 'member_name', 'profile_field' => 'first_name'), //add acf field name according to your setup | |
array( 'acf' => 'member_lastname', 'profile_field' => 'last_name')// add more rows to sync any other fields as well | |
); | |
public function __construct() { | |
add_action( 'profile_update', array($this, 'update_acf_fields'), 10, 2 ); //when profile is updated -> update ACF | |
add_action('updated_user_meta', array($this, 'update_user_profile_fields'),10,4); // when ACF is updated -> update profile | |
add_action('added_user_meta', array($this, 'update_user_profile_fields'),10,4); // when ACF is added -> update profile |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Disable repeat purchase V 22.20 7:40 -- on Adding to Cart check **/ | |
add_filter( 'woocommerce_add_to_cart_validation', 'limit_cart_items_from_category', 10, 5 ); | |
function limit_cart_items_from_category ( $passed, $product_id, $quantity, $variation_id = 0, $variations = null ){ | |
$current_product_id = ($variation_id === 0) ? $product_id : $variation_id; | |
// Loop through cart items checking if the product is already in cart | |
foreach ( WC()->cart->get_cart() as $cart_item ){ | |
if( $cart_item['data']->get_id() == $current_product_id ) { | |
wc_add_notice( __('This product is already in your cart.', 'woocommerce' ), 'error' ); | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Let any user who can edit page insert unfiltered html in text editor | |
add_action( 'init', 'reply_unfiltered_html' ); | |
function reply_unfiltered_html() { | |
$user = wp_get_current_user(); | |
if ( current_user_can('edit_pages') ) | |
kses_remove_filters(); | |
} | |
//Let users with certain roles insert unfiltered html in text editor | |
add_action( 'init', 'reply_unfiltered_html_for_roles' ); | |
function reply_unfiltered_html_for_roles() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
upstream php { | |
{{#each fastcgi_servers}} | |
server {{this}}; | |
{{/each}} | |
} | |
# SZ START | |
# Check if client is capable of handling webp | |
map $http_accept $webp_suffix { | |
default ""; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function delete_empty_terms(){ | |
$taxonomy_name = 'city'; | |
$terms = get_terms( array( | |
'taxonomy' => $taxonomy_name, | |
'hide_empty' => false | |
) ); | |
foreach ( $terms as $term ) { | |
$term_count = $term->count; | |
if ($term_count < 1){ wp_delete_term($term->term_id, $taxonomy_name); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function delete_cpt_attachments(){ | |
$attachments = get_posts( array( | |
'post_type' => 'attachment', | |
'numberposts' =>-1, | |
)); | |
if ($attachments) { | |
foreach ($attachments as $attachment){ | |
$parent_id = $attachment->post_parent; | |
if ( 'card' == get_post_type($parent_id) ) { | |
$attachmentID = $attachment->ID; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Generate image alt from the post title -- for the first image in the post | |
add_filter('the_content', 'add_alt_tags', 99999); | |
function add_alt_tags($content) { | |
global $post; | |
preg_match_all('/<img[^>]+>/i', $content, $images); | |
if(!is_null($images)) { | |
foreach($images[0] as $index => $value) { | |
//If no alt | |
// if(!preg_match('/alt=/', $value)) { | |
$new_img = str_replace('<img', '<img alt="'.get_the_title().'"', $images[0][$index]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Important: When adding a gist link in Editor you MUST choose - convert to link, not Embed! | |
//Embed Gists to be displayed in Gutenberg without plugin, works on new and existing ones | |
add_filter( 'the_content', 'sz_embed_gists_in_gutenberg' ); | |
function sz_embed_gists_in_gutenberg( $content ) { | |
if(empty($content)) return; | |
$dom = new DOMDocument; | |
libxml_use_internal_errors(true); | |
$content = mb_convert_encoding($content, 'HTML-ENTITIES', "UTF-8"); | |
$dom->loadHTML($content); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//add_action( 'wp_print_scripts', 'sz_enqueue_scripts', 10); //run later or via wp_print_scripts ot catch all scripts | |
add_action( 'wp_enqueue_scripts', 'sz_enqueue_scripts', 999); | |
function sz_enqueue_scripts(){ | |
global $wp_scripts; | |
//change dependency to load earlier | |
$handles_to_filter = array('dt-above-fold'); | |
$dependency_handle_to_add = 'wpb_composer_front_js'; //TODO: accept array | |
foreach ($handles_to_filter as $handle_to_filter){ | |
foreach( $wp_scripts->registered as $script_object) { //find script in registered by handle | |
if ($script_object->handle == $handle_to_filter){ |