24 May 2014

Enable Hidden Admin Feature Displaying ALL Site Settings - Wordpress

Here is little Snippets of WordPress that I'd like to share with you.

Following code will help you to display complete list of all the settings from `options` table of database.

You can see this page in "wp-admin --> Setting --> All Settings".
function enable_all_settings_link()
{
 add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php');
}
add_action('admin_menu', 'enable_all_settings_link');
Have Fun!

1 May 2014

Computer Keyboard Shortcut Keys

~~~~~Enjoy Typing~~~~~ 

Common - Keyboard Shortcuts
1. CTRL+C (Copy)
2. CTRL+X (Cut)
3. CTRL+V (Paste)
4. CTRL+Z (Undo)
5. DELETE (Delete)
6. SHIFT+DELETE (Delete the selected item permanently without placing the item in the Recycle Bin)
7. CTRL while dragging an item (Copy the selected item)
8. CTRL+SHIFT while dragging an item (Create a shortcut to the selected item)
9. F2 key (Rename the selected item)
10. CTRL+RIGHT ARROW (Move the insertion point to the beginning of the next word)
11. CTRL+LEFT ARROW (Move the insertion point to the beginning of the previous word)
12. CTRL+DOWN ARROW (Move the insertion point to the beginning of the next paragraph)
13. CTRL+UP ARROW (Move the insertion point to the beginning of the previous paragraph)
14. CTRL+SHIFT with any of the arrow keys (Highlight a block of text)
SHIFT with any of the arrow keys (Select more than one item in a window or on the desktop, or select text in a document)
15. CTRL+A (Select all)
16. F3 key (Search for a file or a folder)
17. ALT+ENTER (View the properties for the selected item)
18. ALT+F4 (Close the active item, or quit the active program)
19. ALT+ENTER (Display the properties of the selected object)
20. ALT+SPACEBAR (Open the shortcut menu for the active window)
21. CTRL+F4 (Close the active document in programs that enable you to have multiple documents opensimultaneously)
22. ALT+TAB (Switch between the open items)
23. ALT+ESC (Cycle through items in the order that they had been opened)
24. F6 key (Cycle through the screen elements in a window or on the desktop)
25. F4 key (Display the Address bar list in My Computer or Windows Explorer)
26. SHIFT+F10 (Display the shortcut menu for the selected item)
27. ALT+SPACEBAR (Display the System menu for the active window)
28. CTRL+ESC (Display the Start menu)
29. ALT+Underlined letter in a menu name (Display the corresponding menu) Underlined letter in a command name on an open menu (Perform the corresponding command)
30. F10 key (Activate the menu bar in the active program)
31. RIGHT ARROW (Open the next menu to the right, or open a submenu)
32. LEFT ARROW (Open the next menu to the left, or close a submenu)
33. F5 key (Update the active window)
34. BACKSPACE (View the folder onelevel up in My Computer or Windows Explorer)
35. ESC (Cancel the current task)
36. SHIFT when you insert a CD-ROMinto the CD-ROM drive (Prevent the CD-ROM from automatically playing)

Dialog Box - Keyboard Shortcuts
1. CTRL+TAB (Move forward through the tabs)
2. CTRL+SHIFT+TAB (Move backward through the tabs)
3. TAB (Move forward through the options)
4. SHIFT+TAB (Move backward through the options)
5. ALT+Underlined letter (Perform the corresponding command or select the corresponding option)
6. ENTER (Perform the command for the active option or button)
7. SPACEBAR (Select or clear the check box if the active option is a check box)
8. Arrow keys (Select a button if the active option is a group of option buttons)
9. F1 key (Display Help)
10. F4 key (Display the items in the active list)
11. BACKSPACE (Open a folder one level up if a folder is selected in the Save As or Open dialog box)

