Skip to content

Instantly share code, notes, and snippets.

View mjangda's full-sized avatar

Mohammad Jangda mjangda

View GitHub Profile
diff --git a/tools/checkstyle.sh b/tools/checkstyle.sh
index 8f536e2..e206727 100755
--- a/tools/checkstyle.sh
+++ b/tools/checkstyle.sh
@@ -1,7 +1,7 @@
#!/bin/sh
-if [ x"$1" == x ]; then
+if [ -z "$1" ]; then
checkstyle -c cq-configs/checkstyle/checkstyle.xml -r src/
@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 / data-attributes.php
Created June 20, 2013 21:30
Update kses and TinyMCE to allow select data-* attributes in WordPress
<?php
add_action( 'after_setup_theme', 'x_kses_allow_data_attributes_on_links' );
function x_kses_allow_data_attributes_on_links() {
global $allowedposttags;
$tags = array( 'a' );
$new_attributes = array(
'data-foo' => array(),
'data-bar' => array(),
@mjangda
mjangda / x_maybe_load_ad_busters.php
Created June 13, 2013 05:01
Load ad-busters from the theme if the REQUEST_URI matches one of the whitelisted requests.
<?php
add_action( 'init', 'x_maybe_load_ad_busters' );
function x_maybe_load_ad_busters() {
$ad_busters = array(
'/adcentric/ifr_b.html',
'/atlas/atlas_rm.htm',
'/doubleclick/DARTIframe.html',
'/eyereturn/eyereturn.html',
@mjangda
mjangda / zoninator-cpt-support.php
Created April 25, 2013 04:16
Adding custom post types to be support in Zone Manager zones
<?php
add_action( 'zoninator_pre_init', function() {
add_post_type_support( 'book', 'zoninator_zones' );
} );
@mjangda
mjangda / liveblog-feed.php
Created March 5, 2013 18:12
Add Liveblog entries to the feed
<?php
/**
* Output Liveblog entries as part of feed content
**/
if ( class_exists( 'WPCOM_Liveblog' ) )
add_filter( 'the_content_feed', 'x_add_liveblog_entries_to_feed_content' );
function x_add_liveblog_entries_to_feed_content( $content ) {
if ( WPCOM_Liveblog::is_liveblog_post() ) {
@mjangda
mjangda / sanitize-as-html.php
Last active December 14, 2015 08:19
Sanitize callback that treats data as HTML.
<?php
function x_custom_metadata_sanitize_as_html( $field_slug, $field, $object_type, $object_id, $value ) {
if ( is_array( $value ) )
$value = array_map( 'wp_filter_post_kses', $value );
else
$value = wp_filter_post_kses( $value );
return $value;
}
@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 / cms_modify_default_delete_term_caps.php
Created January 16, 2013 06:14
Allow limiting deletion of terms.
<?php
add_action( 'registered_taxonomy', 'cms_modify_default_delete_term_caps', 10, 3 );
function cms_modify_default_delete_term_caps( $taxonomy, $object_type, $args ) {
global $wp_taxonomies;
if ( 'category' == $taxonomy ) {
$wp_taxonomies[ $taxonomy ]->cap->delete_terms = 'cms-delete-terms';
}
}
<!--[if lte IE 9]>
<script src="<?php echo get_template_directory_uri(); ?>js/respond/respond.min.js"></script>
<link href="<?php echo get_template_directory_uri(); ?>/js/respond/respond-proxy.html" id="respond-proxy" rel="respond-proxy" />
<?php // need to load the following proxy files from the mapped domain for cross-domain handling ?>
<link href="<?php echo wpcom_vip_noncdn_uri( dirname( __FILE__ ) ); ?>/js/respond/respond.proxy.gif" id="respond-redirect" rel="respond-redirect" />
<script src="<?php echo wpcom_vip_noncdn_uri( dirname( __FILE__ ) ); ?>/js/respond/respond.proxy.js"></script>
<![endif]-->