menu_order; } if ( $old_value != $new_value ) { $updates[ 'menu_order' ] = $new_value; } // We don't actually store update_menu_order as a custom field unset( $updates['custom_updates']['update_menu_order'] ); } /* * Remove or comment out the next line to apply the Title and ALT Text cleanup logic */ return $updates; /* * For the Title and ALT Text cleanup, we are only concerned with Standard Field mapping */ if ( ! in_array( $category, array( 'iptc_exif_mapping', 'iptc_exif_standard_mapping' ) ) ) { return $updates; } /* * If $updates[ 'post_title' ] is set, some mapping rule * has been set up, so we respect the result. If not, * use whatever the current Title value is. */ if ( isset( $updates[ 'post_title' ] ) ) { $old_value = $updates[ 'post_title' ]; } else { $post = get_post( $post_id ); $old_value = $post->post_title; } /* * Derive the new Title from the IPTC Object Name, if present. * You can use MLAOptions::mla_get_data_source() to get anything available. */ $my_setting = array( 'data_source' => 'template', 'meta_name' => '([+iptc:2#005+])', 'option' => 'raw' ); $object_name = trim( MLAOptions::mla_get_data_source( $post_id, 'single_attachment_mapping', $my_setting, NULL ) ); /* * Clean up the Title value. If the cleanup has changed the value, * put the new value in the $updates array. */ $new_title = str_replace( array( '-', '_', '.' ), ' ', $old_value ); if ( $old_value != $new_title ) { $updates[ 'post_title' ] = $new_title; } // Find the current ALT Text value if ( isset( $updates[ 'image_alt' ] ) ) { $old_value = $updates[ 'image_alt' ]; } else { $old_value = get_metadata( 'post', $post_id, '_wp_attachment_image_alt', true ); } // Replace the ALT Text value with the clean Title if ( $old_value != $new_title ) { $updates[ 'image_alt' ] = $new_title; } /* * To stop this rule's updates, return an empty array, i.e., return array(); */ return $updates; } // mla_mapping_updates } //MLASimpleMappingHooksExample /* * Install the filters at an early opportunity */ add_action('init', 'MLASimpleMappingHooksExample::initialize'); ?>