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
PostLink.php
111 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Settings\Column; |
| 4 | |
| 5 | use AC; |
| 6 | use AC\Settings; |
| 7 | use AC\View; |
| 8 | |
| 9 | class PostLink extends Settings\Column |
| 10 | implements Settings\FormatValue { |
| 11 | |
| 12 | /** |
| 13 | * @var string |
| 14 | */ |
| 15 | protected $post_link_to; |
| 16 | |
| 17 | protected function define_options() { |
| 18 | return [ |
| 19 | 'post_link_to' => 'edit_post', |
| 20 | ]; |
| 21 | } |
| 22 | |
| 23 | public function format( $value, $original_value ) { |
| 24 | $id = $original_value; |
| 25 | |
| 26 | switch ( $this->get_post_link_to() ) { |
| 27 | case 'edit_post' : |
| 28 | $link = get_edit_post_link( $id ); |
| 29 | |
| 30 | break; |
| 31 | case 'view_post' : |
| 32 | $link = get_permalink( $id ); |
| 33 | |
| 34 | break; |
| 35 | case 'edit_author' : |
| 36 | $link = get_edit_user_link( ac_helper()->post->get_raw_field( 'post_author', $id ) ); |
| 37 | |
| 38 | break; |
| 39 | case 'view_author' : |
| 40 | $link = get_author_posts_url( ac_helper()->post->get_raw_field( 'post_author', $id ) ); |
| 41 | |
| 42 | break; |
| 43 | default : |
| 44 | $link = false; |
| 45 | } |
| 46 | |
| 47 | if ( $link ) { |
| 48 | $value = ac_helper()->html->link( $link, $value ); |
| 49 | } |
| 50 | |
| 51 | return $value; |
| 52 | } |
| 53 | |
| 54 | public function create_view() { |
| 55 | $select = $this->create_element( 'select' )->set_options( $this->get_display_options() ); |
| 56 | |
| 57 | $view = new View( [ |
| 58 | 'label' => __( 'Link To', 'codepress-admin-columns' ), |
| 59 | 'setting' => $select, |
| 60 | ] ); |
| 61 | |
| 62 | return $view; |
| 63 | } |
| 64 | |
| 65 | protected function get_display_options() { |
| 66 | // Default options |
| 67 | $options = [ |
| 68 | '' => __( 'None' ), |
| 69 | 'edit_post' => __( 'Edit Post' ), |
| 70 | 'view_post' => __( 'View Post' ), |
| 71 | 'edit_author' => __( 'Edit Post Author', 'codepress-admin-columns' ), |
| 72 | 'view_author' => __( 'View Public Post Author Page', 'codepress-admin-columns' ), |
| 73 | ]; |
| 74 | |
| 75 | if ( $this->column instanceof AC\Column\Relation ) { |
| 76 | $relation_options = [ |
| 77 | 'edit_post' => _x( 'Edit %s', 'post' ), |
| 78 | 'view_post' => _x( 'View %s', 'post' ), |
| 79 | 'edit_author' => _x( 'Edit %s Author', 'post', 'codepress-admin-columns' ), |
| 80 | 'view_author' => _x( 'View Public %s Author Page', 'post', 'codepress-admin-columns' ), |
| 81 | ]; |
| 82 | |
| 83 | $label = $this->column->get_relation_object()->get_labels()->singular_name; |
| 84 | |
| 85 | foreach ( $relation_options as $k => $option ) { |
| 86 | $options[ $k ] = sprintf( $option, $label ); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | return $options; |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @return string |
| 95 | */ |
| 96 | public function get_post_link_to() { |
| 97 | return $this->post_link_to; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * @param string $post_link_to |
| 102 | * |
| 103 | * @return bool |
| 104 | */ |
| 105 | public function set_post_link_to( $post_link_to ) { |
| 106 | $this->post_link_to = $post_link_to; |
| 107 | |
| 108 | return true; |
| 109 | } |
| 110 | |
| 111 | } |