Skip to content

FIXES wp-rocket#7556: Adds a filter to show or not the imagify banner#31

Merged
Miraeld merged 8 commits intotrunkfrom
enhancement/7556-add-filter-banner-imagify
Dec 29, 2025
Merged

FIXES wp-rocket#7556: Adds a filter to show or not the imagify banner#31
Miraeld merged 8 commits intotrunkfrom
enhancement/7556-add-filter-banner-imagify

Conversation

@Miraeld
Copy link
Copy Markdown
Contributor

@Miraeld Miraeld commented Dec 15, 2025

Description

Fixes wp-media/wp-rocket#7556

Add filter to control Imagify banner on Media gallery components

  • Add 'wpmedia_plugin_family_show_imagify_banner' filter to allow developers to control banner visibility
  • Banner is enabled by default and can be disabled by setting filter to false
  • Bump version to 1.0.7

Type of change

  • Enhancement (non-breaking change which improves an existing functionality).

Detailed scenario

What was tested

How to test

  1. Install WP Rocket
  2. Ensure Imagify is not installed or activated
  3. Navigate to Media > Library or edit a post
  4. Verify the Imagify promotion banner appears or not

How to test

Use the filter add_filter( 'wpmedia_plugin_family_show_imagify_banner', '__return_false' ); to enable/disable the banner

Affected Features & Quality Assurance Scope

  • Imagify promotion banner: The banner display logic now includes a filter hook, allowing third-party customization
  • Media library and post editor screens: These are the primary screens where the banner appears
  • Default behavior: No changes to existing functionality - banner still shows by default

Technical description

Documentation

This pull request introduces a new dependency for typed filter application, updates the plugin version, and enhances the logic for displaying the Imagify banner by making it filterable and type-safe. The most important changes are grouped below:

Dependency management:

  • Added a new required dependency on wp-media/apply-filters-typed in composer.json to support type-safe filter application.

Plugin versioning:

  • Updated the plugin version from 1.0.6 to 1.0.7 in PluginFamily.php.

Admin banner display logic:

  • Refactored the logic for determining when to show the Imagify banner in the admin area, and introduced a new filter wpmedia_plugin_family_show_imagify_banner that uses the new type-safe filter application (wpm_apply_filters_typed). This allows developers to reliably modify the banner display behavior.

New dependencies

"wp-media/apply-filters-typed": "^1.0" in composer.json

Risks

None

Mandatory Checklist

Code validation

  • I validated all the Acceptance Criteria. If possible, provide screenshots or videos.
  • I triggered all changed lines of code at least once without new errors/warnings/notices.
  • I implemented built-in tests to cover the new/changed code.

Code style

  • I wrote a self-explanatory code about what it does.
  • I protected entry points against unexpected inputs.
  • I did not introduce unnecessary complexity.
  • Output messages (errors, notices, logs) are explicit enough for users to understand the issue and are actionnable.

- Add 'wpmedia_plugin_family_show_imagify_banner' filter to allow developers to control banner visibility
- Banner is enabled by default and can be disabled by setting filter to false
- Bump version to 1.0.7

Fixes wp-media/wp-rocket#7556
@Miraeld Miraeld requested a review from a team December 15, 2025 01:34
@Miraeld Miraeld self-assigned this Dec 15, 2025
Copilot AI review requested due to automatic review settings December 15, 2025 01:34
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a filter hook to allow developers to control the visibility of the Imagify banner in Media gallery components. The change introduces the wpmedia_plugin_family_show_imagify_banner filter with type-safe application and bumps the plugin version to 1.0.7.

  • Adds wpmedia_plugin_family_show_imagify_banner filter to make banner visibility customizable
  • Introduces wp-media/apply-filters-typed dependency for type-safe filter handling
  • Refactors can_enqueue_admin_assets() method logic for clearer control flow

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Controller/PluginFamily.php Adds filter hook with documentation, refactors conditional logic in can_enqueue_admin_assets(), and bumps version to 1.0.7
composer.json Adds wp-media/apply-filters-typed dependency for type-safe filter application

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread composer.json Outdated
Comment thread src/Controller/PluginFamily.php Outdated
Comment thread src/Controller/PluginFamily.php Outdated
- Fix composer.json formatting (remove trailing whitespace and blank line)
- Refactor can_enqueue_admin_assets to use optional override pattern
- Revert test changes per review discussion
@Miraeld
Copy link
Copy Markdown
Contributor Author

Miraeld commented Dec 15, 2025

I've addressed the review comments from @jeawhanlee and Copilot:

Changes in commit 49140f8:

  1. Fixed composer.json formatting

    • Removed trailing whitespace on closing brace
    • Removed extra blank line in the require block
  2. Refactored can_enqueue_admin_assets to use optional override pattern

    • Changed from if-else to set default value first, then override if condition is met
    • This follows the recommended pattern from @jeawhanlee

The code now follows the requested patterns and formatting standards.

jeawhanlee
jeawhanlee previously approved these changes Dec 15, 2025
Comment thread src/Controller/PluginFamily.php Outdated
jeawhanlee
jeawhanlee previously approved these changes Dec 16, 2025
- Add wpmedia_plugin_family_show_imagify_banner filter to enqueue_assets method
- This ensures the filter works for both classic media library and block editor media modal
- Fixes issue where banner was not hidden in block editor when filter returned false
Miraeld added a commit to wp-media/wp-rocket that referenced this pull request Dec 18, 2025
Comment thread src/Controller/PluginFamily.php
- Create should_show_imagify_banner() method to centralize filter logic
- Remove duplicate filter code from enqueue_assets() and can_enqueue_admin_assets()
- Both methods now use the shared method for consistency and maintainability
@Miraeld
Copy link
Copy Markdown
Contributor Author

Miraeld commented Dec 18, 2025

@jeawhanlee Good point!

I've refactored the code to eliminate the duplication. Changes in commit d935f98:

Created a shared method:

private function should_show_imagify_banner( bool $default_value = true ): bool

This method:

  • Centralizes the filter logic in one place
  • Accepts a default value parameter (useful for can_enqueue_admin_assets which passes the calculated $can_enqueue value)
  • Returns the filtered result

Both methods now use it:

  • enqueue_assets() → calls should_show_imagify_banner() with default true
  • can_enqueue_admin_assets() → calls should_show_imagify_banner($can_enqueue) with the calculated value

@Miraeld Miraeld requested a review from jeawhanlee December 18, 2025 10:05
@Mai-Saad
Copy link
Copy Markdown

Working as expected. existing issue(s) already on trunk. wp-media/wp-rocket#7962

@Miraeld Miraeld added this pull request to the merge queue Dec 29, 2025
Merged via the queue into trunk with commit b763b33 Dec 29, 2025
7 of 8 checks passed
@remyperona remyperona deleted the enhancement/7556-add-filter-banner-imagify branch April 30, 2026 17:34
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.

Add a filter to control Imagify banner on Media gallery components

4 participants