Skip to content

Commit fcde77b

Browse files
authored
Update WordPressCoreInstaller.php
1 parent 9852df2 commit fcde77b

File tree

1 file changed

+18
-40
lines changed

1 file changed

+18
-40
lines changed

src/WordPressCoreInstaller.php

Lines changed: 18 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,5 @@
11
<?php
22

3-
/**
4-
* WordPress Core Installer - A Composer installer to install WordPress in a webroot subdirectory
5-
* Copyright (C) 2013 John P. Bloch
6-
* Modified by Moox Developers, 2025
7-
*
8-
* Licensed under the GPLv2 or later.
9-
*/
10-
113
namespace Moox\Composer;
124

135
use Composer\Config;
@@ -25,15 +17,11 @@ class WordPressCoreInstaller extends LibraryInstaller
2517

2618
private $sensitiveDirectories = ['.'];
2719

28-
/**
29-
* {@inheritDoc}
30-
*/
3120
public function getInstallPath(PackageInterface $package)
3221
{
3322
$installationDir = false;
3423
$prettyName = $package->getPrettyName();
3524

36-
// 1️⃣ Read from root package (top-level composer.json)
3725
if ($this->composer->getPackage()) {
3826
$topExtra = $this->composer->getPackage()->getExtra();
3927
if (!empty($topExtra['wordpress-install-dir'])) {
@@ -44,36 +32,34 @@ public function getInstallPath(PackageInterface $package)
4432
}
4533
}
4634

47-
// 2️⃣ Read from dependent packages (like moox/press) - SAFE version
48-
if (
49-
!$installationDir &&
50-
$this->composer &&
51-
method_exists($this->composer, 'getRepositoryManager') &&
52-
$this->composer->getRepositoryManager() &&
53-
method_exists($this->composer->getRepositoryManager(), 'getLocalRepository') &&
54-
$this->composer->getRepositoryManager()->getLocalRepository()
55-
) {
56-
foreach ($this->composer->getRepositoryManager()->getLocalRepository()->getPackages() as $pkg) {
57-
$pkgExtra = $pkg->getExtra();
58-
if (!empty($pkgExtra['wordpress-install-dir'])) {
59-
$installationDir = $pkgExtra['wordpress-install-dir'];
60-
break;
35+
if (!$installationDir) {
36+
try {
37+
$repoManager = $this->composer->getRepositoryManager();
38+
if ($repoManager && method_exists($repoManager, 'getLocalRepository')) {
39+
$localRepo = $repoManager->getLocalRepository();
40+
if ($localRepo && method_exists($localRepo, 'getPackages')) {
41+
foreach ($localRepo->getPackages() as $pkg) {
42+
$pkgExtra = $pkg->getExtra();
43+
if (!empty($pkgExtra['wordpress-install-dir'])) {
44+
$installationDir = $pkgExtra['wordpress-install-dir'];
45+
break;
46+
}
47+
}
48+
}
6149
}
50+
} catch (\Throwable $e) {
6251
}
6352
}
6453

65-
// 3️⃣ Read from the WordPress package itself (rare case)
6654
$extra = $package->getExtra();
6755
if (!$installationDir && !empty($extra['wordpress-install-dir'])) {
6856
$installationDir = $extra['wordpress-install-dir'];
6957
}
7058

71-
// 4️⃣ Fallback default
7259
if (!$installationDir) {
7360
$installationDir = 'public/wp';
7461
}
7562

76-
// 5️⃣ Safety checks
7763
$vendorDir = $this->composer->getConfig()->get('vendor-dir', Config::RELATIVE_PATHS) ?: 'vendor';
7864
if (
7965
in_array($installationDir, $this->sensitiveDirectories) ||
@@ -87,34 +73,26 @@ public function getInstallPath(PackageInterface $package)
8773
$prettyName !== self::$_installedPaths[$installationDir] &&
8874
$package->getType() !== self::TYPE
8975
) {
90-
$conflict_message = $this->getConflictMessage($prettyName, self::$_installedPaths[$installationDir]);
91-
throw new \InvalidArgumentException($conflict_message);
76+
throw new \InvalidArgumentException(
77+
$this->getConflictMessage($prettyName, self::$_installedPaths[$installationDir])
78+
);
9279
}
9380

9481
self::$_installedPaths[$installationDir] = $prettyName;
9582

9683
return $installationDir;
9784
}
9885

99-
/**
100-
* {@inheritDoc}
101-
*/
10286
public function supports($packageType)
10387
{
10488
return self::TYPE === $packageType;
10589
}
10690

107-
/**
108-
* Get the exception message with conflicting packages.
109-
*/
11091
private function getConflictMessage($attempted, $alreadyExists)
11192
{
11293
return sprintf(self::MESSAGE_CONFLICT, $attempted, $alreadyExists);
11394
}
11495

115-
/**
116-
* Get the exception message for attempted sensitive directories.
117-
*/
11896
private function getSensitiveDirectoryMessage($attempted, $packageName)
11997
{
12098
return sprintf(self::MESSAGE_SENSITIVE, $attempted, $packageName);

0 commit comments

Comments
 (0)