Skip to content

feat(admin): add Job Data fields to Bulk Edit - #3045

Open
faisalahammad wants to merge 2 commits into
Automattic:trunkfrom
faisalahammad:feature/2448-bulk-edit-job-data
Open

feat(admin): add Job Data fields to Bulk Edit#3045
faisalahammad wants to merge 2 commits into
Automattic:trunkfrom
faisalahammad:feature/2448-bulk-edit-job-data

Conversation

@faisalahammad

@faisalahammad faisalahammad commented Jul 11, 2026

Copy link
Copy Markdown

Summary

This pull request adds support for bulk editing Job Data fields on the job listings list table. Administrators can now update common fields (such as Location, Company Name, Expiry date, and Filled status) for multiple listings at once, where empty fields are treated as "no change."
Closes #2448

Changes

WP_Job_Manager_Writepanels

Before:

	public function __construct() {
		add_action( 'add_meta_boxes', [ $this, 'add_meta_boxes' ] );
		add_action( 'save_post', [ $this, 'save_post' ], 1, 2 );
		add_action( 'job_manager_save_job_listing', [ $this, 'save_job_listing_data' ], 20, 2 );
	}

After:

	public function __construct() {
		add_action( 'add_meta_boxes', [ $this, 'add_meta_boxes' ] );
		add_action( 'save_post', [ $this, 'save_post' ], 1, 2 );
		add_action( 'job_manager_save_job_listing', [ $this, 'save_job_listing_data' ], 20, 2 );
		add_action( 'bulk_edit_custom_box', [ $this, 'bulk_edit_fields' ], 10, 2 );
		add_action( 'save_post', [ $this, 'bulk_edit_save' ], 10, 2 );
	}

Why:
We need to register hooks for native WordPress bulk edit rendering (bulk_edit_custom_box) and saving (save_post). We implemented get_bulk_edit_fields(), bulk_edit_fields(), and bulk_edit_save() to handle rendering and processing the bulk metadata fields securely with nonce validation and proper capability checks.

Testing

Test 1: Bulk Edit text fields and selects

  1. Select multiple listings in the Jobs list table.
  2. Select Edit under Bulk actions and click Apply.
  3. Set Location to "London" and Position Filled to "Yes**.
  4. Click Update and verify the changes on the selected listings. Verify empty fields were not modified.
    Result: works as expected

Test 2: Clearing Expiry Date

  1. Select multiple listings that have an expiry date set.
  2. Select Edit under Bulk actions and click Apply.
  3. Check the Clear expiry checkbox.
  4. Click Update and verify that the expiry date meta field is cleared.
    Result: works as expected

Test 3: Expiry Date Past status flip

  1. Select a listing.
  2. Bulk Edit and set Listing Expiry Date to a past date (e.g. yesterday).
  3. Click Update and verify the listing status is automatically flipped to expired.
    Result: works as expected

Test 4: Capability and security checks

  1. Log in as a user who lacks manage_job_listings capability.
  2. Try to bulk edit. Verify that fields requiring manage capability (like Featured or Expiry Date) are not visible/editable, and any unauthorized save requests are ignored.
    Result: works as expected

Automated PHPUnit tests were also added in tests/php/tests/includes/admin/test_class.wp-job-manager-writepanels.php and they all pass cleanly.

Screenshots

Before After
Before After

Release Notes

  • Added bulk editing support for Job Data fields on the job listings list table (location, company name, expiry date, filled status). Empty fields act as "no change"; nonces and capability checks gate the request; reviews already in the past flip automatically to expired.

New or Updated Hooks and Templates

  • New filter job_manager_bulk_edit_excluded_field_types (array of field type strings excluded from bulk edit; defaults to file, info, hidden, author, textarea, wp_editor). Receives $excluded array.

Deprecated Code

Add Job Data fields (Location, Company Name, Expiry, etc.) to the Bulk Edit form so administrators can edit multiple listings at once.

Fixes Automattic#2448
@donnchawp

Copy link
Copy Markdown
Contributor

This was generated by AI during triage.

This is solid work — nonce, per-post edit_post capability, the per-field auth_edit_callback
re-check against the real $post_id, blank-means-no-change, and the autosave/revision guards are
all correctly in place and tested. One blocker:

Needs fixing

  1. wp_update_post() is called inside your own save_post handler without unhooking.
    (includes/admin/class-wp-job-manager-writepanels.php:1009-1019, when a bulk-edited expiry is
    in the past.) wp_update_post() fires save_post synchronously, so bulk_edit_save() — and
    every other save_post listener (cache flushes, third-party webhooks/notifications) — runs a
    second time for the post; every meta field is written twice. This file already handles exactly
    this hazard ~250 lines up in save_job_listing_data() (remove_actionwp_update_post
    add_action) and in the _job_author case (raw $wpdb->update(), annotated "Avoid update
    post within save_post action."). Please apply the same guard.
  2. @since 2.4.6 at :781$$next-version$$.
  3. Optional: extensible field types textarea/wp_editor fall through to a single-line
    <input type="text">; worth excluding them by default alongside file/info, or adding a
    <textarea> branch.

Adjacent to #3040 (Quick Edit): no conflict, but the two build parallel auth/sanitization paths
for the same _featured/_filled meta — worth reconciling if both land.

bulk_edit_save hooks save_post at priority 10 and calls wp_update_post
when the listing's expiry puts it in the past. wp_update_post fires
save_post synchronously, so every save_post listener (this one
included) would re-run for the post.

Wrap the wp_update_post call in remove_action/add_action to mirror the
existing guard in save_job_listing_data().

Also switch the new bulk_edit_excluded_field_types @SInCE token to
$$next-version$$ and exclude textarea + wp_editor from the
default bulk-edit field set (single-line text input is not appropriate
for them).

Addresses PR feedback.
Refs Automattic#3045
@faisalahammad

Copy link
Copy Markdown
Author

Fixed in a01511c. Items 1, 2, 3 all addressed.

  1. Wrapped the wp_update_post call at end of bulk_edit_save() with remove_action/add_action on save_post priority 10, mirroring the existing guard in save_job_listing_data() at ~line 740.
  2. @SInCE 2.4.6 -> $$next-version$$.
  3. textarea, wp_editor added to the default excluded types.

PHPCS clean on the edited file locally. PR description filled with Release Notes + Hooks section per template. Ready for re-review when you have a moment.

faisalahammad added a commit to faisalahammad/WP-Job-Manager that referenced this pull request Jul 29, 2026
Address review feedback on Automattic#3040:

- Gate the Quick Edit row action off for expired, pending_payment, and
  preview listings. Core's inline-edit Status select only offers core
  statuses, so a save on a WPJM-managed status would silently fall back
  to publish and republish the listing.
- Add autosave/revision guards to quick_edit_save (post-type, DOING_AUTOSAVE,
  wp_is_post_revision/wp_is_post_autosave) for parity with the existing
  save_post handler and Automattic#3045's bulk_edit_save.
- Switch the capability check from the flat CAP_MANAGE_LISTINGS (which
  ignored $post_id) to a per-post current_user_can('edit_post', $post_id),
  matching the established save_post convention.
- Add @SInCE $$next-version$$ to quick_edit_custom_box, add_inline_data,
  and quick_edit_save.
- Add tests for the WPJM-managed status gate, non-admin denial, and the
  revision short-circuit.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Job Data fields to bulk edit

2 participants