Skip to content

Fix #1764 #1765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 5, 2025
Merged

Fix #1764 #1765

merged 6 commits into from
Jun 5, 2025

Conversation

pfefferle
Copy link
Member

@pfefferle pfefferle commented Jun 4, 2025

The problem with the current implementation of the "default attachment number" is, that the default will not be changed if the user has saved the old default (3). This PR checks if the plugin runs in block mode and ignores the setting then. This PR re-adds the "Media attachments" setting, to be able to change the default.

Fixes #1764

Proposed changes:

  • Check for blog mode in get_option hook (classic editor or block editor)
  • Only use option if blog uses classic editor otherwise fall back to default
  • Re-added "Media attachments" to be able to set the default value also for block-editor users

Other information:

  • Have you written new tests for your changes, if applicable?

Testing instructions:

  • Go to '..'

Changelog entry

  • Automatically create a changelog entry from the details below.
Changelog Entry Details

Significance

  • Patch
  • Minor
  • Major

Type

  • Added - for new features
  • Changed - for changes in existing functionality
  • Deprecated - for soon-to-be removed features
  • Removed - for now removed features
  • Fixed - for any bug fixes
  • Security - in case of vulnerabilities

Message

Allow users of the block editor to set the default number of media attachments.

@pfefferle pfefferle marked this pull request as ready for review June 4, 2025 16:11
@pfefferle pfefferle requested review from obenland and Copilot June 4, 2025 16:11
Copy link

@Copilot 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 ensures the saved default for max image attachments is not overridden when using the block editor unless the classic editor plugin is active.

  • Update default_max_image_attachments() to reset the value only in block mode when the classic editor plugin is inactive
  • Add tests for the new behavior under different editor modes

Reviewed Changes

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

File Description
tests/includes/class-test-options.php Add test_default_max_image_attachments() covering block mode behavior
includes/class-options.php Update default_max_image_attachments() to ignore stored setting in block mode without classic editor plugin
Comments suppressed due to low confidence (2)

includes/class-options.php:145

  • Wrap the is_plugin_active call in a function_exists('is_plugin_active') check to avoid a fatal error when that function isn’t loaded outside admin contexts.
( site_supports_blocks() && ! is_plugin_active( 'classic-editor/classic-editor.php' ) )

tests/includes/class-test-options.php:43

  • [nitpick] Add a test case that simulates the classic editor plugin being active in block mode (mocking is_plugin_active to return true) to verify numeric values are preserved instead of reset.
public function test_default_max_image_attachments() {

@pfefferle pfefferle added [Type] Bug Something isn't working php Pull requests that update Php code [Status] Needs review and removed [Status] In Progress labels Jun 4, 2025
Copy link
Member

@obenland obenland left a comment

Choose a reason for hiding this comment

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

The change has the potential to create a similar confusion on sites where the option value is greater than 4, where it'll be reduced back to the default.

Overall, I think we should re-consider the removal of the setting for sites using the Block Editor. While these sites do have a way of specifying the number of attachments on a per-post basis, the setting would enable it across posts and define a general preference.

@pfefferle
Copy link
Member Author

pfefferle commented Jun 5, 2025

Overall, I think we should re-consider the removal of the setting for sites using the Block Editor. While these sites do have a way of specifying the number of attachments on a per-post basis, the setting would enable it across posts and define a general preference.

Makes sense! I re-enabled the option for all users. I think this is the simplest, most consistent, and most straightforward solution so far.

Copy link
Member

@obenland obenland left a comment

Choose a reason for hiding this comment

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

Thank you!

@pfefferle pfefferle merged commit 5fb3859 into trunk Jun 5, 2025
11 checks passed
@pfefferle pfefferle deleted the fix/1764 branch June 5, 2025 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] WP Admin php Pull requests that update Php code [Status] Needs review [Type] Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Number of attached images
3 participants