Skip to content

Instantly share code, notes, and snippets.

View mjangda's full-sized avatar

Mohammad Jangda mjangda

View GitHub Profile
@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;
<?php
<?php
namespace Automattic\VIP\Files\Acl;
use WP_Error;
class VIP_Files_Acl_Unpublished_Files_Test extends \WP_UnitTestCase {
const TEST_IMAGE_PATH = VIP_GO_MUPLUGINS_TESTS__DIR__ . '/fixtures/image.jpg';
@mjangda
mjangda / beta.php
Last active November 17, 2020 02:47
Client-side, randomized, percentage-based segmentation using the WordPress Cache Segmentation API. Only supports 1 experiment and 1 control group.
<?php
require_once( WPMU_PLUGIN_DIR . '/cache/class-vary-cache.php' );
use Automattic\VIP\Cache\Vary_Cache;
Vary_Cache::register_group( 'beta' );
add_action( 'wp_head', function() {
// TODO: if possible, load this directly very early in the header.php (instead of wp_head)
@mjangda
mjangda / remove-post-term.php
Created December 21, 2011 15:11
Remove a given term from the specified post. This function is missing from core WordPress.
<?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 ) ) {
@mjangda
mjangda / autosaver.js
Created March 3, 2010 05:42
How to hook into and pass your plugin data though WordPress Autosave
// Must be in an external file or loaded at the end of wp_footer()
jQuery(document).ajaxSend(function(e, x, a) {
var awesome = 1;
a.data += '&' + jQuery.param( {is_awesome: awesome} );
});
@mjangda
mjangda / cli-ms-upgrade.php
Created May 23, 2011 15:04
Command Line script to upgrade a WordPress Multisite instance
<?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 / dynamic-facebook-comments.js
Last active January 6, 2019 10:40
Dynamically load Facebook comments on your site (if you already have the FB API running)
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 June 20, 2012 09:17
Adding additional origins to the WordPress Origin API
<?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 January 8, 2010 05:21
WordPress Plugin: Feed Killah (or, How to disable all feeds on your site)
<?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?
<?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 ];