Build options in the backend of WordPress

Creating options in the WordPress backend just got easier than ever! With pwp_field() you can create options for your theme or plugin quickly without worrying about retrieving the field’s value once something is saved or registering the right hooks for things to work properly. Premise WP will take care of all this for us. Lets take a look at how you can use this powerful function.

Important: In Premise WP 2.0.0 premise_field was deprecated and replaced with pwp_field.

 

Parameters

$args array|string Optional. Set of arguments to build a field. Defaults to an empty string.

$echo boolean Optional. Whether to echo or return the html for the field. Defaults to true.

 

Arguments

Arguments are used to build our field’s html. If the argument does not serve a specific purpose for our field such wrapper_class – which adds a class to our field’s wrapper, then it is added to our field as a html attribute. Below is a list of attributes that pwp_field accepts as the first parameter.

tag string – The element tag to use when building the field. i.e. input or button.

type string – Type attribute to use for the input field. Can use textarea or select as well.

name string – The name attribute.

id string – The id attribute.

value string – The value. Leave empty if you want Premise WP to get value when something is saved.

value_att string – For checkbox and radio buttons, set a value attribute. Default is ‘1’.

options array – Option to use for a select field. Format text => value

context string – The context in which the field is being used/saved. Can be post or user. When post or user is used Premise WP looks up the value saved for this field under a post or a user respectively. Otherwise it looks under the options table.

default string – Set a default to use as the value when nothing has been saved.

label string – Enter the text to use for the field’s label.

before_wrapper string – Enter text or html before the field’s wrapper.

after_wrapper string – Enter text or html after the field’s wrapper.

wrapper_class string – Add a class to the field’s wrapper.

before_field string – Enter text or html before the field.

after_field string – Enter text or html after the field.

Send us your comments..

Your email address will not be published. Required fields are marked *