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
Last active November 18, 2017 22:56
Get All posts by tag in a network - wordpress multisite
<?php
/*
*
* Uses: get_tagged_post() or get_tagged_post( AN ARRAY OF BLOG IDs )
*
*/
function get_tagged_post($blogs = array(), $tag) {
if( count( $blogs ) < 1 ){
$blog_list = wp_get_sites();
@bappi-d-great
bappi-d-great / Code.php
Last active November 19, 2017 00:14
Show posts based on user preference in wordpress
<?php
add_action( 'show_user_profile', 'extra_fields' );
add_action( 'edit_user_profile', 'extra_fields' );
add_action( 'personal_options_update', 'save_fields' );
add_action( 'edit_user_profile_update', 'save_fields' );
add_action( 'pre_get_posts', 'exclude_category' );
function extra_fields($user) {
$pref_cat = explode( ',', get_user_meta( $user->ID, 'pref_cat', true ) );
@bappi-d-great
bappi-d-great / code.php
Created July 25, 2014 16:02
Show all upcoming events in events archive page
<?php
add_filter( 'eab-collection-upcoming-start_timestamp', '__all_events_start' );
add_filter( 'eab-collection-upcoming-end_timestamp', '__all_events_end' );
function __all_events_start() {
return date('Y-m-d') . ' 00:01';
}
function __all_events_end() {
@bappi-d-great
bappi-d-great / code.php
Last active August 29, 2015 14:04
Reorder or rearrange buddypress menu items
<?php
function my_change_profile_tab_order() {
global $bp;
$bp->bp_nav['settings']['position'] = 10;
$bp->bp_nav['activity']['position'] = 20;
$bp->bp_nav['friends']['position'] = 30;
$bp->bp_nav['groups']['position'] = 40;
$bp->bp_nav['blogs']['position'] = 50;
$bp->bp_nav['messages']['position'] = 60;
@bappi-d-great
bappi-d-great / code.php
Created July 25, 2014 16:04
Add Excerpt in WPMU Events+ plugin
<?php
add_filter( 'eab-event-post_type-supports', 'adding_excerpt_support' );
function adding_excerpt_support($supports) {
$supports[] = 'excerpt';
return $supports;
}
@bappi-d-great
bappi-d-great / code.php
Created July 25, 2014 16:04
Show messages in reverse order in buddypress message inbox
<?php
// Replace the code of /members/single/messages/single.php with this
?>
<div id="message-thread" role="main">
<?php do_action( 'bp_before_message_thread_content' ); ?>
<?php if ( bp_thread_has_messages(array('order'=>'DESC')) ) : ?>
@bappi-d-great
bappi-d-great / code.html
Created July 25, 2014 16:05
A very simple jQuery text slider
<script type="text/javascript" src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script type="text/javascript">
jQuery(function($){
$('#main_imag').load(function() {
setTimeout(function() {
$('#text1').animate({
left: 0
})
}, 1000);
setTimeout(function() {
@bappi-d-great
bappi-d-great / code.php
Created July 25, 2014 16:09
WPM Pro Sites: Add pro level expire notice in admin bar for sub sites
<?php
add_action( 'admin_bar_menu', 'add_extension', 999 );
function add_extension($wp_admin_bar) {
if( !is_main_site() ) {
$id = get_current_blog_id();
$expire = ProSites::get_expire($id);
$diff = $expire - time();
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
@bappi-d-great
bappi-d-great / code.php
Created July 25, 2014 16:15
Replace duplicate nickname and display name with username in WordPress
<?php
// A dirty script by Ashok
/*
* adding action when user profile is updated
*/
add_action('personal_options_update', 'check_display_name');
add_action('edit_user_profile_update', 'check_display_name');
function check_display_name($user_id) {
global $wpdb;
// Getting user data and user meta data
@bappi-d-great
bappi-d-great / gist:46fdb003ffac3e043533
Created July 25, 2014 16:15
Protect Duplicate nickname and display name for user in WordPress
<?php
add_action('personal_options_update', 'check_display_name');
add_action('edit_user_profile_update', 'check_display_name');
function check_display_name($user_id) {
global $wpdb;
$err['display'] = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM $wpdb->users WHERE display_name = %s AND ID <> %d", $_POST['display_name'], $_POST['user_id']));
$err['nick'] = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM $wpdb->users as users, $wpdb->usermeta as meta WHERE users.ID = meta.user_id AND meta.meta_key = 'nickname' AND meta.meta_value = %s AND users.ID <> %d", $_POST['nickname'], $_POST['user_id']));
foreach($err as $key => $e) {
if($e >= 1) {
$err[$key] = $_POST['username'];