Skip to content

Instantly share code, notes, and snippets.

View andrew-womeldorf's full-sized avatar

Andrew Womeldorf andrew-womeldorf

View GitHub Profile

Keybase proof

I hereby claim:

  • I am andrew-womeldorf on github.
  • I am andrewwomeldorf (https://keybase.io/andrewwomeldorf) on keybase.
  • I have a public key ASCBXGHd1NrGZILAkalLxxmcPnD8SOPaLJaas665OrmDdgo

To claim this, I am signing this object:

$string = "<span class='tooltip-trigger' data-tooltip='[{\"code\":\"XXXXXXX\",\"isTruthy\":false,\"body\":\"Blah blah blah blah, blah blah blah.\"}]'><span class='nested'>*</span></span>";
preg_match_all("/\{(?:[^{}]|(?R))*\}/", $string, $matches);
var_dump($matches);
@andrew-womeldorf
andrew-womeldorf / make_ajax_call.js
Created November 29, 2016 21:19
AJAX POST method without jQuery
/* make_ajax_call( data )
* Very very boiled down AJAX call to replace jQuery
* Can use as a starter for future needs
* data is a json object
*/
function prepareData( data ){
var encodedArray = new Array();
for( key in data ){
encodedArray.push(encodeURIComponent( key ) + "=" + encodeURIComponent( data[key] ) );
// Async & Defer on selected scripts
// This could (should, probably) be broken out into two functions, but since I want both all the time, I'm just combining them
function add_async_and_defer( $tag, $handle ){
// Add handles used in either wp_register_script or wp_enqueue_script
$scripts_to_async_and_defer = array(
'google_maps'
);
foreach( $scripts_to_async_and_defer as $async_and_defer_script ){
if( $async_and_defer_script === $handle ){
@andrew-womeldorf
andrew-womeldorf / save_parent_categories.php
Created September 26, 2016 17:05
If a child category is selected, add this post to any/all of the child category's parents
add_action('save_post', 'assign_parent_terms', 10, 2);
function assign_parent_terms( $post_id, $post ){
$terms = wp_get_post_terms($post_id, 'category' );
foreach($terms as $term){
while($term->parent != 0 && !has_term( $term->parent, 'category', $post )){
wp_set_post_terms($post_id, array($term->parent), 'category', true);
$term = get_term($term->parent, 'category');
}
}
}
@andrew-womeldorf
andrew-womeldorf / gulpfile.js
Last active September 23, 2016 14:34
Recommended to have gulp-config.js also
//░░░░░░░░░░░░░░░░░░░░░░░░
//
// DIRECTORY
//
// _Requires
// _Configuration
// _CSS
// _JS
// _BrowserSync
// _Watch
@andrew-womeldorf
andrew-womeldorf / gulp-config.js
Created September 10, 2016 15:04
To be used with gulpfile
module.exports = {
browserSync : {
proxy : '.dev',
notify : false,
port : 3000,
tunnel : null,
scrollRestoreTechnique : 'cookie'
}
}
@andrew-womeldorf
andrew-womeldorf / all_hooks.php
Last active September 14, 2016 19:55
Way to filter and display all hooks being called on a page - WP
// show_hooks_except to show all except what is in array
// show_hooks_including to search for specific hooks
// can use RegExp
add_action( 'all', 'show_hooks_between' );
// echo all hooks except those that match the regexps in the array
function show_hooks_except() {
$do_not_see = array(
'gettext',
'locale',
@andrew-womeldorf
andrew-womeldorf / local-config.php
Created September 7, 2016 22:22
My typical local-config.php
<?php
define('DB_NAME', '');
define('DB_USER', '');
define('DB_PASSWORD', '');
define('DB_HOST', '');
define('WP_HOME', 'http://.dev');
define('WP_SITEURL', 'http://.dev');
@andrew-womeldorf
andrew-womeldorf / wp-config.php
Last active September 7, 2016 22:19
My typical wp-config.php
<?php
define('AUTH_KEY', '');
define('SECURE_AUTH_KEY', '');
define('LOGGED_IN_KEY', '');
define('NONCE_KEY', '');
define('AUTH_SALT', '');
define('SECURE_AUTH_SALT', '');
define('LOGGED_IN_SALT', '');
define('NONCE_SALT', '');
$table_prefix = 'af_';