Skip to content

refactor: update hook check in asset enqueuing#58

Merged
guibranco merged 2 commits into
mainfrom
feature/fix-prefix
Jun 18, 2026
Merged

refactor: update hook check in asset enqueuing#58
guibranco merged 2 commits into
mainfrom
feature/fix-prefix

Conversation

@guibranco

@guibranco guibranco commented Jun 18, 2026

Copy link
Copy Markdown
Owner

📑 Description

Change the string check in the enqueue_assets function from 'stracini-visitor-analytics' to 'sva-'. This update helps broaden the scope and future-proofs the function for additional sub-pages or features that may have 'sva-' namespaces. Additionally, this ensures that asset enqueuing applies consistently across new admin pages related to the plugin.

✅ Checks

  • My pull request adheres to the code style of this project
  • My code requires changes to the documentation
  • I have updated the documentation as required
  • All the tests have passed

☢️ Does this introduce a breaking change?

  • Yes
  • No

Summary by Sourcery

Broaden the admin asset enqueuing hook check to match all plugin-related pages using the generic 'sva-' namespace instead of a specific slug.

Summary by CodeRabbit

  • Bug Fixes
    • Improved the admin interface asset loading mechanism to ensure plugin CSS and JavaScript resources are correctly delivered to the intended administrative pages, preventing unnecessary resource loading on unrelated pages.

Change the string check in the `enqueue_assets` function from
'stracini-visitor-analytics' to 'sva-'. This update helps broaden
the scope and future-proofs the function for additional
sub-pages or features that may have 'sva-' namespaces.
Additionally, this ensures that asset enqueuing applies
consistently across new admin pages related to the plugin.
@sourcery-ai

sourcery-ai Bot commented Jun 18, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Updates the admin asset enqueue guard so that assets are loaded for any admin page hook containing the broader 'sva-' namespace instead of the previous, more specific 'stracini-visitor-analytics' string, ensuring assets are applied across current and future plugin admin pages.

Flow diagram for updated enqueue_assets hook check

flowchart TD
  A["enqueue_assets(hook)"] --> B{"str_contains(hook, 'sva-')"}
  B -- "No" --> C["return"]
  B -- "Yes" --> D["Enqueue admin assets"]
Loading

File-Level Changes

Change Details Files
Broadened the admin hook substring check used to decide when to enqueue plugin assets.
  • Replaced the string literal used in the str_contains check from a full page slug to a shorter 'sva-' namespace prefix
  • Maintained the early-return pattern so assets are only enqueued when the admin hook matches the new namespace pattern
includes/class-sva-admin.php

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 577625a0-9e3b-4789-83d5-8427832e59e6

📥 Commits

Reviewing files that changed from the base of the PR and between b250a55 and 9022b24.

📒 Files selected for processing (1)
  • includes/class-sva-admin.php

Walkthrough

In SVA_Admin::enqueue_assets, the admin page eligibility check is changed from matching 'stracini-visitor-analytics' to matching 'sva-' in the hook suffix string. This single-line change controls which WordPress admin pages receive the plugin's enqueued CSS, JS, and localized script data.

Changes

Admin Asset Enqueue Filter

Layer / File(s) Summary
Admin page hook suffix filter update
includes/class-sva-admin.php
The hook suffix guard in enqueue_assets now checks for 'sva-' instead of 'stracini-visitor-analytics', changing which admin pages trigger asset enqueueing and script localization.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

Poem

🐇 A single string swap, so small and neat,
The hook now listens for 'sva-' to greet,
No more long names to match on the screen,
Just a tidy short prefix, crisp and clean,
Hop hop hooray, the assets align! 🎉

✨ 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/fix-prefix

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.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • Broadening the hook check to str_contains( $hook, 'sva-' ) may match unintended admin pages that happen to include sva- in their hook; consider tightening this to a more specific pattern (e.g., a known prefix or exact slug pattern) to avoid accidental matches.
  • Since 'sva-' is now the logical namespace for admin pages, consider extracting it into a class constant or shared configuration to avoid future magic strings and keep the namespace consistent across the codebase.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Broadening the hook check to `str_contains( $hook, 'sva-' )` may match unintended admin pages that happen to include `sva-` in their hook; consider tightening this to a more specific pattern (e.g., a known prefix or exact slug pattern) to avoid accidental matches.
- Since `'sva-'` is now the logical namespace for admin pages, consider extracting it into a class constant or shared configuration to avoid future magic strings and keep the namespace consistent across the codebase.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@sonarqubecloud

Copy link
Copy Markdown

@github-actions

Copy link
Copy Markdown
Contributor

🔍 WordPress Plugin Check Report

⚠️ Status: Passed with warnings

📊 Report

🎯 Total Issues ❌ Errors ⚠️ Warnings
1 0 1

⚠️ Warnings (1)

📁 includes/class-sva-db.php (1 warning)
📍 Line 🔖 Check 💬 Message
399 PluginCheck.Security.DirectDB.UnescapedDBParameter Unescaped parameter $sql used in $wpdb->get_results()\n$sql assigned unsafely at line 394.

🤖 Generated by WordPress Plugin Check Action • Learn more about Plugin Check

@guibranco guibranco enabled auto-merge (squash) June 18, 2026 12:47
@gstraccini gstraccini Bot added the ☑️ auto-merge Automatic merging of pull requests (gstraccini-bot) label Jun 18, 2026
@guibranco guibranco merged commit 81299c6 into main Jun 18, 2026
15 of 16 checks passed
@guibranco guibranco deleted the feature/fix-prefix branch June 18, 2026 12:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

☑️ auto-merge Automatic merging of pull requests (gstraccini-bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants