From bf7ffa37be106a4ed70836b32bfc5b79301d700d Mon Sep 17 00:00:00 2001
From: Denver Prophit Jr
Date: Fri, 17 Nov 2017 07:15:07 -0500
Subject: [PATCH 1/6] Updates CPT post type to have featured image
Updates issue /designwall/dw-question-answer/#213 which I believe will enable featured image ability when Question is edited and saved. I'm having to go backwards into my hacks. I believe I also modified a language define or two.
---
inc/Posts/Question.php | 210 ++++++++++++++++++++++-------------------
1 file changed, 115 insertions(+), 95 deletions(-)
diff --git a/inc/Posts/Question.php b/inc/Posts/Question.php
index 12fc19dd..e582d65d 100644
--- a/inc/Posts/Question.php
+++ b/inc/Posts/Question.php
@@ -8,42 +8,42 @@ function dwqa_related_question( $question_id = false, $number = 5, $echo = true
$question_id = get_the_ID();
}
$tag_in = $cat_in = array();
- $tags = wp_get_post_terms( $question_id, 'dwqa-question_tag' );
- if ( ! empty($tags) ) {
+ $tags = wp_get_post_terms( $question_id, 'dwqa-question_tag' );
+ if ( ! empty( $tags ) ) {
foreach ( $tags as $tag ) {
$tag_in[] = $tag->term_id;
}
}
$category = wp_get_post_terms( $question_id, 'dwqa-question_category' );
- if ( ! empty($category) ) {
+ if ( ! empty( $category ) ) {
foreach ( $category as $cat ) {
$cat_in[] = $cat->term_id;
}
}
$args = array(
- 'orderby' => 'rand',
- 'post__not_in' => array($question_id),
- 'showposts' => $number,
+ 'orderby' => 'rand',
+ 'post__not_in' => array( $question_id ),
+ 'showposts' => $number,
'ignore_sticky_posts' => 1,
- 'post_type' => 'dwqa-question',
+ 'post_type' => 'dwqa-question',
);
$args['tax_query']['relation'] = 'OR';
if ( ! empty( $cat_in ) ) {
$args['tax_query'][] = array(
- 'taxonomy' => 'dwqa-question_category',
- 'field' => 'id',
- 'terms' => $cat_in,
- 'operator' => 'IN',
+ 'taxonomy' => 'dwqa-question_category',
+ 'field' => 'id',
+ 'terms' => $cat_in,
+ 'operator' => 'IN',
);
}
if ( ! empty( $tag_in ) ) {
$args['tax_query'][] = array(
- 'taxonomy' => 'dwqa-question_tag',
- 'field' => 'id',
- 'terms' => $tag_in,
- 'operator' => 'IN',
+ 'taxonomy' => 'dwqa-question_tag',
+ 'field' => 'id',
+ 'terms' => $tag_in,
+ 'operator' => 'IN',
);
}
@@ -52,8 +52,9 @@ function dwqa_related_question( $question_id = false, $number = 5, $echo = true
if ( $related_questions->have_posts() ) {
if ( $echo ) {
echo '';
- while ( $related_questions->have_posts() ) { $related_questions->the_post();
- echo ''.get_the_title().' '.__( 'asked by', 'dwqa' ).' ';
+ while ( $related_questions->have_posts() ) {
+ $related_questions->the_post();
+ echo '' . get_the_title() . ' ' . __( 'asked by', 'dwqa' ) . ' ';
the_author_posts_link();
echo ' ';
}
@@ -62,12 +63,15 @@ function dwqa_related_question( $question_id = false, $number = 5, $echo = true
}
$posts = $related_questions->posts;
wp_reset_postdata();
+
return $posts;
}
/**
* Count number of views for a questions
+ *
* @param int $question_id Question Post ID
+ *
* @return int Number of views
*/
function dwqa_question_views_count( $question_id = null ) {
@@ -92,15 +96,15 @@ class DWQA_Posts_Question extends DWQA_Posts_Base {
public function __construct() {
global $dwqa_general_settings;
- if ( !$dwqa_general_settings ) {
+ if ( ! $dwqa_general_settings ) {
$dwqa_general_settings = get_option( 'dwqa_options' );
}
$slug = isset( $dwqa_general_settings['question-rewrite'] ) ? $dwqa_general_settings['question-rewrite'] : 'question';
parent::__construct( 'dwqa-question', array(
- 'plural' => __( 'Questions', 'dwqa' ),
+ 'plural' => __( 'Questions', 'dwqa' ),
'singular' => __( 'Question', 'dwqa' ),
- 'menu' => __( 'Questions', 'dwqa' ),
- 'rewrite' => array( 'slug' => $slug, 'with_front' => false ),
+ 'menu' => __( 'Questions', 'dwqa' ),
+ 'rewrite' => array( 'slug' => $slug, 'with_front' => false ),
) );
add_action( 'manage_dwqa-question_posts_custom_column', array( $this, 'columns_content' ), 10, 2 );
@@ -109,13 +113,13 @@ public function __construct() {
add_action( 'wp_head', array( $this, 'update_view' ) );
//Ajax Get Questions Archive link
- add_action( 'wp_ajax_dwqa-get-questions-permalink', array( $this, 'get_questions_permalink') );
- add_action( 'wp_ajax_nopriv_dwqa-get-questions-permalink', array( $this, 'get_questions_permalink') );
+ add_action( 'wp_ajax_dwqa-get-questions-permalink', array( $this, 'get_questions_permalink' ) );
+ add_action( 'wp_ajax_nopriv_dwqa-get-questions-permalink', array( $this, 'get_questions_permalink' ) );
//Ajax stick question
add_action( 'wp_ajax_dwqa-stick-question', array( $this, 'stick_question' ) );
add_action( 'restrict_manage_posts', array( $this, 'admin_posts_filter_restrict_manage_posts' ) );
-
+
// Ajax Update question status
add_filter( 'parse_query', array( $this, 'posts_filter' ) );
@@ -125,9 +129,9 @@ public function __construct() {
//Prepare question content
add_filter( 'dwqa_prepare_question_content', array( $this, 'pre_content_kses' ), 10 );
- 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_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 );
}
public function init() {
@@ -135,57 +139,58 @@ public function init() {
}
public function set_supports() {
- return array( 'title', 'editor', 'comments', 'author', 'page-attributes' );
+ return array( 'title', 'editor', 'comments', 'author', 'thumbnail', 'page-attributes', 'trackbacks' );
}
public function set_rewrite() {
global $dwqa_general_settings;
- if( isset( $dwqa_general_settings['question-rewrite'] ) ) {
+ if ( isset( $dwqa_general_settings['question-rewrite'] ) ) {
return array(
- 'slug' => $dwqa_general_settings['question-rewrite'],
- 'with_front' => false,
+ 'slug' => $dwqa_general_settings['question-rewrite'],
+ 'with_front' => false
);
}
+
return array(
- 'slug' => 'question',
- 'with_front' => false,
+ 'slug' => 'question',
+ 'with_front' => false
);
}
public function get_question_rewrite() {
global $dwqa_general_settings;
- if ( !$dwqa_general_settings ) {
+ if ( ! $dwqa_general_settings ) {
$dwqa_general_settings = get_option( 'dwqa_options' );
}
- return isset( $dwqa_general_settings['question-rewrite'] ) && !empty( $dwqa_general_settings['question-rewrite'] ) ? $dwqa_general_settings['question-rewrite'] : 'question';
+ return isset( $dwqa_general_settings['question-rewrite'] ) && ! empty( $dwqa_general_settings['question-rewrite'] ) ? $dwqa_general_settings['question-rewrite'] : 'question';
}
public function get_category_rewrite() {
global $dwqa_general_settings;
- if ( !$dwqa_general_settings ) {
+ if ( ! $dwqa_general_settings ) {
$dwqa_general_settings = get_option( 'dwqa_options' );
}
- return isset( $dwqa_general_settings['question-category-rewrite'] ) && !empty( $dwqa_general_settings['question-category-rewrite'] ) ? $dwqa_general_settings['question-category-rewrite'] : 'category';
+ return isset( $dwqa_general_settings['question-category-rewrite'] ) && ! empty( $dwqa_general_settings['question-category-rewrite'] ) ? $dwqa_general_settings['question-category-rewrite'] : 'category';
}
public function get_tag_rewrite() {
global $dwqa_general_settings;
- if ( !$dwqa_general_settings ) {
+ if ( ! $dwqa_general_settings ) {
$dwqa_general_settings = get_option( 'dwqa_options' );
}
- return isset( $dwqa_general_settings['question-tag-rewrite'] ) && !empty( $dwqa_general_settings['question-tag-rewrite'] ) ? $dwqa_general_settings['question-tag-rewrite'] : 'tag';
+ return isset( $dwqa_general_settings['question-tag-rewrite'] ) && ! empty( $dwqa_general_settings['question-tag-rewrite'] ) ? $dwqa_general_settings['question-tag-rewrite'] : 'tag';
}
public function register_taxonomy() {
global $dwqa_general_settings;
- if ( !$dwqa_general_settings ) {
+ if ( ! $dwqa_general_settings ) {
$dwqa_general_settings = get_option( 'dwqa_options' );
}
@@ -222,22 +227,28 @@ 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' ),
- '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' ),
+ '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' ),
+ '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' ),
+ 'featured_image' => __( 'Featured Image', 'dwqa' ), . $names['singular'],
+ 'set_featured_image' => __( 'Set featured image', 'dwqa' ), . $names['singular'],
+ 'remove_featured_image' => __( 'Remove featured image', 'dwqa' ), . $names['singular'],
+ 'set_featured_image' => __( 'Set featured image', 'dwqa' ), . $names['singular'],
+ 'insert_into_item' => __( 'Insert into item', 'dwqa' ), . $names['singular'],
+ 'uploaded_to_this_item' => __( 'Uploaded to this item', 'dwqa' ), . $names['singular'],
);
$args = array(
@@ -249,7 +260,7 @@ public function register_taxonomy() {
'show_tagcloud' => true,
'show_ui' => true,
'query_var' => true,
- 'rewrite' => array( 'slug' => $tag_slug, 'with_front' => false, 'hierarchical' => true ),
+ 'rewrite' => array( 'slug' => $tag_slug, 'with_front' => false, 'hierarchical' => true ),
'query_var' => true,
'capabilities' => array(),
);
@@ -257,9 +268,9 @@ public function register_taxonomy() {
// Create default category for dwqa question type when dwqa plugin is actived
$cats = get_categories( array(
- 'type' => $this->get_slug(),
- 'hide_empty' => 0,
- 'taxonomy' => $this->get_slug() . '_category',
+ 'type' => $this->get_slug(),
+ 'hide_empty' => 0,
+ 'taxonomy' => $this->get_slug() . '_category',
) );
if ( empty( $cats ) ) {
@@ -274,8 +285,12 @@ public function register_taxonomy() {
public function columns_head( $defaults ) {
if ( isset( $_GET['post_type'] ) && esc_html( $_GET['post_type'] ) == $this->get_slug() ) {
$defaults['info'] = __( 'Info', 'dwqa' );
- $defaults = dwqa_array_insert( $defaults, array( 'question-category' => 'Category', 'question-tag' => 'Tags' ), 1 );
+ $defaults = dwqa_array_insert( $defaults, array(
+ 'question-category' => 'Category',
+ 'question-tag' => 'Tags'
+ ), 1 );
}
+
return $defaults;
}
@@ -284,35 +299,35 @@ 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', 'dwqa' ) . ' ';
+ echo '' . dwqa_vote_count( $post_ID ) . ' ' . __( 'voted', 'dwqa' ) . ' ';
+ echo '' . dwqa_question_views_count( $post_ID ) . ' ' . __( 'views', 'dwqa' ) . ' ';
break;
case 'question-category':
$terms = wp_get_post_terms( $post_ID, 'dwqa-question_category' );
- $i = 0;
+ $i = 0;
foreach ( $terms as $term ) {
if ( $i > 0 ) {
echo ', ';
}
- echo ''.$term->name . ' ';
- $i++;
+ echo '' . $term->name . ' ';
+ $i ++;
}
break;
case 'question-tag':
$terms = wp_get_post_terms( $post_ID, 'dwqa-question_tag' );
- $i = 0;
+ $i = 0;
foreach ( $terms as $term ) {
if ( $i > 0 ) {
echo ', ';
}
- echo '' . $term->name . ' ';
- $i++;
+ echo '' . $term->name . ' ';
+ $i ++;
}
break;
}
}
-
+
/**
* Init or increase views count for single question
* @return void
@@ -324,9 +339,9 @@ public function update_view() {
if ( is_user_logged_in() ) {
global $current_user;
//save who see this post
- $viewed = get_post_meta( $post->ID, '_dwqa_who_viewed', true );
- $viewed = ! is_array( $viewed ) ? array() : $viewed;
- $viewed[$current_user->ID] = current_time( 'timestamp' );
+ $viewed = get_post_meta( $post->ID, '_dwqa_who_viewed', true );
+ $viewed = ! is_array( $viewed ) ? array() : $viewed;
+ $viewed[ $current_user->ID ] = current_time( 'timestamp' );
}
if ( ( $refer && $refer != get_permalink( $post->ID ) ) || ! $refer ) {
@@ -348,12 +363,12 @@ public function get_questions_permalink() {
if ( isset( $_GET['params'] ) ) {
global $dwqa_options;
$params = explode( '&', sanitize_text_field( $_GET['params'] ) );
- $args = array();
+ $args = array();
if ( ! empty( $params ) ) {
foreach ( $params as $p ) {
if ( $p ) {
- $arr = explode( '=', $p );
- $args[$arr[0]] = $arr[1];
+ $arr = explode( '=', $p );
+ $args[ $arr[0] ] = $arr[1];
}
}
}
@@ -364,7 +379,7 @@ public function get_questions_permalink() {
$question_tag_rewrite = $dwqa_options['question-tag-rewrite'];
$question_tag_rewrite = $question_tag_rewrite ? $question_tag_rewrite : 'question-tag';
- if ( isset( $args[$question_tag_rewrite] ) ) {
+ if ( isset( $args[ $question_tag_rewrite ] ) ) {
if ( isset( $args['dwqa-question_tag'] ) ) {
unset( $args['dwqa-question_tag'] );
}
@@ -373,17 +388,17 @@ public function get_questions_permalink() {
$question_category_rewrite = $dwqa_options['question-category-rewrite'];
$question_category_rewrite = $question_category_rewrite ? $question_category_rewrite : 'question-category';
- if ( isset( $args[$question_category_rewrite] ) ) {
+ if ( isset( $args[ $question_category_rewrite ] ) ) {
if ( isset( $args['dwqa-question_category'] ) ) {
unset( $args['dwqa-question_category'] );
}
- $term = get_term_by( 'slug', $args[$question_category_rewrite], 'dwqa-question_category' );
- unset( $args[$question_category_rewrite] );
+ $term = get_term_by( 'slug', $args[ $question_category_rewrite ], 'dwqa-question_category' );
+ unset( $args[ $question_category_rewrite ] );
$url = get_term_link( $term, 'dwqa-question_category' );
} else {
- if ( isset( $args[$question_tag_rewrite] ) ) {
- $term = get_term_by( 'slug', $args[$question_tag_rewrite], 'dwqa-question_tag' );
- unset( $args[$question_tag_rewrite] );
+ if ( isset( $args[ $question_tag_rewrite ] ) ) {
+ $term = get_term_by( 'slug', $args[ $question_tag_rewrite ], 'dwqa-question_tag' );
+ unset( $args[ $question_tag_rewrite ] );
$url = get_term_link( $term, 'dwqa-question_tag' );
}
}
@@ -415,14 +430,14 @@ public function stick_question() {
global $current_user;
$sticky_questions = get_option( 'dwqa_sticky_questions', array() );
- if ( ! dwqa_is_sticky( $question->ID ) ) {
+ if ( ! dwqa_is_sticky( $question->ID ) ) {
$sticky_questions[] = $question->ID;
update_option( 'dwqa_sticky_questions', $sticky_questions );
wp_send_json_success( array( 'code' => 'stickied' ) );
} else {
foreach ( $sticky_questions as $key => $q ) {
if ( $q == $question->ID ) {
- unset( $sticky_questions[$key] );
+ unset( $sticky_questions[ $key ] );
}
}
update_option( 'dwqa_sticky_questions', $sticky_questions );
@@ -442,7 +457,11 @@ public function admin_posts_filter_restrict_manage_posts() {
//only add filter to post type you want
if ( 'dwqa-question' == $type ) {
?>
- >
+ >
+
query_vars['post__in'] = $sticky_questions;
}
}
+
return $query;
}
public function delete_question() {
$valid_ajax = check_ajax_referer( '_dwqa_delete_question', 'nonce', false );
- $nonce = isset($_POST['nonce']) ? esc_html( $_POST['nonce'] ) : false;
+ $nonce = isset( $_POST['nonce'] ) ? esc_html( $_POST['nonce'] ) : false;
if ( ! $valid_ajax || ! wp_verify_nonce( $nonce, '_dwqa_delete_question' ) || ! is_user_logged_in() ) {
wp_send_json_error( array(
'message' => __( 'Hello, Are you cheating huh?', 'dwqa' )
@@ -476,7 +496,7 @@ public function delete_question() {
if ( ! isset( $_POST['question'] ) ) {
wp_send_json_error( array(
- 'message' => __( 'Question is not valid','dwqa' )
+ 'message' => __( 'Question is not valid', 'dwqa' )
) );
}
@@ -496,13 +516,13 @@ public function delete_question() {
) );
} else {
wp_send_json_error( array(
- 'question' => $question->ID,
- 'message' => __( 'Delete Action was failed','dwqa' )
+ 'question' => $question->ID,
+ 'message' => __( 'Delete Action was failed', 'dwqa' )
) );
}
} 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', 'dwqa' )
) );
}
}
@@ -517,7 +537,7 @@ public function hook_on_remove_question( $post_id ) {
$answers = $wpdb->get_results( $query );
- wp_cache_set( 'dwqa-answers-for'.$post_id, $answers, 'dwqa', 21600 );
+ wp_cache_set( 'dwqa-answers-for' . $post_id, $answers, 'dwqa', 21600 );
}
if ( ! empty( $answers ) ) {
@@ -539,7 +559,7 @@ public function do_this_hourly() {
$closed_questions = wp_cache_get( 'dwqa-closed-question' );
if ( false == $closed_questions ) {
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 = '_dwqa_status' AND `{$wpdb->postmeta}`.meta_value = 'closed' AND `{$wpdb->posts}`.post_status = 'publish' AND `{$wpdb->posts}`.post_type = 'dwqa-question'";
+ $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 = '_dwqa_status' AND `{$wpdb->postmeta}`.meta_value = 'closed' AND `{$wpdb->posts}`.post_status = 'publish' AND `{$wpdb->posts}`.post_type = 'dwqa-question'";
$closed_questions = $wpdb->get_results( $query );
wp_cache_set( 'dwqa-closed-question', $closed_questions );
@@ -548,7 +568,7 @@ public function do_this_hourly() {
if ( ! empty( $closed_questions ) ) {
foreach ( $closed_questions as $q ) {
$resolved_time = get_post_meta( $q->ID, '_dwqa_resolved_time', true );
- if ( dwqa_is_resolved( $q->ID ) && ( time() - $resolved_time > (3 * 24 * 60 * 60 ) ) ) {
+ if ( dwqa_is_resolved( $q->ID ) && ( time() - $resolved_time > ( 3 * 24 * 60 * 60 ) ) ) {
update_post_meta( $q->ID, '_dwqa_status', 'resolved' );
}
}
From d0d77b0bbd29e35f7664fb26d34a2e9bb9743f05 Mon Sep 17 00:00:00 2001
From: Denver Prophit Jr
Date: Fri, 17 Nov 2017 07:48:32 -0500
Subject: [PATCH 2/6] Fixes Issue /designwall/dw-question-answer/#216
Add detection of yoast seo => breadcrumb function around line 7
---
inc/Template.php | 864 +++++++++++++++++++++++++----------------------
1 file changed, 461 insertions(+), 403 deletions(-)
diff --git a/inc/Template.php b/inc/Template.php
index f976847b..ebda009f 100644
--- a/inc/Template.php
+++ b/inc/Template.php
@@ -4,87 +4,109 @@
* Print class for question detail container
*/
function dwqa_breadcrumb() {
- global $dwqa_general_settings;
- $title = get_the_title( $dwqa_general_settings['pages']['archive-question'] );
- $search = isset( $_GET['qs'] ) ? esc_html( $_GET['qs'] ) : false;
- $author = isset( $_GET['user'] ) ? esc_html( $_GET['user'] ) : false;
- $output = '';
- if ( !is_singular( 'dwqa-question' ) ) {
- $term = get_query_var( 'dwqa-question_category' ) ? get_query_var( 'dwqa-question_category' ) : ( get_query_var( 'dwqa-question_tag' ) ? get_query_var( 'dwqa-question_tag' ) : false );
- $term = get_term_by( 'slug', $term, get_query_var( 'taxonomy' ) );
- $tax_name = 'dwqa-question_tag' == get_query_var( 'taxonomy' ) ? __( 'Tag', 'dwqa' ) : __( 'Category', 'dwqa' );
- } else {
- $term = wp_get_post_terms( get_the_ID(), 'dwqa-question_category' );
- if ( $term ) {
- $term = $term[0];
- $tax_name = __( 'Category', 'dwqa' );
+ if ( function_exists( 'yoast_breadcrumb' ) ) :
+ $post_types = array( 'dwqa-question' );
+ if ( is_post_type_archive( $post_types ) ):
+ ?>
+
+ ', '' );
+ endif;
+ else:
+
+ global $dwqa_general_settings;
+ $title = get_the_title( $dwqa_general_settings['pages']['archive-question'] );
+ $search = isset( $_GET['qs'] ) ? esc_html( $_GET['qs'] ) : false;
+ $author = isset( $_GET['user'] ) ? esc_html( $_GET['user'] ) : false;
+ $output = '';
+ if ( ! is_singular( 'dwqa-question' ) ) {
+ $term = get_query_var( 'dwqa-question_category' ) ? get_query_var( 'dwqa-question_category' ) : ( get_query_var( 'dwqa-question_tag' ) ? get_query_var( 'dwqa-question_tag' ) : false );
+ $term = get_term_by( 'slug', $term, get_query_var( 'taxonomy' ) );
+ $tax_name = 'dwqa-question_tag' == get_query_var( 'taxonomy' ) ? __( 'Tag', 'dwqa' ) : __( 'Category', 'dwqa' );
+ } else {
+ $term = wp_get_post_terms( get_the_ID(), 'dwqa-question_category' );
+ if ( $term ) {
+ $term = $term[0];
+ $tax_name = __( 'Category', 'dwqa' );
+ }
}
- }
- if ( is_singular( 'dwqa-question' ) || $search || $author || $term ) {
- $output .= '';
- }
-
- if ( $term || is_singular( 'dwqa-question' ) || $search || $author ) {
- $output .= '
' . $title . ' ';
- }
+ if ( is_singular( 'dwqa-question' ) || $search || $author || $term ) {
+ $output .= '
';
+ }
- if ( $term ) {
- $output .= '
› ';
- if ( is_singular( 'dwqa-question' ) ) {
- $output .= '
' . $tax_name . ': ' . $term->name . ' ';
- } else {
- $output .= '
' . $tax_name . ': ' . $term->name . ' ';
+ if ( $term || is_singular( 'dwqa-question' ) || $search || $author ) {
+ $output .= '
' . $title . ' ';
}
- }
- if ( $search ) {
- $output .= '
› ';
- $output .= sprintf( '
%s "%s" ', __( 'Showing search results for', 'dwqa' ), rawurldecode( $search ) );
- }
+ if ( $term ) {
+ $output .= '
› ';
+ if ( is_singular( 'dwqa-question' ) ) {
+ $output .= '
' . $tax_name . ': ' . $term->name . ' ';
+ } else {
+ $output .= '
' . $tax_name . ': ' . $term->name . ' ';
+ }
+ }
- if ( $author ) {
- $output .= '
› ';
- $output .= sprintf( '
%s "%s" ', __( 'Author', 'dwqa' ), rawurldecode( $author ) );
- }
+ if ( $search ) {
+ $output .= '
› ';
+ $output .= sprintf( '
%s "%s" ', __( 'Showing search results for', 'dwqa' ), rawurldecode( $search ) );
+ }
- if ( is_singular( 'dwqa-question' ) ) {
- $output .= '
› ';
- if ( !dwqa_is_edit() ) {
- $output .= '
' . get_the_title() . ' ';
- } else {
- $output .= '
'. get_the_title() .' ';
+ if ( $author ) {
$output .= '
› ';
- $output .= '
'. __( 'Edit', 'dwqa' ) .' ';
+ $output .= sprintf( '
%s "%s" ', __( 'Author', 'dwqa' ), rawurldecode( $author ) );
}
- }
- if ( is_singular( 'dwqa-question' ) || $search || $author || $term ) {
- $output .= '
';
- }
+ if ( is_singular( 'dwqa-question' ) ) {
+ $output .= '
› ';
+ if ( ! dwqa_is_edit() ) {
+ $output .= '
' . get_the_title() . ' ';
+ } else {
+ $output .= '
' . get_the_title() . ' ';
+ $output .= '
› ';
+ $output .= '
' . __( 'Edit', 'dwqa' ) . ' ';
+ }
+ }
+ if ( is_singular( 'dwqa-question' ) || $search || $author || $term ) {
+ $output .= '
';
+ }
+ endif;
echo apply_filters( 'dwqa_breadcrumb', $output );
}
+
add_action( 'dwqa_before_questions_archive', 'dwqa_breadcrumb' );
add_action( 'dwqa_before_single_question', 'dwqa_breadcrumb' );
function dwqa_archive_question_filter_layout() {
dwqa_load_template( 'archive', 'question-filter' );
}
+
add_action( 'dwqa_before_questions_archive', 'dwqa_archive_question_filter_layout', 12 );
function dwqa_search_form() {
?>
-
+
add_query_arg( 'ans-page', '%#%', $question_url ),
- 'format' => '',
+ 'base' => add_query_arg( 'ans-page', '%#%', $question_url ),
+ 'format' => '',
'current' => $page,
- 'total' => $wp_query->dwqa_answers->max_num_pages
+ 'total' => $wp_query->dwqa_answers->max_num_pages
);
$paginate = paginate_links( $args );
@@ -119,21 +141,21 @@ function dwqa_question_paginate_link() {
global $wp_query, $dwqa_general_settings;
$archive_question_url = get_permalink( $dwqa_general_settings['pages']['archive-question'] );
- $page_text = dwqa_is_front_page() ? 'page' : 'paged';
- $page = get_query_var( $page_text ) ? get_query_var( $page_text ) : 1;
+ $page_text = dwqa_is_front_page() ? 'page' : 'paged';
+ $page = get_query_var( $page_text ) ? get_query_var( $page_text ) : 1;
$tag = get_query_var( 'dwqa-question_tag' ) ? get_query_var( 'dwqa-question_tag' ) : false;
$cat = get_query_var( 'dwqa-question_category' ) ? get_query_var( 'dwqa-question_category' ) : false;
- $url = $cat
- ? get_term_link( $cat, get_query_var( 'taxonomy' ) )
- : ( $tag ? get_term_link( $tag, get_query_var( 'taxonomy' ) ) : $archive_question_url );
+ $url = $cat
+ ? get_term_link( $cat, get_query_var( 'taxonomy' ) )
+ : ( $tag ? get_term_link( $tag, get_query_var( 'taxonomy' ) ) : $archive_question_url );
$args = array(
- 'base' => add_query_arg( $page_text, '%#%', $url ),
- 'format' => '',
+ 'base' => add_query_arg( $page_text, '%#%', $url ),
+ 'format' => '',
'current' => $page,
- 'total' => $wp_query->dwqa_questions->max_num_pages
+ 'total' => $wp_query->dwqa_questions->max_num_pages
);
$paginate = paginate_links( $args );
@@ -154,18 +176,21 @@ function dwqa_question_button_action() {
$html = '';
if ( is_user_logged_in() ) {
$followed = dwqa_is_followed() ? 'followed' : 'follow';
- $text = __( 'Subscribe', 'dwqa' );
- $html .= '';
- $html .= ' ';
- $html .= '' . $text . ' ';
- $html .= ' ';
+ $text = __( 'Subscribe', 'dwqa' );
+ $html .= '';
+ $html .= ' ';
+ $html .= '' . $text . ' ';
+ $html .= ' ';
if ( dwqa_current_user_can( 'edit_question' ) ) {
- $html .= '' . __( 'Edit', 'dwqa' ) . ' ';
+ $html .= '' . __( 'Edit', 'dwqa' ) . ' ';
}
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 .= '' . __( 'Delete', 'dwqa' ) . ' ';
+ $action_url = add_query_arg( array(
+ 'action' => 'dwqa_delete_question',
+ 'question_id' => get_the_ID()
+ ), admin_url( 'admin-ajax.php' ) );
+ $html .= '' . __( 'Delete', 'dwqa' ) . ' ';
}
}
@@ -177,12 +202,15 @@ function dwqa_answer_button_action() {
if ( is_user_logged_in() ) {
if ( dwqa_current_user_can( 'edit_answer' ) ) {
$parent_id = dwqa_get_question_from_answer_id();
- $html .= '' . __( 'Edit', 'dwqa' ) . ' ';
+ $html .= '' . __( 'Edit', 'dwqa' ) . ' ';
}
if ( dwqa_current_user_can( 'delete_answer' ) ) {
- $action_url = add_query_arg( array( 'action' => 'dwqa_delete_answer', 'answer_id' => get_the_ID() ), admin_url( 'admin-ajax.php' ) );
- $html .= '' . __( 'Delete', 'dwqa' ) . ' ';
+ $action_url = add_query_arg( array(
+ 'action' => 'dwqa_delete_answer',
+ 'answer_id' => get_the_ID()
+ ), admin_url( 'admin-ajax.php' ) );
+ $html .= '' . __( 'Delete', 'dwqa' ) . ' ';
}
}
@@ -190,7 +218,7 @@ function dwqa_answer_button_action() {
}
-function dwqa_question_add_class( $classes, $class, $post_id ){
+function dwqa_question_add_class( $classes, $class, $post_id ) {
if ( get_post_type( $post_id ) == 'dwqa-question' ) {
$have_new_reply = dwqa_have_new_reply();
@@ -198,8 +226,10 @@ function dwqa_question_add_class( $classes, $class, $post_id ){
$classes[] = 'staff-answered';
}
}
+
return $classes;
}
+
add_action( 'post_class', 'dwqa_question_add_class', 10, 3 );
/**
@@ -222,32 +252,35 @@ function dwqa_question_comment_callback( $comment, $args, $depth ) {
function dwqa_body_class( $classes ) {
global $post, $dwqa_options;
- if ( ( $dwqa_options['pages']['archive-question'] && is_page( $dwqa_options['pages']['archive-question'] ) )
- || ( is_archive() && ( 'dwqa-question' == get_post_type()
- || 'dwqa-question' == get_query_var( 'post_type' )
- || 'dwqa-question_category' == get_query_var( 'taxonomy' )
- || 'dwqa-question_tag' == get_query_var( 'taxonomy' ) ) )
- ){
+ if ( ( $dwqa_options['pages']['archive-question'] && is_page( $dwqa_options['pages']['archive-question'] ) )
+ || ( is_archive() && ( 'dwqa-question' == get_post_type()
+ || 'dwqa-question' == get_query_var( 'post_type' )
+ || 'dwqa-question_category' == get_query_var( 'taxonomy' )
+ || 'dwqa-question_tag' == get_query_var( 'taxonomy' ) ) )
+ ) {
$classes[] = 'list-dwqa-question';
}
- if ( $dwqa_options['pages']['submit-question'] && is_page( $dwqa_options['pages']['submit-question'] ) ){
+ if ( $dwqa_options['pages']['submit-question'] && is_page( $dwqa_options['pages']['submit-question'] ) ) {
$classes[] = 'submit-dwqa-question';
}
+
return $classes;
}
+
add_filter( 'body_class', 'dwqa_body_class' );
/**
* Add Icon for DW Question Answer Menu In Dashboard
*/
-function dwqa_add_guide_menu_icons_styles(){
+function dwqa_add_guide_menu_icons_styles() {
echo '';
}
+
add_action( 'admin_head', 'dwqa_add_guide_menu_icons_styles' );
-function dwqa_load_template( $name, $extend = false, $include = true ){
+function dwqa_load_template( $name, $extend = false, $include = true ) {
global $dwqa;
$dwqa->template->load_template( $name, $extend, $include );
}
@@ -255,14 +288,14 @@ function dwqa_load_template( $name, $extend = false, $include = true ){
function dwqa_post_class( $post_id = false ) {
$classes = array();
- if ( !$post_id ) {
+ if ( ! $post_id ) {
$post_id = get_the_ID();
}
if ( 'dwqa-question' == get_post_type( $post_id ) ) {
$classes[] = 'dwqa-question-item';
- if ( !is_singular( 'dwqa-question' ) && dwqa_is_sticky( $post_id ) ) {
+ if ( ! is_singular( 'dwqa-question' ) && dwqa_is_sticky( $post_id ) ) {
$classes[] = 'dwqa-sticky';
}
}
@@ -286,57 +319,61 @@ function dwqa_post_class( $post_id = false ) {
* Enqueue all scripts for plugins on front-end
* @return void
*/
-function dwqa_enqueue_scripts(){
- global $dwqa, $dwqa_options, $script_version, $dwqa_sript_vars, $dwqa_general_settings;
- $template_name = $dwqa->template->get_template();
+function dwqa_enqueue_scripts() {
+ global $dwqa, $dwqa_options, $script_version, $dwqa_sript_vars, $dwqa_general_settings;
+ $template_name = $dwqa->template->get_template();
$question_category_rewrite = $dwqa_general_settings['question-category-rewrite'];
- $question_category_rewrite = $question_category_rewrite ? $question_category_rewrite : 'question-category';
- $question_tag_rewrite = $dwqa_general_settings['question-tag-rewrite'];
- $question_tag_rewrite = $question_tag_rewrite ? $question_tag_rewrite : 'question-tag';
-
- $assets_folder = DWQA_URI . 'templates/assets/';
- wp_enqueue_script( 'jquery' );
- if( is_singular( 'dwqa-question' ) ) {
- wp_enqueue_script( 'jquery-effects-core' );
- wp_enqueue_script( 'jquery-effects-highlight' );
- }
- $script_version = $dwqa->get_last_update();
-
- // Enqueue style
- wp_enqueue_style( 'dwqa-style', $assets_folder . 'css/style.css', array(), $script_version );
- wp_enqueue_style( 'dwqa-rtl', $assets_folder . 'css/rtl.css', array(), $script_version );
- // Enqueue for single question page
- if( is_single() && 'dwqa-question' == get_post_type() ) {
- // js
- wp_enqueue_script( 'dwqa-single-question', $assets_folder . 'js/dwqa-single-question.js', array('jquery'), $script_version, true );
- $single_script_vars = $dwqa_sript_vars;
- $single_script_vars['question_id'] = get_the_ID();
- wp_localize_script( 'dwqa-single-question', 'dwqa', $single_script_vars );
- }
-
- $question_category = get_query_var( 'dwqa-question_category' );
- if ( $question_category ) {
- $question_category_rewrite = $dwqa_options['question-category-rewrite'] ? $dwqa_options['question-category-rewrite'] : 'question-category';
- $dwqa_sript_vars['taxonomy'][$question_category_rewrite] = $question_category;
- }
- $question_tag = get_query_var( 'dwqa-question_tag' );
- if ( $question_tag ) {
- $question_tag_rewrite = $dwqa_options['question-tag-rewrite'] ? $dwqa_options['question-tag-rewrite'] : 'question-category';
- $dwqa_sript_vars['taxonomy'][$question_tag_rewrite] = $question_tag;
- }
- if( (is_archive() && 'dwqa-question' == get_post_type()) || ( isset( $dwqa_options['pages']['archive-question'] ) && is_page( $dwqa_options['pages']['archive-question'] ) ) ) {
- wp_enqueue_script( 'dwqa-questions-list', $assets_folder . 'js/dwqa-questions-list.js', array( 'jquery' ), $script_version, true );
- wp_localize_script( 'dwqa-questions-list', 'dwqa', $dwqa_sript_vars );
- }
-
- if( isset($dwqa_options['pages']['submit-question'])
- && is_page( $dwqa_options['pages']['submit-question'] ) ) {
- wp_enqueue_script( 'jquery-ui-autocomplete' );
- wp_enqueue_script( 'dwqa-submit-question', $assets_folder . 'js/dwqa-submit-question.js', array( 'jquery', 'jquery-ui-autocomplete' ), $script_version, true );
- wp_localize_script( 'dwqa-submit-question', 'dwqa', $dwqa_sript_vars );
- }
+ $question_category_rewrite = $question_category_rewrite ? $question_category_rewrite : 'question-category';
+ $question_tag_rewrite = $dwqa_general_settings['question-tag-rewrite'];
+ $question_tag_rewrite = $question_tag_rewrite ? $question_tag_rewrite : 'question-tag';
+
+ $assets_folder = DWQA_URI . 'templates/assets/';
+ wp_enqueue_script( 'jquery' );
+ if ( is_singular( 'dwqa-question' ) ) {
+ wp_enqueue_script( 'jquery-effects-core' );
+ wp_enqueue_script( 'jquery-effects-highlight' );
+ }
+ $script_version = $dwqa->get_last_update();
+
+ // Enqueue style
+ wp_enqueue_style( 'dwqa-style', $assets_folder . 'css/style.css', array(), $script_version );
+ wp_enqueue_style( 'dwqa-rtl', $assets_folder . 'css/rtl.css', array(), $script_version );
+ // Enqueue for single question page
+ if ( is_single() && 'dwqa-question' == get_post_type() ) {
+ // js
+ wp_enqueue_script( 'dwqa-single-question', $assets_folder . 'js/dwqa-single-question.js', array( 'jquery' ), $script_version, true );
+ $single_script_vars = $dwqa_sript_vars;
+ $single_script_vars['question_id'] = get_the_ID();
+ wp_localize_script( 'dwqa-single-question', 'dwqa', $single_script_vars );
+ }
+
+ $question_category = get_query_var( 'dwqa-question_category' );
+ if ( $question_category ) {
+ $question_category_rewrite = $dwqa_options['question-category-rewrite'] ? $dwqa_options['question-category-rewrite'] : 'question-category';
+ $dwqa_sript_vars['taxonomy'][ $question_category_rewrite ] = $question_category;
+ }
+ $question_tag = get_query_var( 'dwqa-question_tag' );
+ if ( $question_tag ) {
+ $question_tag_rewrite = $dwqa_options['question-tag-rewrite'] ? $dwqa_options['question-tag-rewrite'] : 'question-category';
+ $dwqa_sript_vars['taxonomy'][ $question_tag_rewrite ] = $question_tag;
+ }
+ if ( ( is_archive() && 'dwqa-question' == get_post_type() ) || ( isset( $dwqa_options['pages']['archive-question'] ) && is_page( $dwqa_options['pages']['archive-question'] ) ) ) {
+ wp_enqueue_script( 'dwqa-questions-list', $assets_folder . 'js/dwqa-questions-list.js', array( 'jquery' ), $script_version, true );
+ wp_localize_script( 'dwqa-questions-list', 'dwqa', $dwqa_sript_vars );
+ }
+
+ if ( isset( $dwqa_options['pages']['submit-question'] )
+ && is_page( $dwqa_options['pages']['submit-question'] ) ) {
+ wp_enqueue_script( 'jquery-ui-autocomplete' );
+ wp_enqueue_script( 'dwqa-submit-question', $assets_folder . 'js/dwqa-submit-question.js', array(
+ 'jquery',
+ 'jquery-ui-autocomplete'
+ ), $script_version, true );
+ wp_localize_script( 'dwqa-submit-question', 'dwqa', $dwqa_sript_vars );
+ }
}
+
add_action( 'wp_enqueue_scripts', 'dwqa_enqueue_scripts' );
add_action( 'wp_footer', 'dwqa_wp_footer' );
@@ -345,106 +382,108 @@ function dwqa_wp_footer() {
if ( isset( $dwqa_general_settings['show-status-icon'] ) && $dwqa_general_settings['show-status-icon'] && dwqa_is_enable_status() ) {
?>
-
+
exists() ? $user->display_name : '';
- $args = wp_parse_args( $args );
- if ( ! isset( $args['format'] ) )
+ $args = wp_parse_args( $args );
+ if ( ! isset( $args['format'] ) ) {
$args['format'] = current_theme_supports( 'html5', 'comment-form' ) ? 'html5' : 'xhtml';
- $req = get_option( 'require_name_email' );
- $aria_req = ( $req ? " aria-required='true'" : '' );
- $html5 = 'html5' === $args['format'];
- $fields = array(
+ }
+ $req = get_option( 'require_name_email' );
+ $aria_req = ( $req ? " aria-required='true'" : '' );
+ $html5 = 'html5' === $args['format'];
+ $fields = array(
'email' => '',
- 'author' => ''
+ '
',
+ 'author' => ''
);
$required_text = sprintf( ' ' . __( 'Required fields are marked %s' ), '* ' );
/**
@@ -454,18 +493,18 @@ function dwqa_comment_form( $args = array(), $post_id = null ) {
*
* @param array $fields The default comment fields.
*/
- $fields = apply_filters( 'comment_form_default_fields', $fields );
+ $fields = apply_filters( 'comment_form_default_fields', $fields );
$defaults = array(
'fields' => $fields,
'comment_field' => '',
- 'must_log_in' => '' . sprintf( __( 'You must be logged in to post a comment.','dwqa' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '
',
+ 'must_log_in' => '' . sprintf( __( 'You must be logged in to post a comment.', 'dwqa' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '
',
'logged_in_as' => '',
'comment_notes_before' => '',
- 'comment_notes_after' => '' . sprintf( __( 'You may use these HTML tags and attributes: %s','dwqa' ), ' ' . allowed_tags() . '
' ) . '
',
+ 'comment_notes_after' => '' . sprintf( __( 'You may use these HTML tags and attributes: %s', 'dwqa' ), ' ' . allowed_tags() . '
' ) . '
',
'id_form' => 'commentform',
'id_submit' => 'submit',
- 'title_reply' => __( 'Leave a Reply','dwqa' ),
- 'title_reply_to' => __( 'Leave a Reply to %s','dwqa' ),
+ 'title_reply' => __( 'Leave a Reply', 'dwqa' ),
+ 'title_reply_to' => __( 'Leave a Reply to %s', 'dwqa' ),
'cancel_reply_link' => __( 'Cancel reply', 'dwqa' ),
'label_submit' => __( 'Post Comment', 'dwqa' ),
'format' => 'xhtml',
@@ -488,108 +527,110 @@ function dwqa_comment_form( $args = array(), $post_id = null ) {
*/
do_action( 'comment_form_before' );
?>
-
+
'dwqa-question',
- 'post__in' => $sticky_questions,
+ $query = array(
+ 'post_type' => 'dwqa-question',
+ 'post__in' => $sticky_questions,
'posts_per_page' => 40,
);
$sticky_questions = new WP_Query( $query );
?>
-
+
have_posts() ) : $sticky_questions->the_post(); ?>
-
+
ID ) && 'dwqa-question' == get_post_type( $post->ID ) ) {
- $states[] = __( 'Sticky Question','dwqa' );
+ $states[] = __( 'Sticky Question', 'dwqa' );
}
+
return $states;
}
+
add_filter( 'display_post_states', 'dwqa_question_states', 10, 2 );
-function dwqa_get_ask_question_link( $echo = true, $label = false, $class = false ){
+function dwqa_get_ask_question_link( $echo = true, $label = false, $class = false ) {
global $dwqa_options;
$submit_question_link = get_permalink( $dwqa_options['pages']['submit-question'] );
if ( $dwqa_options['pages']['submit-question'] && $submit_question_link ) {
@@ -658,7 +703,7 @@ function dwqa_get_ask_question_link( $echo = true, $label = false, $class = fals
if ( dwqa_current_user_can( 'post_question' ) ) {
$label = $label ? $label : __( 'Ask a question', 'dwqa' );
} elseif ( ! is_user_logged_in() ) {
- $label = $label ? $label : __( 'Login to ask a question', 'dwqa' );
+ $label = $label ? $label : __( 'Login to ask a question', 'dwqa' );
$submit_question_link = wp_login_url( $submit_question_link );
} else {
return false;
@@ -666,8 +711,8 @@ function dwqa_get_ask_question_link( $echo = true, $label = false, $class = fals
//Add filter to change ask question link text
$label = apply_filters( 'dwqa_ask_question_link_label', $label );
- $class = $class ? $class : 'dwqa-btn-success';
- $button = ''.$label.' ';
+ $class = $class ? $class : 'dwqa-btn-success';
+ $button = '' . $label . ' ';
$button = apply_filters( 'dwqa_ask_question_link', $button, $submit_question_link );
if ( ! $echo ) {
return $button;
@@ -685,12 +730,12 @@ function dwqa_get_template( $template = false ) {
) );
$temp_dir = array(
- 1 => trailingslashit( get_stylesheet_directory() ),
+ 1 => trailingslashit( get_stylesheet_directory() ),
10 => trailingslashit( get_template_directory() )
);
if ( isset( $template ) ) {
- foreach( $temp_dir as $link ) {
+ foreach ( $temp_dir as $link ) {
if ( file_exists( $link . $template ) ) {
return $link . $template;
}
@@ -702,12 +747,13 @@ function dwqa_get_template( $template = false ) {
if ( $template == $old_template ) {
continue;
}
- foreach( $temp_dir as $link ) {
+ foreach ( $temp_dir as $link ) {
if ( file_exists( $link . $template ) ) {
return $link . $template;
}
}
}
+
return false;
}
@@ -716,13 +762,15 @@ function dwqa_has_sidebar_template() {
$template = get_stylesheet_directory() . '/dwqa-templates/';
if ( is_single() && file_exists( $template . '/sidebar-single.php' ) ) {
include $template . '/sidebar-single.php';
+
return;
} elseif ( is_single() ) {
- if ( file_exists( DWQA_DIR . 'inc/templates/'.$dwqa_template.'/sidebar-single.php' ) ) {
- include DWQA_DIR . 'inc/templates/'.$dwqa_template.'/sidebar-single.php';
+ if ( file_exists( DWQA_DIR . 'inc/templates/' . $dwqa_template . '/sidebar-single.php' ) ) {
+ include DWQA_DIR . 'inc/templates/' . $dwqa_template . '/sidebar-single.php';
} else {
get_sidebar();
}
+
return;
}
@@ -778,13 +826,15 @@ public function redirect_answer_to_question( $template ) {
exit( 0 );
}
}
+
return $template;
}
public function generate_template_for_comment_form( $comment_template ) {
- if ( is_single() && ('dwqa-question' == get_post_type() || 'dwqa-answer' == get_post_type() ) ) {
+ if ( is_single() && ( 'dwqa-question' == get_post_type() || 'dwqa-answer' == get_post_type() ) ) {
return $this->load_template( 'comments', false, false );
}
+
return $comment_template;
}
@@ -795,7 +845,10 @@ public function page_template_body_class( $classes ) {
$template_parts = explode( '/', $template_slug );
foreach ( $template_parts as $part ) {
- $classes[] = 'page-template-' . sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) );
+ $classes[] = 'page-template-' . sanitize_html_class( str_replace( array(
+ '.',
+ '/'
+ ), '-', basename( $part, '.php' ) ) );
$classes[] = sanitize_html_class( str_replace( array( '.', '/' ), '-', basename( $part, '.php' ) ) );
}
$classes[] = 'page-template-' . sanitize_html_class( str_replace( '.', '-', $template_slug ) );
@@ -805,13 +858,13 @@ public function page_template_body_class( $classes ) {
public function question_content( $template ) {
global $wp_query;
- $dwqa_options = get_option( 'dwqa_options' );
+ $dwqa_options = get_option( 'dwqa_options' );
$template_folder = trailingslashit( get_template_directory() );
if ( isset( $dwqa_options['pages']['archive-question'] ) ) {
$page_template = get_post_meta( $dwqa_options['pages']['archive-question'], '_wp_page_template', true );
}
- $page_template = isset( $page_template ) && !empty( $page_template ) ? $page_template : 'page.php';
+ $page_template = isset( $page_template ) && ! empty( $page_template ) ? $page_template : 'page.php';
$this->page_template = $page_template;
if ( is_singular( 'dwqa-question' ) ) {
@@ -833,20 +886,21 @@ public function question_content( $template ) {
global $post, $current_user;
$this->reset_content( array(
- 'ID' => $post->ID,
- 'post_title' => $post->post_title,
- 'post_author' => 0,
- 'post_date' => $post->post_date,
- 'post_content' => $content,
- 'post_type' => 'dwqa-question',
- 'post_status' => $post->post_status,
- 'is_single' => true,
+ 'ID' => $post->ID,
+ 'post_title' => $post->post_title,
+ 'post_author' => 0,
+ 'post_date' => $post->post_date,
+ 'post_content' => $content,
+ 'post_type' => 'dwqa-question',
+ 'post_status' => $post->post_status,
+ 'is_single' => true,
) );
$single_template = isset( $dwqa_options['single-template'] ) ? $dwqa_options['single-template'] : false;
$this->remove_all_filters( 'the_content' );
add_filter( 'body_class', array( $this, 'page_template_body_class' ) );
+
return dwqa_get_template( $page_template );
}
if ( is_tax( 'dwqa-question_category' ) || is_tax( 'dwqa-question_tag' ) || is_post_type_archive( 'dwqa-question' ) || is_post_type_archive( 'dwqa-answer' ) || isset( $wp_query->query_vars['dwqa-question_tag'] ) || isset( $wp_query->query_vars['dwqa-question_category'] ) ) {
@@ -859,6 +913,7 @@ public function question_content( $template ) {
}
$this->reset_content( $page );
add_filter( 'body_class', array( $this, 'page_template_body_class' ) );
+
return dwqa_get_template( $page_template );
}
}
@@ -899,16 +954,16 @@ public function reset_content( $args ) {
'comment_count' => $wp_query->post->comment_count,
'filter' => $wp_query->post->filter,
- 'is_404' => false,
- 'is_page' => false,
- 'is_single' => false,
- 'is_archive' => false,
- 'is_tax' => false,
- 'current_comment' => 0,
+ 'is_404' => false,
+ 'is_page' => false,
+ 'is_single' => false,
+ 'is_archive' => false,
+ 'is_tax' => false,
+ 'current_comment' => 0,
) );
} else {
$dummy = wp_parse_args( $args, array(
- 'ID' => -1,
+ 'ID' => - 1,
'post_status' => 'private',
'post_author' => 0,
'post_parent' => 0,
@@ -933,12 +988,12 @@ public function reset_content( $args ) {
'comment_count' => 0,
'filter' => 'raw',
- 'is_404' => false,
- 'is_page' => false,
- 'is_single' => false,
- 'is_archive' => false,
- 'is_tax' => false,
- 'current_comment' => 0,
+ 'is_404' => false,
+ 'is_page' => false,
+ 'is_single' => false,
+ 'is_archive' => false,
+ 'is_tax' => false,
+ 'current_comment' => 0,
) );
}
// Bail if dummy post is empty
@@ -949,17 +1004,17 @@ public function reset_content( $args ) {
$post = new WP_Post( (object ) $dummy );
setup_postdata( $post );
// Copy the new post global into the main $wp_query
- $wp_query->post = $post;
- $wp_query->posts = array( $post );
+ $wp_query->post = $post;
+ $wp_query->posts = array( $post );
// Prevent comments form from appearing
- $wp_query->post_count = 1;
- $wp_query->is_404 = $dummy['is_404'];
- $wp_query->is_page = $dummy['is_page'];
- $wp_query->is_single = $dummy['is_single'];
- $wp_query->is_archive = $dummy['is_archive'];
- $wp_query->is_tax = $dummy['is_tax'];
- $wp_query->current_comment = $dummy['current_comment'];
+ $wp_query->post_count = 1;
+ $wp_query->is_404 = $dummy['is_404'];
+ $wp_query->is_page = $dummy['is_page'];
+ $wp_query->is_single = $dummy['is_single'];
+ $wp_query->is_archive = $dummy['is_archive'];
+ $wp_query->is_tax = $dummy['is_tax'];
+ $wp_query->current_comment = $dummy['current_comment'];
}
@@ -976,6 +1031,7 @@ public function close_default_comment( $open ) {
if ( is_singular( 'dwqa-question' ) || is_singular( 'dwqa-answer' ) || ( $dwqa_options['pages']['archive-question'] && is_page( $dwqa_options['pages']['archive-question'] ) ) || ( $dwqa_options['pages']['submit-question'] && is_page( $dwqa_options['pages']['submit-question'] ) ) ) {
return false;
}
+
return $open;
}
@@ -983,36 +1039,36 @@ public function remove_all_filters( $tag, $priority = false ) {
global $wp_filter, $merged_filters;
// Filters exist
- if ( isset( $wp_filter[$tag] ) ) {
+ if ( isset( $wp_filter[ $tag ] ) ) {
// Filters exist in this priority
- if ( ! empty( $priority ) && isset( $wp_filter[$tag][$priority] ) ) {
+ if ( ! empty( $priority ) && isset( $wp_filter[ $tag ][ $priority ] ) ) {
// Store filters in a backup
- $this->filters->wp_filter[$tag][$priority] = $wp_filter[$tag][$priority];
+ $this->filters->wp_filter[ $tag ][ $priority ] = $wp_filter[ $tag ][ $priority ];
// Unset the filters
- unset( $wp_filter[$tag][$priority] );
+ unset( $wp_filter[ $tag ][ $priority ] );
// Priority is empty
} else {
// Store filters in a backup
- $this->filters->wp_filter[$tag] = $wp_filter[$tag];
+ $this->filters->wp_filter[ $tag ] = $wp_filter[ $tag ];
// Unset the filters
- unset( $wp_filter[$tag] );
+ unset( $wp_filter[ $tag ] );
}
}
// Check merged filters
- if ( isset( $merged_filters[$tag] ) ) {
+ if ( isset( $merged_filters[ $tag ] ) ) {
// Store filters in a backup
- $this->filters->merged_filters[$tag] = $merged_filters[$tag];
+ $this->filters->merged_filters[ $tag ] = $merged_filters[ $tag ];
// Unset the filters
- unset( $merged_filters[$tag] );
+ unset( $merged_filters[ $tag ] );
}
return true;
@@ -1022,35 +1078,35 @@ public function restore_all_filters( $tag, $priority = false ) {
global $wp_filter, $merged_filters;
// Filters exist
- if ( isset( $this->filters->wp_filter[$tag] ) ) {
+ if ( isset( $this->filters->wp_filter[ $tag ] ) ) {
// Filters exist in this priority
- if ( ! empty( $priority ) && isset( $this->filters->wp_filter[$tag][$priority] ) ) {
+ if ( ! empty( $priority ) && isset( $this->filters->wp_filter[ $tag ][ $priority ] ) ) {
// Store filters in a backup
- $wp_filter[$tag][$priority] = $this->filters->wp_filter[$tag][$priority];
+ $wp_filter[ $tag ][ $priority ] = $this->filters->wp_filter[ $tag ][ $priority ];
// Unset the filters
- unset( $this->filters->wp_filter[$tag][$priority] );
+ unset( $this->filters->wp_filter[ $tag ][ $priority ] );
// Priority is empty
} else {
// Store filters in a backup
- $wp_filter[$tag] = $this->filters->wp_filter[$tag];
+ $wp_filter[ $tag ] = $this->filters->wp_filter[ $tag ];
// Unset the filters
- unset( $this->filters->wp_filter[$tag] );
+ unset( $this->filters->wp_filter[ $tag ] );
}
}
// Check merged filters
- if ( isset( $this->filters->merged_filters[$tag] ) ) {
+ if ( isset( $this->filters->merged_filters[ $tag ] ) ) {
// Store filters in a backup
- $merged_filters[$tag] = $this->filters->merged_filters[$tag];
+ $merged_filters[ $tag ] = $this->filters->merged_filters[ $tag ];
// Unset the filters
- unset( $this->filters->merged_filters[$tag] );
+ unset( $this->filters->merged_filters[ $tag ] );
}
return true;
@@ -1069,14 +1125,14 @@ public function load_template( $name, $extend = false, $include = true ) {
$name .= '-' . $extend;
}
- $template = false;
+ $template = false;
$template_dir = array(
DWQA_STYLESHEET_DIR . $this->get_template_dir(),
DWQA_TEMP_DIR . $this->get_template_dir(),
DWQA_DIR . 'templates/'
);
- foreach( $template_dir as $temp_path ) {
+ foreach ( $template_dir as $temp_path ) {
if ( file_exists( $temp_path . $name . '.php' ) ) {
$template = $temp_path . $name . '.php';
break;
@@ -1085,8 +1141,9 @@ public function load_template( $name, $extend = false, $include = true ) {
$template = apply_filters( 'dwqa-load-template', $template, $name );
- if ( !$template || !file_exists( $template ) ) {
+ if ( ! $template || ! file_exists( $template ) ) {
_doing_it_wrong( __FUNCTION__, sprintf( "%s does not exists in %s
.", $name, $template ), '1.4.0' );
+
return false;
}
@@ -1105,11 +1162,12 @@ function dwqa_get_mail_template( $option, $name = '' ) {
if ( $template ) {
return $template;
} else {
- if ( file_exists( DWQA_DIR . 'templates/email/'.$name.'.html' ) ) {
+ if ( file_exists( DWQA_DIR . 'templates/email/' . $name . '.html' ) ) {
ob_start();
- load_template( DWQA_DIR . 'templates/email/'.$name.'.html', false );
+ load_template( DWQA_DIR . 'templates/email/' . $name . '.html', false );
$template = ob_get_contents();
ob_end_clean();
+
return $template;
} else {
return '';
@@ -1120,20 +1178,20 @@ function dwqa_get_mail_template( $option, $name = '' ) {
function dwqa_vote_best_answer_button() {
global $current_user;
$question_id = get_post_meta( get_the_ID(), '_question', true );
- $question = get_post( $question_id );
- $best_answer = dwqa_get_the_best_answer( $question_id );
- $data = is_user_logged_in() && ( $current_user->ID == $question->post_author || current_user_can( 'edit_posts' ) ) ? 'data-answer="'.get_the_ID().'" data-nonce="'.wp_create_nonce( '_dwqa_vote_best_answer' ).'" data-ajax="true"' : 'data-ajax="false"';
+ $question = get_post( $question_id );
+ $best_answer = dwqa_get_the_best_answer( $question_id );
+ $data = is_user_logged_in() && ( $current_user->ID == $question->post_author || current_user_can( 'edit_posts' ) ) ? 'data-answer="' . get_the_ID() . '" data-nonce="' . wp_create_nonce( '_dwqa_vote_best_answer' ) . '" data-ajax="true"' : 'data-ajax="false"';
if ( get_post_status( get_the_ID() ) != 'publish' ) {
return false;
}
if ( $best_answer == get_the_ID() || ( is_user_logged_in() && ( $current_user->ID == $question->post_author || current_user_can( 'edit_posts' ) ) ) ) {
?>
-
+
Date: Fri, 17 Nov 2017 08:08:16 -0500
Subject: [PATCH 3/6] Updates Issue to build schema
Updates /designwall/dw-question-answer/#218 this is the question loop. I changed the stats div to an aside so that indexing doesn't count the content as apart of the main content in SERP results.
---
templates/content-question.php | 50 +++++++++++++++++++---------------
1 file changed, 28 insertions(+), 22 deletions(-)
diff --git a/templates/content-question.php b/templates/content-question.php
index ae84d12a..d050e174 100644
--- a/templates/content-question.php
+++ b/templates/content-question.php
@@ -7,36 +7,42 @@
*/
?>
-
-
-
From 4c3b854603eb43325a6f71cf1dd5a88146ab9ff7 Mon Sep 17 00:00:00 2001
From: Denver Prophit Jr
Date: Fri, 17 Nov 2017 08:13:29 -0500
Subject: [PATCH 4/6] Updates content template for schema answer
Updates issue /designwall/dw-question-answer/#218 for answer schema
---
templates/content-single-answer.php | 51 +++++++++++++++++++----------
1 file changed, 33 insertions(+), 18 deletions(-)
diff --git a/templates/content-single-answer.php b/templates/content-single-answer.php
index dabaaeea..9e913a28 100644
--- a/templates/content-single-answer.php
+++ b/templates/content-single-answer.php
@@ -6,28 +6,43 @@
* @since DW Question & Answer 1.4.3
*/
?>
-
-
+
+
-
-
+
+
-
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
From 9d261f18b0fc6fc274c913ccc93b7bafce4f0113 Mon Sep 17 00:00:00 2001
From: Denver Prophit Jr
Date: Fri, 17 Nov 2017 08:21:17 -0500
Subject: [PATCH 5/6] Updates schema question structured data
Updates issue /designwall/dw-question-answer/#218 with a **TODO** of fixing line 16 with the value of cpt category title as audience type is a text value at schema.org
I changed to HTML5 `` around line 36
---
templates/content-single-question.php | 64 +++++++++++++++++----------
1 file changed, 41 insertions(+), 23 deletions(-)
diff --git a/templates/content-single-question.php b/templates/content-single-question.php
index 0009f334..ba826987 100644
--- a/templates/content-single-question.php
+++ b/templates/content-single-question.php
@@ -8,40 +8,58 @@
?>
-
-
+
+
+// TODO Line 16 Audience Type from category title
From 04e95f9e813dc7b1e1a0e5427017cc26ddd3093a Mon Sep 17 00:00:00 2001
From: Denver Prophit Jr
Date: Fri, 17 Nov 2017 08:27:04 -0500
Subject: [PATCH 6/6] Adds H1 tag for HTML5 outline
Fixes Issue /designwall/dw-question-answer/#219 by adding H1 tag.
---
templates/archive-question.php | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/templates/archive-question.php b/templates/archive-question.php
index 800f51d2..fa557a00 100644
--- a/templates/archive-question.php
+++ b/templates/archive-question.php
@@ -8,8 +8,8 @@
?>
-
-
+
+
@@ -21,13 +21,14 @@
-
-
+
+