Skip to content

Instantly share code, notes, and snippets.

View isaumya's full-sized avatar
👨‍💻
Think Twice, Code Once

Saumya Majumder isaumya

👨‍💻
Think Twice, Code Once
View GitHub Profile
@isaumya
isaumya / cf_cache_rules_implementation_guide_spcc.md
Last active April 19, 2024 09:11
Super Page Cache for Cloudflare — Guide for using Remove Cache Buster Query Parameter feature (when using Cache Everything page rule)

Implementation Guide for using "Remove Cache Buster Query Parameter" feature

The Super Page Cache for Cloudflare plugin has recently added the feature for using the Cache Everything pagerule withing the ?swcfpc=1 cache buster query paramater. This opens up so many new doors where users previously had to use the Cloudflare Workers to remove the cache buster.

With this new option now users are able to take advantage of Cloudflare Cache Everything page rule and take it to the next level by using the new Rulesets released by Cloudflare. Basically this is achived by taking advantage of the all new Cache Rules feature implemented by Cloudflare.


Setp 1 — Setting up the Cache Rules inside your Cloudflare Dashboard

The first thing that you need to do is, log-in to your Cloudflare Dahsbord and go to the domain/zone doe which you are setting up the [Super Page Cache for Cloudflare](https://wordpress.org/plug

@isaumya
isaumya / remove-woocommerce-bloat-marketing-hub.md
Last active April 10, 2024 12:45
Easily Remove WooCommerce Bloated Features like Marketing Hub from WordPress Admin Menu

Remove WooCommerce Bloated Features from WP Admin Menu

Recently WooCommerce has added a lot of improvements to the plugin which we really appriciate but at the same time a lot of bloated features has alos been added to the plugin like Marketing Hub, a completely useless menu taking extra space among the other important menu items. Now if you find Marketing Hub to be useful, you can keep it.

But just in case you are looking for a way to remove these features that you no longer need from your WordPress Admin menus, take a look at the following code snippets. Please note: though I will show you how you can remove the Marketing Hub from your WP Admin menu list completely and make sure WooCommerce doesn't execute codes for that feature you don't need, you can do the same for other WooCommerce features as well like Analytics.

How to remove Marketing Hub for WooCommerce <= v4.2

If you are using WooCommerce <= v4.2, you can simple add this one line of code in your theme's functions.php f

@isaumya
isaumya / wp-rocket-no-cache-installation-guide.md
Last active April 8, 2024 08:51
WP Rocket + Super Page Cache for Cloudflare : Disabling WP Rocket Page caching for it to work with Super Page Cache for Cloudflare

WP Rocket (No Page Cache) - Must Use Plugin - Installation Guide

When using Super Page Cache for Cloudflare along with WP Rocket plugin it is highly recommended that you do not use more than one page caching system on your site as that will lead to compatibility issues and problems.

Whether you have a server level page caching system or some other page caching plugin installed in yoru site, you need to ensure that all page caching mechanisms are disabled on those plugin before using the Super Page Cache for Cloudflare plugin on your website. Also, ensure that there is no server rule in your .htaccess file or nginx.conf file which is modifying the cache-control header value of the page as that value needs to be managed by the Super Page Cache for Cloudflare plugin.

Here is what you should do if you are uising WP Rocket along with Super Page Cache for Cloudflare to get the best results.

Step 1 - Make sure you have a clean sl

@isaumya
isaumya / functions.php
Created September 9, 2016 20:43
Attach files with Gravity Forms Notification Emails - Gravity Forms
<?php
//* Attaching file to the form notification user email
//* in gform_notification_7, the number 7 is the FORM ID
//* This snippet works with the newer version of Gravity Forms too
add_filter('gform_notification_7', 'add_attachment_pdf', 10, 3); //target form id 7, change to your form id
function add_attachment_pdf( $notification, $form, $entry ) {
//There is no concept of user notifications anymore, so we will need to target notifications based on other criteria,
//such as name or subject
if($notification["name"] == "User Notification - Life Lesson"){
//get upload root for WordPress
@isaumya
isaumya / nuxt-js-firebase-auth-and-cloud-firestore.md
Last active September 14, 2023 12:29
Nuxt JS: Keep user logged in with Firebase Auth and also fetch the necessary User data from Cloud Firestore and put it in your Vuex store if the user is already logged in before rendering the page

Nuxt JS: Keep user logged in with Firebase Auth and also fetch the necessary User data from Cloud Firestore and put it in your Vuex store if the user is already logged in before rendering the page

Step - 1

Install the required packages.

  • If you use npm npm i firebase firebase-admin cookies js-cookie

  • If you use yarn yarn add firebase firebase-admin cookies js-cookie

@isaumya
isaumya / remove_unused_gutenberg_block.md
Created October 25, 2022 08:18
Remove the unnecessary/unused Gutenberg blocks and block variations

Remove Unused Gutenberg Blocks and Block Variations

When creating custom WordPress themes, we often create custom Gutenberg blocks as per the website design and development need. As a result the list of available block keep getting increased and sometimes it gets really hard to quickly find the block you are looking for. WordPress being a great CMS, it comes with a lot of in-built core blocks, but not all website need them or use them.

So, if you are also building a custom WordPress theme where you would like to unregister some of the default Gutenberg blocks that WordPress ships with you can do that easily by following the steps below.

⚠️ Note: Read the code first and then only unregister the blocks you don't want. Don't blindly copy paste the code.

Setp 1 — Create editor.js inside your theme

Create a JavaScript file inside your WordPress theme. You can name the file whatever you like and also put it whereever you prefer inside your theme file structure. Here for example, I've named the file `

@isaumya
isaumya / http-curd-req-in-firebase-cloud-functions.js
Last active August 21, 2023 16:46
Making HTTP CRUD requests with Firebase Cloud Functions using node request-promise package
const functions = require('firebase-functions');
const cors = require('cors')({ origin: true });
const rp = require('request-promise');
exports.checkIP = functions.https.onRequest((req, res) => {
cors(req, res, () => {
if( req.method !== "GET" ) {
return res.status(401).json({
message: "Not allowed"
});
@isaumya
isaumya / vs-code-git-repo-add.md
Last active August 9, 2023 15:46
Add repo to VS Code Projects

Add Git Repo to your CLI created project in VS Code

Let's say that you have created a project using @vue/cli or some other cli locally. Now you created a github repo. Also at the time of creating the repo you have set the LICENSE file from the web creation portal. Now if you are using VS Cose, here are the following commands that you need to run for the first time to ensure the remote repo gets properly connected with your project.

Step 1. Add Remote Repo URL

git remote add origin https://<AccountName>.github.com/somerepo.git

Step 2. Pull from the Remote Repo with --allow-unrelated-histories flag

@isaumya
isaumya / cloudflare-cdn-routing-anomaly-detailed-test.md
Created February 28, 2021 12:35
Cloudflare CDN Routing Anomaly detailed test across multiple DNS resolvers

Cloudflare CDN Routing Anomaly Detailed Test Across Multiple DNS Resolvers

Here are some key details about my testing location and ISP:

Important Note: Keep an eye on the value of colo on the following response. As that value will show exactly from which Cloudflare CDN edge the data is getting served from. Moreover these 3 letter colo values are basically the IATA airport code on that city. So, you can use a website like World Airport Codes to find out the exact City and Country Name.

@isaumya
isaumya / wpcspc_device_based_cache_cf_worker_template.js
Last active February 18, 2023 22:50
Custom Cloudflare Worker Code for Device Based Caching - WP Cloudflare Super Page Cache Plugin
/**
* Worker Name: WPCSPC - Device based Cache
* Description: This worker is responsible for caching the requests based on the device type
* Based on Default Worker Version: 2.8.0
* Version: 2.1.0
* @link: https://wordpress.org/plugins/wp-cloudflare-page-cache/
* @link: https://wordpress.org/support/topic/mobile-page-theme-and-cloudflare-caching-plugin-integration/
* @author: Saumya Majumder
*/
// Default cookie prefixes for cache bypassing