Skip to content

Instantly share code, notes, and snippets.

@wpsoul
Created November 9, 2020 16:52
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 wpsoul/d9103e59568005aea0639aa2f7f2e452 to your computer and use it in GitHub Desktop.
Save wpsoul/d9103e59568005aea0639aa2f7f2e452 to your computer and use it in GitHub Desktop.
Old category custom meta for options
//Category old fields here
add_action('admin_init', 'category_custom_fields', 1);
if( !function_exists('category_custom_fields') ) {
function category_custom_fields()
{
add_action('category_edit_form_fields', 'category_custom_fields_form');
add_action('edited_category', 'category_custom_fields_save');
add_action( 'create_category', 'category_custom_fields_save');
add_action( 'category_add_form_fields', 'category_custom_fields_form_new');
}
}
if( !function_exists('category_custom_fields_form') ) {
function category_custom_fields_form($tag)
{
$t_id = $tag->term_id;
$cat_meta = get_option("category_$t_id");
wp_enqueue_script('wp-color-picker');
wp_enqueue_style( 'wp-color-picker' );
?>
<?php $settingseditor = array(
'textarea_name' => 'description',
'textarea_rows' => 10,
'editor_class' => 'i18n-multilingual',
);
?>
<tr class="form-field">
<th scope="row" valign="top"><label><?php esc_html_e('Second category description','rehub-framework'); ?></label></th>
<td>
<?php
$meta_content = !empty($cat_meta['cat_second_description']) ? $cat_meta['cat_second_description'] : '';
wp_editor( $meta_content, 'cat_second_description', array(
'wpautop' => true,
'media_buttons' => false,
'textarea_name' => 'Cat_meta[cat_second_description]',
'textarea_rows' => 10,
'teeny' => false
));
?>
<span class="description"><?php esc_html_e('Set html for second category description (will be after posts)','rehub-framework'); ?></span>
</td>
</tr>
<tr class="form-field color_cat_grade">
<th scope="row" valign="top"><label><?php esc_html_e('Cat color','rehub-framework'); ?></label></th>
<td>
<input type="text" name="Cat_meta[cat_color]" id="Cat_meta[cat_color]" size="25" style="width:60%;" value="<?php echo (!empty($cat_meta['cat_color'])) ? $cat_meta['cat_color'] : ''; ?>" data-default-color="#E43917"><br />
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.color_cat_grade input').wpColorPicker();
});
</script>
<span class="description"><?php esc_html_e('Set category color. Note, this color will be used under white text','rehub-framework'); ?></span>
</td>
</tr>
<tr class="form-field">
<th scope="row" valign="top"><label><?php esc_html_e('Category banner custom html','rehub-framework'); ?></label></th>
<td>
<input type="text" name="Cat_meta[cat_image_url]" id="Cat_meta[cat_image_url]" size="25" style="width:60%;" value="<?php echo (!empty($cat_meta['cat_image_url'])) ? $cat_meta['cat_image_url'] : ''; ?>"><br />
<span class="description"><?php esc_html_e('Set url to image of banner or any custom html, shortcode','rehub-framework'); ?></span>
</td>
</tr>
<?php
}
}
if( !function_exists('category_custom_fields_form_new') ) {
function category_custom_fields_form_new($tag)
{
wp_enqueue_script('wp-color-picker');
wp_enqueue_style( 'wp-color-picker' );
?>
<div class="form-field">
<label><?php esc_html_e('Second category description','rehub-framework'); ?></label>
<textarea name="Cat_meta[cat_second_description]" id="Cat_meta[cat_second_description]" rows="5" cols="50"><?php echo (!empty($cat_meta['cat_second_description'])) ? $cat_meta['cat_second_description'] : ''; ?></textarea><br />
<span class="description"><?php esc_html_e('Set html for second category description (will be after posts)','rehub-framework'); ?></span>
</div>
<div class="form-field color_cat_grade">
<label><?php esc_html_e('Cat color','rehub-framework'); ?></label>
<input type="text" name="Cat_meta[cat_color]" id="Cat_meta[cat_color]" size="25" style="width:60%;" value="" data-default-color="#E43917"><br />
<script type="text/javascript">
jQuery(document).ready(function($) {
$('.color_cat_grade input').wpColorPicker();
});
</script>
<span class="description"><?php esc_html_e('Set category color. Note, this color will be used under white text','rehub-framework'); ?></span>
</div>
<div class="form-field">
<label><?php esc_html_e('Category banner custom html','rehub-framework'); ?></label>
<input type="text" name="Cat_meta[cat_image_url]" id="Cat_meta[cat_image_url]" size="25" style="width:60%;" value=""><br />
<span class="description"><?php esc_html_e('Set url to image of banner or any custom html, shortcode','rehub-framework'); ?></span>
</div>
<?php
}
}
if( !function_exists('category_custom_fields_save') ) {
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] = stripslashes($_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