Skip to content

Commit fea8502

Browse files
authored
Merge pull request #1 from tweakphp/wordpress
add WordPress Loader
2 parents 68ab113 + fb4de48 commit fea8502

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/Loader.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use TweakPHP\Client\Loaders\ComposerLoader;
66
use TweakPHP\Client\Loaders\LaravelLoader;
77
use TweakPHP\Client\Loaders\LoaderInterface;
8+
use TweakPHP\Client\Loaders\WordPressLoader;
89

910
class Loader
1011
{
@@ -22,6 +23,10 @@ public static function load(string $path)
2223
return new ComposerLoader($path);
2324
}
2425

26+
if (file_exists($path . '/wp-load.php')) {
27+
return new WordPressLoader($path);
28+
}
29+
2530
return null;
2631
}
2732
}

src/Loaders/WordPressLoader.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace TweakPHP\Client\Loaders;
4+
5+
use Throwable;
6+
7+
class WordPressLoader extends BaseLoader
8+
{
9+
/**
10+
* @param string $path
11+
*/
12+
public function __construct(string $path)
13+
{
14+
require_once $path . '/wp-load.php';
15+
require_once $path . '/wp-admin/includes/admin.php';
16+
require_once $path . '/wp-includes/pluggable.php';
17+
}
18+
19+
public function name(): string
20+
{
21+
return 'WordPress';
22+
}
23+
24+
/**
25+
* @return string
26+
*/
27+
public function version(): string
28+
{
29+
try {
30+
return get_bloginfo('version');
31+
} catch (Throwable $e) {
32+
//
33+
}
34+
35+
return "";
36+
}
37+
}

0 commit comments

Comments
 (0)