Skip to content

Instantly share code, notes, and snippets.

View UmeshSingla's full-sized avatar
🏠
Working from home

Umesh Kumar UmeshSingla

🏠
Working from home
View GitHub Profile
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAu/DFaxjbxIkqPQMdnD7AKA6QacWext6eeW2FvpilZ4JRDKLhQflxOw5dO/dnOShny9AQ68I4UJTV+lJP/Z9Di5ZMvD3SVjFkK/5KtLoI1+G5q6LTVShjVaJc8aMLMZ6m+i1egeGUSRrxDlH7rVHvNBPMe4HYiQDi1ZFPQIINL4sJnBETLptm3GdvWvlM1Cbe0VOV9At2grqEjnj50IoiCBy3K3MKhLK793wx4jvXZm3p7EF3s8RSJyL4tCbWBEC/m+L6YlIlpImL/fpX6nKJ6KUFL3BgnLvztMTWCZxd2LkVpOoJEfHCbAdWVqQOJWAVY8anig2/s5X/9Awu1j5EvQ== .1@TOBECHANGED
@UmeshSingla
UmeshSingla / auto_resize_wp_editor.php
Created October 31, 2017 08:36
Allows to add auto resizing to a custom wp_editor() instance added in a metabox.
<?php
/* Define the custom box */
add_action( 'add_meta_boxes', 'my_meta_box' );
/* Do something with the data entered */
add_action( 'save_post', 'custom_save_post_meta' );
/* Adds a box to the main column on the Post and Page edit screens */
function my_meta_box() {
add_meta_box( 'wp_editor_metabox', 'Metabox with Editor', 'wp_editor_meta_box' );
@UmeshSingla
UmeshSingla / smush_png_jpg_update_path.php
Last active November 16, 2017 11:17
Smush PNG to JPG, Update image paths for converted images in case it wasn't updated by plugin. Make sure to enable debug log, in order to have a log of what all images are updated.
<?php
add_action('current_screen', 'smush_update_image_url');
function smush_update_image_url() {
global $wpsmush_db;
if( !function_exists('get_current_screen')) {
return;
}
$current_screen = get_current_screen();
if( empty( $current_screen ) ) {
@UmeshSingla
UmeshSingla / check_for_empty_title.php
Created September 15, 2017 08:20
WordPress Post: Check for empty title before publishing and show a warning. Post is saved as draft if the title is empty.
<?php
//WordPress Stack Exchange Link: https://wordpress.stackexchange.com/questions/279947/check-post-on-publish-for-blank-title/279994#279994
//Make sure to upvote if you find it helpful.
/**
* Checks for empty post title, if empty sets the post status to draft
*
* @param $data
* @param $postarr
*
* @return array
@UmeshSingla
UmeshSingla / delete_media.php
Last active September 5, 2017 08:49
Delete WordPress attachments for given Ids, if original image doesn't exists.
<?php
add_action('admin_init', 'delete_attachments');
function delete_attachments() {
$posts = array("16578","16581","5848","5849","5851","5852","5854","5855","5856","5859","5860","5861","5862","5863","5865","5866","5867","5868","5869","5878","5879","5901","5903","5913","5914","5915","5916","5917","5918","5919","5920","5921","5922","5924","5925","5927","5928","5929","5930","5931","5932","5934","6760","6761","6762","6763","6764","6766","6767","6795","6804","6805","6806","6807","6808","6809","6810","6811","6812","6813","6814","6911","6912","6931","6964","6966","6969","6972","6976","6977","6978","6979","6980","6982","6984","6985","6986","6987","6988","6991","6992","6993","6994","6995","6998","6999","7000","7001","7002","7140","7144","7145","7146","7147","7148","7156","7157","7158","7159","7160","7161","7187","7220","7235","7236","7237","7245","7312","7345","7368","7391","7411","8072","8081","8082","8087","8088","8095","8116","8117","8118","8121","8126","8144","8164","8165","8166","8167","8168","8169","8170
@UmeshSingla
UmeshSingla / skip_smush_filename_basis.php
Last active April 18, 2017 22:16
Allows to skip image files have particular search term in the filename
<?php
/**
* @package WP Smush
*/
/*
Plugin Name: Smush - Skip Landing Page Images
Plugin URI: https://wordpress.org/plugins/wp-smushit/
Description: This allows you to skip images from smushing with name containing a string e.g. `landing_page`
Author: Umesh Kumar
Version: 1.0
@UmeshSingla
UmeshSingla / smush-bulk-restore.php
Created March 10, 2017 12:21
Adds a Box after settings, that allows you to restore your images from an existing backup created by Smush using Ajax
<?php
if ( ! class_exists( 'WpSmushRestore' ) ) {
class WpSmushRestore {
/**
* Constructor
*/
function __construct() {
@UmeshSingla
UmeshSingla / skip_directory_smush.php
Created January 31, 2017 12:16
WP Smush - Skip a directory or a list of directories from Smushing
<?php
//Allows to skip multiple directories, as specified in array
add_filter( 'wp_smush_image', 'filter_by_directory', '', 2 );
function filter_by_directory( $smush, $id ) {
$file_path = get_attached_file( $id );
//List of directories to be ignored
$dirs = array(
'uploads/2016/11',
'uploads/2017/01'
);
@UmeshSingla
UmeshSingla / skip_smush.php
Created November 2, 2016 14:12
Allows you to skip given image ids from Smushing ( Bulk/Manual Smush )
<?php
function skip_smush( $smush, $attachment ) {
//Attachment ids that needs to be skipped
if( 116 == $attachment || in_array( $attachment, array(117, 118, 119, 132, 137, 170 ) ) ) {
return false;
}
return $smush;
}
add_filter( 'wp_smush_image', 'skip_smush', '', 2 );
@UmeshSingla
UmeshSingla / exclude_original.php
Created September 14, 2016 11:43
Skip a Original size image from Smushing
add_filter('wp_smush_media_image', 'smush_skip_original_image', '', 2 );
function smush_skip_original_image( $skip, $image_size ) {
if( 'full' == $image_size ) {
return false;
}
return $skip;
}