Hi there,
I have been doing some experiments in Pro to see if it’s possible at all to hook in and add custom settings to the page settings pane within the Pro content builder. I want to do this so that it could be possible to manage a select few Advanced Custom Field options from within Pro, rather than having to come back out to the WordPress editor to make that kind of change.
In v3 of Pro, I was able to create some custom settings for the Page Settings dialogue box that popped up. I achieved this by extending the Cornerstone_Legacy_Setting_Section class and hooking the registration into the cornerstone_register_setting_sections action. This no longer works for me in Pro v4, and the other settings panes that are built-in to Pro (slider-above, slider below and x-settings) don’t show up in the Page Settings pane either.
After some tinkering and experimentation, I have been able to create a bunch of controls in the settings section, copying the structure of the controls I had on a custom Element. I’ve got the following sorted:
This was done by filtering in on the
cs_builder_settings_controls filter.
I even managed to make sure that the values are populated from the post on load, using the cs_content_load_settings filter and grabbing the data from the Advanced Custom Fields data that was set in the WordPress editor.
This is all great, however I have not been able to find a way to update the ACF fields again when the post is saved. I found the two filters above in the Cornerstone_Content class, so looking in there I was able to see that other settings (Title, slug, status) are being set within the class here, in the set_settings function, but there is no hook or filter available to either add my custom settings to the mix, or just hook in to the new values so that they can be transferred over to ACF (in my use case there is no real need to save the settings into the _cornerstone_settings postmeta).
I have managed to make it all work as needed for me by adding an action hook into the set_settings function at line 305 or thereabouts:
do_action('cs_content_set_settings', $this->id, $settings );
With this I was then able to hook in and grab the custom settings that are being updated and send their value over to ACF to be saved like so:
function cxx_content_set_settings( $post_id, $settings ) {
if ( isset($settings['info_content']) ) {
update_field( 'info_content', $settings['info_content'], $post_id );
}
}
add_action( 'cs_content_set_settings', 'cxx_content_set_settings', 10, 2 );
This may or may not be the best place to put that action / hook, but if it is, it would be wonderful for it (or something similar) to be integrated into Pro core so that even more great functionality can be handled and sorted out within Pro!
Also if I have missed a better way of doing this via another filter / hook that exists, I would love to know!
Cheers
