Support » Plugin: Attachments » Cannot add custom fields

  • Resolved apakin

    (@apakin)


    Hi!
    I’ve installed the plugin and edited the functions.php:

    function my_attachments( $attachments )
    {
      $args = array(
    
        // title of the meta box (string)
        'label'         => 'My Attachments',
    
        // all post types to utilize (string|array)
        'post_type'     => array( 'post', 'page' ),
    
        // allowed file type(s) (array) (image|video|text|audio|application)
        'filetype'      => null,  // no filetype limit
    
        // include a note within the meta box (string)
        'note'          => 'Attach files here!',
    
        // text for 'Attach' button (string)
        'button_text'   => __( 'Attach Files', 'attachments' ),
    
        // text for modal 'Attach' button (string)
        'modal_text'    => __( 'Attach', 'attachments' ),
    
        // fields for this instance (array)
        'fields'        => array(
          array(
            'name'  => 'title',                          // unique field name
            'type'  => 'text',                           // registered field type (field available in 3.0: text)
            'label' => __( 'Title', 'attachments' ),     // label to display
          ),
          array(
            'name'  => 'caption',                        // unique field name
            'type'  => 'text',                           // registered field type (field available in 3.0: text)
            'label' => __( 'Caption', 'attachments' ),   // label to display
          ),
          array(
            'name'  => 'group',                      // unique field name
            'type'  => 'text',                           // registered field type (field available in 3.0: text)
            'label' => __( 'Group', 'attachments' ), // label to display
          ),
        ),
    
      );
    
      $attachments->register( 'my_attachments', $args ); // unique instance name
    }

    But I still don’t see the “Group” field in “Edit Post”: screenshot

    Thank you

    M

    http://wordpress.org/extend/plugins/attachments/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author Jonathan Christopher

    (@jchristopher)

    Hi M, you need to add the action as well:

    add_action( 'attachments_register', 'my_attachments' );

    You can add that below the function you pasted.

    Plugin Author Jonathan Christopher

    (@jchristopher)

    Also, your screenshot is using the default instance (meta box titled Attachments with two fields, one for Title one for Caption) — if you don’t want to use the default instance you can disable it and use the one you’re defining in your snippet by adding the following to your wp-config.php:

    define( 'ATTACHMENTS_DEFAULT_INSTANCE', false );

    I have this string. Sorry, didn’t write it.

    $attachments->register( 'my_attachments', $args ); // unique instance name
    }
    
    add_action( 'attachments_register', 'my_attachments' );

    Plugin Author Jonathan Christopher

    (@jchristopher)

    Did you disable the default instance? Your snippet will work as expected, I tested locally and it works. Perhaps the meta box is hidden (check your Screen Options tab in the upper right of the post edit screen)?

    Cannot disable right now, I don’t have FTP access.
    But the irony is that it’s worked till I upgraded the plugin.
    OK, thanx for help, I will wait for a man with FTP-password 🙂

    Plugin Author Jonathan Christopher

    (@jchristopher)

    Which version was it working with? Which version did you upgrade to that broke it?

    From 1.6.2.1 to 3.0.6

    Plugin Author Jonathan Christopher

    (@jchristopher)

    I see, okay so yes I’m thinking you’re actually working with the default instance instead of the one you’re trying to register. Are there two meta boxes on the edit screen?

    Sorry, but it still doesn’t work.
    I don’t even know where to look.

    Screenshot of Screen Options (I don’t see “meta box” there).
    Screenshot of editor with functions.php (yes, I’ve pressed “Update File” button :))
    Screenshot of wp-config.php

    Attachments 3.0.6, WP 3.4.2

    And another one thing: when I opened functions.php and wp-config.php, there wasn’t this required blocks of code. How did it work before update? Could plugin update delete this strings? If not, I don’t understand, how it was working. Till yesterday update another man configured WP with all the plugins 🙁

    Sorry for my terrible English and yammer, I’m in little panic 🙂

    Plugin Author Jonathan Christopher

    (@jchristopher)

    No, the plugin does not touch what you’ve written, it’s worked the same way since 3.0 launched. These snippets were not part of 1.6 and earlier. If you can pass along WordPress login information to jonathan@mondaybynoon.com I’d be more than happy to figure out what’s missing.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Cannot add custom fields’ is closed to new replies.