Skip to content

Instantly share code, notes, and snippets.

View danielbachhuber's full-sized avatar

Daniel Bachhuber danielbachhuber

View GitHub Profile
<?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 September 15, 2020 12:11
Automatically clear WP Native PHP Sessions older than 24 hours
<?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 April 24, 2020 12:35
Language / locale codes used in WordPress
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) বাংলা
<?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 );
}
});
<?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;
});
<?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 July 30, 2019 22:34
Splits wp_mail() with more than 40 bcc into multiple batches
<?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
*/
<?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.
<?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' ) ) {