Skip to content

Commit

Permalink
Make post type constraint condition more durable
Browse files Browse the repository at this point in the history
  • Loading branch information
NoelLH committed Oct 23, 2020
1 parent 1a25c58 commit f78b66e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions src/PostTypeManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,21 @@ public function getClassName($postType)
return array_key_exists($postType, $classNames) ? $classNames[$postType] : null;
}

/**
* Returns true if the given fully-qualified class name represents a post type
* registered via registerPostTypes().
* @param string $className Fully-qualified name of a class which might be a post type.
* @return bool
*/
public function postClassIsRegistered($className)
{
if (!class_exists($className)) {
return false;
}

return array_key_exists($className, $this->postTypes);
}

/**
* Returns true if the post type was registered via registerPostTypes()
* @param string $postType
Expand Down
4 changes: 2 additions & 2 deletions src/PostTypes/WordpressPost.php
Original file line number Diff line number Diff line change
Expand Up @@ -1081,9 +1081,9 @@ static function isHierarchical($postType = null) {

private static function getSelfPostTypeConstraint()
{
// If `get*()` methods are called on abstract post classes directly (not a subclass), do not
// If `get*()` methods are called on abstract post classes directly (not a registered post subclass), do not
// constrain the type of posts returned unless specified.
if (in_array(static::class, array(self::class, RoutemasterPost::class), true)) {
if (!PostTypeManager::get()->postClassIsRegistered(static::class)) {
return 'any';
}

Expand Down

0 comments on commit f78b66e

Please sign in to comment.