Bludit 3 beta 2 - How to check Loged in Role

Post Reply
BlakesHeaven
Ssr. Bludit
Posts: 24
Joined: Sat Jan 27, 2018 12:32 am

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?
Many thanks in advance,
David
User avatar
Edi
Site Admin
Posts: 3121
Joined: Sun Aug 09, 2015 5:01 pm
Location: Zurich
Has thanked: 54 times
Been thanked: 77 times
Contact:

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')) {;
Clickwork - Websites mit Bludit | Planet Bludit - Tipps und Snippets
User avatar
diego
Site Admin
Posts: 773
Joined: Sat May 16, 2015 2:53 pm
Been thanked: 1 time
Contact:

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) )) {
BlakesHeaven
Ssr. Bludit
Posts: 24
Joined: Sat Jan 27, 2018 12:32 am

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
Many thanks in advance,
David
User avatar
diego
Site Admin
Posts: 773
Joined: Sat May 16, 2015 2:53 pm
Been thanked: 1 time
Contact:

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()
BlakesHeaven
Ssr. Bludit
Posts: 24
Joined: Sat Jan 27, 2018 12:32 am

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.
Many thanks in advance,
David
User avatar
diego
Site Admin
Posts: 773
Joined: Sat May 16, 2015 2:53 pm
Been thanked: 1 time
Contact:

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
Post Reply