Skip to content

Instantly share code, notes, and snippets.

View DrewAPicture's full-sized avatar

Drew Jaynes DrewAPicture

View GitHub Profile
@DrewAPicture
DrewAPicture / example_help_tab.php
Last active December 11, 2015 18:48
Generally speaking, help tabs in core commonly follow one of the following three formats. Which should we use in a patch-making tutorial for the docs team?
<?php
/**
* Example format #1
*/
$example_string = '<p>' . __( 'This is some help text' ) . '</p>' .
'<p>' . __( 'This is some more help text' ) . '</p>';
get_current_screen()->add_help_tab( array(
'id' => 'example',
Drew@machine:~/Sites/mutrunk$ ack -i -Q 'action="<?php echo'
wp-activate.php
62: <form name="activateform" id="activateform" method="post" action="<?php echo network_site_url('wp-activate.php'); ?>">
wp-admin/includes/dashboard.php
441: <form action="<?php echo network_admin_url('users.php'); ?>" method="get">
448: <form action="<?php echo network_admin_url('sites.php'); ?>" method="get">
wp-admin/includes/file.php
982:<form action="<?php echo $form_post ?>" method="post">
<?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' );