Skip to content

Instantly share code, notes, and snippets.

View bmsterling's full-sized avatar

Benjamin Sterling bmsterling

View GitHub Profile
@bmsterling
bmsterling / gist:3847048
Created October 7, 2012 03:57
Disable changing the wordpress theme
/**
* Disable changing the theme for anyone a part from the admin user
*/
add_action('admin_init', 'disable_changing_theme_for_non_admin');
function disable_changing_theme_for_non_admin() {
global $submenu, $userdata;
get_currentuserinfo();
if ($userdata->ID != 1) {
unset($submenu['themes.php'][5]);
}
@bmsterling
bmsterling / gist:3681506
Created September 9, 2012 00:21
Wordpress: Add vars so that you can use get_query_var
add_filter('query_vars', 'add_queryvars' );
function add_queryvars( $qvars ){
$qvars[] = '_m';
return $qvars;
}
@bmsterling
bmsterling / gist:3667589
Created September 7, 2012 16:31
Export only changed files between two commits with folder structure for git
tar czf new-files.tar.gz `git diff <COMMITIDFROM> <COMMITIDTO> --name-only`
@bmsterling
bmsterling / gist:3549100
Created August 31, 2012 04:34
Wordpress: List all children pages and include the parent page
$child_of = 0;
if (empty($post->post_parent)){
$child_of = $post->ID;
}
else {
$child_of = $post->post_parent;
}
// Set defaults
$defaults = array(
@bmsterling
bmsterling / add_attr_attachment_link.php
Created August 31, 2012 02:41
Add attributes to attachment links wp_get_attachment_link
@bmsterling
bmsterling / wp_list_pages_add_first_last.php
Created August 30, 2012 15:28
Add the first and last class to wp_list_pages for wordpress
function wp_list_pages_add_first_last($content) {
$content = preg_replace('/li class\=\"/', 'li class="first ', $content, 1);
$content_rev = strrev($content);
$content_rev = preg_replace('/\"\=ssalc il/', ' tsal"=ssalc il', $content_rev, 1);
return strrev($content_rev);
}
add_filter('wp_list_pages','wp_list_pages_add_first_last');
@bmsterling
bmsterling / gist:1978441
Created March 5, 2012 14:06
xdebug overrides
<?php
ini_set('xdebug.var_display_max_children', 3999 );
ini_set('xdebug.var_display_max_data', 3999 );
ini_set('xdebug.var_display_max_depth', 3999 );
?>
@bmsterling
bmsterling / collections_tags.js
Created December 29, 2011 03:54
Pagination of a large set of models. The full story can be found at http://benjaminsterling.com/pagination-and-backbone-js/
(function (collections, pagination, model) {
collections.Tags = Backbone.Collection.extend({
model : model,
url : 'tags_all.php',
/**
* @param resp the response returned by the server
* @returns (Array) tags
*/
parse : function (resp) {
@bmsterling
bmsterling / wpautop_fix
Created May 5, 2011 20:01
Removed the paragraph tag that wordpress' wpautop puts around images.
function wpautop_fix( $content ){
$content = ereg_replace('<p[^>]*>(<img[^>]*>)<\\/p[^>]*>', '\\1', $content);
return $content;
}
add_filter('the_content', 'wpautop_fix');
@bmsterling
bmsterling / equalHeight
Created May 3, 2011 12:49
Conversion of the jQuery Equal height plugin for Dojo 1.3.2 (not sure if it works in newer versions)
(function(d){
dojo.extend(dojo.NodeList, {
equalHeight: function(options, data){
var defaults = {
height:null,
minHeight: 0,
maxHeight: null
};
options = dojo.mixin(defaults, options);