| Total Complexity | 5 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | trait ClassNameAsPostType |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * Class name derived post type identifier |
||
| 9 | * @var string |
||
| 10 | */ |
||
| 11 | protected static $classNamePostType; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * Get the post type identifier for this model |
||
| 15 | * |
||
| 16 | * This method overloads the constant-based default, allowing for |
||
| 17 | * a convenient alternative to hard-coding the post type. |
||
| 18 | * The POST_TYPE constant must take precedence over the derived name, if set. |
||
| 19 | * |
||
| 20 | * @return string post type identifier (slug) |
||
| 21 | */ |
||
| 22 | public static function postTypeId() |
||
| 23 | { |
||
| 24 | if (static::POST_TYPE) { |
||
|
|
|||
| 25 | return static::POST_TYPE; |
||
| 26 | } |
||
| 27 | |||
| 28 | return static::getPostTypeFromName(); |
||
| 29 | } |
||
| 30 | |||
| 31 | /** |
||
| 32 | * Get the post type id from the class name |
||
| 33 | * |
||
| 34 | * @return string |
||
| 35 | */ |
||
| 36 | protected static function getPostTypeFromName() |
||
| 57 | } |
||
| 58 | } |
||
| 59 |