After adding the code, the role does not appear in the selection list. Tell me what's wrong? Maybe something prevents the creation of a new role? Since the code is perfect).

register_activation_hook( __FILE__, array( 'mpg', 'mpg_activation' ) ); function mpg_activation(){ add_role('mpg_new', 'New', array( 'read' => true, 'edit_posts' => true, 'delete_posts' => true, 'publish_posts' => true ) ); } 

The function is written in the plugin. Also, certain rights are already prescribed for the custom type of post, which will be managed by the user with the above role.

Instructions read:

  • Do you have exactly the class name - with a small letter, just 'mpg'? Why not array( $this, 'mpg_activation' ) ? - KAGG Design
  • What is $ this for when writing a plugin? wp-kama.ru/function/add_role - cooledit
  • I see that you absolutely do not understand what is written in your register_activation_hook. You will understand why there is an array, then you will understand my question - KAGG Design
  • Thank! Understood!) - cooledit

1 answer 1

Not correctly used the activation function of the register_activation_hook plugin. Right:

 register_activation_hook( __FILE__, 'mpg_activation' ); function mpg_activation(){ add_role('mpg_new', 'New', array( 'read' => true, 'edit_posts' => true, 'delete_posts' => true, 'publish_posts' => true ) ); } 
  • Well, that sorted out. Give the correct kind of activation hook so that other users can figure it out too. - KAGG Design