can() public method

Check if the user can do a defined capability.
public can ( string $cap ) : boolean
$cap string
return boolean
Esempio n. 1
0
 /**
  * The wrapper install method. Save container values.
  *
  * @param int $postId The post ID value.
  * @return void
  */
 public function save($postId)
 {
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     $nonceName = isset($_POST[Session::nonceName]) ? $_POST[Session::nonceName] : Session::nonceName;
     if (!wp_verify_nonce($nonceName, Session::nonceAction)) {
         return;
     }
     // Grab current custom post type name.
     $postType = get_post_type($postId);
     // Check user capability.
     if ($this->check && $this->datas['postType'] === $postType) {
         if (!$this->user->can($this->capability)) {
             return;
         }
     }
     // Check current post type...avoid to register fields for all registered post type.
     if ($postType !== $this->datas['postType']) {
         return;
     }
     $fields = [];
     // Loop through the registered fields.
     // With sections.
     if (!empty($this->sections)) {
         foreach ($this->datas['fields'] as $fs) {
             $fields = $fs;
         }
     } else {
         $fields = $this->datas['fields'];
     }
     // Register post meta.
     $this->register($postId, $fields);
 }
Esempio n. 2
0
 /**
  * The wrapper install method. Save container values.
  *
  * @param int $postId The post ID value.
  */
 public function save($postId)
 {
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     $nonceName = isset($_POST[$this->nonce]) ? $_POST[$this->nonce] : $this->nonce;
     if (!wp_verify_nonce($nonceName, $this->nonceAction)) {
         return;
     }
     // Grab current custom post type name.
     $postType = get_post_type($postId);
     // Check user capability.
     if ($this->check && $this->datas['postType'] === $postType) {
         if (!$this->user->can($this->capability)) {
             return;
         }
     }
     // Check current post type...avoid to register fields for all registered post type.
     if ($postType !== $this->datas['postType']) {
         return;
     }
     $fields = $this->getFields();
     // Register post meta.
     $this->register($postId, $fields);
 }