Search blog

Thursday, September 28, 2017

Enable both Visual & HTML Editor for Admin, Editor & Author but Only Visual Editor for Subscriber in bbPress

Use the code below to enable both Visual & HTML Editor for roles such as Admin, Editor & Author but Only Visual Editor for Subscriber in your bbPress installation:

 function bbp_enable_visual_editor( $args = array() ) {   
  if (current_user_can('administrator')  
       || current_user_can('editor')  
       || current_user_can('author')  
       || current_user_can('bbp_moderator')  
       || current_user_can('bbp_keymaster')  
       || current_user_can('employer')) {  
      $args['tinymce'] = true;  
   return $args;  
  }   
  else {  
   $args['tinymce'] = true;  
   $args['quicktags'] = false;  
   return $args;  
  }   
 }  
 add_filter( 'bbp_after_get_the_content_parse_args', 'bbp_enable_visual_editor' );  

Monday, September 25, 2017

Disable WP Dashboard for Subscriber but Enable for Editor, Author and Other Custom Roles

Using the code below you can disable access to your WordPress Dashboard/Backend for selected roles and users belonging to that particular role. For example, if you want to restrict dashboard access to your guest users and users belonging to 'Subscriber' role then you may add the following code in your theme's function.php file or best way is to use the Code Snippet plugin.
 There are many added benefits, which you can read in the plugin's description page, when you use Code Snippet instead of directly inserting your code into your theme's function.php file.

 // Source: https://premium.wpmudev.org/blog/limit-access-to-your-wordpress-dashboard/  
 add_action( 'init', 'blockusers_init' );  
 function blockusers_init() {  
  if ( is_admin() && !current_user_can( 'administrator' )   
       && !current_user_can('editor')  
       && !current_user_can('author')  
       && !current_user_can('translator')  
       && !( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {  
      wp_redirect( home_url() );  
      exit;  
  }  
 }  

Note that I have also added a custom role called 'translator' in the above code.

Below is a screenshot of how I have added the code to my site by making use of the Code Snippet plugin.

Disable WP Dashboard for Subscriber but Enable for Editor, Author and Other Custom Roles
Click image to enlarge


Sunday, September 17, 2017

Import SQL File from Command Line (CLI)

Here's a simple way to import your SQL file/dump using your Command Line Interface (CLI) or what is also known as Terminal:
 mysql> USE database_name;  
 mysql> source filename.sql;  
You can use this method to import database, also if your database size is very large and your are facing problems importing it from phpMyAdmin.

Saturday, September 16, 2017

Reset AUTO_INCREMENT Value in MySQL

You can reset the AUTO_INCREMENT value in MySQL either by using a SQL command or by using phpMyAdmin.

NOTE: You cannot reset the counter to a value less than or equal to the value that is currently in use. For both InnoDB and MyISAM, if the value is less than or equal to the maximum value currently in the AUTO_INCREMENT column, the value is reset to the current maximum AUTO_INCREMENT column value plus one.

To reset the Primary Key Value to 1, you should either delete the table and create a new table or TRUNCATE the table and apply the command below. But DON'T do this, if you already have data in your table.

1. Using SQL Command:
 ALTER TABLE table_name AUTO_INCREMENT =1;  

where,
- table_name is the name of the table whose AUTO_INCREMENT value you want to reset.

2. Using phpMyAdmin Operation:
 - First open the table whose AUTO_INCREMENT value you would like to reset.
 - Once inside the table click on the Operation tabs as shown in the image below.

Click on image to enlarge

3. To save the changes you've made, click on Go.

Top 5 Posts (Weekly)