Organize capabilities and user levels wordpress (no plugin)

3

First I will explain the scenario, I want to make a system where you will have 4 different types of people accessing. The Administrator, "moderators", authors, and partners. I wanted to use the wordpress admin panel for everything, so I created a post_type partner. In this system, each partner can have a page on the site. And also, use the standard blog (blog) system of wordpress. So to manage all of this I thought about changing the existing roles to be organized this way:

ROLES:
  ADMIN -
    all

  Editor -
    Pode Cadastrar novo post
    Ver todos os posts de qualquer autor
    Editar o post de qualquer autor
    Publicar posts e deixar para revisão pendente

    Cadastrar página de parceiro
    Ver todas as páginas de parceiros
    Editar as páginas de parceiros de qualquer autor
    Publicar página de parceiro e deixar para revisão pendente

  Autor -
    Pode cadastrar novo post
    ver apenas seus proprios posts
    editar apenas seus proprios posts
    não pode publicar (sempre lançar como revisão)

  Colaborador -
    Ver apenas as suas página de parceiro
    Editar apenas sua página de parceiro
    Não pode publicar página de parceiro (sempre lançar como revisão)

  Subscriber -
    Nada!

So the question has arisen, is this the best way to organize it? Or it would be better to create new roles (at least to manage the partners).

And besides, now technical doubts, to create capabilities new in a custom post_type , would be passing the capabilities argument in this way:

'capabilities' => array(
  'edit_post' => 'edit_partner',
  'edit_posts' => 'edit_partners',
  'edit_others_posts' => 'edit_other_partners',
  'publish_posts' => 'publish_partners',
  'read_post' => 'read_partner',
  'read_private_posts' => 'read_private_partners',
  'delete_post' => 'delete_partner'
)

And then add in each role:

$admins = get_role( 'administrator' );
$admins->add_cap( 'edit_post' );
$admins->add_cap( 'edit_posts' );
$admins->add_cap( 'edit_others_posts' );
$admins->add_cap( 'publish_posts' );
$admins->add_cap( 'read_post' );
$admins->add_cap( 'read_private_posts' );
$admins->add_cap( 'delete_post' );

$editors = get_role( 'editor' );
$editors->add_cap( 'edit_post' );
$editors->add_cap( 'edit_posts' );
$editors->add_cap( 'edit_others_posts' );
$editors->add_cap( 'publish_posts' );
$editors->add_cap( 'read_post' );
$editors->add_cap( 'read_private_posts' );
$editors->add_cap( 'delete_post' );

$partners = get_role( 'subscriber' );
$partners->add_cap( 'edit_post' );

I tried exactly as I showed above, but it did not register the custom post_type with the argument capabilities .

In short: I do not know if it's right to tweak% s of%% of% wordpress patterns, and not even how to do that And I also do not know how to give permission for only capabilities , I did not want roles users to view / change / edit normal posts, only custom post_type , and yet, only the link to his user. And even if Colaboradores users could view / edit / change post_type parceiro .

Thank you.

    
asked by anonymous 19.09.2017 / 23:08

1 answer

1

Individual user login on Wordpress

You can download a plugin for roler .. another for redirection and create a new template as well

<?php
/*
Template Name: Página de login
*/
get_header();

// Dados do formulário de login
$argumentos_login = array(
    'echo'           => true,
    'redirect' => ( is_ssl() ? 'https://' : 'http://' ) . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'],
    'form_id'        => 'tp-login-form',
    'label_username' => __( 'Username' ),
    'label_password' => __( 'Password' ),
    'label_remember' => __( 'Remember Me' ),
    'label_log_in'   => __( 'Log In' ),
    'id_username'    => 'tp-user-login',
    'id_password'    => 'tp-user-pass',
    'id_remember'    => 'tp-remember-me',
    'id_submit'      => 'tp-submit-btn',
    'remember'       => true,
    'value_username' => null,
    'value_remember' => false,
);
?>
<style type="text/css">
<!--
.tp-login-container {
    text-align: center;
}
-->
</style>


<p>&nbsp;</p>
<p>&nbsp;</p>
<div class="tp-login-container">

    <?php if ( ! is_user_logged_in() ): ?>

        <?php wp_login_form( $argumentos_login );?>

    <?php 
    else:

        // Usuário atual
        $usuario_atual = wp_get_current_user();

        // URL da página SAIR DA AREA VIP
        $pagina_login = ' http://localhost/natureza/';

        // Mensagem para o usuário
        echo '<p>Você já fez login <b>' . $usuario_atual->user_firstname . '</b>.';
        echo ' Clique <a href="' . wp_logout_url( $pagina_login ) . '">aqui</a>';
        echo ' para sair.';
        echo '</p>'; 

    endif; // is_user_logged_in
    ?>

</div> <!-- tp-login-container -->

<?php
get_footer();
?>

..

Then just create the new page .. add the new template .. then the login is ready

Then you go to Users > Role > Add role , create a role with the user name .. or department name .. the role can be individual or for groups.

If it is for single user it is important to create an individual role if not, it can be one for many users.

We create the role (role or function of each user) with the name of the user, as each has access to their reserved area.

After registering the user and we give permission, there are several types of permissions, for subscriber I left checked only the option Read , the user being registered the next step is to do the redirection, paper) was already created in the first step, the last step is to just add the redirect with a redirect plugin that works. Ask me how .. rerere

    
20.10.2017 / 22:54