Skip to content

Instantly share code, notes, and snippets.

@nicmare
Created June 9, 2023 12:52
Show Gist options
  • Select an option

  • Save nicmare/ef8b37a89da4b4b70782a06ca9e00adc to your computer and use it in GitHub Desktop.

Select an option

Save nicmare/ef8b37a89da4b4b70782a06ca9e00adc to your computer and use it in GitHub Desktop.
<?php
function set_media_folder($pid = ""){
if(empty($pid)) return;
if(get_post_type($pid) == "attachment"){
if(($path = get_attached_file($pid)) && str_contains($path,"nsl_avatars")) {
if ( $term_avatars = get_term_by( 'slug', 'avatare', 'happyfiles_category' ) )
wp_set_object_terms( $pid, $term_avatars->term_id, 'happyfiles_category' );
wp_update_post([
'ID' => $pid,
'post_title' => __("User-Avatar","myb")
]);
}
}
}
add_action('add_attachment','set_media_folder',30);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment