Skip to content

Instantly share code, notes, and snippets.

View DrewAPicture's full-sized avatar

Drew Jaynes DrewAPicture

View GitHub Profile
<?php
function lol( $content ) {
return str_replace( ', ', ', LOL ', $content, 0 );
}
add_filter( 'the_content', 'lol' );
?>
@DrewAPicture
DrewAPicture / user-settings.php
Last active December 10, 2015 20:48
Get a user's user settings and parse them into an array. Dumps into the admin footer in the Dashboard.
<?php
function get_a_users_settings() {
// Change 1 to the user's ID
// Or do $user = wp_get_current_user() and change $user_id in get_user_option to $user->ID
$user_id = 1;
$option = get_user_option( 'user-settings', $user_id );
if ( $option && is_string( $option ) ) {
parse_str( $option, $array );
echo '<pre>';
var_dump( $array );
@DrewAPicture
DrewAPicture / 3.6.points.txt
Last active December 10, 2015 13:08
3.6 Proposal Points Jan. 2
## 3.6 Proposed Points from <devchat>
# Autosave
- We should never lose anything EVER.
- Seriously. EVER.
- Details TBD.
# Distraction-Free Writing
- Smoother transitions. It feels like a separate screen
- More easily discoverable
@DrewAPicture
DrewAPicture / hide-old-shortcode.php
Created January 2, 2013 20:46
Hide an old shortcode from post content after uninstalling a plugin
function hide_my_old_shortcode( $attr, $content ) {
return;
}
add_shortcode( 'my_old_shortcode', 'hide_my_old_shortcode' );
@DrewAPicture
DrewAPicture / video-query-transient.php
Created January 2, 2013 05:53
Video query transient. The HOUR_IN_SECONDS constant is available in 3.5+, otherwise you can just use something like 60*60
<?php
$query = get_transient( 'video_query' );
if ( false == $query ) {
$query = new WP_Query( $args );
set_transient( 'video_query', $query, HOUR_IN_SECONDS );
}
if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post();
@DrewAPicture
DrewAPicture / download.php
Last active December 10, 2015 11:09
Adds directory traversal protection
<?php
/**
* This script forces download on the specified file-types.
* It was been slightly modified to provide more security from
* unauthorized files such as those with a .php extension being
* downloaded, or force-download.php itself being exposed.
*
* http://creativecommons.org/licenses/by/3.0/
*
* Original Author: Louai Munajim
<?php
//Plugin Name: Comments in Account Menu
new Comments_in_Account_Menu();
class Comments_in_Account_Menu {
function __construct() {
add_action( 'admin_bar_menu', array( &$this, 'admin_bar_menu' ) );
@DrewAPicture
DrewAPicture / gist:4103650
Created November 18, 2012 05:01
Unregister all Core widgets
/**
* Unregister Core Widgets
*
* Unregisters all core widgets based on their individual
* class names.
*
* @uses unregister_widget() to unregister from the Widget Factory class
*/
function remove_core_widgets() {
unregister_widget( 'WP_Widget_Calendar' );
@DrewAPicture
DrewAPicture / plupload_scaling.php
Last active October 12, 2015 18:38
Enable and set plupload scaling dimensions
function plupload_scaling( $defaults ) {
$defaults['resize'] = array(
'width' => 1024,
'height' => 1024,
'quality' => 100
);
return $defaults;
}
add_filter( 'plupload_default_settings', 'plupload_scaling' );
@DrewAPicture
DrewAPicture / masonry-init.js
Created November 10, 2012 09:49
Masonry and WP post_class();
/**
* #content references the outer container selector
* .post references in the inner containers selectors
*/
jQuery(document).ready(function(){
jQuery( '#content' ).masonry({
itemSelector: '.post',
columnWidth: 320
});