Navigation
This is archived content. Visit our new forum.

Tagged: 

  • Author
    Posts
  • #1207879

    arthurodb
    Participant

    Hi,

    I’m looking for a way to add a new Settings Section in the Cornerstone UI as a lot of the pages on my site use cornerstone and currently to set these custom settings (setting up a post relationship using Advanced Custom Fields) I have to go to the default WordPress Edit Post/Page screen to see the metabox

    I can see in the source code how the current Settings Sections are being added through classes like CS_Settings_X_Settings and I’m just wondering what you would recommend as the best practice to extend the Cornerstone Settings Sections to add my own custom section?

    Thanks in advance for any suggestions or tips!

    #1208194

    Nico
    Moderator

    Hi There,

    Thanks for writing in! Regretfully, this particular customization request is outside the scope of our support as this is not related to an issue with the theme and instead has to do with your customization of it. As such, you will need to investigate this particular issue on your own or seek help from a developer should you not feel comfortable making these changes yourself. If you have any further questions about the theme, we are more than happy to provide you with assistance on these inquiries.

    Thank you for your understanding.

    #1208317

    arthurodb
    Participant

    I understand that, no problem. Will there be addition of hooks / easier ways of adding Settings Sections to Cornerstone in the future?

    #1208562

    Rue Nel
    Moderator

    Hello There,

    I would recommend that you create your own custom section element. To know how you can do that, please check out the documentation: https://community.theme.co/kb/cornerstone-custom-elements/

    As this is all custom development, regretfully we won’t be able to assist further. Custom development is outside the scope of our support. We’re happy to provide advice and get you started in the right direction, but you would still be responsible for the implementation.

    Thank you for your understanding.

    #1208709

    arthurodb
    Participant

    Hi Rue,

    Thanks for the pointer, but unfortunately that doesn’t really solve my problem for me! 🙂

    The Settings I’m looking to add are much more like the X-Settings, being applied to every page/post as metadata (essentially I’d love to be able to make an Advanced Custom Fields field group show up in Cornerstone rather than just in the conventional WordPress edit-page environment)

    But I understand it goes beyond the scope of support, thank you anyway

    #1208716

    Christopher
    Moderator

    Thanks for your understanding.

    #1356814

    arthurodb
    Participant

    I have been working on this problem more recently and have found a solution. I’ll try to detail it here for others that may be searching for a similar problem.

    I have managed to add a Custom Settings section with a couple of custom controls in the settings part of the Cornerstone Editor. I am doing it through a child theme as I have lots of other customisation, but it would in theory work in a plugin as well.

    Initially, I copied the ‘General’ settings section folder:
    wp-content\plugins\cornerstone\includes\settings\general
    into my child-theme folder and renamed the folder to the name of my custom settings (‘custom’)

    I then used a similar setup to the custom element registration outlined in the Knowledge Base: https://community.theme.co/kb/cornerstone-plugin-integration/

    The definition.php file for these custom settings has to be altered to reflect the new name and class.

    class CS_Settings_Custom {
    
        public $priority = 10;
        public $manager;
    
        public function ui() {
            return array( 'title' => __( 'Custom Settings', 'cornerstone' ) );
        }
        . . .

    Once the class name has been updated, you can add an action to the ‘cornerstone_register_setting_sections’ hook.

    // Define the path where we can find our options folders
    define( 'CXX_CS_OPTIONS_PATH', dirname( __FILE__ ) . '/options' );
    
    // Ensure the registration happens at the right point in initialisation
    add_action( 'cornerstone_register_setting_sections', 'cxx_register_options' );
    
    function cxx_register_options() {
        // Register Custom Settings section
        cornerstone_register_setting_section( 'Custom', 'custom', CXX_CS_OPTIONS_PATH . '/custom' );
    }
    
    function cornerstone_register_setting_section( $class_name, $name = '', $path = '' ) {
        // Find and include the definition for the new settings section
        $filename = "$path/definition.php";
        if (  !file_exists( $filename ) )
            continue;
    
        require_once( $filename );
    
        // Set the $class_prefix to be similar to existing settings sections
        $class_prefix = 'CS_Settings_';
        $class_name = $class_prefix . $class_name;
    
        // Use the add() method of the Settings_Manager to add our new settings section
        // Full declaration here:
        // wp-content\plugins\cornerstone\includes\classes\builder\class-settings-manager.php @ 140
        CS()->loadComponent( 'Settings_Manager' )->add( $class_name, $name, $path );
    }

    Once all this is done, you should see the new ‘Custom Settings’ section in the settings.
    From here, you’ll need to update controls.php, defaults.php, and definition.php to reflect the changes in controls and functionality of the specific settings you’ll be adding.

    Hope that helps anyone who was searching or struggling!

    #1357306

    Rad
    Moderator

    Thanks for sharing!