21

I was sure that wp_update_user function should do this (http://codex.wordpress.org/Function_Reference/wp_update_user). It even gets user_login as param, but it looks like it ignores it, when you set this param. So this code looks OK, but it doesn't work as you wish it did :( : wp_update_user( array ( 'ID' => $user_id, 'user_login' => $new_login ) ) ;...


18

Use is_admin(). It checks if you're viewing an Admin page, means the backend.


17

For a plugin I'm currently working on, I wanted to grant/restrict access to the plugin settings (i.e., the according admin menu pages) on a per role base. Therefore, I had to add a new plugin-specific capability to the user roles. Unfortunately, kaiser's answer seems to be not working anymore, so I spent some time trying to figure out how to allow for the ...


11

wp_get_current_user then compare the object that's returned user_login proprety with the specific username you'd like to check against. <?php add_action('admin_init', 'wpse74389_check_username'); function wpse74389_check_username() { $user = wp_get_current_user(); if($user && isset($user->user_login) && 'username_to_check' == $...


11

Diff the post content, title and author As had to do something related some month ago, here's the easiest and most future proof way (that I could fine) to check if there's a change made to the content or title or if the author changed: // Update Title '' !== wp_text_diff( $el['post_title'], $GLOBALS['post']->post_title ) AND $GLOBALS['post']-...


10

Use is_admin() to check if the the current page is an administration page. Despite its name this is not a user role check.


10

Write this into a plugin: add_action( 'template_redirect', 'auth_redirect' ); As plugin on GitHub. This will force all visitors login if they aren’t already. In some cases, this is asking for a log-in every time. This might work better: is_admin() || add_action( 'template_redirect', function() { if ( ! is_user_logged_in() ) auth_redirect(); }...


9

You can add this to your functions.php file in your template to allow the user to edit pages that they have created and manage media. Just specify their $user_id (i.e. 27): function add_theme_caps() { // to add capability to $user_id $user = new WP_User( $user_id ); $user->add_cap( 'edit_pages' ); $user->add_cap( 'edit_published_pages'...


9

Either of these 3 will help you: //Before getting the comments, on the WP_Comment_Query object for each comment add_action('pre_get_comments', 'wpse56652_filt_comm'); //Applied on the comments SQL Query, you can modify the 'Where' part of the query add_filter('comments_clauses', 'wpse56652_filt_comm'); //After the comments are fetched, you can modify the ...


9

I explored WordPress to find difference between it and in schema.php file i found the following function only where in WordPress add_users capability is used. /** * Create and modify WordPress roles for WordPress 3.0. * * @since 3.0.0 */ function populate_roles_300() { $role =& get_role( 'administrator' ); if ( !empty( $role ) ) { $role->...


9

The user passwords are stored in one-way encription. Even looking at the database you can not know the password. This is a very basic privacy feature. Most users use the same password on multiple sites; imaging the potential risks for users if the administrator of the site can access to their passwords. You can intercept the password from and get access to ...


8

To let the current users only view his/her uploaded attachments, add the following code to your themes actions: add_filter( 'posts_where', 'devplus_wpquery_where' ); function devplus_wpquery_where( $where ){ global $current_user; if( is_user_logged_in() ){ // logged in user, but are we viewing the library? if( isset( $_POST['...


8

My idea is something simple. You can make an Edit Suggestion link at bottom of posts that has a custom defined template, in that use a textbox (maybe with an editor) that's linked to a custom taxonomy with the default value of post content. Any changes to content will be compared to original post content after submitting (as Draft) and Entering CAPTCHA ...


7

I spent several hours of my Saturday looking for this error. I could not find a guide anywhere on the 'net that described my eventual solution. Here is my solution. In the WP core, the "You do not have sufficient permissions to access this page." error is generated at the end of /wp-admin/includes/menu.php. A grep of my plugin directories also showed that ...


7

This certainly can be done, but it requires some work. I am developing a pretty complex plugin for a client, and I plan to expand on it and make it available publicly when it is ready. Telling you everything would take ages, so I will just give you some pointers on how you can achieve what you are aiming for. Make a page called "Profile" and use a custom ...


7

I suggest not to mess with the existing roles and capabilities in its default, it might help you some trouble when you will have a bunch of custom roles and capabilities in the future. To answer your question, I will have an example: I need new role/user group that has almost an Administrator but don't have the the capability to edit plugins and the theme,...


6

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', '...


6

In short - and for general use - yes. As @s_ha_dum pointed out though, it really depends on what you're using it for. Is the function secure? As @kaiser and @s_ha_dum have mentioned the function is pluggable - meaning that any plug-in (though not themes) can redefine it to do anything. But this isn't really a problem insofar as that plug-ins can do almost ...


5

This code seems to work well for me (in functions.php): add_filter( 'parse_query', 'exclude_pages_from_admin' ); $user_id = get_current_user_id(); if ($user_id == 2) { function exclude_pages_from_admin($query) { global $pagenow,$post_type; if (is_admin() && $pagenow=='edit.php' && $post_type =='page') { $...


5

If I understand you have some categories, eg: 'reserved', 'people', 'landscapes', 'personal' and so on. Now you want that subscribers can see posts in, e.g. 'people', 'landscapes' categories but not posts in 'reserved' and 'personal' categories. This is relatively easy, just hook into pre_get_posts and if the request is for a post having that terms or the ...


5

The manage_options argument you see in both function calls is a capability. That particular capability makes the page accessible only to administrators. To make this work, you could change that to one of the editor capabilities like edit_others_posts You could also create a new capability and use that. However, doing either will mean hacking the plugin ...


5

admin_init runs on admin pages, not the front end. The equivalent front end action, init, is too early to check is_page. A safe action for redirection is template_redirect: function xyz() { if( is_page( 172 ) && ! current_user_can('update_core') ) { wp_redirect( home_url() ); exit; } } add_action( '...


4

Role Scope is very powerful, but I think it's overkill for this. If you set Bob and Smith to have the role of Author (one of the default roles), they'll only be able to edit their own posts.


4

You can do this pretty easily with a shortcode. Hook into init and add the shortcode in your hooked function. <?php add_action('init', 'wpse57819_add_shortcode'); /** * Adds the shortcode * * @uses add_shortcode * @return null */ function wpse57819_add_shortcode() { add_shortcode('restricted', 'wpse57819_shortcode_cb'); } Then in your callback ...


4

Im using remove_role and then add_role to upgrade a user from one role to another. Here is a function that checks all user within the user role subscriber and upgrade them to editor every hour. /** * Add a cron job that will update * Subscribers to editors. Runs hourly */ add_action('check_user_role', 'upgrade_user'); function run_check_user_role() { ...


4

This is a built-in feature of WordPress. Create a page like you normally would. Then look at the Publish box in the upper-right corner for where it says "Visibility: Public." Click "Public" and you'll see some other options - "Private" and "Password Protected." You want "Password Protected." Check the appropriate box and enter the password of your ...


4

We are using this wordpress plug in - New User Approve Provides functionality to approve/deny new user registrations.


4

you can use such conditions to show private posts only to logged in users with role contributor. Now you only need to make post private to make that post available for contributor. <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); $private = get_post_custom_values("private"); if (isset($private[0]) && $private =...


4

Simple answer is yes you can. :) First check out Wordpress's codex here on their RSS feeds. http://codex.wordpress.org/WordPress_Feeds Then what you can do is change the default head rss links that let browsers know that there is an RSS feed. In your theme find: <link rel="alternate" type="application/rss+xml" title="RSS 2.0" href="<?php bloginfo ...


4

Well this is rather complicated, a proper answer would take considerable time to write. So this isn't a real answer just some thoughts.. Using WordPress build in wp_update_post via ajax would give you the needed revision history but not the capability needed to approve edits. Creating drafts from edits is not possible by default but has been discussed ...


Only top voted, non community-wiki answers of a minimum length are eligible