Skip to content

Instantly share code, notes, and snippets.

View ckchaudhary's full-sized avatar

Chandan Chaudhary ckchaudhary

View GitHub Profile
@ckchaudhary
ckchaudhary / 0_reuse_code.js
Created December 21, 2016 04:30
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
<?php
add_filter( 'bp_activity_set_just-me_scope_args', 'bboss_remove_activity_comments_override', 11, 2 );
function bboss_remove_activity_comments_override( $retval = array(), $filter = array() ){
//this happens only only on user profiles,
//so ideally this if condition should not be commented out.
//But in this particular case, apparantely, this is happening on site-wide activity stream too,
//so this if contidiont should be commented out
//if( bp_displayed_user_id() ){
$retval['override']['display_comments'] = 'threaded';
//}
@ckchaudhary
ckchaudhary / gist:f0f9011d2b30665c1892
Created October 20, 2015 10:46
php merge and override arrays recursively
<?php
/**
* Merge given arrays, overriding $defaults array with values from $args array recursively.
*
* @author ckchaudahry
*
* @param $args array
* @param $defaults array
*
* @return array
@ckchaudhary
ckchaudhary / gist:4a930f90a92d21349957
Created July 8, 2015 11:00
og description for buddypress groups and activities
<?php
add_action( 'wp_head', 'dtk_buddypress_og_data', 11 );
function dtk_buddypress_og_data(){
if( bp_is_single_activity() ){
if ( bp_has_activities( 'display_comments=threaded&show_hidden=true&include=' . bp_current_action() ) ){
while ( bp_activities() ){
bp_the_activity();
$title = wp_strip_all_tags( bp_get_activity_action() );
$content = wp_strip_all_tags( bp_get_activity_content_body() );
$url = bp_activity_get_permalink( bp_get_activity_id() );
@ckchaudhary
ckchaudhary / gist:751e32c10aca4c88e16c
Created July 3, 2015 08:23
Geo my wp - member locator - include other members
add_filter( 'gmw_fl_after_query_clauses', 'wdw_gmw_fl_qc_alter', 11, 2 );
/**
* Geo my wp - member locator addon.
* By default the plugin excludes all the users who have not provided their location info yet.
* This is bad. If i am not searching by location, but searching only by xprofile fields,
* the plugin still excludes users who have not entered their location info yet.
*
* This is a dirty hack to attemtp to fix that.
*
* @author ckchaudhary <ckchaudhary@hotmail.com>
@ckchaudhary
ckchaudhary / subsite-lostpassword
Created February 8, 2015 19:44
WordPress multisite forgot password url fix
<?php
/*
Plugin Name: Subsite Lostpassword
Plugin URI: http://webdeveloperswall.com/wordpress/multisite-forgot-password-url-issue/
Description: Updates URLs on susbites and in lost password request emails to point to the subsite where the lost password request started.
Version: 1.0
Author: ckchaudhary
Author URI: http://webdeveloperswall.com/wordpress/multisite-forgot-password-url-issue/
*/
<?php
/**
* http://webdeveloperswall.com/php/get-youtube-video-id-from-url
**/
function extractUTubeVidId($url){
/*
* type1: http://www.youtube.com/watch?v=9Jr6OtgiOIw
* type2: http://www.youtube.com/watch?v=9Jr6OtgiOIw&feature=related
* type3: http://youtu.be/9Jr6OtgiOIw
*/
<?php
/**
* http://webdeveloperswall.com/php/generate-youtube-embed-code-from-url
**/
function youtubeEmbedFromUrl($youtube_url, $width, $height){
$vid_id = extractUTubeVidId($youtube_url);
return generateYoutubeEmbedCode($vid_id, $width, $height);
}
function extractUTubeVidId($url){
<?php
/**
* wdw_crop_img (http://webdeveloperswall.com/wordpress/crop-image-script)
* crops the image to given width and height
* Parameters :-
* $image_url : string : absolute url to the image
* $width: int : desired width after cropping
* $height : desired height after cropping
* $upload_directory : name of the target directory (directoty inside wp-content>uploads folder)
* Returns :- an array containing errors/success messages, new(cropped) file path and cropped file url
/**
* automatically load activities when user scrolls down - like facebook
* @author: @webdwall - http://webdeveloperswall.com/buddypress/load-more-activites-on-scroll
**/
jQuery(window).load(function(){
/*
* 1. bind event on page scroll
* 2. check if user has reched near to the bottom of activity stream( ScrollTop and pageheight etc..)
* 3. load the new content
* 4. update the pageheight etc..