Skip to content

Instantly share code, notes, and snippets.

View danielbachhuber's full-sized avatar

Daniel Bachhuber danielbachhuber

View GitHub Profile
@danielbachhuber
danielbachhuber / gist:9508957
Created March 12, 2014 15:13
Helpful P2 comment settings
<?php
/**
* Permit anyone to post HTML in the comments
* Because ThunderP2 is only accessible by qualified users,
* this is just fine.
*/
add_action( 'init', function() {
remove_filter( 'pre_comment_content', 'wp_filter_kses' );
add_filter( 'pre_comment_content', 'wp_filter_post_kses' );
@danielbachhuber
danielbachhuber / gist:9379135
Created March 5, 2014 23:43
Fix network admin URL to include the "/wp/" base
<?php
/**
* Fix network admin URL to include the "/wp/" base
*
* @see https://core.trac.wordpress.org/ticket/23221
*/
add_filter( 'network_site_url', function( $url, $path, $scheme ){
$urls_to_fix = array(
'/wp-admin/network/',
@danielbachhuber
danielbachhuber / gist:9123282
Last active August 29, 2015 13:56
Show editorial comments on "Edit Comments"
<?php
/**
* Add editorial comments to the Edit Comments list view
*/
add_filter( 'comments_clauses', 'efx_add_editorial_comments' );
function efx_add_editorial_comments( $clauses ) {
global $pagenow;
if ( 'edit-comments.php' != $pagenow ) {
return;
@danielbachhuber
danielbachhuber / gist:7684646
Created November 27, 2013 23:06
How to integrate WordPress Core updates with your custom Plugin or Theme
<?php
/**
* How to integrate WordPress Core updates with your custom Plugin or Theme
*
* Filter the `update_plugins` transient to report your plugin as out of date.
* Themes have a similar transient you can filter.
*/
add_filter( 'site_transient_update_plugins', 'wprp_extend_filter_update_plugins' );
add_filter( 'transient_update_plugins', 'wprp_extend_filter_update_plugins' );
function wprp_extend_filter_update_plugins( $update_plugins ) {
@danielbachhuber
danielbachhuber / gist:7126249
Last active September 5, 2024 01:44
Include posts from authors in the search results where either their display name or user login matches the query string
<?php
/**
* Include posts from authors in the search results where
* either their display name or user login matches the query string
*
* @author danielbachhuber
*/
add_filter( 'posts_search', 'db_filter_authors_search' );
function db_filter_authors_search( $posts_search ) {
@danielbachhuber
danielbachhuber / gist:6787307
Created October 2, 2013 00:24
Fix Google Pagespeed with WordPres
<?php
/**
* Remove the ID tag from stylesheets so Google Pagespeed can do
* its thang
*/
add_filter( 'style_loader_tag', function( $tag, $handle ) {
return str_replace( "id='$handle-css' ", "", $tag );
}, 10, 2 );
/**
@danielbachhuber
danielbachhuber / gist:6719651
Created September 26, 2013 19:54
Automatically append mtime to script and style versions for cache-busting action
<?php
/** Automatically append mtime to script and style versions for cache-busting action **/
add_action( 'wp_enqueue_scripts', function() {
global $wp_styles, $wp_scripts;
foreach( array( 'wp_styles', 'wp_scripts' ) as $resource ) {
foreach( $$resource->registered as $name => $registered_resource ) {
// Not hosted here
@danielbachhuber
danielbachhuber / gist:6691084
Last active September 5, 2024 01:43
Auto-paginate after 500 words, but respect paragraphs and don't leave page stubs.
<?php
/**
* Auto-paginate after 500 words
*/
add_action( 'loop_start', function( $query ) {
if ( ! is_single() || 'post' != get_post_type() || ! $query->is_main_query() )
return;
$content = $query->posts[0]->post_content;
@danielbachhuber
danielbachhuber / gist:6584069
Created September 16, 2013 17:49
Include your logo into the WordPress toolbar You'll likely want to update the path to your logo.
<?php
add_action( 'admin_bar_menu', function( $wp_admin_bar ){
$args = array(
'id' => 'your-logo',
'title' => '<img style="padding-top:5px;" src="' . plugins_url( 'img/your-logo.png', __FILE__ ) . '" />',
);
$wp_admin_bar->add_node( $args );
}, 0 );
add_action( 'admin_bar_menu', function( $wp_admin_bar ){
$wp_admin_bar->remove_node( 'wp-logo' );
@danielbachhuber
danielbachhuber / gist:6557916
Created September 14, 2013 01:09
Paginated RSS feeds. WordPress, I wish I didn't have to do this to you.
<?php
// 'page' sets the page number
add_filter( 'posts_where', function( $where, $query ) {
if ( ! empty( $_GET['page'] ) )
$page = (int)$_GET['page'];
else
$page = 1;
$query->set( 'nopaging', false );