Skip to content

Instantly share code, notes, and snippets.

Mohammad Jangda mjangda

Block or report user

Report or block mjangda

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mjangda
mjangda / cli-ms-upgrade.php
Created May 23, 2011
Command Line script to upgrade a WordPress Multisite instance
View cli-ms-upgrade.php
<?php
/**
* WordPress Multisite upgrade script
*
* IMPORTANT: While a simple safeguard has been added to the script,
* you'll want to add another layer that prevents this script from
* being called via the browser.
*
* Usage:
* 1) Place in the root of your install (or another place, but modify the wp-load.php path to match)
@mjangda
mjangda / widget-post-save.js
Created Sep 9, 2010
Hook into the WordPress widget save javascript callback
View widget-post-save.js
jQuery(document).ajaxSuccess(function(e, xhr, settings) {
var widget_id_base = 'mywidget';
if(settings.data.search('action=save-widget') != -1 && settings.data.search('id_base=' + widget_id_base) != -1) {
alert('yay!');
// do other stuff
}
});
@mjangda
mjangda / ngrok-and-jetpack.md
Last active Mar 18, 2019
How to connect ngrok to your local WordPress environment (props @DanReyLop)
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.

@mjangda
mjangda / dynamic-facebook-comments.js
Last active Jan 6, 2019
Dynamically load Facebook comments on your site (if you already have the FB API running)
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' ) );
@mjangda
mjangda / add-origin.php
Created Jun 20, 2012
Adding additional origins to the WordPress Origin API
View add-origin.php
<?php
add_filter( 'allowed_http_origins', 'my_add_origins' );
function my_add_origins( $origins ) {
$origins[] = 'http://www.example.com'; // this will add www.example.com to the list of allowed origins when send_origin_headers() is called
return $origins;
}
@mjangda
mjangda / feedkillah.php
Created Jan 8, 2010
WordPress Plugin: Feed Killah (or, How to disable all feeds on your site)
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 ];
@mjangda
mjangda / emoji-one.php
Created Nov 24, 2015
Use assets from Emoji One instead of Twitter for your WordPress site.
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 ),
@mjangda
mjangda / jsTimer-test.js
Created Feb 24, 2011
A sweet js countdown timer with a custom callback that gives you a JSON object!
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);
You can’t perform that action at this time.