Coder Social home page Coder Social logo

wp-slim-framework's Introduction

Wordpress Slim framework plugin

I built this plugin from a need of using a micro framework as Slim but inside Wordpress.

Installation

Copy wp-slim-framework folder with all it's content's into /wp-content/plugins directory. From Wordpress administrator enable the plugin and you are ready to go. But keep in mind that after enabling this plugin Wordpress must use permalinks Settings -> Permalinks use any structure except default one and Save changes.

Usage

To use it all you have to do is to map your routes. This plugin will register your routes when action slim_mapping is triggered. This action has one argument which is the Slim object.

Example of usage:

add_action('slim_mapping',function($slim){
    $slim->get('/slim/api/user/:u',function($user){
    printf("User is %s",$user);            
    });
});

Example of usage inside of a class:

class Rest{
    function __construct(){
        add_action('slim_mapping',array(&$this,'slim_mapping');            
    }

    function slim_mapping($slim){
        //if needed the class context
        $context = $this;
        $slim->get('/slim/api/user/:u',function($user)use($context){
              $context->printUser($user);            
        });
        $slim->put('/slim/api/user/:id',function($id)use($context){
              $context->updateUser($id);
        });
        //.... and so on
    }

    function printUser($user){
        printf("User is %s",$user);
    }
}

The default base path of the url is /slim/api. Added the possibility to change the base path, it can be found in Settings -> Slim Framework. Note: All routes must have the default base path /slim/api or the one used here Settings -> Slim Framework. This is added to avoid misunderstandings with Wordpress permalinks.

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.