Automattic / Automattic/WP-Job-Manager

Geocoding runs on WP All Import even when `job_manager_geolocation_enabled` filter returns false

Open Beginner friendly
#3,002 0 comments 0 reactions 0 assignees View on GitHub
Bug Hooks needs-triage
Dominant language
PHP
Stars
899
Forks
369
Avg merge
11h 37m
Merged PRs (30d)
12

Description

### Summary

The `job_manager_geolocation_enabled` filter is documented/intended as the global off-switch for geocoding, but it only guards two of the three geocoding trigger paths. The **WP All Import** path bypasses the filter entirely, so a site that has explicitly disabled geocoding will still geocode imported job listings (hitting the Google Maps Geocoding API and writing `geolocation_*` meta).

### Steps to Reproduce
1. Add a snippet to disable geocoding:
```php
add_filter( 'job_manager_geolocation_enabled', '__return_false' );
```
2. Import one or more job listings via WP All Import with the `_job_location` custom field populated.
3. Inspect an imported job's post meta (e.g. via Custom Fields or `get_post_meta`).

### What I Expected
With `job_manager_geolocation_enabled` returning `false`, **no** creation path geocodes — frontend submit, admin edit, and import alike. No `geolocation_*` meta, no outbound request to Google.

### What Happened Instead
Imported jobs are still geocoded: `geolocation_lat`, `geolocation_long`, `geolocation_formatted_address`, etc. are written and the Google Geocoding API is called. Only the frontend-submit and admin/meta-hook paths respect the filter.

### Root Cause
The filter is checked in two of the three entry points but not the third:

- `WP_Job_Manager_Geocode::update_location_data()` — guarded — `includes/class-wp-job-manager-geocode.php:60`
- `WP_Job_Manager_Geocode::change_location_data()` — guarded — `includes/class-wp-job-manager-geocode.php:73`
- `WP_Job_Manager_Geocode::generate_location_data()` — **not guarded** — `includes/class-wp-job-manager-geocode.php:96-99`

`generate_location_data()` is the public static entry point used by the importer integration, called directly here:

- `includes/3rd-party/wp-all-import.php:21` (from the `pmxi_saved_post` handler)

Because `generate_location_data()` never consults `apply_filters( 'job_manager_geolocation_enabled', true )`, the import path geocodes unconditionally.

### Suggested Fix
Guard `generate_location_data()` with the same filter so the off-switch is honoured on every path:

```php
public static function generate_location_data( $job_id, $location ) {
if ( ! apply_filters( 'job_manager_geolocation_enabled', true ) ) {
return;
}
$address_data = self::get_location_data( $location );
self::save_location_data( $job_id, $address_data );
}
```

Guarding inside the method (rather than at the `wp-all-import.php` call site) is preferable since `generate_location_data()` is the shared public entry point any importer/integration may call.

### PHP / WordPress / WP Job Manager Version
Present on `trunk` (current). Not version-specific.

### Context / Source
Found while reconciling a documentation discrepancy about geocoding behaviour for admin-created and imported jobs (internal ref WPJ-11). The three trigger paths were audited against the code; this filter gap is a byproduct of that audit rather than a directly reported customer issue.

Contributor guide

Open the contributing guide

Research direction

Start in includes/class-wp-job-manager-geocode.php, especially generate_location_data() and the guarded update_location_data() and change_location_data() methods. Then inspect includes/3rd-party/wp-all-import.php and its pmxi_saved_post handler to understand the import entry point. Done means the disabled filter prevents imported geocoding and Google requests while existing enabled behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
php, wordpress
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.