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-image.php
80 lines
| 1 | <?php |
| 2 | |
| 3 | if(!defined('ABSPATH')) |
| 4 | exit; |
| 5 | |
| 6 | add_filter('gettext', 'acfe_field_image_text', 99, 3); |
| 7 | function acfe_field_image_text($translated_text, $text, $domain){ |
| 8 | |
| 9 | if($domain !== 'acf') |
| 10 | return $translated_text; |
| 11 | |
| 12 | if($text === 'No image selected') |
| 13 | return ''; |
| 14 | |
| 15 | return $translated_text; |
| 16 | |
| 17 | } |
| 18 | |
| 19 | add_action('acf/render_field_settings/type=image', 'acfe_field_image_settings', 0); |
| 20 | function acfe_field_image_settings($field){ |
| 21 | |
| 22 | acf_render_field_setting($field, array( |
| 23 | 'label' => __('Uploader type'), |
| 24 | 'name' => 'acfe_uploader', |
| 25 | 'key' => 'acfe_uploader', |
| 26 | 'instructions' => __('Choose the uploader type'), |
| 27 | 'type' => 'radio', |
| 28 | 'choices' => array( |
| 29 | 'wp' => 'Media', |
| 30 | 'basic' => 'Basic', |
| 31 | ), |
| 32 | 'allow_null' => 0, |
| 33 | 'other_choice' => 0, |
| 34 | 'default_value' => '', |
| 35 | 'layout' => 'horizontal', |
| 36 | 'return_format' => 'value', |
| 37 | 'save_other_choice' => 0, |
| 38 | )); |
| 39 | |
| 40 | acf_render_field_setting($field, array( |
| 41 | 'label' => __('Featured thumbnail'), |
| 42 | 'name' => 'acfe_thumbnail', |
| 43 | 'key' => 'acfe_thumbnail', |
| 44 | 'instructions' => __('Make this image the featured thumbnail'), |
| 45 | 'type' => 'true_false', |
| 46 | 'default_value' => false, |
| 47 | 'ui' => true, |
| 48 | 'ui_on_text' => '', |
| 49 | 'ui_off_text' => '', |
| 50 | 'required' => false, |
| 51 | )); |
| 52 | |
| 53 | } |
| 54 | |
| 55 | add_filter('acf/prepare_field/type=image', 'acfe_field_image_uploader_type'); |
| 56 | function acfe_field_image_uploader_type($field){ |
| 57 | |
| 58 | if(!isset($field['acfe_uploader']) || empty($field['acfe_uploader'])) |
| 59 | return $field; |
| 60 | |
| 61 | acf_update_setting('uploader', $field['acfe_uploader']); |
| 62 | |
| 63 | return $field; |
| 64 | |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Field Value Update |
| 69 | */ |
| 70 | add_filter('acf/update_value/type=image', 'acfe_thumbnail_update', 10, 3); |
| 71 | function acfe_thumbnail_update($value, $post_id, $field){ |
| 72 | |
| 73 | if(!isset($field['acfe_thumbnail']) || empty($field['acfe_thumbnail']) || empty($value) || empty(get_post_type($post_id))) |
| 74 | return $value; |
| 75 | |
| 76 | update_post_meta($post_id, '_thumbnail_id', $value); |
| 77 | |
| 78 | return $value; |
| 79 | |
| 80 | } |