Skip to content

Instantly share code, notes, and snippets.

View ckchaudhary's full-sized avatar

Chandan Chaudhary ckchaudhary

View GitHub Profile
<?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
add_filter( 'bp_core_fetch_avatar', 'revert_to_default_wp_avatar', 80, 3 );//late load
function revert_to_default_wp_avatar( $img, $params, $item_id ){
//we are concerned only with users
if( $params['object']!='user' )
return $img;
//check if user has uploaded an avatar
//if not then revert back to wordpress core get_avatar method
//remove the filter first, or else it will go in infinite loop
@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';
//}
<?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..
/*
http://webdeveloperswall.com/javascript/floating-sidebar-for-twentythirteen
*/
var jq=jQuery.noConflict();
var wdw_fs_status = "unaltered";
jq(window).load(function(){
//if there is a sidebar, in the first place
<script>
jQuery(document).ready(function($){
$(".wpcf7").on( 'mailsent.wpcf7', function(){
var redirect_to = $(this).find('#wdw_redirect_to_url').val();
if( typeof(redirect_to)!=='undefined' && redirect_to!='' ){
window.location.href= redirect_to;
}
});
});
</script>
<li class="bbp-body">
<?php while ( bbp_topics() ) : bbp_the_topic(); ?>
<?php bbp_get_template_part( 'loop', 'single-topic' ); ?>
<?php endwhile; ?>
<?php if( function_exists( 'bbpresslmt_loadmore_button' ) ): ?>
<?php bbpresslmt_loadmore_button(); ?>