Answers.Body: <p>You can add permissions using the event <code>EVENT_REGISTER_PERMISSIONS</code>:</p>
  <h3>Craft 4</h3>
  <pre class="lang-php prettyprint-override"><code>use craft\events\RegisterUserPermissionsEvent;
  use craft\services\UserPermissions;
  use yii\base\Event;
  
  Event::on(
      UserPermissions::class,
      UserPermissions::EVENT_REGISTER_PERMISSIONS,
      function(RegisterUserPermissionsEvent $event) {
          $event-&gt;permissions[] = [
              'heading' =&gt; 'Permission Group Name',
              'permissions' =&gt; [
                  'permissionName' =&gt; [
                      'label' =&gt; 'Permission Label',
                  ],
              ],
          ];
      }
  );
  </code></pre>
  <h3>Craft 3</h3>
  <pre class="lang-php prettyprint-override"><code>use craft\events\RegisterUserPermissionsEvent;
  use craft\services\UserPermissions;
  use yii\base\Event;
  
  Event::on(
      UserPermissions::class,
      UserPermissions::EVENT_REGISTER_PERMISSIONS,
      function(RegisterUserPermissionsEvent $event) {
          $event-&gt;permissions['Permission Group Name'] = [
              'permissionName' =&gt; [
                  'label' =&gt; 'Permission Label',
              ],
          ];
      }
  );
  </code></pre>
  <p>See the <a href="https://craftcms.com/docs/4.x/extend/user-permissions.html" rel="nofollow noreferrer">documentation on user permissions</a> for details. The example is taken straight from the documentation. In the code above, <code>Permission Group Name</code> should be the name of your plugin. <code>permissionName</code> is the machine name you can use in your code to check for the permission and <code>Permission Label</code> is the human-readable label displayed in the CP.</p>
  <p>See <a href="https://craftcms.com/docs/4.x/extend/user-permissions.html#requiring-permissions" rel="nofollow noreferrer">requiring permissions</a> and <a href="https://craftcms.com/docs/4.x/extend/user-permissions.html#checking-permissions" rel="nofollow noreferrer">checking permissions</a> for details on using permissions in Twig, custom controllers and other code.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-02T10:03:59.610Z
Answers.Text: Craft 4 require a new syntax: https://craftcms.com/docs/4.x/extend/user-permissions.html
Answers.UserDisplayName: Romain P.
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-02T16:10:07.923Z
Answers.Text: @RomainPoirier Thanks for the reminder, I've updated my answer, added the code example for Craft 4 and changed the links to point to the current docs.
Answers.UserDisplayName: MoritzLost
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-01-04T08:56:53.200Z
Answers.LastActivityDate: 2023-05-02T16:09:32.740Z
Answers.LastEditDate: 2023-05-02T16:09:32.740Z
Answers.UserDisplayName: MoritzLost
Body: <p>How can i make plugin permission appear on permissions list, without setting <code>public $hasCpSection = true;</code> in main plugin class?</p>
  <p>For now i set this variable to <code>true</code> and then removed section link like this:</p>
  <pre><code>    public function getCpNavItem()
      {
          return null;
      }
  </code></pre>
  <p>But i am wondering if there is any other way.</p>
  
Tags: <plugin-development>
Title: Make plugin permission appear on permission list, without defining control panel section
ThreadText: # Make plugin permission appear on permission list, without defining control panel section
  
  (Asked by: username_0 on 2022-01-04)
  
  How can i make plugin permission appear on permissions list, without setting `public $hasCpSection = true;` in main plugin class?
  
  For now i set this variable to `true` and then removed section link like this:
  
  ```
      public function getCpNavItem()
      {
          return null;
      }
  
  ```
  
  But i am wondering if there is any other way.
  
  **Tags:** plugin-development
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-01-04. Score: 3
  
  You can add permissions using the event `EVENT_REGISTER_PERMISSIONS`:
  
  ### Craft 4
  
  ```php
  use craft\events\RegisterUserPermissionsEvent;
  use craft\services\UserPermissions;
  use yii\base\Event;
  
  Event::on(
      UserPermissions::class,
      UserPermissions::EVENT_REGISTER_PERMISSIONS,
      function(RegisterUserPermissionsEvent $event) {
          $event->permissions[] = [
              'heading' => 'Permission Group Name',
              'permissions' => [
                  'permissionName' => [
                      'label' => 'Permission Label',
                  ],
              ],
          ];
      }
  );
  
  ```
  
  ### Craft 3
  
  ```php
  use craft\events\RegisterUserPermissionsEvent;
  use craft\services\UserPermissions;
  use yii\base\Event;
  
  Event::on(
      UserPermissions::class,
      UserPermissions::EVENT_REGISTER_PERMISSIONS,
      function(RegisterUserPermissionsEvent $event) {
          $event->permissions['Permission Group Name'] = [
              'permissionName' => [
                  'label' => 'Permission Label',
              ],
          ];
      }
  );
  
  ```
  
  See the [documentation on user permissions](https://craftcms.com/docs/4.x/extend/user-permissions.html) for details. The example is taken straight from the documentation. In the code above, `Permission Group Name` should be the name of your plugin. `permissionName` is the machine name you can use in your code to check for the permission and `Permission Label` is the human-readable label displayed in the CP.
  
  See [requiring permissions](https://craftcms.com/docs/4.x/extend/user-permissions.html#requiring-permissions) and [checking permissions](https://craftcms.com/docs/4.x/extend/user-permissions.html#checking-permissions) for details on using permissions in Twig, custom controllers and other code.
  
  > **Comments:**
  > **username_2**: Craft 4 require a new syntax: https://craftcms.com/docs/4.x/extend/user-permissions.html  
  > **username_1**: @RomainPoirier Thanks for the reminder, I've updated my answer, added the code example for Craft 4 and changed the links to point to the current docs.  
  
  ---
  
  