Image
2 days ago
Select
2 days ago
Arrays.php
2 days ago
AvailableTranslations.php
2 days ago
Creatable.php
2 days ago
Dashicon.php
2 days ago
Date.php
2 days ago
Html.php
2 days ago
Icon.php
2 days ago
Image.php
2 days ago
LocalFile.php
2 days ago
Mbstring.php
2 days ago
MediaIdResolver.php
2 days ago
Menu.php
2 days ago
Network.php
2 days ago
Post.php
2 days ago
Strings.php
2 days ago
Taxonomy.php
2 days ago
User.php
2 days ago
UserRoles.php
2 days ago
WpDateFormat.php
2 days ago
Post.php
73 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Helper; |
| 6 | |
| 7 | use AC\Formatter\Post\PostStatusIcon; |
| 8 | use AC\Type\Value; |
| 9 | use WP_Post; |
| 10 | |
| 11 | class Post extends Creatable |
| 12 | { |
| 13 | /** |
| 14 | * @param string[]|null $post_types |
| 15 | * @param string[]|null $post_stati |
| 16 | */ |
| 17 | public function count_user_posts(int $user_id, ?array $post_types = null, ?array $post_stati = null): int |
| 18 | { |
| 19 | global $wpdb; |
| 20 | |
| 21 | $where = ['post_author = %d']; |
| 22 | $params = [$user_id]; |
| 23 | |
| 24 | if ($post_stati) { |
| 25 | $where[] = sprintf('post_status IN (%s)', implode(',', array_fill(0, count($post_stati), '%s'))); |
| 26 | $params = array_merge($params, array_values($post_stati)); |
| 27 | } |
| 28 | if ($post_types) { |
| 29 | $where[] = sprintf('post_type IN (%s)', implode(',', array_fill(0, count($post_types), '%s'))); |
| 30 | $params = array_merge($params, array_values($post_types)); |
| 31 | } |
| 32 | |
| 33 | $sql = sprintf("SELECT COUNT(*) FROM $wpdb->posts WHERE %s", implode(' AND ', $where)); |
| 34 | |
| 35 | return (int)$wpdb->get_var($wpdb->prepare($sql, $params)); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * @deprecated 7.0.13 Use get_post_field( $field, $id, 'raw' ) instead. |
| 40 | */ |
| 41 | public function get_raw_field(string $field, int $id): ?string |
| 42 | { |
| 43 | _deprecated_function(__METHOD__, '7.0.13', "get_post_field( \$field, \$id, 'raw' )"); |
| 44 | |
| 45 | $value = get_post_field($field, $id, 'raw'); |
| 46 | |
| 47 | return is_string($value) && '' !== $value |
| 48 | ? $value |
| 49 | : null; |
| 50 | } |
| 51 | |
| 52 | /* |
| 53 | * @deprecated since 7.0.9 |
| 54 | */ |
| 55 | public function get_status_icon(WP_Post $post): ?string |
| 56 | { |
| 57 | _deprecated_function(__METHOD__, '7.0.9'); |
| 58 | |
| 59 | return (string)(new PostStatusIcon())->format(new Value($post->ID, $post)); |
| 60 | } |
| 61 | |
| 62 | /* |
| 63 | * @deprecated since 7.0.9 |
| 64 | */ |
| 65 | public function get_title(): string |
| 66 | { |
| 67 | _deprecated_function(__METHOD__, '7.0.9'); |
| 68 | |
| 69 | return ''; |
| 70 | } |
| 71 | |
| 72 | } |
| 73 |