-
Notifications
You must be signed in to change notification settings - Fork 327
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Store Image as ID #1498
Comments
@JiveDig saving as a URL is the default behaviour, but not the only option. 😉 'choices' => array(
'save_as' => 'array'
), This will save the value as an array containing the url, width, height and ID of the image. |
Ooh that is interesting, and very helpful. Is there a built in way to only save as ID though?
|
I think it's half-implemented... I started working on it but never tested if it works or not (which is why it's not even documented anywhere). |
Okay, it definitely stores the image as an ID, which is great (and easy enough to do with the sanitize_callback. But it has the same issue, the image preview is not showing now. I'm guessing you upon loading of the field you need to check the |
I just pushed a commit that should fix this. |
Hmmm, doesn't seem to work. I just copied the changes to that file into my current local install. Is there an easier way to test? Is there a featured branch I can use? Pardon my git limitations here ;) |
The easiest way is to just download the develop branch from here: https://github.com/aristath/kirki/archive/develop.zip |
Yes, this is working. Awesome. I'll lookout for an update before i push my code for my plugin. Thanks. |
Not to be pushy, but i'm wondering if you have a timeline for the next release, so I can plan my dev/release schedule accordingly. |
@JiveDig I'm hoping for sometime next week, though I can't make any promises about that. |
Hey there! Not to revive and old thread, but it looks like there are still some half-baked issues with saving images as IDs and arrays. Right now, I'm trying to save an image as an array and even when I make a change in the customizer it doesn't give me option to save or publish my changes. And also it's not removing the value from the customizer when I click "remove". |
Nevermind! Ugh, silly user error on my part. Array field type is working for me, I think this issue can be closed. |
Issue description:
First off, I already read #712
I was a bit surprised when I realized Kirki stores image field values as a URL. I have an existing plugin that i'm converting to use Kirki and this is/was the only hiccup. I was easily able to store the value as an ID using the
sanitize_callback
, the only issue now is filtering that option (not theme_mods here) and converting the ID to URL when is_customize_preview(). Then my function to retrieve that field also needs to check if the value is a URL, and convert accordingly, though this only happens when using the customizer.I was hoping
apply_filters( 'kirki/values/get_value', $value, $field_id );
would be the easy solution to convert ID to URL only for the field value, but that didn't work.Is there a better way to do this considering I have a ton of active installs using ID, and I'd prefer to keep it that way?
Lastly, another option is to add a parameter to the image field to give the option to store as URL or ID.
Version used:
3.0.9 from WP repo
Using theme_mods or options?
options
The text was updated successfully, but these errors were encountered: