Skip to content

Instantly share code, notes, and snippets.

View wp_mail_failed.php
<?php
add_action('wp_mail_failed', 'f4t_mail_error_log', 10, 1);
function f4t_mail_error_log($wp_error) {
$fn = WP_CONTENT_DIR . DS . 'mail.log'; // say you've got a mail.log file in your wp-content dir
$fp = fopen($fn, 'a');
fputs($fp, date('[Y-m-d H:i:s] ') . 'Mailer error: ' . $wp_error->get_error_message() ."\n");
fclose($fp);
}
View calc-vimeo-aspect-ratio-height.php
<?php
$vimeo_id = '7489251'
$vimeo_url = 'https://player.vimeo.com/video/' . $vimeo_id;
$oembed_url = 'https://vimeo.com/api/oembed.json?url='. urlencode($vimeo_url);
$oembed_content = @file_get_contents($oembed_url);
if($oembed_content !== false) {
$oembed = json_decode($oembed_content);
$aspect_ratio_height = 100 / $oembed->width * $oembed->height;
} else {
@haze83
haze83 / f4t_wc_email_cc_shipping.php
Last active Aug 13, 2020
Theme hooks to use with the WordPress plugin "F4 Shipping Phone and E-Mail for WooCommerce"
View f4t_wc_email_cc_shipping.php
<?
/**
* Adds shipping email address as cc to WoocCmmerce customer emails
*
* @param string $header WC_Email header
* @param string $id WC_Email id
* @param \WC_Order $object
* @return string
*
@haze83
haze83 / wc_get_logger.php
Last active Oct 8, 2020
Logging with WooCommerce 3.0
View wc_get_logger.php
<?php
$logger = wc_get_logger();
$logger_context = ['source' => 'f4t'];
$logger->debug(wc_print_r(['key' => 'value'], true), $logger_context);
@haze83
haze83 / wp-cli.sh
Last active Jul 21, 2020
some useful wordpress cli commands
View wp-cli.sh
# Create a new wp-cli.yml file in the root of your wp-installation
touch wp-cli.yml
# Open the file to edit
nano wp-cli.yml
# Enter your installation data
apache_modules: mod_rewrite
url: https://dev.domain.ch/
user: admin
@haze83
haze83 / stuff.sh
Last active Jan 9, 2020
Useful Linux bash shell commands
View stuff.sh
# find in current and subdirs by name and ls -l the searchresults
find . -name "*Searchstring*" -exec ls -l {} \;
# find a string current and subdirs (-R) and list matching filenames (-l)
grep -Rl "Searchstring" ./
# find a string current and subdirs (-R) and list matching filenames with context (-i)
grep -Ri "Searchstring" ./
# find a string current and subdirs (-R) and list matching filenames with context and line number (-n)
@haze83
haze83 / indesign-tracking-2-letter-spacing.scss
Created Feb 15, 2018
convert indesign tracking value to the css letter-spacing equivalent
View indesign-tracking-2-letter-spacing.scss
// convert indesign tracking value to css letter-spacing
@function tracking-to-letter-spacing($tracking: 0) {
@return $tracking / 1000 * 1em;
}
@mixin tracking-to-letter-spacing($tracking: 0) {
letter-spacing: tracking-to-letter-spacing($tracking);
}
View date-format.php
date_default_timezone_set('Europe/Zurich');
date("d.m.Y H:i:s");
$date = new \DateTime(strtotime(time()));
$date->setTimezone(new DateTimeZone('Europe/Zurich'));
$timestamp = $date->format('U');
$date = $date->format('d.m.Y H:i:s');