#1417 closed defect (bug) (fixed)
The method insert_with_markers() does not perform as it is supposed to
Reported by: | EricAnderson | Owned by: | markjaquith |
---|---|---|---|
Milestone: | Priority: | high | |
Severity: | major | Version: | 1.5.1.1 |
Component: | Administration | Keywords: | bg|commit |
Focuses: | Cc: |
Description
This method does not insert a new line after the # END {$marker} code, which causes it (somehow, yet unknown) to erase the # END {$marker} line, so when plugin calls this code, the endline gets erased and is replaced with a # BEGIN {$new_marker} ... now if the original code calls the insert_with_markers again, it never sees its end line, and thus replaces everything.
The code is more complicated than it needs to be and the attached replacement function removes the complicated code and solves the problem. The original code did some odd checking for whether to use a new line before the statement or not, but in simply using a new line after every statement, this is avoided.
function insert_with_markers($filename, $marker, $insertion) { if (!file_exists($filename) || is_writeable($filename)) { if (!file_exists($filename)) { $markerdata = ''; } else { $markerdata = explode("\n", implode('', file($filename))); } print_r($markerdata); $f = fopen($filename, 'w'); $foundit = false; if ($markerdata) { $state = true; foreach($markerdata as $markerline) { if (strstr($markerline, "# BEGIN {$marker}\n")) $state = false; if ($state) fwrite($f, "{$markerline}\n"); if (strstr($markerline, "# END {$marker}\n")) { fwrite($f, "# BEGIN {$marker}\n"); if(is_array($insertion)) foreach($insertion as $insertline) fwrite($f, "{$insertline}\n"); fwrite($f, "# END {$marker}\n"); $state = true; $foundit = true; } } } if (!$foundit) { fwrite($f, "# BEGIN {$marker}\n"); foreach($insertion as $insertline) fwrite($f, "{$insertline}\n"); fwrite($f, "# END {$marker}\n"); } fclose($f); return true; } else { return false; } }
Attachments (2)
Change History (10)
#2
@
19 years ago
Oops! Further investigation shows the problem has to do with the last line in the file not having an extra newline at the end of it. The same fix applies.
#3
@
19 years ago
I just noticed I left my debug print_r() in the file I attached as well as the pasted code... That needs to be removed.
Since I can't attach the file again, you can grab the new method here:
http://ericanderson.us/wp-content/ea.us/files/wordpress-fixes/insert_with_markers.zip
Sorry for the inconvience.
#4
@
19 years ago
Doh! Yet again, this bug tracking software tricked me, so now the file is uploaded, ignore the first one :)
#6
@
19 years ago
- Keywords bg|commit added
- Owner changed from anonymous to markjaquith
- Priority changed from normal to high
- Severity changed from normal to major
- Status changed from new to assigned
I forgot to mention that the code for this block starts at line 476 (atleast in 1.5.1.1) of /wp-admin/admin-functions.php