Skip to content

Comments

Implement wp site get command to enable site operations by URL#571

Merged
swissspidy merged 10 commits intomainfrom
copilot/allow-delete-site-with-url
Feb 23, 2026
Merged

Implement wp site get command to enable site operations by URL#571
swissspidy merged 10 commits intomainfrom
copilot/allow-delete-site-with-url

Conversation

Copy link
Contributor

Copilot AI commented Feb 4, 2026

Multisite installations with custom domains couldn't easily delete sites by URL - only by ID or slug, which required manual lookup in automated workflows.

Implementation

Adds wp site get <site> command that accepts both site IDs and full URLs:

URL detection and lookup

  • Uses is_numeric() to distinguish between site IDs (numeric) and URLs/domains (non-numeric)
  • Automatically normalizes URLs without scheme by prepending http://
  • Parses URLs via wp_parse_url() to extract domain and path
  • Uses WordPress's cached get_blog_id_from_url() function for efficient lookups
  • Supports flexible input formats:
    • Numeric site IDs: 2
    • Full URLs: http://example.com/site1/
    • Domains with paths: example.com/site1
    • Simple domains: example.com
    • Subdomains: subdomain.example.com

Output formatting

  • Returns site details via WP_CLI\Formatter with standard format options
  • Default fields: blog_id, url, last_updated, registered
  • Optional fields: site_id, domain, path, public, archived, mature, spam, deleted, lang_id
  • Supports --field parameter for single field extraction

Command registration

  • Added to composer.json commands list

Usage

# Get site ID from URL (with or without scheme)
$ wp site get example.com/subdir/ --field=blog_id
2

$ wp site get http://example.com/subdir/ --field=blog_id
2

# Delete site by URL
$ wp site delete $(wp site get example.com/subdir/ --field=blog_id) --yes
Success: The site at 'http://example.com/subdir/' was deleted.

Test Coverage

Added comprehensive Behat test scenarios covering:

  • Site lookup by numeric ID
  • Site lookup by full URL with scheme
  • Site lookup by URL without scheme
  • Site lookup by domain with path (no trailing slash)
  • Site lookup by subdomain without scheme
  • Main site lookup by domain only
  • Error handling for invalid/non-existent URLs

All 32 test scenarios pass (372 steps).

Follows the pattern established by wp user get and wp post get for consistency with existing commands.

Original prompt

This section details on the original issue you should resolve

<issue_title>site delete: allow deleting a site with the --url option</issue_title>
<issue_description>## Feature Request

Describe your use case and the problem you are facing

Currently the blog ID or slug must be specified when using the command. In cases where a custom domain is used, however, the --slug option fails and it is tedious to look up the assigned site ID in an automated use case.

Describe the solution you'd like

Allow site deletion by only specifying the --url option. For example: wp site delete --url="http://example.com".
</issue_description>

Comments on the Issue (you are @copilot in this section)

@swissspidy We could implement `wp site get ` instead, then one could pair `wp site delete` with `wp site get http://example.com --field=id`. This would be more in line with all the other commands.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@github-actions github-actions bot added command:network-meta-delete Related to 'network meta delete' command command:network-meta-get Related to 'network meta get' command command:network Related to 'network' command labels Feb 4, 2026
@codecov
Copy link

codecov bot commented Feb 4, 2026

Codecov Report

❌ Patch coverage is 93.54839% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/Site_Command.php 93.54% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copilot AI and others added 4 commits February 4, 2026 16:34
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
… reliability

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
Copilot AI changed the title [WIP] Add option to delete site using --url Implement wp site get command to enable site operations by URL Feb 4, 2026
Copilot AI requested a review from swissspidy February 4, 2026 16:56
@swissspidy swissspidy requested a review from Copilot February 4, 2026 19:07

This comment was marked as resolved.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@swissspidy swissspidy marked this pull request as ready for review February 5, 2026 06:28
@swissspidy swissspidy requested a review from a team as a code owner February 5, 2026 06:28
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

gemini-code-assist[bot]

This comment was marked as resolved.

@swissspidy

This comment was marked as resolved.

Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>

This comment was marked as resolved.

@swissspidy swissspidy merged commit 31bb185 into main Feb 23, 2026
69 checks passed
@swissspidy swissspidy deleted the copilot/allow-delete-site-with-url branch February 23, 2026 09:48
@swissspidy swissspidy added this to the 2.9.0 milestone Feb 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:network Related to 'network' command command:network-meta-delete Related to 'network meta delete' command command:network-meta-get Related to 'network meta get' command

Projects

None yet

Development

Successfully merging this pull request may close these issues.

site delete: allow deleting a site with the --url option

2 participants