- 
                Notifications
    
You must be signed in to change notification settings  - Fork 3.1k
 
Notes: Add auth_callback for wp_note_status comment meta #10430
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
Conversation
| 
           The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the  Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.  | 
    
          Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
 For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.  | 
    
| 
           Do you have any ideas why unit tests didn't catch this failure? Why isn't  It would be nice to have unit test coverage for   | 
    
| 
           I was just doing more tests and realized that running only  Unfortunately, I'm not sure what is causing this different behavior. @desrosj, @TimothyBJacobs, any ideas?  | 
    
| 
           I also noticed this and was in the process of investigating the cause. As a result of this, adding new tests and testing them becomes somewhat complicated 😅  | 
    
| 
           If the problem cannot be resolved, I plan to split the test into two parts, without using a data provider.  | 
    
          
 The test is still passing for me, even after removing the data provider (at least that's the case in the Gutenberg repo). I can only fail it when running the command above.  | 
    
          
 Odd, that sounds like some other test is causing a side effect. 👀  | 
    
| 
           When I run the test in isolation, the response error is:   | 
    
          
 Yes, for some reason, the comment metadata itself is either not registered or the authentication has failed.  | 
    
| 
           The underlying cause here was the meta was no longer registered after the first test ran - the test controller probably cleans up all meta registration between test runs. Core is adding registering the meta on 'init' and that fires only once per test run. The solution was to add the meta registration to the set_up method, after this change the test fails in isolation and when run with other tests. I added the change to this PR - 27bd29d assuming you are trying to fix this issue, but feel free to remove it if it belongs elsewhere.  | 
    
          
 That's unexpected.  | 
    
          
 Looking into this further, the meta registrations are stored in the $wp_meta_keys global, so the registration must run before the test. Whats unclear to me so far is why the init hook isn't firing for every run, it could have to do with where we are calling add_action( 'init'. I'm looking further.  | 
    
          
 It happens as part of the top level tear down, see 
 Therefore, we do need to set this up for each test run, or at least for all tests relying on it being available.  | 
    
          
 This wasn't the issue, although I we should probably move that hook to   | 
    
and relocate to src/wp-includes/default-filters.php
          
 The test suite fires "rest_api_init" on every run, but not init so after the first run, the meta is destroyed and the updates do nothing - 
  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fantastic!
…es/js/wp-embed.js` exists
This reverts commit 5501151.
| 
           The failures here were actually because REST API fixture generation was failing (not sure when this started, possibly related to commit 8c2ec29). The code in embed.php uses file_get_contents() to read the wp-embed.js file, which doesn't exist in the src directory where tests are run (it's a built asset). It became apparent here because this PR results in a fixture change. Other oEmbed tests already handle this touch()ing the expected file in their set_up() method to create an empty placeholder file. The REST schema fixture generation test was missing this setup, causing it to fail. Fixed in 05e386c, I reverted my other changes. cc: @westonruter fun times  | 
    
| 
           Working in #10434 to avoid too much noise here, I see one other failing test thaat is meta related, once I have those tests green, I'll merge the changes back here  | 
    
          
 Indeed! wordpress-develop/tests/phpunit/tests/oembed/controller.php Lines 38 to 39 in 87cbbb1 
 wordpress-develop/tests/phpunit/tests/oembed/getResponseData.php Lines 11 to 12 in 87cbbb1 
 wordpress-develop/tests/phpunit/tests/oembed/wpOembed.php Lines 38 to 39 in 87cbbb1 
  | 
    
          
  | 
    
| 
           @westonruter can you please give this another review, see my last comment for an explanation of the additional changes.  | 
    
| 
           @t-hamano Apologies for taking over your ticket, I was trying to help with the failing tests and went down a bit of a rabbit hole. I am done making changes here!  | 
    
| 
           @adamsilverstein Thank you so much for the detailed investigation! 
 My only concern is that with this hook, the timing for registering the comment meta might be a little late. There might be cases where someone wants to access this comment meta before the REST API is initialized. What are your thoughts on directly executing the callback function within the  diff --git a/src/wp-includes/comment.php b/src/wp-includes/comment.php
index acc3379bbe..aa841bfda9 100644
--- a/src/wp-includes/comment.php
+++ b/src/wp-includes/comment.php
@@ -4135,4 +4135,3 @@ function wp_create_initial_comment_meta() {
                )
        );
 }
-add_action( 'rest_api_init', 'wp_create_initial_comment_meta' );
diff --git a/src/wp-includes/default-filters.php b/src/wp-includes/default-filters.php
index 5dc54c3686..f59d25b4fd 100644
--- a/src/wp-includes/default-filters.php
+++ b/src/wp-includes/default-filters.php
@@ -151,6 +151,7 @@ add_filter( 'update_term_metadata_cache', 'wp_check_term_meta_support_prefilter'
 add_action( 'added_comment_meta', 'wp_cache_set_comments_last_changed' );
 add_action( 'updated_comment_meta', 'wp_cache_set_comments_last_changed' );
 add_action( 'deleted_comment_meta', 'wp_cache_set_comments_last_changed' );
+add_action( 'init', 'wp_create_initial_comment_meta' );
 
 // Places to balance tags on input.
 foreach ( array( 'content_save_pre', 'excerpt_save_pre', 'comment_save_pre', 'pre_comment_content' ) as $filter ) {
diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php
index d1e1de9012..7a5109b25d 100644
--- a/tests/phpunit/tests/rest-api/rest-comments-controller.php
+++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php
@@ -170,6 +170,8 @@ class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase
        public function set_up() {
                parent::set_up();
                $this->endpoint = new WP_REST_Comments_Controller();
+               wp_create_initial_comment_meta();
+
                if ( is_multisite() ) {
                        update_site_option( 'site_admins', array( 'superadmin' ) );
                } | 
    
| 
           Yes that works and aligns with how meta is usually registered so maybe better.  | 
    
| 
           I pushed the following changes.  | 
    
| 
           Thanks for debugging this, folks. I think this is good to commit. Sidenote: The   | 
    
| 
           May I try to commit this pull request myself? I believe I have the SVN environment set up locally: https://wordpress.slack.com/archives/C18723MQ8/p1761227412356249 I created the following commit message, and I would appreciate it if you could review it.  | 
    
| 
           The commit message looks good to me 👍  | 
    
| 
           Thank you! I'm going to start preparing for the commit now...  | 
    
| 
           The commit appears to have completed successfully 👍  | 
    
| 
           Congrats @t-hamano!  | 
    
| 
           Nice work on your first commit to core @t-hamano! 🎉 🎉 🎉 
 Thats fine; these fix some CI errors I noticed, but they aren't blockers - I can add in a future commit.  | 
    
Trac ticket: https://core.trac.wordpress.org/ticket/64153