field-advanced-link.php
6 years ago
field-button.php
6 years ago
field-clone.php
6 years ago
field-column.php
6 years ago
field-dynamic-message.php
6 years ago
field-file.php
6 years ago
field-flexible-content.php
6 years ago
field-forms.php
6 years ago
field-group.php
6 years ago
field-hidden.php
6 years ago
field-image.php
6 years ago
field-post-statuses.php
6 years ago
field-post-types.php
6 years ago
field-recaptcha.php
6 years ago
field-repeater.php
6 years ago
field-select.php
6 years ago
field-slug.php
6 years ago
field-taxonomies.php
6 years ago
field-taxonomy-terms.php
6 years ago
field-textarea.php
6 years ago
field-user-roles.php
6 years ago
field-slug.php
100 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')) |
| 4 | exit; |
| 5 | |
| 6 | class acfe_field_slug extends acf_field{ |
| 7 | |
| 8 | function __construct(){ |
| 9 | |
| 10 | $this->name = 'acfe_slug'; |
| 11 | $this->label = __('Slug', 'acfe'); |
| 12 | $this->category = 'basic'; |
| 13 | $this->defaults = array( |
| 14 | 'default_value' => '', |
| 15 | 'maxlength' => '', |
| 16 | 'placeholder' => '', |
| 17 | 'prepend' => '', |
| 18 | 'append' => '' |
| 19 | ); |
| 20 | |
| 21 | parent::__construct(); |
| 22 | |
| 23 | } |
| 24 | |
| 25 | function render_field($field){ |
| 26 | |
| 27 | $field['type'] = 'text'; |
| 28 | |
| 29 | acf_get_field_type('text')->render_field($field); |
| 30 | |
| 31 | } |
| 32 | |
| 33 | function render_field_settings($field){ |
| 34 | |
| 35 | // default_value |
| 36 | acf_render_field_setting($field, array( |
| 37 | 'label' => __('Default Value','acf'), |
| 38 | 'instructions' => __('Appears when creating a new post','acf'), |
| 39 | 'type' => 'text', |
| 40 | 'name' => 'default_value', |
| 41 | )); |
| 42 | |
| 43 | |
| 44 | // placeholder |
| 45 | acf_render_field_setting($field, array( |
| 46 | 'label' => __('Placeholder Text','acf'), |
| 47 | 'instructions' => __('Appears within the input','acf'), |
| 48 | 'type' => 'text', |
| 49 | 'name' => 'placeholder', |
| 50 | )); |
| 51 | |
| 52 | |
| 53 | // prepend |
| 54 | acf_render_field_setting($field, array( |
| 55 | 'label' => __('Prepend','acf'), |
| 56 | 'instructions' => __('Appears before the input','acf'), |
| 57 | 'type' => 'text', |
| 58 | 'name' => 'prepend', |
| 59 | )); |
| 60 | |
| 61 | |
| 62 | // append |
| 63 | acf_render_field_setting($field, array( |
| 64 | 'label' => __('Append','acf'), |
| 65 | 'instructions' => __('Appears after the input','acf'), |
| 66 | 'type' => 'text', |
| 67 | 'name' => 'append', |
| 68 | )); |
| 69 | |
| 70 | |
| 71 | // maxlength |
| 72 | acf_render_field_setting($field, array( |
| 73 | 'label' => __('Character Limit','acf'), |
| 74 | 'instructions' => __('Leave blank for no limit','acf'), |
| 75 | 'type' => 'number', |
| 76 | 'name' => 'maxlength', |
| 77 | )); |
| 78 | |
| 79 | } |
| 80 | |
| 81 | function validate_value($valid, $value, $field, $input){ |
| 82 | |
| 83 | $value = sanitize_title($value); |
| 84 | |
| 85 | if($field['maxlength'] && mb_strlen(wp_unslash($value)) > $field['maxlength']) |
| 86 | return sprintf(__('Value must not exceed %d characters', 'acf'), $field['maxlength']); |
| 87 | |
| 88 | return $valid; |
| 89 | |
| 90 | } |
| 91 | |
| 92 | function update_value($value, $post_id, $field){ |
| 93 | |
| 94 | return sanitize_title($value); |
| 95 | |
| 96 | } |
| 97 | |
| 98 | } |
| 99 | |
| 100 | new acfe_field_slug(); |