8

While working with metaboxes / custom fields I've seemed to indirectly create many of these _encloseme meta_keys all over my wp_postmeta.

Seen here:

So far no problems have arisen from this and the custom fields work fine but I've only fidgeted with 2 or so posts on my local test site and I don't want to implement it to my live site if its going to cause issues later on down the road. Anyone know what to do about these, are they normal?

Here's the code for my metaboxes.

<?php

    //Add meta boxes to post types
    function plib_add_box() {
        global $meta_box;

        foreach($meta_box as $post_type => $value) {
            add_meta_box($value['id'], $value['title'], 'plib_format_box', $post_type, $value['context'], $value['priority']);
        }
    }
    //Formatting
    function plib_format_box() {
      global $meta_box, $post;

      // verification
      echo '<input type="hidden" name="plib_meta_box_nonce" value="', wp_create_nonce(basename(__FILE__)), '" />';

      echo '<table class="form-table">';

      foreach ($meta_box[$post->post_type]['fields'] as $field) {
          // get current post meta data
          $meta = get_post_meta($post->ID, $field['id'], true);

          echo '<tr>'.
                  '<th style="width:20%"><label for="'. $field['id'] .'">'. $field['name']. '</label></th>'.
                  '<td>';
          switch ($field['type']) {
              case 'text':
                  echo '<input type="text" name="'. $field['id']. '" id="'. $field['id'] .'" value="'. ($meta ? $meta : $field['default']) . '" size="30" style="width:97%" />'. '<br />'. $field['desc'];
                  break;
              case 'textarea':
                  echo '<textarea name="'. $field['id']. '" id="'. $field['id']. '" cols="60" rows="4" style="width:97%">'. ($meta ? $meta : $field['default']) . '</textarea>'. '<br />'. $field['desc'];
                  break;
              case 'select':
                  echo '<select name="'. $field['id'] . '" id="'. $field['id'] . '">';
                  foreach ($field['options'] as $option) {
                      echo '<option '. ( $meta == $option ? ' selected="selected"' : '' ) . '>'. $option . '</option>';
                  }
                  echo '</select>';
                  break;
              case 'radio':
                  foreach ($field['options'] as $option) {
                      echo '<input type="radio" name="' . $field['id'] . '" value="' . $option['value'] . '"' . ( $meta == $option['value'] ? ' checked="checked"' : '' ) . ' />' . $option['name'];
                  }
                  break;
              case 'checkbox':
                  echo '<input type="checkbox" name="' . $field['id'] . '" id="' . $field['id'] . '"' . ( $meta ? ' checked="checked"' : '' ) . ' />';
                  break;
          }
          echo     '<td>'.'</tr>';
      }

      echo '</table>';

    }
    // Save data from meta box
    function plib_save_data($post_id) {
        global $meta_box,  $post;

        //Verify
        if (!wp_verify_nonce($_POST['plib_meta_box_nonce'], basename(__FILE__))) {
            return $post_id;
        }

        //Check > autosave
        if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
            return $post_id;
        }

        //Check > permissions
        if ('page' == $_POST['post_type']) {
            if (!current_user_can('edit_page', $post_id)) {
                return $post_id;
            }
        } elseif (!current_user_can('edit_post', $post_id)) {
            return $post_id;
        }

        foreach ($meta_box[$post->post_type]['fields'] as $field) {
            $old = get_post_meta($post_id, $field['id'], true);
            $new = $_POST[$field['id']];

            if ($new && $new != $old) {
                update_post_meta($post_id, $field['id'], $new);
            } elseif ('' == $new && $old) {
                delete_post_meta($post_id, $field['id'], $old);
            }
        }
    }

    add_action('save_post', 'plib_save_data');

    //We create an array called $meta_box and set the array key to the relevant post type
// If custom post type, change the 'post' variable
    $meta_box['post'] = array(

        //This is the id applied to the meta box
        'id' => 'venue_location',  

        //This is the title that appears on the meta box container
        'title' => 'Venue/Location',    

        //This defines the part of the page where the edit screen section should be shown
        'context' => 'normal',    

        //This sets the priority within the context where the boxes should show
        'priority' => 'high',

        //Here we define all the fields we want in the meta box
        'fields' => array(
            array(
                'name' => 'Venue',
                'desc' => 'Venue Name',
                'id' => 'venue_info',
                'type' => 'text',
                'default' => ''
            ),
            array(
                'name' => 'Location',
                'desc' => 'Location of the Venue',
                'id' => 'location_info',
                'type' => 'text',
                'default' => ''
            )
        )
    );
    add_action('admin_menu', 'plib_add_box');
?>

(Just incase, here's a pastbin link to the above code: http://pastebin.com/0QsqxtZW)

3
  • what version of wordpress are you using? a search for _encloseme keeps coming up with information of wordpress 2.0 which is very old.
    – Scott
    Jun 23, 2011 at 23:02
  • Also are you able to add the code to your question you are using to add your meta boxes?
    – Scott
    Jun 23, 2011 at 23:05
  • Yeah. I've come across that too - I'm using 3.1.3. Don't know what the code length limits are here. So here is the pastebin link to the code for my metabox. pastebin.com/0QsqxtZW Jun 23, 2011 at 23:13

1 Answer 1

16

Short version:

_encloseme is added to a post when it's published. The wp-cron process should get scheduled shortly thereafter to process the post to look for enclosures.

In other words, it cleans them up normally later. Nothing to worry about.

Full explanation:

"Enclosures" are links in a post to something like an audio or video file. WordPress finds these based on the MIME type of the files being linked to, then saves extra metadata about them. This metadata is used in the RSS feeds, to create special tags to connect these files to the post.

This is how podcasts work, for example. If you put a link to an MP3 in a post, then an enclosure will be created for that link, and the feed will have the enclosure, and podcast readers like iTunes can then use that to be able to download the MP3 directly from the RSS feed.

_encloseme is just special metadata saying that the post hasn't been processed by the enclosure process yet. When you create or update a published post, that gets auto-added so that the post will be processed by the enclosure creator.

3
  • Thank you Otto for your thorough response, needless to say I'm satisfied. I'd +1 if I could. Jun 24, 2011 at 19:20
  • Just saw that my posts add one 1 to the post meta _encloseme array on each save_pst/update_post. Doesn't this check if it's already set and therefore adds the same on each update/save? Thanks!
    – kaiser
    Jul 6, 2011 at 17:03
  • 1
    No, it doesn't check. It just adds it. This generally doesn't matter, the process that does the enclosures later will remove it.
    – Otto
    Jul 7, 2011 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.