'template', 'meta_name' => '([+name_only+])', 'option' => 'raw' ); $name_only = trim( MLAOptions::mla_get_data_source( $post_id, 'single_attachment_mapping', $my_setting, NULL ) ); $new_value = str_replace( array( '-', '_', '.' ), ' ', $name_only ); /* * If $updates[ 'post_title' ], etc. is set, some mapping rule has been set up, so we respect the result. * If not, use whatever the current value is. */ if ( isset( $updates[ 'post_title' ] ) ) { $old_title = $updates[ 'post_title' ]; } else { $post = get_post( $post_id ); $old_title = $post->post_title; } /* * If the cleanup has changed the value, * put the new value in the $updates array. */ if ( $old_title != $new_value ) { $updates[ 'post_title' ] = $new_value; } if ( isset( $updates[ 'post_excerpt' ] ) ) { $old_caption = $updates[ 'post_excerpt' ]; } else { $post = get_post( $post_id ); $old_caption = $post->post_excerpt; } if ( $old_caption != $new_value ) { $updates[ 'post_excerpt' ] = $new_value; } // Only replace ALT Text if Image Metadata is present $old_metadata = get_metadata( 'post', $post_id, '_wp_attachment_metadata', true ); if ( ! empty( $old_metadata ) ) { // Find the current ALT Text value if ( isset( $updates[ 'image_alt' ] ) ) { $old_alt = $updates[ 'image_alt' ]; } else { $old_alt = get_metadata( 'post', $post_id, '_wp_attachment_image_alt', true ); } // Replace the ALT Text value with the clean file name if ( $old_alt != $new_value ) { $updates[ 'image_alt' ] = $new_value; } } return $updates; } // mla_mapping_updates_filter } //MLAFileNameMappingHooksExample /* * Install the filters at an early opportunity */ add_action('init', 'MLAFileNameMappingHooksExample::initialize'); ?>