diff --git a/gitium/gitium-webhook.php b/gitium/gitium-webhook.php index 6640d04..e5d2cfd 100644 --- a/gitium/gitium-webhook.php +++ b/gitium/gitium-webhook.php @@ -17,10 +17,31 @@ header( 'Content-Type: text/html' ); define( 'SHORTINIT', true ); -//$wordpress_loader = $_SERVER['DOCUMENT_ROOT'] . '/wp-load.php'; + +// First, check if wp-load.php exists in the server root $wordpress_loader = filter_input(INPUT_SERVER, 'DOCUMENT_ROOT', FILTER_SANITIZE_FULL_SPECIAL_CHARS) . '/wp-load.php'; -require_once $wordpress_loader; +if ( file_exists( $wordpress_loader ) ) { + require_once $wordpress_loader; +} else { + // Attempt to find wp-load.php dynamically by splitting the path + if ( defined( 'WP_CONTENT_DIR' ) ) { + // Use WP_CONTENT_DIR if it's defined in wp-config.php + $web_root = dirname( WP_CONTENT_DIR ); + } else { + // Fallback: infer the web root from 'wp-content/plugins' + list( $web_root ) = explode( 'wp-content', $current_dir, 2 ); + } + + $wordpress_loader = $web_root . '/wp-load.php'; + + if ( file_exists( $wordpress_loader ) ) { + require_once $wordpress_loader; + } else { + // Handle error: wp-load.php not found + die( 'Error: Unable to locate wp-load.php. Please verify your WordPress installation.' ); + } +} require_once __DIR__ . '/functions.php'; require_once __DIR__ . '/inc/class-git-wrapper.php';