Skip to content

Instantly share code, notes, and snippets.

@yassiryahya
yassiryahya / functions.php
Created November 24, 2011 16:46
Assigning Role On Wordpress Registration & Profile Page
<?php
// Add two new role.
// Full list of capabilities can be found at http://codex.wordpress.org/Roles_and_Capabilities#Capability_vs._Role_Table
add_role('writer', 'Writer', array(
'delete_posts' => true,
'delete_published_posts' => true,
'edit_posts' => true,
'edit_published_posts' => true,
'publish_posts' => true,
'read' => true,
<?php
function vtp_install_data() {
add_action( 'init', 'vtp_setup_terms', 11 );
}
register_activation_hook( __FILE__, 'vtp_install_data' );
function vtp_setup_terms() {
if ( ! term_exists( 'Customer', 'account_type' ) ) {
wp_insert_term( 'Customer', 'account_type');
@mikeschinkel
mikeschinkel / jills_properties.php
Created December 13, 2011 03:20
Ad-hoc Plugin Example for Atlanta WordPress Developer Meetup - 2011-12-12
<?php
/*
* Plugin Name: Jill's Properties
* Description: Ad-hoc Plugin Example for Atlanta WordPress Developer Meetup - 2011-12-12
* Author: Mike Schinkel
* Author URI: http://about.me/mikeschinkel
* Version: 0.1
*/
class Jills_Properties {
static function on_load() {
@eteubert
eteubert / activate.php
Created December 20, 2011 10:45
WordPress: Find Users by Last Login Activity
<?php
register_activation_hook( __FILE__, 'add_last_activity_for_all_users' );
function add_last_activity_for_all_users() {
global $wpdb;
$sql = $wpdb->prepare( "
SELECT
u.ID
FROM
$wpdb->users AS u
@trepmal
trepmal / countdown-redirect.php
Created December 22, 2011 07:33
WordPress: Countdown, Redirect
<?php
//Plugin Name: Countdown, Redirect
//Description: Just a demo, thus has limitations
new Countdown_Redirect();
class Countdown_Redirect {
@trepmal
trepmal / gist:1518263
Created December 24, 2011 20:21
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;
@trepmal
trepmal / gist:1520378
Created December 26, 2011 01:50
WordPress: [concept] Cross-CPT Parent/Child
<?php
//Plugin Name: [concept] Cross-CPT Parent/Child
//Description: Just a demo!.
add_action( 'init', 'kl_post_types');
function kl_post_types() {
register_post_type( 'parent', array(
'label' => 'Parent',
@chrisguitarguy
chrisguitarguy / logo-wrap.php
Created December 30, 2011 20:10
Wrapping a logo image in an H1 on certain pages
<?php $logo_wrap = in_array( $_SERVER['REQUEST_URI'], array( '/magazine', '/blog', '/' ) ) ? 'h1' : 'div'; ?>
<<?php echo $logo_wrap; ?> class="al_left">
<a href="http://www.2xist.com">
<img id="logo" src="http://www.2xist.com/images/logo-2xist.gif" alt="2xist Mens Underwear" title="2xist Mens Underwear" />
</a>
</<?php echo $logo_wrap; ?>>
@trepmal
trepmal / gist:1565786
Created January 5, 2012 15:45
WordPress: Redirect User at Login
<?php
add_filter('login_redirect', 'change_login_redirect', 10, 3 );
function change_login_redirect( $redirect_to, $request, $user) {
/*
using $user, you can change this on a per-user basis if you want
*/
// options.php is just a sample, change as needed
@trepmal
trepmal / gist:1566525
Created January 5, 2012 18:29
WordPress: Breadcrumb Functions
<?php
/*
Plugin Name: Breadcrumb Functions
Description: Functions for displaying breadcrumbs when working with hierarchical post types. Does nothing out-of-the-box, functions must be added to theme (directly or via hooks, your discretion).
Author: Kailey Lampert
Author URI: http://kaileylampert.com/
*/
/*
Basic:
echo get_breadcrumbs( $post );