Created
October 8, 2010 13:24
-
-
Save scribu/616782 to your computer and use it in GitHub Desktop.
Category Custom Fields
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Plugin Name: Category Custom Fields | |
Author: scribu | |
*/ | |
class Category_Custom_Fields { | |
function init() { | |
add_action( 'load-edit-tags.php', array( __CLASS__, 'save' ) ); | |
add_action( 'category_edit_form', array( __CLASS__, 'form' ) ); | |
} | |
function save() { | |
if ( !isset( $_POST['action'] ) || 'editedtag' != @$_POST['action'] ) | |
return; | |
$term_id = $_POST['tag_ID']; | |
$taxonomy = $_POST['taxonomy']; | |
// Check if the term exists | |
$term = get_term( $term_id, $taxonomy ); | |
if ( is_null( $term ) || is_wp_error( $term ) ) | |
return; | |
// Update the fields | |
update_term_meta( $term_id, 'field-1', $_POST[ 'field-1' ] ); | |
update_term_meta( $term_id, 'field-2', $_POST[ 'field-2' ] ); | |
} | |
function form( $term ) { | |
echo scbForms::table( array( | |
array( | |
'title' => 'Field 1', | |
'name' => 'field-1', | |
'type' => 'text', | |
'value' => get_term_meta( $term->term_id, 'field-1', true ) | |
), | |
array( | |
'title' => 'Field 2', | |
'name' => 'field-2', | |
'type' => 'checkbox', | |
'checked' => get_term_meta( $term->term_id, 'field-2', true ) | |
) | |
) ); | |
} | |
} | |
Category_Custom_Fields::init(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment