bbpress topic info short code

This short code will show the current topic info of the bbpress forum plugin on the sidebar. You can place this code on your theme functions.php file.

 

/**
 * bbpress topic info short code
 */
function bbpress_topic_info_func( $atts ){

    global $wp_query;
    $post = $wp_query->get_queried_object();

    if($post->post_type == "topic"){ 

      ob_start();

     ?> 

   <ul class="topic-info">
      <li class="topic-forum">
          In:<?php echo get_the_title($post->post_parent);?>
      </li>
      <li class="reply-count">
          <?php echo bbp_get_topic_post_count($post->ID, false);?> Replies
      </li>
      <li class="voice-count">
          <?php echo bbp_get_topic_voice_count($post->ID, false); ?> Participants
      </li>
      <li class="topic-freshness-author">
          Last Activity <?php echo bbp_get_topic_last_active_time($post->ID, false); ?>
      </li>
      <li class="topic-subscription-link"><?php bbp_topic_subscription_link(); ?></li>
      <li class="topic-favorites-link"><?php bbp_user_favorites_link(); ?></li>
  </ul>     

  <?php
  return ob_get_clean();

    }

}
add_shortcode( 'bbpress-topic-info', 'bbpress_topic_info_func' );

/**
 * bbpress subscription link | hide
 * From https://bbpress.org/forums/topic/is-there-a-way-to-remove-this-character-next-to-the-subscription-link/
 */

function hide_before ($args = array() ) {
$args['before'] = '';
return $args;
}
add_filter ('bbp_before_get_forum_subscribe_link_parse_args','hide_before') ;

You can use this short code like this [bbpress-topic-info]

 

wpml language switcher shortcode

function language_switcher_fun( $atts ){
	ob_start();
	do_action('icl_language_selector');
	return ob_get_clean();
}
add_shortcode( 'language_switcher_shortcode', 'language_switcher_fun' );

You can use it like this [language_switcher_shortcode]

Include category id in body_class() and post_class()

Use this code on your themes functions.php to add current category id on body and post

function category_id_class($classes) {
	global $post;
	foreach ((get_the_category($post->ID)) as $category)
		$classes[] = 'cat-' . $category->cat_ID . '-id';
	return $classes;
}
add_filter('post_class', 'category_id_class');
add_filter('body_class', 'category_id_class');

Get custom post count in custom taxonomy

To get total custom post count of a custom taxonomy use the follow code

$args = array(
    'post_type' => 'post type name here',
    'post_status' => 'published',
    'taxonomy name here' => 'slug of the category under taxonomy',
    'numberposts' => -1
);
echo $num = count( get_posts( $args ) );

For instance, if you had a custom taxonomy called “product_category” and wanted to only show posts from the “manes” product_category you would use the below code.

$args = array(
    'post_type' => 'product',
    'post_status' => 'published',
    'product_category' => 'manes',
    'numberposts' => -1
);
echo $num = count( get_posts( $args ) );

Set a maximum upload count for users on a specific user role

Use the following code to limit 10 upload for specific role

add_filter( 'wp_handle_upload_prefilter', 'limit_uploads_for_user_roles' );

function limit_uploads_for_user_roles( $file ) {
  $user = wp_get_current_user();
  // add the role you want to limit in the array
  $limit_roles = array('contributor');
  $filtered = apply_filters( 'limit_uploads_for_roles', $limit_roles, $user );
  if ( array_intersect( $limit_roles, $user->roles ) ) {
    $upload_count = get_user_meta( $user->ID, 'upload_count', true ) ? : 0;
    $limit = apply_filters( 'limit_uploads_for_user_roles_limit', 10, $user, $upload_count, $file );
    if ( ( $upload_count + 1 ) > $limit ) {
      $file['error'] = __('Upload limit has been reached for this account!', 'yourtxtdomain');
    } else {
      update_user_meta( $user->ID, 'upload_count', $upload_count + 1 );
    }
  }
  return $file;
}

This action will fire when user delete attachment

add_action('delete_attachment', 'decrease_limit_uploads_for_user');

function decrease_limit_uploads_for_user( $id ) {
   $user = wp_get_current_user();
   // add the role you want to limit in the array
   $limit_roles = array('contributor');
   $filtered = apply_filters( 'limit_uploads_for_roles', $limit_roles, $user );
   if ( array_intersect( $limit_roles, $user->roles ) ) {
     $post = get_post( $id);
     if ( $post->post_author != $user->ID ) return;
     $count = get_user_meta( $user->ID, 'upload_count', true ) ? : 0;
     if ( $count ) update_user_meta( $user->ID, 'upload_count', $count - 1 );
   }
}

Thanks Giuseppe

How to change “Registration complete. Please check your e-mail.” message in wp-login.php

You can use this filter to change the default “Registration complete. Please check your e-mail.” message on wordpress.

