Page 1 of 1

Bludit 3 beta 2 - How to check Loged in Role

Posted: Tue Sep 04, 2018 11:08 pm
by BlakesHeaven
Hello, I am in the process of fixing up my plugin to work in Bludit 3.0 beta2

For Bludit 2.3.4 the existing line is:
  • IF ( in_array($Login->role(), array("editor","admin",true) )) {
I have tried lower case L for "login" and your new checkrole:

The folowing:
  • IF ( in_array($login->role(), array("editor","admin",true) )) {
Gives me:
Fatal error: Call to a member function role() on null in /websites/123reg/LinuxPackage21/bl/ak/es/blakesheaven.co.uk/public_html/bludit3beta/bl-plugins/Auto-Archive-Menu-Plus-More/plugin.php on line 336
And this:
  • IF ( checkrole(array("admin","editor"), true) ) {
  • IF ( checkrole("admin") ) {
Gives me:
Fatal error: Call to a member function role() on null in /websites/123reg/LinuxPackage21/bl/ak/es/blakesheaven.co.uk/public_html/bludit3beta/bl-kernel/functions.php on line 642
Can you please advise how I can check if the logged in user is either an Admin or Editor?

Re: Bludit 3 beta 2 - How to check Loged in Role

Posted: Wed Sep 05, 2018 12:00 pm
by Edi
BlakesHeaven wrote: Tue Sep 04, 2018 11:08 pm
  • IF ( in_array($login->role(), array("editor","admin",true) )) {
You can try:

Code: Select all

if (!checkRole(array('admin','editor'), false)) {
  • IF ( checkrole(array("admin","editor"), true) ) {
  • IF ( checkrole("admin") ) {
Please try:

Code: Select all

if (checkRole(array('admin','editor'), true)) {;
if (checkRole(array('admin')) {;

Re: Bludit 3 beta 2 - How to check Loged in Role

Posted: Wed Sep 05, 2018 1:57 pm
by diego
The object $Login / $login was removed from the site part, only is pre-defined in the admin area, you need to create it first.

Code: Select all

$Login = new Login();
IF ( in_array($Login->role(), array("editor","admin",true) )) {

Re: Bludit 3 beta 2 - How to check Loged in Role

Posted: Sat Sep 08, 2018 11:32 pm
by BlakesHeaven
Many thanks for the suggestions, unfortunatly, if I add

Code: Select all

$Login = new Login()
I get the following:

Code: Select all

Warning: session_start(): Cannot send session cache limiter - 
headers already sent (output started at /websites/123reg/LinuxPackage21/{text removed}
/bludit3beta/bl-kernel/helpers/session.class.php on line 34
If I try any of the following:

Code: Select all

if (checkRole(array('admin','editor'), true)) {
if (!checkRole(array('admin','editor'), false)) {
if (checkRole(array('admin'))) {
if (checkRole('admin') ) {
They all return:

Code: Select all

Fatal error: Call to a member function role() on null in 
/websites/123reg/LinuxPackage21/{text removed}
/bludit3beta/bl-kernel/functions.php on line 642

Re: Bludit 3 beta 2 - How to check Loged in Role

Posted: Sun Sep 09, 2018 4:50 pm
by diego
Are you working in a theme or plugin ?

if you are working in a theme, create the file,

Code: Select all

/bl-theme/myteam/init.php
and add the creation of the login object.

Code: Select all

$Login = new Login()

Re: Bludit 3 beta 2 - How to check Loged in Role

Posted: Sun Sep 09, 2018 5:53 pm
by BlakesHeaven
Thanks Diago,
I am currently working on my plugin, Auto-Archive-Menu-Plus-More.
Diago wrote:the object $Login / $login was removed from the site part,
Just wondering, but could the object, $Login, be put back into the site part?

In the meantime, thanks for the info on themes, that's useful information for when I do start to look at my theme.

Re: Bludit 3 beta 2 - How to check Loged in Role

Posted: Sun Sep 09, 2018 6:03 pm
by diego
The object Login generate a cookie for the session, and the users are afraid of this cookies because of the GDPR, so I removed it from the Site. Also, is good idea to not generate for each user this session in the server.

If you are working in the plugins, you need to generate the Login Object before you print something to the browser.

Take a look to this answered:
https://stackoverflow.com/questions/802 ... ror-in-php

Regards