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
CustomField.php
114 lines
| 1 | <?php |
| 2 | |
| 3 | namespace AC\Settings\Column; |
| 4 | |
| 5 | use AC; |
| 6 | use AC\Settings; |
| 7 | use AC\View; |
| 8 | |
| 9 | class CustomField extends Settings\Column { |
| 10 | |
| 11 | const NAME = 'custom_field'; |
| 12 | |
| 13 | /** |
| 14 | * @var string |
| 15 | */ |
| 16 | private $field; |
| 17 | |
| 18 | protected function define_options() { |
| 19 | return [ 'field' ]; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * @return View |
| 24 | */ |
| 25 | public function create_view() { |
| 26 | $view = new View( [ |
| 27 | 'label' => __( 'Field', 'codepress-admin-columns' ), |
| 28 | 'setting' => $this->get_setting_field(), |
| 29 | ] ); |
| 30 | |
| 31 | return $view; |
| 32 | } |
| 33 | |
| 34 | protected function set_name() { |
| 35 | $this->name = self::NAME; |
| 36 | } |
| 37 | |
| 38 | private function use_text_field() { |
| 39 | return (bool) apply_filters( 'ac/column/custom_field/use_text_input', false ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * @return AC\Form\Element\Input |
| 44 | */ |
| 45 | private function get_settings_field_text() { |
| 46 | return $this->create_element( 'text', 'field' ) |
| 47 | ->set_attribute( 'placeholder', 'Custom field key' ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * @return AC\Form\Element\Select |
| 52 | */ |
| 53 | private function get_settings_field_select() { |
| 54 | $options = $this->get_field() |
| 55 | ? [ $this->get_field() => $this->get_field() ] |
| 56 | : []; |
| 57 | |
| 58 | return $this->create_element( 'select', 'field' ) |
| 59 | ->set_attribute( 'data-selected', $this->get_field() ) |
| 60 | ->set_attribute( 'data-post_type', $this->get_post_type() ) |
| 61 | ->set_attribute( 'data-type', $this->get_meta_type() ) |
| 62 | ->set_options( $options ) |
| 63 | ->set_attribute( 'class', 'custom_field' ); |
| 64 | } |
| 65 | |
| 66 | /** |
| 67 | * @return AC\Form\Element |
| 68 | */ |
| 69 | protected function get_setting_field() { |
| 70 | return $this->use_text_field() |
| 71 | ? $this->get_settings_field_text() |
| 72 | : $this->get_settings_field_select(); |
| 73 | } |
| 74 | |
| 75 | public function get_dependent_settings() { |
| 76 | return [ new Settings\Column\CustomFieldType( $this->column ) ]; |
| 77 | } |
| 78 | |
| 79 | protected function get_meta_type() { |
| 80 | return $this->column->get_list_screen()->get_meta_type(); |
| 81 | } |
| 82 | |
| 83 | /** |
| 84 | * @return string Post type |
| 85 | */ |
| 86 | protected function get_post_type() { |
| 87 | return $this->column->get_post_type(); |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @return string |
| 92 | */ |
| 93 | public function get_field() { |
| 94 | return $this->field; |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * @param string $field |
| 99 | * |
| 100 | * @return self |
| 101 | */ |
| 102 | public function set_field( $field ) { |
| 103 | |
| 104 | // Backwards compatible for WordPress Settings API not storing fields starting with _ |
| 105 | if ( 0 === strpos( $field, 'cpachidden' ) ) { |
| 106 | $field = substr( $field, strlen( 'cpachidden' ) ); |
| 107 | } |
| 108 | |
| 109 | $this->field = $field; |
| 110 | |
| 111 | return $this; |
| 112 | } |
| 113 | |
| 114 | } |