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
Prevent possible warning in COTMigrationUtil::get_post_or_object_meta()
#37026
Conversation
@@ -96,7 +96,7 @@ public function get_post_or_object_meta( ?WP_Post $post, ?\WC_Data $data, string | |||
} | |||
return $data->get_meta( $key, $single ); | |||
} else { | |||
return get_post_meta( $post->ID, $key, $single ); | |||
return isset( $post->ID ) ? get_post_meta( $post->ID, $key, $single ) : false; |
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.
Just noting that I've decided to use false
as "default" value when $post->ID
is not set, just to make get_post_or_object_meta ()
mimic what get_post_meta()
does: return false
for invalid $post_id
(see codex). This, however, makes probably little difference in real use.
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## trunk #37026 +/- ##
==========================================
- Coverage 46.7% 46.7% -0.0%
- Complexity 17183 17188 +5
==========================================
Files 429 429
Lines 64799 64820 +21
==========================================
+ Hits 30251 30253 +2
- Misses 34548 34567 +19
|
Test Results SummaryCommit SHA: 7c76118
To view the full API test report, click here. To view the full E2E test report, click here. To view all test reports, visit the WooCommerce Test Reports Dashboard. |
Hey @jorgeatorres , thanks for working on this! - Once this is ready to merge, could you please share a zip so we can test it on our environments? cc @jimjasson |
@jorgeatorres There were issues in the PHP 7.4 unit tests. |
Thanks @rrennick. Don't know why those failed but after re-running the job, they are now passing. |
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.
LGTM. Tested great.
@PanosSynetos I went ahead and merged this as it was a single line change. If you want to test this you can use |
Thanks, we'll test it out! (sorry I missed the ping) |
Tested, we're good 👌 and the warning is gone |
All Submissions:
Changes proposed in this Pull Request:
This PR makes sure that
$post->ID
is set before attempting to use it inside calls toCOTMigrationUtil::get_post_or_object_meta()
.This function mostly exists for HPOS/posts compat reasons and serves functions
woocommerce_wp_select()
,woocommerce_wp_text_input()
,woocommerce_wp_hidden_input()
, etc. inwc-meta-box-functions.php
.Closes #35543.
How to test the changes in this Pull Request:
Per #35543, you should "write a snippet to call
woocommerce_wp_select
in a WooCommerce > Settings hook […]".The issue can also be replicated by just calling those functions in almost any context where the
$post
global is not set, but to replicate the exact conditions of #35543, the following can be used:functions.php
)trunk
, you should see a warning in the log such asPHP Notice: Trying to get property 'ID' of non-object in […]
.