Skip to content

Conversation

@aminurislamarnob
Copy link

@aminurislamarnob aminurislamarnob commented Jan 22, 2026

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:

Refactored the grant_access_to_download() AJAX method to use the standard dokan_get_template_part() function instead of direct include for loading the download permission template, improving consistency with Dokan's template loading conventions.

How to test the changes in this Pull Request:

  1. Log in as a vendor
  2. Navigate to Dokan Dashboard → Orders
  3. Create or select an order containing a downloadable product
  4. Click on the order to view details
  5. Scroll to the Downloadable Product Permissions section
  6. Click "Grant Access" button
  7. Expected: Download permission should be granted successfully and displayed in the list through Ajax response.

Changelog entry

Changes Made

  • Replaced direct include with dokan_get_template_part() in Ajax::grant_access_to_download()
  • Added template arguments array with proper filtering via dokan_order_download_permission_args hook
  • Improved template variable passing using the standardized $template_args pattern
  • Enhanced extensibility by allowing theme/plugin developers to filter template arguments

Benefits

  1. Consistency: Aligns with Dokan's established template loading patterns used throughout the codebase
  2. Theme Override Support: Enables theme developers to override the template by placing it in {theme}/dokan/orders/order-download-permission-html.php
  3. Extensibility: The new filter hook allows developers to modify template data before rendering
  4. Maintainability: Follows the same pattern as other AJAX handlers like [seller_listing_search()]

Before Changes

include dirname( __DIR__ ) . '/templates/orders/order-download-permission-html.php';

After Changes

$template_args = apply_filters(
    'dokan_order_download_permission_args', [
        'download'   => $download,
        'product'    => $product,
        'file_count' => $file_count,
        'loop'       => $loop,
    ]
);

dokan_get_template_part( 'orders/order-download-permission-html', false, $template_args );

FOR PR REVIEWER ONLY:

As a reviewer, your feedback should be focused on the idea, not the person. Seek to understand, be respectful, and focus on constructive dialog.

As a contributor, your responsibility is to learn from suggestions and iterate your pull request should it be needed based on feedback. Seek to collaborate and produce the best possible contribution to the greater whole.

  • Correct — Does the change do what it’s supposed to? ie: code 100% fulfilling the requirements?
  • Secure — Would a nefarious party find some way to exploit this change? ie: everything is sanitized/escaped appropriately for any SQL or XSS injection possibilities?
  • Readable — Will your future self be able to understand this change months down the road?
  • Elegant — Does the change fit aesthetically within the overall style and architecture?

Summary by CodeRabbit

  • Refactor
    • Improved order download display handling to support better customization through flexible, filterable template data.

✏️ Tip: You can customize this high-level summary in your review settings.

- Replace direct include with dokan_get_template_part()
- Add dokan_order_download_permission_args filter
- Enable theme override support
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 22, 2026

📝 Walkthrough

Walkthrough

Refactors the template loading mechanism in includes/Ajax.php by replacing direct file inclusion with a structured templating approach. Creates a template_args array containing download, product, file_count, and loop, applies a dokan_order_download_permission_args filter, and renders the template via dokan_get_template_part.

Changes

Cohort / File(s) Summary
Template System Refactoring
includes/Ajax.php
Replaces direct template include with structured args-based templating; introduces filterable data bag via dokan_order_download_permission_args filter for enhanced extensibility

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

  • #2574 — Modifies how the download-permission template reads permission IDs, complementing this PR's changes to template argument passing

Suggested labels

Needs: Testing, Dev Review Done

Suggested reviewers

  • mrabbani

Poem

🐰 A template once loose, now packaged with care,
With filters to customize, data to share,
From direct includes we hop and we bound,
To structured, filtered args—a more elegant ground!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: refactoring to use dokan_get_template_part for download permissions instead of direct include.
Description check ✅ Passed The description is comprehensive and covers most required sections: changes proposed, testing steps, changelog entries, before/after comparison, and reviewer checklist are all present and detailed.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

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 and usage tips.

include dirname( __DIR__ ) . '/templates/orders/order-download-permission-html.php';
$template_args = apply_filters(
'dokan_order_download_permission_args', [
'download' => $download,
Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix the PHP array alignment stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants