PluginProbe ʕ •ᴥ•ʔ
Advanced Custom Fields: Extended / 0.9.2.7
Advanced Custom Fields: Extended v0.9.2.7
0.9.2.7 0.9.2.6 0.9.2.5 0.8.6 0.8.6.1 0.8.6.3 0.8.6.5 0.8.6.6 0.8.6.7 0.8.6.8 0.8.6.9 0.8.7 0.8.7.1 0.8.7.2 0.8.7.3 0.8.7.4 0.8.7.5 0.8.7.6 0.8.8 0.8.8.1 0.8.8.10 0.8.8.11 0.8.8.2 0.8.8.3 0.8.8.4 0.8.8.5 0.8.8.6 0.8.8.7 0.8.8.8 0.8.8.9 0.8.9 0.8.9.1 0.8.9.2 0.8.9.3 0.8.9.4 0.8.9.5 0.9 0.9.0.1 0.9.0.2 0.9.0.3 0.9.0.4 0.9.0.5 0.9.0.6 0.9.0.7 0.9.0.8 0.9.0.9 0.9.1 0.9.1.1 0.9.2 0.9.2.1 0.9.2.2 0.9.2.3 0.9.2.4 trunk 0.5 0.5.1 0.5.2 0.5.2.1 0.5.2.3 0.5.5 0.5.5.1 0.5.8 0.5.8.1 0.6 0.6.0.1 0.6.0.2 0.6.1 0.6.3 0.6.5 0.6.7 0.6.7.2 0.7 0.7.0.3 0.7.5 0.7.5.5 0.7.8 0.7.9 0.7.9.3 0.7.9.4 0.7.9.9.8 0.7.9.9.9 0.8 0.8.1 0.8.2 0.8.3 0.8.3.1 0.8.4 0.8.4.1 0.8.4.5 0.8.4.6 0.8.5 0.8.5.5
acf-extended / includes / fields / field-image.php
acf-extended / includes / fields Last commit date
field-advanced-link.php 3 months ago field-button-group.php 1 week ago field-button.php 7 months ago field-checkbox.php 3 months ago field-clone.php 2 years ago field-code-editor.php 3 months ago field-column.php 3 years ago field-dynamic-render.php 3 years ago field-file.php 3 months ago field-flexible-content-actions-title.php 3 months ago field-flexible-content-actions-toggle.php 3 months ago field-flexible-content-actions.php 3 months ago field-flexible-content-async.php 4 months ago field-flexible-content-compatibility.php 3 months ago field-flexible-content-controls.php 9 months ago field-flexible-content-hide.php 3 months ago field-flexible-content-hooks.php 9 months ago field-flexible-content-modal-edit.php 9 months ago field-flexible-content-modal-select.php 3 months ago field-flexible-content-modal-settings.php 3 months ago field-flexible-content-popup.php 3 months ago field-flexible-content-preview.php 3 months ago field-flexible-content-state.php 9 months ago field-flexible-content-thumbnail.php 9 months ago field-flexible-content-wysiwyg.php 9 months ago field-flexible-content.php 3 months ago field-forms.php 3 months ago field-gallery.php 3 months ago field-google-map.php 3 months ago field-group.php 3 months ago field-hidden.php 3 years ago field-image.php 3 months ago field-post-object.php 3 months ago field-post-statuses.php 3 months ago field-post-types.php 3 months ago field-radio.php 3 months ago field-recaptcha.php 3 months ago field-relationship.php 3 months ago field-repeater.php 3 months ago field-select.php 3 months ago field-slug.php 1 year ago field-taxonomies.php 3 months ago field-taxonomy-terms.php 3 months ago field-taxonomy.php 3 months ago field-textarea.php 3 months ago field-user-roles.php 3 months ago field-user.php 3 months ago field-wysiwyg.php 3 months ago
field-image.php
294 lines
1 <?php
2
3 if(!defined('ABSPATH')){
4 exit;
5 }
6
7 if(!class_exists('acfe_field_image')):
8
9 class acfe_field_image extends acfe_field_extend{
10
11 /**
12 * initialize
13 */
14 function initialize(){
15
16 $this->name = 'image';
17 $this->defaults = array(
18 'uploader' => '',
19 'acfe_thumbnail' => 0,
20 );
21
22 $this->add_filter('gettext', array($this, 'gettext'), 99, 3);
23 $this->add_filter('acf/prepare_field/name=library', array($this, 'prepare_library'));
24 $this->add_field_action('acf/render_field_settings', array($this, 'render_field_settings_before'), 0);
25 $this->add_field_action('acf/render_field_settings', array($this, 'render_field_settings_after'), 15);
26
27 }
28
29
30 /**
31 * gettext
32 *
33 * @param $translated_text
34 * @param $text
35 * @param $domain
36 *
37 * @return string
38 */
39 function gettext($translated_text, $text, $domain){
40
41 if($domain === 'acf'){
42 if($text === 'No image selected'){
43 return '';
44 }
45 }
46
47 return $translated_text;
48
49 }
50
51
52 /**
53 * prepare_library
54 *
55 * @param $field
56 *
57 * @return mixed
58 */
59 function prepare_library($field){
60
61 // check if field group ui setting
62 if(acfe_get($field['wrapper'], 'data-setting') === 'image'){
63
64 // add conditional logic
65 $field['conditional_logic'] = array(
66 array(
67 array(
68 'field' => 'uploader',
69 'operator' => '==',
70 'value' => 'wp',
71 )
72 ),
73 array(
74 array(
75 'field' => 'uploader',
76 'operator' => '==',
77 'value' => '',
78 )
79 ),
80 );
81
82 }
83
84 return $field;
85
86 }
87
88
89 /**
90 * render_field_settings_before
91 *
92 * acf/render_field_settings:0
93 *
94 * @param $field
95 */
96 function render_field_settings_before($field){
97
98 // uploader type
99 acf_render_field_setting($field, array(
100 'label' => __('Uploader Type', 'acfe'),
101 'name' => 'uploader',
102 'key' => 'uploader',
103 'instructions' => __('Choose the uploader type', 'acfe'),
104 'type' => 'radio',
105 'choices' => array(
106 '' => __('Default', 'acf'),
107 'wp' => 'WordPress',
108 'basic' => __('Browser', 'acfe'),
109 ),
110 'default_value' => '',
111 'layout' => 'horizontal',
112 'return_format' => 'value',
113 ));
114
115 }
116
117
118 /**
119 * render_field_settings_after
120 *
121 * acf/render_field_settings:15
122 *
123 * @param $field
124 */
125 function render_field_settings_after($field){
126
127 // featured thumbnail
128 acf_render_field_setting($field, array(
129 'label' => __('Featured Thumbnail', 'acfe'),
130 'name' => 'acfe_thumbnail',
131 'key' => 'acfe_thumbnail',
132 'instructions' => __('Make this image the featured thumbnail', 'acfe'),
133 'type' => 'true_false',
134 'default_value' => false,
135 'ui' => true,
136 'ui_on_text' => '',
137 'ui_off_text' => '',
138 'required' => false,
139 ));
140
141 }
142
143
144 /**
145 * prepare_field
146 *
147 * @param $field
148 *
149 * @return mixed
150 */
151 function prepare_field($field){
152
153 // let acfe form force specific uploader
154 if(acf_is_filter_enabled('acfe/form/uploader')){
155 $field['uploader'] = '';
156 }
157
158 // default uploader in settings
159 // use global acf uploader
160 if(empty($field['uploader'])){
161 $field['uploader'] = acf_get_setting('uploader');
162 }
163
164 // current user can't upload files
165 // force basic
166 if(!current_user_can('upload_files')){
167 $field['uploader'] = 'basic';
168 }
169
170 // update global uploader
171 acf_update_setting('uploader', $field['uploader']);
172
173 // return
174 return $field;
175
176 }
177
178
179 /**
180 * update_value
181 *
182 * @param $value
183 * @param $post_id
184 * @param $field
185 *
186 * @return mixed
187 */
188 function update_value($value, $post_id, $field){
189
190 // bail early setting
191 if(!$field['acfe_thumbnail']){
192 return $value;
193 }
194
195 // bail early when local meta
196 if(acfe_is_local_post_id($post_id)){
197 return $value;
198 }
199
200 // bail early on wp preview
201 if(acf_maybe_get_POST('wp-preview') == 'dopreview'){
202 return $value;
203 }
204
205 // bail early if not post
206 $data = acf_get_post_id_info($post_id);
207
208 if($data['type'] !== 'post'){
209 return $value;
210 }
211
212 // update meta
213 update_post_meta($post_id, '_thumbnail_id', $value);
214
215 // return
216 return $value;
217
218 }
219
220
221 /**
222 * load_value
223 *
224 * @param $value
225 * @param $post_id
226 * @param $field
227 *
228 * @return mixed
229 */
230 function load_value($value, $post_id, $field){
231
232 // bail early setting
233 if(!$field['acfe_thumbnail']){
234 return $value;
235 }
236
237 // bail early on wp preview
238 if(acf_maybe_get_GET('preview') && filter_var(acf_maybe_get_GET('preview'), FILTER_VALIDATE_BOOLEAN)){
239 return $value;
240 }
241
242 // bail early if not post
243 $data = acf_get_post_id_info($post_id);
244
245 if($data['type'] !== 'post'){
246 return $value;
247 }
248
249 // return thumbnail
250 return get_post_meta($post_id, '_thumbnail_id', true);
251
252 }
253
254
255 /**
256 * format_front_value
257 *
258 * @param $formatted
259 * @param $unformatted
260 * @param $post_id
261 * @param $field
262 * @param $form
263 *
264 * @return string
265 */
266 function format_front_value($formatted, $unformatted, $post_id, $field, $form){
267
268 // vars
269 $value = acfe_as_array($unformatted);
270 $array = array();
271
272 // loop values
273 foreach($value as $p_id){
274
275 // get post
276 $post = get_post($p_id);
277
278 // validate
279 if($post && !is_wp_error($post)){
280 $array[] = get_the_title($post->ID);
281 }
282
283 }
284
285 // merge
286 return implode(', ', $array);
287
288 }
289
290 }
291
292 acf_new_instance('acfe_field_image');
293
294 endif;