Skip to content

Instantly share code, notes, and snippets.

View dabernathy89's full-sized avatar

Daniel Abernathy dabernathy89

View GitHub Profile
@dabernathy89
dabernathy89 / vue-router-stringify-query-nested-parameters.js
Last active May 29, 2020 09:32
An implementation of the Vue Router `stringifyQuery` method which handles nested query parameters. It uses square brackets (`[]`) for query parameter arrays (regular and nested).
/*
Ex:
stringifyQuery({foo: "bar", baz: ['a','b'], fizz: {foo: [1,2,3], bar: {bees: "knees"}}});
-> ?foo=bar&baz[]=a&baz[]=b&fizz[foo][]=1&fizz[foo][]=2&fizz[foo][]=3&fizz[bar][bees]=knees
Square brackets will be URL encoded; I didn't do so in this example for readability.
*/
function stringifyQuery (obj, parentName) {
const res = obj ? Object.keys(obj).map(key => {
class SimpleEndpoint {
public function hooks() {
add_action( 'init', array( $this, 'add_endpoint' ) );
add_action( 'template_redirect', array( $this, 'handle_request' ) );
}
public function add_endpoint() {
add_rewrite_tag( '%foobar%', '([^&]+)' );
add_rewrite_rule( '^(foobar)/?$', 'index.php?$matches[1]=1', 'top' );
}
@dabernathy89
dabernathy89 / wp_custom_posts_navigation
Created March 17, 2015 16:39
WordPress custom posts navigation function
<?php
// Adapted from Underscores' posts navigation function
// Uses Bootstrap classes
// In a default query:
// custom_posts_navigation();
// In a custom query:
// custom_posts_navigation($my_custom_query);
{"scrollwheel":false,"styles":[{"featureType":"landscape","stylers":[{"saturation":-100},{"lightness":65},{"visibility":"on"}]},{"featureType":"poi","stylers":[{"saturation":-100},{"lightness":51},{"visibility":"simplified"}]},{"featureType":"road.highway","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"road.arterial","stylers":[{"saturation":-100},{"lightness":30},{"visibility":"on"}]},{"featureType":"road.local","stylers":[{"saturation":-100},{"lightness":40},{"visibility":"on"}]},{"featureType":"transit","stylers":[{"saturation":-100},{"visibility":"simplified"}]},{"featureType":"administrative.province","stylers":[{"visibility":"off"}]},{"featureType":"water","elementType":"labels","stylers":[{"visibility":"on"},{"lightness":-25},{"saturation":-100}]},{"featureType":"water","elementType":"geometry","stylers":[{"hue":"#ffff00"},{"lightness":-25},{"saturation":-97}]}]}
<?php
/*
Plugin Name: Gravity Forms Queue Listener
*/
class GravityFormsQueueListener {
function __construct() {
add_action('wp_loaded', array($this,'process_push_queue_msg'), 10 );
add_action('gform_after_submission', array( $this, 'send_to_ironio'), 10, 2);
@dabernathy89
dabernathy89 / gf_button_addclass.php
Last active December 23, 2015 07:19
Add class(es) to Gravity Forms buttons
add_filter("gform_submit_button", "alter_form_submit_button", 10, 2);
function alter_form_submit_button($button, $form){
if ($form["button"]["type"] == "text") {
// (class=) followed by (single or double quote) followed by (anything that is not a single or double quote)
$pattern = '/(class=)(\'|")([^\'"]+)/';
$replacement = '${1}${2}${3} btn';
$newbutton = preg_replace($pattern, $replacement, $button);
if ( !is_null($newbutton) ) {
return $newbutton;
}
@dabernathy89
dabernathy89 / gravity-forms-field-groups.php
Created March 13, 2013 19:55
Insert this script into functions.php in your WordPress theme (be cognizant of the opening and closing php tags) to allow field groups in Gravity Forms. The script will create two new field types - Open Group and Close Group. Add classes to your Open Group fields to style your groups. Note that there is a stray (but empty) <li> element created. …
<?php
/*
Insert this script into functions.php in your WordPress theme (be cognizant of the opening and closing php tags) to allow field groups in Gravity Forms. The script will create two new field types - Open Group and Close Group. Add classes to your Open Group fields to style your groups.
Note that there is a stray (but empty) <li> element created. It is given the class "fieldgroup_extra_li" so that you can hide it in your CSS if needed.
*/
add_filter("gform_add_field_buttons", "add_fieldgroup_fields");
function add_fieldgroup_fields($field_groups){
foreach($field_groups as &$group){