This file contains hidden or 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
| <?php | |
| //https://example.com/?add_to_wishlist_user=1&add_to_wishlist_product=5503 | |
| //https://example.com/?add_to_wishlist_user=1&add_random=5 | |
| function add_product_to_wishlist( $user_id, $product_id ) { | |
| global $wpdb; | |
| // 1. Get or create default wishlist for user | |
| $wishlist = $wpdb->get_var( $wpdb->prepare( | |
| "SELECT ID FROM {$wpdb->prefix}tinvwl_lists |
This file contains hidden or 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
| <?php | |
| add_action('shutdown', function() { | |
| global $wpdb; | |
| if ( empty($wpdb->queries) ) { | |
| return; | |
| } | |
| $timestamp = date('Y-m-d H:i:s'); |
This file contains hidden or 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
| // Get posts with no thumbnails | |
| //add_action('wp_head', 'sz_posts_without_thumbs'); | |
| function sz_posts_without_thumbs() { | |
| $args = array( | |
| 'post_type' => 'post', | |
| 'post_status' => 'publish', | |
| 'posts_per_page' => -1, | |
| 'fields' => 'ids', | |
| 'no_found_rows' => true, | |
| 'ignore_sticky_posts' => true, |
This file contains hidden or 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
| //SZ Compare queries performance | |
| // Function to fetch and display random posts using the initial slow method | |
| function fetch_random_posts_initial() { | |
| $start_time = microtime(true); | |
| $args = array( | |
| 'cat' => array(1, 9, 10, 11, 44, 94), | |
| 'posts_per_page' => 3, | |
| 'no_found_rows' => true, | |
| 'ignore_sticky_posts' => true, |
This file contains hidden or 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_transients_with_prefix( $prefix ) { | |
| foreach ( get_transient_keys_with_prefix( $prefix ) as $key ) { | |
| // delete_transient( $key ); | |
| echo "<br>". $key." ".get_transient( $key ); | |
| } | |
| } | |
| /** | |
| * Gets all transient keys in the database with a specific prefix. | |
| * |
This file contains hidden or 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
| //This goes in functions.php or plugin file or wherever | |
| function dump_hook( $tag, $hook ) { | |
| ksort($hook); | |
| echo "<pre>>>>>>\t$tag<br>"; | |
| foreach( $hook as $priority => $functions ) { | |
| echo $priority; |
This file contains hidden or 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
| RewriteEngine On | |
| # Check if the request is for a PNG or JPEG file | |
| RewriteCond %{REQUEST_FILENAME} \.(png|jpe?g)$ | |
| # Check if a WebP version of the file exists | |
| RewriteCond %{REQUEST_FILENAME}.webp -f | |
| # Redirect to the WebP version of the file | |
| RewriteRule ^(.+)\.(png|jpe?g)$ $1.$2.webp [NC,L] |
This file contains hidden or 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
| //Measure performance of some WP funcitons | |
| $startTime = microtime(true); | |
| $guarded_pages = get_posts([ | |
| 'posts_per_page' => 100, | |
| 'no_found_rows' => true, | |
| 'post_type' => SpeedGuard_Admin::$cpt_name, | |
| 'post_status' => 'publish', | |
| 'fields' => 'ids' | |
| ] ); |
This file contains hidden or 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 hidden or 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 ""; |
NewerOlder