-
Notifications
You must be signed in to change notification settings - Fork 8
Comment
Ultimate Fields allows you to add additional fields to your comments.
Additional fields may only be displayed in the dashboard. Your front-end comment forms will not be modified.
To add fields to comments 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 "Comment" from the bottom row.
- Adjust when and where to show fields
The comment location in Ultimate Fields is handled by the Ultimate_Fields\Location\Comment
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( $args = array() ) {
$args
is an array, which allows you to set arguments without having to explicitly call the particular setter. For example, you can pass 'stati' => 'approved'
instead of calling ->set_stati( 'approved' )
.
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\Comment;
$container = Container::create( 'comment-settings' );
// Create a new location and add definitions to it
$location = new Comment();
$location->set_stati( 'approved' );
// 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 "comment" string as the first parameter to add_location()
. The rest of the parameters are the same as for the constructor of the location class.
use Ultimate_Fields\Container;
Container::create( 'comment-settings' )
->add_location( 'comment', array(
'stati' => 'approved'
));
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 Comment location, $type
parameter of all *_value
functions should have the "comment_XX"
format with XX
representing the ID of the comment.
Examples:
<?php
$style = '';
if( get_value( 'featured_comment', 'comment_5' ) ) {
$style = "font-size: 2em";
}
?>
<div style="<?php echo $style ?>">
<!-- normal comment content -->
</div>
There are a couple of options for the Comment location and all of them are listed below.
You can check which stati you want to associate a comment with. This settings allows you to show fields either on all comments or when a comment is marked as:
- Approved: keyword
approved
- Pending: keyword
pending
- Spam: keyword
spam
$container->add_location( 'comment', array(
'stati' => 'pending'
));
You can select whether the additional fields should appear with a higher priority than other meta boxes on the comment screen.
$container->add_location( 'comment', array(
'priority' => 'high'
));
you need to go the "REST API" tab and select which fields you want to include. You can also select if those fields are editable or not.
Please read the REST API section section of the Container Settings article, as the REST functionality is directly controlled in containers.
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