Skip to content

Instantly share code, notes, and snippets.

View mjangda's full-sized avatar

Mohammad Jangda mjangda

View GitHub Profile
@mjangda
mjangda / wpcom-open-graph.php
Created September 5, 2011 22:30
Add Open Graph tags to your WordPress site
<?php
/**
* Open Graph Tags
*
* Add Open Graph tags so that Facebook (and any other service that supports them)
* can crawl the site better and we provide a better sharing experience.
*
* @link http://ogp.me/
* @link http://developers.facebook.com/docs/opengraph/
*/
@mjangda
mjangda / sync-svn-folders.sh
Created December 30, 2011 16:35
Sync files between two SVN folders
#!/bin/bash
# Script Name: Sync SVN folders
# Description: Use this script to sync changes from one SVN folder to another. A common use is syncing between prod and preprod repos.
# Tags: svn, sync
# Usage: ./sync-svn-folders.sh /path/to/from-repo /path/to/to-repo
FROM_REPO=$1
TO_REPO=$2
# Check that we don't have empty paths
@mjangda
mjangda / widget-post-save.js
Created September 9, 2010 20:21
Hook into the WordPress widget save javascript callback
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 / emoji-one.php
Created November 24, 2015 17:36
Use assets from Emoji One instead of Twitter for your WordPress site.
<?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/' );
@mjangda
mjangda / better-author-urls.php
Created May 28, 2012 21:14
Better author URLs for WordPress. This enables author URLs like /author/firstname-lastname/ or /author/display_name/ instead of the usual /author/user_login/ but comes at a performance cost.
<?php
/**
* Handle author request to change query string as username
*
* This enables author URLs like /author/firstname-lastname/ or /author/display_name/ instead of the usual /author/user_login/
*/
function tc_handle_author_request( $query_vars ) {
if ( ! empty( $query_vars['author_name'] ) ) {
@mjangda
mjangda / ngrok-and-jetpack.md
Last active February 7, 2023 07:57
How to connect ngrok to your local WordPress environment (props @DanReyLop)

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 / wp-command-line-script.php
Created November 2, 2011 22:12
Simple generic command line script for WordPress
<?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();
@mjangda
mjangda / allow-ids.php
Last active January 21, 2022 02:27
Don't let kses strip out ids from section tags
<?php
function x_allow_ids_on_tags() {
global $allowedposttags;
$tags = array( 'section', 'article' );
$new_attributes = array( 'id' => array() );
foreach ( $tags as $tag ) {
if ( isset( $allowedposttags[ $tag ] ) && is_array( $allowedposttags[ $tag ] ) )
$allowedposttags[ $tag ] = array_merge( $allowedposttags[ $tag ], $new_attributes );
@mjangda
mjangda / wp-error-merge.php
Created June 26, 2013 20:49
Merge multiple WP_Error objects together.
<?php
function wpcom_wp_error_merge() {
$wp_error_merged = new WP_Error();
$wp_errors = func_get_args();
foreach ( $wp_errors as $wp_error ) {
if ( ! is_wp_error( $wp_error ) )
continue;
foreach ( $wp_error as $key => $errors ) {
@mjangda
mjangda / domain-whitelist-check.php
Created January 17, 2012 00:27
Checks if a given url matches a domain whitelist
<?php
function my_is_valid_domain( $url ) {
$whitelisted_domains = array( 'mydomain.com', 'mydomain.net' );
$domain = parse_url( $url, PHP_URL_HOST );
// Check if we match the domain exactly
if ( in_array( $domain, $whitelisted_domains ) )
return true;
$valid = false;