Skip to content

Instantly share code, notes, and snippets.

View imvaskii's full-sized avatar
🎯
Focusing

Bhaskar imvaskii

🎯
Focusing
View GitHub Profile
@imvaskii
imvaskii / getDateRange.php
Created March 20, 2015 07:42
Get date range between start and end date
<?php
function returnDates($fromdate, $todate) {
$date_list = array();
$fromdate = date(strtotime($fromdate));
$todate = date(strtotime($todate));
for ($i = $fromdate; $i <= $todate; $i+=86400) {
array_push($date_list, date("Y/m/d H", $i));
}
return $date_list;
}
/**
* Programmatically logs a user in
*
* @param string $username
* @return bool True if the login was successful; false if it wasn't
*/
function programmatic_login( $username ) {
if ( is_user_logged_in() ) {
wp_logout();
@imvaskii
imvaskii / functions.php
Created March 13, 2015 06:06
Restrict non admin users to wp-admin
<?php
add_action('admin_init', 'no_mo_dashboard');
function no_mo_dashboard() {
if (!current_user_can('manage_options') && $_SERVER['DOING_AJAX'] != '/wp-admin/admin-ajax.php') {
wp_redirect(home_url()); exit;
}
}
?>
@imvaskii
imvaskii / template-includer.php
Last active August 29, 2015 14:16
[Wordpress] script to include template from any location
<?php function register_project_templates(){
//Create the key used for the themes cache
$cache_key = 'page_templates-'.md5( get_theme_root().'/'.get_stylesheet());
$templates = wp_get_theme()->get_page_templates();
if( empty( $templates ) ) {
$templates = array();
@imvaskii
imvaskii / loginform.php
Created March 2, 2015 14:50
WP Login Form
<?php function wp_login_form_frontend($args = array()) {
$defaults = array('echo' => true,
'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'], // Default redirect is back to the current page
'form_id' => 'loginformfrontend',
'label_username' => __('Username'),
'label_password' => __('Password'),
'label_remember' => __('Remember Me'),
'label_log_in' => __('SIGN IN'),
'id_username' => 'user_login',
'id_password' => 'user_pass',
<?php
add_action('wp_ajax_twitter_share', 'twitter_share', 0);
add_action('wp_ajax_nopriv_twitter_share', 'twitter_share');
function twitter_share() {
$your_data = $_POST['your_data'];
echo $your_data;
die;
}
<?php # -*- coding: utf-8 -*-
/**
* Create a nav menu with very basic markup.
*
* @author Thomas Scholz http://toscho.de
* @version 1.0
*/
class T5_Nav_Menu_Walker_Simple extends Walker_Nav_Menu
{
/**
@imvaskii
imvaskii / deferjs.js
Last active August 29, 2015 14:11
DeferJS
function downloadJSAtOnload() {
var element = document.createElement("script");
element.src = "defer.js";
document.body.appendChild(element);
}
if (window.addEventListener)
window.addEventListener("load", downloadJSAtOnload, false);
else if (window.attachEvent)
window.attachEvent("onload", downloadJSAtOnload);
#!/bin/bash
#
# SIV : System Information Viewer
#
# Author : Saikat Basak ([email protected])
#
# **** License ****
#
# The software is distributed under "THE BEER-WARE LICENSE" (Revision 42)
# The Beer-ware license was written by Poul-Henning Kamp. <[email protected]>
// Ensure cart contents update when products are added to the cart via AJAX (place the following in functions.php)
add_filter('add_to_cart_fragments', 'woocommerce_header_add_to_cart_fragment');
function woocommerce_header_add_to_cart_fragment( $fragments ) {
global $woocommerce;
ob_start();
?>
<a class="cart-contents" href="<?php echo $woocommerce->cart->get_cart_url(); ?>" title="<?php _e('View your shopping cart', 'woothemes'); ?>"><?php echo sprintf(_n('%d item', '%d items', $woocommerce->cart->cart_contents_count, 'woothemes'), $woocommerce->cart->cart_contents_count);?> - <?php echo $woocommerce->cart->get_cart_total(); ?></a>