WordPress.org

Support

Support » Alpha/Beta » [Resolved] Adding fields to attachments

[Resolved] Adding fields to attachments

  • Jeff Farthing

    @jfarthing84

    Love the new media uploader! But now since both media_fields_to_edit and media_fields_to_save are being deprecated, what is the proper way to add new fields to the media uploader? I understand that there is a print_media_templates action, but what do I do with that?

Viewing 8 replies - 1 through 8 (of 8 total)
  • Moderator keesiemeijer

    @keesiemeijer

    media_fields_to_edit and media_fields_to_save filter hooks are not deprecated. Try WordPress release candidate 3: http://wordpress.org/news/2012/12/wordpress-3-5-release-candidate-3/

    http://codex.wordpress.org/Plugin_API#Hooks.2C_Actions_and_Filters

    Jeff Farthing

    @jfarthing84

    Of course they still work, but are not the “proper” way to add to the uploader now. The proper way would be to utilize the new Backbone system. However, I’m not familiar with this so that’s what I was asking. How do I add stuff using the new javascript API.

    Jeff Farthing

    @jfarthing84

    Perhaps my question should have been “Adding views to media uploader”. How would I do the following from a script of my own?

    sidebar.set( 'compat', new media.view.AttachmentCompat({
    	controller: this.controller,
    	model:      single,
    	priority:   120
    }) );
    Moderator keesiemeijer

    @keesiemeijer

    I’m sorry but I have no Idea, I’ve never worked with Backbone before.
    To add a template of your own to all other media templates with the action print_media_templates use something like this in your plugin or functions.php:

    function add_my_media_view_template(){
    // copied from wp-includes/media.php: tmpl-attachment-display-settings
    ?>
    <script type="text/html" id="tmpl-my-attachment-display-settings">
    		<h3><?php _e('My Attachment Display Settings'); ?></h3>
    
    		<# if ( 'image' === data.type ) { #>
    			<label class="setting">
    				<span><?php _e('my Alignment'); ?></span>
    				<select class="myalignment"
    					data-setting="myalign"
    
    					<option value="left">
    						<?php esc_attr_e('Left'); ?>
    					</option>
    					<option value="center">
    						<?php esc_attr_e('Center'); ?>
    					</option>
    					<option value="right">
    						<?php esc_attr_e('Right'); ?>
    					</option>
    					<option value="none" selected>
    						<?php esc_attr_e('None'); ?>
    					</option>
    				</select>
    			</label>
    		<# } #>
    </script>
    <?php  }
    add_action( 'print_media_templates', 'add_my_media_view_template');

    It will be loaded on the edit post screen (look in the source code) with all the other media templates. I don’t know however how to interact with it with Backbone. Not very useful, I know.

    Maybe ask around on the wp-hackers mailing list: http://codex.wordpress.org/Mailing_Lists#Hackers

    Use attachment_fields_to_edit and attachment_fields_to_save. Still Works in 3.5.

    Great tut here:
    http://net.tutsplus.com/tutorials/wordpress/creating-custom-fields-for-attachments-in-wordpress/

    Really?

    Of course they still work, but are not the “proper” way to add to the uploader now. The proper way would be to utilize the new Backbone system. However, I’m not familiar with this so that’s what I was asking. How do I add stuff using the new javascript API.

    Moderator Andrew Nacin

    @nacin

    Lead Developer

    There will be a lot of tutorials written all month on how to leverage all the cool new stuff in 3.5. Yes, attachment_fields_to_edit and attachment_fields_to_save continue to work as-is and are not deprecated.

    I would very appreciate if there will be also some clue about how to hook custom (“Add Media” like) button with custom overlay content using JS Modal instead of ThickBox.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘[Resolved] Adding fields to attachments’ is closed to new replies.
Skip to toolbar