PluginProbe
PhastPress / 1.80
PhastPress v1.80
3.12 3.11 1.75 1.76 1.77 1.78 1.79 1.80 1.81 1.82 1.83 1.84 1.85 1.86 1.87 1.88 1.89 1.90 1.91 1.92 1.93 1.94 1.95 1.96 1.97 All 119 releases
phastpress / classes / WordPress.php

WordPress.php in PhastPress 1.80, at classes/WordPress.php

66 lines 1.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace Kibo\PhastPlugins\PhastPress;
3
4 use Exception;
5 use Requests;
6 use RuntimeException;
7
8 class WordPress {
9 public static function loadConfig() {
10 if (defined('ABSPATH')) {
11 return;
12 }
13 $complete = false;
14 $hook = function () use (&$complete) {
15 if (!$complete && defined('WP_CONTENT_DIR')) {
16 throw new WordPressLoadedException();
17 }
18 };
19 $GLOBALS['wp_filter']['all'][0][] = [
20 'function' => $hook,
21 'accepted_args' => 0,
22 ];
23 try {
24 require self::findWPLoad();
25 } catch (WordPressLoadedException $e) {
26 return;
27 } finally {
28 $complete = true;
29 }
30 throw new RuntimeException('WordPress loaded without triggering any hooks');
31 }
32
33 private static function findWPLoad() {
34 $startDir = dirname($_SERVER['SCRIPT_FILENAME']);
35 if (!$startDir) {
36 throw new RuntimeException('Could not get directory from SCRIPT_FILENAME');
37 }
38 $dir = $startDir;
39 while (true) {
40 $path = $dir . '/wp-load.php';
41 if (file_exists($path)) {
42 return $path;
43 }
44 $parent = dirname($dir);
45 if ($parent == $dir) {
46 break;
47 }
48 $dir = $parent;
49 }
50 throw new RuntimeException(
51 "Could not find wp-load.php in $startDir or any of its parent directories"
52 );
53 }
54
55 public static function loadRequests() {
56 if (!class_exists(Requests::class)) {
57 require ABSPATH . WPINC . '/class-requests.php';
58 Requests::register_autoloader();
59 Requests::set_certificate_path(ABSPATH . WPINC . '/certificates/ca-bundle.crt');
60 }
61 }
62 }
63
64 class WordPressLoadedException extends Exception {
65 }
66