-
Notifications
You must be signed in to change notification settings - Fork 329
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
Example of using post_meta, i.e page custom css #463
Comments
Hey again! Yes, for the time being Kirki can only use options & theme_mods 'cause that's what people use 99% of the time. |
I just read this article http://torquemag.io/using-wordpress-customizer-saving-user-specific-options/ that explains how to use different types of data types. |
I had also come across customize_update_$type and customize_preview_$type here https://make.wordpress.org/core/2014/07/08/customizer-improvements-in-4-0/ but struggled to find a working example. I'm loving how easy it was for me jump right in with kirki, Thanks again. |
Just had a look at this again and I built a custom setting as follows:
I then built my field:
I then built the the preview function for this custom setting which I've verified does indeed fire upon loading the customizer:
However I can't seem to figure out how to get the post id or post object. I think I need to modify the core Kirki class to make that object available because $_POST['customized'] is empty. Any help is greatly appreciated. |
Hey again We will provide additional data types for the customizer, but tbh at this time it's just not a priority... We have to fix bugs first before adding any new features. |
Great news and no hurry. Looking into this -> https://gist.github.com/westonruter/1feb78845c8e562dd59d but in my situation I don't need to pass the post id and data back and forth via ajax, Kirki can handle that with the code (hidden textarea) type field already. I simply need the post ID so I can grab the meta key value, populate my cm instance and let the cm object's built in update method provide the live preview to a dynamically added DOM style element in the iframe which I already do with my global custom css in wp_options perfectly. So maybe I just need to wrap my stuff in a class extending the Kirki class to pass the post id after a few checks like is_single and such? i.e. lines 52 - 56 in class-customize-queried-post-info.php |
I finally got this working with the help of @westonruter and @aristath, thank you both.
So I use the following js (just below L27 we modified in customize-controls.js) to update the code editor from that style element's contents.
Everytime the code editor is updated we are doing 2 things, 1) updating the preview's css style element contents for the live preview and 2) updating the customizer object's value with an object containing the queried post id and the contents of our code editor.
fin =) |
Sorry, should probably leave this open as I still think it would be beneficial to have this built into kirki as a config type 'option', 'theme_mods' AND 'post_meta' =) |
This will such an incredible addition to Kirki. Per-page layout options, customisations, the applications are immense and will solve many practical needs I have today. Im not an experienced developer but if you need any help, maybe testing or something, please let me know. I have deep interest in this feature. |
Just an update here, I just added the ability to use |
Cool! Post a hopefully term meta open so many options. Thanks for the update. ;)Luís Martins |
After reviewing the changes made by @pingram3541 this is going to be harder than I thought. |
I think we need to tie this in once selective refresh (https://make.wordpress.org/core/2016/02/16/selective-refresh-in-the-customizer/) is part of the core, then we will have more control by adding the specific refresh callback desired for that particular field in the field settings array. Oh and regarding the solution I posted above, the main reason I chose to do it that way was specifically because the page's unique css (stored as post_meta) is already in the preview window as a "style" element so we can use that to populate our code editor's initial value since there's no way to pass it directly with php without modifying the core wp_customize method. We essentially go the long way, pass post_id and post_meta to the customizer js object. Use js to update our Kirki fields initial value from those objects (or the DOM in my example). Use js again to update the wp_customize postData object anytime our fields change which is also what is passed when saving. Our field's sanitize_callback function is executed when saving updating post_meta from the post id and field's value. The magic is all in the above mentioned gist by @westonruter where the post_meta is passed to the customizer "newPost" object. You have all the post meta at your disposal as a js object in which specific keys can be extrapolated for use with any Kirki field type that has a sanitize_callback method. newPost.ID and newPost.meta Since choosing to pass the field's value back via its sanitize_callback function, all that is needed to accomplish the task is the post id and the value because the field itself implies what post_meta key we need to update. |
👍 for post_meta |
Yeah, I agree post_meta will be awesome. |
+1 for me. It would be awesome if we could somehow add (some) Kirki controls to the WP Customize Posts plugin. |
Yes +1 on this. |
+1 on post_meta, and another +1 on term_meta. Kirki would be killer with these features. There are enough users ok Kirki now, I wonder if a bit of crowdfunding would be worth it to "buy" more time for @aristath to keep this moving? |
How is my code half-working if post_meta isn't even yet added to WP Core? My page is ordered into "sections". I created code that uses the Kirki sortable control to reorganise certain sections of the page template. I see the customizer preview update if I move a section to the middle, but it doesn't update properly if I move a sortable section to the "top". Kirki control:
My function:
|
Hello @aristath Kirki is fantastic, almost everything is available now. Let me know. Thanks! |
No update here yet... I'm working on something similar on a custom theme but so far haven't found a way to abstract it in a way that can be reliably used by generic controls. |
Thanks for the update. For now, I have managed my work. Saved as option and option_name has post id But yeah option_type - post_meta would be really good. |
Is there an example of how to use Kirki fields to get/put post_meta? For example, my theme has custom SEO fields for each page, I'd like to add editing capabilities in the customizer. I can't seem to find in the documentation all the possibilities for the config item 'option_name'. Does it currently only support options and theme_mods? If so, seems like post_meta would a great addition. Thanks.
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
The text was updated successfully, but these errors were encountered: