BeforeAfter
5 years ago
Pro
5 years ago
ActionIcons.php
5 years ago
AttachmentDisplay.php
5 years ago
BeforeAfter.php
5 years ago
CharacterLimit.php
5 years ago
Comment.php
5 years ago
CommentCount.php
5 years ago
CommentLink.php
5 years ago
CustomField.php
5 years ago
CustomFieldType.php
5 years ago
Date.php
5 years ago
DateTimeFormat.php
5 years ago
ExifData.php
5 years ago
Image.php
5 years ago
Images.php
5 years ago
Label.php
5 years ago
LinkLabel.php
5 years ago
LinkToMenu.php
5 years ago
MediaLink.php
5 years ago
Message.php
5 years ago
Meta.php
5 years ago
MissingImageSize.php
5 years ago
NumberFormat.php
5 years ago
NumberOfItems.php
5 years ago
Password.php
5 years ago
PathScope.php
5 years ago
Post.php
5 years ago
PostFormatIcon.php
5 years ago
PostLink.php
5 years ago
PostStatus.php
5 years ago
PostType.php
5 years ago
Pro.php
5 years ago
Separator.php
5 years ago
StatusIcon.php
5 years ago
StringLimit.php
5 years ago
Taxonomy.php
5 years ago
Term.php
5 years ago
TermLink.php
5 years ago
Time.php
5 years ago
Toggle.php
5 years ago
Type.php
5 years ago
User.php
5 years ago
UserLink.php
5 years ago
Width.php
5 years ago
WordLimit.php
5 years ago
WordsPerMinute.php
5 years ago
LinkLabel.php
64 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Settings\Column; |
| 4 | |
| 5 | use AC\Settings; |
| 6 | use AC\View; |
| 7 | |
| 8 | class LinkLabel extends Settings\Column |
| 9 | implements Settings\FormatValue { |
| 10 | |
| 11 | /** |
| 12 | * @var string |
| 13 | */ |
| 14 | private $link_label; |
| 15 | |
| 16 | protected function define_options() { |
| 17 | return [ 'link_label' ]; |
| 18 | } |
| 19 | |
| 20 | public function create_view() { |
| 21 | $view = new View( [ |
| 22 | 'setting' => $this->create_element( 'text' ), |
| 23 | 'label' => __( 'Link Label', 'codepress-admin-columns' ), |
| 24 | 'tooltip' => __( 'Leave blank to display the URL', 'codepress-admin-columns' ), |
| 25 | ] ); |
| 26 | |
| 27 | return $view; |
| 28 | } |
| 29 | |
| 30 | /** |
| 31 | * @return string |
| 32 | */ |
| 33 | public function get_link_label() { |
| 34 | return $this->link_label; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * @param string $link_label |
| 39 | * |
| 40 | * @return bool |
| 41 | */ |
| 42 | public function set_link_label( $link_label ) { |
| 43 | $this->link_label = $link_label; |
| 44 | |
| 45 | return true; |
| 46 | } |
| 47 | |
| 48 | public function format( $value, $original_value ) { |
| 49 | $url = $value; |
| 50 | |
| 51 | if ( filter_var( $url, FILTER_VALIDATE_URL ) && preg_match( '/[^\w.-]/', $url ) ) { |
| 52 | $label = $this->get_value(); |
| 53 | |
| 54 | if ( ! $label ) { |
| 55 | $label = $url; |
| 56 | } |
| 57 | |
| 58 | $value = ac_helper()->html->link( $url, $label ); |
| 59 | } |
| 60 | |
| 61 | return $value; |
| 62 | } |
| 63 | |
| 64 | } |