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-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' ) ) {
@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] );
}
@danielbachhuber
danielbachhuber / tasty-recipes-medium-image-size.php
Created Mar 8, 2019
Use the 'medium' image size for a Tasty Recipe card when it exists.
View tasty-recipes-medium-image-size.php
<?php
/**
* Use the 'medium' image size for a Tasty Recipe card when it exists.
*
* @param array $template_vars Template variables to be used.
* @param object $recipe Recipe object.
*/
add_filter( 'tasty_recipes_recipe_template_vars', function( $template_vars, $recipe ) {
$recipe_json = $recipe->to_json();
if ( ! empty( $recipe_json['image_sizes']['medium'] ) ) {
@danielbachhuber
danielbachhuber / easyrecipe-convert-with-post-thumbnail.php
Created Mar 6, 2019
Use the post's featured image when the EasyRecipe doesn't have an image.
View easyrecipe-convert-with-post-thumbnail.php
<?php
/**
* Use the post's featured image when the EasyRecipe doesn't have an image.
*
* @param integer $image_id Image ID to be used.
* @param object $recipe Tasty Recipe object.
* @param integer $post_id Original post ID.
*/
add_filter( 'tasty_recipes_convert_easyrecipe_image_id', function( $image_id, $recipe, $post_id ) {
if ( $image_id ) {
@danielbachhuber
danielbachhuber / tasty-pins-alt-text.php
Created Mar 1, 2019
Includes alt text on a Tasty Pins hidden image if none yet exists.
View tasty-pins-alt-text.php
<?php
/**
* Includes alt text on a Tasty Pins hidden image if none yet exists.
*
* @param string $image_content Image content HTML string.
* @param integer $hidden_image Hidden image ID.
* @return string
*/
add_filter(
'tasty_pins_hidden_image_html',
@danielbachhuber
danielbachhuber / convert-number-to-fraction.js
Created Feb 18, 2019
Convert a number to a fraction in JavaScript
View convert-number-to-fraction.js
/**
* Converts numbers to fractions:
* - 1.25 to 1 1/4
* - 2 to 2
*/
var numberToFraction = function( amount ) {
// This is a whole number and doesn't need modification.
if ( parseFloat( amount ) === parseInt( amount ) ) {
return amount;
}
@danielbachhuber
danielbachhuber / disable-thumbnail-generation.php
Created Feb 18, 2019
Prevent image thumbnails from being created during import
View disable-thumbnail-generation.php
<?php
/**
* Filtering 'intermediate_image_sizes_advanced' to return an empty array
* prior to calling media_sideload_image() will prevent thumbnails from being created.
*/
add_filter( 'intermediate_image_sizes_advanced', '__return_empty_array' );
$attachment_id = media_sideload_image( $image_url, $post_id, '', 'id' );
remove_filter( 'intermediate_image_sizes_advanced', '__return_empty_array' );
You can’t perform that action at this time.