Attachments.php
1 day ago
Author.php
1 day ago
BeforeMoreContent.php
1 day ago
CommentCount.php
1 day ago
CommentsForPostLink.php
1 day ago
ContentExcerpt.php
1 day ago
DatePublishFormatted.php
1 day ago
Depth.php
1 day ago
DescriptivePostStatus.php
1 day ago
DiscussionStatus.php
1 day ago
Excerpt.php
1 day ago
ExcerptMissingMessage.php
1 day ago
ExcerptRaw.php
1 day ago
FeaturedImage.php
1 day ago
HasCommentStatus.php
1 day ago
IsPasswordProtected.php
1 day ago
IsSticky.php
1 day ago
LastModifiedAuthor.php
1 day ago
Meta.php
1 day ago
ModifiedDate.php
1 day ago
Order.php
1 day ago
PageTemplate.php
1 day ago
Path.php
1 day ago
Permalink.php
1 day ago
PingStatus.php
1 day ago
PostContent.php
1 day ago
PostDate.php
1 day ago
PostDateTimestamp.php
1 day ago
PostFormat.php
1 day ago
PostFormatIcon.php
1 day ago
PostFormatLabel.php
1 day ago
PostLink.php
1 day ago
PostParentId.php
1 day ago
PostReferences.php
1 day ago
PostStatus.php
1 day ago
PostStatusIcon.php
1 day ago
PostTerms.php
1 day ago
PostTermsOriginal.php
1 day ago
PostTitle.php
1 day ago
Property.php
1 day ago
ShortLink.php
1 day ago
Shortcodes.php
1 day ago
Slug.php
1 day ago
ExcerptMissingMessage.php
58 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Formatter\Post; |
| 6 | |
| 7 | use AC\Formatter; |
| 8 | use AC\Helper; |
| 9 | use AC\Helper\Dashicon; |
| 10 | use AC\Type\Value; |
| 11 | |
| 12 | class ExcerptMissingMessage implements Formatter |
| 13 | { |
| 14 | private bool $tooltip; |
| 15 | |
| 16 | public function __construct(bool $tooltip = true) |
| 17 | { |
| 18 | $this->tooltip = $tooltip; |
| 19 | } |
| 20 | |
| 21 | public function format(Value $value): Value |
| 22 | { |
| 23 | $excerpt = $value->get_value(); |
| 24 | if (! $excerpt) { |
| 25 | return $value; |
| 26 | } |
| 27 | |
| 28 | $post = get_post($value->get_id()); |
| 29 | $post_excerpt = $post ? $post->post_excerpt : null; |
| 30 | |
| 31 | if ($post_excerpt) { |
| 32 | return $value; |
| 33 | } |
| 34 | |
| 35 | if ($this->tooltip) { |
| 36 | return $value->with_value( |
| 37 | Helper\Html::create()->tooltip( |
| 38 | Dashicon::create('media-text', 'gray')->render(), |
| 39 | sprintf( |
| 40 | '%s %s', |
| 41 | __('Excerpt is missing.', 'codepress-admin-columns'), |
| 42 | __('Current excerpt is generated from the content.', 'codepress-admin-columns') |
| 43 | ) |
| 44 | ) . $excerpt |
| 45 | ); |
| 46 | } |
| 47 | |
| 48 | return $value->with_value( |
| 49 | sprintf( |
| 50 | '[%s] %s', |
| 51 | __('auto-generated', 'codepress-admin-columns'), |
| 52 | $excerpt |
| 53 | ) |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | } |
| 58 |