BeforeAfter
8 years ago
ActionIcons.php
8 years ago
AttachmentDisplay.php
8 years ago
BeforeAfter.php
8 years ago
CharacterLimit.php
8 years ago
CommentCount.php
8 years ago
CustomField.php
8 years ago
CustomFieldType.php
8 years ago
Date.php
8 years ago
ExifData.php
8 years ago
Image.php
8 years ago
Images.php
8 years ago
Label.php
8 years ago
LinkLabel.php
8 years ago
LinkToMenu.php
8 years ago
Message.php
8 years ago
Meta.php
8 years ago
MissingImageSize.php
8 years ago
NumberOfItems.php
8 years ago
Password.php
8 years ago
PathScope.php
8 years ago
Post.php
8 years ago
PostFormatIcon.php
8 years ago
PostLink.php
8 years ago
PostType.php
8 years ago
Separator.php
8 years ago
StatusIcon.php
8 years ago
StringLimit.php
8 years ago
Taxonomy.php
8 years ago
Term.php
8 years ago
Toggle.php
8 years ago
Type.php
8 years ago
User.php
8 years ago
Width.php
8 years ago
WordLimit.php
8 years ago
WordsPerMinute.php
8 years ago
User.php
188 lines
| 1 | <?php |
| 2 | |
| 3 | if ( ! defined( 'ABSPATH' ) ) { |
| 4 | exit; |
| 5 | } |
| 6 | |
| 7 | class AC_Settings_Column_User extends AC_Settings_Column |
| 8 | implements AC_Settings_FormatValueInterface { |
| 9 | |
| 10 | /** |
| 11 | * @var string |
| 12 | */ |
| 13 | private $display_author_as; |
| 14 | |
| 15 | /** |
| 16 | * @var string |
| 17 | */ |
| 18 | private $user_link_to; |
| 19 | |
| 20 | protected function set_name() { |
| 21 | $this->name = 'user'; |
| 22 | } |
| 23 | |
| 24 | protected function define_options() { |
| 25 | return array( 'display_author_as', 'user_link_to' ); |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * @return AC_View |
| 30 | */ |
| 31 | public function create_view() { |
| 32 | $select = $this->create_element( 'select', 'display_author_as' ) |
| 33 | ->set_attribute( 'data-refresh', 'column' ) |
| 34 | ->set_options( $this->get_display_options() ); |
| 35 | |
| 36 | $display_format = new AC_View( array( |
| 37 | 'label' => __( 'Display', 'codepress-admin-columns' ), |
| 38 | 'setting' => $select, |
| 39 | 'for' => $select->get_id(), |
| 40 | ) ); |
| 41 | |
| 42 | $select = $this->create_element( 'select', 'user_link_to' ) |
| 43 | ->set_attribute( 'data-refresh', 'column' ) |
| 44 | ->set_options( $this->get_link_options() ); |
| 45 | |
| 46 | $link_format = new AC_View( array( |
| 47 | 'label' => __( 'Link To', 'codepress-admin-columns' ), |
| 48 | 'setting' => $select, |
| 49 | 'for' => $select->get_id(), |
| 50 | ) ); |
| 51 | |
| 52 | $view = new AC_View( array( |
| 53 | 'label' => __( 'User', 'codepress-admin-columns' ), |
| 54 | 'sections' => array( $display_format, $link_format ), |
| 55 | ) ); |
| 56 | |
| 57 | return $view; |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * @param int $user_id |
| 62 | * |
| 63 | * @return false|string |
| 64 | */ |
| 65 | public function get_user_name( $user_id ) { |
| 66 | return ac_helper()->user->get_display_name( $user_id, $this->get_display_author_as() ); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * @param $user_id |
| 71 | * |
| 72 | * @return bool|string |
| 73 | */ |
| 74 | private function get_user_link( $user_id ) { |
| 75 | $link = false; |
| 76 | |
| 77 | switch ( $this->get_user_link_to() ) { |
| 78 | |
| 79 | case 'edit_user' : |
| 80 | $link = get_edit_user_link( $user_id ); |
| 81 | |
| 82 | break; |
| 83 | case 'view_user_posts' : |
| 84 | $link = add_query_arg( array( |
| 85 | 'post_type' => $this->column->get_post_type(), |
| 86 | 'author' => get_the_author_meta( 'ID' ), |
| 87 | ), 'edit.php' ); |
| 88 | |
| 89 | break; |
| 90 | case 'view_author' : |
| 91 | $link = get_author_posts_url( $user_id ); |
| 92 | |
| 93 | break; |
| 94 | case 'email_user' : |
| 95 | if ( $email = get_the_author_meta( 'email', $user_id ) ) { |
| 96 | $link = 'mailto:' . $email; |
| 97 | } |
| 98 | |
| 99 | break; |
| 100 | } |
| 101 | |
| 102 | return $link; |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * @return array |
| 107 | */ |
| 108 | private function get_display_options() { |
| 109 | $options = array( |
| 110 | 'display_name' => __( 'Display Name', 'codepress-admin-columns' ), |
| 111 | 'first_name' => __( 'First Name', 'codepress-admin-columns' ), |
| 112 | 'last_name' => __( 'Last Name', 'codepress-admin-columns' ), |
| 113 | 'nickname' => __( 'Nickname', 'codepress-admin-columns' ), |
| 114 | 'user_login' => __( 'User Login', 'codepress-admin-columns' ), |
| 115 | 'user_email' => __( 'User Email', 'codepress-admin-columns' ), |
| 116 | 'ID' => __( 'User ID', 'codepress-admin-columns' ), |
| 117 | 'first_last_name' => __( 'First and Last Name', 'codepress-admin-columns' ), |
| 118 | 'user_nicename' => __( 'User Nicename', 'codepress-admin-columns' ), |
| 119 | 'roles' => __( 'Roles', 'codepress-admin-columns' ), |
| 120 | ); |
| 121 | |
| 122 | // resort for possible translations |
| 123 | natcasesort( $options ); |
| 124 | |
| 125 | return $options; |
| 126 | } |
| 127 | |
| 128 | /** |
| 129 | * @return array |
| 130 | */ |
| 131 | private function get_link_options() { |
| 132 | $options = array( |
| 133 | 'edit_user' => __( 'Edit User Profile', 'codepress-admin-columns' ), |
| 134 | 'email_user' => __( 'User Email', 'codepress-admin-columns' ), |
| 135 | 'view_user_posts' => __( 'View User Posts', 'codepress-admin-columns' ), |
| 136 | 'view_author' => __( 'View Public Author Page', 'codepress-admin-columns' ), |
| 137 | ); |
| 138 | |
| 139 | // resort for possible translations |
| 140 | natcasesort( $options ); |
| 141 | |
| 142 | $options = array_merge( array( '' => __( 'None' ) ), $options ); |
| 143 | |
| 144 | return $options; |
| 145 | } |
| 146 | |
| 147 | /** |
| 148 | * @return string |
| 149 | */ |
| 150 | public function get_display_author_as() { |
| 151 | return $this->display_author_as; |
| 152 | } |
| 153 | |
| 154 | /** |
| 155 | * @param string $display_author_as |
| 156 | * |
| 157 | * @return bool |
| 158 | */ |
| 159 | public function set_display_author_as( $display_author_as ) { |
| 160 | $this->display_author_as = $display_author_as; |
| 161 | |
| 162 | return true; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * @return string |
| 167 | */ |
| 168 | public function get_user_link_to() { |
| 169 | return $this->user_link_to; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * @param string $user_link_to |
| 174 | * |
| 175 | * @return bool |
| 176 | */ |
| 177 | public function set_user_link_to( $user_link_to ) { |
| 178 | $this->user_link_to = $user_link_to; |
| 179 | |
| 180 | return true; |
| 181 | } |
| 182 | |
| 183 | public function format( $value, $original_value ) { |
| 184 | return ac_helper()->html->link( $this->get_user_link( $value ), $this->get_user_name( $value ) ); |
| 185 | } |
| 186 | |
| 187 | } |
| 188 |