Skip to content

Instantly share code, notes, and snippets.

View DrewAPicture's full-sized avatar

Drew Jaynes DrewAPicture

View GitHub Profile
@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
@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 / 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 / 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 / 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 );
<?php
function lol( $content ) {
return str_replace( ', ', ', LOL ', $content, 0 );
}
add_filter( 'the_content', 'lol' );
?>
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">
@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',
@DrewAPicture
DrewAPicture / largo-includes.diff
Created February 3, 2013 23:22
An idea for compacting Largo's includes.
diff --git a/functions.php b/functions.php
index 6855695..84634d8 100644
--- a/functions.php
+++ b/functions.php
@@ -50,47 +50,28 @@ if ( ! function_exists( 'optionsframework_init' ) ) {
* Load up all of the other goodies from the /inc directory
*/
-// a list of recommended plugins
-require_once( get_template_directory() . '/inc/largo-plugin-init.php' );
<?php foreach( (array) $nav_menus as $_nav_menu ) : ?>
<option value="<?php echo esc_url(add_query_arg( array( 'action' => 'edit', 'menu' => $_nav_menu->term_id, ), admin_url( 'nav-menus.php' ) )); ?>" <?php if ( $nav_menu_selected_id == $_nav_menu->term_id ) echo 'selected="selected"'; ?>>
<?php
echo esc_html( $_nav_menu->truncated_name ) ;
if ( ! empty( $menu_locations ) && in_array( $_nav_menu->term_id, $menu_locations ) ) {
$locations_assigned_to_this_menu = array();
foreach ( array_keys( $menu_locations, $_nav_menu->term_id ) as $menu_location_key ) {
$locations_assigned_to_this_menu[] = $locations[ $menu_location_key ];
}
$assigned_locations = array_slice( $locations_assigned_to_this_menu, 0, absint( apply_filters( 'wp_nav_locations_listed_per_menu', 3 ) ) );