Skip to content

Conversation

@sapayth
Copy link
Member

@sapayth sapayth commented Apr 22, 2025

fixes #722

Subscription dashboard (plugin) showing 0 always instead of subscribers number. Also the list after the subscription number is clicked is fixed too in this PR

image

Summary by CodeRabbit

  • New Features

    • Added the ability to retrieve users with a specific subscription pack and status.
  • Refactor

    • Improved the way subscriber lists are filtered and retrieved for better accuracy and security.

@coderabbitai
Copy link

coderabbitai bot commented Apr 22, 2025

Walkthrough

The updates refactor SQL query construction in two admin-related PHP files. In List_Table_Subscribers.php, the query within the prepare_items() method is now built dynamically, adding WHERE clauses only for present and non-empty parameters, and safely preparing the statement with the correct number of arguments. In Subscription.php, a new public method subscription_pack_users is introduced, retrieving users by subscription pack and status with improved parameterized SQL for security and flexibility. No changes were made to the signatures of existing public entities, except for the addition of the new method.

Changes

File(s) Change Summary
includes/Admin/List_Table_Subscribers.php Refactored SQL query construction in prepare_items() to dynamically add WHERE clauses and safely prepare statements.
includes/Admin/Subscription.php Added new method subscription_pack_users to fetch users by pack and status, using parameterized SQL queries.

Assessment against linked issues

Objective Addressed Explanation
Add missing translatable string: "You must be logged in to view the content." (#722) No changes related to translation strings or this message are present.

Poem

A hop and a skip in the code today,
SQL queries now safely find their way.
With new methods to fetch, and conditions so neat,
Rabbits rejoice—no more unsafe SQL to beat!
🐇✨
The warren is safer, the queries are tight,
CodeRabbit approves—everything’s right!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4853362 and b31dca4.

📒 Files selected for processing (2)
  • includes/Admin/List_Table_Subscribers.php (1 hunks)
  • includes/Admin/Subscription.php (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
includes/Admin/Subscription.php (1)
class/subscription.php (1)
  • subscription_pack_users (1073-1096)
🪛 GitHub Actions: Inspections
includes/Admin/List_Table_Subscribers.php

[warning] 1-1: Processing form data without nonce verification.

includes/Admin/Subscription.php

[warning] 1-1: Processing form data without nonce verification.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (2)
includes/Admin/Subscription.php (1)

1102-1145: Well-implemented dynamic SQL query builder with proper parameter binding

The refactored subscription_pack_users() method is a significant improvement over the previous implementation. You've correctly:

  1. Built the SQL query dynamically with conditional WHERE clauses
  2. Used an array to collect both the WHERE conditions and their values
  3. Applied proper parameter binding with %d placeholders
  4. Used $wpdb->prepare() to safely execute the query

This change effectively addresses the reported issue where subscription numbers weren't showing correctly, while also enhancing security by preventing SQL injection.

includes/Admin/List_Table_Subscribers.php (1)

180-204: Improved SQL query construction with proper sanitization and parameterization

The refactored prepare_items() method is a significant improvement over the previous implementation. You've:

  1. Started with a clean base query
  2. Built the WHERE clauses conditionally based on request parameters
  3. Collected parameters in an array to match the placeholders
  4. Used $wpdb->prepare() correctly with the right number of parameters

This approach is more secure against SQL injection and addresses the underlying issue with subscription numbers not showing correctly.

✨ 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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Rubaiyat-E-Mohammad Rubaiyat-E-Mohammad added QA In Progress QA Approved This PR is approved by the QA team Ready to Merge This PR is now ready to be merged and removed needs: testing QA In Progress labels Apr 22, 2025
@sapayth sapayth merged commit 97c94c0 into weDevsOfficial:develop Apr 22, 2025
1 of 2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

QA Approved This PR is approved by the QA team Ready to Merge This PR is now ready to be merged

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants