get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->posts} WHERE post_status = 'publish' AND (post_content LIKE %s OR post_content LIKE %s)", '%' . $wpdb->esc_like( $site_url ) . '%', '%' . $wpdb->esc_like( $home_url ) . '%' ) ); // Check postmeta for hardcoded URLs. $meta_with_urls = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->postmeta} WHERE meta_value LIKE %s OR meta_value LIKE %s", '%' . $wpdb->esc_like( $site_url ) . '%', '%' . $wpdb->esc_like( $home_url ) . '%' ) ); // Check options for hardcoded URLs (excluding site_url and home). $options_with_urls = (int) $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM {$wpdb->options} WHERE option_name NOT IN ('siteurl', 'home', 'ping_sites', 'rewrite_rules') AND (option_value LIKE %s OR option_value LIKE %s)", '%' . $wpdb->esc_like( $site_url ) . '%', '%' . $wpdb->esc_like( $home_url ) . '%' ) ); $total_hardcoded = $posts_with_urls + $meta_with_urls + $options_with_urls; $details = array( 'site_url' => $site_url, 'posts_with_urls' => $posts_with_urls, 'meta_with_urls' => $meta_with_urls, 'options_with_urls' => $options_with_urls, 'total_hardcoded' => $total_hardcoded, ); if ( $total_hardcoded > 500 ) { return static::warning( sprintf( /* translators: %d: number of hardcoded URL locations */ __( 'Found %d locations with your current domain hardcoded in the database. This is normal for most sites, but you\'ll need to do a search-and-replace when migrating to a new domain.', '0-day-analytics' ), $total_hardcoded ), __( 'When migrating, use a tool like Better Search Replace or WP-CLI\'s search-replace command to update URLs. Make a backup first!', '0-day-analytics' ), $details ); } if ( $total_hardcoded > 100 ) { return static::info( sprintf( /* translators: %d: number of hardcoded URL locations */ __( 'Found %d locations with hardcoded URLs. This is typical and easy to update during migration with a search-and-replace tool.', '0-day-analytics' ), $total_hardcoded ), $details ); } return static::pass( sprintf( /* translators: %d: number of hardcoded URL locations */ __( 'Your site has %d locations with hardcoded URLs, which is minimal. Migration URL updates will be quick and straightforward.', '0-day-analytics' ), $total_hardcoded ), $details ); } } }