Skip to content

Instantly share code, notes, and snippets.

@dougalcampbell
dougalcampbell / toType.js
Created December 10, 2013 21:33
Really get an object's type in JavaScript
function toType(obj) {
var systype = ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1];
if (systype === "Object") {
/**
* See if this is a custom user type, a la:
* function Foo() {}
* foo = new Foo();
* toType(foo); // returns "Foo"
* toType(Foo); // returns "Function"
*/
@svenl77
svenl77 / menue order of groups and profiles
Created May 13, 2011 07:57
Add this functions in your functions.php in your template directory, to adjust the menue order of groups and profiles
// Change the Profile nav tab order
function change_profile_tab_order() {
global $bp;
$order = ''; // Add the component slugs coma separated in the order you like to have the nav menu tabs
$order = str_replace(' ','',$order);
$order = explode(",", $order);
$i = 1;
foreach($order as $item) {
# For SCSS-Lint v0.31.0
linters:
BangFormat:
enabled: true
space_before_bang: true
space_after_bang: false
BorderZero:
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Stripe Getting Started Form</title>
<!-- The required Stripe lib -->
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<!-- jQuery is used only for this example; it isn't required to use Stripe -->
@charliepark
charliepark / hatchshow.js
Created July 30, 2011 16:07
A jquery typography plugin.
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" charset="utf-8">
$(window).load(function(){
$().hatchShow();
});
jQuery.fn.hatchShow = function(){
$('.hsjs').css('display','inner-block').css('white-space','pre').each(function(){
var t = $(this);
t.wrap("<span class='hatchshow_temp' style='display:block'>");
var pw = t.parent().width();
@tomazzaman
tomazzaman / codeable.io.conf
Created February 26, 2015 21:38
Codeable.io Nginx config
server {
include /home/webmaster/www/codeable.io.conf;
server_name codeable.io;
listen 443 ssl spdy default_server;
root /home/webmaster/www/codeable.io;
index index.php index.html;
error_log /var/log/nginx/codeable.io.error.log warn;
@wkw
wkw / gravity-form.php
Last active November 16, 2020 02:23 — forked from OutThisLife/gravity-form.php
Custom: Gravity Forms WP API Submission and GF API form entry creation plus send notifications
<?php
/**
* Add WP API endpoint for form submission, then create new
* Gravity Forms entry and send notifications.
*/
// rest api endpoint for forms submission
add_action( 'rest_api_init', function () {
register_rest_route( 'ahr/v1', '/forms', array(
'methods' => 'POST',
@jtsternberg
jtsternberg / ajax-endpoint.js
Last active February 1, 2021 06:00
Proof of concept for avoiding admin-ajax for ajax callback requests. Also see Thomas Griffin's excellent post: https://thomasgriffin.io/a-creative-approach-to-efficient-and-scalable-wordpress-api-endpoints/ AND Josh Pollock's excellent post: http://torquemag.io/improved-wordpress-front-end-ajax-processing/
jQuery(document).ready(function($){
$('body').on( 'click', '.some-button', function(){
$.ajax( ajax_endpoint_data.api_url, {
type : 'POST',
dataType : 'json',
data : {
action: 'ajax_action',
some_data: 'some_value'
}
@petenelson
petenelson / multiformat-wp-api-response.php
Last active February 26, 2021 21:49
WordPress: Example of returning non-JSON results from the WP-API
<?php
// reference https://github.com/WP-API/WP-API/blob/develop/lib/infrastructure/class-wp-rest-server.php
// serve_request() function
add_filter( 'rest_pre_serve_request', 'multiformat_rest_pre_serve_request', 10, 4 );
function multiformat_rest_pre_serve_request( $served, $result, $request, $server ) {
// assumes 'format' was passed into the intial API route
// example: https://baconipsum.com/wp-json/baconipsum/test-response?format=text
@trepmal
trepmal / gist:1c66dbe97e8f322bc107
Created December 19, 2014 22:42
wp-cli: reset all user passwords
#!/bin/bash
for uid in $(wp user list --field=ID)
do
pass=`< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-32}`
wp user update $uid --user_pass="$pass"
done