Ejemplo n.º 1
2
/**
 * Create base pages, add roles, add caps and create tables
 * @param $network_wide
 */
function anspress_activate($network_wide)
{
    // add roles
    $ap_roles = new AP_Roles();
    $ap_roles->add_roles();
    $ap_roles->add_capabilities();
    ap_create_base_page();
    if (ap_opt('ap_version') != AP_VERSION) {
        ap_opt('ap_installed', 'false');
        ap_opt('ap_version', AP_VERSION);
    }
    global $wpdb;
    /**
     * Run DB quries only if AP_DB_VERSION does not match
     */
    if (ap_opt('ap_db_version') != AP_DB_VERSION) {
        $charset_collate = !empty($wpdb->charset) ? "DEFAULT CHARACTER SET " . $wpdb->charset : '';
        $meta_table = "CREATE TABLE IF NOT EXISTS `" . $wpdb->prefix . "ap_meta` (\n\t\t\t\t  `apmeta_id` bigint(20) NOT NULL AUTO_INCREMENT,\n\t\t\t\t  `apmeta_userid` bigint(20) DEFAULT NULL,\n\t\t\t\t  `apmeta_type` varchar(256) DEFAULT NULL,\n\t\t\t\t  `apmeta_actionid` bigint(20) DEFAULT NULL,\n\t\t\t\t  `apmeta_value` text,\n\t\t\t\t  `apmeta_param` LONGTEXT DEFAULT NULL,\n\t\t\t\t  `apmeta_date` timestamp NULL DEFAULT NULL,\n\t\t\t\t  PRIMARY KEY (`apmeta_id`)\n\t\t\t\t)" . $charset_collate . ";";
        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
        dbDelta($meta_table);
        ap_opt('ap_db_version', AP_DB_VERSION);
    }
    if (!get_option('anspress_opt')) {
        update_option('anspress_opt', ap_default_options());
    } else {
        update_option('anspress_opt', get_option('anspress_opt') + ap_default_options());
    }
    ap_opt('ap_flush', 'true');
    flush_rewrite_rules(false);
}
Ejemplo n.º 2
0
/**
 * Create base pages, add roles, add caps and create tables
 * @param $network_wide
 */
function anspress_activate($network_wide)
{
    // add roles
    $ap_roles = new AP_Roles();
    $ap_roles->add_roles();
    $ap_roles->add_capabilities();
    ap_create_base_page();
    if (ap_opt('ap_version') != AP_VERSION) {
        ap_opt('ap_installed', 'false');
        ap_opt('ap_version', AP_VERSION);
    }
    global $wpdb;
    /**
     * Run DB quries only if AP_DB_VERSION does not match
     */
    if (ap_opt('ap_db_version') != AP_DB_VERSION) {
        $charset_collate = !empty($wpdb->charset) ? 'DEFAULT CHARACTER SET ' . $wpdb->charset : '';
        $meta_table = 'CREATE TABLE IF NOT EXISTS `' . $wpdb->prefix . 'ap_meta` (
            `apmeta_id` bigint(20) NOT NULL AUTO_INCREMENT,
            `apmeta_userid` bigint(20) DEFAULT NULL,
            `apmeta_type` varchar(256) DEFAULT NULL,
            `apmeta_actionid` bigint(20) DEFAULT NULL,
            `apmeta_value` text,
            `apmeta_param` LONGTEXT DEFAULT NULL,
            `apmeta_date` timestamp NULL DEFAULT NULL,
            PRIMARY KEY (`apmeta_id`)
            )' . $charset_collate . ';';
        $activity_table = 'CREATE TABLE IF NOT EXISTS `' . $wpdb->prefix . 'ap_activity` (
		    `id` bigint(20) NOT NULL AUTO_INCREMENT,
		    `user_id` bigint(20) DEFAULT NULL,
		    `secondary_user` bigint(20) DEFAULT NULL,
		    `type` varchar(256) DEFAULT NULL,
		    `parent_type` varchar(256) DEFAULT NULL,
		    `status` varchar(256) DEFAULT NULL,
		    `content` LONGTEXT DEFAULT NULL,
		    `permalink` text DEFAULT NULL,
		    `question_id` bigint(20) DEFAULT NULL,
		    `answer_id` bigint(20) DEFAULT NULL,
		    `item_id` bigint(20) DEFAULT NULL,
		    `created` timestamp NULL DEFAULT NULL,
		    `updated` timestamp NULL DEFAULT NULL,
		    PRIMARY KEY (`id`)
		    )' . $charset_collate . ';';
        $activity_meta = "CREATE TABLE IF NOT EXISTS `" . $wpdb->base_prefix . "ap_activitymeta` (\n\t\t\t  `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t  `ap_activity_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\t  PRIMARY KEY (`meta_id`)\n\t\t\t)" . $charset_collate . ";";
        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
        dbDelta($meta_table);
        dbDelta($activity_table);
        dbDelta($activity_meta);
        ap_opt('ap_db_version', AP_DB_VERSION);
    }
    if (!get_option('anspress_opt')) {
        update_option('anspress_opt', ap_default_options());
    } else {
        update_option('anspress_opt', get_option('anspress_opt') + ap_default_options());
    }
    ap_opt('ap_flush', 'true');
    flush_rewrite_rules(false);
}
Ejemplo n.º 3
0
/**
 * Create base pages, add roles, add caps and create tables
 * @param $network_wide
 */
