Skip to content

Instantly share code, notes, and snippets.

@mAAdhaTTah
mAAdhaTTah / admin-notice-hook.php
Created February 16, 2015 01:10
save_post Error Reporting Boilerplate
add_action( 'admin_notices', 'my_error_messages' );
@mAAdhaTTah
mAAdhaTTah / pick-randomly-from-array.php
Created February 16, 2015 01:10
Algo to pick every item from array once
$num_posts = count( $languages );
$this->gistpens = $this->factory->post->create_many( $num_posts, array(
'post_type' => 'gistpens',
), array(
'post_title' => new WP_UnitTest_Generator_Sequence( 'Post title %s' ),
'post_name' => new WP_UnitTest_Generator_Sequence( 'Post title %s' ),
'post_content' => new WP_UnitTest_Generator_Sequence( 'Post content %s' )
));
@mAAdhaTTah
mAAdhaTTah / vg-wp-post-up.sh
Created February 16, 2015 01:10
Vagrant WordPress Post-up for WP-Gistpen
sudo apt-get -y install subversion phpunit
cd /srv/www/jamesdigioia.dev/current
cd $(wp plugin path --dir wp-gistpen)
bash test/install-wp-tests.sh wordpress_test root devpw localhost latest
@mAAdhaTTah
mAAdhaTTah / register-ajax.php
Created February 16, 2015 01:11
Register Ajax Form Return
add_action( 'wp_ajax_plugin_slug_insert_dialog', 'plugin_slug_insert_gistpen_dialog' );
function plugin_slug_insert_gistpen_dialog() {
die(include 'path/to/dialog/form.php');
}
@mAAdhaTTah
mAAdhaTTah / register-tiny-mce-plugin.php
Created February 16, 2015 01:11
Register TinyMCE Plugin and Button
add_filter( 'mce_external_plugins', 'plugin_slug_add_button' );
function plugin_slug_add_button( $plugins ) {
$plugins['plugin_slug'] = 'path/to/editor/plugin.js';
return $plugins;
}
add_filter( 'mce_buttons', 'plugin_slug_register_button' );
function plugin_slug_register_button( $buttons ) {
array_push( $buttons, 'plugin_slug' );
return $buttons;
@mAAdhaTTah
mAAdhaTTah / parsecsv-image-downloading.php
Created February 16, 2015 01:11
ParseCSV Image Downloading
require("ParseCSV.php");
$csv = new ParseCSV("youtube-images.csv");
$n = 1;
foreach($csv->data as $data) {
if(false != file_put_contents("pics/{$data['filename']}.jpg", file_get_contents($data['url']))) {
$log = "File {$n}: Downloaded {$data['filename']} from {$data['url']}n";
} else {
$log = "File {$n}: Download from {$data['url']} failedn";
}
@mAAdhaTTah
mAAdhaTTah / user-agent.js
Created February 16, 2015 01:11
userAgent checking
// Source: https://github.com/pixelcog/parallax.js/blob/master/parallax.js#L96
if (navigator.userAgent.match(/(iPod|iPhone|iPad)/)) {
// if iOS
}
if (navigator.userAgent.match(/(Android)/)) {
// if Android
}
@mAAdhaTTah
mAAdhaTTah / vagrantfile
Created April 11, 2015 19:41
Mount Arbitrary Directory with bedrock-ansible
config.vm.synced_folder '../themes/sage', File.join(nfs_path(name), 'web/app/themes/sage'), type: 'nfs'
@mAAdhaTTah
mAAdhaTTah / test
Last active August 29, 2015 14:23
var http = require('http');
var _ = require('lodash');
// An HTTP server for an quick EventEmitter example. Works just like a socket.
var server = http.createServer(function(req, res) {
console.log('Reqest incoming...');
});
// This will not cause an error since partial is invoked after socket gets passed into the function.
server.on('connection', function(socket) {
@mAAdhaTTah
mAAdhaTTah / admin-notice-hook.php
Created November 19, 2015 01:23
save_post Error Reporting Boilerplate
add_action( 'admin_notices', 'my_error_messages' );