Skip to content
This repository was archived by the owner on Feb 1, 2019. It is now read-only.

Unserialize custom fields#5

Merged
kurtrwall merged 2 commits intocfpb:masterfrom
kurtrwall:serialize
Jun 2, 2015
Merged

Unserialize custom fields#5
kurtrwall merged 2 commits intocfpb:masterfrom
kurtrwall:serialize

Conversation

@kurtrwall
Copy link
Copy Markdown

Currently, custom fields are being output in json literally from the Wordpress database. In Wordpress, arrays are serialized into a string and then saved in the database so your JSON output is serialized. No good. We want a nice json object. This accomplishes that in this case.

Additions

  • unserialize_custom_field() that accepts one parameter. It is used to unserialize potentially serialized given fields.

Changes

  • Custom fields are assigned by calling the added method instead of directly copying the field from the Wordpress database.

Testing

Review

Notes

@kurtrwall kurtrwall changed the title Deserialize custom fields Unserialize custom fields Apr 7, 2015
@Scotchester
Copy link
Copy Markdown

@kurtw You closed the related PR cfpb/cms-toolkit#55. Is this PR still needed?

@kurtrwall
Copy link
Copy Markdown
Author

It is not needed quite yet, BUT it is very important and exciting to have. My vision for the cms-toolkit is to change it so that it saves each field of the metabox in a serialized array. This will take that serialized array and output it nicely in JSON. The referenced and closed array did that for links but it broke sheer processors in it's implementation so I decided to make the transition in a different PR (coming soon). It should be noted that this does not break any existing functionality, it just adds support for serialized data.

@Scotchester
Copy link
Copy Markdown

Cool cool.

One question: Can we leverage this existing WP function?

https://developer.wordpress.org/reference/functions/maybe_unserialize/

@kurtrwall
Copy link
Copy Markdown
Author

Well look at you Scott. I try to make something and you just come and here a drop something even better. I should say that my function does accept arrays that have serialized data within them. I think I'll modify it to use this function. Thanks for bringing it to my attention!

@Scotchester
Copy link
Copy Markdown

Teamwork! 👯

@kurtrwall
Copy link
Copy Markdown
Author

Updated to use maybe_unserialize() and tweaked output.

@kurtrwall
Copy link
Copy Markdown
Author

Tagging to make visible to more affected parties @cfarm

@Scotchester
Copy link
Copy Markdown

👍 Ready to rock.

kurtrwall pushed a commit that referenced this pull request Jun 2, 2015
Unserialize custom fields
@kurtrwall kurtrwall merged commit ccf108a into cfpb:master Jun 2, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants