Make a field moderated in the listing submission form

In the below code it works to set the listing to Pending if you edit title, but if you create a new Listing it isn’t moderated to Pending

function custom_moderate_listing_form( $form ) {
    $user_id = get_current_user_id();
    
    // Get the vendor object using the user ID
    $vendor = HivePress\Models\Vendor::query()->filter( [ 'user' => $user_id ] )->get_first();

    if ( $vendor && ! $vendor->get_verified() ) {
        $form['fields']['title']['_moderated'] = true;
    }

    return $form;
}

add_filter( 'hivepress/v1/forms/listing_submit', 'custom_moderate_listing_form' );
add_filter( 'hivepress/v1/forms/listing_update', 'custom_moderate_listing_form' );

PS - As bonus would be helpful to know if way to say if any field is edited then “[‘_moderated’] = true;”

1 Like

Yes, the listing submission form has a different logic, so the “_moderated” parameter will not work there. If you have moderation enabled in settings, then basically all the fields are moderated because they are empty for new listing submissions and the submitted listing gets the Pending status in any case.

If you don’t have moderation enabled, then the listing will be published after the form is submitted because there’s a code that changes the listing status and probably overrides the status set by the moderated fields in the form hivepress/includes/controllers/class-listing.php at master · hivepress/hivepress · GitHub So if the moderation is disabled, adding support for moderated fields in the listing submission form would require further customizations.

Hope this helps

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.