Set a maximum upload count for users on a specific user role

I’m not really sure which is the real problem with code you posted, however I cant understand why use 2 functions when one is enough… add_filter( ‘wp_handle_upload_prefilter’, ‘limit_uploads_for_user_roles’ ); function limit_uploads_for_user_roles( $file ) { $user = wp_get_current_user(); // add the role you want to limit in the array $limit_roles = array(‘contributor’); $filtered = apply_filters( ‘limit_uploads_for_roles’, … Read more

Is WordPress’ is_user_logged_in() secure?

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 … Read more

REST API, get user role?

This is totally possible by registering your own rest field into the response. Here’s some documentation on modifying response data. https://developer.wordpress.org/rest-api/extending-the-rest-api/modifying-responses/ Here’s how to add roles to the endpoint: function get_user_roles($object, $field_name, $request) { return get_userdata($object[‘id’])->roles; } add_action(‘rest_api_init’, function() { register_rest_field(‘user’, ‘roles’, array( ‘get_callback’ => ‘get_user_roles’, ‘update_callback’ => null, ‘schema’ => array( ‘type’ => ‘array’ … Read more

Confusion with adding meta capabilities to a role after registering a Custom Post Type with corresponding ‘capability_type’ parameter

Have you tried defining the capabilities inside the external_roles_post_type_init() function? After the ‘capability_type’ => array(‘external_role’, ‘external_roles’), try add this ‘capabilities’ => array( ‘publish_posts’ => ‘publish_external_roles’, ‘edit_posts’ => ‘edit_external_roles’, ‘edit_others_posts’ => ‘edit_others_external_roles’, ‘delete_posts’ => ‘delete_external_roles’, ‘delete_others_posts’ => ‘delete_others_external_roles’, ‘read_private_posts’ => ‘read_private_external_roles’, ‘edit_post’ => ‘edit_external_role’, ‘delete_post’ => ‘delete_external_role’, ‘read_post’ => ‘read_external_role’, ), as another argument of the … Read more

Temporarily give ‘manage_options’ capability

Good question! The capability checking is probably done quite early in the loading process. By looking at /wp-admin/users.php you can tell that one of the first things to happen is current_user_can( ‘list_users’ ), so that one is clearly needed or you’ll get the “Cheatin’ uh?” warning. But right before that, /wp-admin/admin.php is included, and at … Read more

Creating custom user roles

Adding a role is very simple. Creating custom capabilities is a little bit more to wrap your head around. When you register your custom post type, you define your capabilities for it. Essentially it is an array of “what do you want to count as this?”. My example below will clarify this statement. $caps = … Read more

How to auto-translate custom user roles?

The translate_user_role function is just a wrapper for translate_with_gettext_context, defining the context ‘User role’. In this last function, there is the filter hook gettext_with_context, which provides the context as well as the currently used domain. So we could do this: function wpdev_141551_translate_user_roles( $translations, $text, $context, $domain ) { $plugin_domain = ‘plugin-text-domain’; $roles = array( ‘Someone’, … Read more

How to Change the Entire WordPress Admin panel Look and Feel?

Here’s a great codex article on the topic of creating administration theme: http://codex.wordpress.org/Creating_Admin_Themes And back to your question, you will want to load different stylesheets for different user roles, so you have to check who the current user is. Pay attention, the check is done using current_user_can() function and checking for administrator is not being … Read more

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