Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Bhargav(Bunty) Bhandari BhargavBhandari90

🏠
Working from home
Block or report user

Report or block BhargavBhandari90

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@BhargavBhandari90
BhargavBhandari90 / assign_users.js
Created Dec 20, 2018
Assign Users while importing data in WP importer
View assign_users.js
(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 / allo-preview-to-author.php
Last active Nov 27, 2018
Allow post author to preview non-published post
View allo-preview-to-author.php
<?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 / dl-file.php
Created Jun 7, 2018
Add this file to site's root
View dl-file.php
<?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 / .htaccess
Created Jun 7, 2018
Add these two line at the starting of WP rules
View .htaccess
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^wp-content/uploads/(.*)$ dl-file.php?file=$1 [QSA,L]
@BhargavBhandari90
BhargavBhandari90 / functions.php
Last active Feb 3, 2020
Add links to BuddyPress navigation.
View functions.php
<?php
/**
* Add this function to theme's functions.php
*
* Add links to BuddyPress navigation.
* This will add photo, video and music link to BuddyPress navigation.
*
* If you don't want to display "Media" tab, then add following css to
* rtMedia->Settings->Custom CSS:
*
@BhargavBhandari90
BhargavBhandari90 / functions.php
Last active Dec 29, 2017
Read comment below for how to use.
View functions.php
<?php
/**
* Get media of perticular topic or forum
*
* @param int $item_id Id of forum
* @return array Array of media ids associated with the forum
*/
function rtcamp_get_perticular_forum_media( $item_id ) {
@BhargavBhandari90
BhargavBhandari90 / functions.php
Last active Oct 23, 2017
Change srcset when rtAmazon-s3 plugin is active. Use at your own RISK.
View functions.php
<?php
/**
* Add this function into theme's functions.php
*
* This function will replace domain with amazon s3 bucket url for image's srcset.
*/
function rtawss3_wp_calculate_image_srcset_latin( $sources, $size_array, $image_src, $image_meta, $attachment_id ) {
if ( ! class_exists( 'RTAWSS3_Class' ) ) {
@BhargavBhandari90
BhargavBhandari90 / functions.php
Last active Oct 13, 2017
Show pics on buddyboss photo page. Photos will not show if BuddyBoss is used with rtMedia with "Privacy Settings" enabled. So add this snippet to theme's functions.php
View functions.php
<?php
/**
*
* Fix - Show pics on buddyboss photo page.
* Photos will not show if BuddyBoss is used with rtMedia with "Privacy Settings" enabled.
* So add this snippet to theme's functions.php
*
*/
function rtmc_show_pics_buddyboss() {
@BhargavBhandari90
BhargavBhandari90 / functions.php
Created Aug 16, 2017
Replace media ID with the media title in URL
View functions.php
<?php
// Add this code into theme's functions.php
function custom_get_rtmedia_permalink( $permalink, $media, $id ) {
$post = get_post( $media[0]->media_id );
$title = isset( $post->post_name ) ? $post->post_name : '';
if ( ! empty( $title ) ) {
$permalink = str_replace( '/' . $id , '/' . $title, $permalink );
}
@BhargavBhandari90
BhargavBhandari90 / functions.php
Created May 26, 2017
Add currecnt languge slug of WPML to media url in activity stream.
View functions.php
<?php
/**
* Add this code snippet to theme's functions.php
*
* Add currecnt languge slug of WPML to media url in activity stream.
*
*/
if ( ! function_exists( 'rtmedia_wpml_activity_urls' ) ) {
function rtmedia_wpml_activity_urls( $permalink, $media, $id ) {
global $sitepress;
You can’t perform that action at this time.