Restrict post to user_id

I am not expert on users, simplest way as for me would be to store ID (or IDs) of user in custom field and check for it if user is not admin. Some example code (not tested): if(current_user_can(‘administrator’) || in_array(get_current_user_id(), get_post_meta(get_the_id(), ‘allowed_users’, true))) { the_content(); } else { echo ‘Post restricted’; }

How can we Restrict to access a certain wordpress page to all ip address except some which we allow

Haven’t specifically done this yet but something similar In the theme page/post template files you can get post id of current post/page by doing $currentID = get_the_ID(); Then redirect all traffic not from the specified IPs $ipArr = array(‘xx.xxx.xxx.xxx’, ‘xx.xxx.xxx.xxx’); if (!in_array(@$_SERVER[‘REMOTE_ADDR’], $ipArr)) { header(“Location: http://example.com/myhomepage”); die(); }

User Access Manager plugin

Problem solved. Updating the plugin doesn’t seem to produce the required table structure in the database. The structure has changed between versions. You have to remove the old plugin and tables and then install the new version. This seems to work. Will report any other errors caused by the update here.

How to set privilege to wordpress subscriber for private page

Without a plugin something like this should work //functions.php function get_user_role() { global $current_user; $user_roles = $current_user->roles; $user_role = array_shift($user_roles); return $user_role; } //page template $role = get_user_role(); if($role == “subscriber”){ //cool you can see this } else { //sorry not allowed } A BETTER way would be to use something like the Members Plugins … Read more

How to make user inactive by default while registering?

/* Plugin Name: Role-less New Users Description: Removes all roles from new registrations. Author: 5ubliminal */ // Hook into the registration process add_action(‘user_register’, function($user_id){ $user = new WP_User($user_id); // Remove all user roles after registration foreach($user->roles as $role){ $user->remove_role($role); } }, 11); Create a new .php file. Paste the code above in it. Put it … Read more

How to restrict attachment download to a specific user?

What needs to happen is that you need to proxy download requests for the file types you want through WordPress. Let’s assume you’re going to restrict access to “.doc” files. 1. Define a query variable that indicates the requested file function add_get_file_query_var( $vars ) { $vars[] = ‘get_file’; return $vars; } add_filter( ‘query_vars’, ‘add_get_file_query_var’ ); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)