Microsoft Natural Keyboard Shortcuts
1. Windows Logo (Display or hide the Start menu)
2. Windows Logo+BREAK (Display the System Properties dialog box)
3. Windows Logo+D (Display the desktop)
4. Windows Logo+M (Minimize all of the windows)
5. Windows Logo+SHIFT+M (Restorethe minimized windows)
6. Windows Logo+E (Open My Computer)
7. Windows Logo+F (Search for a file or a folder)
8. CTRL+Windows Logo+F (Search for computers)
9. Windows Logo+F1 (Display Windows Help)
10. Windows Logo+ L (Lock the keyboard)
11. Windows Logo+R (Open the Run dialog box)
12. Windows Logo+U (Open Utility Manager)
13. Accessibility Keyboard Shortcuts
14. Right SHIFT for eight seconds (Switch FilterKeys either on or off)
15. Left ALT+left SHIFT+PRINT SCREEN (Switch High Contrast either on or off)
16. Left ALT+left SHIFT+NUM LOCK (Switch the MouseKeys either on or off)
17. SHIFT five times (Switch the StickyKeys either on or off)
18. NUM LOCK for five seconds (Switch the ToggleKeys either on or off)
19. Windows Logo +U (Open Utility Manager)
20. Windows Explorer Keyboard Shortcuts
21. END (Display the bottom of the active window)
22. HOME (Display the top of the active window)
23. NUM LOCK+Asterisk sign (*) (Display all of the subfolders that are under the selected folder)
24. NUM LOCK+Plus sign (+) (Display the contents of the selected folder)

MMC Console keyboard shortcuts
1. SHIFT+F10 (Display the Action shortcut menu for the selected item)
2. F1 key (Open the Help topic, if any, for the selected item)
3. F5 key (Update the content of all console windows)
4. CTRL+F10 (Maximize the active console window)
5. CTRL+F5 (Restore the active console window)
6. ALT+ENTER (Display the Properties dialog box, if any, for theselected item)
7. F2 key (Rename the selected item)
8. CTRL+F4 (Close the active console window. When a console has only one console window, this shortcut closes the console)

Remote Desktop Connection Navigation
1. CTRL+ALT+END (Open the Microsoft Windows NT Security dialog box)
2. ALT+PAGE UP (Switch between programs from left to right)
3. ALT+PAGE DOWN (Switch between programs from right to left)
4. ALT+INSERT (Cycle through the programs in most recently used order)
5. ALT+HOME (Display the Start menu)
6. CTRL+ALT+BREAK (Switch the client computer between a window and a full screen)
7. ALT+DELETE (Display the Windows menu)
8. CTRL+ALT+Minus sign (-) (Place a snapshot of the active window in the client on the Terminal server clipboard and provide the same functionality as pressing PRINT SCREEN on a local computer.)
9. CTRL+ALT+Plus sign (+) (Place asnapshot of the entire client window area on the Terminal server clipboardand provide the same functionality aspressing ALT+PRINT SCREEN on a local computer.)

