Disable WordPress Admin Bar

Disable WordPress Admin Bar

Disable Admin Bar for everyone

// Disable Admin Bar for everyone
if (!function_exists('df_disable_admin_bar')) {

	function df_disable_admin_bar() {
		
		// for the admin page
		remove_action('admin_footer', 'wp_admin_bar_render', 1000);
		// for the front-end
		remove_action('wp_footer', 'wp_admin_bar_render', 1000);
	  	
		// css override for the admin page
		function remove_admin_bar_style_backend() { 
			echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
		}	  
		add_filter('admin_head','remove_admin_bar_style_backend');
		
		// css override for the frontend
		function remove_admin_bar_style_frontend() {
			echo '<style type="text/css" media="screen">
			html { margin-top: 0px !important; }
			* html body { margin-top: 0px !important; }
			</style>';
		}
		add_filter('wp_head','remove_admin_bar_style_frontend', 99);
  	}
}
add_action('init','df_disable_admin_bar');

 

Disable Admin Bar for everyone but administrators

// Disable Admin Bar for everyone but administrators
if (!function_exists('df_disable_admin_bar')) {

	function df_disable_admin_bar() {
		
		if (!current_user_can('manage_options')) {
		
			// for the admin page
			remove_action('admin_footer', 'wp_admin_bar_render', 1000);
			// for the front-end
			remove_action('wp_footer', 'wp_admin_bar_render', 1000);
			
			// css override for the admin page
			function remove_admin_bar_style_backend() { 
				echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
			}	  
			add_filter('admin_head','remove_admin_bar_style_backend');
			
			// css override for the frontend
			function remove_admin_bar_style_frontend() {
				echo '<style type="text/css" media="screen">
				html { margin-top: 0px !important; }
				* html body { margin-top: 0px !important; }
				</style>';
			}
			add_filter('wp_head','remove_admin_bar_style_frontend', 99);
			
		}
  	}
}
add_action('init','df_disable_admin_bar');

Disable WP Admin Bar for specific users

// Disable Admin Bar for specific user
if (!function_exists('df_disable_admin_bar')) {

	function df_disable_admin_bar() {
		
		// we're getting current user ID
		$user = get_current_user_id();
		
		// and removeing admin bar for user with ID 123
		if ($user == 123) {
		
			// for the admin page
			remove_action('admin_footer', 'wp_admin_bar_render', 1000);
			// for the front-end
			remove_action('wp_footer', 'wp_admin_bar_render', 1000);
			
			// css override for the admin page
			function remove_admin_bar_style_backend() { 
				echo '<style>body.admin-bar #wpcontent, body.admin-bar #adminmenu { padding-top: 0px !important; }</style>';
			}	  
			add_filter('admin_head','remove_admin_bar_style_backend');
			
			// css override for the frontend
			function remove_admin_bar_style_frontend() {
				echo '<style type="text/css" media="screen">
				html { margin-top: 0px !important; }
				* html body { margin-top: 0px !important; }
				</style>';
			}
			add_filter('wp_head','remove_admin_bar_style_frontend', 99);
			
		}
  	}
}
add_action('init','df_disable_admin_bar');

 

Removing Quick Edit option from wordpress rows

Removing Quick Edit option from wordpress rows

Add this to the theme function File.
function remove_stuff ( $actions ) {
if( !is_super_admin() && !current_user_can( 'edit_theme_options' ) ) {
unset($actions['inline hide-if-no-js']);
return $actions;
} else {
return $actions;
}
}
add_filter ( 'page_row_actions' , 'remove_stuff' );
add_filter ( 'post_row_actions' , 'remove_stuff' );

Removing Add Media option from WordPress Editor

Removing Add Media option from WordPress Editor

In Many ways many users doesn’t need the “Add Media” option to add image in the wordpress content editor. Those who wants to remove it can do like below to get rid of this.

Add the below code to theme function

function z_remove_media_controls() {     remove_action( 'media_buttons', 'media_buttons' );} add_action('admin_head','z_remove_media_controls');

Remove Unwanted Admin Menu Items

Remove Unwanted Admin Menu Items from wordpress dashboard. 

In the wordpress dashboard there are many items in the dashboard menu that is not needed almost all of the time. For those who wants to remove unwanted menu items from wordpress dashboard can do like below to get rid of unwanted menu items. Here is the way by which you can Remove Unwanted Admin Menu Items from wordpress dashboard.

In order to remove a menu item, just add it to the $remove_menu_items array in the following format: __(‘menu-item-name’).

