mysql

How To Create a New Role in WordPress?

WordPress integrates six default roles: Administrator, Editor, Contributor, Author, subscriber and sixth multi-role: Super Admin which have all privileges under WordPress blog.

In this tutorial we will see how to create a new role for your website subscribers and how to display the content according to the new role.

Why would you need to create a new role in WordPress blog?
Apart from enhancing the WordPress security, we could give you a lot of reason to create a new role for subscribers. However in this tutorial we will give you one good example on how to keep the default subscriber role but also create a premium subscription to monetize your blog. So if you have a blog where you want to give access to certain articles or special offers only to people to have paid monthly subscription for example, they can have this custom-built new role in WordPress blog.

To create this new role (Premium Subscription) in WordPress you will need to add the following code in function.php file of your WordPress theme:

// Add a role
add_role(‘premium_user’, ‘Premium Subscription’, array(
‘read’ => true, // true : Allow reading of article page
‘edit_posts’ => false, // false : Forbidden to add articles or pages
‘delete_posts’ => false, // false : Forbidden to remove articles or pages
));

Add_role : premium_user identifier will be our new role and Premium Subscription is the name of the role that I attribute to my future subscribers who want this subscription.

Disable Plugin Update

How To Disable Plugin Update in WordPress?

If you have created your own WordPress theme for your blog and you have installed many different plugins, you are most probably facing with the problem when updating those plugins because once you do that you will change your theme and erase all your previous work/changes you’ve done, By using two codes below you can disable all update for all plugins or only select those who should not be updated.

The first method you can implement will disable all updates to your plugins. Copy and paste below code inside your funtion.php file.

remove_action( ‘load-update-core.php’, ‘wp_update_plugins’ );
add_filter( ‘pre_site_transient_update_plugins’, create_function( ‘$a’, “return null;” ) );

The second code will allow you to choose plugins that should not be updated. Add below code in your function.php file.

For this tutorial I decided to disable Akismet plugin. With below 3 line of the code I mentioned the name of the plugin, folder with the name of the php file that usually has the same name as the folder.

You can duplicate below lines of code and replace necessary values with plugin whos updates you want to block..

function stop_plugin_update( $value ) {
unset( $value->response[‘akismet/akismet.php’] );
return $value;
}
add_filter( ‘site_transient_update_plugins’, ‘stop_plugin_update’ );

WP_Query

How To Create WordPress Custom Queries with WP_Query?

WordPress custom queries are very powerful tool. If you want to display on your index.php or single.php file other content different from what the WordPress shows by default, just create WordPress custom queries using WP_Query. For those that don’t know, WP_Query is a class that allows you to create WordPress custom queries and retrieve your posts according to criteria defined via the parameter to the constructor of this class.

To use this application you must store it in a variable and use that object in WordPress loop. In this tutorial I will show you some great examples on how to use WordPress custom queries or WP_Query in your own WordPress projects.

WordPress Custom Queries Examples
This class can be configured as desired, and there are many possibilities available to you, here are some of WordPress custom queries examples I find most useful:

Example 1: Select all posts

$query = new WP_Query(array(‘post_type’ => ‘post’));

Example 2: Select all posts and all pages