Skip to content

Instantly share code, notes, and snippets.

Daniel Bachhuber danielbachhuber

Block or report user

Report or block danielbachhuber

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View tasty-recipes-jump-to-really-late.php
<?php
/**
* Ensures the "Jump to Recipe" button is added to the content really late.
*/
add_action( 'init', function(){
if ( method_exists( 'Tasty_Recipes\Shortcodes', 'filter_the_content_late' ) ) {
remove_filter( 'the_content', array( 'Tasty_Recipes\Shortcodes', 'filter_the_content_late' ), 100 );
add_filter( 'the_content', array( 'Tasty_Recipes\Shortcodes', 'filter_the_content_late' ), 10000 );
}
});
@danielbachhuber
danielbachhuber / gist:7684646
Created Nov 27, 2013
How to integrate WordPress Core updates with your custom Plugin or Theme
View gist:7684646
<?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 ) {
View digest-auth-remote-get.php
<?php
/**
* Make a remote GET using DIGEST authentication.
*
* DIGEST authenticated requests require two GET requests:
* 1. GET the www-authenticate header for nonce, realm, opaque, and other values
* 2. GET the expected response body by constructing an 'Authorization' header
* with nonce, realm, and other values provided by the server.
*
@danielbachhuber
danielbachhuber / gist:7126249
Last active Dec 5, 2019
Include posts from authors in the search results where either their display name or user login matches the query string
View gist:7126249
<?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 / blog-archive.php
Last active Oct 31, 2019
Creating a blog post archive at /blog/ without awkwardly publishing a page
View blog-archive.php
<?php
add_filter( 'register_post_type_args', function( $args, $post_type ) {
global $wp_rewrite;
if ( 'post' === $post_type && ! is_null( $wp_rewrite ) ) {
$archive_slug = 'blog';
// Setting 'has_archive' ensures get_post_type_archive_template() returns an archive.php template.
$args['has_archive'] = $archive_slug;
// We have to register rewrite rules, because WordPress won't do it for us unless $args['rewrite'] is true.
$archive_slug = $wp_rewrite->root . $archive_slug;
View tasty-recipes-featured-image.php
@danielbachhuber
danielbachhuber / disable-logged-out-users.php
Last active Oct 7, 2019
Disable WP REST API requests for logged out users
View disable-logged-out-users.php
<?php
add_filter( 'rest_authentication_errors', function( $result ) {
if ( ! empty( $result ) ) {
return $result;
}
if ( ! is_user_logged_in() ) {
return new WP_Error( 'restx_logged_out', 'Sorry, you must be logged in to make a request.', array( 'status' => 401 ) );
}
return $result;
@danielbachhuber
danielbachhuber / http-to-https.php
Created Mar 28, 2018
Update a specific site from 'http://' to 'https://'.
View http-to-https.php
<?php
/**
* Update a specific site from 'http://' to 'https://'.
*
* Only touches the 'home' and 'siteurl' options.
* Depending on plugins, etc., you may need to update other options too.
*
* Run on WordPress multisite with:
*
* wp site list --field=url | xargs -I % wp eval-file http-to-https.php --url=%
View tasty-recipes-disable-print-pinning.php
<?php
/**
* Disable pinning on the print template.
*/
add_action( 'template_redirect', function() {
if ( function_exists( 'tasty_recipes_is_print' ) && tasty_recipes_is_print() ) {
add_action( 'wp_head', function() {
echo '<meta name="pinterest" content="nopin" description="Sorry, but please don\'t pin from the print page." />' . PHP_EOL;
});
@danielbachhuber
danielbachhuber / disable-comments.php
Created May 15, 2019
Disable comments entirely from the WordPress backend
View disable-comments.php
<?php
add_filter( 'comments_open', '__return_false' );
add_action( 'admin_menu', function(){
global $menu;
// Remove Comments
if ( isset( $menu[25] ) ) {
unset( $menu[25] );
}
You can’t perform that action at this time.