Skip to content

Instantly share code, notes, and snippets.

View BhargavBhandari90's full-sized avatar
🏠
Working from home

Bhargav(Bunty) BhargavBhandari90

🏠
Working from home
View GitHub Profile
@BhargavBhandari90
BhargavBhandari90 / dl-file.php
Created June 7, 2018 05:23
Add this file to site's root
<?php
require_once('wp-load.php');
list($basedir) = array_values(array_intersect_key(wp_upload_dir(), array('basedir' => 1)))+array(NULL);
$file = rtrim($basedir,'/').'/'.str_replace('..', '', isset($_GET[ 'file' ])?$_GET[ 'file' ]:'');
$mime = wp_check_filetype($file);
$ext = $mime['ext'];
$allowed_ext = array( 'jpg', 'jpeg', 'png', 'gif', 'svg' );
@BhargavBhandari90
BhargavBhandari90 / allo-preview-to-author.php
Last active November 27, 2018 17:55
Allow post author to preview non-published post
<?php
/**
* Allow author to preview non published solution.
*
* @param object $posts
* @return object
*/
function preview_post_to_author( $posts ) {
// Get surrent user id.
@BhargavBhandari90
BhargavBhandari90 / assign_users.js
Created December 20, 2018 05:56
Assign Users while importing data in WP importer
(function($){
$('#authors li').each(function(key, value) {
var name = $(this).children('strong').first().html();
var re = /\s\([^\)]+\)/gi;
name = name.replace(re, '');
$(this).find('select').first().children('option').each(function(){
if ($(this).html() == name) {
console.log('Comparing ' + $(this).html() + ' to ' + name + ".\n");
$(this).attr('selected', 'selected');
@BhargavBhandari90
BhargavBhandari90 / buddypress-group-subtab.php
Last active August 27, 2024 10:39
Add custom tab on buddypress group page
<?php
/**
* Add custom sub-tab on groups page.
*/
function buddypress_custom_group_tab() {
// Avoid fatal errors when plugin is not available.
if ( ! function_exists( 'bp_core_new_subnav_item' ) ||
! function_exists( 'bp_is_single_item' ) ||
@BhargavBhandari90
BhargavBhandari90 / remove-tab.php
Created June 9, 2020 10:40
Remove tabs from user profile for BuddyBoss
<?php
/**
* Remove tabs from user profile.
*/
function remove_profile_nav() {
// Prevent fatal error if plugin is not available.
if ( ! function_exists( 'bp_core_remove_nav_item' ) ) {
return;
}
@BhargavBhandari90
BhargavBhandari90 / buddypress-email-setting-manipulation.php
Created June 23, 2020 15:59
Manipulate email notification setting for user when they register for buddypress/buddyboss
<?php
function bpdev_set_email_notifications_preference( $user_id ) {
//I am putting some notifications to no by default and the common ones to yes to enable it.
//ref. https://bp-tricks.com/snippets/changing-default-buddypress-notifications-settings and BP forum
$settings_keys = array(
'notification_activity_new_mention' => 'yes',
'notification_activity_new_reply' => 'yes',
'notification_friends_friendship_request' => 'no',
'notification_friends_friendship_accepted' => 'no',
@BhargavBhandari90
BhargavBhandari90 / buddypress-email-setting-manipulation.php
Last active June 23, 2020 18:38
Turn email notification OFF for new users for BuddyBoss and BuddyPress
<?php
/**
* Disable email notification.
*
* @param integer $user_id User ID.
* @return void
*/
function buddyboss_set_email_notifications_preference( $user_id ) {
@BhargavBhandari90
BhargavBhandari90 / change-default-tab.php
Last active June 27, 2020 17:22
Change default tab for group and user profile for buddyboss & buddypress
<?php
/**
* Change default tab for group.
*
* @param string $default_tab Slug of default tab.
* @return string
*/
function buddyboss_groups_default_extension( $default_tab ) {
return 'slug_of_tab'; // Last part of the URL.
}
@BhargavBhandari90
BhargavBhandari90 / add-tab-user-profile.php
Last active September 23, 2022 18:49
Add tab to user profile
<?php
/**
* Add custom sub-tab on groups page.
*/
function buddyboss_custom_user_tab() {
// Avoid fatal errors when plugin is not available.
if ( ! function_exists( 'bp_core_new_nav_item' ) ||
! function_exists( 'bp_loggedin_user_domain' ) ||
empty( get_current_user_id() ) ) {
@BhargavBhandari90
BhargavBhandari90 / multiple-user-tabs.php
Created July 9, 2020 18:32
Add multiple custom tabs on user profile for buddyboss and buddypress
<?php
/**
* Add custom sub-tab on user profile.
*/
function buddyboss_custom_user_tab() {
// Avoid fatal errors when plugin is not available.
if ( ! function_exists( 'bp_core_new_nav_item' ) ||
! function_exists( 'bp_loggedin_user_domain' ) ||
empty( get_current_user_id() ) ) {