Skip to content

Instantly share code, notes, and snippets.

View dsturm's full-sized avatar

Daniel Sturm dsturm

View GitHub Profile
@dsturm
dsturm / functions.php
Created March 10, 2023 10:09 — forked from tripflex/functions.php
Programmatically create a WooCommerce Subscription and associated WooCommerce Order
<?php
public function give_user_subscription( $product, $user_id, $note = '' ){
// First make sure all required functions and classes exist
if( ! function_exists( 'wc_create_order' ) || ! function_exists( 'wcs_create_subscription' ) || ! class_exists( 'WC_Subscriptions_Product' ) ){
return false;
}
$order = wc_create_order( array( 'customer_id' => $user_id ) );
@dsturm
dsturm / DKIM_SPF_Sendmail
Created March 11, 2019 08:59 — forked from artmouse/DKIM_SPF_Sendmail
DKIM + SPF + Sendmail for multiple domains (Ubuntu)
DKIM is DomainKeys Identified Mail and is used in mail servers, such as Postfix or Sendmail to sign e-mails and thus authenticating the sender so that a forgery can be detected. It also reduces the possibility of an e-mail being flagged as spam, but it's not a definite prevention.
A much simpler method is using SPF (Sender Policy Framework) which, in a nutshell, verifies the sender IP address.
According to the internet, using both should result to ????, PROFIT !!!.
SPF does not need a specific configuration. Whitelisted servers are listed in a DNS record, TXT or SPF, and an example record is:
example.com. IN TXT "v=spf1 a mx ~all"
@dsturm
dsturm / target_blank.js
Last active October 26, 2017 15:15 — forked from allybee/target_blank.js
Add target="_blank" to external links with pure JavaScript.
function targetBlank() {
// remove subdomain of current site's url and setup regex
var internal = location.host.replace(/^[^.]+\./g, '');
internal = new RegExp(internal, "i");
var a = document.getElementsByTagName('a'); // then, grab every link on the page
for (var i = 0; i < a.length; i++) {
var href = a[i].host; // set the host of each link
if (!internal.test(href)) {
// make sure the href doesn't contain current site's host
@dsturm
dsturm / _leastSquaresFit.scss
Created April 28, 2017 08:21 — forked from Jakobud/_leastSquaresFit.scss
Least Squares Fit Linear Regression SASS function
/// leastSquaresFit
/// Calculate the least square fit linear regression of provided values
/// @param {map} $map - A SASS map of viewport width and size value combinations
/// @return Linear equation as a calc() function
/// @example
/// font-size: leastSquaresFit((576: 24, 768: 24, 992: 34));
/// @author Jake Wilson <jake.e.wilson@gmail.com>
@function leastSquaresFit($map) {
// Get the number of provided breakpoints
@dsturm
dsturm / fix-wordpress-permissions.sh
Last active July 29, 2023 06:29 — forked from Adirael/fix-wordpress-permissions.sh
Fix wordpress file permissions (for bedrock)
#!/bin/bash
#
# This script configures WordPress file permissions based on recommendations
# from http://codex.wordpress.org/Hardening_WordPress#File_permissions
#
# Author: Michael Conigliaro <mike [at] conigliaro [dot] org>
#
WP_ROOT=$1 # <-- wordpress root directory
WP_OWNER=www-data # <-- wordpress owner
WP_GROUP=www-data # <-- wordpress group
@dsturm
dsturm / gist:361094442b1f181e420f
Created March 4, 2016 12:53 — forked from fjarrett/gist:5544469
Return an attachment ID using a URL in WordPress
<?php
/**
* Return an ID of an attachment by searching the database with the file URL.
*
* First checks to see if the $url is pointing to a file that exists in
* the wp-content directory. If so, then we search the database for a
* partial match consisting of the remaining path AFTER the wp-content
* directory. Finally, if a match is found the attachment ID will be
* returned.
*
@dsturm
dsturm / _cursor-mixins.scss
Created November 14, 2015 21:10 — forked from laurendorman/_cursor-mixins.scss
Sass mixins + classes for cursors – For use with online photo editors, drag/drop tools, text editors and WYSIWYGs.
// Used to @include a cursor within a pre-existing class
@mixin cursor($cursor-type) {
cursor: $cursor-type;
}
// Used to generate cursor classes
@mixin cursor-class($cursor-type) {
.#{$cursor-type}-cursor { cursor: $cursor-type; }
}
@dsturm
dsturm / gist:71876b7be343d9e77bf8
Created November 9, 2015 15:08
Advanced Custom Fields PRO for Composer
{
"repositories": [
{
"type": "package",
"package": {
"name": "advanced-custom-fields/advanced-custom-fields-pro",
"version": "5.0",
"type": "wordpress-plugin",
"dist": {
"type": "zip",
@dsturm
dsturm / adminMaps.js
Created October 6, 2015 08:35 — forked from darylldoyle/adminMaps.js
Set zoom level for Advanced Custom Fields map field.
var googleMapsLoaded = false;
var timeout;
if(googleMapsLoaded === false) {
timeout = setInterval("checkVariable()", 500);
}
function doGoogleMapsHook() {
// set current zoom level
var currentZoom = parseInt(jQuery('#acf-field-zoom_level').val());
// ==UserScript==
// @name anti key-grabber
// @version 1
// ==/UserScript==
document.addEventListener('keydown', function(e) {
// only if Command key is pressed
if (!e.metaKey) {
return;
}