-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(taxonomy): introduce TaxonomyInterface/Trait
- Loading branch information
Showing
3 changed files
with
94 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* Taxonomy Interface | ||
* | ||
* @author Whizark <devaloka@whizark.com> | ||
* @see http://whizark.com | ||
* @copyright Copyright (C) 2014 Whizark. | ||
* @license MIT | ||
*/ | ||
|
||
namespace Devaloka\Commponent\Taxonomy; | ||
|
||
/** | ||
* Interface TaxonomyInterface | ||
* | ||
* @package Devaloka\Commponent\Taxonomy | ||
* | ||
* @codeCoverageIgnore | ||
*/ | ||
interface TaxonomyInterface | ||
{ | ||
/** | ||
* @return string $taxonomy The taxonomy key (must not exceed 32 characters). | ||
*/ | ||
public function getName(); | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function getOptions(); | ||
|
||
/** | ||
* @return null|\WP_Error WP_Error if errors, otherwise null. | ||
*/ | ||
public function register(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
<?php | ||
/** | ||
* Taxonomy Trait | ||
* | ||
* @author Whizark <devaloka@whizark.com> | ||
* @see http://whizark.com | ||
* @copyright Copyright (C) 2015 Whizark. | ||
* @license MIT | ||
* @license GPL-2.0 | ||
* @license GPL-3.0 | ||
*/ | ||
|
||
namespace Devaloka\Taxonomy; | ||
|
||
/** | ||
* Trait TaxonomyTrait | ||
* | ||
* @package Devaloka\Taxonomy | ||
* | ||
* @codeCoverageIgnore | ||
*/ | ||
trait TaxonomyTrait | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
protected $objectTypes = []; | ||
|
||
public function getOptions() | ||
{ | ||
return []; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function register() | ||
{ | ||
/** @var TaxonomyInterface $this */ | ||
|
||
return register_taxonomy($this->getName(), $this->objectTypes, $this->getOptions()); | ||
} | ||
|
||
public function unregister() | ||
{ | ||
if (count($this->objectTypes) < 1) { | ||
return false; | ||
} | ||
|
||
foreach ($this->objectTypes as $objectType) { | ||
if (!unregister_taxonomy_for_object_type($this->getName(), $objectType)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
} |