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
 public function init()
 {
     // return if reputation is disabled
     if (ap_opt('disable_reputation')) {
         return;
     }
     ap_register_user_page('reputation', __('Reputation', 'ap'), array($this, 'reputation_page'));
     add_filter('ap_user_menu', array($this, 'sort_reputation_page'));
     add_action('ap_after_new_question', array($this, 'new_question'));
     add_action('ap_untrash_question', array($this, 'new_question'));
     add_action('ap_trash_question', array($this, 'trash_question'), 10, 2);
     add_action('ap_after_new_answer', array($this, 'new_answer'));
     add_action('ap_untrash_answer', array($this, 'new_answer'));
     add_action('ap_trash_answer', array($this, 'delete_answer'), 10, 2);
     add_action('ap_select_answer', array($this, 'select_answer'), 10, 3);
     add_action('ap_unselect_answer', array($this, 'unselect_answer'), 10, 3);
     add_action('ap_vote_up', array($this, 'vote_up'), 10, 2);
     add_action('ap_vote_down', array($this, 'vote_down'), 10, 2);
     add_action('ap_undo_vote_up', array($this, 'undo_vote_up'), 10, 2);
     add_action('ap_undo_vote_down', array($this, 'undo_vote_down'), 10, 2);
     add_action('ap_publish_comment', array($this, 'new_comment'));
     add_action('ap_unpublish_comment', array($this, 'delete_comment'));
     add_filter('ap_user_display_meta_array', array($this, 'display_meta'), 10, 2);
     add_filter('user_register', array($this, 'user_register'));
 }
Ejemplo n.º 3
0
function ap_scripts_front()
{
    wp_enqueue_script('jquery');
    wp_enqueue_script('jquery-form', array('jquery'), false);
    wp_enqueue_script('ap-functions-js', ANSPRESS_URL . 'assets/prod/ap-functions.min.js', array('jquery', 'jquery-form'));
    wp_enqueue_script('ap-anspress_script', ANSPRESS_URL . 'assets/prod/anspress_site.min.js', array('jquery', 'jquery-form'), AP_VERSION);
    wp_enqueue_script('peity-js', ap_get_theme_url('js/jquery.peity.min.js'), 'jquery', AP_VERSION);
    wp_enqueue_script('ap-initial.js', ap_get_theme_url('js/initial.min.js'), 'jquery', AP_VERSION);
    wp_enqueue_script('ap-scrollbar.js', ap_get_theme_url('js/jquery.scrollbar.min.js'), 'jquery', AP_VERSION);
    wp_enqueue_script('ap-js', ap_get_theme_url('prod/ap.min.js'), array('jquery', 'jquery-form'), AP_VERSION);
    wp_enqueue_style('ap-style', ap_get_theme_url('css/main.css'), array(), AP_VERSION);
    $custom_css = '
        #anspress .ap-q-cells{
                margin-left: ' . (ap_opt('avatar_size_qquestion') + 10) . 'px;
        }
        #anspress .ap-a-cells{
                margin-left: ' . (ap_opt('avatar_size_qanswer') + 10) . 'px;
        }#anspress .ap-comment-content{
                margin-left: ' . (ap_opt('avatar_size_qcomment') + 15) . 'px;
        }';
    wp_add_inline_style('ap-style', $custom_css);
    wp_enqueue_style('ap-fonts', ap_get_theme_url('fonts/style.css'), array(), AP_VERSION);
    do_action('ap_enqueue');
    wp_enqueue_style('ap-responsive', ap_get_theme_url('css/responsive.css'), array(), AP_VERSION);
    wp_enqueue_style('ap-overrides', ap_get_theme_url('css/overrides.css'), array(), AP_VERSION);
    echo '<script type="text/javascript">';
    echo 'var ajaxurl = "' . admin_url('admin-ajax.php') . '",';
    echo 'ap_nonce 	= "' . wp_create_nonce('ap_ajax_nonce') . '",';
    echo 'ap_max_tags = "' . ap_opt('max_tags') . '",';
    echo 'disable_hover_card = "' . (ap_opt('disable_hover_card') ? true : false) . '"';
    echo '</script>';
    wp_localize_script('ap-anspress_script', 'aplang', array('password_field_not_macthing' => __('Password not matching', 'ap'), 'password_length_less' => __('Password length must be 6 or higher', 'ap'), 'not_valid_email' => __('Not a valid email', 'ap'), 'username_less' => __('Username length must be 4 or higher', 'ap'), 'username_not_avilable' => __('Username not available', 'ap'), 'email_already_in_use' => sprintf(__('Email already in use. %sDo you want to reset your password?%s', 'ap'), '<a href="' . wp_lostpassword_url() . '">', '</a>'), 'loading' => __('Loading', 'ap'), 'sending' => __('Sending request', 'ap'), 'adding_to_fav' => __('Adding question to your favorites', 'ap'), 'voting_on_post' => __('Sending your vote', 'ap'), 'requesting_for_closing' => __('Requesting for closing this question', 'ap'), 'sending_request' => __('Submitting request', 'ap'), 'loading_comment_form' => __('Loading comment form', 'ap'), 'submitting_your_question' => __('Sending your question', 'ap'), 'submitting_your_answer' => __('Sending your answer', 'ap'), 'submitting_your_comment' => __('Sending your comment', 'ap'), 'deleting_comment' => __('Deleting comment', 'ap'), 'updating_comment' => __('Updating comment', 'ap'), 'loading_form' => __('Loading form', 'ap'), 'saving_labels' => __('Saving labels', 'ap'), 'loading_suggestions' => __('Loading suggestions', 'ap'), 'uploading_cover' => __('Uploading cover', 'ap'), 'saving_profile' => __('Saving profile', 'ap'), 'sending_message' => __('Sending message', 'ap'), 'loading_conversation' => __('Loading conversation', 'ap'), 'loading_new_message_form' => __('Loading new message form', 'ap'), 'loading_more_conversations' => __('Loading more conversations', 'ap'), 'searching_conversations' => __('Searching conversations', 'ap'), 'loading_message_edit_form' => __('Loading message form', 'ap'), 'updating_message' => __('Updating message', 'ap'), 'deleting_message' => __('Deleting message', 'ap'), 'uploading' => __('Uploading', 'ap'), 'error' => ap_icon('error'), 'warning' => ap_icon('warning'), 'success' => ap_icon('success'), 'not_valid_response' => __('Something went wrong in server side, not a valid response.', 'ap')));
    wp_localize_script('ap-site-js', 'apoptions', array('ajaxlogin' => ap_opt('ajax_login')));
}
Ejemplo n.º 4
0
 /**
  * Rewrite rules
  * @return array
  */
 public function rewrites()
 {
     global $wp_rewrite;
     global $ap_rules;
     unset($wp_rewrite->extra_permastructs['question']);
     unset($wp_rewrite->extra_permastructs['answer']);
     $base_page_id = ap_opt('base_page');
     $slug = ap_base_page_slug() . '/';
     $question_slug = ap_opt('question_page_slug');
     if (empty($question_slug)) {
         $question_slug = 'question';
     }
     $user_page = ap_opt('base_before_user_perma') ? $slug . ap_get_user_page_slug() . '/' : ap_get_user_page_slug() . '/';
     $new_rules = array($slug . 'parent/([^/]+)/?' => 'index.php?page_id=' . $base_page_id . '&parent=' . $wp_rewrite->preg_index(1), $slug . 'tag/([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?page_id=' . $base_page_id . '&ap_page=tag&q_tag=' . $wp_rewrite->preg_index(1) . '&paged=' . $wp_rewrite->preg_index(2), $slug . 'tag/([^/]+)/?' => 'index.php?page_id=' . $base_page_id . '&ap_page=tag&q_tag=' . $wp_rewrite->preg_index(1), $slug . 'page/?([0-9]{1,})/?$' => 'index.php?page_id=' . $base_page_id . '&paged=' . $wp_rewrite->preg_index(1), $slug . '([^/]+)/page/?([0-9]{1,})/?$' => 'index.php?page_id=' . $base_page_id . '&ap_page=' . $wp_rewrite->preg_index(1) . '&paged=' . $wp_rewrite->preg_index(2));
     if (!ap_opt('question_permalink_follow')) {
         $new_rules[$question_slug . '/([^/]+)/page/?([0-9]{1,})/?$'] = 'index.php?page_id=' . $base_page_id . '&question_name=' . $wp_rewrite->preg_index(1) . '&paged=' . $wp_rewrite->preg_index(2);
         $new_rules[$question_slug . '/([^/]+)/?$'] = 'index.php?page_id=' . $base_page_id . '&question_name=' . $wp_rewrite->preg_index(1);
     } else {
         $new_rules[$slug . $question_slug . '/([^/]+)/page/?([0-9]{1,})/?$'] = 'index.php?page_id=' . $base_page_id . '&question_name=' . $wp_rewrite->preg_index(1) . '&paged=' . $wp_rewrite->preg_index(2);
         $new_rules[$slug . $question_slug . '/([^/]+)/?$'] = 'index.php?page_id=' . $base_page_id . '&question_name=' . $wp_rewrite->preg_index(1);
     }
     $new_rules[$slug . $question_slug . '/([^/]+)/([^/]+)/?$'] = 'index.php?page_id=' . $base_page_id . '&question_id=' . $wp_rewrite->preg_index(1) . '&question_name=' . $wp_rewrite->preg_index(2);
     $new_rules[$user_page . '([^/]+)/([^/]+)/page/?([0-9]{1,})/?$'] = 'index.php?page_id=' . $base_page_id . '&ap_page=' . ap_get_user_page_slug() . '&ap_user='******'&user_page=' . $wp_rewrite->preg_index(2) . '&paged=' . $wp_rewrite->preg_index(3);
     $new_rules[$user_page . '([^/]+)/([^/]+)/?'] = 'index.php?page_id=' . $base_page_id . '&ap_page=' . ap_get_user_page_slug() . '&ap_user='******'&user_page=' . $wp_rewrite->preg_index(2);
     $new_rules[$user_page . '([^/]+)/?$'] = 'index.php?page_id=' . $base_page_id . '&ap_page=' . ap_get_user_page_slug() . '&ap_user='******'?$'] = 'index.php?page_id=' . $base_page_id . '&ap_page=' . ap_get_user_page_slug();
     $new_rules[$slug . 'search/([^/]+)/?'] = 'index.php?page_id=' . $base_page_id . '&ap_page=search&ap_s=' . $wp_rewrite->preg_index(1);
     $new_rules[$slug . 'ask/([^/]+)/?'] = 'index.php?page_id=' . $base_page_id . '&ap_page=ask&parent=' . $wp_rewrite->preg_index(1);
     $new_rules[$slug . '([^/]+)/?'] = 'index.php?page_id=' . $base_page_id . '&ap_page=' . $wp_rewrite->preg_index(1);
     $ap_rules = apply_filters('ap_rewrite_rules', $new_rules, $slug, $base_page_id);
     return $wp_rewrite->rules = $ap_rules + $wp_rewrite->rules;
 }
Ejemplo n.º 5
0
 /**
  * Rewrite rules
  * @return array
  */
 public function rewrites()
 {
     global $wp_rewrite;
     global $ap_rules;
     unset($wp_rewrite->extra_permastructs['question']);
     unset($wp_rewrite->extra_permastructs['answer']);
     $base_page_id = ap_opt('base_page');
     $slug = ap_base_page_slug() . '/';
     $question_slug = ap_opt('question_page_slug');
     $user_page = ap_opt('base_before_user_perma') ? $slug . 'user/' : ap_opt('user_page_slug') . '/';
     $new_rules = array($slug . "parent/([^/]+)/?" => "index.php?page_id=" . $base_page_id . "&parent=" . $wp_rewrite->preg_index(1), $slug . "category/([^/]+)/page/?([0-9]{1,})/?\$" => "index.php?page_id=" . $base_page_id . "&ap_page=category&q_cat=" . $wp_rewrite->preg_index(1) . "&paged=" . $wp_rewrite->preg_index(2), $slug . "tag/([^/]+)/page/?([0-9]{1,})/?\$" => "index.php?page_id=" . $base_page_id . "&ap_page=tag&q_tag=" . $wp_rewrite->preg_index(1) . "&paged=" . $wp_rewrite->preg_index(2), $slug . "category/([^/]+)/?" => "index.php?page_id=" . $base_page_id . "&ap_page=category&q_cat=" . $wp_rewrite->preg_index(1), $slug . "tag/([^/]+)/?" => "index.php?page_id=" . $base_page_id . "&ap_page=tag&q_tag=" . $wp_rewrite->preg_index(1), $slug . "page/?([0-9]{1,})/?\$" => "index.php?page_id=" . $base_page_id . "&paged=" . $wp_rewrite->preg_index(1), $slug . "([^/]+)/page/?([0-9]{1,})/?\$" => "index.php?page_id=" . $base_page_id . "&ap_page=" . $wp_rewrite->preg_index(1) . "&paged=" . $wp_rewrite->preg_index(2));
     if (!ap_opt('question_permalink_follow')) {
         $new_rules[$question_slug . "/([^/]+)/page/?([0-9]{1,})/?\$"] = "index.php?page_id=" . $base_page_id . "&question_name=" . $wp_rewrite->preg_index(1) . "&paged=" . $wp_rewrite->preg_index(2);
         $new_rules[$question_slug . "/([^/]+)/?\$"] = "index.php?page_id=" . $base_page_id . "&question_name=" . $wp_rewrite->preg_index(1);
     } else {
         $new_rules[$slug . $question_slug . "/([^/]+)/page/?([0-9]{1,})/?\$"] = "index.php?page_id=" . $base_page_id . "&question_name=" . $wp_rewrite->preg_index(1) . "&paged=" . $wp_rewrite->preg_index(2);
         $new_rules[$slug . $question_slug . "/([^/]+)/?\$"] = "index.php?page_id=" . $base_page_id . "&question_name=" . $wp_rewrite->preg_index(1);
     }
     $new_rules[$slug . $question_slug . "/([^/]+)/([^/]+)/?\$"] = "index.php?page_id=" . $base_page_id . "&question_id=" . $wp_rewrite->preg_index(1) . "&question_name=" . $wp_rewrite->preg_index(2);
     $new_rules[$user_page . "([^/]+)/([^/]+)/page/?([0-9]{1,})/?\$"] = "index.php?page_id=" . $base_page_id . "&ap_page=user&ap_user="******"&user_page=" . $wp_rewrite->preg_index(2) . "&paged=" . $wp_rewrite->preg_index(3);
     $new_rules[$user_page . "([^/]+)/([^/]+)/?"] = "index.php?page_id=" . $base_page_id . "&ap_page=user&ap_user="******"&user_page=" . $wp_rewrite->preg_index(2);
     $new_rules[$user_page . "([^/]+)/?\$"] = "index.php?page_id=" . $base_page_id . "&ap_page=user&ap_user="******"?\$"] = "index.php?page_id=" . $base_page_id . "&ap_page=user";
     $new_rules[$slug . "search/([^/]+)/?"] = "index.php?page_id=" . $base_page_id . "&ap_page=search&ap_s=" . $wp_rewrite->preg_index(1);
     $new_rules[$slug . "ask/([^/]+)/?"] = "index.php?page_id=" . $base_page_id . "&ap_page=ask&parent=" . $wp_rewrite->preg_index(1);
     $new_rules[$slug . "([^/]+)/?"] = "index.php?page_id=" . $base_page_id . "&ap_page=" . $wp_rewrite->preg_index(1);
     $ap_rules = apply_filters('ap_rewrite_rules', $new_rules);
     return $wp_rewrite->rules = $ap_rules + $wp_rewrite->rules;
 }
Ejemplo n.º 6
0
 public function ask_form_name_field($args)
 {
     if (!is_user_logged_in() && ap_opt('allow_anonymous')) {
         $args['fields'][] = array('name' => 'name', 'label' => __('Name', 'ap'), 'type' => 'text', 'placeholder' => __('Enter your name to display', 'ap'), 'value' => sanitize_text_field(@$_POST['name']), 'order' => 12);
     }
     return $args;
 }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
0
 /**
  * Initialize class
  * @param array $args
  * @access public
  * @since  2.0
  */
 public function __construct($args = array())
 {
     $paged = get_query_var('paged') ? get_query_var('paged') : 1;
     if (isset($args['post_parent'])) {
         $post_parent = $args['post_parent'];
     } else {
         $post_parent = get_query_var('parent') ? get_query_var('parent') : false;
     }
     $defaults = array('showposts' => ap_opt('question_per_page'), 'paged' => $paged);
     $args['post_status'][] = 'publish';
     $args['post_status'][] = 'closed';
     if ($post_parent) {
         $this->args['post_parent'] = $post_parent;
     }
     $this->args = wp_parse_args($args, $defaults);
     if (get_query_var('ap_s') != '') {
         $this->args['s'] = sanitize_text_field(get_query_var('ap_s'));
     }
     if (isset($this->args['sortby'])) {
         $this->orderby_questions();
     }
     $this->args['post_type'] = 'question';
     $args = $this->args;
     /**
      * Initialize parent class
      */
     parent::__construct($args);
 }
Ejemplo n.º 9
0
 /**
  * Initialize class
  * @param array $args Query arguments.
  * @access public
  * @since  2.0
  */
 public function __construct($args = array())
 {
     global $answers;
     $paged = get_query_var('paged') ? get_query_var('paged') : 1;
     $defaults = array('question_id' => get_question_id(), 'ap_answers_query' => true, 'showposts' => ap_opt('answers_per_page'), 'paged' => $paged, 'only_best_answer' => false, 'include_best_answer' => false);
     $args['post_status'][] = 'publish';
     $args['post_status'][] = 'closed';
     $this->args = wp_parse_args($args, $defaults);
     if (isset($this->args['question_id'])) {
         $question_id = $this->args['question_id'];
     }
     if (!empty($question_id)) {
         $this->args['post_parent'] = $question_id;
     }
     if (isset($this->args['sortby'])) {
         $this->orderby_answers();
     }
     // Check if requesting only for best Answer
     if (isset($this->args['only_best_answer']) && $this->args['only_best_answer']) {
         $this->args['meta_query'] = array(array('key' => ANSPRESS_BEST_META, 'type' => 'BOOLEAN', 'compare' => '=', 'value' => '1'));
     }
     $this->args['post_type'] = 'answer';
     $args = $this->args;
     /**
      * Initialize parent class
      */
     parent::__construct($args);
 }
Ejemplo n.º 10
0
    function ap_comment($comment)
    {
        $GLOBALS['comment'] = $comment;
        ?>
		<li <?php 
        comment_class();
        ?>
 id="li-comment-<?php 
        comment_ID();
        ?>
">
			<article id="comment-<?php 
        comment_ID();
        ?>
" class="comment">
				<div class="ap-avatar">
					<a href="<?php 
        echo ap_user_link($comment->user_id);
        ?>
">
					<?php 
        echo get_avatar($comment, ap_opt('avatar_size_qcomment'));
        ?>
					</a>
				</div>
				<div class="comment-content">
					<?php 
        if ('0' == $comment->comment_approved) {
            ?>
						<p class="comment-awaiting-moderation"><?php 
            _e('Your comment is awaiting moderation.', 'ap');
            ?>
</p>
					<?php 
        }
        ?>
										
					<p class="ap-comment-texts">
						<?php 
        echo get_comment_text();
        ?>
						<?php 
        printf(' - <time datetime="%1$s">%2$s %3$s</time>', get_comment_time('c'), ap_human_time(get_comment_time('U')), __('ago', 'ap'));
        ?>
					</p>
					<div class="comment-meta">
						<?php 
        if (ap_user_can_edit_comment(get_comment_ID())) {
            echo '<a class="comment-edit-btn" href="#" data-button="ap-edit-comment" data-args="' . get_comment_ID() . '-' . wp_create_nonce('comment-' . get_comment_ID()) . '"><i class="aicon-pencil"></i> ' . __('Edit', 'ap') . '</a>';
        }
        if (ap_user_can_delete_comment(get_comment_ID())) {
            echo '<a class="comment-delete-btn" href="#" data-button="ap-delete-comment" data-confirm="' . __('Are you sure? It cannot be undone!', 'ap') . '" data-args="' . get_comment_ID() . '-' . wp_create_nonce('delete-comment-' . get_comment_ID()) . '"><i class="aicon-close"></i> ' . __('Delete', 'ap') . '</a>';
        }
        ?>
					</div>					
				</div>
			</article>
		<?php 
    }
Ejemplo n.º 11
0
 public function __construct($args = '')
 {
     $this->per_page = ap_opt('users_per_page');
     // grab the current page number and set to 1 if no page number is set
     $this->paged = get_query_var('paged') ? get_query_var('paged') : 1;
     $this->offset = $this->per_page * ($this->paged - 1);
     $args = wp_parse_args($args, array('number' => $this->per_page, 'offset' => $this->offset, 'sortby' => 'reputtaion'));
     if (isset($args['ID'])) {
         $this->users = array(get_user_by('id', $args['ID']));
         $this->total_user_count = 1;
         $this->total_pages = 1;
         $this->user_count = 1;
     } else {
         if (isset($args['sortby'])) {
             switch ($args['sortby']) {
                 case 'newest':
                     $args['orderby'] = 'registered';
                     $args['order'] = 'DESC';
                     break;
                 case 'active':
                     $args['ap_query'] = 'user_sort_by_active';
                     $args['orderby'] = 'meta_value date';
                     $args['order'] = 'ASC';
                     $args['meta_query'] = array(array('key' => '__last_active'));
                     break;
                 case 'best_answer':
                     $args['ap_query'] = 'user_sort_by_best_answer';
                     $args['orderby'] = 'meta_value date';
                     $args['order'] = 'ASC';
                     $args['meta_query'] = array(array('key' => '__best_answers'));
                     break;
                 case 'answer':
                     $args['ap_query'] = 'user_sort_by_answer';
                     $args['orderby'] = 'meta_value date';
                     $args['order'] = 'ASC';
                     $args['meta_query'] = array(array('key' => '__total_answers'));
                     break;
                 case 'followers':
                     $args['ap_query'] = 'user_sort_by_followers';
                     break;
                 case 'following':
                     $args['ap_query'] = 'user_sort_by_following';
                     break;
                 default:
                     $args['ap_query'] = 'user_sort_by_reputation';
                     $args['orderby'] = 'meta_value';
                     $args['order'] = 'DESC';
                     $args['meta_query'] = array('relation' => 'OR', array('key' => 'ap_reputation'), array('key' => 'ap_reputation', 'compare' => 'NOT EXISTS'));
                     break;
             }
         }
         $ap_user_query = new WP_User_Query($args);
         $this->users = $ap_user_query->results;
         // count the number of users found in the query
         $this->total_user_count = $ap_user_query->get_total();
         $this->total_pages = ceil($this->total_user_count / $this->per_page);
         $this->user_count = count($this->users);
     }
 }
Ejemplo n.º 12
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.º 13
0
/**
 * Surround mentions with anchor tag.
 * @param  string $content Post content.
 * @return string
 */
function ap_linkyfy_mentions($content)
{
    if (!ap_opt('base_before_user_perma')) {
        $base = home_url('/' . ap_get_user_page_slug() . '/');
    } else {
        $base = ap_get_link_to(ap_get_user_page_slug());
    }
    // Find mentions and wrap with anchor.
    return preg_replace('/(?:[\\s.]|^)@(\\w+)/', '<a class="ap-mention-link" href="' . $base . '$1">@$1</a> ', $content);
}
Ejemplo n.º 14
0
 public function custom_category_link($url, $term, $taxonomy)
 {
     if (ap_opt('enable_categories')) {
         /* change category link if permalink not enabled */
         if ('question_category' == $term->taxonomy && !get_option('permalink_structure')) {
             return add_query_arg(array('question_category' => false, 'page_id' => ap_opt('base_page'), 'qcat_id' => $term->term_id), $url);
         } elseif ('question_category' == $term->taxonomy && get_option('permalink_structure')) {
             return ap_get_link_to('category/' . $term->slug);
         }
     }
     return $url;
 }
Ejemplo n.º 15
0
/**
 * Check if checking for bad word is enabled.
 * @return boolean
 * @since  2.4.5
 */
function ap_check_for_bad_words()
{
    $bad_word_file = ap_get_theme_location('badwords.txt');
    // Return if badwords.txt file does not exists.
    if (!file_exists($bad_word_file)) {
        return false;
    }
    if (ap_opt('check_bad_words')) {
        return true;
    }
    return false;
}
Ejemplo n.º 16
0
 /**
  * Process voting button
  * @return void
  * @since 2.0.1.1
  */
 public function vote()
 {
     $post_id = (int) $_POST['post_id'];
     if (!wp_verify_nonce($_POST['__nonce'], 'vote_' . $post_id)) {
         ap_send_json(ap_ajax_responce('something_wrong'));
         return;
     }
     if (!is_user_logged_in()) {
         ap_send_json(ap_ajax_responce('please_login'));
         return;
     }
     $post = get_post($post_id);
     if ($post->post_author == get_current_user_id()) {
         ap_send_json(ap_ajax_responce('cannot_vote_own_post'));
         return;
     }
     $type = sanitize_text_field($_POST['type']);
     $type = $type == 'up' ? 'vote_up' : 'vote_down';
     if ($post->post_type == 'question' && ap_opt('disable_down_vote_on_question') && $type == 'vote_down') {
         ap_send_json(ap_ajax_responce('voting_down_disabled'));
         return;
     } elseif ($post->post_type == 'answer' && ap_opt('disable_down_vote_on_answer') && $type == 'vote_down') {
         ap_send_json(ap_ajax_responce('voting_down_disabled'));
         return;
     }
     $userid = get_current_user_id();
     $is_voted = ap_is_user_voted($post_id, 'vote', $userid);
     if (is_object($is_voted) && $is_voted->count > 0) {
         // if user already voted and click that again then reverse
         if ($is_voted->type == $type) {
             ap_remove_vote($type, $userid, $post_id, $post->post_author);
             $counts = ap_post_votes($post_id);
             //update post meta
             update_post_meta($post_id, ANSPRESS_VOTE_META, $counts['net_vote']);
             do_action('ap_undo_vote', $post_id, $counts);
             $action = 'undo';
             $count = $counts['net_vote'];
             do_action('ap_undo_' . $type, $post_id, $counts);
             ap_send_json(ap_ajax_responce(array('action' => $action, 'type' => $type, 'count' => $count, 'message' => 'undo_vote')));
         } else {
             ap_send_json(ap_ajax_responce('undo_vote_your_vote'));
         }
     } else {
         ap_add_vote($userid, $type, $post_id, $post->post_author);
         $counts = ap_post_votes($post_id);
         //update post meta
         update_post_meta($post_id, ANSPRESS_VOTE_META, $counts['net_vote']);
         do_action('ap_' . $type, $post_id, $counts);
         $action = 'voted';
         $count = $counts['net_vote'];
         ap_send_json(ap_ajax_responce(array('action' => $action, 'type' => $type, 'count' => $count, 'message' => 'voted')));
     }
 }
Ejemplo n.º 17
0
    public function ap_ask_form_bottom()
    {
        if (!is_super_admin() && (ap_opt('captcha_ask') || ap_opt('captcha_answer'))) {
            ?>
			<div class="form-group">
				<div id="recaptcha"><?php 
            ap_recaptch_html();
            ?>
</div>
			</div>
		<?php 
        }
    }
Ejemplo n.º 18
0
/**
 * Generate answer form
 * @param  integer $question_id  Question iD.
 * @param  boolean $editing      true if post is being edited.
 * @return void
 */
function ap_answer_form($question_id, $editing = false)
{
    if (!ap_user_can_answer($question_id) && !$editing) {
        return;
    }
    global $editing_post;
    $is_private = isset($_POST['is_private']) ? (bool) $_POST['is_private'] : false;
    if ($editing) {
        $is_private = $editing_post->post_status == 'private_post' ? true : false;
    }
    $args = array('name' => 'answer_form', 'is_ajaxified' => true, 'submit_button' => $editing ? __('Update answer', 'anspress-question-answer') : __('Post answer', 'anspress-question-answer'), 'nonce_name' => 'nonce_answer_' . $question_id, 'fields' => array(array('name' => 'description', 'type' => 'editor', 'value' => $editing ? apply_filters('the_content', $editing_post->post_content) : wp_kses_post(@$_POST['description']), 'settings' => apply_filters('ap_answer_form_editor_settings', array('textarea_rows' => 8, 'tinymce' => ap_opt('answer_text_editor') ? false : true, 'quicktags' => ap_opt('answer_text_editor') ? true : false, 'media_buttons' => false)), 'placeholder' => __('Your answer..', 'anspress-question-answer')), array('name' => 'form_question_id', 'type' => 'hidden', 'value' => $editing ? $editing_post->post_parent : $question_id, 'order' => 20)));
    if (!is_user_logged_in() && ap_opt('allow_anonymous')) {
        $args['fields'][] = array('name' => 'name', 'label' => __('Name', 'anspress-question-answer'), 'type' => 'text', 'placeholder' => __('Enter your name to display', 'anspress-question-answer'), 'value' => sanitize_text_field(@$_POST['name']), 'order' => 12);
    }
    // If private posts is allowed then show the checkbox.
    if (ap_opt('allow_private_posts')) {
        $args['fields'][] = array('name' => 'is_private', 'type' => 'checkbox', 'desc' => __('Only visible to admin and moderator.', 'anspress-question-answer'), 'value' => $is_private, 'order' => 12, 'show_desc_tip' => false);
    }
    if (ap_show_captcha_to_user()) {
        // Show recpatcha if key exists and enabled.
        if (ap_opt('recaptcha_site_key') == '') {
            $reCaptcha_html = '<div class="ap-notice red">' . __('reCaptach keys missing, please add keys', 'anspress-question-answer') . '</div>';
        } else {
            $reCaptcha_html = '<div class="g-recaptcha" id="recaptcha" data-sitekey="' . ap_opt('recaptcha_site_key') . '"></div>';
            $reCaptcha_html .= '<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl=' . get_locale() . '&onload=onloadCallback&render=explicit" async defer></script>';
            $reCaptcha_html .= '<script type="text/javascript">';
            $reCaptcha_html .= 'var onloadCallback = function() {';
            $reCaptcha_html .= 'widgetId1 = grecaptcha.render("recaptcha", {';
            $reCaptcha_html .= '"sitekey" : "' . ap_opt('recaptcha_site_key') . '"';
            $reCaptcha_html .= '});';
            $reCaptcha_html .= '};</script>';
        }
        $args['fields'][] = array('name' => 'captcha', 'type' => 'custom', 'order' => 100, 'html' => $reCaptcha_html);
    }
    $args['fields'][] = array('name' => 'ap_upload', 'type' => 'custom', 'html' => ap_post_upload_form(), 'order' => 11);
    /**
     * FILTER: ap_ask_form_fields
     * Filter for modifying $args
     * @var array
     * @since  2.0
     */
    $args = apply_filters('ap_answer_form_fields', $args, $editing);
    if ($editing) {
        $args['fields'][] = array('name' => 'edit_post_id', 'type' => 'hidden', 'value' => $editing_post->ID, 'order' => 20);
    }
    anspress()->form = new AnsPress_Form($args);
    echo anspress()->form->get_form();
    // Post image upload form.
    echo ap_post_upload_hidden_form();
}
Ejemplo n.º 19
0
 public function widget($args, $instance)
 {
     $title = apply_filters('widget_title', $instance['title']);
     $avatar = $instance['avatar'];
     $order = $instance['order'];
     $show_selected = $instance['show_selected'];
     $show_activity = $instance['show_activity'];
     $show_answers = $instance['show_answers'];
     $show_vote = $instance['show_vote'];
     $show_views = $instance['show_views'];
     $show_category = $instance['show_category'];
     $show_tags = $instance['show_tags'];
     $label = $instance['label'];
     echo $args['before_widget'];
     if (!empty($title)) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     if (empty($label)) {
         $label = '';
     }
     $question_args = array('ap_query' => 'main_questions', 'post_type' => 'question', 'post_status' => 'publish', 'showposts' => ap_opt('question_per_page'));
     if ($order == 'active') {
         $question_args['ap_query'] = 'main_questions_active';
         $question_args['orderby'] = 'meta_value';
         $question_args['meta_key'] = ANSPRESS_UPDATED_META;
         $question_args['meta_query'] = array('relation' => 'OR', array('key' => ANSPRESS_UPDATED_META, 'compare' => 'NOT EXISTS'));
     } elseif ($order == 'voted') {
         $question_args['orderby'] = 'meta_value_num';
         $question_args['meta_key'] = ANSPRESS_VOTE_META;
     } elseif ($order == 'answers') {
         $question_args['orderby'] = 'meta_value_num';
         $question_args['meta_key'] = ANSPRESS_ANS_META;
     } elseif ($order == 'unanswered') {
         $question_args['orderby'] = 'meta_value';
         $question_args['meta_key'] = ANSPRESS_ANS_META;
         $question_args['meta_value'] = '0';
     } elseif ($order == 'oldest') {
         $question_args['orderby'] = 'date';
         $question_args['order'] = 'ASC';
     }
     if ($label != '') {
         $question_args['tax_query'] = array(array('taxonomy' => 'question_label', 'field' => 'slug', 'terms' => $label));
     }
     $question = new WP_Query($question_args);
     include ap_get_theme_location('questions-widget.php');
     echo $args['after_widget'];
     wp_reset_postdata();
 }
Ejemplo n.º 20
0
/**
 * Generate ask form
 * @param  boolean $editing True if post is being edited.
 * @return void
 */
function ap_ask_form($editing = false)
{
    global $editing_post;
    $is_private = false;
    if ($editing) {
        $is_private = $editing_post->post_status == 'private_post' ? true : false;
    }
    // Ask form arguments.
    $args = array('name' => 'ask_form', 'is_ajaxified' => true, 'multipart' => true, 'submit_button' => $editing ? __('Update question', 'ap') : __('Post question', 'ap'), 'fields' => array(array('name' => 'title', 'label' => __('Title', 'ap'), 'type' => 'text', 'placeholder' => __('Question in one sentence', 'ap'), 'desc' => __('Write a meaningful title for the question.', 'ap'), 'value' => $editing ? $editing_post->post_title : sanitize_text_field(@$_POST['title']), 'order' => 5, 'attr' => 'data-action="suggest_similar_questions"', 'autocomplete' => false), array('name' => 'title', 'type' => 'custom', 'order' => 5, 'html' => '<div id="similar_suggestions"></div>'), array('name' => 'description', 'label' => __('Description', 'ap'), 'type' => 'editor', 'desc' => __('Write description for the question.', 'ap'), 'value' => $editing ? apply_filters('the_content', $editing_post->post_content) : @$_POST['description'], 'settings' => apply_filters('ap_ask_form_editor_settings', array('textarea_rows' => 8, 'tinymce' => ap_opt('question_text_editor') ? false : true, 'quicktags' => ap_opt('question_text_editor') ? true : false, 'media_buttons' => false))), array('name' => 'ap_upload', 'type' => 'custom', 'html' => ap_post_upload_form(), 'order' => 10), array('name' => 'parent_id', 'type' => 'hidden', 'value' => $editing ? $editing_post->post_parent : get_query_var('parent'), 'order' => 20)));
    // Add name fields if anonymous is allowed.
    if (!is_user_logged_in() && ap_opt('allow_anonymous')) {
        $args['fields'][] = array('name' => 'name', 'label' => __('Name', 'ap'), 'type' => 'text', 'placeholder' => __('Enter your name to display', 'ap'), 'value' => sanitize_text_field(@$_POST['name']), 'order' => 12);
    }
    // Add private field checkbox if enabled.
    if (ap_opt('allow_private_posts')) {
        $args['fields'][] = array('name' => 'is_private', 'type' => 'checkbox', 'desc' => __('Only visible to admin and moderator.', 'ap'), 'value' => $is_private, 'order' => 12, 'show_desc_tip' => false);
    }
    if (ap_show_captcha_to_user()) {
        // Show recpatcha if key exists and enabled.
        if (ap_opt('recaptcha_site_key') == '') {
            $reCaptcha_html = '<div class="ap-notice red">' . __('reCaptach keys missing, please add keys', 'ap') . '</div>';
        } else {
            $reCaptcha_html = '<div class="g-recaptcha" id="recaptcha" data-sitekey="' . ap_opt('recaptcha_site_key') . '"></div>';
            $reCaptcha_html .= '<script type="text/javascript" src="https://www.google.com/recaptcha/api.js?hl=' . get_locale() . '&onload=onloadCallback&render=explicit" async defer></script>';
            $reCaptcha_html .= '<script type="text/javascript">';
            $reCaptcha_html .= 'var onloadCallback = function() {';
            $reCaptcha_html .= 'widgetId1 = grecaptcha.render("recaptcha", {';
            $reCaptcha_html .= '"sitekey" : "' . ap_opt('recaptcha_site_key') . '"';
            $reCaptcha_html .= '});';
            $reCaptcha_html .= '};</script>';
        }
        $args['fields'][] = array('name' => 'captcha', 'type' => 'custom', 'order' => 100, 'html' => $reCaptcha_html);
    }
    /**
     * FILTER: ap_ask_form_fields
     * Filter for modifying $args
     * @var array
     * @since  2.0
     */
    $args = apply_filters('ap_ask_form_fields', $args, $editing);
    if ($editing) {
        $args['fields'][] = array('name' => 'edit_post_id', 'type' => 'hidden', 'value' => $editing_post->ID, 'order' => 20);
    }
    $form = new AnsPress_Form($args);
    echo $form->get_form();
    echo ap_post_upload_hidden_form();
}
Ejemplo n.º 21
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);
}
Ejemplo n.º 22
0
 /**
  * Control the output of [anspress] shortcode
  *
  * @param  array  $atts  {
  *     Attributes of the shortcode.
  *
  *     $categories slug of question_category
  *     $tags slug of question_tag
  *     $tax_relation taxonomy relation, see here http://codex.wordpress.org/Taxonomies
  *     $tags_operator operator for question_tag taxnomomy
  *     $categories_operator operator for question_category taxnomomy
  *  }
  * @param  string $content
  * @return string
  * @since 2.0.0-beta
  */
 public function anspress_sc($atts, $content = '')
 {
     global $questions, $wp;
     if (isset($atts['categories'])) {
         $categories = explode(',', str_replace(', ', ',', $atts['categories']));
         // append $atts in global $wp so that we can use it later
         $wp->set_query_var('ap_sc_atts_categories', $categories);
     }
     if (isset($atts['tags'])) {
         $tags = explode(',', str_replace(', ', ',', $atts['tags']));
         $wp->set_query_var('ap_sc_atts_tags', $tags);
     }
     if (isset($atts['tax_relation'])) {
         $tax_relation = $atts['tax_relation'];
         $wp->set_query_var('ap_sc_atts_tax_relation', $tax_relation);
     }
     if (isset($atts['tags_operator'])) {
         $tags_operator = $atts['tags_operator'];
         $wp->set_query_var('ap_sc_atts_tags_operator', $tags_operator);
     }
     if (isset($atts['categories_operator'])) {
         $categories_operator = $atts['categories_operator'];
         $wp->set_query_var('ap_sc_atts_categories_operator', $categories_operator);
     }
     // Load specefic AnsPress page.
     if (isset($atts['page'])) {
         set_query_var('ap_page', $atts['page']);
         $_GET['ap_page'] = $atts['page'];
     }
     ob_start();
     echo '<div id="anspress">';
     /**
      * ACTION: ap_before
      * Action is fired before loading AnsPress body.
      */
     do_action('ap_before');
     // Include theme file.
     ap_page();
     if (!ap_opt('author_credits')) {
         echo '<div class="ap-cradit">' . __('Question and answer is powered by <a href="http://anspress.io" traget="_blank">AnsPress</a>', 'anspress-question-answer') . '</div>';
     }
     echo '</div>';
     wp_reset_postdata();
     return ob_get_clean();
 }
Ejemplo n.º 23
0
 public function add_option_groups()
 {
     $settings = ap_opt();
     // Register general settings
     ap_register_option_group('general', __('General', 'ap'), array(array('name' => 'anspress_opt[base_page]', 'label' => __('Base page', 'ap'), 'desc' => __('Select page for displaying anspress.', 'ap'), 'type' => 'page_select', 'value' => @$settings['base_page'], 'show_desc_tip' => false), array('name' => 'anspress_opt[question_help_page]', 'label' => __('Question Help page', 'ap'), 'desc' => __('Direction for asking a question.', 'ap'), 'type' => 'page_select', 'value' => @$settings['question_help_page'], 'show_desc_tip' => false), array('name' => 'anspress_opt[answer_help_page]', 'label' => __('Answer Help page', 'ap'), 'desc' => __('Direction for answring a question.', 'ap'), 'type' => 'page_select', 'value' => @$settings['answer_help_page'], 'show_desc_tip' => false), array('name' => 'anspress_opt[author_credits]', 'label' => __('Hide author credits', 'ap'), 'desc' => __('Show your love by showing link to AnsPress project site.', 'ap'), 'type' => 'checkbox', 'value' => @$settings['author_credits'], 'order' => '1', 'show_desc_tip' => false), array('name' => 'anspress_opt[allow_private_posts]', 'label' => __('Allow private posts', 'ap'), 'desc' => __('Allow users to create private question and answer.', 'ap'), 'type' => 'checkbox', 'value' => @$settings['allow_private_posts'], 'show_desc_tip' => false), array('name' => 'anspress_opt[db_cleanup]', 'label' => __('Clean DB', 'ap'), 'desc' => __('check this to remove all anspress data including posts on deactivating plugin.', 'ap'), 'type' => 'checkbox', 'value' => @$settings['db_cleanup'], 'show_desc_tip' => false), array('name' => 'anspress_opt[question_permalink_follow]', 'label' => __('Base page slug before question permalink', 'ap'), 'desc' => __('i.e. ' . home_url('/BASE_PAGE/question/QUESTION_TITLE'), 'ap'), 'type' => 'checkbox', 'value' => @$settings['question_permalink_follow'], 'show_desc_tip' => false), array('name' => 'anspress_opt[base_before_user_perma]', 'label' => __('Base page slug before user page permalink', 'ap'), 'desc' => __('i.e. ' . home_url('/BASE_PAGE/user/USER_NAME'), 'ap'), 'type' => 'checkbox', 'value' => @$settings['base_before_user_perma'], 'show_desc_tip' => false), array('name' => 'anspress_opt[disable_hover_card]', 'label' => __('Disable hover card', 'ap'), 'desc' => __('Dont show user hover card on mouseover.', 'ap'), 'type' => 'checkbox', 'value' => @$settings['disable_hover_card'], 'show_desc_tip' => false)));
     //Register layout settings
     ap_register_option_group('layout', __('Layout', 'ap'), array(array('name' => '__sep', 'type' => 'custom', 'html' => '<span class="ap-form-separator">' . __('Avatar') . '</span>'), array('name' => 'anspress_opt[avatar_size_list]', 'label' => __('List avatar size', 'ap'), 'desc' => __('User avatar size for questions list.', 'ap'), 'type' => 'number', 'value' => $settings['avatar_size_list'], 'show_desc_tip' => false), array('name' => 'anspress_opt[avatar_size_qquestion]', 'label' => __('Question avatar size', 'ap'), 'desc' => __('User avatar size for question.', 'ap'), 'type' => 'number', 'value' => $settings['avatar_size_qquestion'], 'show_desc_tip' => false), array('name' => 'anspress_opt[avatar_size_qanswer]', 'label' => __('Answer avatar size', 'ap'), 'desc' => __('User avatar size for answer.', 'ap'), 'type' => 'number', 'value' => $settings['avatar_size_qanswer'], 'show_desc_tip' => false), array('name' => 'anspress_opt[avatar_size_qanswer]', 'label' => __('Answer avatar size', 'ap'), 'desc' => __('User avatar size for answer.', 'ap'), 'type' => 'number', 'value' => $settings['avatar_size_qanswer'], 'show_desc_tip' => false), array('name' => 'anspress_opt[avatar_size_qcomment]', 'label' => __('Comment avatar size', 'ap'), 'desc' => __('User avatar size for comments.', 'ap'), 'type' => 'number', 'value' => $settings['avatar_size_qcomment'], 'show_desc_tip' => false), array('name' => '__sep', 'type' => 'custom', 'html' => '<span class="ap-form-separator">' . __('Items to show per page') . '</span>'), array('name' => 'anspress_opt[question_per_page]', 'label' => __('Questions per page', 'ap'), 'desc' => __('Questions to show per page.', 'ap'), 'type' => 'number', 'value' => $settings['question_per_page'], 'show_desc_tip' => false), array('name' => 'anspress_opt[answers_per_page]', 'label' => __('Answers per page', 'ap'), 'desc' => __('Answers to show per page.', 'ap'), 'type' => 'number', 'value' => $settings['answers_per_page'], 'show_desc_tip' => false), array('name' => 'anspress_opt[users_per_page]', 'label' => __('Users per page', 'ap'), 'desc' => __('Users to show per page.', 'ap'), 'type' => 'number', 'value' => $settings['users_per_page']), array('name' => '__sep', 'type' => 'custom', 'html' => '<span class="ap-form-separator">' . __('Sorting') . '</span>'), array('name' => 'anspress_opt[answers_sort]', 'label' => __('Default answer sort', 'ap'), 'desc' => __('Sort answers by default.', 'ap'), 'type' => 'select', 'options' => array('voted' => __('Voted', 'ap'), 'active' => __('Active', 'ap'), 'newest' => __('Newest', 'ap'), 'oldest' => __('Oldest', 'ap')), 'value' => $settings['answers_sort'], 'show_desc_tip' => false), array('name' => '__sep', 'type' => 'custom', 'html' => '<span class="ap-form-separator">' . __('Toggle') . '</span>'), array('name' => 'anspress_opt[show_comments_by_default]', 'label' => __('Show comments', 'ap'), 'desc' => __('Show comments by default.', 'ap'), 'type' => 'checkbox', 'value' => $settings['show_comments_by_default'], 'show_desc_tip' => false), array('name' => 'anspress_opt[show_question_sidebar]', 'label' => __('Show question sidebar', 'ap'), 'desc' => __('Subbscribe and and stats widget will shown in question page.', 'ap'), 'type' => 'checkbox', 'value' => $settings['show_question_sidebar'], 'show_desc_tip' => false)));
     //Register pages settings
     ap_register_option_group('pages', __('Pages', 'ap'), array(array('name' => '__sep', 'type' => 'custom', 'html' => '<span class="ap-form-separator">' . __('Page slug') . '</span>'), array('name' => 'anspress_opt[ask_page_slug]', 'label' => __('Ask page slug', 'ap'), 'desc' => __('Enter slug for ask page.', 'ap'), 'type' => 'text', 'value' => @$settings['ask_page_slug'], 'show_desc_tip' => false), array('name' => 'anspress_opt[question_page_slug]', 'label' => __('Question page slug', 'ap'), 'desc' => __('Enter slug for question page.', 'ap'), 'type' => 'text', 'value' => @$settings['question_page_slug'], 'show_desc_tip' => false), array('name' => 'anspress_opt[users_page_slug]', 'label' => __('Users page slug', 'ap'), 'desc' => __('Enter slug for users page.', 'ap'), 'type' => 'text', 'value' => @$settings['users_page_slug'], 'show_desc_tip' => false), array('name' => 'anspress_opt[user_page_slug]', 'label' => __('User page slug', 'ap'), 'desc' => __('Enter slug for user page, make sure no page or post exists with same slug.', 'ap'), 'type' => 'text', 'value' => @$settings['user_page_slug'], 'show_desc_tip' => false), array('name' => '__sep', 'type' => 'custom', 'html' => '<span class="ap-form-separator">' . __('Page titles') . '</span>'), array('name' => 'anspress_opt[show_title_in_question]', 'label' => __('Show question title', 'ap'), 'desc' => __('Show question title in single question page.', 'ap'), 'type' => 'checkbox', 'value' => $settings['show_title_in_question'], 'show_desc_tip' => false), array('name' => 'anspress_opt[base_page_title]', 'label' => __('Base page title', 'ap'), 'desc' => __('Main questions list page title', 'ap'), 'type' => 'text', 'value' => $settings['base_page_title'], 'show_desc_tip' => false), array('name' => 'anspress_opt[ask_page_title]', 'label' => __('Ask page title', 'ap'), 'desc' => __('Title of the ask page', 'ap'), 'type' => 'text', 'value' => $settings['ask_page_title'], 'show_desc_tip' => false), array('name' => 'anspress_opt[users_page_title]', 'label' => __('Users page title', 'ap'), 'desc' => __('Title of the users page', 'ap'), 'type' => 'text', 'value' => $settings['users_page_title'], 'show_desc_tip' => false)));
     // Register question settings
     ap_register_option_group('question', __('Question', 'ap'), array(array('name' => 'anspress_opt[minimum_qtitle_length]', 'label' => __('Minimum title length', 'ap'), 'desc' => __('Set minimum letters for a question title.', 'ap'), 'type' => 'number', 'value' => $settings['minimum_qtitle_length'], 'show_desc_tip' => false), array('name' => 'anspress_opt[minimum_question_length]', 'label' => __('Minimum question content', 'ap'), 'desc' => __('Set minimum letters for a question contents.', 'ap'), 'type' => 'number', 'value' => $settings['minimum_question_length'], 'show_desc_tip' => false), array('name' => 'anspress_opt[question_text_editor]', 'label' => __('Use text editor ?', 'ap'), 'desc' => __('Text editor as default.', 'ap'), 'type' => 'checkbox', 'value' => $settings['question_text_editor'], 'show_desc_tip' => false), array('name' => 'anspress_opt[disable_comments_on_question]', 'label' => __('Disable comments', 'ap'), 'desc' => __('Disable comments on questions.', 'ap'), 'type' => 'checkbox', 'value' => $settings['disable_comments_on_question'], 'show_desc_tip' => false), array('name' => 'anspress_opt[disable_voting_on_question]', 'label' => __('Disable voting', 'ap'), 'desc' => __('Disable voting on questions.', 'ap'), 'type' => 'checkbox', 'value' => $settings['disable_voting_on_question'], 'show_desc_tip' => false), array('name' => 'anspress_opt[disable_down_vote_on_question]', 'label' => __('Disable down voting', 'ap'), 'desc' => __('Disable down voting on questions.', 'ap'), 'type' => 'checkbox', 'value' => $settings['disable_down_vote_on_question'], 'show_desc_tip' => false), array('name' => 'anspress_opt[close_selected]', 'label' => __('Close question after selecting answer', 'ap'), 'desc' => __('If enabled this will prevent user to submit answer on solved question.', 'ap'), 'type' => 'checkbox', 'value' => $settings['close_selected'], 'show_desc_tip' => false)));
     // Register answer settings
     ap_register_option_group('answer', __('Answer', 'ap'), array(array('name' => 'anspress_opt[multiple_answers]', 'label' => __('Multiple Answers', 'ap'), 'desc' => __('Allow an user to submit multiple answers on a single question.', 'ap'), 'type' => 'checkbox', 'value' => $settings['multiple_answers'], 'show_desc_tip' => false), array('name' => 'anspress_opt[minimum_ans_length]', 'label' => __('Minimum question content', 'ap'), 'desc' => __('Set minimum letters for a answer contents.', 'ap'), 'type' => 'number', 'value' => $settings['minimum_ans_length'], 'show_desc_tip' => false), array('name' => 'anspress_opt[answer_text_editor]', 'label' => __('Use text editor ?', 'ap'), 'desc' => __('Text editor as default.', 'ap'), 'type' => 'checkbox', 'value' => $settings['answer_text_editor'], 'show_desc_tip' => false), array('name' => 'anspress_opt[disable_comments_on_answer]', 'label' => __('Disable comments', 'ap'), 'desc' => __('Disable comments on answer.', 'ap'), 'type' => 'checkbox', 'value' => $settings['disable_comments_on_answer'], 'show_desc_tip' => false), array('name' => 'anspress_opt[disable_voting_on_answer]', 'label' => __('Disable voting', 'ap'), 'desc' => __('Disable voting on answers.', 'ap'), 'type' => 'checkbox', 'value' => $settings['disable_voting_on_answer'], 'show_desc_tip' => false), array('name' => 'anspress_opt[disable_down_vote_on_answer]', 'label' => __('Disable down voting', 'ap'), 'desc' => __('Disable down voting on answers.', 'ap'), 'type' => 'checkbox', 'value' => $settings['disable_down_vote_on_answer'], 'show_desc_tip' => false), array('name' => 'anspress_opt[disable_answer_nav]', 'label' => __('Disable navigation', 'ap'), 'desc' => __('Disable answer navigation.', 'ap'), 'type' => 'checkbox', 'value' => $settings['disable_answer_nav'], 'show_desc_tip' => false)));
     // register user settings
     ap_register_option_group('users', __('Users', 'ap'), array(array('name' => 'anspress_opt[enable_users_directory]', 'label' => __('Show users directory', 'ap'), 'desc' => __('When enabled public can see directory of users.', 'ap'), 'type' => 'checkbox', 'value' => $settings['enable_users_directory'], 'show_desc_tip' => false), array('name' => '__sep', 'type' => 'custom', 'html' => '<span class="ap-form-separator">' . __('Features', 'ap') . '</span>'), array('name' => 'anspress_opt[disable_reputation]', 'label' => __('Disable reputation', 'ap'), 'desc' => __('Disable reputation for user', 'ap'), 'type' => 'checkbox', 'value' => $settings['disable_reputation'], 'show_desc_tip' => false), array('name' => 'anspress_opt[users_page_avatar_size]', 'label' => __('Users page avatar size', 'ap'), 'desc' => __('Set user avatar size for users page item.', 'ap'), 'type' => 'number', 'value' => $settings['users_page_avatar_size'], 'show_desc_tip' => false), array('name' => 'anspress_opt[cover_width]', 'label' => __('Cover width', 'ap'), 'desc' => __('Set width of user cover photo.', 'ap'), 'type' => 'number', 'value' => @$settings['cover_width'], 'show_desc_tip' => false), array('name' => 'anspress_opt[cover_height]', 'label' => __('Cover height', 'ap'), 'desc' => __('Set height of user cover photo.', 'ap'), 'type' => 'number', 'value' => @$settings['cover_height'], 'show_desc_tip' => false), array('name' => 'anspress_opt[cover_width_small]', 'label' => __('Cover thumb width', 'ap'), 'desc' => __('Set width of user cover photo thumbnail.', 'ap'), 'type' => 'number', 'value' => @$settings['cover_width_small'], 'show_desc_tip' => false), array('name' => 'anspress_opt[cover_height_small]', 'label' => __('Small cover height', 'ap'), 'desc' => __('Set height of user cover photo thumbnail.', 'ap'), 'type' => 'number', 'value' => @$settings['cover_height_small'], 'show_desc_tip' => false), array('name' => 'anspress_opt[default_rank]', 'label' => __('Default rank', 'ap'), 'desc' => __('Assign a default rank for newly registered user.', 'ap'), 'type' => 'select', 'options' => get_terms('rank', array('hide_empty' => false, 'orderby' => 'id')), 'value' => @$settings['default_rank'], 'show_desc_tip' => false)));
     // register permission settings
     ap_register_option_group('permission', __('Permission', 'ap'), array(array('name' => 'anspress_opt[multiple_answers]', 'label' => __('Multiple answers', 'ap'), 'desc' => __('Allow user to submit multiple answer per question.', 'ap'), 'type' => 'checkbox', 'value' => $settings['multiple_answers'], 'show_desc_tip' => false), array('name' => 'anspress_opt[disallow_op_to_answer]', 'label' => __('Asker can answer', 'ap'), 'desc' => __('Allow asker to answer his own question.', 'ap'), 'type' => 'checkbox', 'value' => $settings['disallow_op_to_answer'], 'show_desc_tip' => false), array('name' => 'anspress_opt[allow_anonymous]', 'label' => __('Allow anonymous', 'ap'), 'desc' => __('Non-loggedin user can post questions and answers.', 'ap'), 'type' => 'checkbox', 'value' => $settings['allow_anonymous'], 'show_desc_tip' => false), array('name' => 'anspress_opt[only_admin_can_answer]', 'label' => __('Only admin can answer', 'ap'), 'desc' => __('Only allow admin to answer question.', 'ap'), 'type' => 'checkbox', 'value' => $settings['only_admin_can_answer'], 'show_desc_tip' => false), array('name' => 'anspress_opt[logged_in_can_see_ans]', 'label' => __('Only logged in can see answers', 'ap'), 'desc' => __('non-loggedin user cannot see answers.', 'ap'), 'type' => 'checkbox', 'value' => $settings['logged_in_can_see_ans'], 'show_desc_tip' => false), array('name' => 'anspress_opt[logged_in_can_see_comment]', 'label' => __('Only logged in can see comment', 'ap'), 'desc' => __('non-loggedin user cannot see comments.', 'ap'), 'type' => 'checkbox', 'value' => $settings['logged_in_can_see_comment'], 'show_desc_tip' => false), array('name' => 'anspress_opt[disable_delete_after]', 'label' => __('Lock delete action', 'ap'), 'desc' => __('Lock comment or post after a period so that user cannot delete it. Set the time in epoch i.e. 86400 = 1 day.', 'ap'), 'type' => 'number', 'value' => $settings['disable_delete_after'], 'show_desc_tip' => false), array('name' => '__sep', 'type' => 'custom', 'html' => '<span class="ap-form-separator">' . __('Upload', 'ap') . '</span>'), array('name' => 'anspress_opt[allow_upload_image]', 'label' => __('Allow image upload', 'ap'), 'desc' => __('Allow logged-in users to upload image.', 'ap'), 'type' => 'checkbox', 'value' => $settings['allow_upload_image'], 'show_desc_tip' => false), array('name' => 'anspress_opt[image_per_post]', 'label' => __('Max images per post', 'ap'), 'desc' => __('Set how many images user can upload for each post.', 'ap'), 'type' => 'number', 'value' => $settings['image_per_post'], 'show_desc_tip' => false), array('name' => 'anspress_opt[max_upload_size]', 'label' => __('Max upload size', 'ap'), 'desc' => __('Set maximum upload size.', 'ap'), 'type' => 'text', 'value' => $settings['max_upload_size'], 'show_desc_tip' => false)));
     // register moderate settings
     ap_register_option_group('moderate', __('Moderate', 'ap'), array(array('name' => 'anspress_opt[new_question_status]', 'label' => __('Status of new question', 'ap'), 'desc' => __('Set post status of new question.', 'ap'), 'type' => 'select', 'value' => $settings['new_question_status'], 'options' => array('publish' => __('Publish'), 'moderate' => __('Moderate', 'profile')), 'show_desc_tip' => false), array('name' => 'anspress_opt[edit_question_status]', 'label' => __('Status of edited question', 'ap'), 'desc' => __('Set post status of edited question.', 'ap'), 'type' => 'select', 'value' => $settings['edit_question_status'], 'options' => array('publish' => __('Publish'), 'moderate' => __('Moderate', 'profile')), 'show_desc_tip' => false), array('name' => 'anspress_opt[new_answer_status]', 'label' => __('Status of new answer', 'ap'), 'desc' => __('Set post status of new answer.', 'ap'), 'type' => 'select', 'value' => $settings['new_answer_status'], 'options' => array('publish' => __('Publish'), 'moderate' => __('Moderate', 'profile')), 'show_desc_tip' => false), array('name' => 'anspress_opt[edit_answer_status]', 'label' => __('Status of edited answer', 'ap'), 'desc' => __('Set post status of edited answer.', 'ap'), 'type' => 'select', 'value' => $settings['edit_answer_status'], 'options' => array('publish' => __('Publish'), 'moderate' => __('Moderate', 'profile')), 'show_desc_tip' => false), array('name' => '__sep', 'type' => 'custom', 'html' => '<span class="ap-form-separator">' . __('reCaptacha') . '</span>'), array('name' => 'anspress_opt[enable_recaptcha]', 'label' => __('Enable reCaptcha', 'ap'), 'desc' => __('Use this for preventing spam posts.', 'ap'), 'type' => 'checkbox', 'value' => $settings['enable_recaptcha'], 'show_desc_tip' => false), array('name' => 'anspress_opt[recaptcha_site_key]', 'label' => __('Recaptcha site key', 'ap'), 'desc' => __('Enter your site key, if you dont have it get it from here https://www.google.com/recaptcha/admin', 'ap'), 'type' => 'text', 'value' => $settings['recaptcha_site_key'], 'show_desc_tip' => false), array('name' => 'anspress_opt[recaptcha_secret_key]', 'label' => __('Recaptcha secret key', 'ap'), 'desc' => __('Enter your secret key', 'ap'), 'type' => 'text', 'value' => $settings['recaptcha_secret_key'], 'show_desc_tip' => false)));
 }
Ejemplo n.º 24
0
 public function widget($args, $instance)
 {
     $title = apply_filters('widget_title', $instance['title']);
     $avatar = $instance['avatar'];
     $show_selected = $instance['show_selected'];
     $show_activity = $instance['show_activity'];
     $show_answers = $instance['show_answers'];
     $show_vote = $instance['show_vote'];
     $show_views = $instance['show_views'];
     $show_category = $instance['show_category'];
     $show_tags = $instance['show_tags'];
     echo $args['before_widget'];
     if (!empty($title)) {
         echo $args['before_title'] . $title . $args['after_title'];
     }
     $question_args = array('ap_query' => 'related', 'ap_title' => get_the_title(get_question_id()), 'post_type' => 'question', 'post__not_in' => array(get_question_id()), 'post_status' => 'publish', 'showposts' => ap_opt('question_per_page'));
     $question = new WP_Query($question_args);
     include ap_get_theme_location('questions-widget.php');
     echo $args['after_widget'];
     wp_reset_postdata();
 }
Ejemplo n.º 25
0
 public function default_user_meta($user_id)
 {
     if (ap_opt('default_rank') !== false) {
         wp_set_object_terms($user_id, array(ap_opt('default_rank')), 'rank', false);
     }
 }
Ejemplo n.º 26
0
 public function ap_delete_post()
 {
     $args = explode('-', sanitize_text_field($_REQUEST['args']));
     $action = 'delete_post_' . $args[0];
     if (!ap_user_can_delete($args[0])) {
         $result = array('action' => false, 'message' => __('No Permission', 'ap'));
     } elseif (wp_verify_nonce($args[1], $action)) {
         $post = get_post($args[0]);
         wp_trash_post($args[0]);
         if ($post->post_type == 'question') {
             $result = array('action' => 'question', 'redirect_to' => get_permalink(ap_opt('base_page')), 'message' => __('Question deleted successfully.', 'ap'));
         } else {
             $current_ans = ap_count_ans($post->post_parent);
             $count_label = sprintf(_n('1 Answer', '%d Answers', $current_ans, 'ap'), $current_ans);
             $remove = !$current_ans ? true : false;
             $result = array('action' => 'answer', 'div' => '#answer_' . $args[0], 'count' => $current_ans, 'count_label' => $count_label, 'remove' => $remove, 'message' => __('Answer deleted successfully.', 'ap'));
         }
     }
     die(json_encode($result));
 }
Ejemplo n.º 27
0
 /**
  * Upload a photo to server. Before uploading it check for valid image type
  * @uses 	wp_handle_upload
  * @param  	string $file_name      Name of file input field.
  * @return 	array|false
  */
 public function upload_photo($file_name)
 {
     if ($_FILES[$file_name]['size'] > ap_opt('max_upload_size')) {
         $this->upload_error = sprintf(__('File cannot be uploaded, size is bigger then %d Byte', 'anspress-question-answer'), ap_opt('max_upload_size'));
         return false;
     }
     require_once ABSPATH . 'wp-admin/includes/image.php';
     require_once ABSPATH . 'wp-admin/includes/file.php';
     require_once ABSPATH . 'wp-admin/includes/media.php';
     if (!empty($_FILES[$file_name]['name']) && is_uploaded_file($_FILES[$file_name]['tmp_name'])) {
         $mimes = array('jpg|jpeg|jpe' => 'image/jpeg', 'gif' => 'image/gif', 'png' => 'image/png');
         $photo = wp_handle_upload($_FILES[$file_name], array('mimes' => $mimes, 'test_form' => false, 'unique_filename_callback' => array($this, 'unique_filename_callback')));
         if (empty($photo['file']) || isset($photo['error'])) {
             // Handle failures.
             $this->upload_error = __('There was an error while uploading avatar, please check your image', 'anspress-question-answer');
             return false;
         }
         return $photo;
     }
 }
Ejemplo n.º 28
0
 /**
  * Ajax cllback for updating old taxonomy question_tags to question_tag
  */
 public function ap_taxo_rename()
 {
     if (current_user_can('manage_options')) {
         global $wpdb;
         $wpdb->query('UPDATE ' . $wpdb->prefix . "term_taxonomy SET taxonomy = 'question_tag' WHERE  taxonomy = 'question_tags'");
         ap_opt('tags_taxo_renamed', 'true');
     }
     die;
 }
Ejemplo n.º 29
0
/**
 * ACTION: ap_before_question_title
 * @since 	2.0
 */
do_action('ap_before_question_content');
?>
				<div class="ap-avatar">
					<a href="<?php 
ap_question_the_author_link();
?>
"<?php 
ap_hover_card_attributes(ap_question_get_author_id());
?>
>
						<?php 
ap_question_the_author_avatar(ap_opt('avatar_size_qquestion'));
?>
					</a>
				</div>
				<div class="ap-q-cells clearfix">
					<div class="ap-q-metas">
						<?php 
ap_user_display_meta(true, false, true);
?>
						<span><?php 
ap_question_the_time();
?>
</span>
					</div>

					<!-- Start ap-content-inner -->
/**
 * 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();
}