Skip to content

Instantly share code, notes, and snippets.

View PatelUtkarsh's full-sized avatar
🧘

Utkarsh Patel PatelUtkarsh

🧘
View GitHub Profile
@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 / dnsmasq.conf
Last active June 20, 2022 00:23
stubby cloudflare ipv4 and ipv6
no-resolv
proxy-dnssec
server=::1#5353
server=127.0.0.1#5353
listen-address=::1,127.0.0.1
# Put any other line here like laravel valet using .test domain.
address=/.test/127.0.0.1
@PatelUtkarsh
PatelUtkarsh / readme.md
Last active May 9, 2022 20:52
Git cheat sheet shallow clone

All i know about shallow clone

Usecases:

  • For all readonly purpose this works great.
  • For big repo like linux project, mozilla firefox or WordPress like project it's really boring to wait for git to fetch all refs since we rearely needs all refs (if you know you're not gonna need).
  • You can contribute even after shallow clone but it works only in somecases mentioned below.

Fetch only one commit

git clone -b master git_url --depth 1
@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 / 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 / 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.js
Created February 19, 2020 13:25
Refresh WordPress media library images - useful when editors are uploading image via 3rd party tool using REST API - Example: Mediawires so editor do not need to reload page to get new images on existing article.
jQuery( document ).ready( function () {
// Refresh media library each time on click of add media.
if ( wp.media ) {
wp.media.view.Modal.prototype.on( 'open', function () {
if ( wp.media.frame.content.get() !== null ) {
// this forces a refresh of the content.
wp.media.frame.content.get().collection._requery( true );
}
} );
}
@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.