Skip to content

Instantly share code, notes, and snippets.

View imvaskii's full-sized avatar
🎯
Focusing

Bhaskar imvaskii

🎯
Focusing
View GitHub Profile
@imvaskii
imvaskii / remove_anon_filter.php
Last active February 20, 2018 00:18
WordPress: Removes anonymous object filter
<?php
if ( ! function_exists( 'remove_anonymous_object_filter' ) ) {
/**
* Removes anonymous object filter callbacks.
* Can be used for Closure classes, static class and even dynamic classes
*
* @param string $tag Hook name.
* @param string $class Class name
* @param string $method_to_remove Method name
@imvaskii
imvaskii / remove-img-attr.php
Created January 30, 2017 23:46
WordPress Filter to remove "height" and "width" attributes and values of image only.
<?php
add_filter( 'post_thumbnail_html', 'twr_remove_width_attribute', 10 );
add_filter( 'image_send_to_editor', 'twr_remove_width_attribute', 10 );
add_filter( 'the_content', 'twr_remove_width_attribute', 10);
function twr_remove_width_attribute($html) {
// loop only through img tags
if ( preg_match_all( '/<img[^>]+>/ims', $html, $matches ) ) {
@imvaskii
imvaskii / copy_file_from_url.php
Created December 7, 2016 00:56
[Wordpress] Copies attachments from remote server (Production site)
<?php
/**
* Copies file from url to current path
* @param type $url
* @return type file_name on success else bool false
*/
function copy_file_from_url( $url ) {
if( empty( $url ) )
return false;
@imvaskii
imvaskii / custom-template-router.php
Last active November 17, 2016 00:44
Custom template router for WordPress.
<?php
add_action('template_redirect', 'twr_custom_template_router', 1);
if( ! function_exists( 'twr_custom_template_router' ) ) {
/**
* Routes predefined list of pages to custom template_redirect
*/
function twr_custom_template_router() {
$custom_templates_bucket = array( 'schoolsguide', 'school' );
@imvaskii
imvaskii / twr-admin-post-filter.php
Last active October 5, 2016 03:22
Wordpress admin custom filter
<?php
/**
* @author : Bhaskar K C
* generic class for admin posts custom filters **dropdown filter on admin listing pages
* Assuming column values are to be stored in post meta
*/
if( ! class_exists('TWR_admin_post_filter') ) {
class TWR_admin_post_filter {
@imvaskii
imvaskii / wp-custom-columns.php
Last active October 11, 2016 23:12
WordPress admin custom columns.
<?php
/**
* @author : Bhaskar K C
* generic class for admin columns
* Assuming column values are to be stored in post meta
*
* Columns values can be extended with following usage example
* add_action( 'twr_admin_columns', 'callback_function_name', 2, 10 );
* function callback_function_name( $post_type, $column_key ) { // do something here }
*/
@imvaskii
imvaskii / convertTimestamp.js
Created May 22, 2016 22:27
Unixtimestamp to formatted time
function convertStamp( unix_timestamp ) {
// Create a new JavaScript Date object based on the timestamp
// multiplied by 1000 so that the argument is in milliseconds, not seconds.
var date = new Date(unix_timestamp*1000);
// Hours part from the timestamp
var hours = date.getHours();
// Minutes part from the timestamp
var minutes = "0" + date.getMinutes();
// Seconds part from the timestamp
var seconds = "0" + date.getSeconds();
@imvaskii
imvaskii / .htaccess
Created November 27, 2015 04:56
Wordpress wp-admin rewirte to custom slug
RewriteBase /
RewriteCond %{THE_REQUEST} ^GET\ /wp-admin/
RewriteRule ^wp-admin/(.*)$ manage/$1 [R,L]
RewriteRule ^manage(.*)$ wp-admin$1
@imvaskii
imvaskii / gist:4fe71965e996073da4b6
Created November 27, 2015 04:01 — forked from jruck/gist:4270084
WP: Minimal wp_oembed_get
// Minimal YouTube & Vimeo embeds
function wp_oembed_get( $url, $args = '' ) {
if(preg_match("/youtube.com\/watch\?v=([^&]+)/i", $url, $aMatch)){
return '<iframe width="640" height="360" src="http://www.youtube.com/embed/' . $aMatch[1] . '?loop=1&modestbranding=1&rel=0&showinfo=0&autohide=1" frameborder="0" allowfullscreen></iframe>';
}
if(preg_match("/youtube.com\/watch\?feature=player_embedded&v=([^&]+)/i", $url, $aMatch)){
return '<iframe width="640" height="360" src="http://www.youtube.com/embed/' . $aMatch[1] . '?loop=1&modestbranding=1&rel=0&showinfo=0&autohide=1" frameborder="0" allowfullscreen></iframe>';
}
@imvaskii
imvaskii / gist:a2cd67897d3b20bebacf
Created November 12, 2015 04:41 — forked from grandmanitou/gist:8863248
Place multiple markers with infowindow on Google Maps API v3, use external links to trigger click and center map on desired location.
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?language=fra&amp;sensor=false"></script>
<script type="text/javascript">
var map;
var Markers = {};
var infowindow;
var locations = [
[
'Samsung Store Madeleine',
'<strong>Samsung Store Madeleine</strong><p>5 Boulevard Malesherbes, 75008 Paris<br>10h – 20h</p>',
48.8701925,