alleyinteractive / alleyinteractive/wordpress-fieldmanager

Bug on cron save when using $only_save_to_taxonomy and hooking onto "init"

未關閉
#363 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
bug
主要語言
PHP
星號
563
分支
99
PR 合併指標
30 天內沒有已合併 PR

描述

On an options field using a `Datasource_Term` with `$only_save_to_taxonomy = true`, cron tasks (e.g. publishing a scheduled post) will overwrite the term relationships with empty values. If the field is defined on a context-specific action (e.g. `fm_post_post`), this won't occur because the field won't be defined; therefore, this would only happen if the field were defined on `'init'` or some other global action.

The main issue here is that on cron, [the values are loaded from post meta](https://github.com/alleyinteractive/wordpress-fieldmanager/blob/master/php/context/class-fieldmanager-context-post.php#L220-L221), which is limited because there are other modes of storage, e.g. terms and post_parent. The other factor at play is that `$only_save_to_taxonomy` ignores `$skip_save` (see #362), because the context _does_ set `$skip_save = true`.

The following code will help replicate this issue:

``` php
function my_fm_terms() {
$fm = new Fieldmanager_Group( array(
'name' => 'terms',
'children' => array(
'categories' => new Fieldmanager_Select( array(
'label' => __( 'Categories', 'fm-test' ),
'remove_default_meta_boxes' => true,
'datasource' => new Fieldmanager_Datasource_Term( array(
'taxonomy' => 'category',
'only_save_to_taxonomy' => true,
) ),
) ),
'tags' => new Fieldmanager_Select( array(
'label' => __( 'Tags', 'fm-test' ),
'remove_default_meta_boxes' => true,
'datasource' => new Fieldmanager_Datasource_Term( array(
'taxonomy' => 'post_tag',
'only_save_to_taxonomy' => true,
) ),
) ),
),
) );
$fm->add_meta_box( __( 'Terms', 'fm-test' ), array( 'post' ) );
}
add_action( 'init', 'my_fm_terms' );
```

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。