Skip to content

Instantly share code, notes, and snippets.

/**
* 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();
@vishalbasnet23
vishalbasnet23 / function.php
Created October 7, 2015 04:57
Adding page and assigning page template.
<?php
function create_pages(){
$awesome_page_id = get_option("awesome_page_id");
if (!$awesome_page_id) {
//create a new page and automatically assign the page template
$post1 = array(
'post_title' => "Awesome Page!",
'post_content' => "",
'post_status' => "publish",
'post_type' => 'page',
@vishalbasnet23
vishalbasnet23 / print_r_reverse.php
Created September 30, 2015 07:38
Reverse Print r up to multiple levels
function print_r_reverse($in) {
$lines = explode("\n", trim($in));
if (trim($lines[0]) != 'Array') {
// bottomed out to something that isn't an array
return $in;
} else {
// this is an array, lets parse it
if (preg_match("/(\s{5,})\(/", $lines[1], $match)) {
// this is a tested array/recursive call to this function
// take a set of spaces off the beginning
@vishalbasnet23
vishalbasnet23 / function.php
Created September 21, 2015 08:22
Change password frontend WP function
function change_pass_frontend() {
require_once( ABSPATH . 'wp-includes/class-phpass.php');
$old_pass = $_POST['old_pass'];
$new_pass = $_POST['new_pass'];
$user_id = $_POST['user_id'];
$user_data = get_userdata( $user_id );
$wp_hasher = new PasswordHash(8, TRUE);
$password_hashed = $user_data->user_pass;
if($wp_hasher->CheckPassword($old_pass, $password_hashed)) {
wp_set_password( $new_pass, $user_id );
@vishalbasnet23
vishalbasnet23 / gist:18cff4ee4a160a1c0393
Created August 28, 2015 08:33
Sublime Text 3 User Preferences.
{
"always_show_minimap_viewport": true,
"bold_folder_labels": true,
"caret_extra_bottom": 3,
"caret_extra_top": 3,
"caret_extra_width": 2,
"enable_tab_scrolling": false,
"font_face": "Ubuntu Mono",
"font_options":
[
@vishalbasnet23
vishalbasnet23 / functions.php
Created June 9, 2015 03:54
Allow Deposits In WooCommerce
add_filter('woocommerce_cart_item_subtotal','additional_shipping_cost',10,3);
function additional_shipping_cost($subtotal, $values, $cart_item_key) {
$custom_diposit_cost = get_post_meta($values['product_id'], 'deposit', true);
$ori_val = $values['line_total'];
if ($custom_diposit_cost) {
$total_item_cost = $ori_val-$custom_diposit_cost;
return woocommerce_price($total_item_cost);
} else {
return $subtotal;
}
@vishalbasnet23
vishalbasnet23 / functions.php
Created June 9, 2015 03:52
Allow Single Quantity in Cart Woocommerce
add_filter ( 'woocommerce_before_cart' , 'allow_single_quantity_in_cart' );
function allow_single_quantity_in_cart() {
global $woocommerce;
$cart_contents = $woocommerce->cart->get_cart();
$keys = array_keys ( $cart_contents );
foreach ( $keys as $key ) {
$woocommerce->cart->set_quantity ( $key, 1, true );
}
@vishalbasnet23
vishalbasnet23 / test
Created June 4, 2015 09:33
Set App Menus to ‘Always Show’
To Enable:
gsettings set com.canonical.Unity always-show-menus true
To Disable:
gsettings set com.canonical.Unity always-show-menus false
@vishalbasnet23
vishalbasnet23 / gist:b0d04160ec8bb2505fb7
Last active August 29, 2015 14:21
Enabling shared Repo for git
ssh to server
cd your-repository.git
sudo chmod -R g+ws *
sudo chgrp -R yourgroup *
and maybe:
git repo-config core.sharedRepository true
@vishalbasnet23
vishalbasnet23 / cpm-pointer.js
Created May 5, 2015 11:29
Simple WP Pointer Helper Function.
jQuery(document).ready( function($) {
cpm_open_pointer(0);
function cpm_open_pointer(i) {
pointer = cpmPointer.pointers[i];
options = $.extend( pointer.options, {
close: function() {
$.post( ajaxurl, {
pointer: pointer.pointer_id,
action: 'dismiss-wp-pointer'
});