alleyinteractive / alleyinteractive/wordpress-fieldmanager

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

Offen
#363 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
bug
Vorherrschende Sprache
PHP
Sterne
563
Forks
99
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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' );
```

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.