Skip to content

Commit

Permalink
Forcefully add anspress shortcode in single and search page
Browse files Browse the repository at this point in the history
  • Loading branch information
rahularyan committed Nov 23, 2017
1 parent 3209d22 commit 0be6b70
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion includes/hooks.php
Expand Up @@ -86,7 +86,7 @@ public static function init() {
anspress()->add_filter( 'human_time_diff', __CLASS__, 'human_time_diff' );

anspress()->add_filter( 'template_include', 'AnsPress_Theme', 'anspress_basepage_template', 9999 );
anspress()->add_filter( 'the_content', 'AnsPress_Theme', 'the_content_single_question', 9999 );
//anspress()->add_filter( 'the_content', 'AnsPress_Theme', 'the_content_single_question', 9999 );
anspress()->add_filter( 'comments_open', 'AnsPress_Theme', 'single_question_comment_disable' );
anspress()->add_filter( 'get_the_excerpt', 'AnsPress_Theme', 'get_the_excerpt', 9999, 2 );
anspress()->add_filter( 'post_class', 'AnsPress_Theme', 'remove_hentry_class', 10, 3 );
Expand Down
7 changes: 5 additions & 2 deletions includes/qaquery-hooks.php
Expand Up @@ -190,10 +190,13 @@ public static function imaginary_post( $p ) {
* @since 4.1.0
*/
public static function modify_main_posts( $posts, $query ) {
if ( $query->is_main_query() && $query->is_search() && 'question' === get_query_var( 'post_type' ) ) {
if ( $query->is_main_query() && ( $query->is_search() || $query->is_single() ) && 'question' === get_query_var( 'post_type' ) ) {
$query->found_posts = 1;
$query->max_num_pages = 1;
$posts = [ get_page( ap_opt( 'base_page' ) ) ];

$_page = get_page( ap_opt( 'base_page' ) );
$_page->post_content = '[anspress]';
$posts = [ $_page ];
}

return $posts;
Expand Down
18 changes: 18 additions & 0 deletions tests/tests-anspress-question-answer.php
Expand Up @@ -291,5 +291,23 @@ public function test_site_include() {
$this->assertTrue( class_exists( 'AnsPress_Reputation_Hooks' ) );
$this->assertTrue( class_exists( 'AnsPress_Syntax_Highlighter' ) );
$this->assertTrue( class_exists( 'AnsPress_Tag' ) );

ap_deactivate_addon( 'free/avatar.php' );
ap_deactivate_addon( 'free/buddypress.php' );
ap_deactivate_addon( 'free/category.php' );
ap_deactivate_addon( 'free/email.php' );
ap_deactivate_addon( 'free/notification.php' );
ap_deactivate_addon( 'free/profile.php' );
ap_deactivate_addon( 'free/recaptcha.php' );
ap_deactivate_addon( 'free/reputation.php' );
ap_deactivate_addon( 'free/syntaxhighlighter.php' );
ap_deactivate_addon( 'free/tag.php' );
}

/**
* @covers anspress
*/
public function test_anspress() {
$this->assertInstanceOf( 'AnsPress', anspress() );
}
}

0 comments on commit 0be6b70

Please sign in to comment.