#3146 closed defect (bug) (fixed)
Convertor values passed to JS are cast to string
| Reported by: |
|
Owned by: |
|
|---|---|---|---|
| Milestone: | 2.6 | Priority: | high |
| Severity: | normal | Version: | trunk |
| Component: | API - Importers | Keywords: | has-patch commit |
| Cc: | johnjamesjacoby, jrf |
Description
Boolean and integer values passed to JS via wp_localize_script() will be converted to string *unless* they are within an array.
So the type casting done in the wp_localize_script() call in class-bbp-convertor.php is rendered useless as things stand now.
The net effect was the var being passed as follows (for a new import):
var BBP_Converter = {"ajax_nonce":"e5f8daf4fa","delay":"2","running":"","status":"","started":"","strings":{"button_start":"Start","button_continue":"Continue","start_start":"Starting Import...","start_continue":"Continuing Import...","import_complete":"Import Finished.","import_stopped_user":"Import Stopped (by User.)","import_error_halt":"Import Halted (Error.)","import_error_db":"Database Connection Failed.","status_complete":"Finished","status_stopped":"Stopped","status_starting":"Starting","status_up_next":"Doing step %s...","status_counting":"Next in %s..."}};
This was causing issues with the JS convertor script.
On top of that the comparison for whether or not the convertor had started was reversed.
This results in the "Continuing import" message being displayed on a new import instead of the "Starting import" message.
The attached patch will fix these issues in the simplest possible way.
With the patch applied, the var being passed will have the relevant subkeys in the correct variable type:
var BBP_Converter = {"ajax_nonce":"8cb79361eb","state":{"delay":2,"running":false,"status":false,"started":false},"strings":{"button_start":"Start","button_continue":"Continue","start_start":"Starting Import...","start_continue":"Continuing Import...","import_complete":"Import Finished.","import_stopped_user":"Import Stopped (by User.)","import_error_halt":"Import Halted (Error.)","import_error_db":"Database Connection Failed.","status_complete":"Finished","status_stopped":"Stopped","status_starting":"Starting","status_up_next":"Doing step %s...","status_counting":"Next in %s seconds..."}};
Nice!
This looks great. Thanks a lot for catching this. It's all new code, so I appreciate your eyes on it.
Fix imminent.