Life runs on code

Recent Posts

Exporting all MySQL user privileges

Exporting all MySQL user privileges

To export all MySQL user privileges run following script. Note : Replace {host_name}, {user_name} and {password} with your values. mysql -h {host_name} -u {user_name} -p{password} -Ne “select distinct concat( \”SHOW GRANTS FOR ‘\”,user,\”‘@’\”,host,\”‘;\” ) from user;” mysql | mysql -h {host_name} -u {user_name} -p{password} | sed […]

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 […]

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 […]

Add/Update Git Subtree

Add/Update Git Subtree

Recently I am working on WordPress development helper library, I add it as submodule in many of my plugins, but every time during clone i forgot to init and update submodule, and some time during pull code i forgot to update new submodule. So, Finally i decided to start use Git Subtree.

Following are the set of command that will required during development and working with subtree

Add git subtree in repo

git subtree add --prefix app/lib https://github.com/rtCamp/wp-helpers.git master --squash

Update git subtree in repo

git subtree pull --prefix app/lib https://github.com/rtCamp/wp-helpers.git master --squash

FYI: There are some pros and cons of subtree and submodule, You can find many article on it just google it 😉

[Fixed] MacBook Pro built-in webcam not working ?

[Fixed] MacBook Pro built-in webcam not working ?

So many times its happens with my mac that Skype, Chrome other applications are not able to access built in webcam. After googling i came up with following solution. Usually it’s not a macbook problem. It’s software problem. open a terminal and type sudo killall […]

Run Multiple instance of Skype on Mac OS X

Run Multiple instance of Skype on Mac OS X

Run following command in terminal to start second instance of Skype sudo /Applications/Skype.app/Contents/MacOS/Skype

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 __construct( $dir = '' ) {
      if ( ! empty( $dir ) ){
        $this->dir = trailingslashit( $dir );
      } else {
        /** __DIR__ is actually equivalent to 
         * realpath(dirname(__FILE__)) and Added in PHP 5.3.0
         * Bellow line will also work 
         * for php  5.2.4 (WordPress required php  5.2.4 or greater )
         */
        $this->dir = trailingslashit( ( @__DIR__ == '__DIR__' ) && define( '__DIR__', realpath( dirname( __FILE__ ) ) ) );
      }
      spl_autoload_register( 
          array( $this, 'spl_autoload_register' ) );
     }

    /**
     * @param string $class_name
     */
    function spl_autoload_register( $class_name ) {
      $class_path = $this->dir . strtolower( 
       str_replace( '_', '-', $class_name ) ) . '/class-' 
       . strtolower( str_replace( '_', '-', $class_name ) ) . '.php';
      
      if ( file_exists( $class_path ) ){
        include $class_path;
      }
    }
  }
}

/**
 * Initiate Loader class
 */

$obj_rt_wp_loader = new RT_WP_Autoload();
Add admin to glotpress

Add admin to glotpress

Following is the script to add admin to glotpress php scripts/add-admin.php user-name Before run script, check you have configured database properly.

PHP readdir() return false even if permission are right

PHP readdir() return false even if permission are right

Today (So many times ) i face directory read issue using php. If you are trying to read a directory and readdir function is returning false even if php user have right permission (At least read permission) to that directory mainly while your server is […]