Friday 30 August 2013

How to remove admin bar from non admin users in wordpress?

Hi All,

Please add following script into your functions.php file:

add_action('after_setup_theme', 'remove_admin_bar');

function remove_admin_bar() {
    if (!current_user_can('administrator') && !is_admin()) {
      show_admin_bar(false);
    }
}

Cheers!

How to add login/logout button in wordpress menu?

Hi All,

Add following script into your functions.php

add_filter('wp_nav_menu_items', 'add_login_logout_link', 10, 2);
function add_login_logout_link($items, $args) {

        ob_start();
        wp_loginout('index.php');
        $loginoutlink = ob_get_contents();
        ob_end_clean();

        $items .= '<li>'. $loginoutlink .'</li>';

    return $items;
}

Cheers!!!

Thursday 8 August 2013

How to create cron job in YII framework?

Hi All,

Create cron.php file under project folder and write following:

<?php
// change the following paths if necessary
$yii=dirname(__FILE__).'/../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/console.php';

require_once($yii);
Yii::createConsoleApplication($config)->run();

?>


Create console.php file under protected/config folder and write same data as written in main.php. see below:

/ This is the configuration for yiic console application.
// Any writable CConsoleApplication properties can be configured here.
return array(
    'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
    'name'=>'My Console Application',

    // preloading 'log' component
    'preload'=>array('log'),
        'import'=>array(
                'application.components.*',
                'application.models.*',
        ),

    // application components
    'components'=>array(
           
        // uncomment the following to use a MySQL database       
        'db'=>array(
            'connectionString' => 'mysql:host=localhost;dbname=bollywood_news',
            'emulatePrepare' => true,
            'username' => $dbUsername,
            'password' => $dbPassword,
            'charset' => 'utf8',
                        'enableProfiling' => true,
        ),
       
        'log'=>array(
            'class'=>'CLogRouter',
            'routes'=>array(
                array(
                    'class'=>'CFileLogRoute',
                                        'logFile'=>'cron.log',
                    'levels'=>'error, warning',
                ),
                                array(
                                        'class'=>'CFileLogRoute',
                                        'logFile'=>'cron_trace.log',
                                        'levels'=>'trace',
                                ),
            ),
                       
        ),
    ),
   
);

Now,

Create CronjobCommand.php file under protected/commands folder. Here cronjob is a command.

<?php

class CronjobCommand extends CConsoleCommand {

    public function run($args) {
        // your code will come here...
    }

}

Now,

You have two ways to run your command:

Go to your project folder and write following:

a. php cron.php cronjob
b. php protected/yiic cronjob


Cheers!!!





?>

Wednesday 7 August 2013

How to take backup of log files in symfony 1.4?

Hi All,

Execute following command on your project root folder:

php symfony log:rotate frontend prod --period=1 --history=5


In above command,
period 1 means:
    frontend_prod.log contains 1 day log data and very next day backup of same file will be saved under log/history folder and also empty it.
history 5 means:
    Under log/history folder, backup of 5 days will be stored only.


Cheers!!!