DateFormat
2 days ago
FieldTypeConfigurator
2 days ago
Media
2 days ago
Post
2 days ago
Pro
2 days ago
ActionIcons.php
2 days ago
AttachmentDisplay.php
2 days ago
BaseComponentFactory.php
2 days ago
BeforeAfter.php
2 days ago
BooleanValues.php
2 days ago
CharacterLimit.php
2 days ago
ColumnInfo.php
2 days ago
CommentDisplay.php
2 days ago
CommentLink.php
2 days ago
CommentStatus.php
2 days ago
CustomField.php
2 days ago
CustomFieldFactory.php
2 days ago
DateFormat.php
2 days ago
DateSaveFormat.php
2 days ago
ExifData.php
2 days ago
FieldType.php
2 days ago
FieldTypeFactory.php
2 days ago
FieldTypeFactoryBuilder.php
2 days ago
FileDisplay.php
2 days ago
FileLink.php
2 days ago
FilePreviewSize.php
2 days ago
HiddenInput.php
2 days ago
HiddenLabel.php
2 days ago
ImageSize.php
2 days ago
ImageSizeBase.php
2 days ago
IncludeMissingSizes.php
2 days ago
InputNameAware.php
2 days ago
IsLink.php
2 days ago
IsLinkable.php
2 days ago
IsMultiple.php
2 days ago
Label.php
2 days ago
LinkLabel.php
2 days ago
LinkToMenu.php
2 days ago
LinkablePostProperty.php
2 days ago
MediaLink.php
2 days ago
Message.php
2 days ago
ModalDisplay.php
2 days ago
Name.php
2 days ago
NumberFormat.php
2 days ago
NumberOfItems.php
2 days ago
Password.php
2 days ago
PathScope.php
2 days ago
PostExtendedProperty.php
2 days ago
PostLink.php
2 days ago
PostProperty.php
2 days ago
PostStatus.php
2 days ago
PostStatusIcon.php
2 days ago
PostType.php
2 days ago
PostTypeFactory.php
2 days ago
RelatedUserMetaField.php
2 days ago
SelectOptions.php
2 days ago
Separator.php
2 days ago
SerializedArrayKeys.php
2 days ago
SerializedDisplay.php
2 days ago
StringLimit.php
2 days ago
Taxonomy.php
2 days ago
TaxonomyFactory.php
2 days ago
TermLink.php
2 days ago
TermProperty.php
2 days ago
UseIcon.php
2 days ago
UserLink.php
2 days ago
UserLinkFactory.php
2 days ago
UserProperty.php
2 days ago
VideoDisplay.php
2 days ago
Width.php
2 days ago
WordLimit.php
2 days ago
WordsPerMinute.php
2 days ago
UserLink.php
67 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC\Setting\ComponentFactory; |
| 6 | |
| 7 | use AC; |
| 8 | use AC\FormatterCollection; |
| 9 | use AC\Setting\Config; |
| 10 | use AC\Setting\Control\Input; |
| 11 | use AC\Setting\Control\Input\OptionFactory; |
| 12 | use AC\Setting\Control\OptionCollection; |
| 13 | use AC\Type\PostTypeSlug; |
| 14 | |
| 15 | final class UserLink extends BaseComponentFactory |
| 16 | { |
| 17 | public const PROPERTY_EDIT_USER = 'edit_user'; |
| 18 | public const PROPERTY_VIEW_POSTS = 'view_user_posts'; |
| 19 | public const PROPERTY_VIEW_AUTHOR = 'view_author'; |
| 20 | public const PROPERTY_EMAIL = 'email_user'; |
| 21 | |
| 22 | private ?PostTypeSlug $post_type; |
| 23 | |
| 24 | public function __construct(?PostTypeSlug $post_type = null) |
| 25 | { |
| 26 | $this->post_type = $post_type; |
| 27 | } |
| 28 | |
| 29 | protected function get_label(Config $config): ?string |
| 30 | { |
| 31 | return __('Link To', 'codepress-admin-columns'); |
| 32 | } |
| 33 | |
| 34 | protected function get_input(Config $config): ?Input |
| 35 | { |
| 36 | return OptionFactory::create_select( |
| 37 | 'user_link_to', |
| 38 | OptionCollection::from_array($this->get_input_options()), |
| 39 | (string)$config->get('user_link_to') |
| 40 | ); |
| 41 | } |
| 42 | |
| 43 | protected function add_formatters(Config $config, FormatterCollection $formatters): void |
| 44 | { |
| 45 | if ($config->get('user_link_to') !== '') { |
| 46 | $formatters->add(new AC\Formatter\User\UserLink($config->get('user_link_to', ''), $this->post_type)); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | protected function get_input_options(): array |
| 51 | { |
| 52 | $args = [ |
| 53 | '' => __('None'), |
| 54 | self::PROPERTY_EDIT_USER => __('Edit User Profile', 'codepress-admin-columns'), |
| 55 | self::PROPERTY_EMAIL => __('User Email', 'codepress-admin-columns'), |
| 56 | self::PROPERTY_VIEW_AUTHOR => __('View Public Author Page', 'codepress-admin-columns'), |
| 57 | ]; |
| 58 | |
| 59 | if ($this->post_type) { |
| 60 | $args[self::PROPERTY_VIEW_POSTS] = __('View User Posts', 'codepress-admin-columns'); |
| 61 | } |
| 62 | |
| 63 | return $args; |
| 64 | } |
| 65 | |
| 66 | } |
| 67 |