Skip to content

Instantly share code, notes, and snippets.

View psorensen's full-sized avatar

Peter Sorensen psorensen

  • 10up
  • United States
View GitHub Profile
@psorensen
psorensen / edd_create_subscription.php
Last active January 24, 2017 19:02
create EDD subscription for user email
<?php
private function om_add_nfg_subscription( $args ) {
// check if user already exists
$user = get_user_by('email', $args['email']);
$user_id = $user ? $user->data->ID : null;
// register new user if doesn't exist
if (! $user_id )
Worker information
hostname: i-0388d96-precise-production-2-worker-org-docker.travisci.net:d28a5fd8-3589-4295-975d-59cd61e40876
version: v2.5.0 https://github.com/travis-ci/worker/tree/da3a43228dffc0fcca5a46569ca786b22991979f
instance: e0656f8:travis:php
startup: 518.8849ms
system_info
Build system information
Build language: php
Build group: stable
Build dist: precise
@psorensen
psorensen / Webpack Error:
Last active April 25, 2017 07:49
Webpack error on yarn run build:production
Hash: 9f3e91dd416ab52900c4 i Version: webpack 2.1.0-beta.26
Time: 6262ms
[13] multi customizer 40 bytes {1} [built]
[14] multi main 52 bytes {0} [built]
+ 13 hidden modules
ERROR in ./styles/main.scss
Module build failed: Error
at /Applications/MAMP/htdocs/openminds/wp-content/themes/hoang/node_modules/webpack/lib/NormalModule.js:143:35
at /Applications/MAMP/htdocs/openminds/wp-content/themes/hoang/node_modules/loader-runner/lib/LoaderRunner.js:359:11
@psorensen
psorensen / term-created-event.js
Created July 24, 2017 01:53
Wordpress: Fire event when term is created.
$( document ).ajaxComplete( function( event, xhr, settings ) {
try {
var queryStringArray = settings.data.split('&');
} catch(e) {
var queryStringArray = {};
}
// only when
if ( $.inArray( 'action=add-tag', queryStringArray ) !== -1 ) {
const $xml = $( xhr.responseXML );
@psorensen
psorensen / delete_uncategorized.bash
Created December 6, 2017 21:05
Bash script to remove 'uncategorized' term from posts with existing category terms
#!/bin/bash
for post in $(wp post list --field=ID --url={url} )
do
count=$(wp post term list $post 'category' --fields='name' --format="count" --url={url} )
if [ "$count" -gt "1" ]
then
wp post term remove $post category 'uncategorized' --url={url}
fi
done
@psorensen
psorensen / common.js
Last active February 15, 2018 14:06
Sage 9 Alpha main.js
export default {
init() {
jQuery(document).ready(() => $('.slick').slick());
},
finalize() {
// JavaScript to be fired on all pages, after page specific JS is fired
},
};
<?php
/**
* Functionality for modifying and outputting breadcrumbs provided by Yoast.
*
* @package IPM
*/
namespace IPM\Breadcrumbs;
/**
@psorensen
psorensen / Yoast_SEO_JS_fix
Created February 13, 2015 14:36
Yoast SEO JS Fix
function yst_clean(a){if(""==a||void 0==a)return"";try{a=jQuery("<div/>").html(a).text(),a=a.replace(/<\/?[^>]+>/gi,""),a=a.replace(/\[(.+?)\](.+?\[\/\\1\])?/g,"")}catch(b){}return a}function ptest(a,b){a=yst_clean(a),a=a.toLowerCase();var c=a.match(b);return null!=c?'<span class="good">Yes ('+c.length+")</span>":'<span class="wrong">No</span>'}function removeLowerCaseDiacritics(a){var b,c=[{base:"a",letters:/[\u0061\u24D0\uFF41\u1E9A\u00E0\u00E1\u00E2\u1EA7\u1EA5\u1EAB\u1EA9\u00E3\u0101\u0103\u1EB1\u1EAF\u1EB5\u1EB3\u0227\u01E1\u00E4\u01DF\u1EA3\u00E5\u01FB\u01CE\u0201\u0203\u1EA1\u1EAD\u1EB7\u1E01\u0105\u2C65\u0250]/g},{base:"aa",letters:/[\uA733]/g},{base:"ae",letters:/[\u00E6\u01FD\u01E3]/g},{base:"ao",letters:/[\uA735]/g},{base:"au",letters:/[\uA737]/g},{base:"av",letters:/[\uA739\uA73B]/g},{base:"ay",letters:/[\uA73D]/g},{base:"b",letters:/[\u0062\u24D1\uFF42\u1E03\u1E05\u1E07\u0180\u0183\u0253]/g},{base:"c",letters:/[\u0063\u24D2\uFF43\u0107\u0109\u010B\u010D\u00E7\u1E09\u0188\u023C\uA73F\u2184]/g},{ba
add_action('pmxi_attachment_uploaded', 'my_attachment_uploaded', 10, 3);
function my_attachment_uploaded($pid, $attid, $filepath){
$attachment = get_post($attid);
// do something with $attachment file
if (get_post($pid) == 'industry-resource') {
wp_update_post(array('ID' => $attid, 'guid' => str_replace('uploads/', 'uploads/indres/', $filepath)));
}
}
@psorensen
psorensen / paginated-query.php
Created September 17, 2018 03:12
WP Paginated Query
<?php
use WP_CLI;
/**
* Paginated Query that performs callback for each iteration.
*
* @param string $callback Name of the callback function.
* @param array $args WP_Query arguments.
* @param string $message Message passed to WP CLI make_progress_bar.