0

Help with new user wordpress capabilities and roles custom. The media not work upload and display images in galery.

image error: https://i.imgur.com/1bPbcAm.png

code:

if ( get_role('user_products') ) {
    remove_role('user_products');
}

add_action('init','add_my_custom_role');
function add_my_custom_role() {

    add_role( 
      'user_products', 
      __( 'User Products', 'editproducts' ), 
      array(
               'read'            => true,
               'create_posts'      => true,
               'edit_posts'        => true,
               'edit_others_posts' => true,
               'delete_posts' => true,
               'upload_files' => true,
               'upload_medias' => true,                   
               'edit_files' => true,
               'publish_posts' => true,
               'manage_categories' => true,
               'edit_comment' => true,
               'edit_products' => true,
               'edit_others_products' => true,
               'publish_products' => true,
               'delete_products' => true,
               'read_private_products' => true,
               'delete_private_products' => true,
               'edit_private_products' => true,
               'edit_published_products' => true,
               'delete_others_pages' => true,
               'delete_others_posts' => true,
               'delete_pages' => true,
               'delete_private_pages' => true,
               'delete_private_posts' => true,
               'delete_published_pages' => true,
               'delete_published_posts' => true,
               'edit_others_pages' => true,
               'edit_pages' => true,
               'edit_private_pages' => true,
               'edit_private_posts' => true,
               'edit_published_pages' => true,
               'edit_published_posts' => true,
               'manage_links' => true,
               'moderate_comments' => true,
               'publish_pages' => true,
               'read_private_pages' => true,
               'read_private_posts' => true,
               'unfiltered_html' => false,
               'level_3' => true,                   
              // 'edit_attachments' => true,
              // 'delete_attachments' => true,
              // 'read_others_attachments' => true,
              // 'edit_others_attachments' => true,
              // 'delete_others_attachments' => true,

        // Various Capabilities
    ));
}

Code update, i have the same error:

add_action('init','add_my_custom_role');
function add_my_custom_role() {

    add_role( 
      'user_products', 
      __( 'User Products', 'editproducts' ), 
      array(
               'read'            => true,
               'create_posts'      => true,
               'edit_posts'        => true,
               'edit_others_posts' => true,
               'delete_posts' => true,
               'upload_files' => true,
               'upload_medias' => true,                   
               'edit_files' => true,
               'publish_posts' => true,
               'manage_categories' => true,
               'edit_comment' => true,
               'edit_products' => true,
               'edit_others_products' => true,
               'publish_products' => true,
               'delete_products' => true,
               'read_private_products' => true,
               'delete_private_products' => true,
               'edit_private_products' => true,
               'edit_published_products' => true,
               'delete_others_pages' => true,
               'delete_others_posts' => true,
               'delete_pages' => true,
               'delete_private_pages' => true,
               'delete_private_posts' => true,
               'delete_published_pages' => true,
               'delete_published_posts' => true,
               'edit_others_pages' => true,
               'edit_pages' => true,
               'edit_private_pages' => true,
               'edit_private_posts' => true,
               'edit_published_pages' => true,
               'edit_published_posts' => true,
               'manage_links' => true,
               'moderate_comments' => true,
               'publish_pages' => true,
               'read_private_pages' => true,
               'read_private_posts' => true,
               'unfiltered_html' => false,
               'level_3' => true,                   
              // 'edit_attachments' => true,
              // 'delete_attachments' => true,
              // 'read_others_attachments' => true,
              // 'edit_others_attachments' => true,
              // 'delete_others_attachments' => true,

        // Various Capabilities
    ));
}
  • If i'm reading that right, on every page load, you delete and remove that role from the database then recreate it again from scratch? Roles aren't like post type registrations, they're saved to the database – Tom J Nowell May 20 at 23:10
  • Thanks for information! I am delete the code for remove role. – Barbara Ester May 21 at 1:29
  • and i have the same error, image> i.imgur.com/c48k0bB.png – Barbara Ester May 21 at 1:30
0

This happens because on every page load you call remove_role

As the docs note:

When a role is removed, the users who have this role lose all rights on the site.

Roles are not like post types, they exist in the database, and removing/adding a role updates the database. For that reason you shouldn't add them on every page load, it's better to do it on theme activation or plugin activation

  • Thanks for help! i am delete code that remove. i need desable and enable theme for update the role? I have the same error, image> i.imgur.com/c48k0bB.png – Barbara Ester May 21 at 1:31
  • I just have this code with the same error: – Barbara Ester May 21 at 16:50
  • I Solved! Thanks! i delete one code that display text with id of user, he is cause of not work the media right. thanks! – Barbara Ester May 21 at 18:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.