-
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(post-type): introduce PostTypeInterface/Trait
- Loading branch information
Showing
3 changed files
with
113 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,54 @@ | ||
<?php | ||
/** | ||
* PostType Interface | ||
* | ||
* @author Whizark <devaloka@whizark.com> | ||
* @see http://whizark.com | ||
* @copyright Copyright (C) 2014 Whizark. | ||
* @license MIT | ||
*/ | ||
|
||
namespace Devaloka\Component\PostType; | ||
|
||
use Devaloka\Component\Taxonomy\TaxonomyInterface; | ||
|
||
/** | ||
* Interface PostTypeInterface | ||
* | ||
* @package Devaloka\Component\PostType | ||
* | ||
* @codeCoverageIgnore | ||
*/ | ||
interface PostTypeInterface | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getName(); | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function getOptions(); | ||
|
||
/** | ||
* @param TaxonomyInterface $taxonomy | ||
*/ | ||
public function addTaxonomy(TaxonomyInterface $taxonomy); | ||
|
||
/** | ||
* @return \Devaloka\Component\Taxonomy\TaxonomyInterface[] An array of taxonomy ID(s) that will be registered for | ||
* the Post Type. | ||
*/ | ||
public function getTaxonomies(); | ||
|
||
/** | ||
* @return object|\WP_Error The registered post type object, or an error object. | ||
*/ | ||
public function register(); | ||
|
||
/** | ||
* @return bool|\WP_Error True on success, WP_Error on failure. | ||
*/ | ||
public function unregister(); | ||
} |
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,59 @@ | ||
<?php | ||
/** | ||
* PostType 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\Component\PostType; | ||
|
||
use Devaloka\Component\Taxonomy\TaxonomyInterface; | ||
use LogicException; | ||
|
||
/** | ||
* Trait PostTypeTrait | ||
* | ||
* @package Devaloka\Component\PostType | ||
* | ||
* @codeCoverageIgnore | ||
*/ | ||
trait PostTypeTrait | ||
{ | ||
protected $taxonomies = []; | ||
|
||
public function addTaxonomy(TaxonomyInterface $taxonomy) | ||
{ | ||
$this->taxonomies[$taxonomy->getName()] = $taxonomy; | ||
} | ||
|
||
public function register() | ||
{ | ||
/** @var PostTypeInterface $this */ | ||
|
||
$options = $this->getOptions(); | ||
$taxonomies = []; | ||
|
||
foreach ($this->getTaxonomies() as $taxonomy) { | ||
$taxonomies[] = $taxonomy->getName(); | ||
} | ||
|
||
$options['taxonomies'] = $taxonomies; | ||
|
||
return register_post_type($this->getName(), $options); | ||
} | ||
|
||
/** | ||
* @throws LogicException | ||
* | ||
* @see https://core.trac.wordpress.org/ticket/14761 #14761 (unregister_post_type()) – WordPress Trac | ||
*/ | ||
public function unregister() | ||
{ | ||
throw new LogicException('unregister() is not implemented yet.'); | ||
} | ||
} |