DEV Community

hub
hub

Posted on

simple start with ACF - plugin (wordpress) to get started with a widget

simple start with ACF - plugin (wordpress) to get a widget that contains where a user of the website can send a image and a link in - that has to be approved by the webadmin

!
here a simple starting point for creating a widget in WordPress using the Advanced Custom Fields (ACF) plugin that allows users to submit an image and a link that needs to be approved by the web admin.

Here are the steps you can follow:

Install and activate the ACF plugin in your WordPress website.

Create a new custom post type for the user submissions by adding the following code to your functions.php file:

function create_submission_post_type() {
register_post_type( 'user-submissions',
array(
'labels' => array(
'name' => __( 'User Submissions' ),
'singular_name' => __( 'User Submission' )
),
'public' => true,
'has_archive' => true,
'supports' => array( 'title', 'thumbnail' )
)
);
}
add_action( 'init', 'create_submission_post_type' );
This will create a new custom post type called "User Submissions" with support for title and thumbnail.

Create a new ACF field group for the user submissions by going to Custom Fields > Add New in the WordPress admin dashboard.

Add two fields to the ACF field group:

A file upload field for the image
A text field for the link
In the ACF field group settings, set the location rule to "Post Type is equal to User Submissions" so that the fields only appear on the user submission post type.

**Create a new widget **by adding the following code to your functions.php file:

`class User_Submission_Widget extends WP_Widget {

public function __construct() {
    parent::__construct(
        'user_submission_widget',
        __('User Submission Widget', 'text_domain'),
        array( 'description' => __( 'Allows users to submit an image and`
Enter fullscreen mode Exit fullscreen mode

Top comments (0)