Skip to content

Instantly share code, notes, and snippets.

View anandkumar's full-sized avatar

Anand Kumar anandkumar

View GitHub Profile
@anandkumar
anandkumar / jss-script.js
Created April 26, 2014 12:06
Add 100px offset to jQuery smooth scroll Plugin
/* Smooth Back to Top, Get This functionality from: http://wordpress.org/extend/plugins/cudazi-scroll-to-top/ */
jQuery.noConflict();
jQuery(function($) {
// When to show the scroll link
// higher number = scroll link appears further down the page
var upperLimit = 100;
// Our scroll link element
@anandkumar
anandkumar / functions.php
Created January 29, 2014 15:21
EDD Prevent Double Purchase
<?php
// EDD Prevent Double Purchase
function pw_edd_prevent_double_purchase( $valid_data, $post_data ) {
$cart_items = edd_get_cart_contents();
foreach( $cart_items as $item ) {
if( edd_has_user_purchased( get_current_user_id(), $item['id'] ) ) {
edd_set_error( 'double_purchase', __( 'You may not purchase this item again until your subscription expires', 'edd' ) );
}
}
<?php
/**
* Usage:
* Paste a gist link into a blog post or page and it will be embedded eg:
* https://gist.github.com/2926827
*
* If a gist has multiple files you can select one using a url in the following format:
* https://gist.github.com/2926827?file=embed-gist.php
*/
@anandkumar
anandkumar / functions.php
Created December 24, 2013 16:04
bbPress limit content visibility for non-logged in user
// Display Topic Leads
add_filter('bbp_show_lead_topic', 'custom_bbp_show_lead_topic' );
function custom_bbp_show_lead_topic( $show_lead ) {
if ( !is_user_logged_in() ){
$show_lead[] = 'true';
return $show_lead;
}}
// Show Topic Leads to Public or Anonymous visitors
add_filter('bbp_has_replies', 'synth_logged_in_topics');
@anandkumar
anandkumar / functions.php
Created November 11, 2013 17:28
Remove WordPress Admin bar
// Remove WordPress Admin bar
add_action('after_setup_theme', 'remove_admin_bar');
function remove_admin_bar() {
if (!current_user_can('administrator') && !is_admin()) {
show_admin_bar(false);
}
}
@anandkumar
anandkumar / functions.php
Created October 8, 2013 15:51
Remove (unhook) Genesis Comments from Posts
<?php
//* Do NOT include the opening php tag
//* Remove posted comments from Genesis
remove_action( 'genesis_comments', 'genesis_do_comments' );
@anandkumar
anandkumar / functions.php
Created October 2, 2013 07:53
Move Genesis Comments
/** Move Genesis Comments */
add_action( 'genesis_before_comments' , 'eo_move_comments' );
function eo_move_comments ()
{
if ( is_single() && have_comments() )
{
remove_action( 'genesis_comment_form', 'genesis_do_comment_form' );
add_action( 'genesis_comments', 'genesis_do_comment_form', 5 );
}
}
@anandkumar
anandkumar / disqus.js
Last active December 23, 2015 10:19
disqus lazy load
<script type="text/javascript">
var comments = document.getElementsByClassName('comments')[0],
disqusLoaded=false;
function loadDisqus() {
var disqus_shortname = 'netrival';
var dsq = document.createElement('script');
dsq.type = 'text/javascript';
dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
@anandkumar
anandkumar / functions.php
Last active December 22, 2015 04:58
bbPress Membership levels, Basic, Premium and Lifetime Premium. Based on some codes in bbPress forums.
<?php
function my_custom_get_dynamic_roles( $bbp_roles )
{
/* Add a role called Community Contributor */
$bbp_roles['bbp_basic_member'] = array(
'name' => 'Basic Member',
'capabilities' => my_custom_get_caps_for_role( 'bbp_basic_member' )
);
@anandkumar
anandkumar / functions.php
Created August 23, 2013 14:13
Hide bbPress topics / replies / forums from public or non-logged in users.
function pj_hla_logged_in_topics($have_posts){
if (!is_user_logged_in()){
$have_posts = null;
echo 'Login to see replies';
}
return $have_posts;
}
add_filter('bbp_has_topics', 'pj_hla_logged_in_topics');
add_filter('bbp_has_forums', 'pj_hla_logged_in_topics');