Change the action that occurs when logged out users try to vote

In the Q&A plugin, users have to be logged in to vote. Currently, when a logged out user clicks to vote, a popup gets displayed from the browser.

See this behavior here:

What I would like to do, is change the behavior so that when a logged out user clicks a voting arrow they are taken to a link I specify.

I've thought about using a conditional statement in the template file to display a linked image of the active voting arrows to logged out users, but I don't think this is a good method.

Can you help me with something to modify this behavior so I can direct logged out users to a link when they attempt to vote?

  • Ash

    Hello @Saunt

    I hope you are well today.

    Please try the following code:

    add_action( 'wp_footer', 'disable_voting_for_visitor' );
    function disable_voting_for_visitor() {
    	if( ! is_user_logged_in() ){
    	<script type="text/javascript">
    	jQuery(function($) {
    		setInterval(function() {
    			$('.qa-voting-box input[type=submit]').removeAttr('data-msg');
    		}, 500);
    		$('.vote-up-off, .vote-down-off').click(function() {
    			window.location.href = '';

    Change with your desired URL.

    You can add those codes in your functions.php in the theme, if you think your theme won’t be changed. Otherwise mu-plugins is the best solution. To use mu-plugins, go to /wp-content/ and find the folder with name 'mu-plugins'. If there is no folder in that name, then create a folder, name it 'mu-plugins', create a file inside that, give any name you like and paste the code in there. You don't need to activate that plugin. Mu-plugins means must use plugins, so it will be activated automatically always. If you use mu-plugins then add a php start tag at the beginning of the code.

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.


Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.