{"id":16810418,"date":"2023-06-11T19:40:27","date_gmt":"2023-06-11T19:40:27","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/rest-error-since-version-2-021\/"},"modified":"2023-06-11T19:41:56","modified_gmt":"2023-06-11T19:41:56","slug":"rest-error-since-version-2-021","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/rest-error-since-version-2-021\/","title":{"rendered":"REST error since version 2.021"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Since the 2.0.21 release the REST API call, fetching all terms for an attribute fails with the following error. This only happens for the first time I do this call, later call seem to work correctly.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>PHP Fatal error:  Uncaught Error: Call to undefined method Woo_Variation_Swatches_Backend::get_group() in \/wp-content\/plugins\/woo-variation-swatches\/includes\/class-woo-variation-swatches-wc-api-response.php:50\nStack trace:\n#0 \/wp-includes\/rest-api\/endpoints\/class-wp-rest-controller.php(439): Woo_Variation_Swatches_WC_API_Response-&gt;get_additional_response()\n#1 \/wp-content\/plugins\/woocommerce\/includes\/rest-api\/Controllers\/Version1\/class-wc-rest-product-attribute-terms-v1-controller.php(150): WP_REST_Cont\nroller-&gt;add_additional_fields_to_object()\n#2 \/wp-content\/plugins\/woocommerce\/includes\/rest-api\/Controllers\/Version3\/class-wc-rest-terms-controller.php(349): WC_REST_Product_Attribute_Terms_V\n1_Controller-&gt;prepare_item_for_response()\n#3 \/wp-includes\/rest-api\/class-wp-rest-server.php(118 in \/wp-content\/plugins\/woo-variation-swatche\ns\/includes\/class-woo-variation-swatches-wc-api-response.php on line 50<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The addition rest api response calls a method that hasn&#8217;t been defined.<br \/>When I disable this block the code works as expected.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Workaround for now is to remove the extra rest-api (get_callback) call in <code>\/wp-content\/plugins\/woo-variation-swatches\/includes\/class-woo-variation-swatches-wc-api-response.php:30<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public function register_woo_variation_swatches_field() {\n  register_rest_field('product_attribute_term', 'woo_variation_swatches', array(\n    \/\/ 'get_callback'    =&gt; array( $this, 'get_additional_response' ),  \/\/ &lt;&lt; FIX\n    'update_callback' =&gt; array( $this, 'update_additional_response' ), \n    'schema'          =&gt; array( $this, 'additional_response_schema' ),\n  ));\n}\n<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">It looks like the class hasn&#8217;t been loaded yet in this situation?<\/p>\n","protected":false},"template":"","class_list":["post-16810418","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/16810418","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":1,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/16810418\/revisions"}],"predecessor-version":[{"id":16810419,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/16810418\/revisions\/16810419"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=16810418"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}