Skip to content

Instantly share code, notes, and snippets.

View govindak's full-sized avatar

Govinda Khatiwada govindak

View GitHub Profile
@govindak
govindak / Functions.php
Created November 12, 2013 18:00 — forked from barbwiredmedia/Functions.php
wordpress breadcrumbs
//Bread crumbs created
function wordpress_breadcrumbs() {
$delimiter = '|';
$currentBefore = '<span class="current">';
$currentAfter = '</span>';
if ( !is_home() && !is_front_page() || is_paged() ) {
echo '<div id="crumbs">';
global $post;
if ( is_page() && !$post->post_parent ) {
echo $currentBefore;
<?php
// Magento: Getting categroy from product
$categoryIds = $_product->getCategoryIds();
if(count($categoryIds) ){
$firstCategoryId = $categoryIds[0];
$_category = Mage::getModel('catalog/category')->load($firstCategoryId);
echo $_category->getData('categorysecondimage');
}
add_action( 'user_register', 'myplugin_registration_save', 10, 1 );
function myplugin_registration_save( $user_id ) {
$current_admin_user = wp_get_current_user();
if ( isset( $_POST['first_name'] ) ){
$user = new WP_User( $user_id );
$user_roles = $user->roles;
$user_role = array_shift($user_roles);
if($user_role!="administrator"){
update_user_meta($user_id, 'asso_admin', $current_admin_user->ID);
}else{
<?php
/** maxmind geoip integration in php */
function get_real_ip() {
$ipaddress = '';
if(empty($_REQUEST['ip']) && @$_REQUEST['ip']==""){
if (@$_SERVER['HTTP_CLIENT_IP'])
$ipaddress = @$_SERVER['HTTP_CLIENT_IP'];
else if(@$_SERVER['HTTP_X_FORWARDED_FOR'])
$ipaddress = @$_SERVER['HTTP_X_FORWARDED_FOR'];
else if(@$_SERVER['HTTP_X_FORWARDED'])
<?php
//usage:
//url_title($title);
if ( ! function_exists('url_title'))
{
/**
* Create URL Title
*
defaults delete ~/Library/Preferences/com.teamviewer.teamviewer9.plist
defaults delete ~/Library/Preferences/com.teamviewer.teamviewer9.Machine.plist
sudo defaults delete /Library/Preferences/com.teamviewer.teamviewer9.plist
rm -f ~/Library/Preferences/com.teamviewer.teamviewer9.plist
rm -f ~/Library/Preferences/com.teamviewer.teamviewer9.Machine.plist
sudo rm -f /Library/Preferences/com.teamviewer.teamviewer9.plist
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' );
$registrationIds = array( $_GET['id'] );
// prep the bundle
$msg = array
@govindak
govindak / wp.sh
Created October 6, 2015 16:37 — forked from bgallagh3r/wp.sh
Wordpress: Bash Install Script -- Downloads latest WP version, updates wp-config with user supplied DB name, username and password, creates and CHMOD's uploads dir, copies all the files into the root dir you run the script from, then deletes itself!
#!/bin/bash -e
clear
echo "============================================"
echo "WordPress Install Script"
echo "============================================"
echo "Database Name: "
read -e dbname
echo "Database User: "
read -e dbuser
echo "Database Password: "
@govindak
govindak / custom_post_type_cf7_dropdown.php
Created May 24, 2016 10:52 — forked from alkrauss48/custom_post_type_cf7_dropdown.php
Adding a custom Wordpress shortcode for building a dynamic dropdown of post type titles with Contact Form 7
wpcf7_add_shortcode('postdropdown', 'createbox', true);
function createbox(){
global $post;
extract( shortcode_atts( array( 'post_type' => 'some_post_type',), $atts ) );
$args = array('post_type' => $post_type );
$myposts = get_posts( $args );
$output = "<select name='postType' id='postType' onchange='document.getElementById(\"postType\").value=this.value;'><option></option>";
foreach ( $myposts as $post ) : setup_postdata($post);
$title = get_the_title();
$output .= "<option value='$title'> $title </option>";
@govindak
govindak / auto_enroll.php
Created August 17, 2016 19:39 — forked from supercleanse/auto_enroll.php
Automatically create a lifetime transaction for a specific product each time a user registers.
<?php
if(is_plugin_active('memberpress/memberpress.php')) {
add_action( 'user_register', 'mp_auto_enroll' );
//add_action( 'gform_user_registered', 'mp_auto_enroll', 10, 4 );
function mp_auto_enroll($user_id, $user_config=array(), $entry='', $user_pass='') {
$txn = new MeprTransaction();
$txn->user_id = $user_id;