Skip to content

Instantly share code, notes, and snippets.

View mohsinrasool's full-sized avatar
💪

Mohsin Rasool mohsinrasool

💪
View GitHub Profile
@mohsinrasool
mohsinrasool / Widget Classes
Created November 13, 2015 15:37 — forked from plechazunga/Widget Classes
WordPress
/**
* Add "first" and "last" CSS classes to dynamic sidebar widgets. Also adds numeric index class for each widget (widget-1, widget-2, etc.)
*/
function widget_first_last_classes($params) {
global $my_widget_num; // Global a counter array
$this_id = $params[0]['id']; // Get the id for the current sidebar we're processing
$arr_registered_widgets = wp_get_sidebars_widgets(); // Get an array of ALL registered widgets
if(!$my_widget_num) {// If the counter array doesn't exist, create it
@mohsinrasool
mohsinrasool / buddypress-omit-hidden-visibility-search-results.php
Last active October 29, 2015 12:01
This snippet should be placed in member-loop.php within the if statement of bp_has_members check. it finds and remove the members that has the search term in the fields. It is one attempt to do that.
<?php
global $members_template;
$member_count = $members_template->member_count;
$query = $_GET['s'];
for($i=0; $i<$member_count; $i++) {
$list = bp_xprofile_get_hidden_fields_for_user($members_template->members[$i]->ID,bp_loggedin_user_id());
@mohsinrasool
mohsinrasool / wp_ms_body_class_site_id.php
Created October 26, 2015 16:59
add a class to the body tag identifying the blog on a wordpress multi site install
<?php
add_action( 'body_class', 'my_body_class' );
function my_body_class( $class ) {
global $current_blog;
$class[] = 'site-' . $current_blog-> blog_id;
return $class;
}
?>
@mohsinrasool
mohsinrasool / gravity_form_gtm_tracking.php
Created October 18, 2015 19:32
To track the submission of gravity forms and generate an event through Google Tag Manager, you can utilize the following code, It adds the onclick event to the submit button of the gravity form. So, whenever the submit button is clicked an event is sent to Google Server. You need to do two things to use this code
function add_conversion_tracking_code($button, $form) {
$dom = new DOMDocument();
$dom->loadHTML($button);
$input = $dom->getElementsByTagName('input')->item(0);
if ($input->hasAttribute('onclick')) {
$input->setAttribute("onclick","ga('send', 'event', { eventCategory: 'GTM_Category', eventAction: 'GTM_Action', eventLabel: 'GTM_Label'});".$input->getAttribute("onclick"));
} else {
$input->setAttribute("onclick","ga('send', 'event', { eventCategory: 'GTM_Category', eventAction: 'GTM_Action', eventLabel: 'GTM_Label'});");
}
return $dom->saveHtml();
@mohsinrasool
mohsinrasool / Client.php
Created October 2, 2015 14:14
WordPress Shortcode to Fetch LinkedIn Company Profile updates
<?php
class Client {
public $domain = "https://api.linkedin.com";
/**
* Authorization and AccessToken api endpoints are special in that they live on www.linkedin.com not api.linkedin.com
*/
public $authorizationUrl = "https://www.linkedin.com/uas/oauth2/authorization";
public $accessTokenUrl = "https://www.linkedin.com/uas/oauth2/accessToken";
@mohsinrasool
mohsinrasool / track-ga-click-event-gravityforms.php
Last active May 9, 2016 22:27
Track google analytics click event in in Gravity Forms
<?php
// track conversions in Gravity Forms
function add_conversion_tracking_code($button, $form) {
$dom = new DOMDocument();
$dom->loadHTML($button);
$input = $dom->getElementsByTagName('input')->item(0);
if ($input->hasAttribute('onclick')) {
$input->setAttribute("onclick","ga('send', 'click', 'submit');".$input->getAttribute("onclick"));
} else {
@mohsinrasool
mohsinrasool / wiki_page_shortcode.php
Created August 28, 2015 10:09
Wikis listing for WPMU Dev Wiki Plugin
add_shortcode('wiki_page','my_wiki_page');
function my_wiki_page($atts, $content) {
ob_start();
$post_type = 'incsub_wiki';
// Gets every "category" (term) in this taxonomy to get the respective posts
//$terms = get_terms( 'wiki_category' );
@mohsinrasool
mohsinrasool / bbpress-badgeos-user-achievements-under-avatar
Created August 21, 2015 14:27
This gists adds User's badges earned with badgeos plugin under his avatar in topics and replies of bbpress.
<?php
add_filter( 'bbp_get_reply_author_link', 'my_append_badges_via_filter', 10, 2 );
function my_append_badges_via_filter($author_link = '', $args) {
# Needed to get the user ID of the person intended to be displayed.
$user_id = bbp_get_reply_author_id( $args['post_id'] );
#Construct your output here.
$badge_output = '';
@mohsinrasool
mohsinrasool / login-logout-link-nav.php
Created August 20, 2015 10:26
Add login/logout link to naviagation menu