• Hi Evan, l need your assistance with rest api and PHP 8.0.

    If i set the fields l want in the rest api l get the follwoing error:

    Warning: Undefined array key "custom_key" in /usr/www/users/thefozvzmm/wp-content/plugins/wp-rest-api-controller/wp-rest-api-controller.php on line 320
    
    Warning: Undefined array key "custom_key" in /usr/www/users/thefozvzmm/wp-content/plugins/wp-rest-api-controller/wp-rest-api-controller.php on line 320
    
    Fatal error: Uncaught TypeError: Cannot access offset of type string on string in /usr/www/users/thefozvzmm/wp-content/plugins/wp-rest-api-controller/wp-rest-api-controller.php:320
    Stack trace:
    #0 /usr/www/users/thefozvzmm/wp-content/plugins/wp-rest-api-controller/wp-rest-api-controller.php(255): WP_REST_API_Controller->get_original_meta_key_name('at_biz_dir', '_price', false)
    #1 /usr/www/users/thefozvzmm/wp-includes/rest-api/endpoints/class-wp-rest-controller.php(433): WP_REST_API_Controller->custom_meta_data_callback(Array, '_price', Object(WP_REST_Request), 'at_biz_dir')
    #2 /usr/www/users/thefozvzmm/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php(1923): WP_REST_Controller->add_additional_fields_to_object(Array, Object(WP_REST_Request))
    #3 /usr/www/users/thefozvzmm/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php(377): WP_REST_Posts_Controller->prepare_item_for_response(Object(WP_Post), Object(WP_REST_Request))
    #4 /usr/www/users/thefozvzmm/wp-includes/rest-api/class-wp-rest-server.php(1143): WP_REST_Posts_Controller->get_items(Object(WP_REST_Request))
    #5 /usr/www/users/thefozvzmm/wp-includes/rest-api/class-wp-rest-server.php(990): WP_REST_Server->respond_to_request(Object(WP_REST_Request), '/wp/v2/at_biz_d...', Array, NULL)
    #6 /usr/www/users/thefozvzmm/wp-includes/rest-api/class-wp-rest-server.php(414): WP_REST_Server->dispatch(Object(WP_REST_Request))
    #7 /usr/www/users/thefozvzmm/wp-includes/rest-api.php(394): WP_REST_Server->serve_request('/wp/v2/at_biz_d...')
    #8 /usr/www/users/thefozvzmm/wp-includes/class-wp-hook.php(307): rest_api_loaded(Object(WP))
    #9 /usr/www/users/thefozvzmm/wp-includes/class-wp-hook.php(331): WP_Hook->apply_filters(NULL, Array)
    #10 /usr/www/users/thefozvzmm/wp-includes/plugin.php(524): WP_Hook->do_action(Array)
    #11 /usr/www/users/thefozvzmm/wp-includes/class-wp.php(398): do_action_ref_array('parse_request', Array)
    #12 /usr/www/users/thefozvzmm/wp-includes/class-wp.php(770): WP->parse_request('')
    #13 /usr/www/users/thefozvzmm/wp-includes/functions.php(1330): WP->main('')
    #14 /usr/www/users/thefozvzmm/wp-blog-header.php(16): wp()
    #15 /usr/www/users/thefozvzmm/index.php(17): require('/usr/www/users/...')
    #16 {main}
      thrown in /usr/www/users/thefozvzmm/wp-content/plugins/wp-rest-api-controller/wp-rest-api-controller.php on line 320

    if i just enable the plugin and all fields not selected the API works.
    I need the following fields for my app to work in php 8.0 to be able to sent notifications based on location and distance from coordinates.

    Fields needed in rest api: _manual_lat and _manual_lng if l enable them the rest api won’t work is there a way to get these values like meta_fields in PHP l can use

    • This topic was modified 2 years, 1 month ago by tigere.

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Thread Starter tigere

    (@tigere)

    Anyone with information about the issue of PHP 8.0 and getting custom fields from the Rest API wil be much appreciated l need to resolve the issue as soon as possible as the app is currently down.

    Hello tigere.

    I ran the scripts inside this plugin through rector for php8.1 at https://www.phptools.online/php-checker and it proposed this changes in wp-rest-api-controller/admin/partials/settings-functions.php :

    `— original
    +++ new
    @@ -1,3 +1,3 @@
    <?php
    if ( ! class_exists( ‘WP_REST_API_Controller_Settings’ ) ) {

    @@ -15,10 +15,8 @@

    /**
    * Post type slugs that we should not allow users to enable/disable.
    – *
    – * @var array
    – */
    – private $always_enabled_post_type_slugs;
    + */
    + private readonly array $always_enabled_post_type_slugs;

    /**
    * Class constructor.
    @@ -564,4 +562,4 @@

    }

    -new WP_REST_API_Controller_Settings();
    \ No newline at end of file
    +new WP_REST_API_Controller_Settings(); –

    Maybe this would fix the problem?
    I have not yet tried this plugin myself.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Rest API issues with PHP 8.0 and 8.1’ is closed to new replies.