Changes between Initial Version and Version 1 of Ticket #56944
- Timestamp:
- 11/02/2022 09:24:39 AM (3 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #56944
-
Property
Component
changed from
GeneraltoOptions, Meta APIs
-
Property
Component
changed from
-
Ticket #56944 – Description
initial v1 2 2 3 3 4 I ran into the issue when get_optiondoes not return any value:5 get_option( “_wp_session_{$this->session_id}”, array() ); 4 I ran into the issue when `get_option` does not return any value: 5 `get_option( "_wp_session_{$this->session_id}", array() );` 6 6 7 7 It returns an empty value, but the value exists in DB and in cache. 8 8 9 I tested with 3 different methods one-by-one for option _wp_session_5c1f3b8058ca4b6cf9e637c31300bc23:9 I tested with 3 different methods one-by-one for option `_wp_session_5c1f3b8058ca4b6cf9e637c31300bc23`: 10 10 11 1) **get_option** 12 get_option( “_wp_session_5c1f3b8058ca4b6cf9e637c31300bc23”, array() ); 11 ==== 1) `get_option` 12 13 `get_option( "_wp_session_5c1f3b8058ca4b6cf9e637c31300bc23", array() );` 14 13 15 It returns an empty value (but sometimes it works fine) 14 16 15 2) **wp_cache_get** 16 wp_cache_get( “_wp_session_f5f8546504975ed39fb121b6b1b7c829”, ‘options’ ); 17 ==== 2) `wp_cache_get` 18 19 `wp_cache_get( "_wp_session_f5f8546504975ed39fb121b6b1b7c829", 'options' );` 20 17 21 It returns correct value 18 `a:6:{s:8:"edd_cart";s:40:"[{"id":79377,"options":[],"quantity":1}]";s:13:"edd_cart_fees";s:0:"";s:18:"edd_resume_payment";s:0:"";s:14:"cart_discounts";s:0:"";s:10:"edd_errors";s:0:"";s:12:"edd_purchase";s:1072:"{"downloads":[{"id":147706,"options":[],"quantity":1}],"fees":[],"subtotal":0,"discount":0,"tax":"0.00","tax_rate":0,"price":0,"purchase_key":"f7f8403a9d9edb93f9be9376d117c1f0","user_email":"","date":"2022-10-31 13:59:43","user_info":{"id":37847,"email":"","first_name":"","last_name":"","discount":"none","address":[]},"post_data":{"edd_email":"","edd_first":"","edd_last":"","edd_agree_to_terms":"1","edd-user-id":"","edd_action":"purchase","edd-gateway":"manual","edd-process-checkout-nonce":"911cf02037"},"cart_details":[{"name":"","id":,"item_number":{"id":147706,"options":[],"quantity":1},"item_price":0,"quantity":1,"discount":0,"subtotal":0,"tax":0,"fees":[],"price":0}],"gateway":"manual","card_info":{"card_name":"","card_cvc":"","card_exp_month":"","card_exp_year":"","card_address":"","card_address_2":"","card_city":"","card_state":"","card_country":"","card_zip":""}}";}` 22 {{{ 23 a:6:{s:8:"edd_cart";s:40:"[{"id":79377,"options":[],"quantity":1}]";s:13:"edd_cart_fees";s:0:"";s:18:"edd_resume_payment";s:0:"";s:14:"cart_discounts";s:0:"";s:10:"edd_errors";s:0:"";s:12:"edd_purchase";s:1072:"{"downloads":[{"id":147706,"options":[],"quantity":1}],"fees":[],"subtotal":0,"discount":0,"tax":"0.00","tax_rate":0,"price":0,"purchase_key":"f7f8403a9d9edb93f9be9376d117c1f0","user_email":"","date":"2022-10-31 13:59:43","user_info":{"id":37847,"email":"","first_name":"","last_name":"","discount":"none","address":[]},"post_data":{"edd_email":"","edd_first":"","edd_last":"","edd_agree_to_terms":"1","edd-user-id":"","edd_action":"purchase","edd-gateway":"manual","edd-process-checkout-nonce":"911cf02037"},"cart_details":[{"name":"","id":,"item_number":{"id":147706,"options":[],"quantity":1},"item_price":0,"quantity":1,"discount":0,"subtotal":0,"tax":0,"fees":[],"price":0}],"gateway":"manual","card_info":{"card_name":"","card_cvc":"","card_exp_month":"","card_exp_year":"","card_address":"","card_address_2":"","card_city":"","card_state":"","card_country":"","card_zip":""}}";} 24 }}} 19 25 ''I removed some private information here.'' 20 26 21 3) **direct DB request** 22 $wpdb->get_results(‘SELECT * FROM wp_options WHERE option_name = “_wp_session_f5f8546504975ed39fb121b6b1b7c829″‘) 27 ==== 3) direct DB request 28 29 `$wpdb->get_results('SELECT * FROM wp_options WHERE option_name = "_wp_session_f5f8546504975ed39fb121b6b1b7c829"')` 30 23 31 It returns correct value 24 32 25 `Array 33 {{{ 34 Array 26 35 ( 27 36 [edd_cart] => [{"id":79377,"options":[],"quantity":1}] … … 31 40 [edd_errors] => 32 41 [edd_purchase] => {"downloads":[{"id":147706,"options":[],"quantity":1}],"fees":[],"subtotal":0,"discount":0,"tax":"0.00","tax_rate":0,"price":0,"purchase_key":"f7f8403a9d9edb93f9be9376d117c1f0","user_email":"","date":"2022-10-31 13:59:43","user_info":{"id":37847,"email":"","first_name":"","last_name":"","discount":"none","address":[]},"post_data":{"edd_email":"","edd_first":"","edd_last":"","edd_agree_to_terms":"1","edd-user-id":"37847","edd_action":"purchase","edd-gateway":"manual","edd-process-checkout-nonce":"911cf02037"},"cart_details":[{"name":"","id":147706,"item_number":{"id":147706,"options":[],"quantity":1},"item_price":0,"quantity":1,"discount":0,"subtotal":0,"tax":0,"fees":[],"price":0}],"gateway":"manual","card_info":{"card_name":"","card_cvc":"","card_exp_month":"","card_exp_year":"","card_address":"","card_address_2":"","card_city":"","card_state":"","card_country":"","card_zip":""}} 33 )` 42 ) 43 }}} 34 44 35 45 ''I removed some private information here.'' 36 46 37 ———————– 47 ---- 38 48 39 So the problem only with function get_option. I checked this function as well. It selects values for notoptions40 $notoptions = wp_cache_get( ‘notoptions’, ‘options’ ); 49 So the problem only with function `get_option`. I checked this function as well. It selects values for `notoptions`: 50 `$notoptions = wp_cache_get( 'notoptions', 'options' );` 41 51 42 52 And if current option exists in this array – it do return 43 53 54 {{{ 44 55 if ( isset( $notoptions[ $option ] ) ) { 45 56 /** 46 57 * Filters the default value for an option. 47 58 * 48 * The dynamic portion of the hook name, <code>$option</code>, refers to the option name.59 * The dynamic portion of the hook name, `$option`, refers to the option name. 49 60 * 50 61 * @since 3.4.0 51 * @since 4.4.0 The <code>$option</code>parameter was added.52 * @since 4.7.0 The <code>$passed_default</code> parameter was added to distinguish between a <code>false</code>value and the default parameter value.62 * @since 4.4.0 The `$option` parameter was added. 63 * @since 4.7.0 The `$passed_default` parameter was added to distinguish between a `false` value and the default parameter value. 53 64 * 54 65 * @param mixed $default The default value to return if the option does not exist 55 66 * in the database. 56 67 * @param string $option Option name. 57 * @param bool $passed_default Was <code>get_option()</code>passed a default value?68 * @param bool $passed_default Was `get_option()` passed a default value? 58 69 */ 59 70 return apply_filters( "default_option_{$option}", $default, $option, $passed_default ); 60 71 } 72 }}} 61 73 62 Current option exists in this array, so it applies filter “default_option_{$option}”, function filter_default_option. But this function check `get_registered_settings`, and there is no information about this option, so it returns empty result.74 Current option exists in this array, so it applies filter "default_option_{$option}", function filter_default_option. But this function check `get_registered_settings`, and there is no information about this option, so it returns empty result. 63 75 64 76 That’s all information I have so far.