Skip to content

Instantly share code, notes, and snippets.

@evoratec
Last active August 29, 2015 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evoratec/481e32372591f1496531 to your computer and use it in GitHub Desktop.
Save evoratec/481e32372591f1496531 to your computer and use it in GitHub Desktop.
<?php
/*
Plugin Name: evoratec plugin api slimframework
Plugin URI:
Description: Plugin for Api whith slim framework
Author: Evora sistemas de información,s.l.
Version:
Author URI: http://www.evoratec.com
*/
require 'vendor/autoload.php';
class EvoratecApi {
static $plugin_path;
static $nombreApi ;
public function __construct(){
$this->nombreApi = 'evoratecapi';
$this->plugin_path = plugin_dir_path(__FILE__);
register_activation_hook( __FILE__, array( $this, 'flush' ) );
add_action( 'init', array( $this, 'add_endpoints' ) );
add_action( 'parse_request', array( $this, 'parse_request') );
}
public function flush(){
$this->init();
flush_rewrite_rules();
}
public function add_endpoints() {
global $wp_rewrite;
add_rewrite_endpoint($this->nombreApi, EP_ROOT | EP_PAGES );
$wp_rewrite->flush_rules();
}
public function parse_request( &$wp ){
if ( array_key_exists( $this->nombreApi, $wp->query_vars ) ){
// include $this->plugin_path . 'api.php'; En el caso de querer sacar la api fuera
$app = new \Slim\Slim();
$app->get("/$this->nombreApi/hola", function () {
echo "Hola";
});
$app->run();
die();
}
return;
}
}
$evoratecApi = new EvoratecApi();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment