Last active
August 29, 2015 14:23
-
-
Save evoratec/481e32372591f1496531 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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