{"action":"closed","issue":{"url":"https://api.github.com/repos/CMB2/CMB2/issues/1174","repository_url":"https://api.github.com/repos/CMB2/CMB2","labels_url":"https://api.github.com/repos/CMB2/CMB2/issues/1174/labels{/name}","comments_url":"https://api.github.com/repos/CMB2/CMB2/issues/1174/comments","events_url":"https://api.github.com/repos/CMB2/CMB2/issues/1174/events","html_url":"https://github.com/CMB2/CMB2/issues/1174","id":367754055,"node_id":"MDU6SXNzdWUzNjc3NTQwNTU=","number":1174,"title":"CMB2/Polylang/Gutenberg meta field overrides ","user":{"login":"rasmustaarnby","id":477220,"node_id":"MDQ6VXNlcjQ3NzIyMA==","avatar_url":"https://avatars3.githubusercontent.com/u/477220?v=4","gravatar_id":"","url":"https://api.github.com/users/rasmustaarnby","html_url":"https://github.com/rasmustaarnby","followers_url":"https://api.github.com/users/rasmustaarnby/followers","following_url":"https://api.github.com/users/rasmustaarnby/following{/other_user}","gists_url":"https://api.github.com/users/rasmustaarnby/gists{/gist_id}","starred_url":"https://api.github.com/users/rasmustaarnby/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/rasmustaarnby/subscriptions","organizations_url":"https://api.github.com/users/rasmustaarnby/orgs","repos_url":"https://api.github.com/users/rasmustaarnby/repos","events_url":"https://api.github.com/users/rasmustaarnby/events{/privacy}","received_events_url":"https://api.github.com/users/rasmustaarnby/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2018-10-08T11:52:00Z","updated_at":"2018-10-08T12:16:38Z","closed_at":"2018-10-08T12:16:38Z","author_association":"NONE","body":"CMB2 version: trunk on commit 7b9850a\r\nWP: 4.9.8\r\nGutenberg: 3.9.8 \r\nPolylang: 2.3.11\r\n\r\nWe're experiencing some issues with meta fields being overriden upon save. \r\n\r\nIt seems that this issue is related to the combination of Gutenberg, Polylang and CMB2 registred meta fields. I understand that Gutenberg still must be considered new and Polylang doesn't yet support it officially, nevertheless I'm posting this hoping that someone else has experienced the same issue. \r\n\r\nI suspect this is an issue with the way CMB2 hooks in and saves meta fields, which might be triggered twice or more for each Polylang connected post, overriding the same meta value on different post id's.\r\n\r\nSo, we got a simple site setup using the plugins mentioned above. Two languages are defined, danish and english. \r\n\r\n### Expected Behavior:\r\n- On the danish page we update the field `test_title` (see code below) with \"New Title\"\r\n- The (Polylang connected) english page should still be an empty value, even with no key `test_title` in the postmeta table\r\n\r\n### Actual Behavior:\r\n- On the danish page we update the field `test_title` (see code below) with \"New Title\"\r\n- The (Polylang connected) english page now has the key `test_title` in the postmeta table with the value \"New Title\"\r\n- On each save on either language version, the connected post is updated. \r\n\r\n### Tests\r\nWe have tested using a \"normal\" registred meta box, where the issue is not present. Here the values are respected. \r\n\r\n\r\nMore or less copied directly from the codex: \r\n\r\n```php\r\nfunction wporg_add_custom_box()\r\n{\r\n    $screens = ['post', 'page'];\r\n    foreach ($screens as $screen) {\r\n        add_meta_box(\r\n            'wporg_box_id',           // Unique ID\r\n            'Custom Meta Box Title',  // Box title\r\n            __NAMESPACE__ . '\\wporg_custom_box_html',  // Content callback, must be of type callable\r\n            $screen                   // Post type\r\n        );\r\n    }\r\n}\r\nadd_action('add_meta_boxes', __NAMESPACE__ . '\\wporg_add_custom_box');\r\n\r\nfunction wporg_custom_box_html($post)\r\n{\r\n    ?>\r\n    <label for=\"wporg_field\">Description for this field</label>\r\n    <select name=\"wporg_field\" id=\"wporg_field\" class=\"postbox\">\r\n        <option value=\"\">Select something...</option>\r\n        <option value=\"something\">Something</option>\r\n        <option value=\"else\">Else</option>\r\n    </select>\r\n    <?php\r\n}\r\n\r\nfunction wporg_save_postdata($post_id)\r\n{\r\n    if (array_key_exists('wporg_field', $_POST)) {\r\n        update_post_meta(\r\n            $post_id,\r\n            '_wporg_meta_key',\r\n            $_POST['wporg_field']\r\n        );\r\n    }\r\n}\r\nadd_action('save_post', __NAMESPACE__ . '\\wporg_save_postdata');\r\n```\r\n\r\n### CMB2 Field Registration Code:\r\n\r\n```php\r\nadd_action( 'cmb2_init', function() {\r\n\t$meta_box = new_cmb2_box(\r\n\t\t[\r\n\t\t\t'id'           => 'test_box',\r\n\t\t\t'title'        => __( 'Test Box Title', THEMEDOMAIN ),\r\n\t\t\t'object_types' => [ 'page' ],\r\n\t\t\t'context'      => 'normal',\r\n\t\t\t'priority'     => 'high',\r\n\t\t]\r\n\t);\r\n\t$meta_box->add_field(\r\n\t\t[\r\n\t\t\t'id'          => 'test_title',\r\n\t\t\t'name'        => __( 'Test Title', THEMEDOMAIN ),\r\n\t\t\t'type'        => 'textarea_small',\r\n\t\t\t'default'     => '',\r\n\t\t]\r\n\t);\r\n} );\r\n}\r\n```\r\n"}}
{"actor":{"display_login":"rasmustaarnby"}}