-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathwl-bootstrap.php
More file actions
50 lines (42 loc) · 1.68 KB
/
wl-bootstrap.php
File metadata and controls
50 lines (42 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/**
* @package WL_Bootstrap
* @version 1.0
*/
/*
Plugin Name: WL_Bootstrap
Description: This plugin allows you to use any functions, methods, libraries of Laravel in WordPress project
Author: Duc Le
Version: 1.0
Author URI: https://github.com/lehoangduc
*/
function wl_bootstrap() {
if (!defined('LARAVEL_PATH')) {
throw new Exception('LARAVEL_PATH is not configured.');
}
require LARAVEL_PATH . '/vendor/autoload.php';
$app = require_once LARAVEL_PATH . '/bootstrap/app.php';
$kernel = $app->make(\Illuminate\Contracts\Http\Kernel::class);
$request = \Illuminate\Http\Request::capture();
$app->instance('request', $request);
$kernel->bootstrap();
$response = (new \Illuminate\Routing\Pipeline($app))
->send($request)
->through([
\App\Http\Middleware\EncryptCookies::class,
\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
\Illuminate\Session\Middleware\StartSession::class
])
->then(function () {
return response('', 200, []);
});
// Set cookie from response headers
foreach ($response->headers->getCookies() as $cookie) {
if ($cookie->isRaw()) {
setrawcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
} else {
setcookie($cookie->getName(), $cookie->getValue(), $cookie->getExpiresTime(), $cookie->getPath(), $cookie->getDomain(), $cookie->isSecure(), $cookie->isHttpOnly());
}
}
}
add_action('plugins_loaded', 'wl_bootstrap');