Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MasterHans/c7c56bdde7cfd77e40dc to your computer and use it in GitHub Desktop.
Save MasterHans/c7c56bdde7cfd77e40dc to your computer and use it in GitHub Desktop.
// добавляет вызов функции при инициализации административного раздела
add_action('admin_init', 'category_custom_fields', 1);
// функция расширения функционала административного раздела
function category_custom_fields()
{
// добавления действия после отображения формы ввода параметров категории
add_action('edit_category_form_fields', 'category_custom_fields_form');
// добавления действия при сохранении формы ввода параметров категории
add_action('edited_category', 'category_custom_fields_save');
}
function category_custom_fields_form($tag)
{
$t_id = $tag->term_id;
$cat_meta = get_option("category_$t_id");
?>
<tr class="form-field">
<th scope="row" valign="top"><label for="extra1"><?php _e('Cat Title'); ?></label></th>
<td>
<input type="text" name="Cat_meta[cat_title]" id="Cat_meta[cat_title]" size="25" style="width:60%;" value="<?php echo
$cat_meta['cat_title'] ? $cat_meta['cat_title'] : ''; ?>"><br />
<span class="description"><?php _e('Title категории'); ?></span>
</td>
</tr>
<?php
}
function category_custom_fields_save($term_id)
{
if (isset($_POST['Cat_meta'])) {
$t_id = $term_id;
$cat_meta = get_option("category_$t_id");
$cat_keys = array_keys($_POST['Cat_meta']);
foreach ($cat_keys as $key) {
if (isset($_POST['Cat_meta'][$key])) {
$cat_meta[$key] = $_POST['Cat_meta'][$key];
}
}
//save the option array
update_option("category_$t_id", $cat_meta);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment