コード例 #1
0
ファイル: Base.php プロジェクト: felixarntz/wpdlib
 /**
  * Checks if the slug of the component is valid.
  *
  * @since 0.5.0
  * @param WPDLib\Components\Base $parent the parent component of the component
  * @return bool whether the component slug is valid
  */
 public function is_valid_slug($parent = null)
 {
     if ($this->valid_slug === null) {
         $globalnames = $this->supports_globalslug();
         if ($globalnames !== true) {
             if ($globalnames !== false) {
                 $found = false;
                 $parent = $this->get_parent();
                 if ($parent !== null) {
                     $found = true;
                     while (get_class($parent) != $globalnames) {
                         $parent = $parent->get_parent();
                         if ($parent === null) {
                             $found = false;
                             break;
                         }
                     }
                 }
                 if ($found) {
                     $this->valid_slug = !ComponentManager::exists($this->slug, get_class($this), $parent->slug);
                 } else {
                     $this->valid_slug = !ComponentManager::exists($this->slug, get_class($this));
                 }
             } else {
                 $this->valid_slug = !ComponentManager::exists($this->slug, get_class($this));
             }
         } else {
             ComponentManager::exists($this->slug, get_class($this));
             // just use the function to add the component
             $this->valid_slug = true;
         }
     }
     return $this->valid_slug;
 }