add_filter( 'wp_login_errors', 'override_reg_complete_msg', 10, 2 );
function override_reg_complete_msg( $errors, $redirect_to ) {
   if( isset( $errors->errors['registered'] ) ) {
     $needle = __('Registration complete. Please check your e-mail.');
     foreach( $errors->errors['registered'] as $index => $msg ) {
       if( $msg === $needle ) {
         $errors->errors['registered'][$index] = 'Your new message here';
       }
     }
   }

   return $errors;
}

Thanks DaveRoss

Best ways to detect IE browser

IE6 is a worse dream for every web developers. Good news is that Software giant Microsoft has released a new website with the expressed aim of killing off its Internet Explorer 6 browser.

ie6countdown.com

Still we have to deal with IE7 to IE9

Here is some way to cut down your development time by easily detecting IE.

IE Conditional Comments

It is the most commonly used to fix the IE bugs for specific versions (IE6, IE7, IE8,IE9)

// Target all version of IE
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="all-ie.css" />
<![endif]-->
//Target everything except IE
<!--[if !IE]><!-->
	<link rel="stylesheet" type="text/css" href="not-ie.css" />
 <!--<![endif]-->
//Target IE 6 only
<!--[if IE 6]>
	<link rel="stylesheet" type="text/css" href="ie6.css" />
<![endif]-->
//Target IE 7 only
<!--[if IE 7]>
	<link rel="stylesheet" type="text/css" href="ie7.css">
<![endif]-->
//Target IE 8 and lower
<!--[if lt IE 9]>
	<link rel="stylesheet" type="text/css" href="ie8-and-down.css" />
<![endif]-->
<!--[if lte IE 8]>
	<link rel="stylesheet" type="text/css" href="ie8-and-down.css" />
<![endif]-->
//Target IE 8 and higher 
<!--[if gt IE 7]>
	<link rel="stylesheet" type="text/css" href="ie8-and-up.css" />
<![endif]-->
<!--[if gte IE 8]>
	<link rel="stylesheet" type="text/css" href="ie8-and-up.css" />
<![endif]-->

CSS Rules Specific

Its an way if you just want to do small changes on you css file in a quick way.

.wrapper {
background: red; /* standard */
background: green\9; /* IE 8 and below */
*background: blue; /* IE 7 and below */
_background: black; /* IE 6 */
}

Conditional HTML Class

Paul Irish found a way and it doesn’t cause any validation errors! I think this is best.

<!--[if lt IE 7 ]> <html class="ie6"> <![endif]-->
<!--[if IE 7 ]> <html class="ie7"> <![endif]-->
<!--[if IE 8 ]> <html class="ie8"> <![endif]-->
<!--[if IE 9 ]> <html class="ie9"> <![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--> <html> <!--<![endif]-->

Free HTML5 tools for developer

Since start of HTML5 it took the web to next level.Now most of the web development is implemented using HTML5 and css3 . Today i listed some HTML5 tools to reduce the development time.

1) Modernizr.com

modernizr_com

Modernizr is a JavaScript library that detects HTML5 and CSS3 features in the user’s browser.It will add class on html tag.

2) html5boilerplate.com

html5boilerplate_com

HTML5 Boilerplate helps you build fast, robust, and adaptable web apps or sites. Kick-start your project with the combined knowledge and effort of 100s of developers, all in one little package.

3) html5please.com

html5please_com

html5please.com will let you updated about HTML5, CSS3 features.If they are ready for use, and if so find out how you should use them – with polyfills, fallbacks or as they are.

4) videojs.com

videojs_com

Video.js is a JavaScript and CSS library that makes it easier to work with and build on HTML5 video.Video.js provides a common controls skin built in HTML/CSS, fixes cross-browser inconsistencies, adds additional features like fullscreen and subtitles, manages the fallback to Flash or other playback technologies when HTML5 video isn’t supported, and also provides a consistent JavaScript API for interacting with the video.

5) liveweave.com

liveweave_com

Liveweave is a HTML5, CSS3 & JavaScript playground for web developers and designers.Very useful tool for test your coding quickly.

Hope this tools will help you on your next project.

Happy coding 🙂

Detect HTML5 Geolocation Support

Geolocation is the art of figuring out where you are in the world and (optionally) sharing that information with people you trust.
To check if the user browser support Geolocation you can use any of the following techniques:

Technique #1:

By using a JavaScript junction.

function supports_geolocation() {
  return !!navigator.geolocation;
}

Technique #2:

you can use Modernizr to detect support for the geolocation API.

if (Modernizr.geolocation) {
  // let's find out where you are!
} else {
  // no native geolocation support available 
  // maybe try Gears or another third-party solution
}

Get this tips from http://fortuito.us/diveintohtml5/detect.html#geolocation

Hidden elements using HTML5

HTML5 introduce the hidden attribute, which will allow you to hide a specific element. So no need to use css display:none anymore!

<div hidden>You can't see this text.This is hidden by HTML5 hidden attribute.</div>

Source: http://html5demos.com/hidden