Microsoft Internet Explorer Keyboard Shortcuts
1. CTRL+B (Open the Organize Favorites dialog box)
2. CTRL+E (Open the Search bar)
3. CTRL+F (Start the Find utility)
4. CTRL+H (Open the History bar)wser with the same Web address)
5. CTRL+I (Open the Favorites bar)
6. CTRL+L (Open the Open dialog box)
7. CTRL+N (Start another instance of the bro
8. CTRL+O (Open the Open dialog box,the same as CTRL+L)
9. CTRL+P (Open the Print dialog box)
10. CTRL+R (Update the current Web page)
11. CTRL+W (Close the current window).

Have Fun!

25 April 2014

How To Add Column In Table If Not Exist ?

Hello everyone,

Today i am sharing little information about MySql alteration with database table.

I have added following function to help you to create column in db table if column not exist.

/**
 * To Add Column In Table If Not Exist.
 * @param $db_name Database Name
 * @param $table Table Name
 * @param $column Column Name
 * @param $column_attr Column attributs
 */
function add_column_if_not_exist($db_name, $table, $column_name, $column_attr = "VARCHAR( 255 ) NULL" )
{
 $exists = false;
 $columns = mysql_query("SELECT * FROM information_schema.COLUMNS WHERE `TABLE_SCHEMA`='$db_name' AND `TABLE_NAME`='$table' AND `COLUMN_NAME`='$column_name'");
 if(mysql_num_rows($columns) == 0)
 {
  mysql_query("ALTER TABLE `$table` ADD `$column_name`  $column_attr");
 }
}

I hope that, this will be helpful to you.

Have Fun!

7 April 2014

How to get all days of week from given date.

Hello!,

Here i have added php code for getting all days of week from given date.
Following function will help you to get this.
/**
 * Get all days of week.
 * @param date $date
 */
function getDaysOfWeek( $date )
{
    list($day, $month, $year) = explode( "-", date('d-m-Y', strtotime($date)) );
    // Get the weekday of the given date
    $wkday = date('l', strtotime($date));

    switch($wkday)
    {
        case 'Sunday': $numDaysToSun = 0; break;
        case 'Monday': $numDaysToSun = 1; break;
        case 'Tuesday': $numDaysToSun = 2; break;
        case 'Wednesday': $numDaysToSun = 3; break;
        case 'Thursday': $numDaysToSun = 4; break;
        case 'Friday': $numDaysToSun = 5; break;
        case 'Saturday': $numDaysToSun = 6; break;
    }
    // Timestamp of the sunday for that week
    $sunday = mktime('0','0','0', $month, $day-$numDaysToSun, $year);
    $seconds_in_a_day = 86400;

    // Get date for 7 days from Sunday (inclusive)
    for($i=0;$i<7;$i + +)
    {
        $day_name = date('l', $sunday+($seconds_in_a_day*$i));
        $dates[$day_name] = date('Y-m-d', $sunday+($seconds_in_a_day*$i));
    }
    return $dates;
}

Example:-
$weekdays = getDaysOfWeek(date('d-m-Y'));
echo "<pre>";
var_dump($weekdays);
exit;

/* This will output something like this:-
array(7) {
    ["Sunday"]=>
    string(10) "2014-04-06"
    ["Monday"]=>
    string(10) "2014-04-07"
    ["Tuesday"]=>
    string(10) "2014-04-08"
    ["Wednesday"]=>
    string(10) "2014-04-09"
    ["Thursday"]=>
    string(10) "2014-04-10"
    ["Friday"]=>
    string(10) "2014-04-11"
    ["Saturday"]=>
    string(10) "2014-04-12"
}

Have Fun!

25 March 2014

How to get distance between two points ?

Following function calculates the distance between two points (given the latitude/longitude coordinates of those points).
The calculated distance can be shown in following units.
  • Miles
  • Nautical Miles
  • Kilometeres
  • Meters
  • Yards
  • Feet
  • Inches
Here is the function to calculate distance between two points :-

/**
 * Get distancce between two points.
 * eg.:-
 $point1 = array('lat' => 40.770623, 'long' => -73.964367);
 $point2 = array('lat' => 40.758224, 'long' => -73.917404);
 $distance = getDistanceBetweenPoints($point1['lat'], $point1['long'], $point2['lat'], $point2['long']);
 foreach ($distance as $unit => $value) {
    echo $unit.': '.number_format($value,4).'';
 }
 */
function getDistanceBetweenPoints($latitude1, $longitude1, $latitude2, $longitude2)
{
    $theta = $longitude1 - $longitude2;
    $miles = (sin(deg2rad($latitude1)) * sin(deg2rad($latitude2))) + (cos(deg2rad($latitude1)) * cos(deg2rad($latitude2)) * cos(deg2rad($theta)));
    $miles = acos($miles);
    $miles = rad2deg($miles);
    $miles = $miles * 60 * 1.1515;
    $feet = $miles * 5280;
    $yards = $feet / 3;
    $kilometers = $miles * 1.609344;
    $meters = $kilometers * 1000;
    return compact('miles','feet','yards','kilometers','meters');
}


See example placed at above function.

Have Fun!

15 March 2014

How To Sort An Array By Value ?

You can sort an Array by value with following function:-

function sortByValue (&$array, $key)
{
    $sorter=array();
    $return=array();
    reset($array);
    foreach ($array as $ii => $va)
    {
        $sorter[$ii] = $va[$key];
    }
    asort($sorter);
    foreach ($sorter as $iii => $va)
    {
        $return[$iii] = $array[$iii];
    }
    $array=$return;
    return $array;
}


Have Fun!

10 March 2014

List of HTTP status codes

Here are some `HTTP standard status codes`, that i want to share with you.

Hope this will help you some way.
100 Continue
101 Switching Protocols
102 Processing (WebDAV; RFC 2518)
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information (since HTTP/1.1)
204 No Content
205 Reset Content
206 Partial Content
207 Multi-Status (WebDAV; RFC 4918)
208 Already Reported (WebDAV; RFC 5842)
226 IM Used (RFC 3229)
300 Multiple Choices
301 Moved Permanently
302 Found
303 See Other (since HTTP/1.1)
304 Not Modified
305 Use Proxy (since HTTP/1.1)
306 Switch Proxy
307 Temporary Redirect (since HTTP/1.1)
308 Permanent Redirect (approved as experimental RFC)[12]
400 Bad Request
401 Unauthorized
402 Payment Required
403 Forbidden
404 Not Found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Timeout
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Request Entity Too Large
414 Request-URI Too Long
415 Unsupported Media Type
416 Requested Range Not Satisfiable
417 Expectation Failed
418 I'm a teapot (RFC 2324)
419 Authentication Timeout (not in RFC 2616)
420 Method Failure (Spring Framework)
420 Enhance Your Calm (Twitter)
422 Unprocessable Entity (WebDAV; RFC 4918)
423 Locked (WebDAV; RFC 4918)
424 Failed Dependency (WebDAV; RFC 4918)
424 Method Failure (WebDAV)[14]
425 Unordered Collection (Internet draft)
426 Upgrade Required (RFC 2817)
428 Precondition Required (RFC 6585)
429 Too Many Requests (RFC 6585)
431 Request Header Fields Too Large (RFC 6585)
440 Login Timeout
444 No Response (Nginx)
449 Retry With (Microsoft)
450 Blocked by Windows Parental Controls (Microsoft)
451 Unavailable For Legal Reasons (Internet draft)
451 Redirect (Microsoft)
494 Request Header Too Large (Nginx)
495 Cert Error (Nginx)
496 No Cert (Nginx)
497 HTTP to HTTPS (Nginx)
499 Client Closed Request (Nginx)
500 Internal Server Error
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Timeout
505 HTTP Version Not Supported
506 Variant Also Negotiates (RFC 2295)
507 Insufficient Storage (WebDAV; RFC 4918)
508 Loop Detected (WebDAV; RFC 5842)
509 Bandwidth Limit Exceeded (Apache bw/limited extension)
510 Not Extended (RFC 2774)
511 Network Authentication Required (RFC 6585)
522 Connection timed out
524 A timeout occurred
598 Network read timeout error (Unknown)
599 Network connect timeout error (Unknown)

Have Fun!!

12 February 2014

Remove Height & Width Attributes From Images In Wordpress

WordPress will automatically add the image Width and Height attribute in the image element.

If you want to remove height and width attributes from the image elements it can be done with the following filters:-
  • post_thumbnail_html - Filter any post thumbnails.
  • image_send_to_editor - Filter the HTML when adding a image to the editor.

Add this code into your theme's `functions.php` file.

add_filter( 'image_send_to_editor', 'remove_attribute_from_image', 10 );
add_filter( 'post_thumbnail_html', 'remove_attribute_from_image', 10 );
add_filter( 'get_image_tag', 'remove_attribute_from_image', 10 );

function remove_attribute_from_image( $html )
{
 return preg_replace( '/(width|height)="\d*"\s/', "", $html );
}

Have Fun!

4 February 2014

How to add notification bubble to Wordpress admin menu


Following process will add pending post count in admin menu items..
You also can change as your need..

Edit the theme's `function.php` and add following line of code :-

First, add hook to admin menu
//Add hook to Admin Menu.
add_action('admin_menu', 'notification_count_in_admin_menu');

Now add function that will alter you menu with notification count.
function notification_count_in_admin_menu()
{
    global $menu;
    $post_types = array('post', 'page', 'your_cpt');
    foreach ($post_types as $type)
    {
        $post_count = get_number_of_pending_post_by_type($type);
        if(!empty($post_count))
        {
            foreach ( (array)$menu as $key => $parent_menu )
            {
                if ( $parent_menu[2] == 'edit.php?post_type='.$type )
                {
                    $menu[$key][0] = $menu[$key][0]. ''.$post_count.'';
                }
            }
        }
    }
}
function get_number_of_pending_post_by_type($type)
{
    global $wpdb;
    return $wpdb->get_var( "SELECT COUNT(ID) as count FROM {$wpdb->post} WHERE `post_status`='pending' AND `post_type`='{$type}';" );
}

Have fun!

29 January 2014

Disable theme update notification for a specific theme

Add following code into your specific plugin file to disable update notification,

//Filter to remove theme update notification.
add_filter('site_transient_update_themes', 'remove_theme_update_notification');
function remove_theme_update_notification($value)
{
 unset($value->response[ basename(__DIR__) ]);
 return $value;
}

Have Fun!