• Resolved David Gewirtz

    (@dgewirtz)


    Is it possible to create a field that’s nothing but static text? I’ve tried with the title type, but I was nervous about replacing ‘name’ with a big block of HTML. I tried to use after_field, but the field title kept showing up. I tried to set show_names to false, and even put in a label_cb, but no joy.

    Any suggestions?

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Probably best would be https://github.com/CMB2/CMB2/wiki/Field-Parameters#render_row_cb where you handle the entirety of the output, including html and dynamic values.

    Otherwise, I know there are tutorials out there for custom field types that you could do.

    Also won’t hurt to poke around https://github.com/CMB2/CMB2-Snippet-Library/ as it has a lot of useful scaffold code.

    Thread Starter David Gewirtz

    (@dgewirtz)

    Thanks. That worked. Now, the only problem is I’m getting a Save Changes button. I’ve tried a variety of options to make that button go away, but seem to be striking out. Any suggestions?

    –David

    BTW: I found https://github.com/CMB2/CMB2-Snippet-Library/edit/master/options-and-settings-pages/options-pages-with-tabs-and-submenus.php in the snippet library, which answered a whole bunch of other questions. Thanks for pointing me in that direction.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    How would you save the settings if you don’t have the button?

    Thread Starter David Gewirtz

    (@dgewirtz)

    I’m displaying seven tabs and on two of them, I’m just slamming some HTML. One is some welcome HTML with links and such, while the other is HTML with details on add-ons and tools for plugin users.

    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Since I don’t think CMB2 offers a way to hide the button, tabs version of an options page or no, I am curious if there’s some way you could simply use some admin-side CSS to display:none it. If the URL is different when viewing each tab, you could potentially also get an admin body class on the <body> tab so that you only hide it for one of them.

    Throwing some ideas out there for you.

    Thread Starter David Gewirtz

    (@dgewirtz)

    This worked:

    // Remove primary Save button
    // derived from https://github.com/CMB2/CMB2-Snippet-Library/blob/master/filters-and-actions/custom-css-for-specific-metabox.php
    function myprefix_delete_welcome_button($post_id, $cmb)
    {
        ?>
        <style type="text/css" media="screen">
            input#submit-cmb.button.button-primary {
                display: none;
            }
        </style>
        <?php
    }
    
    $object = 'options-page'; // could also be post | term
    $cmb_id = 'myprefix_my_metabox_id';
    add_action("cmb2_after_{$object}_form_{$cmb_id}", 'myprefix_delete_welcome_button', 10, 2);
    Plugin Contributor Michael Beckwith

    (@tw2113)

    The BenchPresser

    Word.

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘Static text field’ is closed to new replies.