A pastebin or GitHub Gist link would be handy and we could look over things. Better than pasting all here in a forum post directly. Also gets formatting.
Hi, thank you for the reply.
This is the original:
http://pastebin.com/B1vgzTxe
The metabox starts at line 201. Obviously I changed require once to the new /cmb2 and used the new init. However, I want to provide the clean original code for a fresh starting example.
Thank you!
Not quite sure why the code, as is, isn’t working out. I did go ahead and start conversion to work with CMB2 though. You can see it in the gist below. It only covers the first of the two arrays your version inserts into the $meta_boxes array, as I want you to get some hands on experience converting the other π
https://gist.github.com/tw2113/f9f5d893c6d0c6134c51d6b8fb80431c
Some notes.
1. Since you set up two different metabox sections, I named the first one "$first" in my gist. You can rename as you see fit, but you’ll want a 2nd variable name for the second metabox.
2. The “pages” argument is now “object_types”. It was a change meant to better clarify that argument, and indicate that it could be “post”, “page”, “my_slug”, and a variety of other types.
3. Everything above the nested arrays in the “fields” section should be passed into the new_cmb2_box() function, as an array, and the function’s return value assigned to a variable. With that variable, you can start calling the "add_field()" method, and pass in arrays with the value arguments for each field. Do notice that the original code has nested arrays, which isn’t needed any more.
4. The filter to run everything on is different than your original code’s. I don’t know exactly what "wpfc_meta_boxes" is or when it’s run, but I was managing to succeed with "cmb2_admin_init".
Let me know if you have any questions or want to try out an end result on my dev site and confirm saving of data etc.
Michael’s notes are solid. One thing of note though, cmb2_admin_init is an action hook, not a filter, and you’re no longer working with a passed in $meta_boxes array, but instead registering new metaboxes with the new_cmb2_box() funciton, and then registering fields to that metabox with the add_field() method. You do not need to return anything from your wpfc_sermon_metaboxes() function. Michael’s gist is a good example, but you can see more examples in the example-functions.php file.
If you’re interested, I built a Sermon Manager plugin using CMB2 that has some pretty robust functionality: https://github.com/jtsternberg/GC-Sermons
Michael, thank you! I will look what you have done as soon as I can. Thank you again for the response.
Justin, I will look at your plugin as well for the future. I donate my time (and server) to a quite a few organizations that have tons of sermons already posted.
Sermon manager was not chosen because it looked the best, but provided the best needs of the churches. I found that the bundled “Sermons” plugins with themes to be oblivious of what a sermon custom post should be like. Now that Sermon Manager is outdated, there is a huge vacuum in rather large portion of WP users.
Got it! the key was “object_types”. The problems that everyone had with the original metabox went away with cmb2.
Now I can update it and see what else this can do! π
Oh wait. One thing that does now work.
Using <iframe width=”100%” height=”120″ src=”https://www.mixcloud.com/widget/iframe/?feed=https%3A%2F%2Fwww.mixcloud.com%2Fshekinah_temple%2Flast-days%2F&hide_cover=1&light=1″ frameborder=”0″></iframe>
does not work in ‘textarea’ anymore. There is no validation error, it just will not update and the postback will show an empty textarea.
So then I tried ‘oembed’ as per the example function using [mixcloud https://www.mixcloud.com/shekinah_temple/last-days/ width=100% height=120 hide_cover=1 light=1].
This does produce a validation error saying mixcloud is not a valid embed code. It refers me to the codex which shows.. mixcloud lol.
oembed is not a shortcode. The oembed fields expect an oembeddable url only, aka: https://www.mixcloud.com/shekinah_temple/last-days/
Thanks for the tip Justin! That is a good feature. I just have to figure out why html is not longer working in textarea for all the folks that are using the <iframe>. Mixcloud and Soundcloud gives you two options on the embed. WordPress shortcodes and html embeds.
I am a .net developer used to similar syntax as php but php is a bit harder to troubleshoot has not even PHP Storm has the debugging tools that I am used to.
Stumbled upon http://hasinhayder.github.io/cmb2-metabox-generator/.
Thumbs up on that tool!
It is now textarea_code…