Skip to content

Instantly share code, notes, and snippets.

This is a fork of Bootstrap Typeahead that adds minimal but powerful extensions.

For example, process typeahead list asynchronously and return objects

  # This example does an AJAX lookup and is in CoffeeScript
  $('.typeahead').typeahead(
    # source can be a function
    source: (typeahead, query) ->
 # this function receives the typeahead object and the query string
@jgalea
jgalea / microtime.php
Last active December 7, 2022 01:30
Test execution time of WordPress PHP function
<?php
function my_function() {
$start = microtime(true);
// function code here
$time_taken = microtime(true) - $start;
wp_die( $time_taken ); // in seconds
}
<?php
function create_onetime_nonce( $action = -1 ) {
$time = time();
$nonce = wp_create_nonce( $time . $action );
set_transient( '_nonce_' . $time, 1, 60*60 ); // adjust the lifetime of the transient
return $nonce . '-' . $time;
}
function verify_onetime_nonce( $_nonce, $action = -1 ) {
@list( $nonce, $time ) = explode( '-', $_nonce );
@mikeschinkel
mikeschinkel / class-mysite-auth.php
Created May 30, 2013 01:00
Example class showing how to redirect to a custom login page.
class Mysite_Auth {
function __construct() {
add_filter( 'login_redirect', array( $this, 'login_redirect' ) );
}
function login_redirect( $redirect_url ) {
if ( is_user_logged_in() ) {
wp_safe_redirect( '/custom-login' );
exit;
}
<?php
$current_url = "http://" . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
if ( $current_url == 'http://example.com/example' ) {
// DO YOUR THING HERE, THEN REDIRECT
wp_redirect( 'http://example.com' ) );
exit;
}
?>
<?php
// Exit if accessed directly
if ( !defined('ABSPATH')) exit;
/**
* Pages Template
*
*
* @file page.php
$nationals = array(
'Afghan',
'Albanian',
'Algerian',
'American',
'Andorran',
'Angolan',
'Antiguans',
'Argentinean',
'Armenian',
@chrisdigital
chrisdigital / Frontend user profile in WordPress
Created May 6, 2013 13:27
Setting up a editable user profile in WordPress on the frontend.
//How to edit a user profile on the front end?
//http://wordpress.stackexchange.com/questions/9775/how-to-edit-a-user-profile-on-the-front-end
//Forcing nickname as display_name in custom edit profile template
//http://wordpress.stackexchange.com/questions/35403/forcing-nickname-as-display-name-in-custom-edit-profile-template
///////
<?php
@RalfAlbert
RalfAlbert / file_upload.php
Last active May 18, 2018 19:23
WordPress: Simple class to handle file uploads to the wp-content directory and creating an attachment post
<?php
class File_Upload
{
/**
* Index key from upload form
* @var string
*/
public $index_key = '';
/**
<?php
if ($_FILES['userfile']['size'] > 5 * 1024 * 1024) {
$error = 'File is too large.';
@unlink($_FILES['userfile']['tmp_name']) || $error .= $php_errormsg;
}