Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Enabling access for visitors to page restricted by Q&A plugin WordPress

  • SOLVED

Q&A Lite plugin:
premium.wpmudev.org/project/qa-wordpress-questions-and-answers-plugin-lite/
along with main functionality provides restriction management for WP standard user roles (Subscriber, Author, etc.). But it doesn't have support for non-registered users or visitors.

So I need code/function for functions.php that will enable reading access for non-registered visitors to plugin pages like:
http://example.com/questions/
http://example.com/questions/ask/
http://example.com/questions/unanswered/
http://example.com/questions/url-of-example-question/
http://example.com/questions/tags/url-of-example-tag/

Thanks.

Answers (3)

2012-08-23

Arnav Joy answers:

Hi Alex ,

you can check if a user is not logged in and then can redirect to him to a custom page whenever he tries to access the page you do not want to show him

suppose you have created a page with the message that "you are not authorized to see this page" and its id is 222 and

suppose the page id is as follows

page page_id

http://example.com/questions/ 10
http://example.com/questions/ask/ 12
http://example.com/questions/unanswered/ 14

so you can check in the header.php if above page is visited and can redirect user to the page you have created with the message

<?php

if( !is_user_logged_in() ) {
if( is_page( 10 ) || is_page( 12 ) || is_page( 14 ) ){
header('location:'.get_permalink(222));
}
}
?>


Alex B. comments:

I want to show all kind of pages I mentioned, NOT hide it from the visitor.


Arnav Joy comments:

oh Sorry , i misunderstood the question


Arnav Joy comments:

Hi Alex ,

I checked this plugin and you have to edit one of the plugin file to make that work , This is not the best approach but if you really need to work it out then go to following path:-

wp-content\plugins\qa-lite\core

core.php

line no. 217 and find following function function is_page_allowed( )

then replace this whole function with the following

function is_page_allowed( ) {
if ( !is_user_logged_in() )
return true;
// First find the cap requirement for this page
if ( is_qa_page( 'archive' ) )
$cap = 'read_questions';
else if ( is_qa_page( 'ask' ) )
$cap = 'publish_questions';
else return true; // Always allow for unlisted pages

if ( !is_user_logged_in() )
return $this->visitor_has_cap( $cap );
else
return current_user_can( $cap );

}

but remember plugin upgradation will remove all my code ..
so be careful.

Best of luck

Arnav

2012-08-23

Francisco Javier Carazo Gil answers:

Alex,

Give us real URL to can be able to see what can be written.


Alex B. comments:

Francisco,

This URL can be used for example:
http://wpmu.org/questions/

2012-08-23

Clifford P answers:

I haven't tried the Lite version, but here's a screenshot of the full version, most recent version. There are options for Visitor.

[[LINK href="http://premium.wpmudev.org?ref=tourkick-13625"]]http://premium.wpmudev.org?ref=tourkick-13625[[/LINK]]

You can buy the full version for $19, includes 1 month of updates/support.


Hope that helps.


Alex B. comments:

Thanks for the proposition.