Categorize Media Type for WordPress Media Library

The WordPress users and developers, all we are very much familiar to WordPress Media Library where we upload the media type files like images, PDFs, audio, videos, zip and so on. It is a great storage at all. Moreover we link the upload files to our posts and pages. On the Media Library page there are 3 common filters like Images, Video and Audio.

Now just think about spice it up by creating more filters. There are lots of people who upload PDF, archive and different media files and integrating the media library with new categories will make this section more handy at all.Check this screen shot and you can see 4 new category tabs as PDF, DOC, ZIP and JS.

wordpress-media-typeI have coded a simple WordPress plugin by using file mime type and it is handled by the WordPress default ‘post_mime_types’ filter. You can add as many filter (overriding the default) as you wish by adding new mime type.

mime-function-screenshot

After downloading the plugin, unzip it, upload it into your plugin folder, activate it and that’s all. You can edit the plugin file (mimetype.php) to add new mime type.  Presently there are 9 filters already added as PDF, MSWORD, ZIP, JavaScript, SWF, MOV, FLV, AVI, DIVX.

You can download the list of MIME content-types supported by most web servers as PDF format.

Download Link.

Continue Reading

How to create a simple HTML contact form with Ajax & PHP

There are so many times we don’t want to use any PHP file (say contact.php) directly for our HTML websites to process contact form rather we prefer to use HTML contact page (say contact.html). It is not a hard task, we can do this by using Ajax or jQuery. In this tutorial I am describing the easiest way to do the same.
The form will be in any HTML extension page with validation. What we need a separate PHP file for parsing email function only.

Here are the screen shots of the forms.

ajax-contact-form-basic

ajax-contact-form-validated

Step 1: Create an HTML page (contact.html) and write the form code with jQuery library CDN and validation script file  adding.

Step 2: Add a JS file for the form validation and Ajax function of jQuery to get all the data from the submission of the form as soon as the form sends the values to email.php .

Step 3: Create a php file as email.php and write down the main PHP mail function.

Demo | Download

Continue Reading

WordPress add Dashicons for new menu

When we add new menu page in WordPress in our custom plugins or theme functions we use the ‘add_menu_page‘ page function which can option to pass icon path of that menu.
Here is the code snippet of the default example:

add_action('admin_menu', 'members_downloads_menu');
function members_downloads_menu() {
 if (is_admin()){
 add_menu_page('Members Downloads Options', 'Members Downlods', 'manage_options', 'members-downloads','members_downloads_page',plugins_url('your-plugin-folder/images/icon.png'), 80 );
 }
}

Since WordPress version 3.8 there is option to use Dashicons instead of any images used as icons. Dashicons is the official icon font of the WordPress admin as of 3.8.

Here is the code snippet to show where to replace the icon path to Dashicons:

add_action('admin_menu', 'members_downloads_menu');
function members_downloads_menu() {
 if (is_admin()){
 add_menu_page('Members Downloads Options', 'Members Downlods', 'manage_options', 'members-downloads','members_downloads_page','dashicons-download', 80 );
 }
}

You can notice that I have replaced the icon path with ‘dashicons-download’ where ‘dashicons’ is referred to use font and the icon font name is ‘download’ as my menu page is supposed to use a download icon. See this original output.

wp-dashicons

You can get the list of Dashicons from WordPress official page from this link.

Continue Reading

Beautify your codes online, format source codes

If you want to be a good coder then you must format your codes properly with block commenting. It will help you a lot to update or modify your code at any time. I have worked with many coders who rarely love their codes and I had so much pain to work on their codes. It is really a pain.

There are several websites from where you can beautify (format) your codes instantly. Here are some good websites.

1. prettyprinter.de

Supports: PHP, Java, C++, C, Perl, JavaScript, CSS

2. styleneat.com

Supports: CSS

3. dirtymarkup.com

Supports: HTML, CSS, JavaScript

4. jsbeautifier.org

Supports: HTML, JavaScript

The ‘Adobe Dreamweaver’ has a built-in tool for source formatting and it is awesome with perfect source format and killing of unnecessary spaces.

Continue Reading

Disable plugin update notification for specific plugin in WordPress

The major WordPress plugins get updated on regular basis and we often login to the WordPress dashboard and notice notification for one or more plugin updates. If we ignore these updates, these notifications can pile up.

It is strongly recommended to update the WordPress plugins always to the latest versions. 

Now, think differently, if the website developer has some customization done in the plugin core file. So, if the plugin get updated, all the customized work will be gone away and your website may not work as per the previous customized version. If we can disable the specif plugin update notification, then there will be no chance to update the plugin.

There are 2 common ways to do disable specific plugin update notification.

Option 1 (Preferred):

Open the main PHP file of the plugin and just below the plugin header put the following code.

// Stop Plugin Updates
add_filter('site_transient_update_plugins', 'remove_update_notification');
function remove_update_notification($value) {
 unset($value->response[ plugin_basename(__FILE__) ]);
 return $value;
}
plugin-code-screenshot

 

Restriction: the name of the function (remove_update_notification) is unique. You can not add the same function in different plugins to disable update notifications. If you want to disable for multiple plugins then you have to change the function name different in different plugins.
Option 2:

Get the folder and main file name of the specific plugin and put the following code in the ‘functions.php’ file of your theme.

function filter_plugin_updates( $value ) {
 // Replace the plugin folder name and main file name with your plugin's folder and file name
 unset( $value->response['akismet/akismet.php'] );
 return $value;
}
add_filter( 'site_transient_update_plugins', 'filter_plugin_updates' );
Continue Reading

LAN chat without any software and network settings

Chat over the same LAN network among different computers always need a software to be installed. But now it is very easy to do the same without using any software or network settings. Mainly at office or home we have different computers are connected over LAN and have same IP. In this case we just have to open the browser and go to a particular URL WiFi Chat. It will open a text box to enter chat text. If any other user (computer) in the same network and using same IP open the same URL from browser then that user also see the chat text box. In this way different user can text chat over LAN.

Very simple and easy at all. This will be an open chat, so, no personal or confidential chat please.

This is completely an online application which works via Browsers only. You just need to open the link http://chatbyip.appspot.com/

Continue Reading