Skip to content

Instantly share code, notes, and snippets.

View viruthagiri's full-sized avatar

Viruthagiri Thirumavalavan viruthagiri

  • Bangalore, India
View GitHub Profile
@viruthagiri
viruthagiri / widget-tut.php
Created December 30, 2011 01:22 — forked from chrisguitarguy/widget-tut.php
An example of how to build your own WordPress widget
<?php
/*
Plugin Name: PMG Widget Tututorial
Plugin URI: http://pmg.co/category/wordpress
Description: How to create WordPress Widgets.
Version: 1.0
Author: Christopher Davis
Author URI: http://pmg.co/people/chris
License: GPL2
*/
@viruthagiri
viruthagiri / functions.php
Created February 3, 2012 22:46 — forked from johnmegahan/functions.php
Extended Walker class for use with the Twitter Bootstrap toolkit Dropdown menus in Wordpress
<?php
add_action( 'after_setup_theme', 'bootstrap_setup' );
if ( ! function_exists( 'bootstrap_setup' ) ):
function bootstrap_setup(){
add_action( 'init', 'register_menu' );
@viruthagiri
viruthagiri / 00-the-wordpress-way.md
Created February 7, 2012 18:20 — forked from dave1010/00-the-wordpress-way.md
The WordPress Way - The 10 rules of WordPress development

The WordPress Way

A tongue-in-cheek look at coding standards in the WordPress core and the average WordPress plugin.

  1. # Declare variables global - in case they're going to be used again
  2. All function/method parameters should be strings (e.g. 'yes'/'no') - for clarity
  3. Functions and methods should return mixed types
  4. No need to separate PHP logic from HTML, JS or CSS
  5. Don't worry about PHP Notices - they're not important
@viruthagiri
viruthagiri / pw-at-signup.php
Created February 7, 2012 18:27 — forked from trepmal/pw-at-signup.php
WordPress: Choose password at registration (Multisite)
<?php
//Plugin Name: Choose password at registration (Multisite)
//Description: Doesn't change the confirmation screen or email
add_action('signup_extra_fields', 'ask_for_password');
function ask_for_password( $errors ) {
if ( $errmsg = $errors->get_error_message('bad_password') ) {
echo '<p class="error">'.$errmsg.'</p>';
}
@viruthagiri
viruthagiri / scroll-to-top-admin-bar.php
Created February 7, 2012 18:27 — forked from trepmal/scroll-to-top-admin-bar.php
WordPress - Scroll-To-Top Admin Bar
<?php
/*
Plugin Name: Scroll-To-Top Admin Bar
Description: Click anywhere on the Admin Bar that doesn't have a predefined purpose (links, input), and it'll scroll you to the top
Author: Kailey Lampert
Author URI: http://kaileylampert.com
*/
add_action( 'wp_head', 'add_jq' );
add_action( 'admin_head', 'add_jq' );
@viruthagiri
viruthagiri / gist:1761114
Created February 7, 2012 18:27 — forked from trepmal/gist:1518263
WordPress: [concept] Protect users in one role from users in another
<?php
//Plugin Name: [concept] Protect users in one role from users in another
//Description: Users in custom faux-admin role 'site administrator' cannot modify default admins
add_filter( 'map_meta_cap', 'prevent_edit_of_primary_user', 10, 4 );
function prevent_edit_of_primary_user( $caps, $cap, $user_id, $args ) {
if ( ! is_user_logged_in() ) return $caps;
@viruthagiri
viruthagiri / gist:1761116
Created February 7, 2012 18:27 — forked from trepmal/gist:1557750
WordPress: Network-Wide Tips
<?php
/*
Plugin Name: Network-Wide Tips
Description: Save multiple notices, only activate one at a time. Displayed across WP Network.
Author: Kailey Lampert
Author: http://kaileylampert.com
Version: 1.0
*/
@viruthagiri
viruthagiri / multisite_functions.php
Created February 7, 2012 18:28 — forked from freekrai/multisite_functions.php
Some handy wordpress multisite functions
<?php
$posts = multisite_latest_post( array(
"how_many"=>10,
"how_long_days"=>30,
"how_many_words"=>50,
"more_text"=>"[...]",
"remove_html"=>true,
"sort_by"=>"post_date",
// if paginating:
"paginate"=>true,
@viruthagiri
viruthagiri / gist:1761124
Created February 7, 2012 18:29 — forked from freekrai/gist:1149844
wordpress redirect on login based on roles
function fs_login($user, $pass) {
$uname = $user;
$pass1 = $pass;
$credentials = array(
'user_login' => $user,
'user_password' => $pass,
'remember' => true
);
$user = wp_signon($credentials, false);
if( $user->ID ){
@viruthagiri
viruthagiri / filter_wpmu_signup_user_notification.php
Created February 7, 2012 18:29
Change the default WordPress MultiSite user notification mail from using the main network admin_email and site_name to the blog admin_email & blogname.
<?php
add_filter( 'wpmu_signup_user_notification', 'dk_wpmu_signup_user_notification', 10, 4 );
/**
* Problem: WordPress MultiSite sends user signup mails from the main site. This is a problem when using domain mapping functionality as the sender is not the same domain as expected when creating a new user from a blog with another domain.
* Solution: Change the default user notification mail from using the main network admin_email and site_name to the blog admin_email & blogname
*
* @author Daan Kortenbach
* @link http://daankortenbach.nl/wordpress/filter-wpmu_signup_user_notification/
*/
function dk_wpmu_signup_user_notification($user, $user_email, $key, $meta = '') {