Welcome to the Question2Answer Q&A. There's also a demo if you just want to try it out.
+2 votes
979 views
in Q2A Core by

Here https://docs.question2answer.org/plugins/layers/ in the plugin tutorial there is an example of a layer plugin which removes the login and register links. But it doesn't work:

function nav_list($navigation, $navtype) // remove login and register links
    {
        if ($navtype=='user') {
            unset($navigation['login']);
            unset($navigation['register']);
        }

        qa_html_theme_base::nav_list($navigation, $navtype);
    }

gets this warning:

 Warning: Declaration of qa_layer_1_from_qa_my_layer_php::nav_list($navigation, $navtype) should be compatible with qa_html_theme_base::nav_list($navigation, $class, $level = NULL)

I think you should change it to:

function nav_list($navigation, $navtype, $level=null) // remove login and register links
    {
        if ($navtype=='user') {
            unset($navigation['login']);
            unset($navigation['register']);
        }

        qa_html_theme_base::nav_list($navigation, $navtype, $level=null);
    }

This doesn't get warning but doesn't remove the login and register links.

by
Just a reminder to everyone: the Q2A documentation is open source, so if you find particular problems you can submit fixes: https://github.com/q2a/q2a.github.io

2 Answers

+1 vote
by
selected by
 
Best answer

This is a bit trickier than it seems.

1. The $level is indeed missing as a parameter in the tutorial and should be added
2. The $navtype should be 'nav-user' instead of 'user'
3. This is a whole section, as it is more complex than the previous ones:

Considering you're playing with layers and trying to learn, which is the purpose of any tutorial, I'd say it is not the best tutorial. A tutorial should aim at exploring things that are as common/standard between themes as possible. I'm saying the tutorial could be improved because themes usually want to provide a way to register/login which fits the theme's author taste. This results in the author playing with the links to those features.

SnowFlat, which is now the default theme, is no exception. Check this method. If you take a look at it you'll realize that the login button is already gone (unset) in there. So why is it still being displayed? That's because a custom login button is added right above it, which is the <form> that is output in the previous statement.

So if you want to remove the Login button in SnowFlat you'll have to modify that method and maybe even qam_user_account(), to make it look good.

The thing to understand here is that everything is chained in this order: base theme, theme and layers. So you can't really assume anything at a layer-level, as themes (and other layers) can change the context that you give for granted.

by
+1
I've fixed the issues with the warnings in the docs. You are right though, the SnowFlat theme does some unusual stuff outputting raw HTML.
+1 vote
by

First of all why you want remove it, is it due to spam registrations ?! If yes, there is nospam plugin that will 100% prevent all spammers.

If you still want to remove it, you can two option. First, if you dont mind just hide them with css (display:none;)

Alternatively, follow these:

public function nav_list($navigation, $class, $level = null)// remove login and register links 
    { 
       if( $class == 'nav-user' AND isset($navigation['register']) ) {
           unset($navigation['register']);
       }

        qa_html_theme_base::nav_list($navigation, $class, $level = null)
    }

and to remove login, if you use snowflat go to qa-theme.php, find public function nav_user_search().

inside this function remove login input.

by
I have realized that you nav_list variables are different than Q2A 1.8. Can you confirm you q2a version?
by
Hi @esqeudero
Thank you for your reply. I am trying to learn to make plugins, so followed the instruction from here:  https://docs.question2answer.org/plugins/layers/
My q2a version is 1.8.1
I think Scott should update that tutorial.
...