Skip to content

Instantly share code, notes, and snippets.

Avatar

Utkarsh Patel PatelUtkarsh

View GitHub Profile
@PatelUtkarsh
PatelUtkarsh / amp-media-size.php
Created May 26, 2020
AMP Extract Image without external request
View amp-media-size.php
<?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 Feb 19, 2020
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.
View index.js
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 Aug 3, 2019
Attachment custom fields
View index.php
<?php
namespace Utkarsh\Attachment\Meta;
const META_NAME = 'media_credit';
/**
* Bootstrap.
*/
function bootstrap() {
@PatelUtkarsh
PatelUtkarsh / dnsmasq.conf
Last active Apr 8, 2020
stubby cloudflare ipv4 and ipv6
View dnsmasq.conf
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 / snippet.js
Last active Feb 26, 2019
Get all hostname from homepage <a>
View snippet.js
var anchors = document.querySelectorAll('a');
var hosts = new Set();
anchors.forEach((anch) => {
hosts.add(anch.hostname);
});
console.table(Array.from(hosts));
View class-demo.php
<?php
/**
* The Demo class.
*
* @package xyz
*/
namespace UtkarshPatel\Demo
/**
@PatelUtkarsh
PatelUtkarsh / easyengine-cask.rb
Last active Nov 23, 2018
Easyengine Brew core and cask formula
View easyengine-cask.rb
cask 'easyengine' do
version '4.0.0'
homepage 'https://easyengine.io/'
url 'https://github.com/EasyEngine/easyengine/releases/download/v4.0.0/easyengine.phar'
sha256 '5d7f7ec95911883240717458024f0e7c69309f7bd3646353a0594e1b0900eaa6'
name 'Easyengine'
depends_on formula: 'php'
depends_on cask: 'docker'
container type: :naked
@PatelUtkarsh
PatelUtkarsh / notify.sh
Last active Jan 3, 2019
Get notification when internet is up, This uses pushbullet api.
View notify.sh
function notifynet(){
isdown=0
echo "Pres CTRL+C to stop..."
while :
do
sleep 5
if [ $(ping -q -c 1 -W 1 8.8.4.4 >/dev/null) ]; then
echo -n "1"
if [ $isdown -eq 1 ]; then
isdown=0
@PatelUtkarsh
PatelUtkarsh / fix-symlink-url.php
Last active Oct 29, 2018
Fix url when wp-content and mu-plugins are added as symlink.
View fix-symlink-url.php
@PatelUtkarsh
PatelUtkarsh / class-migrate.php
Last active Jun 28, 2018
Custom table to WordPress schema migration base class proof of concept. NOT TESTED.
View class-migrate.php
<?php
/**
* Migration Abstract class.
*
* Should inherit this class and all documented class variable must overwrite in child class for this to work.
*
* @package rtCamp
*/
namespace rtCamp\TableMigrate;
You can’t perform that action at this time.