Instantly share code, notes, and snippets.

View ngrok-and-jetpack.md

How to develop with Jetpack locally with ngrok

To connect Jetpack in your local installation, you'll need a way for WP.com servers to reach your server. That can be done in a number of different ways:

  • You can open your router's ports and use your public IP
  • You can use some kind of Dynamic DNS provider.

But these options fall short of ngrok, which is a "localhost tunnel". It basically allows the Internet to hit a local port on your machine without worrying about ports or IPs.

As long as ngrok is running, Jetpack / WP.com will be able to communicate with your local site. This will allow remote modules like Site Search and Manage to work.

View dynamic-facebook-comments.js
jQuery( function( $ ) {
if ( 'undefined' === typeof FB )
return;
if ( $( 'body' ).hasClass( 'single-post' ) || $( 'body' ).hasClass( 'page' ) ) {
var $comments_div = $( '<div/>' );
$comments_div.addClass( 'fb-comments' );
$comments_div.attr( 'data-href', document.location );
$comments_div.appendTo( $( '.primary-content' ) );
View feedkillah.php
<?php
/*
Plugin Name: Feed Killah!
Plugin URI: http://digitalize.ca
Description: Kills feeds like a mo-fo!
Author: Mohammad Jangda
Version: 0.1
Author URI: http://digitalize.ca
Be nice, and use sort of GPL License, okay?
View html-map.php
<?php
add_action( 'init', function() {
$html_map = [
'howdy/world' => 'howdy',
];
$current_path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
if ( in_array( $current_path, array_keys( $html_map ), true ) ) {
$filename = $html_map[ $current_path ];
View emoji-one.php
<?php
/**
* Plugin Name: Emoji One
* Description: Use assets from Emoji One (emojione.com) when displaying emoji.
* Version: 0.1
*/
add_filter( 'emoji_url', '//cdn.jsdelivr.net/emojione/assets/png/' );
View load-wp-filesystem-vip.php
<?php
/**
* With the filters below, our override should load automatically when `WP_Filesystem()` is called.
*
* If we don't want to explicitly initialize it everywhere:
*
* $api_client = Automattic\VIP\Files\new_api_client();
* WP_Filesystem( [
* new Automattic\VIP\Files\WP_Filesystem_VIP_Uploads( $api_client ),
View jsTimer-test.js
timer('2011-12-31', function(timeRemaining) {
console.log('Timer 1:', timeRemaining);
});
// This will run every minute, instead of every second
timer('2012-12-31', function(timeRemaining) {
console.log('Timer 2:', timeRemaining);
}, 60000);
View remove-post-term.php
<?php
/**
* Remove a given term from the specified post
*
* Helper function since this functionality doesn't exist in core
*/
function my_remove_post_term( $post_id, $term, $taxonomy ) {
if ( ! is_numeric( $term ) ) {
View console-busting.js
var DEBUG_MODE = true; // Set this value to false for production
if(typeof(console) === 'undefined') {
console = {}
}
if(!DEBUG_MODE || typeof(console.log) === 'undefined') {
// FYI: Firebug might get cranky...
console.log = console.error = console.info = console.debug = console.warn = console.trace = console.dir = console.dirxml = console.group = console.groupEnd = console.time = console.timeEnd = console.assert = console.profile = function() {};
}
View wp-command-line-script.php
<?php
// Let's load WordPress
require( 'wp-load.php' );
if ( ! function_exists( 'wp' ) )
die( 'Sorry, looks like WordPress isn\'t loaded.' );
// Run the core code for our script
my_command_line_script();