Skip to content

PROD-10342 - Fix empty default extensions in Manage File Extensions modal - #5040

Open
sajib-bb wants to merge 4 commits into
releasefrom
PROD-10342
Open

PROD-10342 - Fix empty default extensions in Manage File Extensions modal #5040
sajib-bb wants to merge 4 commits into
releasefrom
PROD-10342

Conversation

@sajib-bb

Copy link
Copy Markdown

Jira Issue:

https://buddyboss.atlassian.net/browse/PROD-10342

General Note

Keep all conversations related to this PR in the associated Jira issue(s). Do NOT add comment on this PR or edit this PR’s description.

Notes to Developer

  • Ensure the IDs (i.e. PROD-1) of all associated Jira issues are reference in this PR’s title
  • Ensure that you have achieved the Definition of Done before submitting for review
  • When this PR is ready for review, move the associate Jira issue(s) to “Needs Review” (or “Code Review” for Dev Tasks)

Notes to Reviewer

  • Ensure that the Definition of Done have been achieved before approving a PR
  • When this PR is approved, move the associated Jira issue(s) to “Needs QA” (or “Approved” for Dev Tasks)

bb_media_get_extension_options() and bb_media_get_extension_data()
read the extensions option with an empty array as fallback, so a
site where bp_document_extensions_support or bp_video_extensions_support
was never saved shows no default extensions in the Manage File
Extensions modal.

Also fixes the same gap in the toggle-only save path in
bb_media_sanitize_extensions(), which could otherwise persist an
empty array and permanently lose the defaults on first toggle.
The document extensions field is registered during bb_register_features,
before bp_media_allowed_document_type() is guaranteed to be loaded, so
its options and extension_data can still end up empty even with the
fallback in callbacks.php.

Re-populate the field on bb_admin_settings_before_get_feature, which
fires per settings request after the full plugin has loaded, so the
Manage File Extensions modal reliably shows the default extensions.
Same fix as the document extensions field: bp_video_allowed_video_type()
may not be loaded yet when the video extensions field is registered,
leaving its options and extension_data empty. Refresh them on
bb_admin_settings_before_get_feature once the plugin has fully loaded.
@sajib-bb
sajib-bb requested a review from reza-bb August 23, 2026 04:23
@sajib-bb sajib-bb self-assigned this Aug 23, 2026
…/document default mix-up

bb_media_get_extension_options() and bb_media_get_extension_data() only
substituted the hard-coded default extension list when bp_get_option()
found the option row missing entirely. That doesn't cover sites where
bp_document_extensions_support (or bp_video_extensions_support) exists
in wp_options but was saved as an empty array — which is exactly what
the legacy bb_update_to_2_4_10() upgrade routine does on any site that
passed through DB version 20561 without ever having a custom extension
list: it reads the option with array() as fallback, finds nothing to
merge, and writes that same empty array back unconditionally. Once an
option is poisoned that way, get_option() keeps returning the real
(empty) stored value forever, so the "fall back to defaults" fix never
engages for that site.

Both getters also always used bp_media_allowed_document_type() as their
default source regardless of $option_name, so a site where
bp_video_extensions_support was genuinely never saved would have its
video extensions field populated with document extensions instead of
video ones.

- Add bb_media_get_default_extensions( $option_name ) to centralize the
  option-name -> defaults mapping in one place instead of duplicating
  it (correctly, for video vs document) across three call sites.
- Use it in bb_media_get_extension_options(), bb_media_get_extension_data(),
  and bb_media_sanitize_extensions(), and treat an empty-but-present
  option the same as a missing one by falling back to the defaults
  whenever the read comes back empty.

@reza-bb reza-bb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please check the feedback and update accordingly

bb_register_feature_field( 'media', 'videos', 'videos_settings', $field );
}
add_action( 'bb_admin_settings_before_get_feature', 'bb_media_lazy_refresh_video_extension_defaults' );

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

WPCS indentation missing

// default extensions to an empty array before any of them have been
// persisted.
//
// @since BuddyBoss [BBVERSION]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

WPCS Squiz.Commenting.InlineComment.InvalidEndChar error

// See bb_media_get_extension_options() above — an empty-but-present
// option needs the same fallback as a missing one.
//
// @since BuddyBoss [BBVERSION]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

WPCS Squiz.Commenting.InlineComment.InvalidEndChar error

// saved at all — get_option() only substitutes the default for a
// missing row, so an empty-but-present option needs its own fallback.
//
// @since BuddyBoss [BBVERSION]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

WPCS Squiz.Commenting.InlineComment.InvalidEndChar error

*
* @param string $feature_id The feature being loaded.
*/
function bb_media_lazy_refresh_video_extension_defaults( $feature_id ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the two bb_media_lazy_refresh_*_extension_defaults() functions are ~90% identical. One shared helper parameterised by panel/section/field and some wrappers cuts ~40 lines and removes the copy-paste risk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants