diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 00000000..a25a4208
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1,14 @@
+.gitattributes export-ignore
+.gitignore export-ignore
+.editorconfig export-ignore
+codesniffer.ruleset.xml export-ignore
+phpunit.xml export-ignore
+.travis.yml export-ignore
+/tools export-ignore
+screenshot-1.png export-ignore
+screenshot-2.png export-ignore
+screenshot-3.png export-ignore
+screenshot-4.png export-ignore
+screenshot-5.png export-ignore
+thumbnail.png export-ignore
+banner.png export-ignore
\ No newline at end of file
diff --git a/.gitignore b/.gitignore
index e17768d5..5ab7c43d 100755
--- a/.gitignore
+++ b/.gitignore
@@ -28,6 +28,7 @@ tests/clover.xml
# Grunt
node_modules
+tools/node_modules
# Vendor
vendor
diff --git a/assets/css/dwqa-akismet-button-report-spam.css b/assets/css/dwqa-akismet-button-report-spam.css
new file mode 100644
index 00000000..d672b360
--- /dev/null
+++ b/assets/css/dwqa-akismet-button-report-spam.css
@@ -0,0 +1,3 @@
+.dwqa_report_spam{
+ cursor:pointer;
+}
\ No newline at end of file
diff --git a/assets/img/dw-widgets.png b/assets/img/dw-widgets.png
new file mode 100644
index 00000000..ed2a3639
Binary files /dev/null and b/assets/img/dw-widgets.png differ
diff --git a/assets/js/admin-settings-page.js b/assets/js/admin-settings-page.js
index d566dabe..4626e9de 100644
--- a/assets/js/admin-settings-page.js
+++ b/assets/js/admin-settings-page.js
@@ -1,90 +1,28 @@
jQuery(document).ready(function($) {
- $('.dwqa-reset-email-template').on('click', function(event) {
- event.preventDefault();
- var template = $(this).data('template');
- var editor = $(this).closest('.tab-pane').find('.wp-editor-area').attr('id');
- tinyMCE.execCommand('mceFocus', false, editor);
- $.ajax({
- url: dwqa.template_folder + template,
- type: 'GET',
- dataType: 'html'
- }).done(function(html) {
- if ($('#' + editor).closest('.wp-editor-wrap').hasClass('tmce-active')) {
- tinyMCE.get(editor).setContent(html);
- } else {
- $('#' + editor).val(html);
- }
- });
-
- });
-
- $('.reset-permission').on('click', function(event) {
- event.preventDefault();
- if (confirm(dwqa.reset_permission_confirm_text)) {
- var nonce = $('#reset-permission-nonce').val();
- var type = $(this).data('type');
-
- $.ajax({
- url: dwqa.ajax_url,
- type: 'POST',
- dataType: 'json',
- data: {
- action: 'dwqa-reset-permission-default',
- nonce: nonce,
- type: type
- }
- }).done(function() {
- window.location.href = window.location.href;
- });
-
- }
- });
-
- var refererField = $('[name="_wp_http_referer"]');
- var updateHashInUrl = function() {
- var url = refererField.val();
- if (location.hash.length > 0) {
-
- if (url.match(/#(\S*)/)) {
- refererField.val(url.replace(/#(\S*)/g, location.hash));
- } else {
- refererField.val(url + location.hash);
+ function hide_item(element,element2) {
+ if ($(element).is(':checked')) {
+ $(element2).attr('disabled','disabled');
+ if ($(element2).is(':checked')) {
+ $(element2).removeAttr('checked');
}
+ } else {
+ $(element2).removeAttr('disabled');
}
}
- $('.dwqa-notification-settings .nav-tabs li').click(function(event) {
- event.preventDefault();
- var tab = $(this).find('a:first').attr('href');
- window.location.hash = tab;
- $('.dwqa-notification-settings .nav-tabs li').removeClass('active');
- $('.dwqa-notification-settings .tab-content .tab-pane').removeClass('active');
- $(tab).addClass('active');
- $(this).addClass('active');
- updateHashInUrl();
- $('.dwqa-mail-templates .progress-bar .progress-bar-inner').stop().css('width', 0).animate({
- width: '70%'
- },
- 600,
- function() {
- $(this).css('width', '100%').fadeOut(200, function() {
- $(this).css({
- width: '0%'
- }).show();
- });;
- }
- );
+ hide_item('#dwqa_options_dwqa_show_all_answers','#dwqa_setting_answers_per_page');
+ hide_item('#dwqa_options_dwqa_disable_question_status','#dwqa_options_enable_show_status_icon');
+
+ $('#dwqa_options_dwqa_show_all_answers').on('change',function() {
+ hide_item(this,'#dwqa_setting_answers_per_page');
});
- $(document).ready(function($) {
- updateHashInUrl();
- if ($('.dwqa-notification-settings').length > 0 && location.hash.length > 0) {
- var tab = window.location.hash;
- $('.dwqa-notification-settings .nav-tabs li').removeClass('active');
- $('.dwqa-notification-settings .tab-content .tab-pane').removeClass('active');
- $('.dwqa-notification-settings .nav-tabs li a[href="' + tab + '"]').parent().addClass('active');
- $('.dwqa-notification-settings .tab-content ' + tab + '.tab-pane').addClass('active');
- }
+ $('#dwqa_options_dwqa_disable_question_status').on('change',function(){
+ hide_item(this,'#dwqa_options_enable_show_status_icon');
+ });
+
+ $('#dwqa-message').on('click', function(e){
+ document.cookie = "qa-pro-notice=off";
});
});
\ No newline at end of file
diff --git a/assets/js/dwqa-akismet-button-report-spam.js b/assets/js/dwqa-akismet-button-report-spam.js
new file mode 100644
index 00000000..1e99d40c
--- /dev/null
+++ b/assets/js/dwqa-akismet-button-report-spam.js
@@ -0,0 +1,30 @@
+jQuery(document).ready(function($){
+ $('.dwqa_report_spam').on('click', function(){
+ if(confirm("Are you sure?")){
+ var post_id = $(this).data("post");
+ var nonce = $(this).data("nonce");
+ var dwqa_this = $(this);
+ // console.log('abc');
+ $.ajax({
+ url: dwqa.ajax_url,
+ type: 'POST',
+ dataType: 'json',
+ data: {
+ action: 'dwqa_report_spam_to_admin',
+ nonce: nonce,
+ post_id: post_id,
+ },
+ success: function( data ) {
+ console.log( data );
+ if (data.success) {
+ alert(data.data.message);
+ dwqa_this.remove();
+ }else{
+ alert(data.data.message);
+ }
+ }
+ });
+ }
+ });
+
+});
\ No newline at end of file
diff --git a/dw-question-answer.php b/dw-question-answer.php
index ed1819d6..ab25e0e4 100644
--- a/dw-question-answer.php
+++ b/dw-question-answer.php
@@ -4,40 +4,29 @@
* Description: A WordPress plugin was make by DesignWall.com to build an Question Answer system for support, asking and comunitcate with your customer
* Author: DesignWall
* Author URI: http://www.designwall.com
- * Version: 1.4.0
- * Text Domain: dwqa
- * @since 1.3.6
+ * Version: 1.5.7
+ * Text Domain: dw-question-answer
+ * @since 1.4.0
*/
-// DWQA plugin dir path
-if ( ! defined( 'DWQA_DIR' ) ) {
- define( 'DWQA_DIR', plugin_dir_path( __FILE__ ) );
-}
-// DWQA plugin dir URI
-if ( ! defined( 'DWQA_URI' ) ) {
- define( 'DWQA_URI', plugin_dir_url( __FILE__ ) );
-}
-
-// These lines just is used to back to older version of this plugin
-// require_once DWQA_DIR . 'dw-question-answer-bak.php';
-// return;
-
-// Add autoload class
-require_once DWQA_DIR . 'inc/autoload.php';
-require_once DWQA_DIR . 'inc/helper/functions.php';
-//require_once DWQA_DIR . 'upgrades/upgrades.php';
-require_once DWQA_DIR . 'inc/deprecated.php';
+if ( !class_exists( 'DW_Question_Answer' ) ) :
class DW_Question_Answer {
- private $last_update = 010220161055; //last update time of the plugin
+ private $last_update = 180720161357; //last update time of the plugin
public function __construct() {
+ $this->define_constants();
+ $this->includes();
+
$this->dir = DWQA_DIR;
$this->uri = DWQA_URI;
- $this->version = '1.4.0';
+ $this->temp_dir = DWQA_TEMP_DIR;
+ $this->temp_uri = DWQA_TEMP_URL;
+ $this->stylesheet_dir = DWQA_STYLESHEET_DIR;
+ $this->stylesheet_uri = DWQA_STYLESHEET_URL;
+
+ $this->version = '1.5.7';
- // Add recaptcha library from google, 99 to sure that the library was not include if any other plugins use same library
- add_action( 'plugins_loaded', array( $this, 'include_recaptcha_library' ), 99 );
// load posttype
$this->question = new DWQA_Posts_Question();
$this->answer = new DWQA_Posts_Answer();
@@ -52,6 +41,10 @@ public function __construct() {
$this->editor = new DWQA_Editor();
$this->user = new DWQA_User();
$this->notifications = new DWQA_Notifications();
+
+ $this->akismet = new DWQA_Akismet();
+ $this->autoclosure = new DWQA_Autoclosure();
+
$this->filter = new DWQA_Filter();
$this->session = new DWQA_Session();
@@ -65,13 +58,74 @@ public function __construct() {
// All init action of plugin will be included in
add_action( 'init', array( $this, 'init' ) );
+ add_action( 'widgets_init', array( $this, 'widgets_init' ) );
+ add_filter( 'plugin_action_links', array( $this, 'go_pro' ), 10, 2 );
+ add_filter( 'plugin_row_meta', array( $this, 'plugin_rows_meta' ), 10, 2 );
register_activation_hook( __FILE__, array( $this, 'activate_hook' ) );
register_deactivation_hook( __FILE__, array( $this, 'deactivate_hook' ) );
+
+ add_action( 'bp_include', array($this,'dwqa_setup_buddypress'), 10 );
+ }
+
+ public function dwqa_setup_buddypress(){
+ // Include the BuddyPress Component
+ require( DWQA_DIR . 'inc/extend/buddypress/loader.php' );
+
+ // Instantiate BuddyPress for bbPress
+ $this->DWQA_Buddypress = new DWQA_QA_Component();
+ }
+
+ public static function instance() {
+ static $instance = null;
+
+ if ( is_null( $instance ) ) {
+ $instance = new self();
+ }
+
+ return $instance;
+ }
+
+ public function includes() {
+ require_once DWQA_DIR . 'inc/autoload.php';
+ require_once DWQA_DIR . 'inc/helper/functions.php';
+ //require_once DWQA_DIR . 'upgrades/upgrades.php';
+ require_once DWQA_DIR . 'inc/deprecated.php';
+ require_once DWQA_DIR . 'inc/helper/plugin-compatibility.php';
+ require_once DWQA_DIR . 'inc/helper/theme-compatibility.php';
+
+ require_once DWQA_DIR . 'inc/widgets/Closed_Question.php';
+ require_once DWQA_DIR . 'inc/widgets/Latest_Question.php';
+ require_once DWQA_DIR . 'inc/widgets/Popular_Question.php';
+ require_once DWQA_DIR . 'inc/widgets/Related_Question.php';
}
- public function include_recaptcha_library() {
- if ( ! defined( 'RECAPTCHA_VERIFY_SERVER' ) ) {
- require_once DWQA_DIR . 'lib/recaptcha-php/recaptchalib.php';
+ public function define_constants() {
+ $defines = array(
+ 'DWQA_DIR' => plugin_dir_path( __FILE__ ),
+ 'DWQA_URI' => plugin_dir_url( __FILE__ ),
+ 'DWQA_TEMP_DIR' => trailingslashit( get_template_directory() ),
+ 'DWQA_TEMP_URL' => trailingslashit( get_template_directory_uri() ),
+ 'DWQA_STYLESHEET_DIR' => trailingslashit( get_stylesheet_directory() ),
+ 'DWQA_STYLESHEET_URL' => trailingslashit( get_stylesheet_directory_uri() ),
+ );
+
+ foreach( $defines as $k => $v ) {
+ if ( !defined( $k ) ) {
+ define( $k, $v );
+ }
+ }
+ }
+
+ public function widgets_init() {
+ $widgets = array(
+ 'DWQA_Widgets_Closed_Question',
+ 'DWQA_Widgets_Latest_Question',
+ 'DWQA_Widgets_Popular_Question',
+ 'DWQA_Widgets_Related_Question'
+ );
+
+ foreach( $widgets as $widget ) {
+ register_widget( $widget );
}
}
@@ -80,7 +134,16 @@ public function init() {
$active_template = $this->template->get_template();
//Load translate text domain
- load_plugin_textdomain( 'dwqa', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
+ // load_plugin_textdomain( 'dw-question-answer', false, plugin_basename( dirname( __FILE__ ) ) . '/languages' );
+ // load_plugin_textdomain( 'dw-question-answer');
+
+ $locale = get_locale();
+ $mo = 'dw-question-answer-' . $locale . '.mo';
+
+ load_textdomain( 'dw-question-answer', WP_LANG_DIR . '/dw-question-answer/' . $mo );
+ load_textdomain( 'dw-question-answer', plugin_dir_path( __FILE__ ) . 'languages/' . $mo );
+ load_plugin_textdomain( 'dw-question-answer' );
+
//Scripts var
$question_category_rewrite = $dwqa_general_settings['question-category-rewrite'];
@@ -88,59 +151,23 @@ public function init() {
$question_tag_rewrite = $dwqa_general_settings['question-tag-rewrite'];
$question_tag_rewrite = $question_tag_rewrite ? $question_tag_rewrite : 'question-tag';
$dwqa_sript_vars = array(
- 'is_logged_in' => is_user_logged_in(),
- 'plugin_dir_url' => DWQA_URI,
- 'code_icon' => DWQA_URI . 'inc/templates/' . $active_template . '/assets/img/icon-code.png',
'ajax_url' => admin_url( 'admin-ajax.php' ),
- 'text_next' => __( 'Next','dwqa' ),
- 'text_prev' => __( 'Prev','dwqa' ),
- 'questions_archive_link' => get_post_type_archive_link( 'dwqa-question' ),
- 'error_missing_question_content' => __( 'Please enter your question', 'dwqa' ),
- 'error_question_length' => __( 'Your question must be at least 2 characters in length', 'dwqa' ),
- 'error_valid_email' => __( 'Enter a valid email address', 'dwqa' ),
- 'error_valid_user' => __( 'Enter a question title', 'dwqa' ),
- 'error_valid_name' => __( 'Please add your name', 'dwqa' ),
- 'error_missing_answer_content' => __( 'Please enter your answer', 'dwqa' ),
- 'error_missing_comment_content' => __( 'Please enter your comment content', 'dwqa' ),
- 'error_not_enought_length' => __( 'Comment must have more than 2 characters', 'dwqa' ),
- 'search_not_found_message' => __( 'Not found! Try another keyword.', 'dwqa' ),
- 'search_enter_get_more' => __( 'Or press ENTER to get more questions', 'dwqa' ),
- 'comment_edit_submit_button' => __( 'Update', 'dwqa' ),
- 'comment_edit_link' => __( 'Edit', 'dwqa' ),
- 'comment_edit_cancel_link' => __( 'Cancel', 'dwqa' ),
- 'comment_delete_confirm' => __( 'Do you want to delete this comment?', 'dwqa' ),
- 'answer_delete_confirm' => __( 'Do you want to delete this answer?', 'dwqa' ),
- 'answer_update_privacy_confirm' => __( 'Do you want to update this answer?', 'dwqa' ),
- 'report_answer_confirm' => __( 'Do you want to report this answer?', 'dwqa' ),
- 'flag' => array(
- 'label' => __( 'Report', 'dwqa' ),
- 'label_revert' => __( 'Undo', 'dwqa' ),
- 'text' => __( 'This answer will be marked as spam and hidden. Do you want to flag it?', 'dwqa' ),
- 'revert' => __( 'This answer was flagged as spam. Do you want to show it', 'dwqa' ),
- 'flag_alert' => __( 'This answer was flagged as spam', 'dwqa' ),
- 'flagged_hide' => __( 'hide', 'dwqa' ),
- 'flagged_show' => __( 'show', 'dwqa' ),
- ),
- 'follow_tooltip' => __( 'Follow This Question', 'dwqa' ),
- 'unfollow_tooltip' => __( 'Unfollow This Question', 'dwqa' ),
- 'stick_tooltip' => __( 'Pin this question to top', 'dwqa' ),
- 'unstick_tooltip' => __( 'Unpin this question from top', 'dwqa' ),
- 'question_category_rewrite' => $question_category_rewrite,//$question_category_rewrite,
- 'question_tag_rewrite' => $question_tag_rewrite, //$question_tag_rewrite,
- 'delete_question_confirm' => __( 'Do you want to delete this question?', 'dwqa' )
);
+
+ $this->flush_rules();
}
// Update rewrite url when active plugin
public function activate_hook() {
$this->permission->prepare_permission_caps();
+ flush_rewrite_rules();
//Auto create question page
$options = get_option( 'dwqa_options' );
- if ( ! isset( $options['pages']['archive-question'] ) || ( isset( $options['pages']['archive-question'] ) && ! get_page( $options['pages']['archive-question'] ) ) ) {
+ if ( ! isset( $options['pages']['archive-question'] ) || ( isset( $options['pages']['archive-question'] ) && ! get_post( $options['pages']['archive-question'] ) ) ) {
$args = array(
- 'post_title' => __( 'DWQA Questions', 'dwqa' ),
+ 'post_title' => __( 'DWQA Questions', 'dw-question-answer' ),
'post_type' => 'page',
'post_status' => 'publish',
'post_content' => '[dwqa-list-questions]',
@@ -154,10 +181,10 @@ public function activate_hook() {
}
}
- if ( ! isset( $options['pages']['submit-question'] ) || ( isset( $options['pages']['submit-question'] ) && ! get_page( $options['pages']['submit-question'] ) ) ) {
+ if ( ! isset( $options['pages']['submit-question'] ) || ( isset( $options['pages']['submit-question'] ) && ! get_post( $options['pages']['submit-question'] ) ) ) {
$args = array(
- 'post_title' => __( 'DWQA Ask Question', 'dwqa' ),
+ 'post_title' => __( 'DWQA Ask Question', 'dw-question-answer' ),
'post_type' => 'page',
'post_status' => 'publish',
'post_content' => '[dwqa-submit-question-form]',
@@ -194,7 +221,9 @@ public function activate_hook() {
update_option( 'dwqa_options', $options );
update_option( 'dwqa_plugin_activated', true );
// dwqa_posttype_init();
- flush_rewrite_rules();
+
+ //update option delay email
+ update_option('dwqa_enable_email_delay', true);
}
public function deactivate_hook() {
@@ -205,9 +234,44 @@ public function deactivate_hook() {
flush_rewrite_rules();
}
+ public function flush_rules() {
+ if ( get_option( 'dwqa_plugin_activated', false ) || get_option( 'dwqa_plugin_upgraded', false ) ) {
+ delete_option( 'dwqa_plugin_upgraded' );
+ flush_rewrite_rules();
+ }
+ }
+
public function get_last_update() {
return $this->last_update;
}
+ public function go_pro( $actions, $file ) {
+ $file_name = plugin_basename( __FILE__ );
+ if ( $file == $file_name ) {
+ $actions['dwqa_go_pro'] = 'Go Pro! ';
+ $action = $actions['dwqa_go_pro'];
+ unset( $actions['dwqa_go_pro'] );
+ array_unshift( $actions, $action );
+ }
+
+ return $actions;
+ }
+
+ public function plugin_rows_meta( $meta, $file ) {
+ $file_name = plugin_basename( __FILE__ );
+ if ( $file == $file_name ) {
+ $meta['extensions'] = 'Extensions ';
+ // $meta['facebook'] = 'Facebook ';
+ }
+
+ return $meta;
+ }
+}
+
+function dwqa() {
+ return DW_Question_Answer::instance();
}
-$GLOBALS['dwqa'] = new DW_Question_Answer();
+
+$GLOBALS['dwqa'] = dwqa();
+
+endif;
\ No newline at end of file
diff --git a/dwqa-dummy-data.xml b/dwqa-dummy-data.xml
new file mode 100644
index 00000000..6d0633f5
--- /dev/null
+++ b/dwqa-dummy-data.xml
@@ -0,0 +1,2935 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ DW Question & Answer
+ http://10.0.0.47/joom/dw-dummy-data
+ Just another WordPress site
+ Wed, 17 Feb 2016 09:27:54 +0000
+ en-US
+ 1.2
+ http://10.0.0.47/joom/dw-dummy-data
+ http://10.0.0.47/joom/dw-dummy-data
+
+ 1
+ 2
+ 3
+ 4
+ 5
+
+ 1
+
+
+
+
+
+
+
+ 3 nav_menu
+
+ https://wordpress.org/?v=4.4.2
+
+ -
+
Answer for What is the differences between DWQA and Forum?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-what-is-the-differences-between-dwqa-and-forum
+ Wed, 17 Feb 2016 03:19:20 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-what-is-the-differences-between-dwqa-and-forum
+
+
+
+ 11
+
+
+
+
+
+
+ 10
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for What is the differences between DWQA and Forum?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-what-is-the-differences-between-dwqa-and-forum-2
+ Wed, 17 Feb 2016 03:19:58 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-what-is-the-differences-between-dwqa-and-forum-2
+
+ Hi, Very cool question, my friend. It makes me a little bit confused :D Ohm, at first glance, we will think that they are both the same in function. Both forum and Q&A are a place where people have the ability to ask questions about the product/service/problem they are interested and wait for responses. Even if they look the same from the outside, they are very different on the inside.Forum. An online forum is a discussion area. A topic of discussion is posted and people can respond, discuss, give their own ideas or evoke further conversations…Of course, you can get several answers but some of which will be nothing and the question ended inconclusively.Q&A Although, the Q & A is similar to a “forum-style” of open, free for discussion like Quora or Stack Overflow but, on Q&A you will get specific answers that are 100% related to your question. It means that Q & A is very directed toward problem solving. In addition, users can pick the best answer, which will then float to the top making it more easier for other users to find out. Regarding the interaction and community, the Q & A isn’t as strong as forum. I hope this answer is useful and have a nice day.
+]]>
+
+ 12
+
+
+
+
+
+
+ 10
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for How to pin a sticky question to the top of the questions page?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-to-pin-a-sticky-question-to-the-top-of-the-questions-page
+ Wed, 17 Feb 2016 03:30:25 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-to-pin-a-sticky-question-to-the-top-of-the-questions-page
+
+
+
+ 14
+
+
+
+
+
+
+ 13
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 3
+
+
+
+
+
+
+
+
+
+ 0
+ 3
+
+
+ 6
+
+
+
+
+
+
+
+
+
+ 0
+ 1
+
+
+ -
+
Answer for How to pin a sticky question to the top of the questions page?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-to-pin-a-sticky-question-to-the-top-of-the-questions-page-2
+ Wed, 17 Feb 2016 03:33:04 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-to-pin-a-sticky-question-to-the-top-of-the-questions-page-2
+
+ It would be a good thing if DW Question & Answer adds the feature "pin a post" at the front-end for administrator.
+]]>
+
+ 15
+
+
+
+
+
+
+ 13
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 4
+
+
+
+
+
+
+
+
+
+ 0
+ 3
+
+
+ 7
+
+
+
+
+
+
+
+
+
+ 0
+ 2
+
+
+ 12
+
+
+
+
+
+
+
+
+
+ 0
+ 1
+
+
+ -
+
Answer for How to pin a sticky question to the top of the questions page?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-to-pin-a-sticky-question-to-the-top-of-the-questions-page-3
+ Wed, 17 Feb 2016 03:35:20 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-to-pin-a-sticky-question-to-the-top-of-the-questions-page-3
+
+
+
+ 16
+
+
+
+
+
+
+ 13
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for How to pin a sticky question to the top of the questions page?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-to-pin-a-sticky-question-to-the-top-of-the-questions-page-4
+ Wed, 17 Feb 2016 03:52:01 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-to-pin-a-sticky-question-to-the-top-of-the-questions-page-4
+
+ ]]>
+
+ 17
+
+
+
+
+
+
+ 13
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 8
+
+
+
+
+
+
+
+
+
+ 0
+ 4
+
+
+ 9
+
+
+
+
+
+
+
+
+
+ 0
+ 1
+
+
+ 10
+
+
+
+
+
+
+
+
+
+ 0
+ 4
+
+
+ -
+
Answer for How to pin a sticky question to the top of the questions page?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-to-pin-a-sticky-question-to-the-top-of-the-questions-page-5
+ Wed, 17 Feb 2016 04:21:50 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-to-pin-a-sticky-question-to-the-top-of-the-questions-page-5
+
+ DWQA will not allow 2 or more posts to be pinned at the same time ? I have a problem, please check with my account: Username: Shan Judd Password: 1234567890
+]]>
+
+ 19
+
+
+
+
+
+
+ 13
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 11
+
+
+
+
+
+
+
+
+
+ 0
+ 1
+
+
+ -
+
Answer for How do I require a password if I forgot it?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-do-i-require-a-password-if-i-forgot-it
+ Wed, 17 Feb 2016 04:37:58 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-do-i-require-a-password-if-i-forgot-it
+
+
+Click on My Account in the top right of the page.
+Click login
+Click the link “Forgot password?”
+Enter your email that you used to register before.
+]]>
+
+ 22
+
+
+
+
+
+
+ 20
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for How do I require a password if I forgot it?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-do-i-require-a-password-if-i-forgot-it-2
+ Wed, 17 Feb 2016 04:39:38 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-do-i-require-a-password-if-i-forgot-it-2
+
+
+
+ 23
+
+
+
+
+
+
+ 20
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for WordPress site seems convinced that it’s still at its old URL
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-wordpress-site-seems-convinced-that-its-still-at-its-old-url
+ Wed, 17 Feb 2016 04:42:43 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-wordpress-site-seems-convinced-that-its-still-at-its-old-url
+
+
+
+ 25
+
+
+
+
+
+
+ 24
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for WordPress site seems convinced that it’s still at its old URL
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-wordpress-site-seems-convinced-that-its-still-at-its-old-url-2
+ Wed, 17 Feb 2016 04:44:04 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-wordpress-site-seems-convinced-that-its-still-at-its-old-url-2
+
+
+
+ 26
+
+
+
+
+
+
+ 24
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 13
+
+
+
+
+
+
+
+
+
+ 0
+ 1
+
+
+ -
+
Answer for What is notifications in backend of DWQA?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-what-is-notifications-in-backend-of-dwqa
+ Wed, 17 Feb 2016 04:50:50 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-what-is-notifications-in-backend-of-dwqa
+
+
+
+ 29
+
+
+
+
+
+
+ 28
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for What is notifications in backend of DWQA?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-what-is-notifications-in-backend-of-dwqa-2
+ Wed, 17 Feb 2016 04:51:14 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-what-is-notifications-in-backend-of-dwqa-2
+
+
+
+ 30
+
+
+
+
+
+
+ 28
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for How do I edit my notification settings?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-do-i-edit-my-notification-settings
+ Wed, 17 Feb 2016 05:00:20 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-do-i-edit-my-notification-settings
+
+
+Email for new questions
+Email for new answers
+Email for new comments?
+
+ ]]>
+
+ 32
+
+
+
+
+
+
+ 31
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 14
+
+
+
+
+
+
+
+
+
+ 0
+ 2
+
+
+ -
+
Answer for Where do I edit my notification settings?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-where-do-i-edit-my-notification-settings
+ Wed, 17 Feb 2016 05:02:45 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-where-do-i-edit-my-notification-settings
+
+
+
+ 33
+
+
+
+
+
+
+ 31
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 15
+
+
+
+
+
+
+
+
+
+ 0
+ 2
+
+
+ -
+
Answer for Where do I edit my notification settings?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-where-do-i-edit-my-notification-settings-2
+ Wed, 17 Feb 2016 05:03:00 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-where-do-i-edit-my-notification-settings-2
+
+
+
+ 34
+
+
+
+
+
+
+ 31
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for I'm not receiving email notifications.
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-im-not-receiving-email-notifications
+ Wed, 17 Feb 2016 06:49:56 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-im-not-receiving-email-notifications
+
+
+Go to your backend >> Questions >> Settings >> Notifications.
+Choose if you want to receive all notifications, important notifications or only notifications about your account
+
+If you're still having issues with email notifications, try these troubleshooting tips:
+
+
+Make sure you setup the general settings.
+
+
+Check your spam or junk email filter to make sure that emails coming from the site used DWQA aren't being placed in this folder.
+
+
+If you're still not receiving emails, please contact your ISP (Internet Service Provider) to ensure that they aren't blocking email traffic.
+
+
+If the issue continues, please let us know here.
+
+ ]]>
+
+ 37
+
+
+
+
+
+
+ 36
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for When I search for someone, I can't find them.
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-when-i-search-for-someone-i-cant-find-them
+ Wed, 17 Feb 2016 06:57:22 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-when-i-search-for-someone-i-cant-find-them
+
+
+This plugin doesn’t support this feature :D
+Your search isn’t specific enough.
+
+Pls check a gain.]]>
+
+ 40
+
+
+
+
+
+
+ 38
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 17
+
+
+
+
+
+
+
+
+
+ 0
+ 4
+
+
+ 18
+
+
+
+
+
+
+
+
+
+ 0
+ 5
+
+
+ 19
+
+
+
+
+
+
+
+
+
+ 0
+ 4
+
+
+ -
+
Answer for When I search for someone, I can't find them.
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-when-i-search-for-someone-i-cant-find-them-2
+ Wed, 17 Feb 2016 07:01:58 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-when-i-search-for-someone-i-cant-find-them-2
+
+
+
+ 41
+
+
+
+
+
+
+ 38
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for How can I participate in a Q&A?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-can-i-participate-in-a-qa
+ Wed, 17 Feb 2016 07:06:38 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-can-i-participate-in-a-qa
+
+ To participate in a Q&A, write a question in the box in the Q&A and press the Submit button. Keep in mind that your question was asked before. So, search to have the results before dropping a question.
+]]>
+
+ 43
+
+
+
+
+
+
+ 42
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 20
+
+
+
+
+
+
+
+
+
+ 0
+ 1
+
+
+ -
+
What is the differences between DWQA and Forum?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=what-is-the-differences-between-dwqa-and-forum
+ Wed, 17 Feb 2016 03:14:05 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=what-is-the-differences-between-dwqa-and-forum
+
+
+
+ 10
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
How to pin a sticky question to the top of the questions page?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-to-pin-a-sticky-post-to-the-top-of-the-questions-page
+ Wed, 17 Feb 2016 03:25:28 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?post_type=dwqa-question&p=13
+
+
+
+ 13
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 2
+
+
+
+
+
+
+
+
+
+ 0
+ 3
+
+
+
+
+
+
+
+
+
+
+ 5
+
+
+
+
+
+
+
+
+
+ 0
+ 3
+
+
+ -
+
How do I require a password if I forgot it?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-do-i-require-a-password-if-i-forgot-it
+ Wed, 17 Feb 2016 04:34:55 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-do-i-require-a-password-if-i-forgot-it
+
+
+
+ 20
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
WordPress site seems convinced that it’s still at its old URL
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=wordpress-site-seems-convinced-that-its-still-at-its-old-url
+ Wed, 17 Feb 2016 04:41:40 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=wordpress-site-seems-convinced-that-its-still-at-its-old-url
+
+
+
+ 24
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
What is notifications in backend of DWQA?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=what-is-notifications-in-backend-of-dwqa
+ Wed, 17 Feb 2016 04:48:37 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=what-is-notifications-in-backend-of-dwqa
+
+
+
+ 28
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
Where do I edit my notification settings?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-do-i-edit-my-notification-settings
+ Wed, 17 Feb 2016 04:58:20 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-do-i-edit-my-notification-settings
+
+ I want to change some info in the notification email. How to edit?
+]]>
+
+ 31
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
How do I post and share with an external site such as Facebook, Twitter?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-do-i-post-and-share-with-an-external-site-such-as-facebook-twitter
+ Wed, 17 Feb 2016 05:05:36 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-do-i-post-and-share-with-an-external-site-such-as-facebook-twitter
+
+
+
+ 35
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 16
+
+
+
+
+
+
+
+
+
+ 0
+ 3
+
+
+ -
+
Answer for What are the guidelines for ratings and reviews?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-what-are-the-guidelines-for-ratings-and-reviews
+ Wed, 17 Feb 2016 07:12:58 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-what-are-the-guidelines-for-ratings-and-reviews
+
+
+
+ 45
+
+
+
+
+
+
+ 44
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for How do I upload photos or videos directly on DWQA?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-do-i-upload-photos-or-videos-directly-on-dwqa
+ Wed, 17 Feb 2016 07:27:41 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-do-i-upload-photos-or-videos-directly-on-dwqa
+
+
+
+ 47
+
+
+
+
+
+
+ 46
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 21
+
+
+
+
+
+
+
+
+
+ 0
+ 2
+
+
+ 22
+
+
+
+
+
+
+
+
+
+ 0
+ 1
+
+
+ -
+
Answer for Do DWQA moderate new questions?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-do-dwqa-moderate-new-questions
+ Wed, 17 Feb 2016 07:34:28 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-do-dwqa-moderate-new-questions
+
+
+
+ 49
+
+
+
+
+
+
+ 48
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for Who can post ratings and reviews?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-who-can-post-ratings-and-reviews
+ Wed, 17 Feb 2016 07:37:11 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-who-can-post-ratings-and-reviews
+
+
+
+ 51
+
+
+
+
+
+
+ 50
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 23
+
+
+
+
+
+
+
+
+
+ 0
+ 3
+
+
+ 24
+
+
+
+
+
+
+
+
+
+ 0
+ 5
+
+
+ -
+
Answer for Who can post ratings and reviews?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-who-can-post-ratings-and-reviews-2
+ Wed, 17 Feb 2016 07:42:29 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-who-can-post-ratings-and-reviews-2
+
+
+
+ 52
+
+
+
+
+
+
+ 50
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for Where I can see or edit ratings I've posted?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-where-i-can-see-or-edit-ratings-ive-posted
+ Wed, 17 Feb 2016 07:46:04 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-where-i-can-see-or-edit-ratings-ive-posted
+
+
+
+ 54
+
+
+
+
+
+
+ 53
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 25
+
+
+
+
+
+
+
+
+
+ 0
+ 4
+
+
+ -
+
Answer for Where I can see or edit ratings I've posted?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-where-i-can-see-or-edit-ratings-ive-posted-2
+ Wed, 17 Feb 2016 07:52:16 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-where-i-can-see-or-edit-ratings-ive-posted-2
+
+
+
+ 55
+
+
+
+
+
+
+ 53
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for Why can Admins no longer pin more than one post in the question page?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-why-can-admins-no-longer-pin-more-than-one-post-in-the-question-page
+ Wed, 17 Feb 2016 07:57:47 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-why-can-admins-no-longer-pin-more-than-one-post-in-the-question-page
+
+
+
+ 57
+
+
+
+
+
+
+ 56
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for How do I write a question in more than one language?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-do-i-write-a-question-in-more-than-one-language
+ Wed, 17 Feb 2016 08:08:18 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-do-i-write-a-question-in-more-than-one-language
+
+
+
+ 59
+
+
+
+
+
+
+ 58
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 30
+
+
+
+
+
+
+
+
+
+ 0
+ 1
+
+
+ 31
+
+
+
+
+
+
+
+
+
+ 0
+ 3
+
+
+ 32
+
+
+
+
+
+
+
+
+
+ 0
+ 1
+
+
+ 33
+
+
+
+
+
+
+
+
+
+ 0
+ 3
+
+
+ -
+
How to make Question list page shown automatically after question is posted ?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-to-make-question-list-page-shown-automatically-after-question-is-posted
+ Wed, 17 Feb 2016 08:17:27 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-to-make-question-list-page-shown-automatically-after-question-is-posted
+
+
+
+ 60
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
Answer for How to make Question list page shown automatically after question is posted ?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-to-make-question-list-page-shown-automatically-after-question-is-posted
+ Wed, 17 Feb 2016 08:19:02 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-to-make-question-list-page-shown-automatically-after-question-is-posted
+
+ wp-content/plugins/dw-question-answer/inc/Posts/Answer.php file. Find the line 408. Replace the following code:
+// wp_redirect( get_permalink( $question_id ) ); // wp_send_json_success( array( 'url' => get_permalink( $question_id ) ) ); // return true;
+With new code:
+wp_redirect ( 'https://your-site.com' ); wp_send_json_success ( array ( 'url' => get_permalink ( $question_id ) ) ); return true ;
+To redirect users to a different page when user submit a question, please open the Question.php file in the folder path wp-content -> plugins -> dw-question-answer -> inc -> Post -> Question.phpfile. Find the line code around line 439:
+exit( wp_safe_redirect( get_permalink( $new_question ) ) );`
+Then replace with the following code to redirect to home page:
+exit( wp_safe_redirect( home_url() ) );
+Notice: you can use similar to redirect user to any other page as you wish (in your case to the question listing page)
+Eg: like this is my url :http://mysite/discussion-forum/
+exit( wp_safe_redirect( home_url() .'discussion-forum/' ) );
+About the permalink of categories, have you tried to add the permalink in the Settings of Q&A]]>
+
+ 61
+
+
+
+
+
+
+ 60
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Answer for How can i delete more than one post at a time?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-can-i-delete-more-than-one-post-at-a-time
+ Wed, 17 Feb 2016 08:23:42 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-can-i-delete-more-than-one-post-at-a-time
+
+
+
+ 63
+
+
+
+
+
+
+ 62
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 35
+
+
+
+
+
+
+
+
+
+ 0
+ 3
+
+
+ -
+
Answer for How can i delete more than one post at a time?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-can-i-delete-more-than-one-post-at-a-time-2
+ Wed, 17 Feb 2016 08:25:27 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-answer=answer-for-how-can-i-delete-more-than-one-post-at-a-time-2
+
+
+
+ 64
+
+
+
+
+
+
+ 62
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+ -
+
Hello world!
+ http://10.0.0.47/joom/dw-dummy-data/?p=1
+ Wed, 17 Feb 2016 02:14:24 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?p=1
+
+
+
+ 1
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1
+
+
+ https://wordpress.org/
+
+
+
+
+
+
+ 0
+ 0
+
+
+ -
+
I'm not receiving email notifications.
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=im-not-receiving-email-notifications
+ Wed, 17 Feb 2016 06:45:27 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=im-not-receiving-email-notifications
+
+
+
+ 36
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
When I search for someone, I can't find them.
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=when-i-search-for-someone-i-cant-find-them
+ Wed, 17 Feb 2016 06:54:38 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=when-i-search-for-someone-i-cant-find-them
+
+
+
+ 38
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
How can I participate in a Q&A?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-can-i-participate-in-a-qa
+ Wed, 17 Feb 2016 07:04:52 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-can-i-participate-in-a-qa
+
+
+
+ 42
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
What are the guidelines for ratings and reviews?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=what-are-the-guidelines-for-ratings-and-reviews
+ Wed, 17 Feb 2016 07:11:26 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=what-are-the-guidelines-for-ratings-and-reviews
+
+
+
+ 44
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
How do I upload photos or videos directly on DWQA?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-do-i-upload-photos-or-videos-directly-on-dwqa
+ Wed, 17 Feb 2016 07:24:40 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-do-i-upload-photos-or-videos-directly-on-dwqa
+
+
+
+ 46
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
Do DWQA moderate new questions?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=do-dwqa-moderate-new-questions
+ Wed, 17 Feb 2016 07:32:35 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=do-dwqa-moderate-new-questions
+
+
+
+ 48
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
Who can post ratings and reviews?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=who-can-post-ratings-and-reviews
+ Wed, 17 Feb 2016 07:35:51 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=who-can-post-ratings-and-reviews
+
+
+
+ 50
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
Where I can see or edit ratings I've posted?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=where-i-can-see-or-edit-ratings-ive-posted
+ Wed, 17 Feb 2016 07:43:47 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=where-i-can-see-or-edit-ratings-ive-posted
+
+
+
+ 53
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
Why can Admins no longer pin more than one post in the question page?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=why-can-admins-no-longer-pin-more-than-one-post-in-the-question-page
+ Wed, 17 Feb 2016 07:54:29 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=why-can-admins-no-longer-pin-more-than-one-post-in-the-question-page
+
+
+
+ 56
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 26
+
+
+
+
+
+
+
+
+
+ 0
+ 4
+
+
+ 27
+
+
+
+
+
+
+
+
+
+ 0
+ 4
+
+
+ 28
+
+
+
+
+
+
+
+
+
+ 0
+ 2
+
+
+ 29
+
+
+
+
+
+
+
+
+
+ 0
+ 4
+
+
+ -
+
How do I write a question in more than one language?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-do-i-write-a-question-in-more-than-one-language
+ Wed, 17 Feb 2016 08:02:39 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-do-i-write-a-question-in-more-than-one-language
+
+
+
+ 58
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
How can I delete more than one post at a time?
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-can-i-delete-more-than-one-post-at-a-time
+ Wed, 17 Feb 2016 08:21:03 +0000
+
+ http://10.0.0.47/joom/dw-dummy-data/?dwqa-question=how-can-i-delete-more-than-one-post-at-a-time
+
+ I want delete more than one post at the same time at the front-end, how to do it?
+]]>
+
+ 62
+
+
+
+
+
+
+ 0
+ 0
+
+
+ 0
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 34
+
+
+
+
+
+
+
+
+
+ 0
+ 2
+
+
+
+
diff --git a/inc/Admin/Extensions.php b/inc/Admin/Extensions.php
index e91cd3e0..09876082 100644
--- a/inc/Admin/Extensions.php
+++ b/inc/Admin/Extensions.php
@@ -10,35 +10,41 @@ function register_extensions() {
global $dwqa;
$extension = array(
'dwqa-markdown' => array(
- 'name' => __( 'DWQA Markdown', 'dwqa' ),
+ 'name' => __( 'DWQA Markdown', 'dw-question-answer' ),
'url' => 'http://bit.ly/dwqa-markdown',
'img_url' => $dwqa->uri . 'assets/img/dw-markdown.png'
),
'dwqa-leaderboard' => array(
- 'name' => __( 'DWQA Leaderboard', 'dwqa' ),
+ 'name' => __( 'DWQA Leaderboard', 'dw-question-answer' ),
'url' => 'http://bit.ly/dwqa-leaderboard',
'img_url' => $dwqa->uri . 'assets/img/dw-leaderboard.png'
),
'dwqa-captcha' => array(
- 'name' => __( 'DWQA Captcha', 'dwqa' ),
+ 'name' => __( 'DWQA Captcha', 'dw-question-answer' ),
'url' => 'http://bit.ly/dwqa-captcha',
'img_url' => $dwqa->uri . 'assets/img/dw-captcha.png',
),
'dwqa-embed-question' => array(
- 'name' => __( 'DWQA Embed Question', 'dwqa' ),
+ 'name' => __( 'DWQA Embed Question', 'dw-question-answer' ),
'url' => 'http://bit.ly/dwqa-embed-questions',
'img_url' => $dwqa->uri . 'assets/img/dw-embedquestion.png'
),
+
+ 'dwqa-widgets' => array(
+ 'name' => __( 'DWQA Widgets', 'dw-question-answer' ),
+ 'url' => 'http://bit.ly/dwqa-widgets',
+ 'img_url' => $dwqa->uri . 'assets/img/dw-widgets.png'
+ ),
);
return $extension;
}
function register_extension_menu() {
- add_submenu_page( 'edit.php?post_type=dwqa-question', __( 'Extensions', 'dwqa' ), sprintf( '%s ', __( 'Extensions', 'dwqa' ) ), 'manage_options', 'dwqa-extensions', array( $this, 'extension_menu_layout' ) );
+ add_submenu_page( 'edit.php?post_type=dwqa-question', __( 'Extensions', 'dw-question-answer' ), sprintf( '%s ', __( 'Extensions', 'dw-question-answer' ) ), 'manage_options', 'dwqa-extensions', array( $this, 'extension_menu_layout' ) );
}
function extension_menu_layout() {
@@ -66,12 +72,149 @@ function extension_menu_layout() {
+
+
+
+
+
+
+ Features / Options
+ Premium Version
+ Free Version
+
+
+
+
+ Multi style
+
+
+
+
+ All Extension
+
+
+
+
+ Markdown Editor
+
+
+
+
+ Anti-spam by Google reCaptchaV2
+
+
+
+
+ Anti-spam by FunCaptcha
+
+
+
+
+ Anti-spam by Akismet
+
+
+
+
+ Manual approve answer
+
+
+
+
+ Manual approve question
+
+
+
+
+ Anonymous vote
+
+
+
+
+ Mention user
+
+
+
+
+ Permalink friendly SEO
+
+
+
+
+ Upload Files
+
+
+
+
+ Notification Bar
+
+
+
+
+ Ultimate Member Integration
+
+
+
+
+ UserPro Integration
+
+
+
+
+ Manager Anonymous info
+
+
+
+
+ Alway Show Admin answer First
+
+
+
+
+ Login/register Redirect Page
+
+
+
+
+ The ShortCode
+ 5
+ 2
+
+
+ The Widgets
+ 7
+ 4
+
+
+ Get DWQA
+
+ Get Pro Version
+
+
+
+
+
+
+
+
'dwqa-about' ), admin_url( 'index.php' ) ) ) );
+ wp_safe_redirect( esc_url( add_query_arg( array( 'page' => 'dwqa-changelog' ), admin_url( 'index.php' ) ) ) );
exit;
}
}
+ public function admin_notices() {
+ if ( !isset( $_COOKIE['qa-pro-notice'] ) ) {
+ echo '';
+ }
+ }
+
public function admin_menus() {
add_dashboard_page(
- __( 'Welcome to DW Question & Answer', 'dwqa' ),
- __( 'Welcome to DW Question & Answer', 'dwqa' ),
+ __( 'Welcome to DW Question & Answer', 'dw-question-answer' ),
+ __( 'Welcome to DW Question & Answer', 'dw-question-answer' ),
'manage_options',
'dwqa-about',
array( $this, 'about_layout' )
);
add_dashboard_page(
- __( 'DW Question & Answer Changelog', 'dwqa' ),
- __( 'DW Question & Answer Changelog', 'dwqa' ),
+ __( 'DW Question & Answer Changelog', 'dw-question-answer' ),
+ __( 'DW Question & Answer Changelog', 'dw-question-answer' ),
'manage_options',
'dwqa-changelog',
array( $this, 'changelog_layout' )
);
add_dashboard_page(
- __( 'DW Question & Answer Credits', 'dwqa' ),
- __( 'DW Question & Answer Credits', 'dwqa' ),
+ __( 'DW Question & Answer Credits', 'dw-question-answer' ),
+ __( 'DW Question & Answer Credits', 'dw-question-answer' ),
'manage_options',
'dwqa-credits',
array( $this, 'credits_layout' )
@@ -51,8 +57,8 @@ public function admin_init() {
public function page_head() {
global $dwqa;
?>
- version ) ?>
- Q&A section.', 'dwqa' ); ?>
+ version ) ?>
+ Q&A section.', 'dw-question-answer' ); ?>
-
+
-
+
- login ) ?>
+ login ) ?>
@@ -209,7 +215,7 @@ public function parse_readme() {
$file = file_exists( DWQA_DIR . 'readme.txt' ) ? DWQA_DIR . 'readme.txt' : false;
if ( !$file ) {
- $readme = '' . __( 'No valid changelog was found.', 'dwqa' ) . '
';
+ $readme = '' . __( 'No valid changelog was found.', 'dw-question-answer' ) . '
';
} else {
$readme = file_get_contents( $file );
$readme = nl2br( esc_html( $readme ) );
@@ -236,4 +242,4 @@ public function get_contributors() {
}
}
-?>
\ No newline at end of file
+?>
diff --git a/inc/Ajax.php b/inc/Ajax.php
index 0b2434bc..b41c0baa 100644
--- a/inc/Ajax.php
+++ b/inc/Ajax.php
@@ -7,8 +7,10 @@ public function __construct() {
// Ajax remove Answer
add_action( 'wp_ajax_dwqa_delete_answer', array( $this, 'delete_answer' ) );
+
// Ajax flag answer spam
add_action( 'wp_ajax_dwqa-action-flag-answer', array( $this, 'flag_answer' ) );
+
//Ajax vote best answer
add_action( 'wp_ajax_dwqa-vote-best-answer', array( $this, 'vote_best_answer' ) );
add_action( 'wp_ajax_dwqa-unvote-best-answer', array( $this, 'unvote_best_answer' ) );
@@ -16,19 +18,23 @@ public function __construct() {
//Question
add_action( 'wp_ajax_dwqa_delete_question', array( $this, 'delete_question' ) );
add_action( 'wp_ajax_dwqa-update-question-status', array( $this, 'update_status' ) );
+
+ // Ajax search and suggest question
+ 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' ) );
}
public function delete_comment() {
if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_GET['_wpnonce'] ), '_dwqa_delete_comment' ) ) {
- wp_die( __( 'Are you cheating huh?', 'dwqa' ) );
+ wp_die( __( 'Are you cheating huh?', 'dw-question-answer' ) );
}
if ( !dwqa_current_user_can( 'delete_comment' ) ) {
- wp_die( __( 'You do not have permission to edit comment.', 'dwqa' ) );
+ wp_die( __( 'You do not have permission to edit comment.', 'dw-question-answer' ) );
}
if ( ! isset( $_GET['comment_id'] ) ) {
- wp_die( __( 'Comment ID must be showed.', 'dwqa' ) );
+ wp_die( __( 'Comment ID must be showed.', 'dw-question-answer' ) );
}
wp_delete_comment( intval( $_GET['comment_id'] ) );
@@ -37,47 +43,53 @@ public function delete_comment() {
}
function delete_answer() {
- if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], '_dwqa_action_remove_answer_nonce' ) || 'dwqa_delete_answer' !== $_GET['action'] ) {
- wp_die( __( 'Are you cheating huh?', 'dwqa' ) );
+ if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_GET['_wpnonce'] ), '_dwqa_action_remove_answer_nonce' ) || 'dwqa_delete_answer' !== $_GET['action'] ) {
+ wp_die( __( 'Are you cheating huh?', 'dw-question-answer' ) );
}
if ( ! isset( $_GET['answer_id'] ) ) {
- wp_die( __( 'Answer is missing.', 'dwqa' ), 'error' );
+ wp_die( __( 'Answer is missing.', 'dw-question-answer' ), 'error' );
}
- if ( 'dwqa-answer' !== get_post_type( $_GET['answer_id'] ) ) {
- wp_die( __( 'This post is not answer.', 'dwqa' ) );
+ $answer_id = absint( $_GET['answer_id'] );
+
+ if ( 'dwqa-answer' !== get_post_type( $answer_id ) ) {
+ wp_die( __( 'This post is not answer.', 'dw-question-answer' ) );
}
- if ( !dwqa_current_user_can( 'delete_answer' ) ) {
- wp_die( __( 'You do not have permission to delete this post.', 'dwqa' ) );
+ if ( !dwqa_current_user_can( 'delete_answer', $answer_id ) && !dwqa_current_user_can( 'edit_posts' ) ) {
+ wp_die( __( 'You do not have permission to delete this post.', 'dw-question-answer' ) );
}
- do_action( 'dwqa_prepare_delete_answer', $_GET['answer_id'] );
+ do_action( 'dwqa_prepare_delete_answer', $answer_id );
- $question_id = get_post_meta( $_GET['answer_id'], '_question', true );
+ $question_id = dwqa_get_post_parent_id( $answer_id );
- $id = wp_delete_post( $_GET['answer_id'] );
+ $id = wp_trash_post( $answer_id );
if ( is_wp_error( $id ) ) {
wp_die( $id->get_error_message() );
}
$answer_count = get_post_meta( $question_id, '_dwqa_answers_count', true );
- update_post_meta( $question_id, '_dwqa_answers_count', (int) $answer_count - 1 );
+ $new_answer_count = (int) $answer_count - 1;
+ if ( (int) $new_answer_count < 0 ) {
+ $new_answer_count = intval( 0 );
+ }
+ update_post_meta( $question_id, '_dwqa_answers_count', $new_answer_count );
- do_action( 'dwqa_delete_answer', $_GET['answer_id'], $question_id );
+ do_action( 'dwqa_delete_answer', $answer_id, $question_id );
wp_redirect( get_permalink( $question_id ) );
- exit();
+ die();
}
public function flag_answer() {
if ( ! isset( $_POST['wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['wpnonce'] ), '_dwqa_action_flag_answer_nonce' ) ) {
- wp_send_json_error( array( 'message' => __( 'Are you cheating huh?', 'dwqa' ) ) );
+ wp_send_json_error( array( 'message' => __( 'Are you cheating huh?', 'dw-question-answer' ) ) );
}
if ( ! isset( $_POST['answer_id'] ) ) {
- wp_send_json_error( array( 'message' => __( 'Missing id of answer', 'dwqa' ) ) );
+ wp_send_json_error( array( 'message' => __( 'Missing id of answer', 'dw-question-answer' ) ) );
}
global $current_user;
$answer_id = intval( $_POST['answer_id'] );
@@ -103,62 +115,72 @@ public function flag_answer() {
public function vote_best_answer() {
global $current_user;
- check_ajax_referer( '_dwqa_vote_best_answer', 'nonce' );
- if ( ! isset( $_POST['answer'] ) ) {
+ if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], '_dwqa_vote_best_answer' ) ) {
+ wp_die( __( 'Are you cheating huh?', 'dw-question-answer' ) );
+ }
+ if ( ! isset( $_GET['answer'] ) ) {
exit( 0 );
}
- $answer_id = intval( $_POST['answer'] );
- $q = get_post_meta( $answer_id, '_question', true );
- $question = get_post( $q );
+ $answer_id = intval( $_GET['answer'] );
+
+ $question_id = dwqa_get_post_parent_id( $answer_id );
+ $question = get_post( $question_id );
+
if ( $current_user->ID == $question->post_author || current_user_can( 'edit_posts' ) ) {
do_action( 'dwqa_vote_best_answer', $answer_id );
- update_post_meta( $q, '_dwqa_best_answer', $answer_id );
+ update_post_meta( $question_id, '_dwqa_best_answer', $answer_id );
}
+
+ wp_redirect( get_permalink( $question_id ) );
+ exit;
}
public function unvote_best_answer() {
global $current_user;
- check_ajax_referer( '_dwqa_vote_best_answer', 'nonce' );
- if ( ! isset( $_POST['answer'] ) ) {
+ if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], '_dwqa_vote_best_answer' ) ) {
+ wp_die( __( 'Are you cheating huh?', 'dw-question-answer' ) );
+ }
+ if ( ! isset( $_GET['answer'] ) ) {
exit( 0 );
}
- $answer_id = intval( $_POST['answer'] );
- $q = get_post_meta( $answer_id, '_question', true );
- $question = get_post( $q );
+ $answer_id = intval( $_GET['answer'] );
+ $question_id = dwqa_get_post_parent_id( $answer_id );
+ $question = get_post( $question_id );
if ( $current_user->ID == $question->post_author || current_user_can( 'edit_posts' ) ) {
do_action( 'dwqa_unvote_best_answer', $answer_id );
- delete_post_meta( $q, '_dwqa_best_answer' );
+ delete_post_meta( $question_id, '_dwqa_best_answer' );
}
-
+ wp_redirect( get_permalink( $question_id ) );
+ exit;
}
public function delete_question() {
global $dwqa_general_settings;
- if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( $_GET['_wpnonce'], '_dwqa_action_remove_question_nonce' ) || 'dwqa_delete_question' !== $_GET['action'] ) {
- wp_die( __( 'Are you cheating huh?', 'dwqa' ) );
+ if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_GET['_wpnonce'] ), '_dwqa_action_remove_question_nonce' ) || 'dwqa_delete_question' !== $_GET['action'] ) {
+ wp_die( __( 'Are you cheating huh?', 'dw-question-answer' ) );
}
if ( ! isset( $_GET['question_id'] ) ) {
- wp_die( __( 'Question is missing.', 'dwqa' ), 'error' );
+ wp_die( __( 'Question is missing.', 'dw-question-answer' ), 'error' );
}
- if ( 'dwqa-question' !== get_post_type( $_GET['question_id'] ) ) {
- wp_die( __( 'This post is not question.', 'dwqa' ) );
+ if ( 'dwqa-question' !== get_post_type( intval( $_GET['question_id'] ) ) ) {
+ wp_die( __( 'This post is not question.', 'dw-question-answer' ) );
}
if ( !dwqa_current_user_can( 'delete_answer' ) ) {
- wp_die( __( 'You do not have permission to delete this post.', 'dwqa' ) );
+ wp_die( __( 'You do not have permission to delete this post.', 'dw-question-answer' ) );
}
- do_action( 'before_delete_post', $_GET['question_id'] );
+ do_action( 'before_delete_post', intval( $_GET['question_id'] ) );
- $id = wp_delete_post( $_GET['question_id'] );
+ $id = wp_delete_post( intval( $_GET['question_id'] ) );
if ( is_wp_error( $id ) ) {
wp_die( $id->get_error_message() );
}
- do_action( 'dwqa_delete_question', $_GET['question_id'] );
+ do_action( 'dwqa_delete_question', intval( $_GET['question_id'] ) );
$url = home_url();
if ( isset( $dwqa_general_settings['pages']['archive-question'] ) ) {
@@ -191,8 +213,92 @@ public function update_status() {
}
} else {
wp_send_json_error( array(
- 'message' => __( 'You do not have permission to edit question status', 'dwqa' )
+ 'message' => __( 'You do not have permission to edit question status', 'dw-question-answer' )
) );
}
}
+
+ public function auto_suggest_for_seach(){
+ if ( ! isset( $_POST['nonce']) ) {
+ wp_send_json_error( array( array(
+ 'error' => 'sercurity',
+ 'message' => __( 'Are you cheating huh?', 'dw-question-answer' )
+ ) ) );
+ }
+ check_ajax_referer( '_dwqa_filter_nonce', 'nonce' );
+
+ if ( ! isset( $_POST['title'] ) ) {
+ wp_send_json_error( array( array(
+ 'error' => 'empty title',
+ 'message' => __( 'Not Found!!!', 'dw-question-answer' ),
+ ) ) );
+ }
+
+ $status = 'publish';
+ if ( is_user_logged_in() ) {
+ $status = array( 'publish', 'private' );
+ }
+
+ $search = sanitize_text_field( $_POST['title'] );
+ $args_query = array(
+ 'post_type' => 'dwqa-question',
+ 'posts_per_page' => 6,
+ 'post_status' => $status,
+ );
+ preg_match_all( '/#\S*\w/i', $search, $matches );
+ if ( $matches && is_array( $matches ) && count( $matches ) > 0 && count( $matches[0] ) > 0 ) {
+ $args_query['tax_query'][] = array(
+ 'taxonomy' => 'dwqa-question_tag',
+ 'field' => 'slug',
+ 'terms' => $matches[0],
+ 'operator' => 'IN',
+ );
+ $search = preg_replace( '/#\S*\w/i', '', $search );
+ }
+ $args_query['s'] = $search;
+ $args_query = apply_filters( 'dwqa_prepare_search_query_args', $args_query );
+ $query = new WP_Query( $args_query );
+ if ( ! $query->have_posts() ) {
+ global $current_search;
+ $current_search = $search;
+ add_filter( 'posts_where' , array( $this, 'posts_where_suggest' ) );
+ unset( $args_query['s'] );
+ $query = new WP_Query( $args_query );
+ remove_filter( 'posts_where' , array( $this, 'posts_where_suggest') );
+ }
+ $results = array();
+ if ( $query->have_posts() ) {
+ $html = '';
+ while ( $query->have_posts() ) {
+ $query->the_post();
+ $results[] = array(
+ 'title' => get_post_field( 'post_title', get_the_ID() ),
+ 'url' => get_permalink( get_the_ID() )
+ );
+ }
+ wp_reset_query();
+ wp_send_json_success( $results );
+ } else {
+ wp_reset_query();
+ wp_send_json_error( array( array( 'error' => 'not found', 'message' => __( 'Not Found!!!', 'dw-question-answer' ) ) ) );
+ }
+ }
+
+ public function posts_where_suggest( $where ) {
+ global $current_search;
+ $first = true;
+ $s = explode( ' ', $current_search );
+ if ( count( $s ) > 0 ) {
+ $where .= ' AND (';
+ foreach ( $s as $w ) {
+ if ( ! $first ) {
+ $where .= ' OR ';
+ }
+ $where .= "post_title REGEXP '".preg_quote( $w )."'";
+ $first = false;
+ }
+ $where .= ' ) ';
+ }
+ return $where;
+ }
}
\ No newline at end of file
diff --git a/inc/Akismet.php b/inc/Akismet.php
new file mode 100644
index 00000000..570d62b2
--- /dev/null
+++ b/inc/Akismet.php
@@ -0,0 +1,555 @@
+akismet_ua = "DWQA/".get_option( 'dwqa-db-version', '1.4.7' )." | Akismet/3.1.7";
+ add_action('init', array( $this, 'dwqa_admin_show_spam_page'));
+ add_action('init', array( $this, 'dwqa_akismet_mark_spam'));
+ // add_action( 'admin_menu', array( $this, 'reported_list_admin' ) );
+
+ // add_action( 'wp_enqueue_scripts', array($this,'dwqa_akismet_enqueue_script' ),10);
+
+ add_action('manage_posts_extra_tablenav', array( $this, 'dwqa_admin_add_button_empty_spam'));
+ // add_action( 'wp_ajax_dwqa_report_spam_to_admin', array( $this, 'dwqa_report_spam_to_admin') );
+ // add_filter( 'dwqa_question_button_action', array( $this, 'dwqa_add_button_action_report_spam_to_admin'), 10);
+ // add_filter( 'dwqa_answer_button_action', array( $this, 'dwqa_add_button_action_report_spam_to_admin'), 10);
+ add_filter( 'post_row_actions', array( $this, 'dwqa_admin_add_post_row_button'), 11, 2 );
+
+ //setkey
+ $this->akismetAPIKey = (isset($dwqa_general_settings['akismet-api-key']) && $dwqa_general_settings['akismet-api-key']!='')?$dwqa_general_settings['akismet-api-key']:'';
+
+ // Call to verify key function
+ if($this->akismet_verify_key($this->akismetAPIKey)){
+ //verified do something
+
+ $this->data = array(
+ 'blog' => get_option( 'home' ),
+ 'blog_charset' => get_option( 'blog_charset' ),
+ 'blog_lang' => get_locale(),
+ 'user_ip' => $this->get_user_ip(),
+ 'user_agent' => (isset($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:''),
+ 'referrer' => (isset($_SERVER['HTTP_REFERER'])?$_SERVER['HTTP_REFERER']:''),
+ 'permalink' => '',
+ 'comment_type' => '',
+ 'comment_author' => '',
+ 'comment_author_email' => '',
+ 'comment_author_url' => '',
+ 'comment_content' => '',
+ 'comment_approved' => '', //post_status
+ 'comment_date' => '', //post_date
+ 'comment_ID' => '', //postID
+ 'comment_post_ID' => '', //post_parent_ID
+ 'is_test' => false,
+ );
+
+ // Keys to ignore
+ $ignore = array( 'HTTP_COOKIE', 'HTTP_COOKIE2', 'PHP_AUTH_PW' );
+ // Loop through _SERVER args and remove whitelisted keys
+ foreach ( $_SERVER as $key => $value ) {
+
+ // Key should not be ignored
+ if ( !in_array( $key, $ignore ) && is_string( $value ) ) {
+ $this->data[$key] = $value;
+
+ // Key should be ignored
+ } else {
+ $this->data[$key] = '';
+ }
+ }
+
+ add_filter( 'dwqa_insert_question_args', array( $this, 'dwqa_check_spam' ) , 10, 1 );
+ add_filter( 'dwqa_insert_answer_args', array( $this, 'dwqa_check_spam' ) , 10, 1 );
+ add_filter( 'dwqa_insert_comment_args', array( $this, 'dwqa_check_spam' ) , 10, 1 );
+ // add_action( 'dwqa_after_mark_unspam', array( $this, 'dwqa_check_spam' ) , 10, 1 );
+ }
+ }
+ }
+
+ // Create reported list admin
+ public function reported_list_admin(){
+ $dwqa_reported_page = add_submenu_page( 'edit.php?post_type=dwqa-question', __( 'Report Spam List','dw-question-answer' ), __( 'Report Spam','dw-question-answer' ), 'manage_options', 'dwqa-report-spam-list', array( $this, 'reported_list_admin_display' ) );
+ }
+ public function reported_list_admin_display(){
+ require_once DWQA_DIR . 'inc/class/class-display-reported-list-table.php';
+ $reportedTable = new Reported_List_Table();
+ $reportedTable->process_bulk_action();
+
+ echo 'Reported Spam List ';
+ $columns = array(
+ 'id' => 'id',
+ 'title' => __( 'Title', 'dw-question-answer' ),
+ 'type' => __( 'Type', 'dw-question-answer' ),
+ 'author' => __( 'Author', 'dw-question-answer' ),
+ 'countreport' =>__( 'Count Report', 'dw-question-answer' )
+ );
+
+ $hiddens = array(
+ 'id'
+ );
+ $sortable = array(
+ 'id' => array('id',false),
+ 'title' => array('title',false),
+ 'type' => array('type',false),
+ 'author' => array('author',false),
+ 'countreport' => array('countreport',false)
+ );
+ $reportedTable->edit_columns($columns);
+ $reportedTable->edit_hiddens($hiddens);
+ $reportedTable->edit_sortable($sortable);
+ $reportedTable->edit_perpage(11);
+
+ $query = get_posts( array(
+ 'post_type' => array('dwqa-answer','dwqa-question'),
+ 'post_status' => array('publish', 'pending', 'draft', 'auto-draft', 'future', 'private', 'inherit'),
+ 'meta_query' => array(
+ array(
+ 'key' => '_dwqa_spam_reported',
+ 'value' => '',
+ 'compare' =>'!='
+ ),
+ )
+ ) );
+ // echo '
';
+ // print_r($query);
+ // echo ' ';
+ $_data = $this->setup_data_list($query);
+ $reportedTable->prepare_items($_data);
+
+ echo '
';
+ echo '
';
+ }
+ private function setup_data_list($report_list){
+
+ $data_report = array();
+ foreach ($report_list as $item) {
+ $id = $item->ID;
+ $id_link = admin_url().'post.php?post='.$id.'&action=edit';
+ $title = ''.$item->post_title.' ';
+
+ $author_id = $item->post_author;
+ $author_info = get_user_by('id',$author_id);
+ $author = ''.$author_info->display_name.' ';
+ $rp_list = get_post_meta($id, '_dwqa_spam_reported',true);
+ if($rp_list!='' && $rp_list){
+ $countreport = count(unserialize($rp_list));
+ }else{
+ $countreport = 0;
+ }
+
+ /*action*/
+ $actions = array(
+ 'nospam' => sprintf(
+ '%s ',
+ wp_nonce_url( admin_url("edit.php?post_type=".$item->post_type."&action=unspam&post=".$item->ID), "nospam-post_{$item->ID}" ),
+ esc_attr( sprintf( __( 'Unspam “%s”' ), $item->post_title ) ),
+ __( 'publish' )
+ ),
+ 'view' => sprintf(
+ '%s ',
+ admin_url().'post.php?post='.$id.'&action=edit',
+ esc_attr( sprintf( __( 'View %s' ), $item->post_title ) ),
+ __( 'View','dw-question-answer' )
+ ),
+ 'delete' => sprintf(
+ '%s ',
+ get_delete_post_link( $id , '', true), __( 'Delete permanently', 'dw-question-answer' )
+ )
+ );
+ $action='';
+ $action .= implode(' | ', $actions);
+ $action .= '
';
+ $temp = array(
+ 'id' => $id,
+ 'title' => $title.$action,
+ 'type'=> $type,
+ 'author'=> $author,
+ 'countreport' => $countreport
+ );
+
+ array_push($data_report,$temp);
+ }
+ return $data_report;
+ }
+
+ private function dwqa_prepare_data($data){
+ $data_check_spam = $this->data;
+
+ $post_permalink = '';
+ if ( !empty( $data['post_parent'] ) ) {
+ $post_permalink = get_permalink( $data['post_parent'] );
+ }
+ $data_check_spam['permalink'] = $post_permalink;
+
+ if ( empty( $data['post_author'] ) ) {
+ $data['post_author'] = 0;
+ }
+ $userdata = get_userdata( $data['post_author'] );
+
+ if ( !empty( $userdata ) ) {
+ $user_data['name'] = $userdata->display_name;
+ $user_data['email'] = $userdata->user_email;
+ $user_data['website'] = $userdata->user_url;
+ } else if ( isset( $data['is_anonymous'] ) ) {
+ $user_data['name'] = isset( $data['dwqa_anonymous_name'] ) ? $data['dwqa_anonymous_name'] : __( 'Anonymous', 'dw-question-answer' );
+ $user_data['email'] = isset( $data['dwqa_anonymous_email'] ) ? $data['dwqa_anonymous_email'] : '';
+ $user_data['website'] = '';
+ } else {
+ $user_data['name'] = '';
+ $user_data['email'] = '';
+ $user_data['website'] = '';
+ }
+
+ $data_check_spam['comment_author'] = $user_data['name'];
+ // $data_check_spam['comment_author'] = 'viagra-test-123'; // for test
+ // $data_check_spam['is_test'] = true; // for test
+ $data_check_spam['comment_author_email'] = $user_data['email'];
+ $data_check_spam['comment_author_url'] = $user_data['website'];
+
+ $data_check_spam['comment_content'] = isset($data['post_content'])?$data['post_content']:'';
+ $data_check_spam['comment_type'] = isset($data['post_type'])?$data['post_type']:'';
+ $data_check_spam['comment_approved'] = isset($data['post_status'])?$data['post_status']:'';
+ $data_check_spam['comment_date'] = isset($data['post_date'])?$data['post_date']:'';
+ $data_check_spam['comment_date_gmt'] = isset($data['post_date_gmt'])?$data['post_date_gmt']:'';
+ $data_check_spam['comment_ID'] = isset($data['ID'])?$data['ID']:'';
+ $data_check_spam['comment_post_ID'] = isset($data['post_parent'])?$data['post_parent']:'';
+
+
+ return $data_check_spam;
+ }
+
+ public function dwqa_check_spam($data){
+ if($this->akismet_comment_check($this->akismetAPIKey, $this->dwqa_prepare_data($data))){
+ //is spam mark status spam
+ $data['post_status'] = 'spam';
+ }
+ return $data;
+ }
+
+
+ // Display User IP in WordPress
+ private function get_user_ip() {
+ if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) {
+ $ip = $_SERVER['HTTP_CLIENT_IP'];
+ } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) {
+ $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
+ } else {
+ $ip = $_SERVER['REMOTE_ADDR'];
+ }
+ return apply_filters( 'dwqa_get_ip', $ip );
+ }
+
+ // Authenticates your Akismet API key
+ public static function akismet_verify_key( $key, $blog = '', $port = 443, $akismet_ua = "WordPress/4.4.1 | Akismet/3.1.7" ) {
+ if($blog==''){
+ $blog = urlencode(get_home_url());
+ }else{
+ $blog = urlencode($blog);
+ }
+
+ $request = 'key='. $key .'&blog='. $blog;
+ $host = $http_host = 'rest.akismet.com';
+ $path = '/1.1/verify-key';
+ // $port = $this->port;
+ // $akismet_ua = $this->akismet_ua;
+ $content_length = strlen( $request );
+ $http_request = "POST $path HTTP/1.0\r\n";
+ $http_request .= "Host: $host\r\n";
+ $http_request .= "Content-Type: application/x-www-form-urlencoded\r\n";
+ $http_request .= "Content-Length: {$content_length}\r\n";
+ $http_request .= "User-Agent: {$akismet_ua}\r\n";
+ $http_request .= "\r\n";
+ $http_request .= $request;
+ $response = '';
+ if( false != ( $fs = @fsockopen( 'ssl://' . $http_host, $port, $errno, $errstr, 10 ) ) ) {
+
+ fwrite( $fs, $http_request );
+
+ while ( !feof( $fs ) )
+ $response .= fgets( $fs, 1160 ); // One TCP-IP packet
+ fclose( $fs );
+
+ $response = explode( "\r\n\r\n", $response, 2 );
+ }
+
+ if ( 'valid' == $response[1] ){
+ return true;
+ }else{
+ return false;
+ }
+ }
+
+
+
+ // Passes back true (it's spam) or false (it's ham)
+ public function akismet_comment_check( $key, $data ) {
+
+ $request = '';
+
+ foreach($data as $kData => $vData){
+ if($request == ''){
+ $request .= $kData.'='.urlencode($vData);
+ }else{
+ $request .= '&'.$kData.'='.urlencode($vData);
+ }
+ }
+
+ $host = $http_host = $key.'.rest.akismet.com';
+ $path = '/1.1/comment-check';
+ $port = $this->port;
+ $akismet_ua = $this->akismet_ua;
+ $content_length = strlen( $request );
+ $http_request = "POST $path HTTP/1.0\r\n";
+ $http_request .= "Host: $host\r\n";
+ $http_request .= "Content-Type: application/x-www-form-urlencoded\r\n";
+ $http_request .= "Content-Length: {$content_length}\r\n";
+ $http_request .= "User-Agent: {$akismet_ua}\r\n";
+ $http_request .= "\r\n";
+ $http_request .= $request;
+ $response = '';
+ if( false != ( $fs = @fsockopen( 'ssl://' . $http_host, $port, $errno, $errstr, 10 ) ) ) {
+
+ fwrite( $fs, $http_request );
+
+ while ( !feof( $fs ) )
+ $response .= fgets( $fs, 1160 ); // One TCP-IP packet
+ fclose( $fs );
+
+ $response = explode( "\r\n\r\n", $response, 2 );
+ }
+
+ if ( 'true' == $response[1] )
+ return true;
+ else
+ return false;
+ }
+
+
+ // Passes back true (it's spam) or false (it's ham)
+ public function akismet_submit_spam( $key, $data ) {
+ $new_data = $this->dwqa_prepare_data($data);
+ $request = '';
+
+ foreach($new_data as $kData => $vData){
+ if($request == ''){
+ $request .= $kData.'='.urlencode($vData);
+ }else{
+ $request .= '&'.$kData.'='.urlencode($vData);
+ }
+ }
+ $host = $http_host = $key.'.rest.akismet.com';
+ $path = '/1.1/submit-spam';
+ $port = $this->port;
+ $akismet_ua = $this->akismet_ua;
+ $content_length = strlen( $request );
+ $http_request = "POST $path HTTP/1.0\r\n";
+ $http_request .= "Host: $host\r\n";
+ $http_request .= "Content-Type: application/x-www-form-urlencoded\r\n";
+ $http_request .= "Content-Length: {$content_length}\r\n";
+ $http_request .= "User-Agent: {$akismet_ua}\r\n";
+ $http_request .= "\r\n";
+ $http_request .= $request;
+ $response = '';
+ if( false != ( $fs = @fsockopen( 'ssl://' . $http_host, $port, $errno, $errstr, 10 ) ) ) {
+
+ fwrite( $fs, $http_request );
+
+ while ( !feof( $fs ) )
+ $response .= fgets( $fs, 1160 ); // One TCP-IP packet
+ fclose( $fs );
+
+ $response = explode( "\r\n\r\n", $response, 2 );
+ }
+
+ if ( 'Thanks for making the web a better place.' == $response[1] )
+ return true;
+ else
+ return false;
+ }
+
+
+ // Passes back true (it's spam) or false (it's ham)
+ public function akismet_submit_ham( $key, $data ) {
+ $new_data = $this->dwqa_prepare_data($data);
+ $request = '';
+
+ foreach($new_data as $kData => $vData){
+ if($request == ''){
+ $request .= $kData.'='.urlencode($vData);
+ }else{
+ $request .= '&'.$kData.'='.urlencode($vData);
+ }
+ }
+ $host = $http_host = $key.'.rest.akismet.com';
+ $path = '/1.1/submit-ham';
+ $port = $this->port;
+ $akismet_ua = $this->akismet_ua;
+ $content_length = strlen( $request );
+ $http_request = "POST $path HTTP/1.0\r\n";
+ $http_request .= "Host: $host\r\n";
+ $http_request .= "Content-Type: application/x-www-form-urlencoded\r\n";
+ $http_request .= "Content-Length: {$content_length}\r\n";
+ $http_request .= "User-Agent: {$akismet_ua}\r\n";
+ $http_request .= "\r\n";
+ $http_request .= $request;
+ $response = '';
+ if( false != ( $fs = @fsockopen( 'ssl://' . $http_host, $port, $errno, $errstr, 10 ) ) ) {
+
+ fwrite( $fs, $http_request );
+
+ while ( !feof( $fs ) )
+ $response .= fgets( $fs, 1160 ); // One TCP-IP packet
+ fclose( $fs );
+
+ $response = explode( "\r\n\r\n", $response, 2 );
+ }
+
+ if ( 'Thanks for making the web a better place.' == $response[1] )
+ return true;
+ else
+ return false;
+ }
+
+ public function dwqa_admin_show_spam_page(){
+ register_post_status( 'spam', array(
+ 'label' => _x( 'Spam', 'dw-question-answer' ),
+ 'public' => false,
+ 'exclude_from_search' => false,
+ 'show_in_admin_all_list' => false,
+ 'show_in_admin_status_list' => true,
+ 'label_count' => _n_noop( 'Spam (%s) ', 'Spam (%s) ' ),
+ ) );
+ }
+ public function dwqa_admin_add_button_empty_spam(){
+ if ( isset( $_GET['post_status'] ) && sanitize_text_field( $_GET['post_status'] ) == 'spam') {
+ echo '';
+ submit_button( __( 'Empty Spam' ), 'apply', 'delete_all', false );
+ echo '
';
+ }
+ }
+ public function dwqa_admin_add_post_row_button($actions, $post){
+
+ if($post->post_type=="dwqa-question" || $post->post_type=="dwqa-answer"){
+ if($post->post_status!="spam"){
+ $actions['spam'] = sprintf(
+ '%s ',
+ wp_nonce_url( admin_url("edit.php?post_type=".$post->post_type."&action=spam&post=".$post->ID), "spam-post_{$post->ID}" ),
+ esc_attr( sprintf( __( 'Spam “%s”' ), $post->post_title ) ),
+ __( 'Spam' )
+ );
+ }else{
+ $actions['unspam'] = sprintf(
+ '%s ',
+ wp_nonce_url( admin_url("edit.php?post_type=".$post->post_type."&action=unspam&post=".$post->ID), "unspam-post_{$post->ID}" ),
+ esc_attr( sprintf( __( 'Unspam “%s”' ), $post->post_title ) ),
+ __( 'publish' )
+ );
+ }
+
+ }
+ return $actions;
+ }
+
+ public function dwqa_akismet_mark_spam(){
+ if(isset($_GET['post_type']) && ($_GET['post_type']=='dwqa-question' || $_GET['post_type']=='dwqa-answer')){
+ if(isset($_GET['post']) && $_GET['post'] && is_numeric($_GET['post'])){
+ if (isset($_GET['action']) && ! wp_verify_nonce( $_REQUEST['_wpnonce'], "{$_GET['action']}-post_{$_GET['post']}" ) ) {
+ die( 'Security check' );
+ }
+
+ if($_GET['action']=='spam'){
+ if ( !current_user_can( 'delete_post', $_GET['post'] ) )
+ die( 'Security check' );
+
+ $args = array(
+ 'ID' => $_GET['post'],
+ 'post_status' => 'spam'
+ );
+ wp_update_post( $args );
+ if(!$this->akismet_submit_spam($this->akismetAPIKey, get_post($_GET['post']))){
+ //is spam
+ }
+ // do_action("dwqa_after_mark_spam");
+ wp_redirect(admin_url( 'edit.php?post_type='.$_GET['post_type']));
+ exit();
+ }
+ if($_GET['action']=='unspam'){
+ if($_GET['post_type']=='dwqa-question'){
+ $args = array(
+ 'ID' => $_GET['post'],
+ 'post_status' => 'publish'
+ );
+ }else{
+ $args = array(
+ 'ID' => $_GET['post'],
+ 'post_status' => 'inherit'
+ );
+ }
+
+ wp_update_post( $args );
+ if(!$this->akismet_submit_ham($this->akismetAPIKey, get_post($_GET['post']))){
+ //is spam
+ }
+ // do_action("dwqa_after_mark_unspam");
+ wp_redirect(admin_url( 'edit.php?post_type='.$_GET['post_type']));
+ exit();
+ }
+
+ }
+ }
+ return;
+ }
+
+ public function dwqa_report_spam_to_admin(){
+ $user_id = get_current_user_id();
+ if(!$user_id>0 || !is_numeric($user_id)){
+ wp_send_json_error( array( 'message' => __( 'You need login to report spam!', 'dw-question-answer' ) ) );
+ }
+ if ( ! isset( $_POST['post_id'] ) || !is_numeric($_POST['post_id']) ) {
+ wp_send_json_error( array( 'message' => __( 'Post not found!', 'dw-question-answer' ) ) );
+ }
+ if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['nonce'] ), '_dwqa_action_report_spam_to_admin' ) ) {
+ wp_send_json_error( array( 'message' => __( 'Are you cheating huh?', 'dw-question-answer' ) ) );
+ }
+ $post_id = $_POST['post_id'];
+ $key = '_dwqa_spam_reported';
+ $args = get_post_meta($post_id , $key, true);
+ if($args=='' || !$args){
+ $args[] = $user_id;
+ }else{
+ $args = unserialize($args);
+ if(!in_array($user_id,$args)){
+ $args[] = $user_id;
+ }else{
+ wp_send_json_error( array( 'message' => __( 'You reported this post before!', 'dw-question-answer' ) ) );
+ }
+ }
+ update_post_meta($post_id, $key, serialize($args));
+ // if(empty)
+ wp_send_json_success( array( 'message' => __( 'Reported to admin', 'dw-question-answer' ) ) );
+ }
+
+ public function dwqa_add_button_action_report_spam_to_admin($html){
+ if ( is_user_logged_in() ) {
+ $action_url = add_query_arg( array( 'action' => 'dwqa_delete_answer', 'answer_id' => get_the_ID() ), admin_url( 'admin-ajax.php' ) );
+ $html .= '' . __( 'Report Spam', 'dw-question-answer' ) . ' ';
+ }
+ return $html;
+
+ }
+ public function dwqa_akismet_enqueue_script() {
+ wp_enqueue_script( 'dwqa-akismet-button-report-spam-script', DWQA_URI.'assets/js/dwqa-akismet-button-report-spam.js', false );
+ wp_enqueue_style( 'dwqa-akismet-button-report-spam-style', DWQA_URI.'assets/css/dwqa-akismet-button-report-spam.css', false );
+ }
+}
+?>
\ No newline at end of file
diff --git a/inc/Answer_List_Table.php b/inc/Answer_List_Table.php
index 6d144f89..c4db2fcd 100644
--- a/inc/Answer_List_Table.php
+++ b/inc/Answer_List_Table.php
@@ -45,15 +45,9 @@ function prepare_items() {
'post_type' => 'dwqa-answer',
'posts_per_page' => $per_page,
'order' => 'ASC',
- 'meta_query' => array(
- array(
- 'key' => '_question',
- 'value' => array( $question_id ),
- 'compare' => 'IN',
- ),
- ),
- 'post_status' => 'publish',
- );
+ 'post_parent' => $question_id,
+ 'post_status' => 'publish',
+ );
$data = get_posts( $args );
$this->items = $data;
}
@@ -78,8 +72,8 @@ function display() {
function get_columns() {
$columns = array(
- 'author' => __( 'Author', 'dwqa' ),
- 'detail' => __( 'Detail', 'dwqa' ),
+ 'author' => __( 'Author', 'dw-question-answer' ),
+ 'detail' => __( 'Detail', 'dw-question-answer' ),
);
return $columns;
}
@@ -89,7 +83,7 @@ function column_default( $item, $column_name ) {
case 'author':
$user_info = get_userdata( $item->post_author );
if ( ! $user_info ) {
- echo ''.__( 'Anonymous','dwqa' ).' ';
+ echo ''.__( 'Anonymous','dw-question-answer' ).' ';
} else {
echo ''.get_avatar( $item->post_author, $size = '32' ) . ' ' .$user_info->display_name . ' ';
}
@@ -98,7 +92,7 @@ function column_default( $item, $column_name ) {
global $post;
setup_postdata( $item );
?>
-
+
...', $excerpt );
+ return str_replace( '[...]', '... ', $excerpt );
}
}
diff --git a/inc/Autoclosure.php b/inc/Autoclosure.php
new file mode 100644
index 00000000..ef3e73d3
--- /dev/null
+++ b/inc/Autoclosure.php
@@ -0,0 +1,71 @@
+0){
+
+ $this->days = $dwqa_general_settings['number-day-auto-closure'];
+
+ add_filter( 'cron_schedules', array($this, 'dwqa_add_schedule') );
+
+ if (! wp_next_scheduled ( 'auto_closure' )) {
+ wp_schedule_event(time(), 'half_daily', 'auto_closure');
+ }
+
+ add_action('auto_closure', array($this, 'do_auto_closure'));
+ }
+ }else{
+ wp_clear_scheduled_hook( 'auto_closure' );
+ }
+ }
+
+ public function do_auto_closure(){
+ $days = $this->days;
+ $posts = get_posts(array(
+ 'post_type' => 'dwqa-question',
+ 'date_query' => array(
+ array(
+ 'column' => 'post_modified_gmt',
+ 'before' => $days.' day ago',
+ ),
+ ),
+ 'meta_query' => array(
+ array(
+ 'key' => '_dwqa_status',
+ 'value' => 'closed',
+ 'compare' =>'!='
+ )
+ )
+ ));
+ foreach($posts as $value){
+ update_post_meta( $value->ID, '_dwqa_status', 'closed' );
+ }
+ }
+
+ public function dwqa_add_schedule( $schedules ) {
+ // add a 'weekly' schedule to the existing set
+ /* $schedules['weekly'] = array(
+ 'interval' => 604800,
+ 'display' => __('Once Weekly', 'dw-question-answer')
+ );
+ $schedules['monthly'] = array(
+ 'interval' => 2635200,
+ 'display' => __('Once a month', 'dw-question-answer')
+ );
+ $schedules['minutely'] = array(
+ 'interval' => 60,
+ 'display' => __('Minutely', 'dw-question-answer')
+ ); */
+ $schedules['half_daily'] = array(
+ 'interval' => 43200,
+ 'display' => __('Half Daily', 'dw-question-answer')
+ );
+ return $schedules;
+ }
+
+}
+?>
\ No newline at end of file
diff --git a/inc/Editor.php b/inc/Editor.php
index 9d804e99..99ca47ed 100644
--- a/inc/Editor.php
+++ b/inc/Editor.php
@@ -15,9 +15,6 @@ class DWQA_Editor {
public function __construct() {
add_action( 'init', array( $this, 'tinymce_addbuttons' ) );
- //Ajaxs
- add_action( 'wp_ajax_dwqa-editor-update-answer-init', array( $this, 'ajax_create_update_answer_editor' ) );
- add_action( 'wp_ajax_dwqa-editor-update-question-init', array( $this, 'ajax_create_update_question_editor' ) );
add_filter( 'dwqa_prepare_edit_answer_content', 'wpautop' );
add_filter( 'dwqa_prepare_edit_question_content', 'wpautop' );
@@ -71,114 +68,6 @@ public function display( $args ) {
public function toolbar_buttons() {
}
-
- public function ajax_create_update_answer_editor() {
-
- if ( ! isset( $_POST['answer_id'] ) || ! isset( $_POST['question'] ) ) {
- return false;
- }
- extract( $_POST );
-
- ob_start();
- ?>
-
- $editor ) );
- }
-
- public function ajax_create_update_question_editor() {
-
- check_ajax_referer( '_dwqa_edit_question', 'nonce' );
-
- if ( ! isset( $_POST['post'] ) ) {
- return false;
- }
-
- extract( $_POST );
- $title = get_the_title( $post );
- $title = apply_filters( 'dwqa_prepare_edit_question_title', $title, $post );
- $content = get_post_field( 'post_content', $post );
- $content = apply_filters( 'dwqa_prepare_edit_question_content', $title, $post );
- $args = array(
- 'content' => $content,
- 'id' => 'dwqa-question-edit-form',
- 'textarea_name' => 'question-content-edit'
- );
-
- ob_start();
- ?>
-
- $editor ) );
- }
}
?>
\ No newline at end of file
diff --git a/inc/Filter.php b/inc/Filter.php
index d79d9ced..c228b3c0 100644
--- a/inc/Filter.php
+++ b/inc/Filter.php
@@ -4,501 +4,18 @@
* Inlucde all funtion for filter of dw question answer plugin
*/
class DWQA_Filter {
-
- //Properties
- private $tb_post; // Name of table of posts
- private $tb_postmeta; // Name of table of postmeta
- private $filter = array(
- 'type' => 'all',
- 'posts_per_page' => 5,
- 'filter_plus' => 'open',
- 'category' => 'all',
- 'paged' => 1,
- 'tags' => 0,
- 'order' => 'DESC',
- );
- /**
- * AJAX: To make filter questions for plugins
- * @return string JSON
- */
- public function filter_question(){
- if ( ! isset( $_POST['nonce']) ) {
- wp_die( 0 );
- }
- if ( ! check_ajax_referer( '_dwqa_filter_nonce', 'nonce', false ) ) {
- wp_die( 0 );
- }
- if ( ! isset( $_POST['type']) ) {
- wp_die( 0 );
- }
- // Make an query for
- global $wpdb;
- if ( ! defined( 'DWQA_FILTERING' ) ) {
- define( 'DWQA_FILTERING', true );
- }
- $this->filter = wp_parse_args( $_POST,$this->filter );
- //query post filter
- add_filter( 'posts_join', array( $this, 'join_postmeta_count_answers') );
- add_filter( 'posts_orderby', array( $this, 'edit_posts_orderby') );
- add_filter( 'posts_where', array( $this, 'posts_where') );
-
- $questions = $this->get_questions();
-
- //remove query post filter
- remove_filter( 'posts_join', array( $this, 'join_postmeta_count_answers') );
- remove_filter( 'posts_orderby', array( $this, 'edit_posts_orderby') );
- remove_filter( 'posts_where', array( $this, 'posts_where') );
- // Print content of questions
- if ( $questions->have_posts() ) {
- global $post;
- $pages_total = $questions->found_posts;
- $pages_number = ceil( $pages_total / (int) $this->filter['posts_per_page'] );
- $start_page = isset( $this->filter['paged']) && $this->filter['paged'] > 2 ? $this->filter['paged'] - 2 : 1;
- if ( $pages_number > 1 ) {
- $link = get_post_type_archive_link( 'dwqa-question' );
- ob_start();
- echo '';
- echo 'Prev ';
-
- if ( $start_page > 1 ) {
- echo '1 ... ';
- }
- for ( $i = $start_page; $i < $start_page + 5; $i++ ) {
- if ( $pages_number < $i ) {
- break;
- }
- if ( $i == $this->filter['paged'] ) {
- echo ''.$i.' ';
- } else {
- echo ''.$i.' ';
- }
- }
-
- if ( $i - 1 < $pages_number ) {
- echo '... '.$pages_number.' ';
- }
- echo ''.__( 'Next','dwqa' ).' ';
-
- echo ' ';
- $pagenavigation = ob_get_contents();
- ob_end_clean();
- }
-
- ob_start();
- while ( $questions->have_posts() ) { $questions->the_post();
- dwqa_load_template( 'content', 'question' );
- }
- $results = ob_get_contents();
- ob_end_clean();
-
- } else { // Notthing found
- ob_start();
- if ( ! dwqa_current_user_can( 'read_question' ) ) {
- echo ''.__( 'You do not have permission to view questions','dwqa' ).'
';
- }
- echo '';
- _e( 'Sorry, but nothing matched your filter. ', 'dwqa' );
- if ( is_user_logged_in() ) {
- global $dwqa_options;
- if ( isset( $dwqa_options['pages']['submit-question']) ) {
- $submit_link = get_permalink( $dwqa_options['pages']['submit-question'] );
- if ( $submit_link ) {
- printf(
- '%s %s ',
- __( 'You can ask question', 'dwqa' ),
- $submit_link,
- __( 'here', 'dwqa' )
- );
- }
- }
- } else {
- printf( '%s %s ',
- __( 'Please','dwqa' ),
- wp_login_url( get_post_type_archive_link( 'dwqa-question' ) ),
- __( 'Login','dwqa' )
- );
- $register_link = wp_register( '', '',false );
- if ( ! empty( $register_link) && $register_link ) {
- echo __( ' or','dwqa' ).' '.$register_link;
- }
- _e( ' to submit question.','dwqa' );
- }
-
- echo '
';
- $results = ob_get_contents();
- ob_end_clean();
- }
-
- wp_send_json_success( array(
- 'results' => $results,
- 'pagenavi' => isset( $pagenavigation) ? $pagenavigation : ''
- ) );
- wp_die();
- }
-
- private function get_questions( $on_paged = true ) {
- $posts_per_page = $this->filter['posts_per_page'] ;
- $paged = $this->filter['paged'];
- $offset = ($paged - 1) * $posts_per_page;
-
- // pagenavigation
- $number = -1;
- if ( $on_paged )
- $number = $posts_per_page;
- // arguments array for get questions
- $status = array( 'publish' );
- if ( is_user_logged_in() ) {
- $status[] = 'private';
- $status[] = 'pending';
- }
- $sticky_questions = get_option( 'dwqa_sticky_questions', array() );
- $args = array(
- 'posts_per_page' => $number,
- 'offset' => $offset,
- 'post_type' => 'dwqa-question',
- 'suppress_filters' => false,
- 'post__not_in' => $sticky_questions,
- 'post_status' => $status,
- );
-
- if ( is_user_logged_in() ) {
- $args['perm'] = 'readable';
- }
-
- $args['order'] = ( $this->filter['order'] && $this->filter['order'] != 'ASC' ? 'DESC' : 'ASC' );
-
- switch ( $this->filter['type'] ) {
- case 'views':
- $args['meta_key'] = '_dwqa_views';
- $args['orderby'] = 'meta_value_num';
- break;
- case 'votes':
- $args['meta_key'] = '_dwqa_votes';
- $args['orderby'] = 'meta_value_num';
- break;
- default :
- $args['orderby'] = 'modified';
- break;
- }
-
- switch ( $this->filter['filter_plus'] ) {
- case 'resolved' :
- $args['meta_query'][] = array(
- 'key' => '_dwqa_status',
- 'value' => array( 'resolved' ),
- 'compare' => 'IN',
- );
- break;
- case 'replied':
-
- $args['meta_query'][] = array(
- 'key' => '_dwqa_status',
- 'value' => array( 'open', 're-open', 'pending', 'answered' ),
- 'compare' => 'IN',
- );
- //not have answered by admin
- break;
- case 'overdue':
- case 'new-comment':
- case 'open' :
- $args['meta_query'][] = array(
- 'key' => '_dwqa_status',
- 'value' => array( 'open', 're-open', 'pending' ),
- 'compare' => 'IN',
- );
- //not have answered by admin
- break;
- case 'pending-review':
- $args['meta_query'][] = array(
- 'key' => '_dwqa_status',
- 'value' => array( 'pending' ),
- 'compare' => 'IN',
- );
- break;
- case 'closed' :
- $args['meta_query'][] = array(
- 'key' => '_dwqa_status',
- 'value' => array( 'closed' ),
- 'compare' => 'IN',
- );
- break;
- }
- if ( $this->filter['category'] != 'all' ) {
- $args['tax_query'][] = array(
- 'taxonomy' => 'dwqa-question_category',
- 'field' => 'id',
- 'terms' => array( $this->filter['category'] ),
- 'operator' => 'IN',
- );
- }
-
- if ( (boolean) $this->filter['tags'] ) {
- $args['tax_query'][] = array(
- 'taxonomy' => 'dwqa-question_tag',
- 'field' => 'id',
- 'terms' => array( $this->filter['tags'] ),
- 'operator' => 'IN',
- );
- }
-
- if ( isset( $this->filter['title'] ) && $this->filter['title'] && $this->filter['title'] !== 'Search' ) {
- $args['s'] = $this->filter['title'];
- }
-
- $questions = new WP_Query( $args );
- return $questions;
- }
-
- function edit_posts_orderby( $orderby_statement ) {
- switch ( $this->filter['type'] ) {
- case 'answers':
- $order = ( $this->filter['order'] && $this->filter['order'] != 'ASC' ? 'DESC' : 'ASC' );
- $orderby_statement = 'count_answer.dwqa_answers '. $order;
- break;
- case 'views';
- case 'votes';
- break;
-
- default:
- // $order = ( $this->filter['order'] && $this->filter['order'] != 'ASC' ? 'DESC' : 'ASC' );
- // $orderby_statement = $this->order_filter_default( $orderby_statement, $order );
- break;
- }
- return $orderby_statement;
- }
-
- // Join for searching metadata
- function join_postmeta_count_answers( $join ) {
- global $wp_query, $wpdb;
- switch ( $this->filter['type'] ) {
- case 'answers':
- $join .= "LEFT JOIN
- ( SELECT meta_value AS question, COUNT( * ) AS dwqa_answers
- FROM $wpdb->postmeta
- WHERE meta_key = '_question'
- GROUP BY meta_value ) AS count_answer
- ON $wpdb->posts.ID = count_answer.question
- ";
- break;
- case 'views';
- case 'votes';
- break;
- default:
- // $join = $this->join_filter_default( $join );
- break;
- }
- return $join;
- }
-
-
- public function join_filter_default( $join ) {
- global $wpdb;
-
- $join .= "LEFT JOIN
- ( SELECT $wpdb->postmeta.meta_value as question, max( $wpdb->posts.post_modified) as post_modified
- FROM $wpdb->posts, $wpdb->postmeta
- WHERE
- $wpdb->posts.post_type = 'dwqa-answer'
- AND (
- $wpdb->posts.post_status = 'publish'";
- if ( is_user_logged_in() ) {
- $join .= " OR $wpdb->posts.post_status = 'private' ";
- $join .= " OR $wpdb->posts.post_status = 'pending' ";
- }
- $join .= ")
- AND $wpdb->postmeta.post_id = $wpdb->posts.ID
- AND $wpdb->postmeta.meta_key = '_question'
- GROUP BY question ) as dw_table_latest_answers
- ON $wpdb->posts.ID = dw_table_latest_answers.question ";
-
- return $join;
- }
-
- public function order_filter_default( $orderby_statement, $order = 'DESC' ) {
- global $wpdb;
- return " ifnull( dw_table_latest_answers.post_modified, $wpdb->posts.post_modified) ".$order;
- }
-
- public function posts_where_filter_default( $where ) {
- global $current_user;
- $manager = 0;
- if ( dwqa_current_user_can( 'edit_question' ) ) {
- $manager = 1;
- }
- $where .= " AND if ( post_status = 'private', if ( $manager = 1, 1, if ( post_author = $current_user->ID, 1, 0 ) ), 1 ) = 1";
- $where .= " AND if ( post_status = 'pending', if ( $manager = 1, 1, if ( post_author = $current_user->ID, 1, 0 ) ), 1 ) = 1";
- return $where;
- }
-
- // Filter post where
- public function posts_where( $where ) {
- global $wpdb, $dwqa_general_settings;
- $get_question_answered_query = "SELECT `dw_latest_answer_date`.question
- FROM `{$wpdb->posts}`,
- ( SELECT `{$wpdb->postmeta}`.meta_value as question, max( `{$wpdb->posts}`.post_date) as post_date
- FROM `{$wpdb->posts}`, `{$wpdb->postmeta}`
- WHERE `{$wpdb->posts}`.post_type = 'dwqa-answer'
- AND ( `{$wpdb->posts}`.post_status = 'publish'
- OR `{$wpdb->posts}`.post_status = 'private' )
- AND `{$wpdb->postmeta}`.post_id = `{$wpdb->posts}`.ID
- AND `{$wpdb->postmeta}`.meta_key = '_question'
- GROUP BY question ) AS dw_latest_answer_date,
- {$wpdb->users},
- {$wpdb->usermeta}
-
- WHERE `{$wpdb->posts}`.post_status = 'publish'
- AND `{$wpdb->posts}`.post_type = 'dwqa-answer'
- AND `{$wpdb->posts}`.post_date = `dw_latest_answer_date`.post_date
- AND `{$wpdb->users}`.ID = `{$wpdb->posts}`.post_author
- AND `{$wpdb->usermeta}`.user_id = `{$wpdb->users}`.ID
- AND `{$wpdb->usermeta}`.meta_key = '{$wpdb->prefix}capabilities'
- AND (
- `{$wpdb->usermeta}`.meta_value LIKE '%administrator%'
- OR `{$wpdb->usermeta}`.meta_value LIKE '%editor%'
- OR `{$wpdb->usermeta}`.meta_value LIKE '%author%'
- )";
-
- switch ( $this->filter['filter_plus'] ) {
- case 'overdue' :
- $overdue_time_frame = isset( $dwqa_general_settings['question-overdue-time-frame']) ? $dwqa_general_settings['question-overdue-time-frame'] : 2;
- $where .= " AND post_date < '" . date( 'Y-m-d H:i:s', strtotime( '-'.$overdue_time_frame.' days' ) ) . "'";
- case 'open':
- // answered
- $where .= ' AND ID NOT IN (' . $get_question_answered_query . ' )';
- break;
- case 'replied':
- // answered
- $where .= ' AND ID IN (' . $get_question_answered_query. ' )';
- break;
- case 'new-comment':
- if ( current_user_can( 'edit_posts' ) ) {
- $where .= " AND ID IN (
- SELECT `{$wpdb->postmeta}`.meta_value FROM
- `{$wpdb->comments}`
- JOIN
- ( SELECT `{$wpdb->comments}`.comment_ID, `{$wpdb->comments}`.comment_post_ID, max( `{$wpdb->comments}`.comment_date ) as comment_time FROM `{$wpdb->comments}`
- JOIN `{$wpdb->posts}` ON `{$wpdb->comments}`.comment_post_ID = `{$wpdb->posts}`.ID
- WHERE `{$wpdb->comments}`.comment_approved = 1 AND `{$wpdb->posts}`.post_type = 'dwqa-answer'
- GROUP BY `{$wpdb->comments}`.comment_post_ID ) as t1
- ON `{$wpdb->comments}`.comment_post_ID = t1.comment_post_ID AND `{$wpdb->comments}`.comment_date = t1.comment_time
- JOIN `{$wpdb->usermeta}` ON `{$wpdb->comments}`.user_id = `{$wpdb->usermeta}`.user_id
- JOIN `{$wpdb->postmeta}` ON `{$wpdb->postmeta}`.post_id = `{$wpdb->comments}`.comment_post_ID
- WHERE 1=1 AND `{$wpdb->usermeta}`.meta_key = '{$wpdb->prefix}capabilities'
- AND `{$wpdb->usermeta}`.meta_value NOT LIKE '%administrator%'
- AND `{$wpdb->usermeta}`.meta_value NOT LIKE '%editor%'
- AND `{$wpdb->usermeta}`.meta_value NOT LIKE '%author%'
- AND `{$wpdb->postmeta}`.meta_key = '_question'
- ) ";
- }
- # code...
- break;
- }
-
- return $where;
- }
-
- public function where_title( $where ){
- if ( isset( $_POST['title'] ) ) {
- $where .= " AND post_title LIKE '%".preg_quote( sanitize_text_field( $_POST['title'] ) )."%'";
- }
- return $where;
- }
-
- public function posts_where_suggest( $where ) {
- global $current_search;
- $first = true;
- $s = explode( ' ', $current_search );
- if ( count( $s ) > 0 ) {
- $where .= ' AND (';
- foreach ( $s as $w ) {
- if ( ! $first ) {
- $where .= ' OR ';
- }
- $where .= "post_title REGEXP '".preg_quote( $w )."'";
- $first = false;
- }
- $where .= ' ) ';
- }
- return $where;
- }
-
- public function auto_suggest_for_seach(){
- if ( ! isset( $_POST['nonce']) ) {
- wp_send_json_error( array( array(
- 'error' => 'sercurity',
- 'message' => __( 'Are you cheating huh?', 'dwqa' )
- ) ) );
- }
- check_ajax_referer( '_dwqa_filter_nonce', 'nonce' );
-
- if ( ! isset( $_POST['title'] ) ) {
- wp_send_json_error( array( array(
- 'error' => 'empty title',
- 'message' => __( 'Search query is empty', 'dwqa' ),
- ) ) );
- }
-
- $status = 'publish';
- if ( is_user_logged_in() ) {
- $status = array( 'publish', 'private' );
- }
-
- $search = sanitize_text_field( $_POST['title'] );
- $args_query = array(
- 'post_type' => 'dwqa-question',
- 'posts_per_page' => 6,
- 'post_status' => $status,
- );
- preg_match_all( '/#\S*\w/i', $search, $matches );
- if ( $matches && is_array( $matches ) && count( $matches ) > 0 && count( $matches[0] ) > 0 ) {
- $args_query['tax_query'][] = array(
- 'taxonomy' => 'dwqa-question_tag',
- 'field' => 'slug',
- 'terms' => $matches[0],
- 'operator' => 'IN',
- );
- $search = preg_replace( '/#\S*\w/i', '', $search );
- }
- $args_query['s'] = $search;
- $query = new WP_Query( $args_query );
- if ( ! $query->have_posts() ) {
- global $current_search;
- $current_search = $search;
- add_filter( 'posts_where' , array( $this, 'posts_where_suggest' ) );
- unset( $args_query['s'] );
- $query = new WP_Query( $args_query );
- remove_filter( 'posts_where' , array( $this, 'posts_where_suggest') );
- }
- $results = array();
- if ( $query->have_posts() ) {
- $html = '';
- while ( $query->have_posts() ) {
- $query->the_post();
- $results[] = array(
- 'title' => get_post_field( 'post_title', get_the_ID() ),
- 'url' => get_permalink( get_the_ID() )
- );
- }
- wp_reset_query();
- wp_send_json_success( $results );
- } else {
- wp_reset_query();
- wp_send_json_error( array( array( 'error' => 'not found', 'message' => __( 'Search query is empty', 'dwqa' ) ) ) );
- }
- }
-
- public function prepare_archive_posts() {
+ public function prepare_archive_posts( $args ) {
global $wp_query,$dwqa_general_settings;
$posts_per_page = isset( $dwqa_general_settings['posts-per-page'] ) ? $dwqa_general_settings['posts-per-page'] : 5;
$user = isset( $_GET['user'] ) && !empty( $_GET['user'] ) ? urldecode( $_GET['user'] ) : false;
- $filter = isset( $_GET['filter'] ) && !empty( $_GET['filter'] ) ? $_GET['filter'] : 'all';
- $search_text = isset( $_GET['qs'] ) ? $_GET['qs'] : false;
- $sort = isset( $_GET['sort'] ) ? $_GET['sort'] : '';
+ $filter = isset( $_GET['filter'] ) && !empty( $_GET['filter'] ) ? sanitize_text_field( $_GET['filter'] ) : 'all';
+ $search_text = isset( $_GET['qs'] ) ? sanitize_text_field( $_GET['qs'] ) : false;
+ $sort = isset( $_GET['sort'] ) ? sanitize_text_field( $_GET['sort'] ) : '';
$query = array(
'post_type' => 'dwqa-question',
'posts_per_page' => $posts_per_page,
- 'orderby' => 'modified',
+ 'orderby' => 'modified'
);
$page_text = dwqa_is_front_page() ? 'page' : 'paged';
$paged = get_query_var( $page_text );
@@ -527,8 +44,7 @@ public function prepare_archive_posts() {
// filter by user
if ( $user ) {
- $user = get_user_by( 'login', $user );
- $query['author'] = $user->ID;
+ $query['author_name'] = esc_html( $user );
}
@@ -571,7 +87,7 @@ public function prepare_archive_posts() {
case 'closed':
$query['meta_query'][] = array(
'key' => '_dwqa_status',
- 'value' => array( 'closed' ),
+ 'value' => array( 'closed', 'close' ),
'compare' => 'IN',
);
break;
@@ -610,7 +126,7 @@ public function prepare_archive_posts() {
// search
if ( $search_text ) {
$search = sanitize_text_field( $search_text );
- preg_match_all( '/#\S*\w/i', $search_text, $matches );
+ preg_match_all( '/#\S*\w/i', $search, $matches );
if ( $matches && is_array( $matches ) && count( $matches ) > 0 && count( $matches[0] ) > 0 ) {
$query['tax_query'][] = array(
'taxonomy' => 'dwqa-question_tag',
@@ -621,86 +137,94 @@ public function prepare_archive_posts() {
$search = preg_replace( '/#\S*\w/i', '', $search );
}
- $query['s'] = $search;
+ $query['search_question_title'] = $search;
}
$sticky_questions = get_option( 'dwqa_sticky_questions' );
- // exclude sticky question
- if ( $sticky_questions && 'all' == $filter && !$sort && !$search_text ) {
- $query['post__not_in'] = $sticky_questions;
- }
-
if ( is_user_logged_in() ) {
- $query['post_status'] = array( 'publish', 'private', 'pending' );
+ $query['post_status'] = array( 'publish', 'private' );
}
- $wp_query->dwqa_questions = new WP_Query( $query );
- }
+ $query = wp_parse_args( $args, $query );
- public function sticky_question() {
- global $wp_query;
- $sticky_questions = get_option( 'dwqa_sticky_questions' );
+ $query = apply_filters( 'dwqa_prepare_archive_posts', $query );
- $user = isset( $_GET['user'] ) && !empty( $_GET['user'] ) ? urldecode( $_GET['user'] ) : false;
- $filter = isset( $_GET['filter'] ) && !empty( $_GET['filter'] ) ? $_GET['filter'] : 'all';
- $search_text = isset( $_GET['qs'] ) ? $_GET['qs'] : false;
- $sort = isset( $_GET['sort'] ) ? $_GET['sort'] : '';
+ // $wp_query->dwqa_questions = new WP_Query( $query );
- $cat = get_query_var( 'dwqa-question_category' ) ? get_query_var( 'dwqa-question_category' ) : false;
- $tag = get_query_var( 'dwqa-question_tag' ) ? get_query_var( 'dwqa-question_tag' ) : false;
+ if(isset($query['search_question_title']) && $query['search_question_title'] != ''){
+
+ add_filter( 'posts_where', array($this, 'questions_where'), 10, 1 );
+ $wp_query->dwqa_questions = new WP_Query( $query );
+ remove_filter( 'posts_where', array($this, 'questions_where'), 10, 1 );
+ }else{
+ $wp_query->dwqa_questions = new WP_Query( $query );
+ }
+
+ // sticky question
+ $sticky_questions = get_option( 'dwqa_sticky_questions' );
+ if ( !empty( $sticky_questions ) && 'all' == $filter && ! $sort && !$search_text && $query['paged'] == 1 ) {
- if ( $sticky_questions && 'all' == $filter && !$search_text && !$sort ) {
if ( $cat ) {
foreach( $sticky_questions as $key => $id ) {
$terms = wp_get_post_terms( $id, 'dwqa-question_category' );
-
if ( empty( $terms ) || $cat !== $terms[0]->slug ) {
unset( $sticky_questions[ $key ] );
}
}
-
- $args['tax_query'][] = array(
- 'taxonomy' => 'dwqa-question_category',
- 'terms' => $cat,
- 'field' => 'slug'
- );
}
if ( $tag ) {
foreach( $sticky_questions as $key => $id ) {
$terms = wp_get_post_terms( $id, 'dwqa-question_tag' );
-
if ( empty( $terms ) || $tag !== $terms[0]->slug ) {
unset( $sticky_questions[ $key ] );
}
}
-
- $args['tax_query'][] = array(
- 'taxonomy' => 'dwqa-question_category',
- 'terms' => $cat,
- 'field' => 'slug'
- );
}
if ( $user ) {
- $user = get_user_by( 'login', $user );
foreach( $sticky_questions as $key => $id ) {
- if ( $user->data->ID !== get_post_field( 'post_author', $id ) ) {
+ if ( $user->ID !== get_post_field( 'post_author', $id ) ) {
unset( $sticky_questions[ $key ] );
}
}
}
-
- $args = array(
- 'posts_per_page' => 40,
- 'post_type' => 'dwqa-question',
- 'post__in' => $sticky_questions,
- );
+
+ if ( !is_array( $sticky_questions ) ) {
+ $sticky_questions = array( $sticky_questions );
+ }
+ $num_posts = count( $wp_query->dwqa_questions->posts );
+ $stickies_offset = 0;
+
+ for ( $i = 0; $i < $num_posts; $i++ ) {
+ if ( in_array( $wp_query->dwqa_questions->posts[ $i ]->ID, $sticky_questions ) ) {
+ $sticky_post = $wp_query->dwqa_questions->posts[$i];
+
+ array_splice( $wp_query->dwqa_questions->posts, $i, 1 );
+ array_splice( $wp_query->dwqa_questions->posts, $stickies_offset, 0, array( $sticky_post ) );
+
+ $stickies_offset++;
+
+ $offset = array_search( $sticky_post->ID, $sticky_questions );
+ unset( $sticky_questions[$offset] );
+ }
+ }
if ( !empty( $sticky_questions ) ) {
- $wp_query->dwqa_question_stickies = new WP_Query( $args );
+ $stickies = get_posts( array(
+ 'post__in' => $sticky_questions,
+ 'post_type' => 'dwqa-question',
+ 'post_status' => 'publish',
+ 'nopaging' => true
+ ) );
+
+ foreach( $stickies as $sticky_post ) {
+ array_splice( $wp_query->dwqa_questions->posts, $stickies_offset, 0, array( $sticky_post ) );
+ $stickies_offset++;
+ }
}
+ $wp_query->dwqa_questions->post_count = count( $wp_query->dwqa_questions->posts );
}
}
@@ -710,60 +234,108 @@ public function after_archive_posts() {
}
public function prepare_answers( $posts, $query ) {
- global $dwqa;
- $query->test = 'rambu';
+ global $dwqa, $dwqa_general_settings;
- if ( is_main_query() && $query->is_single() && $query->query_vars['post_type'] == $dwqa->question->get_slug() ) {
+ if ( $query->is_single() && $query->query_vars['post_type'] == $dwqa->question->get_slug() ) {
$question = $posts[0];
$ans_cur_page = isset( $_GET['ans-page'] ) ? intval( $_GET['ans-page'] ) : 1;
+ $posts_per_page = isset( $dwqa_general_settings['answer-per-page'] ) ? $dwqa_general_settings['answer-per-page'] : 5;
// We will include the all answers of this question here;
$args = array(
'post_type' => 'dwqa-answer',
- 'posts_per_page' => get_option( 'posts_per_page' ),
'order' => 'ASC',
'paged' => $ans_cur_page,
- 'meta_query' => array(
- array(
- 'key' => '_question',
- 'value' => $question->ID
- ),
- ),
- 'post_status' => array( 'publish', 'private', 'draft' ),
- 'perm' => 'readable',
+ 'post_parent' => $question->ID,
+ 'post_status' => array( 'publish', 'private', 'draft' )
);
+
+ if ( isset( $dwqa_general_settings['show-all-answers-on-single-question-page'] ) && $dwqa_general_settings['show-all-answers-on-single-question-page'] ) {
+ $args['nopaging'] = true;
+ } else {
+ $args['posts_per_page'] = $posts_per_page;
+ }
+
+ $best_answer = dwqa_get_the_best_answer( $question->ID );
+
+ $args = apply_filters( 'dwqa_prepare_answers', $args );
+
$query->dwqa_answers = new WP_Query( $args );
- $query->dwqa_answers->best_answer = dwqa_get_the_best_answer( $question->ID );
+
+ // best answer
+ if ( $best_answer && !empty( $best_answer ) ) {
+ $sticky_posts = array( $best_answer );
+ $num_posts = count( $query->dwqa_answers->posts );
+ $best_offset = 0;
+
+ for( $i = 0; $i < $num_posts; $i++ ) {
+ if ( $query->dwqa_answers->posts[ $i ]->ID == $best_answer ) {
+ $sticky_post = $query->dwqa_answers->posts[$i];
+
+ array_splice($query->dwqa_answers->posts, $i, 1);
+
+ array_splice($query->dwqa_answers->posts, $best_offset, 0, array($sticky_post));
+
+ $best_offset++;
+
+ $offset = array_search($sticky_post->ID, $sticky_posts);
+ unset( $sticky_posts[$offset] );
+ }
+ }
+
+ if ( !empty($sticky_posts) ) {
+ $stickies = get_posts( array(
+ 'post__in' => $sticky_posts,
+ 'post_type' => 'dwqa-answer',
+ 'post_status' => 'publish',
+ 'nopaging' => true
+ ) );
+
+ foreach ( $stickies as $sticky_post ) {
+ array_splice( $query->dwqa_answers->posts, $best_offset, 0, array( $sticky_post ) );
+ $best_offset++;
+ }
+ }
+ }
+ $query->dwqa_answers->post_count = count( $query->dwqa_answers->posts );
}
return $posts;
}
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';
- $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' ) );
-
- add_action( 'dwqa_before_questions_list', array( $this, 'prepare_archive_posts' ) );
+ add_action( 'bp_dwqa_before_questions_list', array( $this, 'prepare_archive_posts' ) );
add_action( 'dwqa_after_questions_list', array( $this, 'after_archive_posts' ) );
- add_action( 'dwqa_before_question_stickies', array( $this, 'sticky_question' ) );
add_action( 'dwqa_after_question_stickies', array( $this, 'after_archive_posts' ) );
//Prepare answers for single questions
add_action( 'the_posts', array( $this, 'prepare_answers' ), 10, 2 );
+ add_filter( 'parse_query', array( $this, 'dwqa_theme_fix_category_page' ) );
+ }
+
+ function dwqa_theme_fix_category_page( $query ) {
+ if ( isset( $query->query_vars['dwqa-question_tag'] ) || isset( $query->query_vars['dwqa-question_category'] ) ) {
+ $dwqa_options = get_option( 'dwqa_options', array() );
+ $query->query_vars['posts_per_page'] = isset( $dwqa_options['posts-per-page'] ) ? $dwqa_options['posts-per-page'] : 15;
+ }
+ return $query;
+ }
+
+ public function questions_where($where){
+ global $wpdb;
+ $search_text = isset( $_GET['qs'] ) ? sanitize_text_field( $_GET['qs'] ) : false;
+ $first = true;
+ $s = explode( ' ', $search_text );
+ if ( count( $s ) > 0 ) {
+ $where .= ' AND (';
+ foreach ( $s as $w ) {
+ if ( ! $first ) {
+ $where .= ' OR ';
+ }
+ $where .= "post_title REGEXP '".preg_quote( $w )."'";
+ $first = false;
+ }
+ $where .= ' ) ';
+ }
+ return $where;
}
}
?>
\ No newline at end of file
diff --git a/inc/Handle.php b/inc/Handle.php
index 75e0e0b9..b5f7b1b8 100644
--- a/inc/Handle.php
+++ b/inc/Handle.php
@@ -20,34 +20,43 @@ public function insert_answer() {
if ( ! isset( $_POST['dwqa-action'] ) || ! isset( $_POST['submit-answer'] ) ) {
return false;
}
-
- if ( 'add-answer' !== $_POST['dwqa-action'] ) {
+ // do_action( 'dwqa_add_answer', $answer_id, $question_id );
+ // die();
+ if ( 'add-answer' !== sanitize_text_field( $_POST['dwqa-action'] ) ) {
return false;
}
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( esc_html( $_POST['_wpnonce'] ), '_dwqa_add_new_answer' ) ) {
- dwqa_add_notice( __( '"Helllo", Are you cheating huh?.', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( '"Helllo", Are you cheating huh?.', 'dw-question-answer' ), 'error' );
}
- if ( $_POST['submit-answer'] == __( 'Delete draft', 'dwqa' ) ) {
+ if ( sanitize_text_field( $_POST['submit-answer'] ) == __( 'Delete draft', 'dw-question-answer' ) ) {
$draft = isset( $_POST['answer-id'] ) ? intval( $_POST['answer-id'] ) : 0;
if ( $draft )
wp_delete_post( $draft );
}
if ( empty( $_POST['answer-content'] ) ) {
- dwqa_add_notice( __( 'Answer content is empty', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( 'Answer content is empty', 'dw-question-answer' ), 'error' );
}
if ( empty( $_POST['question_id'] ) ) {
- dwqa_add_notice( __( 'Question is empty', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( 'Question is empty', 'dw-question-answer' ), 'error' );
}
if ( !dwqa_current_user_can( 'post_answer' ) ) {
- dwqa_add_notice( __( 'You do not have permission to submit question.', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( 'You do not have permission to submit question.', 'dw-question-answer' ), 'error' );
+ }
+
+ if ( !is_user_logged_in() && ( empty( $_POST['user-email'] ) || !is_email( sanitize_email( $_POST['user-email'] ) ) ) ) {
+ dwqa_add_notice( __( 'Missing email information', 'dw-question-answer' ), 'error' );
+ }
+
+ if ( !is_user_logged_in() && ( empty( $_POST['user-name'] ) ) ) {
+ dwqa_add_notice( __( 'Missing name information', 'dw-question-answer' ), 'error' );
}
if ( !dwqa_valid_captcha( 'single-question' ) ) {
- dwqa_add_notice( __( 'Captcha is not correct', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( 'Captcha is not correct', 'dw-question-answer' ), 'error' );
}
$user_id = 0;
@@ -59,11 +68,14 @@ public function insert_answer() {
if ( isset( $_POST['user-email'] ) && is_email( $_POST['user-email'] ) ) {
$post_author_email = sanitize_email( $_POST['user-email'] );
}
+ if ( isset( $_POST['user-name'] ) && !empty( $_POST['user-name'] ) ) {
+ $post_author_name = sanitize_text_field( $_POST['user-name'] );
+ }
}
$question_id = intval( $_POST['question_id'] );
- $answer_title = __( 'Answer for ', 'dwqa' ) . get_post_field( 'post_title', $question_id );
+ $answer_title = __( 'Answer for ', 'dw-question-answer' ) . get_post_field( 'post_title', $question_id );
$answ_content = apply_filters( 'dwqa_prepare_answer_content', $_POST['answer-content'] );
$answers = array(
@@ -75,9 +87,9 @@ public function insert_answer() {
'post_parent' => $question_id,
);
- $answers['post_status'] = isset( $_POST['save-draft'] )
- ? 'draft'
- : ( isset( $_POST['dwqa-status'] ) && $_POST['dwqa-status'] ? $_POST['dwqa-status'] : 'publish' );
+ $answers['post_status'] = isset( $_POST['save-draft'] )
+ ? 'draft'
+ : ( isset( $_POST['dwqa-status'] ) && $_POST['dwqa-status'] ? sanitize_text_field( $_POST['dwqa-status'] ) : 'publish' );
do_action( 'dwqa_prepare_add_answer' );
@@ -85,6 +97,8 @@ public function insert_answer() {
return false;
}
+ $answers = apply_filters( 'dwqa_insert_answer_args', $answers );
+
$answer_id = wp_insert_post( $answers );
if ( !is_wp_error( $answer_id ) ) {
@@ -95,7 +109,6 @@ public function insert_answer() {
$answer_count = get_post_meta( $question_id, '_dwqa_answers_count', true );
update_post_meta( $question_id, '_dwqa_answers_count', (int) $answer_count + 1 );
}
- update_post_meta( $answer_id, '_question', $question_id );
if ( $is_anonymous ) {
update_post_meta( $answer_id, '_dwqa_is_anonymous', true );
@@ -103,11 +116,19 @@ public function insert_answer() {
if ( isset( $post_author_email ) && is_email( $post_author_email ) ) {
update_post_meta( $answer_id, '_dwqa_anonymous_email', $post_author_email );
}
+
+ if ( isset( $post_author_name ) && !empty( $post_author_name ) ) {
+ update_post_meta( $answer_id, '_dwqa_anonymous_name', $post_author_name );
+ }
} else {
- add_post_meta( $question_id, '_dwqa_followers', get_current_user_id() );
+ if ( !dwqa_is_followed( $question_id, get_current_user_id() ) ) {
+ add_post_meta( $question_id, '_dwqa_followers', get_current_user_id() );
+ }
}
do_action( 'dwqa_add_answer', $answer_id, $question_id );
+ $this->update_modified_date( $question_id , current_time( 'timestamp', 0 ), current_time( 'timestamp', 1 ) );
+
exit( wp_redirect( get_permalink( $question_id ) ) );
} else {
dwqa_add_wp_error_message( $answer_id );
@@ -117,29 +138,29 @@ public function insert_answer() {
public function update_answer() {
if ( isset( $_POST['dwqa-edit-answer-submit'] ) ) {
if ( !dwqa_current_user_can( 'edit_answer' ) ) {
- dwqa_add_notice( __( "You do not have permission to edit answer.", 'dwqa' ), 'error' );
+ dwqa_add_notice( __( "You do not have permission to edit answer.", 'dw-question-answer' ), 'error' );
}
if ( !isset( $_POST['_wpnonce'] ) && !wp_verify_nonce( esc_html( $_POST['_wpnonce'] ), '_dwqa_edit_answer' ) ) {
- dwqa_add_notice( __( 'Hello, Are you cheating huh?', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( 'Hello, Are you cheating huh?', 'dw-question-answer' ), 'error' );
}
$answer_content = apply_filters( 'dwqa_prepare_edit_answer_content', $_POST['answer_content'] );
if ( empty( $answer_content ) ) {
- dwqa_add_notice( __( 'You must enter a valid answer content.', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( 'You must enter a valid answer content.', 'dw-question-answer' ), 'error' );
}
- $answer_id = isset( $_POST['answer_id'] ) ? $_POST['answer_id'] : false;
+ $answer_id = isset( $_POST['answer_id'] ) ? intval( $_POST['answer_id'] ) : false;
if ( !$answer_id ) {
- dwqa_add_notice( __( 'Answer is missing.', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( 'Answer is missing.', 'dw-question-answer' ), 'error' );
}
if ( 'dwqa-answer' !== get_post_type( $answer_id ) ) {
- dwqa_add_notice( __( 'This post is not answer.', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( 'This post is not answer.', 'dw-question-answer' ), 'error' );
}
- do_action( 'dwqa_prepare_update_question', $answer_id );
+ do_action( 'dwqa_prepare_insert_question', $answer_id );
if ( dwqa_count_notices( 'error' ) > 0 ) {
return false;
@@ -156,7 +177,9 @@ public function update_answer() {
$old_post = get_post( $answer_id );
$new_post = get_post( $new_answer_id );
do_action( 'dwqa_update_answer', $new_answer_id, $old_post, $new_post );
- $question_id = get_post_meta( $new_answer_id, '_question', true );
+ $question_id = dwqa_get_post_parent_id( $new_answer_id );
+ $this->update_modified_date( $question_id , current_time( 'sql', 0 ), current_time( 'sql', 1 ) );
+
wp_safe_redirect( get_permalink( $question_id ) . '#answer-' . $new_answer_id );
} else {
dwqa_add_wp_error_message( $new_answer_id );
@@ -170,16 +193,16 @@ public function insert_comment() {
global $current_user;
if ( isset( $_POST['comment-submit'] ) ) {
if ( ! dwqa_current_user_can( 'post_comment' ) ) {
- dwqa_add_notice( __( 'You can\'t post comment', 'dwqa' ), 'error', true );
+ dwqa_add_notice( __( 'You can\'t post comment', 'dw-question-answer' ), 'error', true );
}
if ( ! isset( $_POST['comment_post_ID'] ) ) {
- dwqa_add_notice( __( 'Missing post id.', 'dwqa' ), 'error', true );
+ dwqa_add_notice( __( 'Missing post id.', 'dw-question-answer' ), 'error', true );
}
$comment_content = isset( $_POST['comment'] ) ? $_POST['comment'] : '';
$comment_content = apply_filters( 'dwqa_pre_comment_content', $comment_content );
if ( empty( $comment_content ) ) {
- dwqa_add_notice( __( 'Please enter your comment content', 'dwqa' ), 'error', true );
+ dwqa_add_notice( __( 'Please enter your comment content', 'dw-question-answer' ), 'error', true );
}
$args = array(
@@ -194,26 +217,50 @@ public function insert_comment() {
$args['comment_author'] = $current_user->display_name;
} else {
if ( ! isset( $_POST['email'] ) || ! sanitize_email( $_POST['email'] ) ) {
- dwqa_add_notice( __( 'Missing email information', 'dwqa' ), 'error', true );
+ dwqa_add_notice( __( 'Missing email information', 'dw-question-answer' ), 'error', true );
+ }
+
+ if ( ! isset( $_POST['name'] ) || empty( $_POST['name'] ) ) {
+ dwqa_add_notice( __( 'Missing name information', 'dw-question-answer' ), 'error', true );
}
- $args['comment_author'] = isset( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : 'anonymous';
+ $args['comment_author'] = isset( $_POST['name'] ) ? sanitize_text_field( $_POST['name'] ) : 'Anonymous';
$args['comment_author_email'] = sanitize_email( $_POST['email'] );
$args['comment_author_url'] = isset( $_POST['url'] ) ? esc_url( $_POST['url'] ) : '';
$args['user_id'] = -1;
}
+
+ $question_id = absint( $_POST['comment_post_ID'] );
+ if ( 'dwqa-answer' == get_post_type( $question_id ) ) {
+ $question_id = dwqa_get_question_from_answer_id( $question_id );
+ }
+ $redirect_to = get_permalink( $question_id );
+
+ if ( isset( $_GET['ans-page'] ) ) {
+ $redirect_to = add_query_arg( 'ans-page', absint( $_GET['ans-page'] ), $redirect_to );
+ }
+
+
+
+
if ( dwqa_count_notices( 'error', true ) > 0 ) {
+ $redirect_to = apply_filters( 'dwqa_submit_comment_error_redirect', $redirect_to, $question_id);
+ exit(wp_safe_redirect( $redirect_to ));
return false;
}
+
+ $args = apply_filters( 'dwqa_insert_comment_args', $args );
- $comment_id = wp_insert_comment( $args );
+ $comment_id = wp_insert_comment( $args );
global $comment;
$comment = get_comment( $comment_id );
$client_id = isset( $_POST['clientId'] ) ? sanitize_text_field( $_POST['clientId'] ) : false;
do_action( 'dwqa_add_comment', $comment_id, $client_id );
+ $redirect_to = apply_filters( 'dwqa_submit_comment_success_redirect', $redirect_to, $question_id);
+ exit(wp_safe_redirect( $redirect_to ));
}
}
@@ -221,28 +268,28 @@ public function update_comment() {
global $post_submit_filter;
if ( isset( $_POST['dwqa-edit-comment-submit'] ) ) {
if ( ! isset( $_POST['comment_id']) ) {
- dwqa_add_notice( __( 'Comment is missing', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( 'Comment is missing', 'dw-question-answer' ), 'error' );
}
$comment_id = intval( $_POST['comment_id'] );
- $comment_content = isset( $_POST['comment_content'] ) ? esc_html( $_POST['comment_content'] ) : '';
+ $comment_content = isset( $_POST['comment_content'] ) ? $_POST['comment_content'] : '';
$comment_content = apply_filters( 'dwqa_pre_update_comment_content', $comment_content );
if ( ! isset( $_POST['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['_wpnonce'] ), '_dwqa_edit_comment' ) ) {
- dwqa_add_notice( __( 'Are you cheating huh?', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( 'Are you cheating huh?', 'dw-question-answer' ), 'error' );
}
- if ( !dwqa_current_user_can( 'You do not have permission to edit answer.' ) ) {
- dwqa_add_notice( __( 'You do not have permission to edit comment.', 'dwqa' ), 'error' );
+ if ( !dwqa_current_user_can( 'edit_comment', $comment_id ) ) {
+ dwqa_add_notice( __( 'You do not have permission to edit comment.', 'dw-question-answer' ), 'error' );
}
if ( strlen( $comment_content ) <= 0 || ! isset( $comment_id ) || ( int )$comment_id <= 0 ) {
- dwqa_add_notice( __( 'Comment content must not be empty.', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( 'Comment content must not be empty.', 'dw-question-answer' ), 'error' );
} else {
$commentarr = array(
'comment_ID' => $comment_id,
'comment_content' => $comment_content
);
-
+
$intval = wp_update_comment( $commentarr );
if ( !is_wp_error( $intval ) ) {
$comment = get_comment( $comment_id );
@@ -266,12 +313,22 @@ public function submit_question() {
if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( esc_html( $_POST['_wpnonce'] ), '_dwqa_submit_question' ) ) {
if ( $valid_captcha ) {
if ( empty( $_POST['question-title'] ) ) {
-
- // $dwqa_submit_question_errors->add( 'submit_question', 'You must enter a valid question title' );
- dwqa_add_notice( __( 'You must enter a valid question title.', 'error' ) );
+ dwqa_add_notice( __( 'You must enter a valid question title.', 'dw-question-answer' ), 'error' );
return false;
}
+ if ( !is_user_logged_in() ) {
+ if ( empty( $_POST['_dwqa_anonymous_email'] ) || !is_email( sanitize_email( $_POST['_dwqa_anonymous_email'] ) ) ) {
+ dwqa_add_notice( __( 'Missing email information', 'dw-question-answer' ), 'error' );
+ return false;
+ }
+
+ if ( empty( $_POST['_dwqa_anonymous_name'] ) ) {
+ dwqa_add_notice( __( 'Missing name information', 'dw-question-answer' ), 'error' );
+ return false;
+ }
+ }
+
$title = esc_html( $_POST['question-title'] );
$category = isset( $_POST['question-category'] ) ?
@@ -283,7 +340,7 @@ public function submit_question() {
$tags = isset( $_POST['question-tag'] ) ?
esc_html( $_POST['question-tag'] ): '';
- $content = isset( $_POST['question-content'] ) ? $_POST['question-content'] : '';
+ $content = isset( $_POST['question-content'] ) ? $_POST['question-content'] : '';
$content = apply_filters( 'dwqa_prepare_question_content', $content );
$user_id = 0;
@@ -292,7 +349,7 @@ public function submit_question() {
$user_id = get_current_user_id();
} else {
//$post_author_email = $_POST['user-email'];
- if ( isset( $_POST['login-type'] ) && $_POST['login-type'] == 'sign-in' ) {
+ if ( isset( $_POST['login-type'] ) && sanitize_text_field( $_POST['login-type'] ) == 'sign-in' ) {
$user = wp_signon( array(
'user_login' => isset( $_POST['user-name'] ) ? esc_html( $_POST['user-name'] ) : '',
'user_password' => isset( $_POST['user-password'] ) ? esc_html( $_POST['user-password'] ) : '',
@@ -307,7 +364,7 @@ public function submit_question() {
$dwqa_current_error = $user;
return false;
}
- } elseif ( isset( $_POST['login-type'] ) && $_POST['login-type'] == 'sign-up' ) {
+ } elseif ( isset( $_POST['login-type'] ) && sanitize_text_field( $_POST['login-type'] ) == 'sign-up' ) {
//Create new user
$users_can_register = get_option( 'users_can_register' );
if ( isset( $_POST['user-email'] ) && isset( $_POST['user-name-signup'] )
@@ -346,13 +403,13 @@ public function submit_question() {
} else {
$message = '';
if ( ! $users_can_register ) {
- $message .= __( 'User Registration was disabled.','dwqa' ).' ';
+ $message .= __( 'User Registration was disabled.','dw-question-answer' ).' ';
}
if ( isset( $_POST['user-name'] ) && email_exists( sanitize_email( $_POST['user-email'] ) ) ) {
- $message .= __( 'This email is already registered, please choose another one.','dwqa' ).' ';
+ $message .= __( 'This email is already registered, please choose another one.','dw-question-answer' ).' ';
}
if ( isset( $_POST['user-name'] ) && username_exists( esc_html( $_POST['user-name'] ) ) ) {
- $message .= __( 'This username is already registered. Please use another one.','dwqa' ).' ';
+ $message .= __( 'This username is already registered. Please use another one.','dw-question-answer' ).' ';
}
// $dwqa_current_error = new WP_Error( 'submit_question', $message );
dwqa_add_notice( $message, 'error' );
@@ -361,6 +418,7 @@ public function submit_question() {
} else {
$is_anonymous = true;
$question_author_email = isset( $_POST['_dwqa_anonymous_email'] ) && is_email( $_POST['_dwqa_anonymous_email'] ) ? sanitize_email( $_POST['_dwqa_anonymous_email'] ) : false;
+ $question_author_name = isset( $_POST['_dwqa_anonymous_name'] ) && !empty( $_POST['_dwqa_anonymous_name'] ) ? sanitize_text_field( $_POST['_dwqa_anonymous_name'] ) : false;
$user_id = 0;
}
}
@@ -390,31 +448,33 @@ public function submit_question() {
if ( apply_filters( 'dwqa-current-user-can-add-question', dwqa_current_user_can( 'post_question' ), $postarr ) ) {
$new_question = $this->insert_question( $postarr );
+ do_action('dwqa_after_insert_question',$new_question);
} else {
- //$dwqa_submit_question_errors->add( 'submit_question', __( 'You do not have permission to submit question.', 'dwqa' ) );
- dwqa_add_notice( __( 'You do not have permission to submit question.', 'dwqa' ), 'error' );
+ //$dwqa_submit_question_errors->add( 'submit_question', __( 'You do not have permission to submit question.', 'dw-question-answer' ) );
+ dwqa_add_notice( __( 'You do not have permission to submit question.', 'dw-question-answer' ), 'error' );
$new_question = $dwqa_submit_question_errors;
}
if ( dwqa_count_notices( 'error' ) == 0 ) {
if ( $is_anonymous ) {
update_post_meta( $new_question, '_dwqa_anonymous_email', $question_author_email );
+ update_post_meta( $new_question, '_dwqa_anonymous_name', $question_author_name );
update_post_meta( $new_question, '_dwqa_is_anonymous', true );
}
if ( isset( $dwqa_options['enable-review-question'] ) && $dwqa_options['enable-review-question'] && !current_user_can( 'manage_options' ) && $post_status != 'private' ) {
- dwqa_add_notice( __( 'Your question is waiting moderator.', 'dwqa' ), 'success' );
+ dwqa_add_notice( __( 'Your question is waiting moderator.', 'dw-question-answer' ), 'success' );
} else {
exit( wp_safe_redirect( get_permalink( $new_question ) ) );
}
}
} else {
- // $dwqa_submit_question_errors->add( 'submit_question', __( 'Captcha is not correct','dwqa' ) );
- dwqa_add_notice( __( 'Captcha is not correct', 'dwqa' ), 'error' );
+ // $dwqa_submit_question_errors->add( 'submit_question', __( 'Captcha is not correct','dw-question-answer' ) );
+ dwqa_add_notice( __( 'Captcha is not correct', 'dw-question-answer' ), 'error' );
}
} else {
- // $dwqa_submit_question_errors->add( 'submit_question', __( 'Are you cheating huh?','dwqa' ) );
- dwqa_add_notice( __( 'Are you cheating huh?', 'dwqa' ), 'error' );
+ // $dwqa_submit_question_errors->add( 'submit_question', __( 'Are you cheating huh?','dw-question-answer' ) );
+ dwqa_add_notice( __( 'Are you cheating huh?', 'dw-question-answer' ), 'error' );
}
//$dwqa_current_error = $dwqa_submit_question_errors;
}
@@ -425,22 +485,22 @@ public function update_question() {
if ( isset( $_POST['_wpnonce'] ) && wp_verify_nonce( esc_html( $_POST['_wpnonce'] ), '_dwqa_edit_question' ) ) {
if ( !dwqa_current_user_can( 'edit_question' ) ) {
- dwqa_add_notice( __( "You do not have permission to edit question", 'dwqa' ), 'error' );
+ dwqa_add_notice( __( "You do not have permission to edit question", 'dw-question-answer' ), 'error' );
}
- $question_title = apply_filters( 'dwqa_prepare_edit_question_title', $_POST['question_title'] );
+ $question_title = apply_filters( 'dwqa_prepare_edit_question_title', sanitize_text_field( $_POST['question_title'] ) );
if ( empty( $question_title ) ) {
- dwqa_add_notice( __( 'You must enter a valid question title.', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( 'You must enter a valid question title.', 'dw-question-answer' ), 'error' );
}
- $question_id = isset( $_POST['question_id'] ) ? $_POST['question_id'] : false;
+ $question_id = isset( $_POST['question_id'] ) ? sanitize_text_field( $_POST['question_id'] ) : false;
if ( !$question_id ) {
- dwqa_add_notice( __( 'Question is missing.', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( 'Question is missing.', 'dw-question-answer' ), 'error' );
}
if ( 'dwqa-question' !== get_post_type( $question_id ) ) {
- dwqa_add_notice( __( 'This post is not question.', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( 'This post is not question.', 'dw-question-answer' ), 'error' );
}
$question_content = apply_filters( 'dwqa_prepare_edit_question_content', $_POST['question_content'] );
@@ -479,7 +539,7 @@ public function update_question() {
return false;
}
} else {
- dwqa_add_notice( __( 'Hello, Are you cheating huh?', 'dwqa' ), 'error' );
+ dwqa_add_notice( __( 'Hello, Are you cheating huh?', 'dw-question-answer' ), 'error' );
return false;
}
exit(0);
@@ -503,6 +563,8 @@ public function insert_question( $args ) {
'post_title' => '',
'post_type' => 'dwqa-question',
) );
+
+ $args = apply_filters( 'dwqa_insert_question_args', $args );
$new_question = wp_insert_post( $args, true );
@@ -525,4 +587,17 @@ public function insert_question( $args ) {
}
return $new_question;
}
-}
\ No newline at end of file
+
+ function update_modified_date( $question_id, $modified_date, $modified_date_gmt ) {
+ $data = array(
+ 'ID' => $question_id,
+ 'post_modified' => $this->timeformat_convert( $modified_date ),
+ 'post_modified_gmt' => $this->timeformat_convert( $modified_date_gmt ),
+ );
+ wp_update_post( $data );
+ }
+
+ function timeformat_convert( $timestamp ) {
+ return date("Y-m-d H:i:s", $timestamp );
+ }
+}
diff --git a/inc/Helptab.php b/inc/Helptab.php
index 04d75709..b763c44e 100644
--- a/inc/Helptab.php
+++ b/inc/Helptab.php
@@ -31,8 +31,12 @@ public function get_current_posttype(){
return $current_screen->post_type;
//lastly check the post_type querystring
- elseif ( isset( $_REQUEST['post_type'] ) )
+ elseif ( isset( $_REQUEST['post_type'] ) ) {
+ //Some plugins set post_type to an array
+ if ( is_array( $_REQUEST['post_type'] ) )
+ return null;
return sanitize_key( $_REQUEST['post_type'] );
+ }
}
private function create_tabs(){
@@ -40,24 +44,24 @@ private function create_tabs(){
// The assoc key represents the ID
// It is NOT allowed to contain spaces
'dwqa-overview' => array(
- 'title' => __( 'Overview', 'dwqa' ),
- 'content' => ''.__( 'DW Question Answer Plugin', 'dwqa' ).' '.
- ''.__( 'DW Question Answer is a WordPress Plugin which helps you build a Question & Answer system on your WordPress sites. The plugin is easy to install and set up. Let start building up your community with this WordPress question & answer system.', 'dwqa' ).'
'.$this->help_tab_designwall()
+ 'title' => __( 'Overview', 'dw-question-answer' ),
+ 'content' => ''.__( 'DW Question Answer Plugin', 'dw-question-answer' ).' '.
+ ''.__( 'DW Question Answer is a WordPress Plugin which helps you build a Question & Answer system on your WordPress sites. The plugin is easy to install and set up. Let start building up your community with this WordPress question & answer system.', 'dw-question-answer' ).'
'.$this->help_tab_designwall()
),
'dwqa-guide-add-list-page' => array(
- 'title' => __( 'Setup Question List Page', 'dwqa' ),
+ 'title' => __( 'Setup Question List Page', 'dw-question-answer' ),
'content' => $this->help_tab_guide_make_question_list_page()
),
'dwqa-guide-add-ask-page' => array(
- 'title' => __( 'Setup Ask Question Page', 'dwqa' ),
+ 'title' => __( 'Setup Ask Question Page', 'dw-question-answer' ),
'content' => $this->help_tab_guide_make_ask_question_page()
),
'dwqa-guide-shortcode' => array(
- 'title' => __( 'Shortcode', 'dwqa' ),
+ 'title' => __( 'Shortcode', 'dw-question-answer' ),
'content' => $this->help_tab_guide_shortcode()
),
'dwqa-guide-style-integration' => array(
- 'title' => __( 'Style integration', 'dwqa' ),
+ 'title' => __( 'Style integration', 'dw-question-answer' ),
'content' => $this->help_tab_guide_style_integration()
)
);
@@ -146,7 +150,7 @@ private function help_tab_guide_style_integration() {
ob_start();
?>
Style integration
- The DW Question & Answer plugin can work well on any WordPress site, however, in order to get the plugin fit well in the style, we will need to work on CSS a bit.
+ The DW Question & Answer plugin can work well on any WordPress site, however, in order to get the plugin fit well in the style, we will need to work on CSS a bit.
tabs as $id => $data ) {
get_current_screen()->add_help_tab( array(
'id' => $id,
- 'title' => __( $data['title'], 'dwqa' ),
+ 'title' => __( $data['title'], 'dw-question-answer' ),
// Use the content only if you want to add something
// static on every help tab. Example: Another title inside the tab
'content' => $data['content'],
@@ -176,4 +180,4 @@ public function add_tabs() {
}
-?>
\ No newline at end of file
+?>
diff --git a/inc/Metaboxes.php b/inc/Metaboxes.php
index 6257d6a4..a47052c1 100644
--- a/inc/Metaboxes.php
+++ b/inc/Metaboxes.php
@@ -10,23 +10,23 @@ function dwqa_question_status_box_html( $post ){
?>
-
+
- value="open">
- value="pending">
- value="resolved">
- value="re-open">
- value="closed">
+ value="open">
+ value="pending">
+ value="resolved">
+ value="re-open">
+ value="closed">
-
+
- ID, $sticky_questions ), true ); ?> type="checkbox" name="dwqa-question-sticky" id="dwqa-question-sticky" value="1" >
+ ID, $sticky_questions ), true ); ?> type="checkbox" name="dwqa-question-sticky" id="dwqa-question-sticky" value="1" >
get_admin_email();
@@ -24,31 +53,12 @@ public function new_question_notify( $question_id, $user_id ) {
$subject = get_option( 'dwqa_subscrible_new_question_email_subject' );
if ( ! $subject ) {
- $subject = __( 'A new question was posted on {site_name}', 'dwqa' );
+ $subject = __( 'A new question was posted on {site_name}', 'dw-question-answer' );
}
$subject = str_replace( '{site_name}', get_bloginfo( 'name' ), $subject );
$subject = str_replace( '{question_title}', $question->post_title, $subject );
$subject = str_replace( '{question_id}', $question->ID, $subject );
$subject = str_replace( '{username}', get_the_author_meta( 'display_name', $user_id ), $subject );
- // To send HTML mail, the Content-type header must be set
- $headers = 'MIME-Version: 1.0' . "\r\n";
- $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
- //From email
- $from_email = get_option( 'dwqa_subscrible_from_address' );
- if ( $from_email ) {
- $headers .= 'From: ' . $from_email . "\r\n";
- }
-
- //Cc email
- $cc_address = get_option( 'dwqa_subscrible_cc_address' );
- if ( $cc_address ) {
- $headers .= 'Cc: ' . $cc_address . "\r\n";
- }
- //Bcc email
- $bcc_address = get_option( 'dwqa_subscrible_bcc_address' );
- if ( $bcc_address ) {
- $headers .= 'Bcc: ' . $bcc_address . "\r\n";
- }
$message = dwqa_get_mail_template( 'dwqa_subscrible_new_question_email', 'new-question' );
if ( ! $message ) {
@@ -62,7 +72,7 @@ public function new_question_notify( $question_id, $user_id ) {
}
//sender
$message = str_replace( '{user_avatar}', get_avatar( $user_id, '60' ), $message );
- $message = str_replace( '{user_link}', get_author_posts_url( $user_id ), $message );
+ $message = str_replace( '{user_link}', dwqa_get_author_link( $user_id ), $message );
$message = str_replace( '{username}', get_the_author_meta( 'display_name', $user_id ), $message );
//question
$message = str_replace( '{question_link}', get_permalink( $question_id ), $message );
@@ -76,158 +86,193 @@ public function new_question_notify( $question_id, $user_id ) {
$message = str_replace( '{site_description}', get_bloginfo( 'description' ), $message );
$message = str_replace( '{site_url}', site_url(), $message );
+ $headers = array(
+ "From: {$this->get_from_name()} <{$this->get_from_address()}>",
+ "Reply-To: {$this->get_from_address()}",
+ "Content-Type: {$this->get_content_type()}; charset=utf-8"
+ );
+
// start send out email
- wp_mail( $admin_email, $subject, $message, $headers );
+ foreach( $admin_email as $to ) {
+ if ( is_email( $to ) )
+ $sended = $this->send( sanitize_email( $to ), $subject, $message, $headers );
+ }
}
- public function new_answer_nofity( $answer_id ) {
- $enabled = get_option( 'dwqa_subscrible_enable_new_answer_notification', 1 );
- if ( ! $enabled ) {
+ public function new_answer_notify( $answer_id, $question_id ) {
+ // print_r( $answer_id ); die;
+ if ( 'dwqa-answer' !== get_post_type( $answer_id ) ) {
return false;
}
- //Admin email
- $admin_email = get_bloginfo( 'admin_email' );;
- $enable_send_copy = get_option( 'dwqa_subscrible_send_copy_to_admin' );
-
- $question_id = get_post_meta( $answer_id, '_question', true );
- $question = get_post( $question_id );
- $answer = get_post( $answer_id );
- if ( $answer->post_status != 'publish' && $answer->post_status != 'private' ) {
+ if ( 'dwqa-question' !== get_post_type( $question_id ) ) {
return false;
}
- //Send email alert for author of question about this answer
- if ( dwqa_is_anonymous( $question_id ) ) {
- $email = get_post_meta( $question_id, '_dwqa_anonymous_email', true );
- if ( ! is_email( $email ) ) {
- return false;
- }
- } else {
- // if user is not the author of question/answer, add user to followers list
- if ( $question->post_author != $answer->post_author ) {
- if ( ! dwqa_is_followed( $question_id, $answer->post_author ) ) {
- add_post_meta( $question_id, '_dwqa_followers', $answer->post_author );
- }
- }
- $email = get_the_author_meta( 'user_email', $question->post_author );
+ // default value
+ $site_name = get_bloginfo( 'name' );
+ $question_title = get_the_title( $question_id );
+ $answer_content = get_post_field( 'post_content', $answer_id );
+ $question_link = get_permalink( $question_id );
+ $answer_link = trailingslashit( $question_link ) . '#answer-' . $answer_id;
+ $site_description = get_bloginfo( 'description' );
+ $site_url = site_url();
+ $enable_send_copy = get_option( 'dwqa_subscrible_send_copy_to_admin' );
+ $admin_email = $this->get_admin_email('answer');
+ $site_logo = get_option( 'dwqa_subscrible_email_logo', '' );
+ $site_logo = $site_logo ? ' ' : '';
+
+ // for answer
+ $answer_is_anonymous = dwqa_is_anonymous( $answer_id );
+ if ( $answer_is_anonymous ) {
+ $user_answer_id = 0;
+ $user_answer_display_name = get_post_meta( $answer_id, '_dwqa_anonymous_name', true );
+ $user_answer_display_name = $user_answer_display_name ? sanitize_text_field( $user_answer_display_name ) : __( 'Anonymous', 'dw-question-answer' );
+ $user_answer_email = get_post_meta( $answer_id, '_dwqa_anonymous_email', true );
+ $user_answer_email = $user_answer_email ? sanitize_email( $user_answer_email ) : false;
+ } else {
+ $user_answer_id = get_post_field( 'post_author', $answer_id );
+ $user_answer_display_name = get_the_author_meta( 'display_name', $user_answer_id );
+ $user_answer_email = get_the_author_meta( 'user_email', $user_answer_id );
}
- $subject = get_option( 'dwqa_subscrible_new_answer_email_subject' );
- if ( ! $subject ) {
- $subject = __( 'A new answer for "{question_title}" was posted on {site_name}', 'dwqa' );
+ if ( $user_answer_email ) {
+ $user_answer_avatar = get_avatar( $user_answer_email, 60 );
+ } else {
+ $user_answer_avatar = get_avatar( $user_answer_id, 60 );
}
- $subject = str_replace( '{site_name}', get_bloginfo( 'name' ), $subject );
- $subject = str_replace( '{question_title}', $question->post_title, $subject );
- $subject = str_replace( '{question_id}', $question->ID, $subject );
-
- // To send HTML mail, the Content-type header must be set
- $headers = 'MIME-Version: 1.0' . "\r\n";
- $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
-
- //From email
- $from_email = get_option( 'dwqa_subscrible_from_address' );
- if ( $from_email ) {
- $headers .= 'From: ' . $from_email . "\r\n";
+
+ // for question
+ $question_is_anonymous = dwqa_is_anonymous( $question_id );
+ if ( $question_is_anonymous ) {
+ $user_question_id = 0;
+ $user_question_display_name = get_post_meta( $question_id, '_dwqa_anonymous_name', true );
+ $user_question_display_name = $user_question_display_name ? sanitize_text_field( $user_question_display_name ) : __( 'Anonymous', 'dw-question-answer' );
+ $user_question_email = get_post_meta( $question_id, '_dwqa_anonymous_email', true );
+ $user_question_email = $user_question_email ? sanitize_email( $user_question_email ) : false;
+ } else {
+ $user_question_id = get_post_field( 'post_author', $question_id );
+ $user_question_display_name = get_the_author_meta( 'display_name', $user_question_id );
+ $user_question_email = get_the_author_meta( 'user_email', $user_question_id );
}
- $message = dwqa_get_mail_template( 'dwqa_subscrible_new_answer_email', 'new-answer' );
- if ( ! $message ) {
- return false;
+ if ( $user_question_email ) {
+ $user_question_avatar = get_avatar( $user_question_email, 60 );
+ } else {
+ $user_question_avatar = get_avatar( $user_question_id, 60 );
}
- //Receiver
- $message = str_replace( '{question_author}', get_the_author_meta( 'display_name', $question->post_author ), $message );
- //Answer
- $answer = get_post( $answer_id );
-
- if ( dwqa_is_anonymous( $answer_id ) ) {
- $user_id = 0;
- $display_name = __( 'Anonymous', 'dwqa' );
- $avatar = get_avatar( $user_id, '60' );
- $answer_author = __( 'Anonymous', 'dwqa' );
- } else {
- $user_id = $answer->post_author;
- $display_name = get_the_author_meta( 'display_name', $user_id );
- $avatar = get_avatar( $user_id, '60' );
- $answer_author = ''.get_the_author_meta( 'display_name', $user_id ).' ';
+ // get all follower email lists
+ $followers = get_post_meta( $question_id, '_dwqa_followers' );
+ $followers_email = array();
+ if ( !empty( $followers ) && is_array( $followers ) ) {
+ foreach( $followers as $follower ) {
+ if ( is_numeric( $follower ) ) {
+ // prevent send to answer author and question author
+ if ( absint( $follower ) == $user_answer_id || absint( $follower ) == $user_question_id ) continue;
+ // get user email has registered
+ $followers_email[] = get_the_author_meta( 'user_email', $follower );
+ } else {
+ // prevent send to question author and answer author
+ if ( sanitize_email( $user_answer_email ) == sanitize_email( $follower ) || sanitize_email( $user_question_email ) == sanitize_email( $follower ) ) continue;
+ // get anonymous email
+ $followers_email[] = sanitize_email( $follower );
+ }
+ }
}
+ // start send to followers
+ $answer_notify_enabled = get_option( 'dwqa_subscrible_enable_new_answer_followers_notification', 1 );
+ if ( $answer_notify_enabled && !empty( $followers_email ) && is_array( $followers_email ) && 'private' !== get_post_status( $answer_id ) ) {
+ $subject = get_option( 'dwqa_subscrible_new_answer_followers_email_subject', __( '[{site_name}] You have a new answer for your followed question', 'dw-question-answer' ) );
+ $subject = str_replace( '{site_name}', esc_html( $site_name ), $subject );
+ $subject = str_replace( '{question_title}', $question_title, $subject );
+ $subject = str_replace( '{answer_author}', esc_html( $user_answer_display_name ), $subject );
- $subject = str_replace( '{username}', $display_name, $subject );
- $subject = str_replace( '{answer_author}', $answer_author, $subject );
+ $message = dwqa_get_mail_template( 'dwqa_subscrible_new_answer_followers_email', 'new-answer-followers' );
+ $message = apply_filters( 'dwqa_get_new_answer_email_to_followers_message', $message, $answer_id, $question_id );
- $message = str_replace( '{answer_avatar}', $avatar, $message );
- $message = str_replace( '{answer_author}', $answer_author, $message );
- $message = str_replace( '{question_link}', get_permalink( $question->ID ), $message );
- $message = str_replace( '{answer_link}', get_permalink( $question->ID ) . '#answer-' . $answer_id, $message );
- $message = str_replace( '{question_title}', $question->post_title, $message );
- $message = str_replace( '{answer_content}', $answer->post_content, $message );
- // logo replace
- $logo = get_option( 'dwqa_subscrible_email_logo', '' );
- $logo = $logo ? ' ' : '';
- $message = str_replace( '{site_logo}', $logo, $message );
- $message = str_replace( '{site_name}', get_bloginfo( 'name' ), $message );
- $message = str_replace( '{site_description}', get_bloginfo( 'description' ), $message );
- $message = str_replace( '{site_url}', site_url(), $message );
+ if ( !$message ) {
+ return false;
+ }
- $enable_notify = get_option( 'dwqa_subscrible_enable_new_answer_followers_notification', true );
-
- if ( $enable_notify ) {
- $followers = get_post_meta( $question_id, '_dwqa_followers' );
+ $message = str_replace( 'Howdy {follower},', '', $message );
+ $message = str_replace( '{answer_author}', esc_html( $user_answer_display_name ), $message );
+ $message = str_replace( '{question_link}', esc_url( $question_link ), $message );
+ $message = str_replace( '{answer_link}', esc_url( $answer_link ), $message );
+ $message = str_replace( '{question_title}', $question_title, $message );
+ $message = str_replace( '{answer_content}', wp_kses_post( $answer_content ), $message );
+ $message = str_replace( '{answer_avatar}', $user_answer_avatar, $message );
+ $message = str_replace( '{site_logo}', $site_logo, $message );
+ $message = str_replace( '{site_name}', esc_html( $site_name ), $message );
+ $message = str_replace( '{site_description}', esc_html( $site_description ), $message );
+ $message = str_replace( '{site_url}', esc_url( $site_url ), $message );
+
+ if ( $enable_send_copy ) {
+ $followers_email = array_merge( $followers_email, $admin_email );
+ }
+ // make sure it is not duplicate email
+ $followers_email = array_unique( $followers_email );
- $answer_email = get_the_author_meta( 'user_email', $answer->post_author );
- if ( ! empty( $followers ) ) {
- $question_link = get_permalink( $question->ID );
+ $headers = array(
+ "From: {$this->get_from_name()} <{$this->get_from_address()}>",
+ "Content-Type: {$this->get_content_type()}; charset=utf-8"
+ );
- $follow_subject = get_option( 'dwqa_subscrible_new_answer_followers_email_subject' );
- if ( ! $follow_subject ) {
- $follow_subject = __( 'You have a new answer for your followed question','dwqa' );
- }
- $follow_subject = str_replace( '{site_name}', get_bloginfo( 'name' ), $follow_subject );
- $follow_subject = str_replace( '{question_title}', $question->post_title, $follow_subject );
- $follow_subject = str_replace( '{question_id}', $question->ID, $follow_subject );
- $follow_subject = str_replace( '{username}', $display_name, $follow_subject );
- $follow_subject = str_replace( '{answer_author}', $answer_author, $follow_subject );
+ foreach( $followers_email as $f_email ) {
+ $headers[] = "Bcc: " . $f_email;
+ }
- $message_to_follower = dwqa_get_mail_template( 'dwqa_subscrible_new_answer_followers_email', 'new-answer-followers' );
+ $sitename = strtolower( $_SERVER['SERVER_NAME'] );
+ if ( substr( $sitename, 0, 4 ) === 'www.' ) {
+ $sitename = substr( $sitename, 4 );
+ }
+ $no_reply = 'noreply@' . $sitename;
-
- $message_to_follower = str_replace( '{answer_avatar}', $avatar, $message_to_follower );
- $message_to_follower = str_replace( '{answer_author}', $answer_author, $message_to_follower );
- $message_to_follower = str_replace( '{question_link}', get_permalink( $question->ID ), $message_to_follower );
- $message_to_follower = str_replace( '{question_title}', $question->post_title, $message_to_follower );
- $message_to_follower = str_replace( '{answer_content}', $answer->post_content, $message_to_follower );
- $message_to_follower = str_replace( '{site_logo}', $logo, $message_to_follower );
- $message_to_follower = str_replace( '{site_name}', get_bloginfo( 'name' ), $message_to_follower );
- $message_to_follower = str_replace( '{site_description}', get_bloginfo( 'description' ), $message_to_follower );
- $message_to_follower = str_replace( '{site_url}', site_url(), $message_to_follower );
+ $sender = $this->send( $no_reply, $subject, $message, $headers );
+ }
- foreach ( $followers as $follower ) {
- $follower = intval( $follower );
- $user_data = get_userdata( $follower );
- if ( $user_data ) {
- $follow_email = $user_data->user_email;
- $follower_name = $user_data->display_name;
- if ( $follow_email && $follow_email != $email && $follow_email != $answer_email ) {
- //Send email to follower
- $message_to_each_follower = str_replace( '{follower}', $follower_name, $message_to_follower );
- wp_mail( $follow_email, $follow_subject, $message_to_each_follower, $headers );
- if ( $enable_send_copy && $follow_email != $admin_email ) {
- wp_mail( $admin_email, $follow_subject, $message_to_each_follower, $headers );
- }
- }
- }
- }
+ // start send to question author
+ $answer_notify_for_question_enabled = get_option( 'dwqa_subscrible_enable_new_answer_notification', 1 );
+ if ( $user_question_email && $answer_notify_for_question_enabled && absint( $user_answer_id ) !== absint( $user_question_id ) ) {
+ $subject = get_option( 'dwqa_subscrible_new_answer_email_subject', __( '[{site_name}] A new answer for "{question_title}" was posted on {site_name}', 'dw-question-answer' ) );
+ $subject = str_replace( '{site_name}', esc_html( $site_name ), $subject );
+ $subject = str_replace( '{question_title}', $question_title, $subject );
+ $subject = str_replace( '{question_id}', absint( $question_id ), $subject );
+ $subject = str_replace( '{username}', esc_html( $user_question_display_name ), $subject );
+ $subject = str_replace( '{answer_author}', esc_html( $user_answer_display_name ), $subject );
+
+ $message = dwqa_get_mail_template( 'dwqa_subscrible_new_answer_email', 'new-answer' );
+ $message = apply_filters( 'dwqa_get_new_answer_email_to_author_message', $message, $question_id, $answer_id );
+ if ( !$message ) {
+ return false;
}
- } // Send email to followers
- if ( $question->post_author != $answer->post_author ) {
- wp_mail( $email, $subject, $message, $headers );
- if ( $enable_send_copy && $email != $admin_email ) {
- wp_mail( $admin_email, $subject, $message, $headers );
+ $message = str_replace( '{answer_avatar}', $user_answer_avatar, $message );
+ $message = str_replace( '{answer_author}', esc_html( $user_answer_display_name ), $message );
+ $message = str_replace( '{question_link}', esc_url( $question_link ), $message );
+ $message = str_replace( '{question_author}', esc_html( $user_question_display_name ), $message );
+ $message = str_replace( '{answer_link}', esc_url( $answer_link ), $message );
+ $message = str_replace( '{question_title}', $question_title, $message );
+ $message = str_replace( '{answer_content}', wp_kses_post( $answer_content ), $message );
+ $message = str_replace( '{site_logo}', $site_logo, $message );
+ $message = str_replace( '{site_name}', esc_html( $site_name ), $message );
+ $message = str_replace( '{site_description}', esc_html( $site_description ), $message );
+ $message = str_replace( '{site_url}', esc_url( $site_url ), $message );
+
+ $headers = array(
+ "From: {$this->get_from_name()} <{$this->get_from_address()}>",
+ "Content-Type: {$this->get_content_type()}; charset=utf-8"
+ );
+
+ if ( $enable_send_copy ) {
+ foreach( $admin_email as $a_email ) {
+ $headers[] = "Bcc: " . $a_email;
+ }
}
+
+ $sender = $this->send( $user_question_email, $subject, $message, $headers );
}
}
@@ -240,9 +285,11 @@ public function new_comment_notify( $comment_id, $comment ) {
if ( 1 == $comment->comment_approved && ( 'dwqa-question' == $parent || 'dwqa-answer' == $parent ) ) {
if ( $parent == 'dwqa-question' ) {
- $enabled = get_option( 'dwqa_subscrible_enable_new_comment_question_notification', 1 );
+ $enabled = get_option( 'dwqa_subscrible_enable_new_comment_question_notification', 1 );
+ // $admin_email = $this->get_admin_email( 'comment-question' ); //ignore in this time
} elseif ( $parent == 'dwqa-answer' ) {
$enabled = get_option( 'dwqa_subscrible_enable_new_comment_answer_notification', 1 );
+ // $admin_email = $this->get_admin_email( 'comment-answer' );
}
if ( ! $enabled ) {
@@ -269,24 +316,21 @@ public function new_comment_notify( $comment_id, $comment ) {
}
// To send HTML mail, the Content-type header must be set
- $headers = 'MIME-Version: 1.0' . "\r\n";
- $headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
- //From email
- $from_email = get_option( 'dwqa_subscrible_from_address' );
- if ( $from_email ) {
- $headers .= 'From: ' . $from_email . "\r\n";
- }
+ $headers = array(
+ "From: {$this->get_from_name()} <{$this->get_from_address()}>",
+ "Content-Type: {$this->get_content_type()}; charset=utf-8"
+ );
if ( $parent == 'dwqa-question' ) {
$message = dwqa_get_mail_template( 'dwqa_subscrible_new_comment_question_email', 'new-comment-question' );
- $subject = get_option( 'dwqa_subscrible_new_comment_question_email_subject',__( '[{site_name}] You have a new comment for question {question_title}', 'dwqa' ) );
+ $subject = get_option( 'dwqa_subscrible_new_comment_question_email_subject',__( '[{site_name}] You have a new comment for question {question_title}', 'dw-question-answer' ) );
$message = str_replace( '{question_author}', get_the_author_meta( 'display_name', $post_parent->post_author ), $message );
$question = $post_parent;
} else {
$message = dwqa_get_mail_template( 'dwqa_subscrible_new_comment_answer_email', 'new-comment-answer' );
- $subject = get_option( 'dwqa_subscrible_new_comment_answer_email_subject',__( '[{site_name}] You have a new comment for answer', 'dwqa' ) );
+ $subject = get_option( 'dwqa_subscrible_new_comment_answer_email_subject',__( '[{site_name}] You have a new comment for answer', 'dw-question-answer' ) );
$message = str_replace( '{answer_author}', get_the_author_meta( 'display_name', $post_parent->post_author ), $message );
- $question_id = get_post_meta( $post_parent->ID, '_question', true );
+ $question_id = dwqa_get_post_parent_id( $post_parent->ID );
$question = get_post( $question_id );
}
$subject = str_replace( '{site_name}', get_bloginfo( 'name' ), $subject );
@@ -306,7 +350,7 @@ public function new_comment_notify( $comment_id, $comment ) {
$message = str_replace( '{comment_link}', get_permalink( $question->ID ) . '#comment-' . $comment_id, $message );
$message = str_replace( '{question_title}', $question->post_title, $message );
$message = str_replace( '{comment_author_avatar}', get_avatar( $comment->user_id, '60' ), $message );
- $message = str_replace( '{comment_author_link}', get_author_posts_url( $comment->user_id ), $message );
+ $message = str_replace( '{comment_author_link}', dwqa_get_author_link( $comment->user_id ), $message );
$message = str_replace( '{comment_author}', get_the_author_meta( 'display_name', $comment->user_id ), $message );
$message = str_replace( '{comment_content}', $comment->comment_content, $message );
$message = str_replace( '{site_name}', get_bloginfo( 'name' ), $message );
@@ -325,12 +369,12 @@ public function new_comment_notify( $comment_id, $comment ) {
if ( $parent == 'dwqa-question' ) {
$message_to_follower = dwqa_get_mail_template( 'dwqa_subscrible_new_comment_question_followers_email', 'new-comment-question' );
- $follow_subject = get_option( 'dwqa_subscrible_new_comment_question_followers_email_subject',__( '[{site_name}] You have a new comment for question {question_title}', 'dwqa' ) );
+ $follow_subject = get_option( 'dwqa_subscrible_new_comment_question_followers_email_subject',__( '[{site_name}] You have a new comment for question {question_title}', 'dw-question-answer' ) );
$message_to_follower = str_replace( '{question_author}', get_the_author_meta( 'display_name', $post_parent->post_author ), $message_to_follower );
$question = $post_parent;
} else {
$message_to_follower = dwqa_get_mail_template( 'dwqa_subscrible_new_comment_answer_followers_email', 'new-comment-answer' );
- $follow_subject = get_option( 'dwqa_subscrible_new_comment_answer_followers_email_subject',__( '[{site_name}] You have a new comment for answer', 'dwqa' ) );
+ $follow_subject = get_option( 'dwqa_subscrible_new_comment_answer_followers_email_subject',__( '[{site_name}] You have a new comment for answer', 'dw-question-answer' ) );
$message_to_follower = str_replace( '{answer_author}', get_the_author_meta( 'display_name', $post_parent->post_author ), $message_to_follower );
}
$follow_subject = str_replace( '{site_name}', get_bloginfo( 'name' ), $follow_subject );
@@ -345,27 +389,25 @@ public function new_comment_notify( $comment_id, $comment ) {
$message_to_follower = str_replace( '{comment_link}', $comment_link, $message_to_follower );
$message_to_follower = str_replace( '{question_title}', $question->post_title, $message_to_follower );
$message_to_follower = str_replace( '{comment_author_avatar}', get_avatar( $comment->user_id, '60' ), $message_to_follower );
- $message_to_follower = str_replace( '{comment_author_link}', get_author_posts_url( $comment->user_id ), $message_to_follower );
+ $message_to_follower = str_replace( '{comment_author_link}', dwqa_get_author_link( $comment->user_id ), $message_to_follower );
$message_to_follower = str_replace( '{comment_author}', get_the_author_meta( 'display_name', $comment->user_id ), $message_to_follower );
$message_to_follower = str_replace( '{comment_content}', $comment->comment_content, $message_to_follower );
$message_to_follower = str_replace( '{site_name}', get_bloginfo( 'name' ), $message_to_follower );
$message_to_follower = str_replace( '{site_description}', get_bloginfo( 'description' ), $message_to_follower );
$message_to_follower = str_replace( '{site_url}', site_url(), $message_to_follower );
-
- if ( ! empty( $followers ) ) {
+ if ( ! empty( $followers ) && is_array( $followers ) ) {
foreach ( $followers as $follower ) {
- $follower = (int ) $follower;
- $user_data = get_userdata( $follower );
+ $follower = (int) $follower;
+ $user_data = get_user_by( 'id', $follower );
if ( $user_data ) {
$follow_email = $user_data->user_email;
$follower_name = $user_data->display_name;
-
- if ( $follow_email && $follow_email != $post_parent_email && $follow_email != $comment_email ) {
+ if ( $follow_email && absint( $follower ) !== absint( $post_parent->post_author ) && absint( $follower ) !== absint( $comment->user_id ) ) {
$message_to_each_follower = str_replace( '{follower}', $follower_name, $message_to_follower );
- wp_mail( $follow_email, $follow_subject, $message_to_each_follower, $headers );
+ $test = $this->send( $follow_email, $follow_subject, $message_to_each_follower, $headers );
if ( $enable_send_copy && $follow_email != $admin_email ) {
- wp_mail( $admin_email, $follow_subject, $message_to_each_follower, $headers );
+ $this->send( $admin_email, $follow_subject, $message_to_each_follower, $headers );
}
}
}
@@ -374,20 +416,119 @@ public function new_comment_notify( $comment_id, $comment ) {
}
if ( $post_parent->post_author != $comment->user_id ) {
- wp_mail( $post_parent_email, $subject, $message, $headers );
+ $this->send( $post_parent_email, $subject, $message, $headers );
if ( $enable_send_copy && $admin_email != $post_parent_email ) {
- wp_mail( $admin_email, $subject, $message, $headers );
+ $this->send( $admin_email, $subject, $message, $headers );
}
}
}
}
- public function get_admin_email(){
- $admin_email = get_option( 'dwqa_subscrible_sendto_address' );
- if ( ! $admin_email ) {
- $admin_email = get_bloginfo( 'admin_email' );
+ public function get_admin_email( $type = 'question' ){
+ switch ($type) {
+ case 'answer':
+ $admin_email = get_option( 'dwqa_subscrible_new_answer_forward', '' );
+ break;
+ case 'comment-question':
+ $admin_email = get_option( 'dwqa_subscrible_new_comment_question_forward', '' );
+ break;
+ case 'comment-answer':
+ $admin_email = get_option( 'dwqa_subscrible_new_comment_answer_forward', '' );
+ break;
+ case 'question':
+ default:
+ $admin_email = get_option( 'dwqa_subscrible_sendto_address', '' );
+ break;
+ }
+ $emails = preg_split('/\r\n|\r|\n/', $admin_email );
+ $emails = array_merge( $emails, array( get_bloginfo( 'admin_email' ) ) );
+ $emails = array_unique($emails);
+ return $emails;
+ }
+
+ // Pushover
+ public function push( $args ) {
+ if ( !function_exists( 'ckpn_send_notification' ) ) {
+ if ( class_exists( 'CKPushoverNotifications' ) ) {
+ $ckpn_core = CKPushoverNotifications::getInstance();
+ $ckpn_core->ckpn_send_notification( $args );
+ }
+ } else {
+ ckpn_send_notification( $args );
+ }
+ }
+
+ function new_activity( $post_id = 0 ) {
+ if ( empty( $post_id ) ) {
+ return false;
+ }
+ $title = false;
+
+ if ( 'dwqa_add_comment' == current_action() ) {
+ $comment = get_comment( $post_id );
+ $title = __( 'New Comment in: ', 'dwqa-notification' );
+ $post_id = $comment->comment_post_ID;
}
- return explode( ',', $admin_email );
+
+ if ( 'dwqa-answer' == get_post_type( $post_id ) ) {
+ $question_id = dwqa_get_post_parent_id( $post_id );
+
+ if ( !$title ) {
+ $title = __( 'New Answer in: ', 'dwqa-notification' );
+ }
+
+ } else {
+ $question_id = $post_id;
+ if ( !$title ) {
+ $title = __( 'New Question: ', 'dwqa-notification' );
+ }
+ }
+
+ $question_title = get_post_field( 'post_title', $question_id );
+ $question_link = get_permalink( $question_id );
+ $content = get_post_field( 'post_content', $post_id );
+ $title = $title . $question_title;
+
+ $args = array( 'title' => $title, 'message' => strip_tags( $content ) );
+ $this->push( $args );
+ }
+
+ public function get_from_address() {
+ $from_email = get_option( 'dwqa_subscrible_from_address', get_bloginfo( 'admin_email' ) );
+
+ if ( empty( $from_email ) ) {
+ $from_email = get_bloginfo( 'admin_email' );
+ }
+
+ return sanitize_email( $from_email );
+ }
+
+ public function get_from_name() {
+ $name = get_option( 'dwqa_subscrible_from_name', get_bloginfo( 'name' ) );
+
+ if ( empty( $name ) ) {
+ $name = get_bloginfo( 'name' );
+ }
+
+ return $name;
+ }
+
+ public function get_content_type() {
+ return apply_filters( 'dwqa_notifications_get_content_type', 'text/html' );
+ }
+
+ public function send( $to, $subject, $message, $headers = '', $attachments = array() ) {
+ // return ;
+ add_filter( 'wp_mail_from', array( $this, 'get_from_address' ), 9999 );
+ add_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ), 9999 );
+ add_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ), 9999 );
+
+ $sended = wp_mail( $to, $subject, $message, $headers, $attachments );
+
+ remove_filter( 'wp_mail_from', array( $this, 'get_from_address' ) );
+ remove_filter( 'wp_mail_from_name', array( $this, 'get_from_name' ) );
+ remove_filter( 'wp_mail_content_type', array( $this, 'get_content_type' ) );
+ return $sended;
}
}
diff --git a/inc/Permission.php b/inc/Permission.php
index 80acddb4..71688a5c 100644
--- a/inc/Permission.php
+++ b/inc/Permission.php
@@ -1,26 +1,47 @@
user_id ) ) {
+ $post_author = $comment->user_id;
+ }
+ } else {
+ $post_author = get_post_field( 'post_author', $post_id );
+ }
-function dwqa_current_user_can( $perm, $post_id = false ) {
- global $dwqa, $current_user;
- if ( is_user_logged_in() ) {
- if ( $post_id && $current_user->ID == get_post_field( 'post_author', $post_id ) ) {
- return true;
- }
-
- if ( current_user_can( 'dwqa_can_' . $perm ) ) {
- return true;
+ if ( (int) $user_id === (int) $post_author || user_can( $user_id, 'dwqa_can_' . $perm ) ) {
+ $can = true;
+ }
+ } else {
+ // normal perms
+ if ( user_can( $user_id, 'dwqa_can_' . $perm ) ) {
+ $can = true;
+ }
}
- return false;
} else {
- $anonymous = $dwqa->permission->perms['anonymous'];
+ $anonymous = isset($dwqa->permission->perms['anonymous'])?$dwqa->permission->perms['anonymous']:array();
$type = explode( '_', $perm );
if ( isset( $anonymous[$type[1]][$type[0]] ) && $anonymous[$type[1]][$type[0]] ) {
- return true;
+ $can = true;
} else {
- return false;
+ $can = false;
}
}
- return false;
+ return apply_filters( 'dwqa_user_can', $can, $perm, $user_id, $post_id );
+}
+
+function dwqa_current_user_can( $perm, $post_id = false ) {
+ $current_user_id = get_current_user_id();
+ $can = dwqa_user_can( $current_user_id, $perm, $post_id );
+ return apply_filters( 'dwqa_current_user_can', $can, $current_user_id, $perm, $post_id );
}
function dwqa_get_warning_page() {
@@ -176,9 +197,13 @@ public function __construct() {
),
),
);
+
add_action( 'init', array( $this, 'first_update_role_functions' ) );
add_action( 'init', array( $this, 'prepare_permission' ) );
- add_action( 'update_option_dwqa_permission', array( $this, 'update_caps' ), 10, 2 );
+
+ add_action( 'admin_init', array( $this, 'admin_menu_reset_permission_default' ) );
+
+ add_action( 'update_option_dwqa_permission', array( $this, 'update_permission' ), 10, 2 );
add_filter( 'user_has_cap', array( $this, 'allow_user_view_their_draft_post' ), 10, 4 );
@@ -189,17 +214,19 @@ public function __construct() {
add_filter( 'the_posts', array( $this, 'restrict_single_question' ), 11 );
}
+ public function admin_menu_reset_permission_default(){
+ if(is_admin() && current_user_can('manage_options') && isset($_POST['dwqa-permission-reset'])){
+ $this->reset_caps($_POST['dwqa-permission-reset']);
+ wp_redirect(admin_url('edit.php?post_type=dwqa-question&page=dwqa-settings&tab=permission'));
+ die();
+ }
+ }
+
public function prepare_permission() {
$this->perms = get_option( 'dwqa_permission' );
- $this->perms = $this->perms ? $this->perms : array();
- $this->perms = wp_parse_args( $this->perms, $this->defaults );
}
-
public function add_caps( $value ) {
- // $roles = get_editable_roles();
- $this->prepare_permission();
-
foreach ( $value as $role_name => $role_info ) {
if ( $role_name == 'anonymous' )
continue;
@@ -209,7 +236,7 @@ public function add_caps( $value ) {
foreach ( $this->objects as $post_type ) {
foreach ( $this->default_cap as $cap => $default ) {
- if ( isset( $this->perms[$role_name][$post_type][$cap] ) && $this->perms[$role_name][$post_type][$cap] ) {
+ if ( isset( $role_info[$post_type][$cap] ) && $role_info[$post_type][$cap] ) {
$role->add_cap( 'dwqa_can_' . $cap . '_' . $post_type );
} else {
$role->remove_cap( 'dwqa_can_' . $cap . '_' . $post_type );
@@ -218,46 +245,72 @@ public function add_caps( $value ) {
}
}
}
- public function update_caps( $old_value, $value ) {
- //update_option( 'dwqa_permission', $this->perms );
- $this->add_caps( $value );
+
+ public function update_permission( $old_value, $value ) {
+ $this->update_caps($value);
}
-
- public function reset_caps( $old_value, $value ) {
- update_option( 'dwqa_permission', $this->perms );
+
+ public function update_caps( $value ) {
+ update_option( 'dwqa_permission', $value );
$this->add_caps( $value );
}
- public function prepare_permission_caps() {
- $this->add_caps( $this->defaults );
+ public function reset_caps( $post_type = 'question' ) {
+ //change cap of post type
+ $roles = get_editable_roles();
+ $roles['anonymous'] = array();
+ foreach($roles as $role => $role_info){
+ if(isset($this->defaults[$role])){
+ $this->perms[$role][$post_type] = $this->defaults[$role][$post_type];
+ }else{
+ $this->perms[$role][$post_type] = array();
+ }
+ }
+ $this->update_caps($this->perms);
}
public function first_update_role_functions() {
$dwqa_has_roles = get_option( 'dwqa_has_roles' );
- $dwqa_permission = get_option( 'dwqa_permission' );
$this->perms = get_option( 'dwqa_permission' );
if ( ! $dwqa_has_roles || ! is_array( $this->perms ) || empty( $this->perms ) ) {
+ //perms default
$this->perms = $this->defaults;
- $this->prepare_permission_caps();
- update_option( 'dwqa_permission', $this->perms );
+
+ $this->update_caps($this->perms);
+
update_option( 'dwqa_has_roles', 1 );
}
}
+
+ public function prepare_permission_caps() {
+ $this->update_caps( $this->defaults );
+ }
public function remove_permision_caps() {
foreach ( $this->defaults as $role_name => $perm ) {
if ( $role_name == 'anonymous' ) {
continue;
}
+
$role = get_role( $role_name );
+
foreach ( $perm['question'] as $key => $value ) {
- $role->remove_cap( 'dwqa_can_'.$key.'_question' );
+ $cap = 'dwqa_can_'.$key.'_question';
+ if(isset($role->capabilities[$cap])){
+ $role->remove_cap( $cap );
+ }
}
foreach ( $perm['answer'] as $key => $value ) {
- $role->remove_cap( 'dwqa_can_'.$key.'_answer' );
+ $cap = 'dwqa_can_'.$key.'_answer';
+ if(isset($role->capabilities[$cap])){
+ $role->remove_cap( $cap );
+ }
}
foreach ( $perm['comment'] as $key => $value ) {
- $role->remove_cap( 'dwqa_can_'.$key.'_comment' );
+ $cap = 'dwqa_can_'.$key.'_comment';
+ if(isset($role->capabilities[$cap])){
+ $role->remove_cap( $cap );
+ }
}
}
}
@@ -265,7 +318,7 @@ public function remove_permision_caps() {
public function allow_user_view_their_draft_post( $all_caps, $caps, $name, $user ) {
if ( is_user_logged_in() ) {
global $wp_query, $current_user;
- if ( isset( $wp_query->is_single ) && $wp_query->is_single && $wp_query->query_vars['post_type'] == 'dwqa-question' && $name[0] == 'edit_post' ) {
+ if ( isset( $wp_query->is_single ) && $wp_query->is_single && isset( $wp_query->query_vars['post_type'] ) && $wp_query->query_vars['post_type'] == 'dwqa-question' && $name[0] == 'edit_post' ) {
if ( isset( $name[2] ) ) {
$post_id = $name[2];
$author = get_post_field( 'post_author', $post_id );
@@ -283,7 +336,7 @@ public function allow_user_view_their_draft_post( $all_caps, $caps, $name, $user
public function reset_permission_default() {
global $dwqa;
if ( ! isset( $_POST['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['nonce'] ), '_dwqa_reset_permission' ) ) {
- wp_send_json_error( array( 'message' => __( 'Are you cheating huh?', 'dwqa' ) ) );
+ wp_send_json_error( array( 'message' => __( 'Are you cheating huh?', 'dw-question-answer' ) ) );
}
if ( isset( $_POST['type'] ) ) {
$old = $dwqa->permission->perms;
@@ -306,16 +359,6 @@ public function read_permission_apply( $posts, $query ) {
if ( isset( $query->query['post_type'] ) && $query->query['post_type'] == 'dwqa-answer' && ! dwqa_current_user_can( 'read_answer' ) ) {
return false;
}
-
- if ( ! is_single() && isset( $query->query['post_type'] ) && $query->query['post_type'] == 'dwqa-question' ) {
- $availables = array();
- foreach ( $posts as $key => $post ) {
- if ( $post->post_status == 'publish' || ( $post->post_status != 'publish' && dwqa_current_user_can( 'edit_question' ) ) ){
- $availables[] = $post;
- }
- }
- return $availables;
- }
return $posts;
}
diff --git a/inc/PointerHelper.php b/inc/PointerHelper.php
index 03ad25fa..7efe85ee 100644
--- a/inc/PointerHelper.php
+++ b/inc/PointerHelper.php
@@ -57,8 +57,8 @@ public function register_pointer_testing( $p ) {
'target' => '#contextual-help-link',
'options' => array(
'content' => sprintf( ' %s %s
',
- __( 'How to use DW Question Answer', 'dwqa' ),
- __( 'Documents, Support From DesignWall (help)', 'dwqa' )
+ __( 'How to use DW Question Answer', 'dw-question-answer' ),
+ __( 'Documents, Support From DesignWall (help)', 'dw-question-answer' )
),
'position' => array( 'edge' => 'top', 'align' => 'right' )
)
@@ -67,8 +67,8 @@ public function register_pointer_testing( $p ) {
'target' => '#adminmenu a[href="edit.php?post_type=dwqa-question&page=dwqa-settings"]',
'options' => array(
'content' => sprintf( ' %s %s
',
- __( 'Config your support channel', 'dwqa' ),
- __( 'Change comment settings, and create the Submit question page.', 'dwqa' )
+ __( 'Config your support channel', 'dw-question-answer' ),
+ __( 'Change comment settings, and create the Submit question page.', 'dw-question-answer' )
),
'position' => array( 'edge' => 'left', 'align' => 'middle' )
)
diff --git a/inc/Posts/Answer.php b/inc/Posts/Answer.php
index c3b1de3a..414f8909 100644
--- a/inc/Posts/Answer.php
+++ b/inc/Posts/Answer.php
@@ -15,18 +15,24 @@ function dwqa_question_answers_count( $question_id = null ) {
$question_id = $post->ID;
}
- $answer_count = get_transient( 'dwqa_answer_count_for_' . $question_id );
+ $answer_count = wp_cache_get( 'dwqa_answer_count_for_' . $question_id );
- if ( false === $answer_count ) {
- $sql = "SELECT COUNT( DISTINCT `P`.ID ) FROM {$wpdb->postmeta} PM JOIN {$wpdb->posts} P ON `PM`.post_id = `P`.ID WHERE `PM`.meta_key = '_question' AND meta_value = {$question_id} AND `P`.post_type = 'dwqa-answer' AND `P`.post_status = 'publish'";
- $sql .= " AND ( `P`.post_status = 'publish' ";
- if ( dwqa_current_user_can( 'edit_question', $question_id ) ) {
- $sql .= " OR `P`.post_status = 'private'";
+ if ( !$answer_count ) {
+
+ $args = array(
+ 'post_type' => 'dwqa-answer',
+ 'post_parent' => $question_id,
+ 'post_per_page' => '-1',
+ 'post_status' => array('publish')
+ );
+
+ if ( dwqa_current_user_can( 'edit_question', $question_id ) || dwqa_current_user_can( 'manage_question' ) ) {
+ $args['post_status'][] = 'private';
}
- $sql .= " )";
- $answer_count = $wpdb->get_var( $sql );
+ $answer = new WP_Query($args);
+ $answer_count = $answer->found_posts;
- set_transient( 'dwqa_answer_count_for_' . $question_id, $answer_count, 15*60 );
+ wp_cache_set( 'dwqa_answer_count_for_' . $question_id, $answer_count, '', 15*60 );
}
return $answer_count;
@@ -49,11 +55,11 @@ function dwqa_is_answer_flag( $post_id ) {
return false; //showing
}
-function dwqa_is_the_best_answer( $answer_id, $question_id = false ) {
- if ( ! $question_id ) {
- $question_id = get_the_ID();
+function dwqa_is_the_best_answer( $answer_id = false ) {
+ if ( ! $answer_id ) {
+ $answer_id = get_the_ID();
}
-
+ $question_id = dwqa_get_question_from_answer_id( $answer_id );
$best_answer = dwqa_get_the_best_answer( $question_id );
if ( $best_answer && $best_answer == $answer_id ) {
return true;
@@ -82,14 +88,7 @@ function dwqa_get_the_best_answer( $question_id = false ) {
'post_type' => $dwqa->answer->get_slug(),
'posts_per_page' => 1,
'meta_key' => '_dwqa_votes',
- 'meta_query' => array(
- 'relation' => 'AND',
- array(
- 'key' => '_question',
- 'value' => $question_id . '',
- 'compare' => '=',
- )
- ),
+ 'post_parent' => $question_id,
'fields' => 'ids',
'orderby' => 'meta_value_num',
'order' => 'DESC'
@@ -122,14 +121,8 @@ function dwqa_user_get_draft( $question_id = false ) {
}
global $current_user;
$args = array(
- 'post_type' => 'dwqa-answer',
- 'meta_query' => array(
- array(
- 'key' => '_question',
- 'value' => array( $question_id ),
- 'compare' => 'IN',
- ),
- ),
+ 'post_type' => 'dwqa-answer',
+ 'post_parent' => $question_id,
'post_status' => 'draft',
);
@@ -163,13 +156,7 @@ function dwqa_get_drafts( $question_id = false ) {
$answers = get_posts( array(
'post_type' => 'dwqa-answer',
'posts_per_page' => 40,
- 'meta_query' => array(
- array(
- 'key' => '_question',
- 'value' => array( $question_id ),
- 'compare' => 'IN',
- ),
- ),
+ 'post_parent' => $question_id,
'post_status' => 'draft',
) );
@@ -192,12 +179,7 @@ function dwqa_question_answer_count_by_status( $question_id, $status = 'publish'
$query = new WP_Query( array(
'post_type' => 'dwqa-answer',
'post_status' => $status,
- 'meta_query' => array(
- array(
- 'key' => '_question',
- 'value' => $question_id,
- ),
- ),
+ 'post_parent' => $question_id,
'fields' => 'ids'
) );
return $query->found_posts;
@@ -215,21 +197,23 @@ function dwqa_get_question_from_answer_id( $answer_id = false ) {
$answer_id = get_the_ID();
}
- return get_post_meta( $answer_id, '_question', true );
+ return dwqa_get_post_parent_id( $answer_id );
}
class DWQA_Posts_Answer extends DWQA_Posts_Base {
public function __construct() {
parent::__construct( 'dwqa-answer', array(
- 'plural' => __( 'Answers', 'dwqa' ),
- 'singular' => __( 'Answer', 'dwqa' ),
- 'menu' => __( 'Answers', 'dwqa' ),
+ 'plural' => __( 'Answers', 'dw-question-answer' ),
+ 'singular' => __( 'Answer', 'dw-question-answer' ),
+ 'menu' => __( 'Answers', 'dw-question-answer' ),
) );
add_action( 'manage_' . $this->get_slug() . '_posts_custom_column', array( $this, 'columns_content' ), 10, 2 );
add_action( 'post_row_actions', array( $this, 'unset_old_actions' ) );
+ add_action( 'add_meta_boxes', array( $this, 'question_metabox' ) );
+ add_filter( 'wp_insert_post_data', array( $this, 'save_metabox_post_data' ), 10, 2 );
//Cache
add_action( 'dwqa_add_answer', array( $this, 'update_transient_when_add_answer' ), 10, 2 );
@@ -262,13 +246,13 @@ public function set_has_archive() {
}
public function columns_head( $defaults ) {
- if ( isset( $_GET['post_type'] ) && $_GET['post_type'] == $this->get_slug() ) {
+ if ( isset( $_GET['post_type'] ) && sanitize_text_field( $_GET['post_type'] ) == $this->get_slug() ) {
$defaults = array(
'cb' => ' ',
- 'info' => __( 'Answer', 'dwqa' ),
- 'author' => __( 'Author', 'dwqa' ),
+ 'info' => __( 'Answer', 'dw-question-answer' ),
+ 'author' => __( 'Author', 'dw-question-answer' ),
'comment' => ' ',
- 'dwqa-question' => __( 'In Response To', 'dwqa' ),
+ 'dwqa-question' => __( 'In Response To', 'dw-question-answer' ),
);
}
return $defaults;
@@ -318,17 +302,17 @@ public function columns_content( $column_name, $post_ID ) {
);
printf(
'%s %s %s %s %s %s',
- __( 'Submitted', 'dwqa' ),
- __( 'on', 'dwqa' ),
+ __( 'Submitted', 'dw-question-answer' ),
+ __( 'on', 'dw-question-answer' ),
get_permalink(),
- date( 'M d Y', get_post_time( 'U', false, $answer ) ),
- ( time() - get_post_time( 'U', false, $answer ) ) > 60 * 60 * 24 * 2 ? '' : ' at ' . human_time_diff( get_post_time( 'U', false, $answer ) ) . ' ago',
+ date( 'M d Y', get_post_time( 'U', true, $answer ) ),
+ ( time() - get_post_time( 'U', true, $answer ) ) > 60 * 60 * 24 * 2 ? '' : ' at ' . human_time_diff( get_post_time( 'U', true, $answer ) ) . ' ago',
substr( get_the_content(), 0 , 140 ) . ' ...',
$this->row_actions( $actions )
);
break;
case 'dwqa-question':
- $question_id = get_post_meta( $post_ID, '_question', true );
+ $question_id = dwqa_get_post_parent_id( $post_ID );
if ( $question_id ) {
$question = get_post( $question_id );
echo '' . $question->post_title . ' ';
@@ -350,6 +334,48 @@ public function update_transient_when_remove_answer( $answer_id, $question_id )
delete_transient( 'dwqa_latest_answer_for_' . $question_id );
delete_transient( 'dwqa_answer_count_for_' . $question_id );
}
+
+ public function question_metabox() {
+ add_meta_box(
+ 'dwqa-answer-question-metabox',
+ __( 'Question ID', 'dw-question-answer' ),
+ array( $this, 'question_metabox_output' ),
+ 'dwqa-answer',
+ 'side'
+ );
+ }
+
+ public function question_metabox_output( $post ) {
+ $question = $post->post_parent ? $post->post_parent : 0;
+ ?>
+
+
+
+
+
+
+
+
diff --git a/inc/Posts/Base.php b/inc/Posts/Base.php
index bb9ba4c9..21b2b967 100644
--- a/inc/Posts/Base.php
+++ b/inc/Posts/Base.php
@@ -1,8 +1,37 @@
'authorization',
- 'error_message' => __( 'Are you cheating, huh?', 'dwqa' ),
+ 'error_message' => __( 'Are you cheating, huh?', 'dw-question-answer' ),
);
$vote_for = isset( $_POST['vote_for'] ) && sanitize_text_field( $_POST['vote_for'] ) == 'question'
@@ -15,7 +44,7 @@ function dwqa_action_vote( ) {
if ( ! isset( $_POST[ 'post' ] ) ) {
$result['error_code'] = 'missing ' . $vote_for;
- $result['error_message'] = __( 'What '.$vote_for.' are you looking for?', 'dwqa' );
+ $result['error_message'] = __( 'What '.$vote_for.' are you looking for?', 'dw-question-answer' );
wp_send_json_error( $result );
}
@@ -23,16 +52,34 @@ function dwqa_action_vote( ) {
$point = isset( $_POST['type'] ) && sanitize_text_field( $_POST['type'] ) == 'up' ? 1 : -1;
//vote
+ $dwqa_user_vote_id = '';
if ( is_user_logged_in( ) ) {
global $current_user;
+ $dwqa_user_vote_id = $current_user->ID;
+ }else{
+ global $dwqa_general_settings;
+ if(isset($dwqa_general_settings['allow-anonymous-vote']) && $dwqa_general_settings['allow-anonymous-vote']){
+ $dwqa_user_vote_id = dwqa_get_current_user_session();
+ }
+ }
+ if ($dwqa_user_vote_id!=''){
+ if ( ! dwqa_is_user_voted( $post_id, $point, $dwqa_user_vote_id ) ) {
+ $votes = get_post_meta( $post_id, '_dwqa_votes_log', true );
- if ( ! dwqa_is_user_voted( $post_id, $point ) ) {
- $votes = maybe_unserialize( get_post_meta( $post_id, '_dwqa_votes_log', true ) );
-
- $votes[$current_user->ID] = $point;
+ //remove vote serialize
+ $data_votes = @unserialize($votes);
+ if ($data_votes !== false) {
+ $votes = $data_votes;
+ }
+
+ if(!$votes || !is_array($votes)){
+ $votes = array();
+ }
+
+ $votes[$dwqa_user_vote_id] = $point;
//update
do_action( 'dwqa_vote_'.$vote_for, $post_id, ( int ) $point );
- update_post_meta( $post_id, '_dwqa_votes_log', serialize( $votes ) );
+ update_post_meta( $post_id, '_dwqa_votes_log', $votes);
// Update vote point
dwqa_update_vote_count( $post_id );
@@ -43,21 +90,13 @@ function dwqa_action_vote( ) {
wp_send_json_success( array( 'vote' => $point ) );
} else {
$result['error_code'] = 'voted';
- $result['error_message'] = __( 'You voted for this ' . $vote_for, 'dwqa' );
+ $result['error_message'] = __( 'You voted for this ' . $vote_for, 'dw-question-answer' );
wp_send_json_error( $result );
}
- } elseif ( 'question' == $vote_for ) {
- // useful of question with meta field is "_dwqa_question_useful", point of this question
- $useful = get_post_meta( $post_id, '_dwqa_'.$vote_for.'_useful', true );
- $useful = $useful ? ( int ) $useful : 0;
-
- do_action( 'dwqa_vote_'.$vote_for, $post_id, ( int ) $point );
- update_post_meta( $post_id, '_dwqa_'.$vote_for.'_useful', $useful + $point );
-
- // Number of votes by guest
- $useful_rate = get_post_meta( $post_id, '_dwqa_'.$vote_for.'_useful_rate', true );
- $useful_rate = $useful_rate ? ( int ) $useful_rate : 0;
- update_post_meta( $post_id, '_dwqa_'.$vote_for.'_useful_rate', $useful_rate + 1 );
+ }else{
+ $result['error_code'] = 'anonymous';
+ $result['error_message'] = __( 'You aren\'t allowed voted for this ' . $vote_for, 'dw-question-answer' );
+ wp_send_json_error( $result );
}
}
add_action( 'wp_ajax_dwqa-action-vote', 'dwqa_action_vote' );
@@ -75,7 +114,7 @@ function dwqa_is_user_voted( $post_id, $point, $user = false ) {
global $current_user;
$user = $current_user->ID;
}
- $votes = maybe_unserialize( get_post_meta( $post_id, '_dwqa_votes_log', true ) );
+ $votes = get_post_meta( $post_id, '_dwqa_votes_log', true );
if ( empty( $votes ) ) {
return false;
@@ -111,7 +150,7 @@ function dwqa_update_vote_count( $post_id ) {
global $post;
$post_id = $post->ID;
}
- $votes = maybe_unserialize( get_post_meta( $post_id, '_dwqa_votes_log', true ) );
+ $votes = get_post_meta( $post_id, '_dwqa_votes_log', true );
if ( empty( $votes ) ) {
return 0;
@@ -218,7 +257,7 @@ function dwqa_get_latest_action_date( $question = false, $before = '', $af
$question_list_link = isset( $dwqa_general_settings['pages']['archive-question'] ) ? get_permalink( $dwqa_general_settings['pages']['archive-question'] ) : false;
$latest_answer = dwqa_get_latest_answer( $question );
- $last_activity_date = $latest_answer ? $latest_answer->post_date : get_post_field( 'post_date', $question );
+ $last_activity_date = $latest_answer ? $latest_answer->post_date_gmt : get_post_field( 'post_date_gmt', $question );
$post_id = $latest_answer ? $latest_answer->ID : $question;
$author_id = $post->post_author;
if ( $author_id == 0 || dwqa_is_anonymous( $post_id ) ) {
@@ -227,7 +266,7 @@ function dwqa_get_latest_action_date( $question = false, $before = '', $af
if ( $anonymous_name ) {
$display_name = $anonymous_name . ' ';
} else {
- $display_name = __( 'Anonymous', 'dwqa' ) . ' ';
+ $display_name = __( 'Anonymous', 'dw-question-answer' ) . ' ';
}
} else {
$display_name = get_the_author_meta( 'display_name', $author_id );
@@ -248,13 +287,13 @@ function dwqa_get_latest_action_date( $question = false, $before = '', $af
if ( $last_activity_date && $post->last_activity_type == 'answer' ) {
$date = human_time_diff( strtotime( $last_activity_date ), current_time( 'timestamp' ) );
- return sprintf( __( '%s answered %s ago', 'dwqa' ), $author_link, $date );
+ return sprintf( __( '%s answered %s ago', 'dw-question-answer' ), $author_link, $date );
}
if ( 'dwqa-answer' == get_post_type( $question ) ) {
- return sprintf( __( '%s answered %s ago', 'dwqa' ), $author_link, human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) );
+ return sprintf( __( '%s answered %s ago', 'dw-question-answer' ), $author_link, human_time_diff( get_post_time( 'U', true, $question ) ) );
}
- return sprintf( __( '%s asked %s ago', 'dwqa' ), $author_link, human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) );
+ return sprintf( __( '%s asked %s ago', 'dw-question-answer' ), $author_link, human_time_diff( get_post_time( 'U', true, $question ) ) );
}
function dwqa_is_edit() {
@@ -303,8 +342,8 @@ public function get_slug() {
public function get_name_labels() {
return wp_parse_args( $this->labels, array(
- 'plural' => __( 'DWQA Posts', 'dwqa' ),
- 'singular' => __( 'DWQA Post', 'dwqa' ),
+ 'plural' => __( 'DWQA Posts', 'dw-question-answer' ),
+ 'singular' => __( 'DWQA Post', 'dw-question-answer' ),
'rewrite' => true,
) );
}
@@ -315,15 +354,15 @@ public function set_labels() {
return $labels = array(
'name' => $names['plural'],
'singular_name' => $names['singular'],
- 'add_new' => _x( 'Add New', 'dwqa', 'dwqa' ) . ' ' . $names['singular'],
- 'add_new_item' => __( 'Add New', 'dwqa' ) . ' ' . $names['singular'],
- 'edit_item' => __( 'Edit', 'dwqa' ) . ' ' . $names['singular'],
- 'new_item' => __( 'New', 'dwqa' ) . ' ' . $names['singular'],
- 'view_item' => __( 'View', 'dwqa' ) . ' ' . $names['singular'],
- 'search_items' => __( 'Search ', 'dwqa' ) . $names['plural'],
- 'not_found' => $names['plural'] . ' ' . __( 'not found', 'dwqa' ),
- 'not_found_in_trash' => $names['plural'] . ' ' . __( 'not found in Trash', 'dwqa' ),
- 'parent_item_colon' => __( 'Parent:', 'dwqa' ) . ' ' . $names['singular'],
+ 'add_new' => _x( 'Add New', 'dwqa', 'dw-question-answer' ) . ' ' . $names['singular'],
+ 'add_new_item' => __( 'Add New', 'dw-question-answer' ) . ' ' . $names['singular'],
+ 'edit_item' => __( 'Edit', 'dw-question-answer' ) . ' ' . $names['singular'],
+ 'new_item' => __( 'New', 'dw-question-answer' ) . ' ' . $names['singular'],
+ 'view_item' => __( 'View', 'dw-question-answer' ) . ' ' . $names['singular'],
+ 'search_items' => __( 'Search ', 'dw-question-answer' ) . $names['plural'],
+ 'not_found' => $names['plural'] . ' ' . __( 'not found', 'dw-question-answer' ),
+ 'not_found_in_trash' => $names['plural'] . ' ' . __( 'not found in Trash', 'dw-question-answer' ),
+ 'parent_item_colon' => __( 'Parent:', 'dw-question-answer' ) . ' ' . $names['singular'],
'menu_name' => isset( $names['menu'] ) ? $names['menu'] : $names['plural'],
);
}
diff --git a/inc/Posts/Comment.php b/inc/Posts/Comment.php
index 71e33b09..50aaf18d 100644
--- a/inc/Posts/Comment.php
+++ b/inc/Posts/Comment.php
@@ -11,7 +11,7 @@ public function __construct() {
add_filter( 'comment_id_fields', array( $this, 'comment_form_id_fields_filter' ), 10, 3 );
add_filter( 'get_comment_text', array( $this, 'sanitizie_comment' ), 10, 2 );
- add_filter( 'get_comment', array( $this, 'comment_author_link_anonymous' ) );
+ //add_filter( 'get_comment', array( $this, 'comment_author_link_anonymous' ) );
add_action( 'wp_insert_comment', array( $this, 'reopen_question_have_new_comment' ) );
@@ -27,9 +27,9 @@ public function __construct() {
public function hook_redirect_comment_for_answer( $location, $comment ) {
if ( 'dwqa-answer' == get_post_type( $comment->comment_post_ID ) ) {
- $question = get_post_meta( $comment->comment_post_ID, '_question', true );
- if ( $question ) {
- return get_post_permalink( $question ).'#'.'answer-' . $comment->comment_post_ID . '&comment='.$comment->comment_ID;
+ $question_id = dwqa_get_post_parent_id( $comment->comment_post_ID );
+ if ( $question_id ) {
+ return get_post_permalink( $question_id ).'#'.'answer-' . $comment->comment_post_ID . '&comment='.$comment->comment_ID;
}
}
return $location;
@@ -73,7 +73,7 @@ public function comment_form_id_fields_filter( $result, $id, $replytoid ) {
public function sanitizie_comment( $content, $comment ) {
$post_type = get_post_type( $comment->comment_post_ID );
if ( $post_type == 'dwqa-question' || $post_type == 'dwqa-answer' ) {
- $content = str_replace( esc_html( ' ' ), ' ', esc_html( $content ) );
+ $content = str_replace( ' ', ' ', $content );
$content = make_clickable( $content );
$content = preg_replace( '/( ]* )( > )/', '$1 target="_blank" $2', $content );
}
@@ -99,7 +99,7 @@ public function get_comments() {
public function comment_author_link_anonymous( $comment ) {
// global $current_comment;
if ( $comment->user_id <= 0 && ( get_post_type( $comment->comment_post_ID ) == 'dwqa-question' || get_post_type( $comment->comment_post_ID ) == 'dwqa-answer' ) ) {
- $comment->comment_author = __( 'Anonymous','dwqa' );
+ $comment->comment_author = __( 'Anonymous','dw-question-answer' );
}
return $comment;
}
@@ -108,24 +108,24 @@ public function comment_author_link_anonymous( $comment ) {
public function reopen_question_have_new_comment( $comment_ID ){
$comment = get_comment( $comment_ID );
$comment_post_type = get_post_type( $comment->comment_post_ID );
- $question = false;
+ $question_id = false;
if ( 'dwqa-answer' == $comment_post_type ) {
- $question = get_post_meta( $comment->comment_post_ID, '_question', true );
+ $question_id = dwqa_get_post_parent_id( $comment->comment_post_ID );
} elseif ( 'dwqa-question' == $comment_post_type ) {
- $question = $comment->comment_post_ID;
+ $question_id = $comment->comment_post_ID;
}
- if ( $question ) {
- $question_status = get_post_meta( $question, '_dwqa_status', true );
+ if ( $question_id ) {
+ $question_status = get_post_meta( $question_id, '_dwqa_status', true );
if ( ! user_can( $comment->user_id, 'edit_posts' ) ) {
if ( 'resolved' == $question_status ) {
- update_post_meta( $question, '_dwqa_status', 're-open' );
+ update_post_meta( $question_id, '_dwqa_status', 're-open' );
}
}
}
if ( $comment->user_id ) {
- add_post_meta( $question, '_dwqa_followers', $comment->user_id );
+ add_post_meta( $question_id, '_dwqa_followers', $comment->user_id );
}
}
}
diff --git a/inc/Posts/Question.php b/inc/Posts/Question.php
index 450ddfa4..6a9aa8d1 100644
--- a/inc/Posts/Question.php
+++ b/inc/Posts/Question.php
@@ -53,7 +53,7 @@ function dwqa_related_question( $question_id = false, $number = 5, $echo = true
if ( $echo ) {
echo '';
while ( $related_questions->have_posts() ) { $related_questions->the_post();
- echo ''.get_the_title().' '.__( 'asked by', 'dwqa' ).' ';
+ echo ''.get_the_title().' '.__( 'asked by', 'dw-question-answer' ).' ';
the_author_posts_link();
echo ' ';
}
@@ -87,20 +87,6 @@ function dwqa_question_views_count( $question_id = null ) {
}
}
-function dwqa_question_get_tags_list( $post_id = false ) {
- if ( ! $post_id ) {
- $post_id = get_the_ID();
- }
-
- $tags = wp_get_post_terms( $post_id, 'dwqa-question_tag' );
- $list = array();
- foreach( $tags as $tag ) {
- $list[] = $tag->name;
- }
-
- // $list
-}
-
class DWQA_Posts_Question extends DWQA_Posts_Base {
public function __construct() {
@@ -111,9 +97,9 @@ public function __construct() {
}
$slug = isset( $dwqa_general_settings['question-rewrite'] ) ? $dwqa_general_settings['question-rewrite'] : 'question';
parent::__construct( 'dwqa-question', array(
- 'plural' => __( 'Questions', 'dwqa' ),
- 'singular' => __( 'Question', 'dwqa' ),
- 'menu' => __( 'Questions', 'dwqa' ),
+ 'plural' => __( 'Questions', 'dw-question-answer' ),
+ 'singular' => __( 'Question', 'dw-question-answer' ),
+ 'menu' => __( 'Questions', 'dw-question-answer' ),
'rewrite' => array( 'slug' => $slug, 'with_front' => false ),
) );
@@ -142,10 +128,6 @@ public function __construct() {
add_filter( 'dwqa_prepare_question_content', array( $this, 'pre_content_filter'), 20 );
add_filter( 'dwqa_prepare_update_question', array( $this, 'pre_content_kses'), 10 );
add_filter( 'dwqa_prepare_update_question', array( $this, 'pre_content_filter'), 20 );
-
- add_action( 'dwqa-prepare-archive-posts', array( $this, 'prepare_archive_posts' ) );
- add_action( 'dwqa-after-archive-posts', array( $this, 'after_archive_posts' ) );
-
}
public function init() {
@@ -211,17 +193,17 @@ public function register_taxonomy() {
$tag_slug = $this->get_question_rewrite() . '/' . $this->get_tag_rewrite();
$labels = array(
- 'name' => _x( 'Question Categories', 'taxonomy general name', 'dwqa' ),
- 'singular_name' => _x( 'Question Category', 'taxonomy singular name', 'dwqa' ),
- 'search_items' => __( 'Search Question Categories', 'dwqa' ),
- 'all_items' => __( 'All Question Categories', 'dwqa' ),
- 'parent_item' => __( 'Parent Question Category', 'dwqa' ),
- 'parent_item_colon' => __( 'Parent Question Category:', 'dwqa' ),
- 'edit_item' => __( 'Edit Question Category', 'dwqa' ),
- 'update_item' => __( 'Update Question Category', 'dwqa' ),
- 'add_new_item' => __( 'Add New Question Category', 'dwqa' ),
- 'new_item_name' => __( 'New Question Category Name', 'dwqa' ),
- 'menu_name' => __( 'Question Category', 'dwqa' ),
+ 'name' => _x( 'Question Categories', 'taxonomy general name', 'dw-question-answer' ),
+ 'singular_name' => _x( 'Question Category', 'taxonomy singular name', 'dw-question-answer' ),
+ 'search_items' => __( 'Search Question Categories', 'dw-question-answer' ),
+ 'all_items' => __( 'All Question Categories', 'dw-question-answer' ),
+ 'parent_item' => __( 'Parent Question Category', 'dw-question-answer' ),
+ 'parent_item_colon' => __( 'Parent Question Category:', 'dw-question-answer' ),
+ 'edit_item' => __( 'Edit Question Category', 'dw-question-answer' ),
+ 'update_item' => __( 'Update Question Category', 'dw-question-answer' ),
+ 'add_new_item' => __( 'Add New Question Category', 'dw-question-answer' ),
+ 'new_item_name' => __( 'New Question Category Name', 'dw-question-answer' ),
+ 'menu_name' => __( 'Question Category', 'dw-question-answer' ),
);
$args = array(
@@ -240,22 +222,22 @@ public function register_taxonomy() {
register_taxonomy( $this->get_slug() . '_category', array( $this->get_slug() ), $args );
$labels = array(
- 'name' => _x( 'Question Tags', 'taxonomy general name', 'dwqa' ),
- 'singular_name' => _x( 'Question Tag', 'taxonomy singular name', 'dwqa' ),
- 'search_items' => __( 'Search Question Tags', 'dwqa' ),
- 'popular_items' => __( 'Popular Question Tags', 'dwqa' ),
- 'all_items' => __( 'All Question Tags', 'dwqa' ),
+ 'name' => _x( 'Question Tags', 'taxonomy general name', 'dw-question-answer' ),
+ 'singular_name' => _x( 'Question Tag', 'taxonomy singular name', 'dw-question-answer' ),
+ 'search_items' => __( 'Search Question Tags', 'dw-question-answer' ),
+ 'popular_items' => __( 'Popular Question Tags', 'dw-question-answer' ),
+ 'all_items' => __( 'All Question Tags', 'dw-question-answer' ),
'parent_item' => null,
'parent_item_colon' => null,
- 'edit_item' => __( 'Edit Question Tag', 'dwqa' ),
- 'update_item' => __( 'Update Question Tag', 'dwqa' ),
- 'add_new_item' => __( 'Add New Question Tag', 'dwqa' ),
- 'new_item_name' => __( 'New Question Tag Name', 'dwqa' ),
- 'separate_items_with_commas' => __( 'Separate question tags with commas', 'dwqa' ),
- 'add_or_remove_items' => __( 'Add or remove question tags', 'dwqa' ),
- 'choose_from_most_used' => __( 'Choose from the most used question tags', 'dwqa' ),
- 'not_found' => __( 'No question tags found.', 'dwqa' ),
- 'menu_name' => __( 'Question Tags', 'dwqa' ),
+ 'edit_item' => __( 'Edit Question Tag', 'dw-question-answer' ),
+ 'update_item' => __( 'Update Question Tag', 'dw-question-answer' ),
+ 'add_new_item' => __( 'Add New Question Tag', 'dw-question-answer' ),
+ 'new_item_name' => __( 'New Question Tag Name', 'dw-question-answer' ),
+ 'separate_items_with_commas' => __( 'Separate question tags with commas', 'dw-question-answer' ),
+ 'add_or_remove_items' => __( 'Add or remove question tags', 'dw-question-answer' ),
+ 'choose_from_most_used' => __( 'Choose from the most used question tags', 'dw-question-answer' ),
+ 'not_found' => __( 'No question tags found.', 'dw-question-answer' ),
+ 'menu_name' => __( 'Question Tags', 'dw-question-answer' ),
);
$args = array(
@@ -281,7 +263,7 @@ public function register_taxonomy() {
) );
if ( empty( $cats ) ) {
- wp_insert_term( __( 'Questions', 'dwqa' ), $this->get_slug() . '_category' );
+ wp_insert_term( __( 'Questions', 'dw-question-answer' ), $this->get_slug() . '_category' );
}
// global $dwqa;
@@ -291,7 +273,7 @@ public function register_taxonomy() {
// ADD NEW COLUMN
public function columns_head( $defaults ) {
if ( isset( $_GET['post_type'] ) && esc_html( $_GET['post_type'] ) == $this->get_slug() ) {
- $defaults['info'] = __( 'Info', 'dwqa' );
+ $defaults['info'] = __( 'Info', 'dw-question-answer' );
$defaults = dwqa_array_insert( $defaults, array( 'question-category' => 'Category', 'question-tag' => 'Tags' ), 1 );
}
return $defaults;
@@ -302,9 +284,9 @@ public function columns_content( $column_name, $post_ID ) {
switch ( $column_name ) {
case 'info':
echo ucfirst( get_post_meta( $post_ID, '_dwqa_status', true ) ) . ' ';
- echo ''.dwqa_question_answers_count( $post_ID ) . ' '.__( 'answered', 'dwqa' ) . ' ';
- echo ''.dwqa_vote_count( $post_ID ).' '.__( 'voted', 'dwqa' ) . ' ';
- echo ''.dwqa_question_views_count( $post_ID ).' '.__( 'views', 'dwqa' ) . ' ';
+ echo ''.dwqa_question_answers_count( $post_ID ) . ' '.__( 'answered', 'dw-question-answer' ) . ' ';
+ echo ''.dwqa_vote_count( $post_ID ).' '.__( 'voted', 'dw-question-answer' ) . ' ';
+ echo ''.dwqa_question_views_count( $post_ID ).' '.__( 'views', 'dw-question-answer' ) . ' ';
break;
case 'question-category':
$terms = wp_get_post_terms( $post_ID, 'dwqa-question_category' );
@@ -425,7 +407,7 @@ public function get_questions_permalink() {
public function stick_question() {
check_ajax_referer( '_dwqa_stick_question', 'nonce' );
if ( ! isset( $_POST['post'] ) ) {
- wp_send_json_error( array( 'message' => __( 'Invalid Post', 'dwqa' ) ) );
+ wp_send_json_error( array( 'message' => __( 'Invalid Post', 'dw-question-answer' ) ) );
}
$question = get_post( intval( $_POST['post'] ) );
@@ -460,7 +442,7 @@ public function admin_posts_filter_restrict_manage_posts() {
//only add filter to post type you want
if ( 'dwqa-question' == $type ) {
?>
- >
+ >
__( 'Hello, Are you cheating huh?', 'dwqa' )
+ 'message' => __( 'Hello, Are you cheating huh?', 'dw-question-answer' )
) );
}
if ( ! isset( $_POST['question'] ) ) {
wp_send_json_error( array(
- 'message' => __( 'Question is not valid','dwqa' )
+ 'message' => __( 'Question is not valid','dw-question-answer' )
) );
}
@@ -515,12 +497,12 @@ public function delete_question() {
} else {
wp_send_json_error( array(
'question' => $question->ID,
- 'message' => __( 'Delete Action was failed','dwqa' )
+ 'message' => __( 'Delete Action was failed','dw-question-answer' )
) );
}
} else {
wp_send_json_error( array(
- 'message' => __( 'You do not have permission to delete this question','dwqa' )
+ 'message' => __( 'You do not have permission to delete this question','dw-question-answer' )
) );
}
}
@@ -530,10 +512,15 @@ public function hook_on_remove_question( $post_id ) {
$answers = wp_cache_get( 'dwqa-answers-for-' . $post_id, 'dwqa' );
if ( false == $answers ) {
- global $wpdb;
- $query = "SELECT `{$wpdb->posts}`.ID FROM `{$wpdb->posts}` JOIN `{$wpdb->postmeta}` ON `{$wpdb->posts}`.ID = `{$wpdb->postmeta}`.post_id WHERE 1=1 AND `{$wpdb->postmeta}`.meta_key = '_question' AND `{$wpdb->postmeta}`.meta_value = {$post_id} AND `{$wpdb->posts}`.post_status = 'publish' AND `{$wpdb->posts}`.post_type = 'dwqa-answer'";
- $answers = $wpdb->get_results( $query );
+ $args = array(
+ 'post_type' => 'dwqa-answer',
+ 'post_parent' => $post_id,
+ 'post_per_page' => '-1',
+ 'post_status' => array('publish', 'private', 'pending')
+ );
+
+ $answers = get_posts($args);
wp_cache_set( 'dwqa-answers-for'.$post_id, $answers, 'dwqa', 21600 );
}
@@ -572,96 +559,6 @@ public function do_this_hourly() {
}
}
}
-
- public function prepare_archive_posts() {
- global $wp_query,$dwqa_general_settings;
-
- $posts_per_page = isset( $dwqa_general_settings['posts-per-page'] ) ? $dwqa_general_settings['posts-per-page'] : 5;
- $filter = isset( $_GET['filter'] ) && !empty( $_GET['filter'] ) ? $_GET['filter'] : 'all';
- $query = array(
- 'post_type' => 'dwqa-question',
- 'posts_per_page' => $posts_per_page,
- 'orderby' => 'modified',
- );
-
- $cat = get_query_var( 'dwqa-question_category' ) ? get_query_var( 'dwqa-question_category' ) : false;
- if ( $cat ) {
- $query['tax_query'][] = array(
- 'taxonomy' => 'dwqa-question_category',
- 'field' => 'slug',
- 'terms' => $cat
- );
- }
-
- $tag = get_query_var( 'dwqa-question_tag' ) ? get_query_var( 'dwqa-question_tag' ) : false;
- if ( $tag ) {
- $query['tax_query'][] = array(
- 'taxonomy' => 'dwqa-question_tag',
- 'field' => 'slug',
- 'terms' => $tag
- );
- }
- $paged = get_query_var( 'paged' );
- $query['paged'] = $paged ? $paged : 1;
- $sticky_questions = get_option( 'dwqa_sticky_questions' );
-
- if ( $sticky_questions ) {
- $query['post__not_in'] = $sticky_questions;
- }
-
- $query['post_status'] = array( 'publish', 'private', 'pending' );
-
- switch ( $filter ) {
- case 'replied':
- $query['meta_query'][] = array(
- 'key' => '_dwqa_status',
- 'value' => array( 'open', 're-open', 'pending', 'answered' ),
- 'compare' => 'IN',
- );
- break;
-
- case 'resolved':
- $query['meta_query'][] = array(
- 'key' => '_dwqa_status',
- 'value' => array( 'resolved' ),
- 'compare' => 'IN',
- );
- break;
-
- case 'closed':
- $query['meta_query'][] = array(
- 'key' => '_dwqa_status',
- 'value' => array( 'closed' ),
- 'compare' => 'IN',
- );
- break;
-
- case 'overdue':
- case 'unanswered':
- case 'new-comment':
- $query['meta_query'][] = array(
- 'key' => '_dwqa_status',
- 'value' => array( 'open', 're-open', 'pending' ),
- 'compare' => 'IN',
- );
- break;
-
- case 'queue':
- $query['meta_query'][] = array(
- 'key' => '_dwqa_status',
- 'value' => array( 'pending' ),
- 'compare' => 'IN',
- );
- break;
- }
-
- query_posts( $query );
- }
-
- public function after_archive_posts() {
- wp_reset_query();
- wp_reset_postdata();
- }
}
?>
diff --git a/inc/Rewrite.php b/inc/Rewrite.php
index 53ef1dd7..12242aad 100644
--- a/inc/Rewrite.php
+++ b/inc/Rewrite.php
@@ -11,7 +11,7 @@ function update_term_rewrite_rules() {
$options = get_option( 'dwqa_options' );
$page_id = $options['pages']['archive-question'];
- $question_list_page = get_page( $page_id );
+ $question_list_page = get_post( $page_id );
$rewrite_category = isset( $options['question-category-rewrite'] ) ? sanitize_title( $options['question-category-rewrite'] ) : 'question-category';
$rewrite_tag = isset( $options['question-tag-rewrite'] ) ? sanitize_title( $options['question-tag-rewrite'] ) : 'question-tag';
diff --git a/inc/Session.php b/inc/Session.php
index ad25cca3..2fc269ad 100644
--- a/inc/Session.php
+++ b/inc/Session.php
@@ -65,7 +65,7 @@ public function set( $key, $value ) {
public function add( $message, $type = 'success', $comment = false ) {
if ( ! did_action( 'init' ) ) {
- _doing_it_wrong( __FUNCTION__, __( 'This function should not be called before init.', 'dwqa' ), '1.4.0' );
+ _doing_it_wrong( __FUNCTION__, __( 'This function should not be called before init.', 'dw-question-answer' ), '1.4.0' );
return;
}
@@ -82,7 +82,7 @@ public function add( $message, $type = 'success', $comment = false ) {
public function clear() {
if ( ! did_action( 'init' ) ) {
- _doing_it_wrong( __FUNCTION__, __( 'This function should not be called before init.', 'dwqa' ), '1.4.0' );
+ _doing_it_wrong( __FUNCTION__, __( 'This function should not be called before init.', 'dw-question-answer' ), '1.4.0' );
return;
}
@@ -92,7 +92,7 @@ public function clear() {
public function print_notices( $comment = false ) {
if ( ! did_action( 'init' ) ) {
- _doing_it_wrong( __FUNCTION__, __( 'This function should not be called before init.', 'dwqa' ), '1.4.0' );
+ _doing_it_wrong( __FUNCTION__, __( 'This function should not be called before init.', 'dw-question-answer' ), '1.4.0' );
return;
}
@@ -115,7 +115,7 @@ public function print_notices( $comment = false ) {
public function count( $type = '', $comment = false ) {
if ( ! did_action( 'init' ) ) {
- _doing_it_wrong( __FUNCTION__, __( 'This function should not be called before init.', 'dwqa' ), '1.4.0' );
+ _doing_it_wrong( __FUNCTION__, __( 'This function should not be called before init.', 'dw-question-answer' ), '1.4.0' );
return;
}
diff --git a/inc/Settings.php b/inc/Settings.php
index 8fc42dd8..da895cad 100644
--- a/inc/Settings.php
+++ b/inc/Settings.php
@@ -5,7 +5,7 @@ function dwqa_question_registration_setting_display() {
global $dwqa_general_settings;
?>
id="dwqa_option_answer_registation">
-
+
'dwqa_options[pages][archive-question]',
- 'show_option_none' => __( 'Select Archive Question Page','dwqa' ),
+ 'show_option_none' => __( 'Select Archive Question Page','dw-question-answer' ),
'option_none_value' => 0,
'selected' => $archive_question_page,
) );
- ?>
+ ?>[dwqa-list-questions] short code must be on this page.','dw-question-answer' ) ?>
'.__( 'hours','dwqa' ).'( ? ) ';
+ echo ' '.__( 'hours','dw-question-answer' ).'( ? )
';
}
function dwqa_question_overdue_time_frame_display() {
global $dwqa_general_settings;
- echo ' '.__( 'days','dwqa' ).'( ? )
';
+ echo ' '.__( 'days','dw-question-answer' ).'( ? )
';
}
function dwqa_submit_question_page_display(){
@@ -44,12 +44,12 @@ function dwqa_submit_question_page_display(){
'dwqa_options[pages][submit-question]',
- 'show_option_none' => __( 'Select Submit Question Page','dwqa' ),
+ 'show_option_none' => __( 'Select Submit Question Page','dw-question-answer' ),
'option_none_value' => 0,
'selected' => $submit_question_page,
) );
- ?>
-
+ ?>
+ [dwqa-submit-question-form] short code must be on this page.','dw-question-answer' ) ?>
'dwqa_options[pages][404]',
- 'show_option_none' => __( 'Select 404 DWQA Page','dwqa' ),
+ 'show_option_none' => __( 'Select 404 DWQA Page','dw-question-answer' ),
'option_none_value' => 0,
'selected' => $submit_question_page,
) );
?>
-
+
'dwqa_options[subscribe][email-template]',
+ 'textarea_name' => 'dwqa_options[subscribe][email-template]'
) );
}
function dwqa_subscrible_email_logo_display(){
+ wp_enqueue_media();
?>
-
-
-
-
-
- ';
-}
-
-
-
-
-/**
- * A ReCaptchaResponse is returned from recaptcha_check_answer()
- */
-if ( ! class_exists('ReCaptchaResponse') ) {
- class ReCaptchaResponse {
- var $is_valid;
- var $error;
- }
-}
-
-
-/**
- * Calls an HTTP POST function to verify if the user's guess was correct
- * @param string $privkey
- * @param string $remoteip
- * @param string $challenge
- * @param string $response
- * @param array $extra_params an array of extra variables to post to the server
- * @return ReCaptchaResponse
- */
-function recaptcha_check_answer ($privkey, $remoteip, $challenge, $response, $extra_params = array())
-{
- if ($privkey == null || $privkey == '') {
- die ("To use reCAPTCHA you must get an API key from https://www.google.com/recaptcha/admin/create ");
- }
-
- if ($remoteip == null || $remoteip == '') {
- die ("For security reasons, you must pass the remote ip to reCAPTCHA");
- }
-
-
-
- //discard spam submissions
- if ($challenge == null || strlen($challenge) == 0 || $response == null || strlen($response) == 0) {
- $recaptcha_response = new ReCaptchaResponse();
- $recaptcha_response->is_valid = false;
- $recaptcha_response->error = 'incorrect-captcha-sol';
- return $recaptcha_response;
- }
-
- $response = _recaptcha_http_post (RECAPTCHA_VERIFY_SERVER, "/recaptcha/api/verify",
- array (
- 'privatekey' => $privkey,
- 'remoteip' => $remoteip,
- 'challenge' => $challenge,
- 'response' => $response
- ) + $extra_params
- );
-
- $answers = explode ("\n", $response [1]);
- $recaptcha_response = new ReCaptchaResponse();
-
- if (trim ($answers [0]) == 'true') {
- $recaptcha_response->is_valid = true;
- }
- else {
- $recaptcha_response->is_valid = false;
- $recaptcha_response->error = $answers [1];
- }
- return $recaptcha_response;
-
-}
-
-/**
- * gets a URL where the user can sign up for reCAPTCHA. If your application
- * has a configuration page where you enter a key, you should provide a link
- * using this function.
- * @param string $domain The domain where the page is hosted
- * @param string $appname The name of your application
- */
-function recaptcha_get_signup_url ($domain = null, $appname = null) {
- return "https://www.google.com/recaptcha/admin/create?" . _recaptcha_qsencode (array ('domains' => $domain, 'app' => $appname));
-}
-
-function _recaptcha_aes_pad($val) {
- $block_size = 16;
- $numpad = $block_size - (strlen ($val) % $block_size);
- return str_pad($val, strlen ($val) + $numpad, chr($numpad));
-}
-
-/* Mailhide related code */
-
-function _recaptcha_aes_encrypt($val,$ky) {
- if (! function_exists ("mcrypt_encrypt")) {
- die ("To use reCAPTCHA Mailhide, you need to have the mcrypt php module installed.");
- }
- $mode=MCRYPT_MODE_CBC;
- $enc=MCRYPT_RIJNDAEL_128;
- $val=_recaptcha_aes_pad($val);
- return mcrypt_encrypt($enc, $ky, $val, $mode, "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0");
-}
-
-
-function _recaptcha_mailhide_urlbase64 ($x) {
- return strtr(base64_encode ($x), '+/', '-_');
-}
-
-/* gets the reCAPTCHA Mailhide url for a given email, public key and private key */
-function recaptcha_mailhide_url($pubkey, $privkey, $email) {
- if ($pubkey == '' || $pubkey == null || $privkey == "" || $privkey == null) {
- die ("To use reCAPTCHA Mailhide, you have to sign up for a public and private key, " .
- "you can do so at http://www.google.com/recaptcha/mailhide/apikey ");
- }
-
-
- $ky = pack('H*', $privkey);
- $cryptmail = _recaptcha_aes_encrypt ($email, $ky);
-
- return "http://www.google.com/recaptcha/mailhide/d?k=" . $pubkey . "&c=" . _recaptcha_mailhide_urlbase64 ($cryptmail);
-}
-
-/**
- * gets the parts of the email to expose to the user.
- * eg, given johndoe@example,com return ["john", "example.com"].
- * the email is then displayed as john...@example.com
- */
-function _recaptcha_mailhide_email_parts ($email) {
- $arr = preg_split("/@/", $email );
-
- if (strlen ($arr[0]) <= 4) {
- $arr[0] = substr ($arr[0], 0, 1);
- } else if (strlen ($arr[0]) <= 6) {
- $arr[0] = substr ($arr[0], 0, 3);
- } else {
- $arr[0] = substr ($arr[0], 0, 4);
- }
- return $arr;
-}
-
-/**
- * Gets html to display an email address given a public an private key.
- * to get a key, go to:
- *
- * http://www.google.com/recaptcha/mailhide/apikey
- */
-function recaptcha_mailhide_html($pubkey, $privkey, $email) {
- $emailparts = _recaptcha_mailhide_email_parts ($email);
- $url = recaptcha_mailhide_url ($pubkey, $privkey, $email);
-
- return htmlentities($emailparts[0]) . "... @" . htmlentities ($emailparts [1]);
-
-}
-
-
-?>
diff --git a/readme.txt b/readme.txt
index 03a69c91..0e7131d1 100644
--- a/readme.txt
+++ b/readme.txt
@@ -2,8 +2,8 @@
Contributors: designwall, Farid-Gh, scheunemann, gciprian, Ahmet Kolcu, Astrotenko Roman, David Robles, Nidhal Naji, developez, markhall1971
Tags: question, answer, support, quora, stackoverflow
Requires at least: 3.0.1
-Tested up to: 4+
-Stable tag: 1.4.0
+Tested up to: 5.2.2
+Stable tag: 1.5.7
License: GPLv3
License URI: http://www.gnu.org/licenses/gpl-3.0.html
@@ -20,7 +20,7 @@ DW Question and Answer is a WordPress plugin which builds a complete Question &
* Notification Email system
* Instant search by keywords
* 11+ languages supported
-* reCAPTCHA supported
+* Captcha supported
* Shortcodes available
* Private/ Public for Question and Answer
* Questions / Answers follow function
@@ -84,6 +84,122 @@ Visit our [Github](https://github.com/designwall/dw-question-answer) project or
5. Back-end settings
== Changelog ==
+= 1.5.7 =
+* Fix: Upgrade new version not showing answer
+
+= 1.5.6 =
+* Fix: Question filter on buddypress tab
+* Fix: Remove sanitize_title in Notification
+* Fix: Remove old function & compatible php 7.2
+
+= 1.5.5 =
+* Fix: Fix bug email
+* Fix: Fix Permission
+
+= 1.5.4 =
+* Update: Chang text domain to dw-question-answer
+* Update: Update pot file
+* Fix: Fix paginate link shortcode category
+* Fix: Fix count posts
+* Fix: Fix error on singular dwqa answer
+
+= 1.5.3 =
+* Update: Optimize speed
+* Fix: Fix error singular function
+* Fix: Fix human time diff
+
+= 1.5.2 =
+* New: Add option delay email
+
+= 1.5.1 =
+* Fix: Fix search page
+* Fix: Fix notice user
+* Fix: Fix vote best answer
+
+= 1.5.0 =
+* Fix: Fix bug with php 7.2
+
+= 1.4.9 =
+* Fix: Fix bug count vote in post_status private
+* Fix: Fix bug with arabic language
+
+= 1.4.8 =
+* New: Integrate yoast breadscrumb
+* Fix: Fix empty answer integrate buddypress
+* Fix: Fix comment vote
+* Fix: Remove function get_page
+
+= 1.4.7 =
+* New: Integrate Akismet
+* Fix: Fix save permissions
+* Fix: Empty file assets Akismet
+
+= 1.4.6 =
+* New: allows anonymous users to vote
+* New: add Setting time to auto close the questions
+* New: integrate buddypress plugin
+* New: Update languages RU, IT
+* Fix: fix notification
+
+= 1.4.5 =
+* New: Short-code list question by category [dwqa-list-questions category="question"]
+* New: Support template from child theme
+* Tweak: Add some filter
+* Fix: Display name in Latest Questions
+* Fix: Fix some issue in Notifications
+* Fix: Time of question and answer show not correctly
+* Fix: Addressed some security issues
+
+= 1.4.4 =
+* Compatible with Genesis Framework, Advanced Ads, Facebook Comments
+* New: Support RTL languages
+* Tweak: update main file
+* Tweak: Name and Email fields in submit question and answer is require fields
+* Fix: Don't show question listing when use the_excerpt() function
+
+= 1.4.3.4 =
+* Fix: Fix cannot format text
+
+= 1.4.3.3 =
+* Fix: Addressed some security issues
+
+= 1.4.3.2 =
+* Quick fix
+
+= 1.4.3.1 =
+* Quick fix and update some language file.
+
+= 1.4.3 =
+* Tweak: Update language file
+* Fix: Addressed some security issues
+
+= 1.4.2.3 =
+* Fix: Addressed some security issues
+
+= 1.4.2.2 =
+* Tweak: flush rewrite rule after active or upgrade plugin
+* Fix: Fatal error in comment
+
+= 1.4.2.1 =
+* Quick fix
+
+= 1.4.2 =
+* Tweak: Update Language Files
+* New: Option show all answers on a single question page
+* New: Option show status icon on question list page
+* New: Add function pick best answer
+* Fix: Some string cannot translate
+* Fix: Fix losing data when saving changes.
+* Fix: Display name of person instead of anonymous in question and comment
+
+
+= 1.4.1 =
+* Tweak: Update Language Files
+* Tweak: Update Swedish Language Files
+* New: Display name of the person instead of Anonymous
+* Fix: Some string cannot translate
+* Fix: Widget issue
+* Fix: Improvement style for mobile and tablet
= 1.4.0 =
* New: Template Structure Updates
diff --git a/templates/answer-submit-form.php b/templates/answer-submit-form.php
index 58fe7b48..d019f139 100644
--- a/templates/answer-submit-form.php
+++ b/templates/answer-submit-form.php
@@ -3,35 +3,40 @@
* The template for displaying answer submit form
*
* @package DW Question & Answer
- * @since DW Question & Answer 1.4.0
+ * @since DW Question & Answer 1.4.3
*/
?>