AlertProvider.php
11 months ago
ApiClient.php
11 months ago
DateTimeHelper.php
11 months ago
DateTimes.php
11 months ago
DateTimesImmutable.php
11 months ago
Debugger.php
11 months ago
DisplayHelper.php
11 months ago
EmailHelper.php
11 months ago
PostTypeHelper.php
11 months ago
Random.php
11 months ago
SecurityValidator.php
11 months ago
ShortcodeSubstitutor.php
11 months ago
TemplateProvider.php
11 months ago
functions.php
11 months ago
PostTypeHelper.php
40 lines
| 1 | <?php |
| 2 | |
| 3 | namespace FapiMember\Utils; |
| 4 | |
| 5 | class PostTypeHelper |
| 6 | { |
| 7 | public static array $excludedPostTypePrefixes = ['jet-', 'elementor_', 'elemental_']; |
| 8 | |
| 9 | /** |
| 10 | * @return array<string> |
| 11 | */ |
| 12 | public static function getSupportedPostTypes(bool $cptOnly = false): array |
| 13 | { |
| 14 | $supportedPostTypes = []; |
| 15 | $excludedPostTypes = $cptOnly ? ['attachment', 'page', 'post'] : ['attachment']; |
| 16 | $supportedPostTypesObjects = get_post_types(['public' => true], 'objects'); |
| 17 | |
| 18 | foreach ($supportedPostTypesObjects as $obj) { |
| 19 | $name = $obj->name; |
| 20 | |
| 21 | if (in_array($name, $excludedPostTypes, true)) { |
| 22 | continue; |
| 23 | } |
| 24 | |
| 25 | foreach (self::$excludedPostTypePrefixes as $prefix) { |
| 26 | if (str_starts_with($name, $prefix)) { |
| 27 | continue 2; |
| 28 | } |
| 29 | } |
| 30 | |
| 31 | $supportedPostTypes[] = $name; |
| 32 | } |
| 33 | |
| 34 | sort($supportedPostTypes); |
| 35 | |
| 36 | return $supportedPostTypes; |
| 37 | } |
| 38 | |
| 39 | } |
| 40 |