WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Adding fields to attachments (9 posts)

  1. Jeff Farthing
    Member
    Posted 1 year ago #

    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?

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    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

  3. Jeff Farthing
    Member
    Posted 1 year ago #

    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.

  4. Jeff Farthing
    Member
    Posted 1 year ago #

    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
    }) );
  5. keesiemeijer
    moderator
    Posted 1 year ago #

    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

  6. Patrick Hesselberg
    Member
    Posted 1 year ago #

    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/

  7. Jeff Farthing
    Member
    Posted 1 year ago #

    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.

  8. Andrew Nacin
    Lead Developer
    Posted 1 year ago #

    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.

  9. lilike
    Member
    Posted 1 year ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic