public function __construct()
 {
     global $wpdb;
     add_action('admin_menu', array($this, 'add_menu'));
     $this->table = $wpdb->prefix . $this->table;
     add_action('wp_ajax_dwqa_upgrade_database', array($this, 'create_table'));
     if ($this->db_version != get_option('dwqa_db_version')) {
         update_option('dwqa_db_version', $this->db_version);
     }
     // Replace old data by new table
     if (dwqa_table_exists($this->table)) {
         remove_filter('dwqa-prepare-archive-posts', 'dwqa_prepare_archive_posts');
         remove_filter('dwqa-after-archive-posts', 'dwqa-after-archive-posts');
         add_action('dwqa-prepare-archive-posts', array($this, 'prepare_archive_posts'));
         add_action('dwqa-after-archive-posts', array($this, 'after_archive_posts'));
         //Filter update table
         add_action('save_post', array($this, 'update_question'));
         add_action('before_delete_post', array($this, 'delete_question'));
         add_action('before_delete_post', array($this, 'delete_answer'));
         add_action('dwqa_add_answer', array($this, 'answers_change'));
         add_action('dwqa_update_answer', array($this, 'answers_change'));
         add_action('update_postmeta', array($this, 'update_question_metadata'), 10, 4);
     }
 }
예제 #2
0
<?php

global $dwqa_options, $wpdb;
$taxonomy = get_query_var('taxonomy');
$term_name = get_query_var($taxonomy);
if (function_exists('dwqa_table_exists') && dwqa_table_exists($wpdb->prefix . 'dwqa_question_index')) {
    // Page navigation
    $total = wp_cache_get('dwqa_total_questions_new_table', 'dwqa');
    if (!$total) {
        $sticky_questions = get_option('dwqa_sticky_questions', array());
        $where = ' WHERE 1=1';
        if (!empty($sticky_questions)) {
            $where .= " AND ID NOT IN ( " . implode(',', $sticky_questions) . " )";
        }
        $query = "SELECT count(*) FROM " . ($wpdb->prefix . 'dwqa_question_index') . " " . $where;
        $total = $wpdb->get_var($query);
        wp_cache_add('dwqa_total_questions_new_table', $total, 'dwqa');
    }
} else {
    if ($taxonomy && $term_name) {
        $term = get_term_by('slug', $term_name, $taxonomy);
        $total = $term->count;
    } else {
        $post_count = wp_count_posts('dwqa-question');
        $total = $post_count->publish;
        if (current_user_can('manage_options')) {
            $total += $post_count->private;
        }
    }
}
$number_questions = $total;
예제 #3
0
 public function __construct()
 {
     global $wpdb;
     //Init
     $prefix = wp_cache_get('dwqa-database-prefix');
     if (false == $prefix) {
         $prefix = $wpdb->prefix;
         wp_cache_set('dwqa-database-prefix', $prefix);
     }
     $this->tb_posts = $prefix . 'posts';
     $this->tb_postmeta = $prefix . 'postmeta';
     $table = $prefix . 'dwqa_question_index';
     if (dwqa_table_exists($table)) {
         $filter = array($this, 'filter_question_width_index_table');
     } else {
         $filter = array($this, 'filter_question');
     }
     add_action('wp_ajax_dwqa-filter-question', $filter);
     add_action('wp_ajax_nopriv_dwqa-filter-question', $filter);
     add_action('wp_ajax_dwqa-auto-suggest-search-result', array($this, 'auto_suggest_for_seach'));
     add_action('wp_ajax_nopriv_dwqa-auto-suggest-search-result', array($this, 'auto_suggest_for_seach'));
 }