{"id":623,"date":"2018-06-21T11:06:18","date_gmt":"2018-06-21T16:06:18","guid":{"rendered":"https:\/\/easydigitaldownloads.com\/development\/?p=623"},"modified":"2021-12-15T15:30:55","modified_gmt":"2021-12-15T21:30:55","slug":"breaking-changes-to-orders-in-easy-digital-downloads-3-0","status":"publish","type":"post","link":"https:\/\/easydigitaldownloads.com\/development\/2018\/06\/21\/breaking-changes-to-orders-in-easy-digital-downloads-3-0\/","title":{"rendered":"Breaking changes to orders in Easy Digital Downloads 3.0"},"content":{"rendered":"<p>Since our <a href=\"https:\/\/easydigitaldownloads.com\/development\/2018\/04\/13\/easy-digital-downloads-3-0-development-update\/\">last development update<\/a> for Easy Digital Downloads 3.0, we have continued working away on this <em>huge<\/em> release.<\/p>\n<p><strong>Disclaimer:<\/strong> before we proceed, it\u2019s important to note that this version of Easy Digital Downloads will bring significant changes and it is highly advised that all developers read through these changes thoroughly. We\u2019ve made every effort to ensure backwards compatibility throughout the entire codebase, but any change has the potential to break some custom code, and we want to make everything go as smoothly as we can for everyone.<\/p>\n<p>We have now completed our migration from payments to orders. Upgrade routines have been written that migrate payments from <code>wp_posts<\/code>\u00a0and <code>wp_postmeta<\/code> across to our new custom database tables. The new schema allows for the complete overhaul we are bringing to reporting and boasts huge performance improvements.<\/p>\n<p>Here at Sandhills Development, we pride ourselves in creating solutions that are backwards compatible.\u00a0 However, with this migration there are some changes that will break custom implementations.<\/p>\n<p>As part of the migration of payments, we&#8217;ve moved away from using <code>-1<\/code>\u00a0as user IDs.\u00a0 Up until now, customers that do not have a user ID would get a user ID of <code>-1<\/code>\u00a0stored in the <code>_edd_payment_meta<\/code>\u00a0meta key.\u00a0 Going forwards, any customer that does not have a corresponding WordPress user ID will have the ID stored as <code>0<\/code>.\u00a0 The migration routine also converts all user IDs that were <code>-1<\/code>\u00a0to <code>0<\/code>.\u00a0 This will, unfortunately, break custom code that retrieves the meta value and checks specifically for <code>-1<\/code>\u00a0as it will no longer evaluate to <code>true<\/code>.<\/p>\n<p>Another breaking change that arises is when using <code>get_post()<\/code>\u00a0and <code>get_post_status()<\/code>.\u00a0 Both of these are WordPress Core methods and these will continue to work with all existing data that is migrated as our new backwards compatibility layer checks if the ID referred to a post of the <code>edd_payment<\/code> post type at which point our new database layer takes over.\u00a0 However, this will not work for new orders that do not have a corresponding legacy ID stored.\u00a0 In all cases, <code>get_post()<\/code>\u00a0should not be used to fetch Easy Digital Downloads data, be it downloads or payments.\u00a0 We have helper methods that handle the retrieval of this data from the database: <code>edd_get_download()<\/code>\u00a0and <code>edd_get_payment()<\/code>, respectively.<\/p>\n<p>Unfortunately, our receipt template also makes use of <code>get_post()<\/code>\u00a0.\u00a0 Of course, it will be updated to use our new query methods but it means that any developers that have extended the template will also have to adjust the <a href=\"https:\/\/github.com\/easydigitaldownloads\/easy-digital-downloads\/blob\/master\/templates\/shortcode-receipt.php\"><code>shortcode-receipt.php<\/code><\/a>\u00a0template to change the <code>get_post()<\/code>\u00a0call to <code>edd_get_payment()<\/code>.\u00a0 We are adding some code to automatically update the file to use the new method, however, if this is unsuccessful (perhaps due to file permissions), a notice will be displayed with a guide as to how to go about updating the file.<\/p>\n<p>To update compatibility, in <code>shortcode-receipt.php<\/code>\u00a0change <code>$payment = get_post( $edd_receipt_args['id'] );<\/code> to <code>$payment = edd_get_payment( $edd_receipt_args['id'] );<\/code>.<\/p>\n<p>Please note if you are using the <code>get_post<\/code> functions to retrieve downloads or payments, it is wise to update your code to use the aforementioned wrapper functions provided by EDD to be future-friendly.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since our last development update for Easy Digital Downloads 3.0, we have continued working away on this huge release. Disclaimer: before we proceed, it\u2019s important to note that this version of Easy Digital Downloads will&#8230;<\/p>\n<p class=\"continue-reading\"><a class=\"more-link\" href=\"https:\/\/easydigitaldownloads.com\/development\/2018\/06\/21\/breaking-changes-to-orders-in-easy-digital-downloads-3-0\/\">Continue reading &rarr;<\/a><\/p>\n","protected":false},"author":650,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[4],"tags":[17],"class_list":["post-623","post","type-post","status-publish","format-standard","hentry","category-core","tag-3dd"],"_links":{"self":[{"href":"https:\/\/easydigitaldownloads.com\/development\/wp-json\/wp\/v2\/posts\/623","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/easydigitaldownloads.com\/development\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/easydigitaldownloads.com\/development\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/easydigitaldownloads.com\/development\/wp-json\/wp\/v2\/users\/650"}],"replies":[{"embeddable":true,"href":"https:\/\/easydigitaldownloads.com\/development\/wp-json\/wp\/v2\/comments?post=623"}],"version-history":[{"count":10,"href":"https:\/\/easydigitaldownloads.com\/development\/wp-json\/wp\/v2\/posts\/623\/revisions"}],"predecessor-version":[{"id":634,"href":"https:\/\/easydigitaldownloads.com\/development\/wp-json\/wp\/v2\/posts\/623\/revisions\/634"}],"wp:attachment":[{"href":"https:\/\/easydigitaldownloads.com\/development\/wp-json\/wp\/v2\/media?parent=623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/easydigitaldownloads.com\/development\/wp-json\/wp\/v2\/categories?post=623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/easydigitaldownloads.com\/development\/wp-json\/wp\/v2\/tags?post=623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}