function un_do_db_upgrade() { global $un_default_options, $wp_roles, $wpdb; $icons = array('idea' => 'icon-lightbulb', 'question' => 'icon-question-sign', 'problem' => 'icon-exclamation-sign', 'praise' => 'icon-heart'); $plural = array('idea' => __('Ideas', 'usernoise'), 'question' => __('Questions', 'usernoise'), 'problem' => __('Problems', 'usernoise'), 'praise' => __('Praises', 'usernoise')); $index = 0; $wpdb->un_termmeta = $wpdb->prefix . "un_termmeta"; if ($wpdb->get_var("SHOW TABLES LIKE '{$wpdb->un_termmeta}'") != $wpdb->un_termmeta) { require_once ABSPATH . 'wp-admin/includes/upgrade.php'; $sql = "CREATE TABLE `{$wpdb->un_termmeta}` (\n\t\t\t`meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t`un_term_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t`meta_key` varchar(255) DEFAULT NULL,\n\t\t\t`meta_value` longtext,\n\t\t\tPRIMARY KEY (`meta_id`),\n\t\t\tKEY `un_term_id` (`un_term_id`),\n\t\t\tKEY `meta_key` (`meta_key`)\n\t\t);"; dbDelta($sql); } foreach (array('idea' => __('Idea', 'usernoise'), 'question' => __('Question', 'usernoise'), 'problem' => __('Problem', 'usernoise'), 'praise' => __('Praise', 'usernoise')) as $type => $value) { if (null == ($term = get_term_by('slug', $type, 'feedback_type', ARRAY_A))) { $term = wp_insert_term($value, FEEDBACK_TYPE, array('slug' => $type)); } if (null == un_get_term_meta($term['term_id'], 'icon')) { un_add_term_meta($term['term_id'], 'icon', $icons[$type], true); un_add_term_meta($term['term_id'], 'plural', $plural[$type], true); un_add_term_meta($term['term_id'], 'position', $index, true); } $index++; } if (!isset($wp_roles)) { $wp_roles = new WP_Roles(); } foreach (un_get_capable_roles() as $role) { foreach (un_get_feedback_capabilities() as $cap) { $wp_roles->add_cap($role, $cap); } } update_option('un_db_revision', '2'); }
public function action_manage_feedback_posts_custom_column($column_name, $post_id) { global $un_h; if ($column_name == 'un-type') { $terms = wp_get_post_terms($post_id, FEEDBACK_TYPE); if (!empty($terms)) { echo "<span class='type'>"; $un_h->tag('i', array('class' => un_get_term_meta($terms[0]->term_id, 'icon'))); echo $terms[0]->name; echo "</span>"; } } }
function feedback_form($action) { global $un_h; ?> <form action="<?php echo esc_attr(un_ajax_url('feedback_form_submit')); ?> " method="post" class="un-feedback-form"> <?php if (un_get_option(UN_FEEDBACK_FORM_SHOW_TYPE)) { ?> <div class="un-types-wrapper"> <?php $tags = get_terms(FEEDBACK_TYPE, array('un_orderby_meta' => 'position', 'hide_empty' => false)); ?> <?php foreach ($tags as $tag) { ?> <a href="#" class="un-feedback-type" data-type="<?php echo $tag->slug; ?> "><?php if (!un_get_option(UN_DISABLE_ICONS)) { ?> <i class="<?php echo un_get_term_meta($tag->term_id, 'icon'); ?> "></i><?php } echo esc_html(__($tag->name, 'usernoise')); ?> </a> <?php } ?> <?php if (isset($tags[0])) { ?> <?php $slug = $tags[0]; ?> <?php $slug = $slug->slug; ?> <?php } else { ?> <?php $slug = null; ?> <?php } ?> <?php $un_h->hidden_field('type', $slug); ?> </div> <?php } ?> <?php $un_h->textarea('description', un_get_option(UN_FEEDBACK_TEXTAREA_PLACEHOLDER), array('id' => 'un-description', 'class' => 'text text-empty')); ?> <?php if (un_get_option(UN_FEEDBACK_FORM_SHOW_SUMMARY)) { ?> <?php $un_h->text_field('title', un_get_option(UN_FEEDBACK_SUMMARY_PLACEHOLDER), array('id' => 'un-title', 'class' => 'text text-empty')); ?> <?php } ?> <?php if (un_get_option(UN_FEEDBACK_FORM_SHOW_EMAIL)) { ?> <?php $un_h->text_field('email', un_get_option(UN_FEEDBACK_EMAIL_PLACEHOLDER), array('id' => 'un-email', 'class' => 'text text-empty')); ?> <?php } ?> <?php if (un_get_option(UN_FEEDBACK_FORM_SHOW_NAME)) { ?> <?php $un_h->text_field('name', un_get_option(UN_FEEDBACK_NAME_PLACEHOLDER), array('id' => 'un-name', 'class' => 'text text-empty')); ?> <?php } ?> <?php do_action('un_feedback_form_body'); ?> <input type="submit" class="un-submit" value="<?php echo esc_attr(un_submit_feedback_button_text()); ?> " id="un-feedback-submit"> <img src="<?php echo usernoise_url('/images/loader.gif'); ?> " id="un-feedback-loader" class="loader" style="display: none;"> <div class="un-feedback-errors-wrapper" style="display: none;"> <div class="un-errors"></div> </div> </form> <?php }
function un_get_feedback_type_span($id, $show_text = true) { global $un_h; if ($type = wp_get_post_terms($id, FEEDBACK_TYPE)) { $img = $un_h->_tag('i', array('class' => un_get_term_meta($type[0]->term_id, 'icon'))); return $img . ($show_text ? " " . __(esc_html($type[0]->name), 'usernoise') : ''); } return null; }
public function get_plural_feedback_type_label($type) { $term = get_term_by('slug', $type, FEEDBACK_TYPE); return un_get_term_meta($term->term_id, 'plural'); }