Life runs on code

Tag: snippet

OpenSSH 7.3 on CentOs 6.7

OpenSSH 7.3 on CentOs 6.7

A simple script to upgrade OpneSSH on CentOs 6.7. To use you can run following command with root user bash < ( curl -sL https://bit.ly/2OaOGPZ )

User Avatar in buddyPress notification loop

User Avatar in buddyPress notification loop

To display user avatar in buddypress notification-loop (You can find it in members / single / notifications / notifications-loop.php ) Below snippet will return user id of that activity ( BuddyPress stored it as  secondary_item ) $bp = buddypress(); $user_id = $bp->notifications->query_loop->notification->secondary_item_id; To echo avatar from user id […]

Loading IE Conditional Stylesheets in WordPress

Loading IE Conditional Stylesheets in WordPress

Most web developers are familiar with the IE conditional comments that allow you to load a stylesheet only in Internet Explorer.

<!-- [if lt IE 9]>
   <link href="ie.css" rel="stylesheet" type="text/css">
<![endif]-->

Many new WordPress developers tend to just hardcode these conditional comments directly into their theme’s header.php file. The correct way to load stylesheets in WordPress is using the wp_enqueue_style() function.

add_action( 'wp_enqueue_scripts', 'enqueue_my_styles' );

function enqueue_my_styles() {
   global $wp_styles;
   enqeue_style( 'my-theme-ie', get_stylesheet_directory_uri() . 'ie.css' );
   //add_data function to add IE Condition
   $wp_styles->add_data( 'my-theme-ie', 'conditional', 'IE 9' );
}

 

Automatic update of Child Theme to Parent Theme

Automatic update of Child Theme to Parent Theme

After automatic update of child theme to parent theme, During update we just update code of theme, but what about WordPress, WordPress still assuming current theme as child theme. When you activate child theme, there are mainly two site options template and stylesheet who store […]

Enable Category/Tag support for WordPress Media files

Enable Category/Tag support for WordPress Media files

To enable category/tag support on WordPress Media, You have to register taxonomy for Media(attachment) by adding following code in theme function.php or in plugin file register_taxonomy( ‘media-category’, ‘attachment’, $args ); Note : This will work with WordPress 3.5 or higher.

Check if session is started or not in php

Check if session is started or not in php

To avoid Cannot send session cookie - headers already sent warning which is caused by calling the session_start()function without checking if the session is already started or not.

You can find following warning in error log file :

Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /xxx/xxx/abc.php:8) in /xxx/xxx/test.php on line 11

Recommended way for versions of PHP >= 5.4.0

 Instant Images if ( session_status() == PHP_SESSION_NONE ) {
    session_start();
}

Source: http://www.php.net/manual/en/function.session-status.php

For versions of PHP < 5.4.0

if ( session_id() == '' ) {
    session_start();
}
Get php class file path from class name – ReflectionClass

Get php class file path from class name – ReflectionClass

During development of common library for WordPress plugins and themes ( WordPress development helper library ), I just want to find from which plugin it is called ( I just want to debug the code, but I used in many plugins and i am not […]

Generic autoloader for classes named in WordPress coding style

Generic autoloader for classes named in WordPress coding style

if ( ! class_exists( ‘RT_WP_Autoload’ ) ){ /** * Generic autoloader for classes named in WordPress coding style. */ class RT_WP_Autoload { /** * @var string Current directory absolute path */ public $dir; /** * @param string $dir optional, default value is current */ function […]

Java User Agent Detection code

Java User Agent Detection code