Make WordPress Core

Changes between Initial Version and Version 1 of Ticket #56944


Ignore:
Timestamp:
11/02/2022 09:24:39 AM (3 years ago)
Author:
sabernhardt
Comment:

Hi and thanks for the report!

I updated the ticket description's formatting, which includes replacing the “smart quotes” that came from the support topic.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #56944

    • Property Component changed from General to Options, Meta APIs
  • Ticket #56944 – Description

    initial v1  
    22
    33
    4 I ran into the issue when get_option does not return any value:
    5 get_option( “_wp_session_{$this->session_id}”, array() );
     4I ran into the issue when `get_option` does not return any value:
     5`get_option( "_wp_session_{$this->session_id}", array() );`
    66
    77It returns an empty value, but the value exists in DB and in cache.
    88
    9 I tested with 3 different methods one-by-one for option _wp_session_5c1f3b8058ca4b6cf9e637c31300bc23:
     9I tested with 3 different methods one-by-one for option `_wp_session_5c1f3b8058ca4b6cf9e637c31300bc23`:
    1010
    11 1) **get_option**
    12 get_option( “_wp_session_5c1f3b8058ca4b6cf9e637c31300bc23”, array() );
     11==== 1) `get_option`
     12
     13`get_option( "_wp_session_5c1f3b8058ca4b6cf9e637c31300bc23", array() );`
     14
    1315It returns an empty value (but sometimes it works fine)
    1416
    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
    1721It 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{{{
     23a: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}}}
    1925''I removed some private information here.''
    2026
    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
    2331It returns correct value
    2432
    25 `Array
     33{{{
     34Array
    2635(
    2736    [edd_cart] => [{"id":79377,"options":[],"quantity":1}]
     
    3140    [edd_errors] =>
    3241    [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}}}
    3444
    3545''I removed some private information here.''
    3646
    37 ———————–
     47----
    3848
    39 So the problem only with function get_option. I checked this function as well. It selects values for notoptions
    40 $notoptions = wp_cache_get( ‘notoptions’, ‘options’ );
     49So 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' );`
    4151
    4252And if current option exists in this array – it do return
    4353
     54{{{
    4455if ( isset( $notoptions[ $option ] ) ) {
    4556                        /**
    4657                         * Filters the default value for an option.
    4758                         *
    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.
    4960                         *
    5061                         * @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.
    5364                         *
    5465                         * @param mixed  $default The default value to return if the option does not exist
    5566                         *                        in the database.
    5667                         * @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?
    5869                         */
    5970                        return apply_filters( "default_option_{$option}", $default, $option, $passed_default );
    6071                }
     72}}}
    6173
    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.
     74Current 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.
    6375
    6476That’s all information I have so far.