function widget($args, $instance) { extract($args, EXTR_SKIP); $instance = wp_parse_args($instance, array('title' => __('Latest Questions', 'dwqa'), 'number' => 5)); echo $before_widget; echo $before_title; echo $instance['title']; echo $after_title; $args = array('posts_per_page' => $instance['number'], 'order' => 'DESC', 'orderby' => 'post_date', 'post_type' => 'dwqa-question', 'suppress_filters' => false); $questions = new WP_Query($args); if ($questions->have_posts()) { echo '<div class="dwqa-popular-questions">'; echo '<ul>'; while ($questions->have_posts()) { $questions->the_post(); echo ' <li><a href="' . get_permalink() . '" class="question-title">' . get_the_title() . '</a> ' . __('asked by', 'dwqa') . ' ' . (dwqa_is_anonymous(get_the_ID()) ? __('Anonymous', 'dwqa') : get_the_author_link()) . ', ' . human_time_diff(get_the_time('U'), current_time('timestamp')) . ' ago'; '</li>'; } echo '</ul>'; echo '</div>'; } wp_reset_query(); wp_reset_postdata(); echo $after_widget; }
function dwqa_restrict_single_question($posts) { global $wp_query, $wpdb, $dwqa_options; if (is_user_logged_in()) { return $posts; } //user is not logged if (!is_single()) { return $posts; } //this is a single post if (!$wp_query->is_main_query()) { return $posts; } //this is the main query if ($wp_query->post_count) { return $posts; } if (!isset($wp_query->query['post_type']) || $wp_query->query['post_type'] != 'dwqa-question') { return $posts; } if (isset($wp_query->query['name']) && !$posts) { $question = get_page_by_path($wp_query->query['name'], OBJECT, 'dwqa-question'); } elseif (isset($wp_query->query['p']) && !$posts) { $question = get_post($wp_query->query['p']); } elseif (!empty($posts)) { $question = $posts[0]; } else { return dwqa_get_warning_page(); } //this is a question which was submitted by anonymous user if (!dwqa_is_anonymous($question->ID)) { if (!$posts) { return dwqa_get_warning_page(); } return $posts; } else { //This is a pending question if ('pending' == get_post_status($question->ID) || 'private' == get_post_status($question->ID)) { $anonymous_author_view = get_post_meta($question->ID, '_anonymous_author_view', true); $anonymous_author_view = $anonymous_author_view ? $anonymous_author_view : 0; if ($anonymous_author_view < 3) { // Allow to read question right after this was added $questions[] = $question; $anonymous_author_view++; update_post_meta($question->ID, '_anonymous_author_view', $anonymous_author_view); return $questions; } else { return dwqa_get_warning_page(); } } } return $posts; }
function dwqa_get_latest_action_date($question = false, $before = '<span>', $after = '</span>') { if (!$question) { $question = get_the_ID(); } $message = ''; $latest_answer = dwqa_get_latest_answer($question); $post_id = $latest_answer ? $latest_answer->ID : $question; $author_id = get_post_field('post_author', $post_id); if ($author_id == 0 || dwqa_is_anonymous($post_id)) { $author_link = __('Anonymous', 'dwqa'); } else { $display_name = get_the_author_meta('display_name', $author_id); $author_link = sprintf('<span class="dwqa-author"><span class="dwqa-user-avatar">%4$s</span> <a href="%1$s" title="%2$s" rel="author">%3$s</a></span>', get_author_posts_url($author_id), esc_attr(sprintf(__('Posts by %s'), $display_name)), $display_name, get_avatar($author_id, 12)); } if ($latest_answer) { $date = dwqa_human_time_diff(strtotime($latest_answer->post_date), false, get_option('date_format')); return sprintf(__('%s answered <span class="dwqa-date">%s</span>', 'dwqa'), $author_link, $date); } return sprintf(__('%s asked <span class="dwqa-date">%s</span>', 'dwqa'), $author_link, get_the_date()); }
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); } } } }
echo $current_user->ID == $post->post_author ? __('Your question has been submitted and is currently awaiting approval', 'dwqa') : __('This question is currently awaiting approval', 'dwqa'); ?> </div> <?php } ?> <?php dwqa_question_meta_button($post_id); ?> <div class="dwqa-author"> <?php echo get_avatar($post->post_author, 64, false); ?> <span class="author"> <?php if (dwqa_is_anonymous($post->ID)) { ?> <?php _e('Anonymous', 'dwqa'); ?> <?php } else { ?> <?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')); ?> <?php } ?> </span><!-- Author Info --> <span class="dwqa-date">
/** * Get username * * @param int $post_id * @return string * @since 1.4.0 */ function dwqa_get_author($post_id = false) { if (!$post_id) { $post_id = get_the_ID(); } $display_name = false; if (dwqa_is_anonymous($post_id)) { $anonymous_name = get_post_meta($post_id, '_dwqa_anonymous_name', true); if ($anonymous_name) { $display_name = $anonymous_name; } else { $display_name = __('Anonymous', 'dwqa'); } } else { $user_id = get_post_field('post_author', $post_id); $display_name = get_the_author_meta('display_name', $user_id); } return apply_filters('dwqa_get_author', $display_name, $post_id); }
echo 'private' == get_post_status() ? '<i class="fa fa-lock"></i> ' . __('Private', 'dwqa') : '<i class="fa fa-globe"></i> ' . __('Public', 'dwqa'); ?> </span> <?php } ?> </div> </div> <div class="dwqa-author"> <?php echo get_avatar(get_the_author_meta('ID'), 64); ?> <span class="author"> <?php if (!dwqa_is_anonymous($answer_id)) { the_author_posts_link(); ?> <?php if (user_can($answer->post_author, 'edit_posts')) { echo ' <strong>⋅</strong> <span class="dwqa-label dwqa-staff">' . __('Staff', 'dwqa') . '</span>'; } ?> <?php } else { _e('Anonymous', 'dwqa'); } ?> </span> <span class="dwqa-date">
function dwqa_get_latest_action_date($question = false, $before = '<span>', $after = '</span>') { if (!$question) { $question = get_the_ID(); } global $post, $dwqa_general_settings; $message = ''; $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); $post_id = $latest_answer ? $latest_answer->ID : $question; $author_id = $post->post_author; if ($author_id == 0 || dwqa_is_anonymous($post_id)) { $anonymous_name = get_post_meta($post_id, '_dwqa_anonymous_name', true); $author_email = get_post_meta($post_id, '_dwqa_anonymous_email', true); if ($anonymous_name) { $display_name = $anonymous_name . ' '; } else { $display_name = __('Anonymous', 'dwqa') . ' '; } } else { $display_name = get_the_author_meta('display_name', $author_id); $author_url = $question_list_link ? add_query_arg(array('user-question' => get_the_author_meta('user_login', $author_id)), $question_list_link) : the_author_posts_link($author_id); $author_email = get_the_author_meta('user_email', $author_id); } $author_avatar = wp_cache_get('avatar_of_' . $author_id, 'dwqa'); if (false === $author_avatar) { $author_avatar = get_avatar($author_email, 48); wp_cache_set('avatar_of_' . $author_email, $author_avatar, 'dwqa', 60 * 60 * 24 * 7); } $author_display = dwqa_is_anonymous() ? $display_name : sprintf('<a href="%1$s" title="%2$s" rel="author">%3$s</a>', $author_url, esc_attr(sprintf(__('Posts by %s'), $display_name)), $display_name); $author_link = sprintf('<span class="dwqa-author"><span class="dwqa-user-avatar">%2$s</span>%1$s</span>', $author_display, $author_avatar); if ($last_activity_date && $post->last_activity_type == 'answer') { $date = human_time_diff(strtotime($last_activity_date), current_time('timestamp')); return sprintf(__('%s answered <span class="dwqa-date">%s</span> ago', 'dwqa'), $author_link, $date); } if ('dwqa-answer' == get_post_type($question)) { return sprintf(__('%s answered <span class="dwqa-date">%s</span> ago', 'dwqa'), $author_link, human_time_diff(get_the_time('U'), current_time('timestamp'))); } return sprintf(__('%s asked <span class="dwqa-date">%s</span> ago', 'dwqa'), $author_link, human_time_diff(get_the_time('U'), current_time('timestamp'))); }
?> " title="<?php echo esc_attr(sprintf(__('Permalink to %s', 'dwqa'), the_title_attribute('echo=0'))); ?> " rel="bookmark"> <?php the_title(); ?> </a> <div class="dwqa-meta"> <?php dwqa_question_print_status($post_id); ?> <?php global $authordata; if (!dwqa_is_anonymous($post_id)) { $author_link = sprintf('<a href="%1$s" title="%2$s" rel="author">%3$s</a>', get_author_posts_url($authordata->ID, $authordata->user_nicename), esc_attr(sprintf(__('Posts by %s'), get_the_author())), dw_strip_email_to_display(get_the_author())); } else { $author_link = __('Anonymous', 'dwqa'); } echo __('by', 'dwqa') . ' ' . $author_link; ?> <strong>⋅</strong> <span><?php echo get_the_date(); ?> </span> <?php echo get_the_term_list($post_id, 'dwqa-question_category', ' <strong>⋅</strong> <span>Category: ', ', ', '</span>'); ?>
function dwqa_get_latest_action_date($question = false, $before = '<span>', $after = '</span>') { if (!$question) { $question = get_the_ID(); } global $post; $message = ''; $latest_answer = dwqa_get_latest_answer($question); $last_activity_date = $latest_answer ? $latest_answer->post_date : get_post_field('post_date', $question); $post_id = $latest_answer ? $latest_answer->ID : $question; $author_id = $post->post_author; if ($author_id == 0 || dwqa_is_anonymous($post_id)) { $anonymous_name = get_post_meta($post_id, '_dwqa_anonymous_name', true); if ($anonymous_name) { $author_link = $anonymous_name . ' '; } else { $author_link = __('Anonymous', 'dwqa') . ' '; } } else { $display_name = get_the_author_meta('display_name', $author_id); $author_url = get_author_posts_url($author_id); $author_avatar = wp_cache_get('avatar_of_' . $author_id, 'dwqa'); if (false === $author_avatar) { $author_avatar = get_avatar($author_id, 12); wp_cache_set('avatar_of_' . $author_id, $author_avatar, 'dwqa', 60 * 60 * 24 * 7); } $author_link = sprintf('<span class="dwqa-author">%3$s</span>', $author_url, esc_attr(sprintf(__('Posts by %s'), $display_name)), $display_name, $author_avatar); } if ($last_activity_date && $post->last_activity_type == 'answer') { $date = dwqa_human_time_diff(strtotime($last_activity_date), false, get_option('date_format')); return sprintf(__('%s respondida <span class="dwqa-date">%s</span>', 'dwqa'), $author_link, $date); } return sprintf(__('%s perguntou <span class="dwqa-date">%s</span>', 'dwqa'), $author_link, get_the_date()); }