Support

Account

Home Forums Backend Issues (wp-admin) Button field with lots of options

Solving

Button field with lots of options

  • I use ACF to build the layout for my pages using one Flexible content field with all the elements/blocks I have on a page as Layouts defined.
    Some elements/blocks have the option to add buttons. I also want to provide the option to specify lots of attributes for the button (button style, text, link, target, shadow, effect). This can be done by adding all the options for each Layout (e.g. button style = Select, text = Textfield, Link = Page Link, target = True/false, shadow = Select, effect = Select) but I don’t want to specify all those options over and over again for every Layout I create.

    So I wanted to create an Input Field Plugin (like a Super-Button) which you can just include in the Layout and which provides all the available options.

    I was wondering if I can use the build in Field types to build this (in PHP). So instead of recreating the Page Link plugin I simply load the Field type and echo it.

    Is this a thing that can be done or does will it conflict since maybe not all the Field types are initialized yet? If it’s possible, what would be the code to load it? (already tried $buttontext = new acf_field_text(); and such)

  • This sounds like what you need is a new field type because I don’t think this is possible using any of the exiting field types

    I’ve actually done something similar for a theme where all of the attributes of a link element to turn into a button had to be set for each button.

    Anyway, you’d want look at this: http://www.advancedcustomfields.com/resources/creating-a-new-field-type/

  • Yes, I’ve already created a new field type. But I don’t want to recreate the various ‘subfields’. For example the Page Link select (not sure that’s the name exactly) works perfect with ajax and all so it would be foolish to recreate the html+js for this ‘subfield’ of my new field type.

  • Sorry, I guess I didn’t quite understand. So you want to create a new field type that makes use of an existing field type but just add additional options.

    I could be wrong, but I think that what you’re really looking to do is “extend” one of the existing fields.

    Instead of this at the top of the new field class acf_field_FIELD_NAME extends acf_field

    you could extend the page link field

    class acf_field_FIELD_NAME extends acf_field_page_link

    Then I think you would only need to write new functions to replace parts of the page link field, like

    render_field
    render_field_settings
    format_value
    update_value
  • Thanks, that helps. Only this solution is limited to one field type this way. I would base/extend my ‘super-button-field’ on let’s say: the acf_field_page_link. If I want to also story more data (style, target, button text). I would hook into the update_value and render_field to extract the required data. And modify the html for the select and inputfields.
    Not quite what I was hoping for 🙂 no offense. But already helps a lot.

    Thanks.

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘Button field with lots of options’ is closed to new replies.