Skip to content

Instantly share code, notes, and snippets.

@cfaria
Created April 15, 2026 12:31
Show Gist options
  • Select an option

  • Save cfaria/a522e715ff278c84f68dabc0c6157eda to your computer and use it in GitHub Desktop.

Select an option

Save cfaria/a522e715ff278c84f68dabc0c6157eda to your computer and use it in GitHub Desktop.
In Bedrock installations, where WP is treated as a composer dependency, it is installed in a separate folder. Find the wp-load.php scanning any immediate subdirectory of each ancestor, so it works regardless of whether the WordPress folder is named wp, wordpress, cms, or anything else.
<?php
// If called directly by Stripe, bootstrap WordPress so we can use plugin functions
if (!defined('ABSPATH')) {
// try to locate wp-load.php by walking up the directory tree
$search_dir = __DIR__;
$wp_load = '';
for ($i = 0; $i < 10; $i++) {
$possible = $search_dir . '/wp-load.php';
if (file_exists($possible)) {
$wp_load = $possible;
break;
}
$parent = dirname($search_dir);
if ($parent === $search_dir) {
// reached root
break;
}
$search_dir = $parent;
}
// Bedrock layout: WordPress core lives in a subdirectory (e.g. web/wp/ or web/cms/)
// Walk up and scan immediate children at each level for a folder containing wp-load.php
if (!$wp_load) {
$try_dir = __DIR__;
for ($i = 0; $i < 10; $i++) {
foreach (glob($try_dir . '/*/wp-load.php') ?: [] as $candidate) {
$wp_load = $candidate;
break 2;
}
$parent = dirname($try_dir);
if ($parent === $try_dir) break;
$try_dir = $parent;
}
}
// fallback: document root (covers some multi-domain setups)
if (!$wp_load && isset($_SERVER['DOCUMENT_ROOT'])) {
$doc = rtrim($_SERVER['DOCUMENT_ROOT'], "/\\");
if (file_exists($doc . '/wp-load.php')) {
$wp_load = $doc . '/wp-load.php';
}
}
if ($wp_load) {
require_once $wp_load;
} else {
// Cannot bootstrap WP; log and exit
error_log('WPGV: stripewebhook.php could not locate wp-load.php');
http_response_code(500);
exit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment