-
Notifications
You must be signed in to change notification settings - Fork 8
Widget
Widgets in WordPress allow you to populate sidebars in order to display similarly structured data in multiple places on your website.
The Widget location of Ultimate Fields associates a container with one or more widgets.
This location only works with existing widgets. If you are looking to create a new widget, please follow the simple steps from the Creating a custom widget tutorial.
To add fields to users with the the Administration Interface, please follow these steps:
- If you are not on the "Add Container" screen already, locate the "Ultimate Fields" section in the administration area and click the "Add New" button on the top (next to the "Containers" title).
- Locate the "Locations" box.
- Click "Widget" from the bottom row.
- Select if you want to add fields to every widget or only a specific one.
The user location in Ultimate Fields is handled by the Ultimate_Fields\Location\Widget
class. In order to use it, you can either create the new location object manually or let the container do it for you.
The constructor of the class looks like this:
public function __construct( $widgets = array(), $args = array() ) {
-
$widgets
should either be the PHP class of a single widget or an array of widgets. -
$args
is an array, which allows you to set arguments without having to explicitly call the particular setter.
Create a new location by using the new
keyword and assign it to the container through the add_location()
method.
use Ultimate_Fields\Container;
use Ultimate_Fields\Location\Widget;
$container = Container::create( 'wysiwyg_widget' );
// Create a new location and add definitions to it
$location = new Widget( 'WP_Widget_Text' );
// Once the location has been fully set up, add it to the container
$container->add_location( $location );
Do not forget to use the correct namespace for the location class!
You can also let the container create the location for you by providing the "widget" string as the first parameter to add_location()
.
use Ultimate_Fields\Container;
Container::create( 'wysiwyg_widget' )
->add_location( 'widget', 'WP_Widget_Text' );
This method allows you to use method chaining and shortens the syntax, in order to make the code more readable.
To retrieve the values of fields, associated with the Widget location, $type
parameter of all *_value
functions should be "widget"
. This will automatically link the functions with the current widget.
Examples:
$title = get_value( 'title', 'widget' );
$sections = get_value( 'sections', 'widget' );
Quick start
- Creating fields and using their values
- Installation
- Administration interface
- Using the PHP API
- Container Settings
Locations
- Overview & Usage
- Post Type
- Options Page
- Taxonomy
- Comment
- User
- Widget
- Shortcode
- Menu Item
- Attachment
- Customizer
Fields
- Fields
- Text
- Textarea
- WYSIWYG
- Password
- Checkbox
- Select
- Multiselect
- Image Select
- File
- Image
- Audio
- Video
- Gallery
- WP Object
- WP Objects
- Link
- Date
- DateTime
- Time
- Color
- Font
- Icon
- Map
- Embed
- Number
- Sidebar
- Complex
- Repeater
- Layout
- Section
- Tab
- Message
Features
- Adding fields to the Customizer
- Conditional Logic
- Front-End Forms
- Administration columns
- Import and Export
- REST API
- JSON Synchronization
- Yoast SEO
Ultimate Post Types
Functions and API
Tutorials