Skip to content
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

Consider multisite for posts abstraction. #1004

Closed
wants to merge 4 commits into from

Conversation

peterwilsoncc
Copy link
Collaborator

@peterwilsoncc peterwilsoncc commented Jan 13, 2023

Description of the Change

Accounts for multisite in the post abstraction helper methods.

Ensures the site switched correctly when using accessing post data. This prevents incorrect data during post ID collisions, or missing data if the post does not exist on the switched site.

Uses a lot of statics to avoid needless switching. This might not be worth it.

Closes #1007

How to test the Change

Changelog Entry

Credits

Props @peterwilsoncc

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

}
}

return $thumbnail[ $hash ];
return get_the_post_thumbnail( $this->post, $size, $attr );
Copy link
Collaborator

Choose a reason for hiding this comment

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

Need to remove this return statement


$this->site_id = get_current_blog_id();

// Pre-populate the post data to account for switching sites.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you expound on what the problem is? I guess I'm not quite understanding why all the data below needs to be set when we are on a multisite. I'm assuming it has something to do with ensuring we have the right information from the right site but I guess not completely following without being able to see in what situations this comes into play

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ensuring we have the right information from the right site

This is the goal.

We we distribute network sites, we run switch_to_blog() fairly early on (I'll probably try to delay it) and calling the helper methods was returning either false or the wrong post's information if there was a post ID collision.

In the DistributorPost::post_data() method, we currently call get_the_title() and the ::get_media(), ::get_terms() and ::get_meta() methods.

I'm wanting to make sure they always return data related to the post and site we set up the object with.

I guess I need to improve the comment.

@@ -314,7 +335,12 @@ public function get_the_id() {
* @return string Post permalink.
*/
public function get_permalink() {
return get_permalink( $this->post );
static $permalink = null;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not opposed to using statics here but does this actually help in practice? Are we calling these methods multiple times in the same execution?

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 may... some of the canonical filters call get_permalink.

I'm not sure what's better or worse: making sure the site matches and switching if needs be or using statics. The former is slow but the latter may hit order of operations issues if other plugins add or remove filters.

@jeffpaul jeffpaul added this to the 2.0.0 milestone Jan 24, 2023
@peterwilsoncc
Copy link
Collaborator Author

Closing this off as an interesting experiment.

Replaced with #1010

@peterwilsoncc peterwilsoncc deleted the try/consider-multisite-switching branch January 30, 2023 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Consider multisite for post abstraction.
3 participants