Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions includes/class-instawp-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,14 @@ public static function is_migrate_file_accessible( $file_url, $in_details = fals
'file_url' => $file_url,
'error' => false,
);

// Skip external accessibility check for local development URLs
if ( self::is_local_development_url( $file_url ) ) {
$result['is_accessible'] = true;
$result['message'] = 'Local development - skipping external check';
return $in_details ? $result : $result['is_accessible'];
}

try {
$response = wp_remote_post(
INSTAWP_API_DOMAIN_PROD . '/public/check/?url=' . rawurlencode( $file_url ),
Expand Down Expand Up @@ -791,6 +799,35 @@ public static function is_migrate_file_accessible( $file_url, $in_details = fals
return $in_details ? $result : $result['is_accessible'];
}

/**
* Check if a URL is for local development (not publicly accessible).
*
* @param string $url The URL to check.
* @return bool True if local development URL.
*/
private static function is_local_development_url( $url ) {
$local_patterns = array(
'localhost',
'.local',
'.test',
'.dev',
'127.0.0.1',
'10.5.0.', // Docker macvlan network
'172.17.', // Docker bridge network
'172.18.', // Docker custom networks
'192.168.', // Local network
'-local.instawp', // InstaWP local dev pattern (e.g., vik-local.instawp.me)
);

foreach ( $local_patterns as $pattern ) {
if ( strpos( $url, $pattern ) !== false ) {
return true;
}
}

return false;
}

public static function process_migration_settings( $migrate_settings = array() ) {

$options = Helper::get_args_option( 'options', $migrate_settings, array() );
Expand Down Expand Up @@ -1470,6 +1507,12 @@ public static function get_pull_pre_check_response( $migrate_key, $migrate_setti
$is_wp_root_available = self::is_wp_root_available();
$serve_with_wp = false;

// Fallback: If ABSPATH is defined and wp-load.php exists, WordPress root is available
// This handles symlinked plugin directories where __DIR__ walking fails
if ( ! $is_wp_root_available && defined( 'ABSPATH' ) && file_exists( ABSPATH . 'wp-load.php' ) ) {
$is_wp_root_available = true;
}

if ( ! $is_wp_root_available ) {
$is_wp_root_available = self::is_wp_root_available( 'wp-config.php' );
}
Expand Down
67 changes: 63 additions & 4 deletions includes/functions-pull-push.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,73 @@ function iwp_debug( $data ) {
}

if ( ! function_exists( 'iwp_get_wp_root_directory' ) ) {
/**
* Find WordPress root directory by traversing up from the current directory.
*
* This function handles symlinked plugin installations by trying multiple
* starting paths: the real path (__DIR__), and the request URI path which
* preserves symlink paths.
*
* @param string $find_with_files File to look for (e.g., 'wp-load.php', 'wp-config.php')
* @param string $find_with_dir Directory to look for (e.g., 'wp', 'flywheel-config')
* @return array Array with 'status' (bool) and 'root_path' (string)
*/
function iwp_get_wp_root_directory( $find_with_files = 'wp-load.php', $find_with_dir = '' ) {
// Build list of starting directories to try
// This handles symlinked plugins where __DIR__ resolves to the real path
$starting_dirs = array( __DIR__ );

// Try to get the symlink path from REQUEST_URI or SCRIPT_FILENAME
if ( isset( $_SERVER['SCRIPT_FILENAME'] ) ) {
$script_dir = dirname( $_SERVER['SCRIPT_FILENAME'] );
if ( $script_dir !== __DIR__ && ! in_array( $script_dir, $starting_dirs ) ) {
$starting_dirs[] = $script_dir;
}
}

// Also try DOCUMENT_ROOT based path construction from REQUEST_URI
if ( isset( $_SERVER['DOCUMENT_ROOT'] ) && isset( $_SERVER['REQUEST_URI'] ) ) {
$request_path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
if ( $request_path ) {
$doc_root_path = $_SERVER['DOCUMENT_ROOT'] . dirname( $request_path );
if ( is_dir( $doc_root_path ) && ! in_array( $doc_root_path, $starting_dirs ) ) {
$starting_dirs[] = $doc_root_path;
}
}
}

foreach ( $starting_dirs as $start_dir ) {
$result = iwp_find_wp_root_from_dir( $start_dir, $find_with_files, $find_with_dir );
if ( $result['status'] ) {
return $result;
}
}

// If all attempts failed, return the last result
return array(
'status' => false,
'root_path' => '',
);
}
}

if ( ! function_exists( 'iwp_find_wp_root_from_dir' ) ) {
/**
* Helper function to find WordPress root from a specific starting directory.
*
* @param string $start_dir Starting directory to traverse from
* @param string $find_with_files File to look for
* @param string $find_with_dir Directory to look for
* @return array Array with 'status' (bool) and 'root_path' (string)
*/
function iwp_find_wp_root_from_dir( $start_dir, $find_with_files = '', $find_with_dir = '' ) {
$is_find_root_dir = true;
$root_path = '';

if ( ! empty( $find_with_files ) ) {
$level = 0;
$root_path_dir = __DIR__;
$root_path = __DIR__;
$root_path_dir = $start_dir;
$root_path = $start_dir;
$is_find_root_dir = true;

while ( ! file_exists( $root_path . DIRECTORY_SEPARATOR . $find_with_files ) ) {
Expand All @@ -39,8 +98,8 @@ function iwp_get_wp_root_directory( $find_with_files = 'wp-load.php', $find_with

if ( ! empty( $find_with_dir ) ) {
$level = 0;
$root_path_dir = __DIR__;
$root_path = __DIR__;
$root_path_dir = $start_dir;
$root_path = $start_dir;
$is_find_root_dir = true;
while ( ! is_dir( $root_path . DIRECTORY_SEPARATOR . $find_with_dir ) ) {

Expand Down
4 changes: 1 addition & 3 deletions migrate/templates/ajax/part-site-plans.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,7 @@ class="plan-selector peer !hidden"
<?php } ?>
</div>
<div class="font-medium whitespace-nowrap">
<?php if ( $is_free_plan ) { ?>
<?php echo esc_html( $site_plan['rate']['monthly'] ); ?><span class="text-xs text-gray-500 font-light">/mo</span>
<?php } else { ?>
<?php if ( ! $is_free_plan ) { ?>
<?php echo esc_html( $site_plan['rate']['monthly'] ); ?><span class="text-xs text-gray-500 font-light">/mo - <?php echo esc_html( $site_plan['rate']['daily'] ); ?>/day</span>
<?php } ?>
</div>
Expand Down