Skip to content

Instantly share code, notes, and snippets.

@aaroneaton
aaroneaton / fuse-init.js
Last active August 29, 2015 14:22
Real-time support documentation search
var docs = om_docs.docs; // Loaded via wp_localize_script()
/*
Sample docs array
[
{
title: 'A post title',
url: 'http://optinmonster.com/docs/a-post-title'
}
]
@aaroneaton
aaroneaton / collection.php
Created March 17, 2015 03:14
Conditional unserialize
<?php
// Instead of blindly returning $collection...
if ( $collection instanceof \Serializable ) {
// We know this would be a new collection
return $collection;
} else {
// This is a transient from the database so
// we need to use the native PHP unserialize function.
return unserialize( $collection );
}
@aaroneaton
aaroneaton / is_serialized.php
Created March 17, 2015 02:46
is_serialized
<?php
/**
* Check value to find if it was serialized.
*
* If $data is not an string, then returned value will always be false.
* Serialized data is always a string.
*
* @since 2.0.5
*
* @param string $data Value to check to see if was serialized.
@aaroneaton
aaroneaton / collection.php
Last active August 29, 2015 14:17
Storing ArrayObject as WordPress transient
<?php
/** ..... */
public function all() {
if ( false === ( $collection = get_transient( '_optin_cache_' . $this->user->ID . '_all' ) ) ) {
$optins = get_posts(
array(
'post_type' => 'optin_saas',
'author' => $this->user->ID,
'no_found_rows' => true,
'cache_results' => false,
@aaroneaton
aaroneaton / tasks.js
Last active August 29, 2015 14:16
tasks
grunt.registerTask('default', 'An empty task', function() {
grunt.log.error('This is an empty task to keep bad things from happening.');
return false;
});
grunt.registerTask('package', ['mkdir', 'compress', 'rename', 'aws_s3:myBucket']);
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
mkdir: {
all: {
options: {
create: ['dist']
}
}
},
compress: {
main: {
options: {
archive: 'my-cool-plugin.zip'
},
expand: true,
src: [
'assets/*',
'includes/*',
'my-cool-plugin.php'
@aaroneaton
aaroneaton / aws.js
Last active August 29, 2015 14:16
aws
aws_s3: {
options: {
accessKeyId: '1234', // Use your own access key
secretAccessKey: 'abcd', // Use your own secret access key
region: 'US1', // Fill in your S3 region
uploadConcurrency: 5, // 5 simultaneous uploads
downloadConcurrency: 5, // 5 simultaneous downloads
params: {
CacheControl: '2592000'
}
@aaroneaton
aaroneaton / Gruntfile.js
Last active August 29, 2015 14:16
Full gruntfile
module.exports = function (grunt) {
require('load-grunt-tasks')(grunt);
grunt.initConfig({
mkdir: {
all: {
options: {
create: ['dist']
}
}
},