Exemplo n.º 1
0
 /**
  * Perform IPTC/EXIF and Custom Field mapping on just-inserted attachment
  *
  * This filter tests the $add_attachment_id variable set by the mla_add_attachment_action
  * to ensure that mapping is only performed for new additions, not metadata updates.
  *
  * @since 1.10
  *
  * @param	array	Attachment metadata for just-inserted attachment
  * @param	integer	ID of just-inserted attachment
  *
  * @return	array	Updated attachment metadata
  */
 public static function mla_update_attachment_metadata_filter($data, $post_id)
 {
     $options = array();
     $options['is_upload'] = MLAOptions::$add_attachment_id == $post_id;
     MLAOptions::$add_attachment_id = 0;
     $options['enable_iptc_exif_mapping'] = 'checked' == MLACore::mla_get_option('enable_iptc_exif_mapping');
     $options['enable_custom_field_mapping'] = 'checked' == MLACore::mla_get_option('enable_custom_field_mapping');
     $options['enable_iptc_exif_update'] = 'checked' == MLACore::mla_get_option('enable_iptc_exif_update');
     $options['enable_custom_field_update'] = 'checked' == MLACore::mla_get_option('enable_custom_field_update');
     $options = apply_filters('mla_update_attachment_metadata_options', $options, $data, $post_id);
     $data = apply_filters('mla_update_attachment_metadata_prefilter', $data, $post_id, $options);
     if ($options['is_upload']) {
         if ($options['enable_iptc_exif_mapping'] || $options['enable_custom_field_mapping']) {
             do_action('mla_begin_mapping', 'create_metadata', $post_id);
         }
         if ($options['enable_iptc_exif_mapping']) {
             $item = get_post($post_id);
             $updates = MLAOptions::mla_evaluate_iptc_exif_mapping($item, 'iptc_exif_mapping', NULL, $data, true);
             $updates = MLAOptions::_update_attachment_metadata($updates, $data);
             if (!empty($updates)) {
                 $item_content = MLAData::mla_update_single_item($post_id, $updates);
             }
         }
         if ($options['enable_custom_field_mapping']) {
             $updates = MLAOptions::mla_evaluate_custom_field_mapping($post_id, 'single_attachment_mapping', NULL, $data);
             $updates = MLAOptions::_update_attachment_metadata($updates, $data);
             if (!empty($updates)) {
                 $item_content = MLAData::mla_update_single_item($post_id, $updates);
             }
         }
         if ($options['enable_iptc_exif_mapping'] || $options['enable_custom_field_mapping']) {
             do_action('mla_end_mapping');
         }
     } else {
         if ($options['enable_iptc_exif_update'] || $options['enable_custom_field_update']) {
             do_action('mla_begin_mapping', 'update_metadata', $post_id);
         }
         if ($options['enable_iptc_exif_update']) {
             $item = get_post($post_id);
             $updates = MLAOptions::mla_evaluate_iptc_exif_mapping($item, 'iptc_exif_mapping', NULL, $data);
             $updates = MLAOptions::_update_attachment_metadata($updates, $data);
             if (!empty($updates)) {
                 $item_content = MLAData::mla_update_single_item($post_id, $updates);
             }
         }
         if ($options['enable_custom_field_update']) {
             $updates = MLAOptions::mla_evaluate_custom_field_mapping($post_id, 'single_attachment_mapping', NULL, $data);
             $updates = MLAOptions::_update_attachment_metadata($updates, $data);
             if (!empty($updates)) {
                 $item_content = MLAData::mla_update_single_item($post_id, $updates);
             }
         }
         if ($options['enable_iptc_exif_update'] || $options['enable_custom_field_update']) {
             do_action('mla_end_mapping');
         }
     }
     $data = apply_filters('mla_update_attachment_metadata_postfilter', $data, $post_id, $options);
     return $data;
 }