Skip to content

Instantly share code, notes, and snippets.

View PatelUtkarsh's full-sized avatar
🧘

Utkarsh Patel PatelUtkarsh

🧘
View GitHub Profile
@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.
@PatelUtkarsh
PatelUtkarsh / feedback.js
Created April 5, 2021 11:38
Download active collab attachments from discussion
Array.from(document.getElementsByClassName('attachment_download')).forEach(function(elem) {
setTimeout(() => {
elem.click();
}, key * 2000 )
});
@PatelUtkarsh
PatelUtkarsh / amp-media-size.php
Created May 26, 2020 09:31
AMP Extract Image without external request
<?php
add_filter( 'amp_extract_image_dimensions_batch', function ( $dimensions ) {
$home_url = get_home_url();
foreach ( $dimensions as $url => &$data ) {
if ( false !== strpos( $url, $home_url ) ) {
$attachment_id = wpcom_vip_attachment_url_to_postid( $url );
if ( false !== $attachment_id ) {
$src = wp_get_attachment_image_src( $attachment_id );
$height = $src[1];
$width = $src[2];
@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 August 3, 2019 05:21
Attachment custom fields
<?php
namespace Utkarsh\Attachment\Meta;
const META_NAME = 'media_credit';
/**
* Bootstrap.
*/
function bootstrap() {