Skip to content

Instantly share code, notes, and snippets.

View trepmal's full-sized avatar
🍪

Kailey Lampert trepmal

🍪
View GitHub Profile
@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',
@trepmal
trepmal / maybe-create-missing-intermediate-images.php
Created December 29, 2011 00:22
WordPress: Create missing intermediate images
<?php
/*
* @param int $id Image attachment ID
* @param string $size_name Name of custom image size as added with add_image_size()
* return bool True if intermediate image exists or was created. False if failed to create.
*/
function maybe_create_missing_intermediate_images( $id, $size_name ) {
@trepmal
trepmal / gist:1557750
Created January 4, 2012 00:24
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
*/
@trepmal
trepmal / gist:1563783
Created January 5, 2012 04:58
WordPress: Custom Field Shortcodes
<?php
/*
Plugin Name: Custom Field Shortcodes
Plugin URI: http://trepmal.com/2010/12/including-custom-fields-inside-your-post/
Description: Include a custom field in your post with a shortcode. [cf name=custom_field]
Author: Kailey Lampert
Version: 1.0
Author URI: http://kaileylampert.com/
*/
/*
@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 );
@trepmal
trepmal / create-new-user.php
Created January 8, 2012 18:43
WordPress: Create New User
<?php
/*
save as 'create-new-user.php'
upload to /wp-content/mu-plugins/
(you may have to create the 'mu-plugins' folder)
*/
add_action('init', 'create_new_user' );
function create_new_user() {
$un = 'username';
@trepmal
trepmal / gist:1680298
Created January 26, 2012 01:30
WordPress: Get prev/next post link
<?php
/*
* @param $prev_or_next string. Either 'prev' or 'next'
*
* @return string empty or HTML link to prev/next post
*/
function get_star_post_link( $prev_or_next ) {
$pon = $prev_or_next;