0

I've got a problem. I'm adding custom columns and contents to term lists on admin term/taxonomy creation/editing page. I'm using the classic 'manage_edit-{$taxonomy}columns' and 'manage{$taxonomy}_custom_column' filters. Till now, all fine.

But when I create a new term, all is done wia ajax by wordpress, thus not firing 'manage_{$taxonomy}_custom_column' at all and thus not adding any content.

So what can I do here? Is there any solution or way to 'hook' into js actions too?


// EDIT: as asked below by Fencer04, I show some code, but I don't this is useful, since the problem is wordpress doing ajax upon term creation, and the question is how to hook into that.

add_action('admin_head', 'init_taxonomy_images');

function init_taxonomy_images(){
  $taxonomies = get_taxonomies();

  if(is_array($taxonomies)){
    foreach($taxonomies as $taxonomy){
      add_filter( "manage_edit-{$taxonomy}_columns", 'edit_term_column');
      add_filter( "manage_{$taxonomy}_custom_column", 'add_image_to_column_content', 10, 3);
    }
  }
}

function edit_term_column($columns){
  // cleanup
  unset($columns['description']);
  unset($columns['posts']);

  // find insertion position
  $slug_index = array_search('slug', array_keys($columns));

  // add the column
  $new_column = array('term_image' => 'Immagine');
  return array_slice($columns, 0, $slug_index+1, true ) + $new_column + array_slice($columns, $slug_index+1, null, true);
}

// this one won't (obviously) be executed upon term creation
// because wp does it with ajax and won't apply manage_{$taxonomy}_custom_column
function add_image_to_column_content($content, $column_name, $term_id){
  if($column_name !== 'term_image') return $content;
  $image_data = get_term_image_data($term_id); // other code, image previously saved
  if(!$image_data) return $content;
  $image_src = $image_data['src'];
  return '<img src="' . $image_src . '" style="width:50px;" />';
}
  • Have you been doing this with AJAX all along or are you trying to convert it to AJAX? Can you show us the code you are using? – Fencer04 Jul 29 '16 at 20:25
  • No, as I wrote, I'm using the classic filters (thus, php). But the problem is wordpress itself: when editing an existing term it will reload the page, so all fine; but when creating a new one, wordpress adds it via ajax, and thus the filters won't be executed and the list table won't get the columns correctly populated. – Luca Reghellin Jul 31 '16 at 11:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.