Coder Social home page Coder Social logo

Comments (1)

Botnary avatar Botnary commented on August 11, 2024

If you use Slim Framework as a Wordpress plugin then in your routes you have access to Wordpress API.
i would do something like this:

add_action('slim_mapping',function($app){
    $app->get('/slim/api/books',function(){
        //wordpress current user
        $user = wp_get_current_user(); // this function returns current user as a Wp_User object.
        if($user->ID > 0) { // it means that there is a user online
            //do something as logged in user.
        }
    });
});

and actually this is how i do it, and i don't use any middlewares.
Also you should not access directly Slim files with include, but use composer autoloader.
So in your code if you need any class from Slim just do this:

use \Slim\Middleware;
$auth = new HttpBasicAuth();

and autoloader will find the required file automatically for you.

from wp-slim-framework.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.