Skip to content

Commit

Permalink
feat(taxonomy): introduce TaxonomyInterface/Trait
Browse files Browse the repository at this point in the history
  • Loading branch information
whizark committed Jan 3, 2016
1 parent aed5822 commit c8b9144
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 0 deletions.
Empty file removed src/Component/Taxonomy/.gitkeep
Empty file.
36 changes: 36 additions & 0 deletions src/Component/Taxonomy/TaxonomyInterface.php
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();
}
58 changes: 58 additions & 0 deletions src/Component/Taxonomy/TaxonomyTrait.php
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;
}
}

0 comments on commit c8b9144

Please sign in to comment.