Organize capabilities and levels of wordpress users (no plugin)

Asked

Viewed 147 times

3

First I’ll explain the scenario, I want to make a system where there will be four different types of people accessing it. The Administrator, "moderators", authors, and partners. I wanted to use the wordpress admin panel itself 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 default wordpress posts (blog) system. So to manage all this I thought I’d change the roles existing to be organized in 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!

When the doubt arose, is this the best way to organize it? Or would it 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 argument capabilities in that 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 roll:

$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' );

Because I tried exactly as shown above, but he did not register the custom post_type with the argument capabilities.

To summarize: I don’t know if it’s right to touch capabilities of roles wordpress patterns, and not exactly how to do it And I also don’t know how to give permission only to one custom post_type, I didn’t want the users Colaboradores could see/change/edit normal posts, only the post_type parceiro, and yet, only the link to the user of it. And nor that users Autores can see/edit/change the post_type parceiro.

Thank you.

1 answer

1


Individual user login on Wordpress

You can download a plugin for roler.. another for redirecting and create a new template like this

<?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 login is ready

Then you go on Users > Roll > 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 created the role (role or function of each user) with the name of the user, because each has its access to its reserved area.

After we register the user and give permission, has several types of permissions, for subscriber I left checked only the option Read, the user being registered the next step is to redirect, as the role(paper) has already been created in the first step, the last step is to just add the redirect with a plugin redirect that’s right. Ask me how.. rerere

Browser other questions tagged

You are not signed in. Login or sign up in order to post.