-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcatalog.php
53 lines (40 loc) · 1.57 KB
/
catalog.php
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
51
52
53
<?php
require __DIR__ . '/vendor/autoload.php';
use Mariadb\CatalogsPHP\CatalogManager;
class MariaDB_Catalog
{
private static ?CatalogManager $api = null;
public function __construct() {
add_action( 'init', [ $this, 'hijack' ] );
add_filter( 'dbdelta_queries', [ $this, 'network_site_creation' ] );
}
public function hijack() {
if ( defined( 'CATALOG_SIMPLE_SETUP' ) && CATALOG_SIMPLE_SETUP && str_contains( $_SERVER['REQUEST_URI'], 'wp-admin/setup-config.php' ) ) {
$path = wp_guess_url() . '/wp-content/mu-plugins/catalog/setup-config.php';
header( 'Location: ' . $path );
exit;
}
}
public static function get_api() {
if (!self::$api) {
$dbhost = (defined( 'CATALOG_DB_HOST' ) ? CATALOG_DB_HOST : defined( 'DB_HOST' ) ) ? DB_HOST : '';
$dbuser = (defined( 'CATALOG_DB_USER' ) ? CATALOG_DB_USER : defined( 'DB_USER' ) ) ? DB_USER : '';
$dbpassword = (defined( 'CATALOG_DB_PASSWORD' ) ? CATALOG_DB_PASSWORD : defined( 'DB_PASSWORD' ) ) ? DB_PASSWORD : '';
self::$api = new CatalogManager($dbhost, 3306, $dbuser, $dbpassword, null);
}
return self::$api;
}
public static function get_new_config() {
$name = str_replace( '.', '', $_SERVER['HTTP_HOST'] );
return [
'dbname' => $name,
'username' => $name,
'password' => wp_generate_password(),
'host' => (defined( 'CATALOG_DB_HOST' ) ? CATALOG_DB_HOST : defined( 'DB_HOST' ) ) ? DB_HOST : '127.0.0.1',
];
}
public function network_site_creation( $queries ) {
return $queries;
}
}
new MariaDB_Catalog();