alleyinteractive / alleyinteractive/wordpress-fieldmanager

DraggablePost fields save an array of strings rather than integers

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

Beschreibung

I don't know if this is intentional or not, but the behavior of the `Fieldmanager_DraggablePost` field seems inconsistent.

Here's my issue:
- I have a class which extends `Fieldmanager_DraggablePost` set up to reorder posts for a view in my theme. I store the output as an array of post IDs in an option. I expect that option to look something like

```
array (
0 => 102455,
1 => 102365,
)
```
- After reordering these fields with the UI and saving, this array looks like this:

```
array (
0 => '102365',
1 => '102455',
)
```
- I also have methods elsewhere which can add or remove post IDs from that option. They do that by checking the option value against the list of posts which should be available and adding or removing as necessary, then saving back to the option. This is more complicated when my option is a mix of strings and integers, because simple checks like `in_array()` and `array_diff()` don't work as I'd expect them to.

It's not difficult for me to just add a presave filter which casts the values in this array to int before saving. But I wonder why it's not done that way by default. Mapping to integer on presave [here](https://github.com/alleyinteractive/wordpress-fieldmanager/blob/master/php/class-fieldmanager-draggablepost.php#L64) would make the saved data much more normalized.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

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