Skip to content

Instantly share code, notes, and snippets.

View Irfan-Ansari's full-sized avatar

Irfan Ansari Irfan-Ansari

View GitHub Profile
var app = app || {};
//object literal
app = {
init: function(){
this.cache();
this.bind();
},
cache: function(){
this.anchor = $( 'a' );
<?php
/**
* Merge multiple WP_Error objects together
*
* @return WP_Error
*/
function wp_error_merge() {
$wp_error_merged = new WP_Error();
$wp_errors = func_get_args();
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' ) );
<?php $query = new WP_Query( array( 'posts_per_page' => 100, 'fields' => 'ids' ) ); ?>
<?php if ( $query->have_posts() ) :
$post_ids = $query->posts;
shuffle( $post_ids );
$post_ids = array_splice( $post_ids, 0, 12 );
foreach ( $post_ids as $post_id ) :
$post = get_post( $post_id );
setup_postdata( $post );
?>
add_filter( 'pre_post_link', 'make__permalink', 10, 2 );
function make_new_permalink( $permalink, $post ) {
if ( 'page' == $post->post_type && in_array( $post->page_name, array( 'home-page', 'home-page-include' ) ) ) {
$permalink = 'http://makezine.com';
}
return $permalink;
}
<?php
function dump_rewrite_rules() {
$tmp_file = '/tmp/rewrite_rule_dump.txt'; // define filename here if needed
if ( !touch( $tmp_file ) || !is_writeable( $tmp_file ) ) {
error_log( 'dump_rewrite_rules: The file ' . $tmp_file . ' is not writable. Please check the permissions.' );
return;
}
global $wp_rewrite;
$rules = var_export( $wp_rewrite, true );
<?php
/**
* Generates a domain-mapping safe URL on WordPress.com
* Core's ajaxurl uses admin_url() which returns *.wordpress.com which doesn't work for the front-end on domain-mapped sites.
* This works around that and generates the correct URL based on context.
*/
function my_admin_ajax_url( $path = '' ) {
if ( is_admin() )
$url = admin_url( 'admin-ajax.php' );
else
<?php
function debug_get_functions_for_hook( $hook ) {
global $wp_filter;
if( ! isset( $wp_filter[$hook] ) )
return;
$functions = array();
foreach( (array) $wp_filter[$hook] as $key => $actions ) {
//$functions = array_merge( $functions, $actions );
<?php
/**
* Saves post meta value
*
* @param int ID of the post
* @param string Name of the post_meta key (same as the $_POST key and nonce name)
* @param string Name of the nonce key
* @param mixed The default value to be assigned if not set
*
* @return string Value that was saved