Skip to content

Fix activitypub_max_image_attachments check #1822

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 3 commits into from
Jun 16, 2025
Merged

Conversation

pfefferle
Copy link
Member

@pfefferle pfefferle commented Jun 16, 2025

The code currently uses the Ternary Operator (?:) to check if the activitypub_max_image_attachments meta is set and to fallback to the default ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS otherwise. The problem is, that the Ternary Operator sees '0' and 0 as negative/empty/null values and falls back to the default if the user sets 0 as the number of images in the block editor.

Fixes #1818

Proposed changes:

  • Check for is_numberic instead of using the Ternary Operator

Other information:

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

Testing instructions:

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

The image attachment setting now correctly respects a value of 0, instead of falling back to the default.

@pfefferle pfefferle self-assigned this Jun 16, 2025
@pfefferle pfefferle requested a review from Copilot June 16, 2025 09:45
@pfefferle pfefferle requested a review from obenland June 16, 2025 09:45
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 fixes the logic for determining the maximum number of image attachments so that a value of 0 is correctly accepted instead of falling back to the default. It replaces the short ternary operator with an explicit is_numeric check.

  • Replace ?: fallback with is_numeric check for post meta
  • Add corresponding changelog entry

Reviewed Changes

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

File Description
includes/transformer/class-post.php Use is_numeric to validate meta before falling back
.github/changelog/1822-from-description Add patch-level changelog entry
Comments suppressed due to low confidence (1)

includes/transformer/class-post.php:288

  • Add a unit test that sets activitypub_max_image_attachments to 0 and verifies that the transformer returns 0 instead of the default value to cover this edge case.
if ( ! is_numeric( $max_media ) ) {

@pfefferle pfefferle merged commit 9c4a598 into trunk Jun 16, 2025
13 checks passed
@pfefferle pfefferle deleted the fix/max-image-attachments branch June 16, 2025 13:35
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.

Maximum image attachments ignores 0
3 participants