WordPress add active class to Menu item – Plugin

Hello friends,

I have developed a simple WordPress plugin to add active class to menu item li tag. Currently it is current-menu-item or current_page_parent. You can even set custom class to li tag if your need is other than active class. Hope you will like it.

Download it from: https://wordpress.org/plugins/wp-add-active-class-to-menu-item/

Note: For any customization or help please do contact me on my mail or at plugins support page.

indian rupee symbol not showing

Indian Rupee Symbol For Woocommerce – Plugin

I was facing a issue in displaying new Indian Rupee Symbol in Woocommerce. In my shopping page, cart, filters etc. the rupee symbol was not showing. It was display a square box (error). So with the help of google and other means I have developed new plugin as a solution to this problem. Hope you will like and it will be really helpful.

Check it out on: https://wordpress.org/plugins/indian-rupee-symbol-for-woocommerce/

Note: For any type of customization or help please do contact me or at plugins support page.

How to convert number to words in PHP

For example you need to convert a particular amount number into a word, let say

55892 – “fifty five thousand eight hundred ninety two”

To achieve this we can use below given code:

<?php
$ones = array(
“”,
” one”,
” two”,
” three”,
” four”,
” five”,
” six”,
” seven”,
” eight”,
” nine”,
” ten”,
” eleven”,
” twelve”,
” thirteen”,
” fourteen”,
” fifteen”,
” sixteen”,
” seventeen”,
” eighteen”,
” nineteen”
);
$tens = array(
“”,
“”,
” twenty”,
” thirty”,
” forty”,
” fifty”,
” sixty”,
” seventy”,
” eighty”,
” ninety”
);
$triplets = array(
“”,
” thousand”,
” million”,
” billion”,
” trillion”,
” quadrillion”,
” quintillion”,
” sextillion”,
” septillion”,
” octillion”,
” nonillion”
);
// recursive fn, converts three digits per pass
function convertTri($num, $tri) {
global $ones, $tens, $triplets;
// chunk the number, …rxyy
$r = (int) ($num / 1000);
$x = ($num / 100) % 10;
$y = $num % 100;
// init the output string
$str = “”;
// do hundreds
if ($x > 0)
$str = $ones[$x] . ” hundred”;
// do ones and tens
if ($y < 20)
$str .= $ones[$y];
else
$str .= $tens[(int) ($y / 10)] . $ones[$y % 10];
// add triplet modifier only if there
// is some output to be modified…
if ($str != “”)
$str .= $triplets[$tri];
// continue recursing?
if ($r > 0)
return convertTri($r, $tri+1).$str;
else
return $str;
}
// returns the number as an anglicized string
function convertNum($num) {
$num = (int) $num; // make sure it’s an integer
if ($num < 0)
return “negative”.convertTri(-$num, 0);
if ($num == 0)
return “zero”;
return convertTri($num, 0);
}
// Returns an integer in -10^9 .. 10^9
// with log distribution
function makeLogRand() {
$sign = mt_rand(0,1)*2 – 1;
$val = randThousand() * 1000000
+ randThousand() * 1000
+ randThousand();
$scale = mt_rand(-9,0);
return $sign * (int) ($val * pow(10.0, $scale));
}
// example of usage
echo “-5564 : “.convertNum(-5564).”<br>”;
echo “55892 : “.convertNum(55892);
?>

How to install Codeigniter in Xampp localhost

1. Download Latest Version 3.0.0 : Download Zip
2. Unzip it at your server in folder “codeigniter”. for example :xampp/htaccess/codeigniter

3. Now go to – application/config/config.php Here add base url ie. Base path of your application directory.

For example :

4. Now to go the : application/config/database.php Add database settings here :

For Example :

5 . (Optional) : Remove Index.php from url

Create a .htaccess file at the root of the application for example at :xampp/htaccess/codeigniter – add here .htaccess file

Add the following code in the .htaccess file :

6. You are done : Now your application is ready : Hit the url : http://localhost/codeigniter you will see default welcome message

Setup Maintenance Mode Using Hooks in Codeigniter

image1 (1)

There are so many ways to achieve maintenance mode in codeigniter. Codeigniter itself doesn`t provide such kind of functionality as other framework supports. This post supports how to setup maintenance mode using hooks.

Following are the steps to achieve this:

  1. Enable Hooks in the config.php file
  2. Create a custom config file for maintenance settings i.e maintenance_config.php
  3. Create an html called maintenance_view.php page under views or in root folder
  4. Create a Hook file called maintenance.php
  5. In the hooks config setup your hooks call to run on post_controller

application/views/maintenance_view.php

<!DOCTYPE html>
<html>
  <head>
    <title>Maintenance</title>
    <style>Style your page</style>
  </head>
  <body>
    <p>We apologize but our site is currently undergoing maintenance at this time.</p>
    <p>Please check back later.</p>
  </body>
</html>

application/config/maintenance_config.php

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$config['site_under_maintenance'] = TRUE;
?>

application/hooks/maintenance.php

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Maintenance {
  var $CI;
  public function maintenance() {
     $this->CI = & get_instance();
     $this->CI->config->load('maintenance_config'); // Load custom config file
     if ($this->CI->config->item("site_under_maintenance")) {
        include(APPPATH . '/views/maintenance_view.php');
        die();
     }
  }
}
?>

application/config/hooks.php

<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
$hook['post_controller'][] = array(
  'class' => 'maintenance',
  'function' => 'maintenance',
  'filename' => 'maintenance.php',
  'filepath' => 'hooks',
  'params' => array()
);
?>

Output

Maintenance

 

Session based flash messages

Quite a while ago, I grew tired of trying to come up with new and creative ways to display simple, one-time messages to users without crazy amounts of code for something that was frequently as trivial as “Saved!”.

Sessions are the obvious solution, however, without a single function that could both generate, AND display the messages, it still wasn’t any better.  And as usual, where there’s a will, and some code- there’s a way!

Before we get started, make sure that a session is started, otherwise a) no message will be displayed, and b) super fun headers already sent messages.

//Ensure that a session exists (just in case)
if( !session_id() )
{
    session_start();
}

//Actual function

/**
 * Function to create and display error and success messages
 * @access public
 * @param string session name
 * @param string message
 * @param string display class
 * @return string message
 */
function flash( $name = '', $message = '', $class = 'success fadeout-message' )
{
    //We can only do something if the name isn't empty
    if( !empty( $name ) )
    {
        //No message, create it
        if( !empty( $message ) &amp;& empty( $_SESSION[$name] ) )
        {
            if( !empty( $_SESSION[$name] ) )
            {
                unset( $_SESSION[$name] );
            }
            if( !empty( $_SESSION[$name.'_class'] ) )
            {
                unset( $_SESSION[$name.'_class'] );
            }

            $_SESSION[$name] = $message;
            $_SESSION[$name.'_class'] = $class;
        }
        //Message exists, display it
        elseif( !empty( $_SESSION[$name] ) &amp;& empty( $message ) )
        {
            $class = !empty( $_SESSION[$name.'_class'] ) ? $_SESSION[$name.'_class'] : 'success';
            echo '
.$class.'" id="msg-flash">'.$_SESSION[$name].'
'
; unset($_SESSION[$name]); unset($_SESSION[$name.'_class']); } } }
//Set the first flash message with default class
flash( 'example_message', 'This content will show up on example2.php' );

//Set the second flash with an error class
flash( 'example_class', 'This content will show up on example2.php with the error class', 'error' );
//Displaying the messages
<?php flash( 'example_message' ); ?>
<?php flash( 'example_class' ); ?>

You can download the source from here

From: http://www.phpdevtips.com/