Skip to content

Conversation

@mboynes
Copy link
Contributor

@mboynes mboynes commented Oct 15, 2025

Resolves #524

See this comment for a note about an alternate solution:

Thinking aloud, I wonder if a more perfect solution might be to...

  1. Replace 'author' support with 'bylines' support at some point in time, e.g. once the plugin is loaded, for any post types that have so far been registered.
  2. Hook into registered_post_type and replace 'author' support with 'bylines' support for any future-registered post types.
  3. Change Utils::get_supported_post_types() to query for post types with 'bylines' support, and do not store the value in a static variable (fwiw, static variables in functions and methods can be a real headache when writing automated tests).

This PR is a quick fix, so maybe it's worth merging now and spinning off a followup issue to implement that idea? Or maybe we should do that now. Open to feedback!

Copilot AI review requested due to automatic review settings October 15, 2025 20:14
Copy link

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 addresses race condition issues related to register_post_type() by ensuring that post type support checks occur after all post types have been registered. The changes move hook execution from init to wp_loaded and update the caching logic to properly handle the WordPress lifecycle.

  • Modified get_supported_post_types() to invalidate cache before wp_loaded action fires
  • Changed maybe_modify_post_edit_columns() hook from init to wp_loaded to ensure all post types are registered

Reviewed Changes

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

File Description
inc/class-utils.php Updated caching condition to check wp_loaded action status
inc/admin-ui.php Changed hook priority from init to wp_loaded

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

public static function get_supported_post_types(): array {
static $post_types;
if ( ! isset( $post_types ) ) {
if ( ! isset( $post_types ) || ! did_action( 'wp_loaded' ) ) {
Copy link

Copilot AI Oct 15, 2025

Choose a reason for hiding this comment

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

The condition ! did_action( 'wp_loaded' ) will cause the cache to be invalidated and regenerated on every call before wp_loaded fires, negating the purpose of the static cache during early execution. Consider using did_action( 'wp_loaded' ) && ! isset( $post_types ) instead, or only caching after wp_loaded has fired: if ( ! isset( $post_types ) || ( ! did_action( 'wp_loaded' ) && isset( $post_types ) ) ).

Suggested change
if ( ! isset( $post_types ) || ! did_action( 'wp_loaded' ) ) {
if ( did_action( 'wp_loaded' ) && ! isset( $post_types ) ) {

Copilot uses AI. Check for mistakes.
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.

Custom post types not detected as supported when registered after byline-manager plugin loads

2 participants