Skip to content

Conversation

@patil-vipul
Copy link
Collaborator

@patil-vipul patil-vipul commented Dec 18, 2025

Overview

This PR refactors the OneMedia plugin to follow PSR-4 autoloading standards and modern PHP best practices, improving code organization, maintainability, and developer experience.

Code Organization & Architecture

PSR-4 Autoloading: Restructured all PHP classes to follow PSR-4 naming conventions and directory structure
Namespace Organization: Organized code into logical modules under OneMedia\Modules*

  • Core: Core functionality (Assets, REST)
  • Plugin: Plugin-specific features (Admin, MediaSharing, MediaLibrary)
  • Rest: REST API controllers
  • Settings: Settings management

Important

Large files such as class-admin, class-hook, class-brand-admin, along with many global helpers, have been broken down and reorganized into MediaSharing and MediaLibrary modules based on their responsibility. Media-sharing (governing-site) logic lives in MediaSharing, while Media Library specific logic lives in MediaLibrary.

There are a few cases of overlapping usage across both modules. I’ve cleaned this up as much as possible. Looking for suggestions for further improvements.

Checklist

  • I have read the Contribution Guidelines.
  • I have read the Development Guidelines.
  • My code is tested to the best of my abilities.
  • My code passes all lints (ESLint etc.).
  • My code has detailed inline documentation.
  • I have updated the project documentation as needed.

Attachment::update_is_syncing( $media['id'], 'sync' === $sync_option );

// Share the attachment metadata with the brand sites.
// Get attachment metadata.
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we're not going to validate the id or handle the false, we should at least coerce the false ?: []

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also below (~L1392)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We are ensuring the value of media['id'] above here $media['id'] = isset( $media['id'] ) ? intval( $media['id'] ) : 0;

Copy link
Collaborator

Choose a reason for hiding this comment

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

which part of that ensures that's a valid attachment ID and the db isnt locked, and whatever else that can cause wp_get_attachment_metadata() to return false? 🤨

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please pay more attention to the feedback I give you.

  1. General rule: don't call a function when you can avoid it. Like what do you even gain conceptually by calling wp_get_attachment_metadata( 0 )?
  2. What you get IRL is the bug I was telling you to fix in the first place, which is that there are multiple ways for the function to return false instead of an empty array (passing an invalid post id is just one of them: https://github.com/WordPress/wordpress-develop/blob/cd5b7b140a230713c06d97d2fd4a3dac947e0e5c/src/wp-includes/post.php#L6897), so therefore you should $attachment_data = wp_get_attachment_metadata( $media['id'] ) ?: [];

If this is still not clear, please DM.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've added ?? 0

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah thats the entire problem....

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Understood, somehow this comment is visible now. Added changes.

*
* @return array The array of sync site URLs.
*/
private static function get_sync_site_urls_postmeta( int $attachment_id ): array {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This should have been moved below. ::health_check_attachment_brand_sites

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Apologies. Remember the hierarchy, updated

@patil-vipul patil-vipul dismissed justlevine’s stale review December 23, 2025 10:31

Proceeding with merge

@patil-vipul patil-vipul merged commit 173e475 into develop Dec 23, 2025
10 checks passed
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.

4 participants