JReviews logo
Guides My site
← All guides Community guide

Prevent title changes on listing updates

T Alejandro
Thread started by ToroLoco. Contributors Alejandro.
Thread started
Last updated

What you’ll achieve

Keep the existing title when a listing is updated, while other fields still save.

My site

Platform
JReviews version

Keep the owner's original listing title

Prevent signed-in listing owners from changing a manually entered title through the frontend edit form while allowing other fields to save. New listings accept their initial title. The input remains visible, so explain the restriction in your form.

The examples below apply when the signed-in editor is the stored owner. A non-owner editor and control-panel saves retain their existing title behavior. A staff member editing a listing they own on the frontend also meets the owner rule; add a separate staff exemption if your policy requires one.

Automatic title generation can run after these filters. These examples preserve manually entered titles; they do not freeze generated titles.

JReviews 6 Early Access

Enable Listing Form in Early Access before adding this customization.

Keep the stored title on frontend updates

Joomla. Use templates/jreviews_overrides/hooks.php.

WordPress. Use jreviews_overrides/hooks.php.

Add the callback marked with +. It ignores an owner's newly entered title on frontend updates.

  • If hooks.php already exists, add the marked lines at the end of the file. The copy button copies only those lines.
  • If you are creating hooks.php, type the two dimmed lines first, then add the marked lines below them.
<?php
defined('MVC_FRAMEWORK') or die;

fwd_add_filter('jreviews:listing.data_before_save', function ($data, $listing) {
    $userId = (int) fwd_auth()->id();

    if (fwd_request()->inFrontend() && $listing->exists
        && $userId > 0 && $userId === (int) $listing->owner_id) {
        unset($data['title']);
    }

    return $data;
}, 20, 2);

The code ignores an owner's newly entered title and keeps the saved title instead. Keep the site-form check in place so control-panel saves retain their normal behavior.

JReviews 5 and v6 Legacy

Keep the stored title on owner updates

Joomla. Use templates/jreviews_overrides/filters/filter_functions.php.

WordPress. Use jreviews_overrides/filters/filter_functions.php.

Add the callback marked with +. It ignores an owner's title change on edits through the site form.

  • If filter_functions.php already exists, add the marked lines at the end of the file. The copy button copies only those lines.
  • If you are creating filter_functions.php, type the two dimmed lines first, then add the marked lines below them.
<?php
defined('MVC_FRAMEWORK') or die;

Clickfwd\Hook\Filter::add('listing_save_pre', function ($data, $params) {
    $auth = S2Object::make('auth');
    $userId = (int) $auth->id;
    $listingId = (int) ($data['Listing']['id'] ?? 0);

    if ($params['is_new'] || $userId <= 0 || $listingId <= 0) {
        return $data;
    }

    $Listing = new EverywhereComContentModel;
    $existing = $Listing->findRow([
        'conditions' => ['Listing.' . EverywhereComContentModel::_LISTING_ID . ' = ' . $listingId],
    ]);

    if ($userId === (int) ($existing['Listing']['user_id'] ?? 0)) {
        unset($data['Listing']['title']);
    }

    return $data;
}, 10);

The code leaves new listings unchanged. On edits through the site form, it checks the owner saved on the listing, rather than trusting an owner ID sent with the form, before ignoring the title change.

Keep one PHP opening tag and framework guard in the file.

Check creation and editing

As an owner, create a listing, then change its title and another field through the frontend form. The original manual title should remain and the other change should save. Test a non-owner editor, a control-panel edit, and a staff-owned listing separately. Check any automatic title format too.

Clear Cache & File Registry after creating an override file.

Learn more