name = 'image'; $this->title = __('Image','acf'); add_action('admin_head-media-upload-popup', array($this, 'popup_head')); add_filter('get_media_item_args', array($this, 'allow_img_insertion')); add_action('acf_head-update_attachment-image', array($this, 'acf_head_update_attachment')); add_action('wp_ajax_acf/fields/image/get_images', array($this, 'ajax_get_images')); //add_filter('image_size_names_choose', array($this, 'image_size_names_choose')); add_action('wp_prepare_attachment_for_js', array($this, 'wp_prepare_attachment_for_js'), 10, 3); } /* * acf_head_update_attachment * * @description: * @since: 3.2.7 * @created: 4/07/12 */ function acf_head_update_attachment() { ?> '', 'images' => array(), 'preview_size' => 'thumbnail' ); $return = array(); // load post options $options = array_merge($options, $_POST); // verify nonce if( ! wp_verify_nonce($options['nonce'], 'acf_nonce') ) { die(0); } if( $options['images'] ) { foreach( $options['images'] as $id ) { $src = wp_get_attachment_image_src( $id, $options['preview_size'] ); $return[] = array( 'id' => $id, 'src' => $src[0], ); } } // return json echo json_encode( $return ); die; } /*-------------------------------------------------------------------------------------- * * admin_print_scripts / admin_print_styles * * @author Elliot Condon * @since 3.0.1 * *-------------------------------------------------------------------------------------*/ function allow_img_insertion($vars) { $vars['send'] = true; return($vars); } /*-------------------------------------------------------------------------------------- * * create_field * * @author Elliot Condon * @since 2.0.5 * @updated 2.2.0 * *-------------------------------------------------------------------------------------*/ function create_field($field) { // vars $class = ""; $file_src = ""; $preview_size = isset($field['preview_size']) ? $field['preview_size'] : 'thumbnail'; // get image url if($field['value'] != '' && is_numeric($field['value'])) { $file_src = wp_get_attachment_image_src($field['value'], $preview_size); $file_src = $file_src[0]; if($file_src) { $class = "active"; } } ?>

'id', 'preview_size' => 'thumbnail', ); $field = array_merge($defaults, $field); ?> 'radio', 'name' => 'fields['.$key.'][save_format]', 'value' => $field['save_format'], 'layout' => 'horizontal', 'choices' => array( 'object' => __("Image Object",'acf'), 'url' => __("Image URL",'acf'), 'id' => __("Image ID",'acf') ) )); ?> parent->get_all_image_sizes(); do_action('acf/create_field', array( 'type' => 'radio', 'name' => 'fields['.$key.'][preview_size]', 'value' => $field['preview_size'], 'layout' => 'horizontal', 'choices' => $image_sizes )); ?> '', 'acf_preview_size' => 'thumbnail', 'tab' => 'type', ); $options = array_merge($defaults, $_GET); // validate if( $options['acf_type'] != 'image' ) { return; } // update attachment if( isset($_POST["attachments"]) ) { echo '

' . __("Media attachment updated.","acf") . '

'; } ?> $attachment->ID, 'alt' => get_post_meta($attachment->ID, '_wp_attachment_image_alt', true), 'title' => $attachment->post_title, 'caption' => $attachment->post_excerpt, 'description' => $attachment->post_content, 'url' => wp_get_attachment_url( $attachment->ID ), 'sizes' => array(), ); // find all image sizes $image_sizes = get_intermediate_image_sizes(); if( $image_sizes ) { foreach( $image_sizes as $image_size ) { // find src $src = wp_get_attachment_image_src( $attachment->ID, $image_size ); // add src $value['sizes'][$image_size] = $src[0]; } // foreach( $image_sizes as $image_size ) } // if( $image_sizes ) } return $value; } /* * image_size_names_choose * * @description: * @since: 3.5.7 * @created: 13/01/13 */ function image_size_names_choose( $sizes ) { global $_wp_additional_image_sizes; if( $_wp_additional_image_sizes ) { foreach( $_wp_additional_image_sizes as $k => $v ) { $title = $k; $title = str_replace('-', ' ', $title); $title = str_replace('_', ' ', $title); $title = ucwords( $title ); $sizes[ $k ] = $title; } // foreach( $image_sizes as $image_size ) } return $sizes; } /* * wp_prepare_attachment_for_js * * @description: This sneaky hook adds the missing sizes to each attachment in the 3.5 uploader. It would be a lot easier to add all the sizes to the 'image_size_names_choose' filter but then it will show up on the normal the_content editor * @since: 3.5.7 * @created: 13/01/13 */ function wp_prepare_attachment_for_js( $response, $attachment, $meta ) { // only for image if( $response['type'] != 'image' ) { return $response; } $attachment_url = $response['url']; $base_url = str_replace( wp_basename( $attachment_url ), '', $attachment_url ); if( is_array($meta['sizes']) ) { foreach( $meta['sizes'] as $k => $v ) { if( !isset($response['sizes'][ $k ]) ) { $response['sizes'][ $k ] = array( 'height' => $v['height'], 'width' => $v['width'], 'url' => $base_url . $v['file'], 'orientation' => $v['height'] > $v['width'] ? 'portrait' : 'landscape', ); } } } return $response; } } ?>