"Ask question" button points to /questions/unanswered when users aren't logged in

I noticed that as of the current release (1.4.1.1), the button to "Ask Question" points to "www.example.com/questions/unanswered". I assume this is related to the setting which prevents un-registered users from asking a question, so of course the form should not appear. But the current behavior is confusing to users because there is no explanation. Wouldn't the registration page be a better redirection? Or maybe some sort of message explaining what's happening? Is there a way to configure this without changing core files?

  • Hakan
    • The Incredible Smush

    Hi,

    I assume this is related to the setting which prevents un-registered users from asking a question, so of course the form should not appear.

    No, not related.

    It works fine for me on my server: If a user does not have the capability to ask a question, "Ask a Question" menu item is not displayed at all.

    However I see that there is something wrong with that menu item on your website.

    Do you have some functions that hook to Q&A in your functions.php? Just switch to the default theme and see what happens.

    Cheers,
    Hakan

  • StreetofWalls
    • Design Lord, Child of Thor

    Hi Hakan,
    Sorry I didn't notice your response...

    I do have a hook that calls a slightly modified version of the qa_menu() function. I'm posting it below. Would you mind having a look and letting me know if there's a way to modify it to resolve this?

    function sow_qa_menu() {
    	global $user_ID;
    	$menu = array();
    
    	if ( ($user_ID == 0 && qa_visitor_can('read_questions')) || current_user_can( 'read_questions' )) {
    		$menu[] = array(
    				'title' => __( 'Questions', QA_TEXTDOMAIN ),
    				'type' => 'archive',
    				'current' => !is_qa_page( 'unanswered' ) && !is_qa_page( 'ask' ) && !is_qa_page( 'edit' )
    			);
    		$menu[] = array(
    				'title' => __( 'Unanswered', QA_TEXTDOMAIN ),
    				'type' => 'unanswered',
    				'current' => is_qa_page( 'unanswered' )
    			);
    	}
    
    	if ( ($user_ID == 0 && qa_visitor_can('publish_questions')) || current_user_can( 'publish_questions' )) {
    		$menu[] = array(
    			'title' => __( 'Ask a Question', QA_TEXTDOMAIN ),
    			'type' => 'ask',
    			'current' => is_qa_page( 'ask' )
    		);
    	}
    	$menu = apply_filters( 'qa_modify_menu_items', $menu );
    
    	echo apply_filters( 'qa_before_menu', '' );
    
    	echo "<div id='qa-header'>";
    	echo "<div id='qa-menu'>";
    
    	echo "<ul>";
    	echo apply_filters( 'qa_first_menu_item', '' );
    	foreach ( $menu as $item ) {
    		extract( $item );
    
    		$url = qa_get_url( $type );
    
    		$id = $current ? 'qa-current-url' : '';
    
    		echo _qa_html( 'li', array( 'id' => $id ),
    			_qa_html( 'a', array( 'href' => $url ),
    				$title
    			)
    		);
    	}
    	echo apply_filters( 'qa_last_menu_item', '' );
    	echo "</ul>";
    	echo apply_filters( 'qa_after_menu', '' );
    
    	echo "</div><!-- qa-menu -->";
    
    	echo "<div class='qa-search'>";
    	my_qa_search_form();
    	echo "</div>";
    
    	echo '<div id="" class="clear"></div><!--.clear-->';
    	echo "</div><!--qa-header-->";
    
    }
  • Hakan
    • The Incredible Smush

    I just see the apply_filters("qa_modify_menu_items" function call above. This gives the opportunity to override, but it does not do it itself.

    There must be an add_filter( "qa_modify_menu_items",... function call somewhere.

    The latter one overrides the default behavior.

  • Hakan
    • The Incredible Smush

    Completely remove these:

    add_filter('qa_modify_menu_items', 'modify_qa_menu_func');
    function modify_qa_menu_func( $menu ) {
    	//krumo( $menu[2]['title'] );
    	$menu[2]['title']='Ask a question';
    	return $menu;
    }

    It forces that menu item to be displayed there, without checking if user has the right to ask a question. In addition to that it defines a 'title' for menu, but no 'link'. That is why browser simply uses the previous menu item's link.

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.