Skip to content

Instantly share code, notes, and snippets.

View PatelUtkarsh's full-sized avatar
🧘

Utkarsh Patel PatelUtkarsh

🧘
View GitHub Profile
@PatelUtkarsh
PatelUtkarsh / root-based-category-urls.php
Last active February 8, 2023 01:39 — forked from mikeschinkel/root-based-category-urls.php
Enabled Root-based Category URLs in WordPress (Any bugs? Post comments below.)
<?php
/*
* Plugin Name: Root-based Category URLs
* Description: Enables root-based Category URLs, i.e. Makes /category/my-category/ URLs route as /my-category/
* Author: Mike Schinkel
* Author URI: http://about.me/mikeschinkel
* Plugin URI: https://gist.github.com/1421235
* Version: 0.1.1
*/
@PatelUtkarsh
PatelUtkarsh / script.sh
Created January 11, 2023 10:34
Migrate domain to new domain? A script to verify domains are redirecting 1:1 in new site based on old sitemap.
function verify_sitemap_urls() {
if [ -z "$1" ]; then
echo "Usage: check_sitemap [file_path/url] (new_domain)"
echo "If no new domain passed it will use the url from sitemap; if domain is passed then it will replace the domain in sitemap url with same path."
return
fi
if [[ "$1" == *"http"* ]]; then
TEMPFILE=$(mktemp)
# Download the sitemap file from the given URL
@PatelUtkarsh
PatelUtkarsh / disable-plugin-update-mu.php
Created August 15, 2022 04:06
Disable plugin updates WordPress
<?php
// Return zero updates and current time as last checked time
function __disable_wp_updates() {
include ABSPATH . WPINC . '/version.php';
return (object) array(
'updates' => array(),
'version_checked' => $wp_version,
'last_checked' => time(),
);
@PatelUtkarsh
PatelUtkarsh / proxy.js
Created June 22, 2022 04:40
Cloudflare worker proxy object storage image
addEventListener("fetch", event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const hiddenImageOrigin = "s3 url without trailing shash"
const requestURL = new URL(request.url)
// Append the request path such as "/assets/image1.jpg" to the hiddenImageOrigin.
// You could also process the path to add or remove directories, modify filenames, etc.
const imageURL = hiddenImageOrigin + requestURL.pathname;
@PatelUtkarsh
PatelUtkarsh / restore_customizer.php
Created December 7, 2021 14:41
Restore customizer
<?php
namespace utkarsh;
/**
* Restore customizer which is removed by WP Core.
*/
function restore_customizer() {
// WP version is 5.9 beta or later than only add customize.php back.
if ( ! version_compare( get_bloginfo( 'version' ), '5.9-beta', '>=' ) ) {
return;
@PatelUtkarsh
PatelUtkarsh / injected-data.php
Created October 29, 2021 09:07
Add taxonomy filter for media library
<?php
namespace utkarsh;
add_action( 'wp_enqueue_media', __NAMESPACE__ . '\\media_filter' );
/**
* Add media filter script.
*/
@PatelUtkarsh
PatelUtkarsh / custom.css
Last active October 20, 2021 05:00
Material tab bar with icons
.site__navigation .tab-bar .mdc-tab .material-icons {
color: var(--mdc-theme-on-header, var(--mdc-theme-on-primary, #fff));
}
@PatelUtkarsh
PatelUtkarsh / config
Created October 11, 2021 06:15
ssh config to foward remote port over ssh - create new or append on .ssh/config
Host dockerServer
Hostname server-host-or-ip
User ssh-remote-user
LocalForward 8088 localhost:8088
LocalForward 3306 localhost:3306
ServerAliveInterval 10
@PatelUtkarsh
PatelUtkarsh / index.php
Last active April 13, 2021 11:21
ACF exclude current post from post object
<?php
namespace Utkarsh\acf;
/**
* Exclude current post from ACF filter.
* Add param include_current_post => true in ACF field if you need include current post. Defaults to exclude.
*
* @param array $args WP_Query args.
* @param array $field ACF field params.
* @param int $post_id current post id.
@PatelUtkarsh
PatelUtkarsh / temperature_cron.sh
Last active April 7, 2021 08:46
Setup cron to monitor raspberry pi temperature
#!/bin/bash
# Usage ./temperature_cron.sh $HOME/pi-temp-log
timestamp=`date +%F`
temp=`/opt/vc/bin/vcgencmd measure_temp`
temp=${temp:5:16}
mkdir -p $1 # make sure dir exists
echo "$(date +%H:%M:%S) = $temp" >> $1/temperature_log_$timestamp.txt # create new file for each day.