Skip to content

Instantly share code, notes, and snippets.

@ckchaudhary
ckchaudhary / 1. rest-endpoints.php
Last active February 25, 2025 06:11
Add url parameters to a GET request made using javascript fetch, in the context of querying wordpress rest api custom endpoints.
<?php
// Send errors like this:
$update_status = $widget_obj->update( $new_data );
if ( ! $update_status['status'] ) {
// validation erorrs!
return rest_send_error( $update_status['message'] );
}
// Or, like this:
<?php
/**
* Plugin Name: RB Tabify Settings Sections
* Plugin URI: https://blogs.recycleb.in/2024/07/wordpress-plugin-theme-settings-screen-turn-sections-into-tabs/
* Description: Turn plugin/theme settings screen sections into tabs.
* Version: 1.0.0
* Author: ckchaudhary
* Author URI: https://www.recycleb.in/u/chandan/
* Licence: GPLv2
*
<?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: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 <[email protected]>
@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/
*/
@ckchaudhary
ckchaudhary / get-youtube-video-id-from-url
Last active July 27, 2024 07:46
Get youtube video id from youtube url
<?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
*/
@ckchaudhary
ckchaudhary / generate-youtube-embed-code-from-url
Last active July 27, 2024 07:45
Generate youtube embed code from youtube url
<?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){
/**
* 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>