mage-eventpress/lib/classes/class-taxonomy-edit.php

99 lines
3.5 KiB
PHP
Raw Normal View History

2020-04-28 06:37:33 -04:00
<?php
2021-11-02 03:28:50 -04:00
if (!defined('ABSPATH')) exit; // if direct access
2020-04-28 06:37:33 -04:00
2021-11-02 03:28:50 -04:00
if (!class_exists('TaxonomyEdit')) {
2020-04-28 06:37:33 -04:00
2021-11-02 03:28:50 -04:00
class TaxonomyEdit
{
2020-04-28 06:37:33 -04:00
public $data = array();
2021-11-02 03:28:50 -04:00
public function __construct($args)
{
2020-04-28 06:37:33 -04:00
$this->data = &$args;
2021-11-02 03:28:50 -04:00
add_action($this->get_taxonomy() . '_add_form_fields', array($this, 'add_form_fields'), 12);
add_action($this->get_taxonomy() . '_edit_form_fields', array($this, 'edit_form_fields'), 12);
add_action('edited_' . $this->get_taxonomy(), array($this, 'save_update_taxonomy'), 12);
add_action('create_' . $this->get_taxonomy(), array($this, 'save_update_taxonomy'), 12);
2020-04-28 06:37:33 -04:00
}
2021-11-02 03:28:50 -04:00
public function save_update_taxonomy($term_id)
{
foreach ($this->get_panels() as $optionIndex => $option) :
$option_value = isset($_POST[$option['id']]) ? mage_array_strip($_POST[$option['id']]) : '';
if (is_array($option_value)) {
$option_value = serialize($option_value);
}
update_term_meta($term_id, $option['id'], $option_value);
endforeach;
2020-04-28 06:37:33 -04:00
}
2021-11-02 03:28:50 -04:00
public function edit_form_fields($term)
{
2020-04-28 06:37:33 -04:00
$term_id = $term->term_id;
2021-11-02 03:28:50 -04:00
foreach ($this->get_panels() as $optionIndex => $option) : ?>
<tr class="form-field">
<th scope="row" valign="top"><label for="<?php echo esc_attr($option['id']); ?>"><?php echo esc_html($option['title']); ?></label></th>
<td>
2020-04-28 06:37:33 -04:00
<?php
2021-11-02 03:28:50 -04:00
$this->field_generator($option, $term_id)
?>
</td>
</tr>
<?php
2020-04-28 06:37:33 -04:00
endforeach;
}
2021-11-02 03:28:50 -04:00
public function add_form_fields($term)
{
2020-04-28 06:37:33 -04:00
$term_id = '';
?>
2021-11-02 03:28:50 -04:00
<?php foreach ($this->get_panels() as $optionIndex => $option) : ?>
<tr class="form-field">
<th scope="row" valign="top"><label for="<?php echo esc_attr($option['id']); ?>"><?php echo esc_html($option['title']); ?></label></th>
<td>
<?php $this->field_generator($option, $term_id); ?>
</td>
</tr>
2020-04-28 06:37:33 -04:00
<?php
endforeach;
}
2021-11-02 03:28:50 -04:00
public function field_generator($option, $term_id)
{
2020-04-28 06:37:33 -04:00
2021-11-02 03:28:50 -04:00
$id = isset($option['id']) ? $option['id'] : "";
$type = isset($option['type']) ? $option['type'] : "";
$details = isset($option['details']) ? $option['details'] : "";
2020-04-28 06:37:33 -04:00
2021-11-02 03:28:50 -04:00
if (empty($id)) return;
$option['field_name'] = $id;
$option_value = get_term_meta($term_id, $id, true);
$option['value'] = is_serialized($option_value) ? unserialize($option_value) : $option_value;
2020-04-28 06:37:33 -04:00
2021-11-02 03:28:50 -04:00
if (sizeof($option) > 0 && isset($option['type'])) {
echo mep_field_generator($option['type'], $option);
do_action("wp_theme_settings_field_$type", $option);
2020-04-28 06:37:33 -04:00
}
2021-11-02 03:28:50 -04:00
if (!empty($details)) echo "<p class='description'>$details</p>";
2020-04-28 06:37:33 -04:00
}
2021-11-02 03:28:50 -04:00
private function get_taxonomy()
{
if (isset($this->data['taxonomy'])) return $this->data['taxonomy'];
2020-04-28 06:37:33 -04:00
else return "category";
}
2021-11-02 03:28:50 -04:00
private function get_panels()
{
if (isset($this->data['options'])) return $this->data['options'];
2020-04-28 06:37:33 -04:00
else return array();
}
}
2021-11-02 03:28:50 -04:00
}