Skip to content

Instantly share code, notes, and snippets.

View bappi-d-great's full-sized avatar

Bappi D great bappi-d-great

View GitHub Profile
@bappi-d-great
bappi-d-great / code.php
Created July 25, 2014 16:16
How to detect bot in your website in php
<?php
function is_bot() {
$spiders = array(
"abot",
"dbot",
"ebot",
"hbot",
"kbot",
@bappi-d-great
bappi-d-great / code.php
Last active August 29, 2015 14:04
WPMU Pro Site - make the badge image clickable / add a link
<?php
add_action( 'wp_footer', 'make_clickable_image_in_pro_badge' );
function make_clickable_image_in_pro_badge() {
$link = "YOUR_DESIRED_LINK";
?>
<script type="text/javascript">
jQuery(function($){
$('.psts_widget')
.css({
'cursor': 'pointer'
@bappi-d-great
bappi-d-great / code.php
Created July 25, 2014 16:19
Shows events of a date in WPMU Events+
<?php
// Caution: works only for single events (not recurring events)
/*
Usage: [eab_event_date date="2014-07-05"], [eab_event_date date="today"], [eab_event_date date="tomorrow"]
*/
function process_eab_event_date( $atts ) {
$atts = shortcode_atts( array(
@bappi-d-great
bappi-d-great / code.php
Created July 26, 2014 00:12
WPMU Domain Mapping - Get all domain as an array
<?php
function get_all_domains(){
return $wpdb->get_results( 'SELECT Distinct domain from wp_domain_mapping', 'ARRAY_A' );
}
// $domains = get_all_domains() should return array of domains
@bappi-d-great
bappi-d-great / code.php
Created July 26, 2014 01:38
Stop accessing themes.php for subsite admin in a multisite
<?php
add_action('admin_init', 'disallowed_theme_page');
function disallowed_theme_page() {
global $pagenow;
if($pagenow == 'themes.php' && !is_super_admin()){
wp_redirect(admin_url());
exit;
}
}
@bappi-d-great
bappi-d-great / code.php
Last active August 29, 2015 14:04
WPMU Membership Card with shortcode
<?php
/*
* Use [my_mem_card] shorcode in anywhere in a page
*/
function my_mem_func() {
if( is_user_logged_in() ){
$current_user = wp_get_current_user();
$factory = Membership_Plugin::factory();
$user_object = $factory->get_member( $current_user->ID );
$userlevels = $user_object->get_level_ids();
@bappi-d-great
bappi-d-great / code.php
Created July 30, 2014 19:50
Hide buddypress profile groups for WPMU membership Level
<?php
/*
* $restricted_level is the level ID that needs to be restricted to see BP profile fields
* .bp-widget.contact-details here .contact-details should be the class name of the profile group
*/
add_action( 'wp_head', 'hide_bp_field' );
function hide_bp_field() {
if( is_user_logged_in() ){
$restricted_level = 3;
$current_user = wp_get_current_user();
@bappi-d-great
bappi-d-great / code.php
Created July 30, 2014 20:32
Let author to add categories but categories and tags are not accessible restricted by some keywords
<?php
// Adding capabilities in admin init
add_action( 'admin_init', 'add_author_cap' );
function add_author_cap() {
// Get current user's role
global $current_user;
$user_roles = $current_user->roles;
$user_role = array_shift($user_roles);
if( $user_role == 'author' ) {
@bappi-d-great
bappi-d-great / code.php
Created July 30, 2014 21:49
WPMU MarketPress add terms and conditions checkbox in shipping form
<?php
add_action( 'wp_footer', 'add_tos' );
function add_tos() {
?>
<script type="text/javascript">
jQuery(function($){
if($('.mp_cart_shipping').length) {
var html = '<tr><td colspan="2"><label><input type="checkbox" id="tos" /> I agree with the <a href="#">terms and conditions.</a></label></td></tr>';
$('.mp_cart_shipping tbody').append(html);
@bappi-d-great
bappi-d-great / WordPress Multisite - only allow one site per user.php
Last active September 21, 2022 18:31
WordPress Multisite - only allow one site per user
<?php
function wpms_one_blog_only($active_signup) {
// get the array of the current user's blogs
$blogs = get_blogs_of_user( get_current_user_id() );
// all users may be members of blog 1 so remove it from the count, could be a "Dashboard" blog as well
if ($blogs["1"]) unset($blogs["1"]);
//if the user still has blogs, disable signup else continue with existing active_signup rules at SiteAdmin->Options
$n = count($blogs);
if(n > 0){