Like this
$remove_menu_items = array(__('Comments'),__('Links'),__('Posts'));

In this way you can remove Unwanted Admin Menu Items from wordpress dashboard. 

Short description with limit in Woocommerce product page

Short description with limit in Woocommerce product page

To do so go to your woocommerce plugin directory like below

wp-content/plugins/woocommerce/templates
And find the php file named content-product.php  . After that just add the flowing code below

Here you can change the limit of character you want to display in short description. In the above code you can see that 230 number. Change that as you wish.

That’s all and have fun 🙂

Importing Large Database to Wamp Server

Importing Large Database to Wamp Server

It is obvious that most of us do website development in local server in terms of CMS like WordPress. I do that also. Few days ago i was working with a client site that has a big database. Which I need to copy into my local server and redesign the site. Then I export that database from his Cpanle but I couldn’t install it to my local Wamp Server. At that point I found the below solution which works great.

1) Open the php.ini file:
Click Wamp Server >PHP >php.ini
Find and change the following lines:
upload_max_filesize = 100M
post_max_size = 100M
2) Restart Apache Server.
3) Try importing the file

Note:
You may get the following error uploading a large file:
Set timeout
Fatal error: Maximum execution time of 300 seconds exceeded in C:\wamp\apps\phpmyadmin2.11.6\libraries\import\sql.php on line 118

4) Open C:\wamp\apps\phpmyadmin\config.inc.php
a) Near line 128 you can change the time for which phpmyadmin will execute
b) Change the number.
Before:
$cfg[‘ExecTimeLimit’]           = 300;    // maximum execution time in seconds (0 for no limit)
After:
$cfg[‘ExecTimeLimit’]           = 10000;    // maximum execution time in seconds (0 for no limit)
5) Restart All Services

More Options:

6) a) Open:
my.ini located in C:\wamp\bin\mysql\mysql5.0.51b\my.ini
b) Add the code:
max_allowed_packet = 200M

7) Open:
C:\wamp\apps\phpmyadmin3.4.5\config.inc.php
Look for:
$cfg[‘UploadDir’] = ”;
Change to:
$cfg[‘UploadDir’] = ‘upload’;

8) Create a directory called ‘upload’ in:
C:\wamp\apps\phpmyadmin3.X.X
Copy and Paste sql file to:
C:\wamp\apps\phpmyadmin3.X.X\upload\

9) Restart All Services

 

Those are the options that will work for you. So do it and enjoy

Where is my php.ini?

A new and easy trick to find your php.ini would be to ask php itself what it’s using, eg:

/usr/local/bin/php -i | grep ‘Loaded Configuration File’

which does assume that the php output will be in English.


If you’re running the default version of CLI php, your php.ini will be located at:

/usr/local/lib/php.ini

If you’re running php5 in CGI mode (suPhp), your php.ini will be located at:

/usr/local/etc/php5/cgi/php.ini

If you’re running php4 in CGI mode (suPhp), your php.ini will be located at:

/usr/local/etc/php4/cgi/php.ini

If you’re running php5.4 in php-FPM mode, your php.ini will be located at:

/usr/local/php54/lib/php.ini

Fatal error maximum execution time in wamp server

Fatal error maximum execution time in wamp server
When you will try to import a database which is little bigger like 5 or 10 MB in to wamp server in windows then you will get this error.

This error occurs when you importing mysql file into local mysql database.

edit the config.inc.php in phpmyadmin folder and then
add this line $Cfg[‘ExecTimeLimit’]=0;

or

change max_execution_time=1000 in php.ini (restart wamp server to take effect).
This way you can get rid of Fatal error maximum execution time in wamp server.

Importing large file using wamp server phpmyadmin

Importing large file using wamp server phpmyadmin

When trying to import large SQL files into mysql using phpmyadmin, at wamp server it gets error that says “You probably trying to upload large files”.

To get rid of this error I have got a nice solution which is so simple

Find the config.inc.php file located in the phpmyadmin directory. In my case it is located here:

1
C:\wamp\apps\phpmyadmin2.11.6\config.inc.php

Find the line with $cfg[‘UploadDir’] on it and update it to:

1
$cfg['UploadDir'] = 'upload';

Create a directory called ‘upload’ within the phpmyadmin directory.

1
C:\wamp\apps\phpmyadmin2.11.6\upload\

Then place the large sql file that you are trying to import into the new upload directory. Now when you go onto the db import page within phpmyadmin console you will notice a drop down present that wasn’t there before – it contains all of the sql files in the upload directory that you have just created. You can now select this and begin the import.