Skip to content

Instantly share code, notes, and snippets.

Avatar

Daniel Bachhuber danielbachhuber

View GitHub Profile
View use-fields-for-post-content.php
<?php
/**
* Uses the custom fields as the document's 'post_content'.
*/
add_action(
'solr_build_document',
function ( $doc, $post ) {
// Only override for this page template.
@danielbachhuber
danielbachhuber / wpnps-auto-clear-sessions.php
Created Sep 15, 2020
Automatically clear WP Native PHP Sessions older than 24 hours
View wpnps-auto-clear-sessions.php
<?php
add_action(
'init',
function() {
if ( ! wp_next_scheduled( 'pantheonx_clear_sessions' ) ) {
wp_schedule_event( time(), 'twicedaily', 'pantheonx_clear_sessions' );
}
}
);
@danielbachhuber
danielbachhuber / wordpress-language-codes.csv
Created Apr 24, 2020
Language / locale codes used in WordPress
View wordpress-language-codes.csv
language english_name native_name
af Afrikaans Afrikaans
ar Arabic العربية
ary Moroccan Arabic العربية المغربية
as Assamese অসমীয়া
az Azerbaijani Azərbaycan dili
azb South Azerbaijani گؤنئی آذربایجان
bel Belarusian Беларуская мова
bg_BG Bulgarian Български
bn_BD Bengali (Bangladesh) বাংলা
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 );
}
});
View tasty-recipes-featured-image.php
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;
});
View tasty-recipes-reposition-jump-to.php
<?php
/**
* Re-positions the "Jump to Recipe" button.
*/
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' ), 10 );
}
});
@danielbachhuber
danielbachhuber / postmark-split-wp-mail.php
Created Jul 30, 2019
Splits wp_mail() with more than 40 bcc into multiple batches
View postmark-split-wp-mail.php
<?php
/**
* Splits a wp_mail() call with more than 40 bcc
* headers into multiple batches.
*
* Postmark only accepts 50 bcc, so this ensures the API call doesn't fail.
*
* @param array $args Original arguments passed to wp_mail().
* @return
*/
View tasty-recipes-filter-block-output.php
<?php
/**
* Filters the output of the Tasty Recipes block.
*
* @param string $output Existing output.
* @param array $block Block data.
* @return string
*/
add_filter( 'render_block', function( $output, $block ){
// Only modify the Tasty Recipes block.
View tasty-recipes-ratings-top.php
<?php
/**
* Adds the Tasty Recipes ratings to the top of the post.
*
* @param string $content Existing post content.
* @return string
*/
add_filter( 'the_content', function( $content ) {
if ( ! class_exists( 'Tasty_Recipes' ) ) {