Example #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);
}
Example #2
0
/**
 * To retrive AnsPress option 		
 * @param  string $key   Name of option to retrive,
 *                       Keep it blank to get all options of AnsPress
 * @param  string $value Enter value to update existing option
 * @return string         
 * @since 0.1
 */
function ap_opt($key = false, $value = null)
{
    $settings = wp_cache_get('ap_opt', 'options');
    if ($settings === false) {
        $settings = get_option('anspress_opt');
        if (!$settings) {
            $settings = array();
        }
        $settings = $settings + ap_default_options();
        wp_cache_set('ap_opt', $settings, 'options');
    }
    if (!is_null($value)) {
        $settings[$key] = $value;
        update_option('anspress_opt', $settings);
        // clear cache if option updated
        wp_cache_delete('ap_opt', 'options');
        return;
    }
    if (false === $key) {
        return $settings;
    }
    if (isset($settings[$key])) {
        return $settings[$key];
    } else {
        return NULL;
    }
    return false;
}
Example #3
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);
}
Example #4
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);
}
Example #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);
 }
Example #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);
 }
Example #7
0
<?php

$options = get_option('anspress_opt');
$settings = $options + ap_default_options();
if (!isset($_REQUEST['settings-updated'])) {
    $_REQUEST['settings-updated'] = false;
}
// This checks whether the form has just been submitted.
?>

<div class="wrap">
	<?php 
screen_icon();
echo '<h2>' . __('AnsPress Options') . '</h2>';
// This shows the page's name and an icon if one has been provided
?>
			
	<?php 
if (false !== $_REQUEST['settings-updated']) {
    ?>
	<div class="updated fade"><p><strong><?php 
    _e('Options saved');
    ?>
</strong></p></div>
	<?php 
}
// If the form has just been submitted, this shows the notification
?>
	
	<div class="get-support">
		<strong>Need more help ? feel free to ask for support. </strong>
Example #8
0
 /**
  * Fired when the plugin is activated.
  *
  * @since    1.0.0
  *
  * @param    boolean    $network_wide    True if WPMU superadmin uses
  *                                       "Network Activate" action, false if
  *                                       WPMU is disabled or plugin is
  *                                       activated on an individual blog.
  */
 public static function activate($network_wide)
 {
     global $wpdb;
     anspress_activate::add_roles();
     // create base page
     if (!get_option('ap_base_page_created') || !get_post(get_option('ap_base_page_created'))) {
         global $user_ID;
         $post = array();
         $post['post_type'] = 'page';
         $post['post_content'] = '[anspress]';
         $post['post_author'] = null;
         $post['post_status'] = 'publish';
         $post['post_title'] = '[anspress]';
         $postid = wp_insert_post($post);
         if ($postid) {
             update_option('ap_base_page_created', $postid);
             $post = get_post($postid);
             ap_opt('base_page_slug', $post->post_name);
             ap_opt('base_page', $postid);
         }
     }
     if (get_option('ap_version') != AP_VERSION) {
         update_option('ap_installed', false);
         update_option('ap_version', AP_VERSION);
     }
     // create table
     if (get_option('ap_db_version') != AP_DB_VERSION) {
         if (!empty($wpdb->charset)) {
             $charset_collate = "DEFAULT CHARACTER SET " . $wpdb->charset;
         }
         $meta_table = "CREATE TABLE IF NOT EXISTS `" . $wpdb->base_prefix . "ap_meta` (\n\t\t\t\t\t  `apmeta_id` bigint(20) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t  `apmeta_userid` bigint(20) DEFAULT NULL,\n\t\t\t\t\t  `apmeta_type` varchar(256) DEFAULT NULL,\n\t\t\t\t\t  `apmeta_actionid` bigint(20) DEFAULT NULL,\n\t\t\t\t\t  `apmeta_value` text,\n\t\t\t\t\t  `apmeta_param` LONGTEXT DEFAULT NULL,\n\t\t\t\t\t  `apmeta_date` timestamp NULL DEFAULT NULL,\n\t\t\t\t\t  PRIMARY KEY (`apmeta_id`)\n\t\t\t\t\t)" . $charset_collate . ";";
         $message_table = "CREATE TABLE IF NOT EXISTS " . $wpdb->prefix . "ap_messages (\n\t\t\t\t\t`message_id` bigint(20) NOT NULL auto_increment,\n\t\t\t\t\t`message_content` text NOT NULL,\n\t\t\t\t\t`message_sender` bigint(20) NOT NULL,\n\t\t\t\t\t`message_conversation` bigint(20) NOT NULL,\n\t\t\t\t\t`message_date` datetime NOT NULL,\n\t\t\t\t\t`message_read` tinyint(1) NOT NULL,\n\t\t\t\t\tPRIMARY KEY (`message_id`)\n\t\t\t\t  )" . $charset_collate . ";";
         require_once ABSPATH . 'wp-admin/includes/upgrade.php';
         dbDelta($meta_table);
         dbDelta($message_table);
         update_option('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());
     }
     if (function_exists('is_multisite') && is_multisite()) {
         if ($network_wide) {
             // Get all blog ids
             $blog_ids = self::get_blog_ids();
             foreach ($blog_ids as $blog_id) {
                 switch_to_blog($blog_id);
                 self::single_activate();
             }
             restore_current_blog();
         } else {
             self::single_activate();
         }
     } else {
         self::single_activate();
     }
     add_option('ap_flush', true);
     flush_rewrite_rules(false);
 }