function anspress_activate($network_wide)
{
    $category_ext = 'categories-for-anspress/categories-for-anspress.php';
    $category_error = false;
    if (file_exists(WP_PLUGIN_DIR . '/' . $category_ext)) {
        $category_ext_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $category_ext);
        $category_error = !version_compare($category_ext_data['Version'], '1.3.5', '>=') ? true : false;
    }
    $tag_ext = 'tags-for-anspress/tags-for-anspress.php';
    $tag_error = false;
    if (file_exists(WP_PLUGIN_DIR . '/' . $tag_ext)) {
        $tag_ext_data = get_plugin_data(WP_PLUGIN_DIR . '/' . $tag_ext);
        $tag_error = !version_compare($tag_ext_data['Version'], '1.2.7', '>=') ? true : false;
    }
    if ($category_error || $tag_error) {
        echo '<h3>' . __('Please update all AnsPress extensions before activating. <a target="_blank" href="http://anspress.io/questions/ask/">Ask for help</a>', 'ap') . '</h3>';
        @trigger_error(__('Please update all AnsPress extensions before activating.', 'ap'), E_USER_ERROR);
    }
    // add roles
    $ap_roles = new AP_Roles();
    $ap_roles->add_roles();
    $ap_roles->add_capabilities();
    ap_create_base_page();
    if (ap_opt('ap_version') != AP_VERSION) {
        ap_opt('ap_installed', 'false');
        ap_opt('ap_version', AP_VERSION);
    }
    global $wpdb;
    /**
     * Run DB quries only if AP_DB_VERSION does not match
     */
    if (ap_opt('ap_db_version') != AP_DB_VERSION) {
        $charset_collate = !empty($wpdb->charset) ? "DEFAULT CHARACTER SET " . $wpdb->charset : '';
        $meta_table = "CREATE TABLE IF NOT EXISTS `" . $wpdb->base_prefix . "ap_meta` (\r\n\t\t\t\t  `apmeta_id` bigint(20) NOT NULL AUTO_INCREMENT,\r\n\t\t\t\t  `apmeta_userid` bigint(20) DEFAULT NULL,\r\n\t\t\t\t  `apmeta_type` varchar(256) DEFAULT NULL,\r\n\t\t\t\t  `apmeta_actionid` bigint(20) DEFAULT NULL,\r\n\t\t\t\t  `apmeta_value` text,\r\n\t\t\t\t  `apmeta_param` LONGTEXT DEFAULT NULL,\r\n\t\t\t\t  `apmeta_date` timestamp NULL DEFAULT NULL,\r\n\t\t\t\t  PRIMARY KEY (`apmeta_id`)\r\n\t\t\t\t)" . $charset_collate . ";";
        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
        dbDelta($meta_table);
        ap_opt('ap_db_version', AP_DB_VERSION);
    }
    if (!get_option('anspress_opt')) {
        update_option('anspress_opt', ap_default_options());
    } else {
        update_option('anspress_opt', get_option('anspress_opt') + ap_default_options());
    }
    ap_opt('ap_flush', 'true');
    flush_rewrite_rules(false);
}
/**
 * Plugin un-installation hook, called by WP while removing AnsPress
 */
function anspress_uninstall()
{
    if (!current_user_can('activate_plugins')) {
        return;
    }
    check_admin_referer('bulk-plugins');
    if (!ap_opt('db_cleanup')) {
        return;
    }
    global $wpdb;
    // remove question and answer cpt
    $wpdb->query("DELETE FROM {$wpdb->posts} WHERE post_type = 'question'");
    $wpdb->query("DELETE FROM {$wpdb->posts} WHERE post_type = 'answer'");
    // remove meta table
    $meta_table = $wpdb->prefix . 'ap_meta';
    $wpdb->query("DROP TABLE IF EXISTS {$meta_table}");
    // remove option
    delete_option('anspress_opt');
    delete_option('ap_reputation');
    // Remove user roles
    AP_Roles::remove_roles();
}
Ejemplo n.º 5
0
 /**
  * Create base pages, add roles, add caps and create tables
  * @param $network_wide
  */
 public function activate($network_wide)
 {
     // add roles.
     $ap_roles = new AP_Roles();
     $ap_roles->add_roles();
     $ap_roles->add_capabilities();
     ap_create_base_page();
     if (in_array(ap_opt('ap_version'), array('2.3.8', '2.4-beta1', '2.4-beta2', '2.4-beta3', '2.4-beta4'))) {
         update_option('ap_update_helper', true);
     }
     if (ap_opt('ap_version') != AP_VERSION) {
         ap_opt('ap_installed', 'false');
         ap_opt('ap_version', AP_VERSION);
     }
     /**
      * Run DB quries only if AP_DB_VERSION does not match
      */
     if (ap_opt('ap_db_version') != AP_DB_VERSION) {
         $this->insert_tables();
         ap_opt('ap_db_version', AP_DB_VERSION);
     }
     if (!get_option('anspress_opt')) {
         update_option('anspress_opt', ap_default_options());
     } else {
         update_option('anspress_opt', get_option('anspress_opt') + ap_default_options());
     }
     ap_opt('ap_flush', 'true');
     flush_rewrite_rules(false);
 }
Ejemplo n.º 6
0
 /**
  * Create base pages, add roles, add caps and create tables
  */
 public function activate()
 {
     // add roles.
     $ap_roles = new AP_Roles();
     $ap_roles->add_roles();
     $ap_roles->add_capabilities();
     ap_create_base_page();
     if (in_array(ap_opt('ap_version'), array('2.3.8', '2.4-beta1', '2.4-beta2', '2.4-beta3', '2.4-beta4'))) {
         update_option('ap_update_helper', true);
     }
     if (ap_opt('ap_version') != AP_VERSION) {
         ap_opt('ap_installed', 'false');
         ap_opt('ap_version', AP_VERSION);
     }
     $this->insert_tables();
     update_option('anspress_opt', get_option('anspress_opt') + ap_default_options());
     ap_opt('ap_flush', 'true');
     flush_rewrite_rules(false);
 }