name = 'file'; $this->title = __('File','acf'); add_action('admin_head-media-upload-popup', array($this, 'popup_head')); add_filter('get_media_item_args', array($this, 'allow_file_insertion')); add_action('acf_head-update_attachment-file', array($this, 'acf_head_update_attachment')); add_action('wp_ajax_acf/fields/file/get_files', array($this, 'ajax_get_files')); } /* * acf_head_update_attachment * * @description: * @since: 3.2.7 * @created: 4/07/12 */ function acf_head_update_attachment() { ?> '', 'files' => array() ); $return = array(); // load post options $options = array_merge($options, $_POST); // verify nonce if( ! wp_verify_nonce($options['nonce'], 'acf_nonce') ) { die(0); } if( $options['files'] ) { foreach( $options['files'] as $id ) { $file_src = wp_get_attachment_url( $id ); preg_match("~[^/]*$~", $file_src, $file_name); // vars $return[] = array( 'id' => $id, 'icon' => wp_mime_type_icon( $id ), 'name' => $file_name[0] ); } } // return json echo json_encode( $return ); die; } /*-------------------------------------------------------------------------------------- * * allow_file_insertion * * @author Elliot Condon * @since 3.0.1 * *-------------------------------------------------------------------------------------*/ function allow_file_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 $options = array( 'class' => '', 'icon' => '', 'file_name' => '' ); if( $field['value'] ) { $file_src = wp_get_attachment_url( $field['value'] ); preg_match("~[^/]*$~", $file_src, $file_name); $options['class'] = 'active'; $options['icon'] = wp_mime_type_icon( $field['value'] ); $options['file_name'] = $file_name[0]; } ?>
'id', ); $field = array_merge($defaults, $field); ?>' . __("Media attachment updated.","acf") . '