O
O
OlegSedoy2018-06-14 09:28:57
WordPress
OlegSedoy, 2018-06-14 09:28:57

How to create a user for only one plugin?

I am writing a plugin where a user is created, how can I make this user have access only to this plugin?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Sobolev, 2018-06-14
@OlegSedoy

You can create an option in the plugin with a nickname or user id and check it for a match.

function plugin_user_option_settings() {
  global $plugin_option_page; // Страница опций
   
  /* Cекция пользователей */
  add_settings_section( 'plugin_user_section', 'Пользователи плагина', '', $plugin_option_page );
 
  $plugin_users_field_params = array(
    'type'      => 'text', //может быть чекбоксы, селекты и т.д., взависимости от ТЗ 
    'id'        => 'plugin_users',
    'desc'      => 'Пользователи с допуском к UI плагина. Укажите ID, или Ник', 
    'label_for' => 'Пользователи с допуском',    
  );
  add_settings_field( 'plugin_user_section_', 'Пользователи системы', 'plugin_user_option_settings',  $plugin_option_page, 'plugin_user_section', $plugin_users_field_params );
    
}
 
add_action( 'admin_init', 'now_open_option_settings' );

// Код написан в качестве примера. Нужны правки и доработки

In fact, it is not entirely clear on the question what exactly is needed. If access to the user is in the backend, then you need to hide everything superfluous. If in the front, then you can write ajax UI (which is a little more complicated, but more correct)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question