22

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 ) ) ;...


19

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

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

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


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

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

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


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

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): $user_id = get_current_user_id(); if ($user_id == 2) { add_filter( 'parse_query', 'exclude_pages_from_admin' ); } function exclude_pages_from_admin($query) { global $pagenow,$post_type; if (is_admin() && $pagenow=='edit.php' && $post_type =='page') { $query->...


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

something like this : https://codex.wordpress.org/Function_Reference/add_role then if ( current_user_can('new_role') && !current_user_can('upload_files') ) add_action('admin_init', 'allow_new_role_uploads'); function allow_new_role_uploads() { $new_role = get_role('new_role'); $new_role->add_cap('upload_files'); }


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

I created a simple plugin that will allow you to do this without messing around with code. The message displayed to disabled users is also filterable. http://wordpress.org/plugins/disable-users/


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


4

This is impossible to answer definitively without a better description, but I am assuming that app.php is a completely distinct piece of code. In which case, WordPress can't really manage access to it. You will need to incorporate it into WordPress. While this is not the only way to do it I would advise: Create a custom page template for the app. In that ...


4

It won't let me comment, so I'm adding this as a new answer. The error: Warning: "call_user_func_array() expects parameter 1 to be a valid callback, >function 'exclude_pages_from_admin' not found or invalid function name". ... is due to the function being called only after the user_id is checked. So if you're logged in NOT as that user, the function ...


4

You might consider changing the user_nicename as well via the SQL query. Once this is done, all permalinks and other functions will work perfect.


4

Well, you have to ask yourself "Secure enough for what?" I doubt you are a bank or other institution that needs exceptionally high security. If you were you'd a team of $100,000+ per year experts to answer this question for you. With that in mind... You'd have to subvert the WordPress login system to get past that code. I am sure that is possible but if ...


4

Pluggable functions First off, pluggables are loaded from within the ~/wp-settings.php file. They are included after all plug-in files have been included (but before plugins_loaded) so any plugin can replace them. (mu-plugins are included even earlier, so they take precedence). Obstacles for a hack The default user will never worry about this, as (s)he ...


4

You can try this: /** * Is the current user registred for more than x days ago? * * Based on the compare idea in this answer: * http://stackoverflow.com/a/7130744/2078474 * * @link http://wordpress.stackexchange.com/a/143597/26350 * @param int $reg_days_ago * @return bool */ function is_user_reg_matured( $reg_days_ago = 30 ) { $cu = ...


4

Just a quick note, the code define('FORCE_SSL_ADMIN', true); if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') $_SERVER['HTTPS']='on'; need to be at the top of the config file just after the <php or it will not work.


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