I'm trying to in some way hook into when a new category is created. What I would like to do is to see the term and slug that was created and log them/email them. I have tried to hook in to create_category(). That only gives me an ID, not the term and slug. Would be great if someone could lead me on the right track.
2 Answers
You could use the get_term_by() function: http://codex.wordpress.org/Function_Reference/get_term_by
// get the category object
$category = get_term_by( 'id', $category_id, 'category');
// use the object to get your values
$name = $category->name;
$slug = $category->slug;
Does this help?
<?php
/*
Plugin Name: Xml Write
Plugin URI: http://wordpress.org/plugins/
Description: This is post category xml write plugin
Version: 1.6
Author URI:
*/
add_action('admin_menu', 'xmlwrite_admin_actions');
function xmlwrite_admin_actions() {
add_options_page('xmlwrite', 'xmlwrite', 'manage_options', xmlwrite, 'xmlwrite_admin');
}
add_action('add_category_form_pre', 'update_category_function');
add_action('edit_category', 'update_category_function');
add_action('delete_category', 'update_category_function');
function update_category_function($category_id) {
$categories = get_categories($category_id);
$xml = new XMLWriter();
$xml->openURI("text.xml");
$xml->startDocument();
$xml->setIndent(true);
$xml->startElement('Categories');
foreach ($categories as $category) {
$xml->startElement("Category");
$xml->writeRaw($category->name);
$xml->endElement();
$xml->startElement("url");
$xml->writeRaw(esc_url(get_category_link($category->term_id)));
$xml->endElement();
}
$xml->endElement();
header('Content-type: tet/xml');
$xml->flush();
}
create_category
here?