Skip to content

feat: add shared WP-CLI command registry for wp dokan#3301

Open
MdAsifHossainNadim wants to merge 5 commits into
developfrom
feature/dokan-cli-registry
Open

feat: add shared WP-CLI command registry for wp dokan#3301
MdAsifHossainNadim wants to merge 5 commits into
developfrom
feature/dokan-cli-registry

Conversation

@MdAsifHossainNadim

@MdAsifHossainNadim MdAsifHossainNadim commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

All Submissions:

  • My code follow the WordPress' coding standards
  • My code satisfies feature requirements
  • My code is tested
  • My code passes the PHPCS tests
  • My code has proper inline documentation
  • I've included related pull request(s) (optional)
  • I've included developer documentation (optional)
  • I've added proper labels to this pull request

Changes proposed in this Pull Request:

Adds a shared WP-CLI command registry to Dokan (free) so the wp dokan command namespace has a single owner in Lite, and any extension — starting with Dokan Pro — registers its commands under it from one place. This PR ships no user-facing commands on its own; it is the registration seam that Dokan Pro (and future free-tier commands) plug into.

What it does

  • New WeDevs\Dokan\CLI\Manager owns the wp dokan namespace.
  • Exposes a dokan_cli_commands filter — extensions add a [ 'dokan <command>' => HandlerClass::class ] map, and the Manager registers each entry with WP_CLI::add_command().
  • Loaded via a dedicated CliServiceProvider (tags the Manager cli-service) and resolved from init_classes() only under WP-CLI — mirroring the existing ajax-service / DOING_AJAX pattern, so nothing is instantiated on normal web requests.
  • Registers on init priority 99, so every extension has already contributed its commands to the filter by the time registration runs.

Why

Previously Dokan Pro registered its wp dokan … commands directly, so the wp dokan namespace had no owner in the free plugin. Moving the registry into Lite means:

  • Free-tier commands (a future wp dokan vendor, wp dokan withdraw, …) can be added right here.
  • Pro and other extensions extend the same namespace through a filter — the same Lite → Pro extension pattern already used for REST controllers (dokan_rest_api_class_map).

Developer usage

Register a command from any plugin that loads after Dokan:

add_filter( 'dokan_cli_commands', function ( $commands ) {
    $commands['dokan vendor'] = \My\Plugin\CLI\VendorCommand::class;
    return $commands;
} );

HandlerClass is a standard WP_CLI_Command subclass — the registry just forwards it to WP_CLI::add_command().


Implementation notes

  • includes/CLI/Manager.php — owns the namespace, applies the dokan_cli_commands filter, and registers each command with WP-CLI.
  • includes/DependencyManagement/Providers/CliServiceProvider.php — tags the Manager cli-service, mirroring AjaxServiceProvider.
  • dokan-class.phpinit_classes() resolves cli-service only under WP-CLI, right next to the existing ajax-service line.

Related Pull Request(s)

  • Dokan Pro — getdokan/dokan-pro#5789 — contributes wp dokan license and wp dokan module through the new filter. This PR should merge first, since Pro bails when the registry is absent.

How to test the changes in this Pull Request:

With Dokan Pro checked out on the companion branch (feature/dokan-cli-license-modules):

  1. wp dokan — lists the license and module subcommands.
  2. wp dokan module list --status=active — lists active modules.
  3. wp dokan license status — prints the current license status.
  4. Load any web page (non-CLI) and confirm no regression — the Manager is not instantiated off WP-CLI.

Without Dokan Pro (or with an older build) the dokan_cli_commands filter returns an empty map and no commands are registered.

Changelog entry

Title: Add a shared WP-CLI command registry for the wp dokan namespace

Dokan now owns the wp dokan WP-CLI namespace and exposes a dokan_cli_commands filter so Dokan and its extensions can register commands from a single place. Previously there was no CLI registry in Dokan Lite. No user-facing commands are added by this PR on its own.

Before Changes

Dokan Lite had no WP-CLI registry; the wp dokan namespace was owned ad-hoc by Dokan Pro.

After Changes

Dokan Lite owns the wp dokan namespace and exposes dokan_cli_commands; extensions register commands through the filter, and the registry loads only under WP-CLI.

Summary by CodeRabbit

  • New Features

    • Added WP-CLI support for registering Dokan commands when running in a CLI environment.
    • Introduced a dedicated CLI service so command setup is available only under WP-CLI.
  • Bug Fixes

    • Prevented CLI-related services and command registration from activating outside WP-CLI to avoid unintended behavior.

Introduce WeDevs\Dokan\CLI\Manager to own the `wp dokan` command namespace
and expose the `dokan_cli_commands` filter. Dokan and its extensions (e.g.
Dokan Pro) contribute their commands through this single registry, so
free-version commands can be added here later.

The Manager is instantiated only under WP-CLI (from init_classes) and
registers commands on `init` priority 99, so every extension has already
added its commands to the filter by then.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 2f16b0a1-6e1e-4cfb-b687-2898b7598a4e

📥 Commits

Reviewing files that changed from the base of the PR and between 4ff9706 and 805a28a.

📒 Files selected for processing (1)
  • includes/CLI/Manager.php

📝 Walkthrough

Walkthrough

This PR adds WP-CLI service wiring for Dokan, registers a new CLI manager through the container, and conditionally loads it during Dokan initialization when WP-CLI is active.

Changes

WP-CLI Command Registration

Layer / File(s) Summary
CLI service wiring
includes/DependencyManagement/Providers/ServiceProvider.php, includes/DependencyManagement/Providers/CliServiceProvider.php, dokan-class.php
A new CLI service provider is added to boot registration, it registers WeDevs\Dokan\CLI\Manager as a shared container service, and init_classes() resolves the cli-service only when WP_CLI is defined and truthy.
CLI command registration
includes/CLI/Manager.php
The new manager class skips non-WP-CLI runs, hooks command registration onto init at priority 99, and registers commands from the dokan_cli_commands filter with WP_CLI::add_command.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: adding a shared WP-CLI command registry for wp dokan.
Description check ✅ Passed The description covers the required template sections, change summary, testing steps, related PR, and changelog, with only minor optional items missing.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/dokan-cli-registry

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@includes/CLI/Manager.php`:
- Around line 38-45: Add defensive checks in register_commands() before calling
\WP_CLI::add_command(): ensure apply_filters( 'dokan_cli_commands', [] ) returns
an array, and skip or ignore any entry whose handler is not a valid, loadable
command class or callable. Mirror the validation approach used in the Captcha
Manager by verifying the filtered result with is_array and confirming each
$handler is safe to register (for example with class_exists and a
callable/instance check) so malformed filter values do not trigger warnings or
fatal errors.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 609137f1-f51a-4cc9-96c4-57fa4724561b

📥 Commits

Reviewing files that changed from the base of the PR and between ece223f and 71c2f3d.

📒 Files selected for processing (2)
  • dokan-class.php
  • includes/CLI/Manager.php

Comment thread includes/CLI/Manager.php
Load the WP-CLI registry through a dedicated CliServiceProvider that tags the
Manager as `cli-service`, resolved from init_classes() only under WP-CLI —
mirroring how the ajax-service group is loaded. This keeps CLI registration
inside Dokan's service container while avoiding a no-op Manager instantiation
on non-CLI requests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
includes/DependencyManagement/Providers/CliServiceProvider.php (1)

29-31: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

register() hardcodes Manager::class instead of iterating $this->services.

The sibling ServiceProvider::register() loops over its $services map to register every declared service. Here, $services declares Manager::class but register() ignores it and hardcodes the class directly — if a second CLI-related service is ever added to $services, it silently won't be registered unless register() is also updated.

♻️ Proposed refactor to keep `register()` in sync with `$services`
     public function register(): void {
-        $this->add_tags(
-            $this->getContainer()->addShared( Manager::class ),
-            $this->tags
-        );
+        foreach ( $this->services as $class_name ) {
+            $this->add_tags(
+                $this->getContainer()->addShared( $class_name ),
+                $this->tags
+            );
+        }
     }

Also applies to: 38-43

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@includes/DependencyManagement/Providers/CliServiceProvider.php` around lines
29 - 31, `CliServiceProvider::register()` is hardcoding `Manager::class` instead
of using the `$services` list, so any future entries in `$services` would not be
registered. Update `register()` to iterate over `$this->services` the same way
the sibling `ServiceProvider::register()` does, and register each declared
service from that array rather than referencing `Manager::class` directly.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@includes/DependencyManagement/Providers/CliServiceProvider.php`:
- Around line 29-31: `CliServiceProvider::register()` is hardcoding
`Manager::class` instead of using the `$services` list, so any future entries in
`$services` would not be registered. Update `register()` to iterate over
`$this->services` the same way the sibling `ServiceProvider::register()` does,
and register each declared service from that array rather than referencing
`Manager::class` directly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 89378a12-0f9e-4881-b57c-2331d5f15677

📥 Commits

Reviewing files that changed from the base of the PR and between 71c2f3d and 175534f.

📒 Files selected for processing (3)
  • dokan-class.php
  • includes/DependencyManagement/Providers/CliServiceProvider.php
  • includes/DependencyManagement/Providers/ServiceProvider.php

MdAsifHossainNadim and others added 3 commits July 1, 2026 13:19
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Guard the `dokan_cli_commands` filter result: bail if it is not an array, and
skip any entry whose name is not a non-empty string or whose handler is not a
callable/loadable class, so a misbehaving filter cannot trigger WP-CLI warnings
or fatals. Mirrors the validation the Captcha Manager already applies to its
provider filter.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Simplify register_commands(): cast the `dokan_cli_commands` result to an array
(covering a misbehaving non-array filter) and let WP-CLI validate each
name/handler itself. Drops the verbose per-entry checks.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@MdAsifHossainNadim MdAsifHossainNadim self-assigned this Jul 1, 2026
@MdAsifHossainNadim MdAsifHossainNadim added Needs: Testing This requires further testing Needs: Dev Review It requires a developer review and approval labels Jul 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Needs: Dev Review It requires a developer review and approval Needs: Testing This requires further testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant