wordpressGetRelativeAbsPath returns the portion of the ABSPATH value that will come after "/" in wp-config.php - this is done by searching (at a max depth of one directory from the docroot) for wp-settings.php, the file we're using as a signal to indicate that this is a WordPress project.
(app *DdevApp)
| 287 | // this is done by searching (at a max depth of one directory from the docroot) for wp-settings.php, the |
| 288 | // file we're using as a signal to indicate that this is a WordPress project. |
| 289 | func wordpressGetRelativeAbsPath(app *DdevApp) (string, error) { |
| 290 | needle := "wp-settings.php" |
| 291 | |
| 292 | curDirMatches, err := filepath.Glob(filepath.Join(app.GetAbsDocroot(false), needle)) |
| 293 | if err != nil { |
| 294 | return "", err |
| 295 | } |
| 296 | |
| 297 | if len(curDirMatches) > 0 { |
| 298 | return "", nil |
| 299 | } |
| 300 | |
| 301 | subDirMatches, err := filepath.Glob(filepath.Join(app.GetAbsDocroot(false), "*", needle)) |
| 302 | if err != nil { |
| 303 | return "", err |
| 304 | } |
| 305 | |
| 306 | if len(subDirMatches) == 0 { |
| 307 | return "", fmt.Errorf("unable to find %s in subdirectories", needle) |
| 308 | } |
| 309 | |
| 310 | if len(subDirMatches) > 1 { |
| 311 | return "", fmt.Errorf("multiple subdirectories contain %s", needle) |
| 312 | } |
| 313 | |
| 314 | absPath := filepath.Base(filepath.Dir(subDirMatches[0])) |
| 315 | |
| 316 | return absPath, nil |
| 317 | } |
no test coverage detected