public function new_comment_notify($comment_id, $comment) { $parent = get_post_type($comment->comment_post_ID); //Admin email $admin_email = get_bloginfo('admin_email'); $enable_send_copy = get_option('dwqa_subscrible_send_copy_to_admin'); 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); } elseif ($parent == 'dwqa-answer') { $enabled = get_option('dwqa_subscrible_enable_new_comment_answer_notification', 1); } if (!$enabled) { return false; } $post_parent = get_post($comment->comment_post_ID); if (dwqa_is_anonymous($comment->comment_post_ID)) { $post_parent_email = get_post_meta($comment->comment_post_ID, '_dwqa_anonymous_email', true); if (!is_email($post_parent_email)) { return false; } } else { // if user is not the author of question/answer, add user to followers list if ($post_parent->post_author != $comment->user_id) { if (!dwqa_is_followed($post_parent->ID, $comment->user_id)) { add_post_meta($post_parent->ID, '_dwqa_followers', $comment->user_id); } } $post_parent_email = get_the_author_meta('user_email', $post_parent->post_author); } // 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"; } 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')); $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')); $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 = get_post($question_id); } $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', $comment->user_id), $subject); if (!$message) { return false; } // logo replace $logo = get_option('dwqa_subscrible_email_logo', ''); $logo = $logo ? '<img src="' . $logo . '" alt="' . get_bloginfo('name') . '" style="max-width: 100%; height: auto;" />' : ''; $subject = str_replace('{comment_author}', get_the_author_meta('display_name', $comment->user_id), $subject); $message = str_replace('{site_logo}', $logo, $message); $message = str_replace('{question_link}', get_permalink($question->ID), $message); $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}', 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); $message = str_replace('{site_description}', get_bloginfo('description'), $message); $message = str_replace('{site_url}', site_url(), $message); if ($parent == 'dwqa-question') { $enable_notify = get_option('dwqa_subscrible_enable_new_comment_question_followers_notify', true); } else { $enable_notify = get_option('dwqa_subscrible_enable_new_comment_answer_followers_notification', true); } if ($enable_notify) { //Follower email task $followers = get_post_meta($post_parent->ID, '_dwqa_followers'); $comment_email = get_the_author_meta('user_email', $comment->user_id); 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')); $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')); $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); $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}', get_the_author_meta('display_name', $comment->user_id), $follow_subject); $follow_subject = str_replace('{comment_author}', get_the_author_meta('display_name', $comment->user_id), $follow_subject); $message_to_follower = str_replace('{site_logo}', $logo, $message_to_follower); $message_to_follower = str_replace('{question_link}', get_permalink($question->ID), $message_to_follower); $comment_link = get_permalink($question->ID) . '#comment-' . $comment_id; $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}', 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)) { foreach ($followers as $follower) { $follower = (int) $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 != $post_parent_email && $follow_email != $comment_email) { $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); } } } } } } if ($post_parent->post_author != $comment->user_id) { wp_mail($post_parent_email, $subject, $message, $headers); if ($enable_send_copy && $admin_email != $post_parent_email) { wp_mail($admin_email, $subject, $message, $headers); } } } }
function dwqa_question_meta_button($post_id = false) { if (!$post_id) { $post_id = get_the_ID(); } ?> <div class="dwqa-meta"> <div class="dwqa-vote" data-type="question" data-nonce="<?php echo wp_create_nonce('_dwqa_question_vote_nonce'); ?> " data-question="<?php echo $post_id; ?> " > <a class="dwqa-vote-dwqa-btn dwqa-vote-up" data-vote="up" href="#" title="<?php _e('Vote Up', 'dwqa'); ?> "><?php _e('Vote Up', 'dwqa'); ?> </a> <div class="dwqa-vote-count"><?php $point = dwqa_vote_count(); echo $point > 0 ? '+' . $point : $point; ?> </div> <a class="dwqa-vote-dwqa-btn dwqa-vote-down" data-vote="down" href="#" title="<?php _e('Vote Down', 'dwqa'); ?> "><?php _e('Vote Down', 'dwqa'); ?> </a> </div> <?php dwqa_question_status_button($post_id); ?> <?php dwqa_question_privacy_button($post_id); ?> <?php $categories = wp_get_post_terms($post_id, 'dwqa-question_category'); ?> <?php if (!empty($categories)) { ?> <?php $cat = $categories[0]; ?> <div class="dwqa-category"> <a class="dwqa-category-name" href="<?php echo get_term_link($cat); ?> " title="<?php _e('All questions from', 'dwqa'); ?> <?php echo $cat->name; ?> "><i class="fa fa-folder-open"></i> <?php echo $cat->name; ?> </a> </div> <?php } ?> <!-- Question Categories --> <?php dwqa_question_action_buttons($post_id); ?> <?php if (is_user_logged_in()) { ?> <span data-post="<?php echo $post_id; ?> " data-nonce="<?php echo wp_create_nonce('_dwqa_follow_question'); ?> " class="dwqa-favourite <?php echo dwqa_is_followed($post_id) ? 'active' : ''; ?> " title="<?php echo dwqa_is_followed($post_id) ? __('Unfollow This Question', 'dwqa') : __('Follow This Question', 'dwqa'); ?> "><!-- add class 'active' --> <span class="dwpa_follow"><?php _e('follow', 'dwqa'); ?> </span> <span class="dwpa_following"><?php _e('following', 'dwqa'); ?> </span> <span class="dwpa_unfollow"><?php _e('unfollow', 'dwqa'); ?> </span> </span> <?php } ?> <?php if (dwqa_current_user_can('edit_question')) { ?> <span data-post="<?php echo $post_id; ?> " data-nonce="<?php echo wp_create_nonce('_dwqa_stick_question'); ?> " class="dwqa-stick-question <?php echo dwqa_is_sticky($post_id) ? 'active' : ''; ?> " title="<?php echo dwqa_is_sticky($post_id) ? __('Unpin this Question from the top', 'dwqa') : __('Pin this Question to top', 'dwqa'); ?> "><i class="fa fa-bookmark"></i></span> <?php } ?> </div> <?php }
function follow_question() { check_ajax_referer('_dwqa_follow_question', 'nonce'); if (!isset($_POST['post'])) { wp_send_json_error(array('message' => __('Invalid Post', 'dwqa'))); } $question = get_post(intval($_POST['post'])); if (is_user_logged_in()) { global $current_user; if (!dwqa_is_followed($question->ID)) { do_action('dwqa_follow_question', $question->ID, $current_user->ID); add_post_meta($question->ID, '_dwqa_followers', $current_user->ID); wp_send_json_success(array('code' => 'followed')); } else { do_action('dwqa_unfollow_question', $question->ID, $current_user->ID); delete_post_meta($question->ID, '_dwqa_followers', $current_user->ID); wp_send_json_success(array('code' => 'unfollowed')); } } else { wp_send_json_error(array('code' => 'not-logged-in')); } }
</span> <?php if (is_user_logged_in()) { ?> <span data-post="<?php echo $post_id; ?> " data-nonce="<?php echo wp_create_nonce('_dwqa_follow_question'); ?> " class="dwqa-favourite <?php echo dwqa_is_followed($post_id) ? 'active' : ''; ?> " title="<?php echo dwqa_is_followed($post_id) ? __('Unfollow This Question', 'dwqa') : __('Follow This Question', 'dwqa'); ?> "><!-- add class 'active' --> <i class="fa fa-star"></i> </span> <?php } ?> <?php if (dwqa_current_user_can('edit_question')) { ?> <span data-post="<?php echo $post_id; ?> " data-nonce="<?php echo wp_create_nonce('_dwqa_stick_question');
function dwqa_question_button_action() { $html = ''; if (is_user_logged_in()) { $followed = dwqa_is_followed() ? 'followed' : 'follow'; $text = __('Subscribe', 'dwqa'); $html .= '<label for="dwqa-favorites">'; $html .= '<input type="checkbox" id="dwqa-favorites" data-post="' . get_the_ID() . '" data-nonce="' . wp_create_nonce('_dwqa_follow_question') . '" value="' . $followed . '" ' . checked($followed, 'followed', false) . '/>'; $html .= '<span>' . $text . '</span>'; $html .= '</label>'; if (dwqa_current_user_can('edit_question')) { $html .= '<a class="dwqa_edit_question" href="' . add_query_arg(array('edit' => get_the_ID()), get_permalink()) . '">' . __('Edit', 'dwqa') . '</a> '; } if (dwqa_current_user_can('delete_question')) { $action_url = add_query_arg(array('action' => 'dwqa_delete_question', 'question_id' => get_the_ID()), admin_url('admin-ajax.php')); $html .= '<a class="dwqa_delete_question" href="' . wp_nonce_url($action_url, '_dwqa_action_remove_question_nonce') . '">' . __('Delete', 'dwqa') . '</a> '; } } echo apply_filters('dwqa_question_button_action', $html); }
public function single_question() { global $post, $current_user; $post_id = get_the_ID(); ?> <div class="dwqa-single-question"> <!-- dwqa-status-private --> <article id="question-<?php echo $post_id; ?> " <?php post_class('dwqa-question'); ?> > <header class="dwqa-header"> <h1 class="dwqa-title"><?php the_title(); ?> </h1> <div class="dwqa-meta"> <span class="dwqa-vote" data-type="question" data-nonce="<?php echo wp_create_nonce('_dwqa_question_vote_nonce'); ?> " data-question="<?php echo $post_id; ?> " > <a class="dwqa-vote-dwqa-btn dwqa-vote-up" data-vote="up" href="#" title="<?php _e('Vote Up', 'dwqa'); ?> "><?php _e('Vote Up', 'dwqa'); ?> </a> <div class="dwqa-vote-count"><?php $point = dwqa_vote_count(); echo $point > 0 ? '+' . $point : $point; ?> </div> <a class="dwqa-vote-dwqa-btn dwqa-vote-down" data-vote="down" href="#" title="<?php _e('Vote Down', 'dwqa'); ?> "><?php _e('Vote Down', 'dwqa'); ?> </a> </span> <?php if (is_user_logged_in()) { ?> <span data-post="<?php echo $post_id; ?> " data-nonce="<?php echo wp_create_nonce('_dwqa_follow_question'); ?> " class="dwqa-favourite <?php echo dwqa_is_followed($post_id) ? 'active' : ''; ?> " title="<?php echo dwqa_is_followed($post_id) ? __('Unfollow This Question', 'dwqa') : __('Follow This Question', 'dwqa'); ?> "><!-- add class 'active' --> <i class="fa fa-star"></i> </span> <?php } ?> </div> </header> <div class="dwqa-content"> <?php the_content(); ?> </div> <?php $tags = get_the_term_list($post_id, 'dwqa-question_tag', '<span class="dwqa-tag">', '</span><span class="dwqa-tag">', '</span>'); if (!empty($tags)) { ?> <div class="dwqa-tags"><?php echo $tags; ?> </div> <?php } ?> <!-- Question Tags --> <footer class="dwqa-footer"> <div class="dwqa-author"> <?php echo get_avatar($post->post_author, 32, false); ?> <span class="author"> <?php printf('<a href="%1$s" title="%2$s %3$s">%3$s</a>', get_author_posts_url(get_the_author_meta('ID')), __('Posts by', 'dwqa'), get_the_author_meta('display_name')); ?> </span><!-- Author Info --> <span class="dwqa-date"> <?php printf('<a href="%s" title="%s #%d">%s %s</a>', get_permalink(), __('Link to', 'dwqa'), $post_id, __('asked', 'dwqa'), get_the_date()); ?> </span> <!-- Question Date --> <div data-post="<?php echo $post_id; ?> " data-nonce="<?php echo wp_create_nonce('_dwqa_update_privacy_nonce'); ?> " data-type="question" class="dwqa-privacy"> <input type="hidden" name="privacy" value="<?php get_post_status(); ?> "> <span class="dwqa-current-privacy"> <?php echo 'private' == get_post_status() ? '<i class="fa fa-lock"></i> ' . __('Private', 'dwqa') : '<i class="fa fa-globe"></i> ' . __('Public', 'dwqa'); ?> </span> <?php if (dwqa_current_user_can('edit_question') || dwqa_current_user_can('edit_answer') || $post->post_author == $current_user->ID) { ?> <span class="dwqa-change-privacy"> <div class="dwqa-btn-group"> <button type="button" class="dropdown-toggle" ><i class="fa fa-caret-down"></i></button> <div class="dwqa-dropdown-menu"> <div class="dwqa-dropdown-caret"> <span class="dwqa-caret-outer"></span> <span class="dwqa-caret-inner"></span> </div> <ul role="menu"> <li title="<?php _e('Everyone can see', 'dwqa'); ?> " data-privacy="publish" <?php echo 'publish' == get_post_status() ? 'class="current"' : ''; ?> ><a href="#"><i class="fa fa-globe"></i> <?php _e('Public', 'dwqa'); ?> </a></li> <li title="<?php _e('Only Author and Administrator can see', 'dwqa'); ?> " data-privacy="private" <?php echo 'private' == get_post_status() ? 'class="current"' : ''; ?> ><a href="#" ><i class="fa fa-lock"></i> <?php _e('Private', 'dwqa'); ?> </a></li> </ul> </div> </div> </span> <?php } ?> </div><!-- post status --> </div> <?php $categories = wp_get_post_terms($post_id, 'dwqa-question_category'); if (!empty($categories)) { $cat = $categories[0]; ?> <div class="dwqa-category"> <span class="dwqa-category-title"><?php _e('Category', 'dwqa'); ?> </span> <a class="dwqa-category-name" href="<?php echo get_term_link($cat); ?> " title="<?php _e('All questions from', 'dwqa'); ?> <?php echo $cat->name; ?> "><?php echo $cat->name; ?> </a> </div> <?php } ?> <!-- Question Categories --> <?php $meta = get_post_meta($post_id, '_dwqa_status', true); if (!$meta) { $meta = 'open'; } ?> <div class="dwqa-current-status"> <span class="dwqa-status-title"><?php _e('Status', 'dwqa'); ?> </span> <span class="dwqa-status-name"><?php echo $meta; ?> </span> <?php if (dwqa_current_user_can('edit_question') || dwqa_current_user_can('edit_answer') || $current_user->ID == $post->post_author) { ?> <span class="dwqa-change-status"> <div class="dwqa-btn-group"> <button type="button" class="dropdown-toggle" ><i class="fa fa-caret-down"></i></button> <div class="dwqa-dropdown-menu" data-nonce="<?php echo wp_create_nonce('_dwqa_update_question_status_nonce'); ?> " data-question="<?php the_ID(); ?> " > <div class="dwqa-dropdown-caret"> <span class="dwqa-caret-outer"></span> <span class="dwqa-caret-inner"></span> </div> <ul role="menu" data-nonce="<?php echo wp_create_nonce('_dwqa_update_question_status_nonce'); ?> " data-question="<?php the_ID(); ?> "> <?php if ('resolved' == $meta || 'pending' == $meta || 'closed' == $meta) { ?> <li class="dwqa-re-open" data-status="re-open"> <a href="#"><i class="fa fa-reply"></i> <?php _e('Re-Open', 'dwqa'); ?> </a> </li> <?php } ?> <?php if ('closed' != $meta) { ?> <li class="dwqa-closed" data-status="closed"> <a href="#"><i class="fa fa-lock"></i> <?php _e('Closed', 'dwqa'); ?> </a> </li> <?php } ?> <?php if ('pending' != $meta && 'closed' != $meta && current_user_can('edit_posts', $post_id)) { ?> <li class="dwqa-pending" data-status="pending"> <a href="#"><i class="fa fa-question-circle"></i> <?php _e('Pending', 'dwqa'); ?> </a> </li> <?php } ?> <?php if ('resolved' != $meta && 'closed' != $meta) { ?> <li class="dwqa-resolved" data-status="resolved"> <a href="#"><i class="fa fa-check-circle-o"></i> <?php _e('Resolved', 'dwqa'); ?> </a> </li> <?php } ?> </ul> </div> </div> </span> <?php } ?> <!-- Change Question Status --> </div> </footer> <div class="dwqa-comments"> <?php comments_template(); ?> </div> </article><!-- end question --> <div id="dwqa-answers"> <?php dwqa_load_template('answers'); ?> </div><!-- end dwqa-add-answers --> </div><!-- end dwqa-single-question --> <?php }