Exemplo n.º 1
0
 public function action_plugins_loaded()
 {
     global $wpdb;
     $db_version = get_option('un_version');
     if ($db_version == UN_VERSION) {
         return;
     }
     if (!$db_version) {
         add_option('un_version', UN_VERSION);
         $wpdb->query("UPDATE {$wpdb->postmeta} \n\t\t\t\tINNER JOIN {$wpdb->posts} ON {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id\n\t\t\t\tSET meta_key = '_email' \n\t\t\t\tWHERE meta_key = 'email' AND post_type = 'feedback'\n\t\t\t\t");
     }
     if (version_compare($db_version, '0.4') == -1) {
         $wpdb->query($wpdb->prepare("UPDATE {$wpdb->posts} SET post_type = %s WHERE post_type = %s", FEEDBACK, 'feedback'));
         global $wp_roles;
         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);
             }
         }
     }
     if (version_compare($db_version, '0.6') == -1) {
         $options = array(UN_USE_FONT, UN_FEEDBACK_BUTTON_TEXT, UN_FEEDBACK_BUTTON_COLOR, UN_FEEDBACK_BUTTON_TEXT_COLOR, UN_FEEDBACK_BUTTON_POSITION, UN_FEEDBACK_FORM_TITLE, UN_FEEDBACK_FORM_TEXT, UN_FEEDBACK_FORM_SHOW_SUMMARY, UN_FEEDBACK_FORM_SHOW_TYPE, UN_FEEDBACK_FORM_SHOW_EMAIL, UN_SUBMIT_FEEDBACK_BUTTON_TEXT, UN_THANKYOU_TITLE, UN_THANKYOU_TEXT, UN_ADMIN_NOTIFY_ON_FEEDBACK, UN_SUBMIT_FEEDBACK_BUTTON_TEXT, UN_SHOW_POWERED_BY, UN_FEEDBACK_BUTTON_SHOW_BORDER, UN_DISABLE_ON_MOBILES, UN_ENABLED, UN_LOAD_IN_FOOTER);
         foreach ($options as $option) {
             $value = get_option('un_' . $option);
             if ($value) {
                 un_set_option($option, $value);
             }
             delete_option('un_' . $option);
         }
     }
     update_option('un_version', UN_VERSION);
 }
Exemplo n.º 2
0
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');
}
Exemplo n.º 3
0
function un_deactivation_hook()
{
    delete_option('un_version');
    global $wp_roles;
    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->remove_cap($role, $cap);
        }
    }
    flush_rewrite_rules();
}