Skip to content

Instantly share code, notes, and snippets.

View imvaskii's full-sized avatar
🎯
Focusing

Bhaskar imvaskii

🎯
Focusing
View GitHub Profile
@imvaskii
imvaskii / functions.php
Created October 8, 2015 04:53
500 error on comment submit. Custom wp_die handler
<?php
add_filter('wp_die_handler', 'get_my_custom_die_handler');
function my_custom_die_handler($message, $title='', $args=array()) {
$errorTemplate = get_theme_root().'/'.get_template().'/commenterror.php';
if(!is_admin() && file_exists($errorTemplate)) {
$defaults = array( 'response' => 500 );
$r = wp_parse_args($args, $defaults);
$have_gettext = function_exists('__');
if ( function_exists( 'is_wp_error' ) && is_wp_error( $message ) ) {
@imvaskii
imvaskii / custom-search-acf-wordpress.php
Created October 30, 2015 01:23 — forked from charleslouis/custom-search-acf-wordpress.php
PHP - Wordpress - Search - wordpress custom search function that encompasses ACF/advanced custom fields and taxonomies and split expression before request
<?php
/**
* [list_searcheable_acf list all the custom fields we want to include in our search query]
* @return [array] [list of custom fields]
*/
function list_searcheable_acf(){
$list_searcheable_acf = array("title", "sub_title", "excerpt_short", "excerpt_long", "xyz", "myACF");
return $list_searcheable_acf;
}
@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,
@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 / .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 / 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 / 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 / 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 / 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 / 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;