WordPress 2.0.1 Posting Bug

by Aaron Brazell on February 26, 2006 · 83 comments

I’ve squashed a bug in WordPress 2.0.1 that has been preventing our bloggers from posting reliably. The write up on the fix is as follows:

For the handful of you that are running WordPress 2.0.1, there is a bug that is causing bloggers to not be able to post. I’ve done some research and squashed the bug and have submitted it to the WordPress core for inclusion there. For us, I’ll be deploying the patch to ONLY WP 2.0.1 blogs in the next day or so.

How do I know If I am affected by the bug?
The bug only applies to WordPress 2.0.1 users. You can find out what version of WordPress you are on by logging into wp-admin and looking at the footer. If it says 2.0.1, 2.0.1 rc1 or 2.0.1 rc2, then this affects you.

Symptoms of Bug
Bloggers on WordPress 2.0.1 have reported experiencing problems when they submit posts where WordPress redirects to a 404 Page Not Found or directs to the blog itself. Normal behavior from the post screen is to hit publish and be redirected after the publish back to the Manage page. The problem is detailed further in WordPress Trac Ticket #2498 and on the WordPress Support Forum.

Technical Patch Details
There is a line in wp-includes/functions.php which tests for the existence of a $posts array. Typically, the $posts array contains all details about a post entry such as ID, post_author, post_title, etc. If the $posts array exists, WordPress continues to assume certain things - namely, that all relevant data regarding an entry is available to the function and proceeds to try to create a list of IDs from the $posts array (which contains all the relevant posts in one array, not just one.

Unfortunately, in the context that $posts is called (from within the edit screen in wp-admin, there is very little available regarding a post prior to publishing. It is not saved with a title, URL, timestamp, etc. All it has really is a date. So when $posts is passed to this function in this context there is not enough information for the rest of the function to use. The essential data that is needed by the rest of the function is a list of the post IDs in the $posts array. It does not have this information, so it cannot construct a list which is needed for a database query. This causes the database query to fail and the error appears in the value of hidden form field “referredby” on the edit screen.

On publish, WordPress looks to find out if there is a hidden “referredby” field and if one exists, will redirect to that page.. Quite a complicated little problem.

My patch solves this problem by testing for the existence of post IDs as well as posts themselves. If there is post data but no post ID, the function will now skip over this feature and keep going causing posting to function as normal.

Whew!
If you run 2.0.1 and you’re interested to see the bug in action, follow these steps:

1. Login to WordPress wp-admin
2. Write a post
3. Save and Continue Editing (this runs a function in PHP which calculates the referredby field - which errors - which causes problems later)
4. View Source on the new page. You should see a bit like this down the page a ways:

<input name="referredby" type="hidden" id="referredby" value=" id='error'>

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') ORDER BY post_id, meta_key' at line 1] SELECT post_id, meta_key, meta_value FROM wp2_postmeta WHERE post_id IN() ORDER BY post_id, meta_key

Manual Fix
For those running WP 2.0.1 blogs that want to get this fixed, edit line 1403 of wp-includes/functions from:


if( !$posts )

to

if( !$posts || !$posts[0]->ID )

Or ask me to do it. I don’t charge much. ;)

{ 3 trackbacks }

Speed Linking - 27 Feb 2006: ProBlogger Blog Tips
02.26.06 at 11:53 pm
einfach persoenlich Sideblog
02.27.06 at 3:17 am
Starboykb Blogger » Things I have done today…
02.27.06 at 6:11 am

{ 80 comments }

1

anty 02.27.06 at 6:52 am

Thank you for the solution, I’ve already added it to my blog ;)

2

anty 02.27.06 at 6:52 am

Thank you for the solution, I’ve already added it to my blog ;)

3

anty 02.27.06 at 6:52 am

Thank you for the solution, I’ve already added it to my blog ;)

4

anty 02.27.06 at 6:52 am

Thank you for the solution, I’ve already added it to my blog ;)

5

anty 02.27.06 at 6:52 am

Thank you for the solution, I’ve already added it to my blog ;)

6

Cary 02.27.06 at 3:58 pm

Hey…thanks for the fix!

7

Cary 02.27.06 at 3:58 pm

Hey…thanks for the fix!

8

Cary 02.27.06 at 3:58 pm

Hey…thanks for the fix!

9

Cary 02.27.06 at 3:58 pm

Hey…thanks for the fix!

10

Cary 02.27.06 at 3:58 pm

Hey…thanks for the fix!

11

Stuart 03.07.06 at 3:40 pm

Hmmm - did not work for me :(
Im getting a 500 - Internal Server Error (a wordpress one, not a real apache one). Only effects me when I try and post an entry with code in it.

Any ideas??

12

Stuart 03.07.06 at 3:40 pm

Hmmm - did not work for me :(
Im getting a 500 - Internal Server Error (a wordpress one, not a real apache one). Only effects me when I try and post an entry with code in it.

Any ideas??

13

Stuart 03.07.06 at 3:40 pm

Hmmm - did not work for me :(
Im getting a 500 - Internal Server Error (a wordpress one, not a real apache one). Only effects me when I try and post an entry with code in it.

Any ideas??

14

Stuart 03.07.06 at 3:40 pm

Hmmm - did not work for me :(
Im getting a 500 - Internal Server Error (a wordpress one, not a real apache one). Only effects me when I try and post an entry with code in it.

Any ideas??

15

Stuart 03.07.06 at 3:40 pm

Hmmm - did not work for me :(
Im getting a 500 - Internal Server Error (a wordpress one, not a real apache one). Only effects me when I try and post an entry with code in it.

Any ideas??

16

Aaron 03.07.06 at 3:50 pm

Wait a day or two. WP 2.0.2 will be out which fixes this and a bunch of other bugs.

17

Aaron 03.07.06 at 3:50 pm

Wait a day or two. WP 2.0.2 will be out which fixes this and a bunch of other bugs.

18

Aaron 03.07.06 at 3:50 pm

Wait a day or two. WP 2.0.2 will be out which fixes this and a bunch of other bugs.

19

Aaron 03.07.06 at 3:50 pm

Wait a day or two. WP 2.0.2 will be out which fixes this and a bunch of other bugs.

20

Aaron 03.07.06 at 3:50 pm

Wait a day or two. WP 2.0.2 will be out which fixes this and a bunch of other bugs.

21

Trevor 03.10.06 at 1:06 am

Didn’t work for me. I continue receiving stuff like this:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''schroeder\') as score FROM wp_posts where id=567' at line 1]
SELECT MATCH(post_content, post_title) against (’schroeder\’) as score FROM wp_posts where id=567;

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''don\') as score FROM wp_posts where id=567' at line 1]
SELECT MATCH(post_content, post_title) against (’don\’) as score FROM wp_posts where id=567;

22

Trevor 03.10.06 at 1:06 am

Didn’t work for me. I continue receiving stuff like this:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''schroeder') as score FROM wp_posts where id=567' at line 1]
SELECT MATCH(post_content, post_title) against (’schroeder’) as score FROM wp_posts where id=567;

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''don') as score FROM wp_posts where id=567' at line 1]
SELECT MATCH(post_content, post_title) against (’don’) as score FROM wp_posts where id=567;

23

Trevor 03.10.06 at 1:06 am

Didn’t work for me. I continue receiving stuff like this:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''schroeder') as score FROM wp_posts where id=567' at line 1]
SELECT MATCH(post_content, post_title) against (’schroeder’) as score FROM wp_posts where id=567;

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''don') as score FROM wp_posts where id=567' at line 1]
SELECT MATCH(post_content, post_title) against (’don’) as score FROM wp_posts where id=567;

24

Trevor 03.10.06 at 1:06 am

Didn’t work for me. I continue receiving stuff like this:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''schroeder') as score FROM wp_posts where id=567' at line 1]
SELECT MATCH(post_content, post_title) against (’schroeder’) as score FROM wp_posts where id=567;

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''don') as score FROM wp_posts where id=567' at line 1]
SELECT MATCH(post_content, post_title) against (’don’) as score FROM wp_posts where id=567;

25

Trevor 03.10.06 at 1:06 am

Didn’t work for me. I continue receiving stuff like this:

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''schroeder') as score FROM wp_posts where id=567' at line 1]
SELECT MATCH(post_content, post_title) against (’schroeder’) as score FROM wp_posts where id=567;

WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''don') as score FROM wp_posts where id=567' at line 1]
SELECT MATCH(post_content, post_title) against (’don’) as score FROM wp_posts where id=567;

26

Nimrod 03.14.06 at 4:07 am

Installed WP 2.0.2. The bug is still there. Even worse, the patch above does not work :(

27

Nimrod 03.14.06 at 4:07 am

Installed WP 2.0.2. The bug is still there. Even worse, the patch above does not work :(

28

Nimrod 03.14.06 at 4:07 am

Installed WP 2.0.2. The bug is still there. Even worse, the patch above does not work :(

29

Nimrod 03.14.06 at 4:07 am

Installed WP 2.0.2. The bug is still there. Even worse, the patch above does not work :(

30

Nimrod 03.14.06 at 4:07 am

Installed WP 2.0.2. The bug is still there. Even worse, the patch above does not work :(

31

Aaron 03.14.06 at 1:56 pm

Nimrod–

The problem was fixed in 2.0.2 and the patch is not required. If you have installed WP 2.0.2 and ran the upgrade script, what version is your wp-admin reporting???

32

Aaron 03.14.06 at 1:56 pm

Nimrod–

The problem was fixed in 2.0.2 and the patch is not required. If you have installed WP 2.0.2 and ran the upgrade script, what version is your wp-admin reporting???

33

Aaron 03.14.06 at 1:56 pm

Nimrod–

The problem was fixed in 2.0.2 and the patch is not required. If you have installed WP 2.0.2 and ran the upgrade script, what version is your wp-admin reporting???

34

Aaron 03.14.06 at 1:56 pm

Nimrod–

The problem was fixed in 2.0.2 and the patch is not required. If you have installed WP 2.0.2 and ran the upgrade script, what version is your wp-admin reporting???

35

Aaron 03.14.06 at 1:56 pm

Nimrod–

The problem was fixed in 2.0.2 and the patch is not required. If you have installed WP 2.0.2 and ran the upgrade script, what version is your wp-admin reporting???

36

Nimrod 03.14.06 at 2:08 pm

[Comment ID #4695 Will Be Quoted Here]

I am using 2.0.2. I reuploaded the unmodified functions.php. Anyway, I have tracked down the culprit. It seems that the host that my blog is on is using mod_security.

The post that triggers the behavior is very long and contains what would be interpreted as a shell scripting attack by mod_security. I found out that it gets triggered only if my post contained the word ‘curl’ in it. Since I am on a virtual hosted environment, I cannot turn off mod_security or even change the rules it uses.

Here is the post http://abing.gotdns.com/2006/03/14/php4-and-php5-side-by-side-installation-on-breezy/

The work-around I have found is to wrap the words ‘curl’ with tags.

37

Nimrod 03.14.06 at 2:08 pm

[Comment ID #4695 Will Be Quoted Here]

I am using 2.0.2. I reuploaded the unmodified functions.php. Anyway, I have tracked down the culprit. It seems that the host that my blog is on is using mod_security.

The post that triggers the behavior is very long and contains what would be interpreted as a shell scripting attack by mod_security. I found out that it gets triggered only if my post contained the word ‘curl’ in it. Since I am on a virtual hosted environment, I cannot turn off mod_security or even change the rules it uses.

Here is the post http://abing.gotdns.com/2006/03/14/php4-and-php...

The work-around I have found is to wrap the words ‘curl’ with tags.

38

Nimrod 03.14.06 at 2:08 pm

[Comment ID #4695 Will Be Quoted Here]

I am using 2.0.2. I reuploaded the unmodified functions.php. Anyway, I have tracked down the culprit. It seems that the host that my blog is on is using mod_security.

The post that triggers the behavior is very long and contains what would be interpreted as a shell scripting attack by mod_security. I found out that it gets triggered only if my post contained the word ‘curl’ in it. Since I am on a virtual hosted environment, I cannot turn off mod_security or even change the rules it uses.

Here is the post http://abing.gotdns.com/2006/03/14/php4-and-php...

The work-around I have found is to wrap the words ‘curl’ with tags.

39

Nimrod 03.14.06 at 2:08 pm

[Comment ID #4695 Will Be Quoted Here]

I am using 2.0.2. I reuploaded the unmodified functions.php. Anyway, I have tracked down the culprit. It seems that the host that my blog is on is using mod_security.

The post that triggers the behavior is very long and contains what would be interpreted as a shell scripting attack by mod_security. I found out that it gets triggered only if my post contained the word ‘curl’ in it. Since I am on a virtual hosted environment, I cannot turn off mod_security or even change the rules it uses.

Here is the post http://abing.gotdns.com/2006/03/14/php4-and-php...

The work-around I have found is to wrap the words ‘curl’ with tags.

40

Nimrod 03.14.06 at 2:08 pm

[Comment ID #4695 Will Be Quoted Here]

I am using 2.0.2. I reuploaded the unmodified functions.php. Anyway, I have tracked down the culprit. It seems that the host that my blog is on is using mod_security.

The post that triggers the behavior is very long and contains what would be interpreted as a shell scripting attack by mod_security. I found out that it gets triggered only if my post contained the word ‘curl’ in it. Since I am on a virtual hosted environment, I cannot turn off mod_security or even change the rules it uses.

Here is the post http://abing.gotdns.com/2006/03/14/php4-and-php...

The work-around I have found is to wrap the words ‘curl’ with tags.

41

Nimrod 03.14.06 at 2:11 pm

That last bit should have been:

The work-around I have found is to wrap the words ‘curl’ with SPAN tags.

42

Nimrod 03.14.06 at 2:11 pm

That last bit should have been:

The work-around I have found is to wrap the words ‘curl’ with SPAN tags.

43

Nimrod 03.14.06 at 2:11 pm

That last bit should have been:

The work-around I have found is to wrap the words ‘curl’ with SPAN tags.

44

Nimrod 03.14.06 at 2:11 pm

That last bit should have been:

The work-around I have found is to wrap the words ‘curl’ with SPAN tags.

45

Nimrod 03.14.06 at 2:11 pm

That last bit should have been:

The work-around I have found is to wrap the words ‘curl’ with SPAN tags.

46

Aaron 03.14.06 at 2:23 pm

Actually you can use <code> or <pre> or a combination of both as well. Do you have a plugin that executes PHP in the post because that could be making it wonky as well.

47

Aaron 03.14.06 at 2:23 pm

Actually you can use &lt;code&gt; or &lt;pre&gt; or a combination of both as well. Do you have a plugin that executes PHP in the post because that could be making it wonky as well.

48

Aaron 03.14.06 at 2:23 pm

Actually you can use &lt;code&gt; or &lt;pre&gt; or a combination of both as well. Do you have a plugin that executes PHP in the post because that could be making it wonky as well.

49

Aaron 03.14.06 at 2:23 pm

Actually you can use &lt;code&gt; or &lt;pre&gt; or a combination of both as well. Do you have a plugin that executes PHP in the post because that could be making it wonky as well.

50

Aaron 03.14.06 at 2:23 pm

Actually you can use &lt;code&gt; or &lt;pre&gt; or a combination of both as well. Do you have a plugin that executes PHP in the post because that could be making it wonky as well.

51

Nimrod 03.14.06 at 2:30 pm

[Comment ID #4698 Will Be Quoted Here]

No, I don’t think so. I do have PHP Markdown installed. But since the words ‘curl’ is usually found in <code> or <pre> markup on my post, I was not able to use Markdown to format text with ‘curl’ in them. Markdown would use HTML entities for anything that is formatted as code (indented by 4 spaces). So I had to resort to using HTML tags.

52

Nimrod 03.14.06 at 2:30 pm

[Comment ID #4698 Will Be Quoted Here]

No, I don’t think so. I do have PHP Markdown installed. But since the words ‘curl’ is usually found in &lt;code&gt; or &lt;pre&gt; markup on my post, I was not able to use Markdown to format text with ‘curl’ in them. Markdown would use HTML entities for anything that is formatted as code (indented by 4 spaces). So I had to resort to using HTML tags.

53

Nimrod 03.14.06 at 2:30 pm

[Comment ID #4698 Will Be Quoted Here]

No, I don’t think so. I do have PHP Markdown installed. But since the words ‘curl’ is usually found in &lt;code&gt; or &lt;pre&gt; markup on my post, I was not able to use Markdown to format text with ‘curl’ in them. Markdown would use HTML entities for anything that is formatted as code (indented by 4 spaces). So I had to resort to using HTML tags.

54

Nimrod 03.14.06 at 2:30 pm

[Comment ID #4698 Will Be Quoted Here]

No, I don’t think so. I do have PHP Markdown installed. But since the words ‘curl’ is usually found in &lt;code&gt; or &lt;pre&gt; markup on my post, I was not able to use Markdown to format text with ‘curl’ in them. Markdown would use HTML entities for anything that is formatted as code (indented by 4 spaces). So I had to resort to using HTML tags.

55

Nimrod 03.14.06 at 2:30 pm

[Comment ID #4698 Will Be Quoted Here]

No, I don’t think so. I do have PHP Markdown installed. But since the words ‘curl’ is usually found in &lt;code&gt; or &lt;pre&gt; markup on my post, I was not able to use Markdown to format text with ‘curl’ in them. Markdown would use HTML entities for anything that is formatted as code (indented by 4 spaces). So I had to resort to using HTML tags.

56

Stacie 03.15.06 at 9:21 pm

Well, I finally did it and updated. Now, do I still do the second patch or will I mess something up? Everything is running great right now.

57

Stacie 03.15.06 at 9:21 pm

Well, I finally did it and updated. Now, do I still do the second patch or will I mess something up? Everything is running great right now.

58

Stacie 03.15.06 at 9:21 pm

Well, I finally did it and updated. Now, do I still do the second patch or will I mess something up? Everything is running great right now.

59

Stacie 03.15.06 at 9:21 pm

Well, I finally did it and updated. Now, do I still do the second patch or will I mess something up? Everything is running great right now.

60

Stacie 03.15.06 at 9:21 pm

Well, I finally did it and updated. Now, do I still do the second patch or will I mess something up? Everything is running great right now.

61

Aaron 03.15.06 at 9:36 pm

Which version are you running, Stacie?

62

Aaron 03.15.06 at 9:36 pm

Which version are you running, Stacie?

63

Aaron 03.15.06 at 9:36 pm

Which version are you running, Stacie?

64

Aaron 03.15.06 at 9:36 pm

Which version are you running, Stacie?

65

Aaron 03.15.06 at 9:36 pm

Which version are you running, Stacie?

66

Minks 04.30.06 at 12:56 am

I tried that on wp 2.02 and still face the same problem. Any other soloution

67

Minks 04.30.06 at 12:56 am

I tried that on wp 2.02 and still face the same problem. Any other soloution

68

Minks 04.30.06 at 12:56 am

I tried that on wp 2.02 and still face the same problem. Any other soloution

69

Minks 04.30.06 at 12:56 am

I tried that on wp 2.02 and still face the same problem. Any other soloution

70

Minks 04.30.06 at 12:56 am

I tried that on wp 2.02 and still face the same problem. Any other soloution

71

Minks 04.30.06 at 1:05 am

Finally, I found the problem. It’s the word that trigger the problem. So I changed it to plural or tense and the problem solved. This is crazy, because that sentence doesn’t make sense let alone is grammatically correct.

I find this really ridculous, what is wrong with the word curl? Any significant issue to technical or program problem?

72

Minks 04.30.06 at 1:05 am

Finally, I found the problem. It’s the word that trigger the problem. So I changed it to plural or tense and the problem solved. This is crazy, because that sentence doesn’t make sense let alone is grammatically correct.

I find this really ridculous, what is wrong with the word curl? Any significant issue to technical or program problem?

73

Minks 04.30.06 at 1:05 am

Finally, I found the problem. It’s the word that trigger the problem. So I changed it to plural or tense and the problem solved. This is crazy, because that sentence doesn’t make sense let alone is grammatically correct.

I find this really ridculous, what is wrong with the word curl? Any significant issue to technical or program problem?

74

Minks 04.30.06 at 1:05 am

Finally, I found the problem. It’s the word that trigger the problem. So I changed it to plural or tense and the problem solved. This is crazy, because that sentence doesn’t make sense let alone is grammatically correct.

I find this really ridculous, what is wrong with the word curl? Any significant issue to technical or program problem?

75

Minks 04.30.06 at 1:05 am

Finally, I found the problem. It’s the word that trigger the problem. So I changed it to plural or tense and the problem solved. This is crazy, because that sentence doesn’t make sense let alone is grammatically correct.

I find this really ridculous, what is wrong with the word curl? Any significant issue to technical or program problem?

76

Aaron Brazell 04.30.06 at 10:54 pm

Are you running PHP exec or something? ‘curl‘ is a unix library for fetching/grokking URLs from the command line and PHP has wrapper functions around it.

77

Aaron Brazell 04.30.06 at 10:54 pm

Are you running PHP exec or something? ‘curl‘ is a unix library for fetching/grokking URLs from the command line and PHP has wrapper functions around it.

78

Aaron Brazell 04.30.06 at 10:54 pm

Are you running PHP exec or something? ‘curl‘ is a unix library for fetching/grokking URLs from the command line and PHP has wrapper functions around it.

79

Aaron Brazell 04.30.06 at 10:54 pm

Are you running PHP exec or something? ‘curl‘ is a unix library for fetching/grokking URLs from the command line and PHP has wrapper functions around it.

80

Aaron Brazell 04.30.06 at 10:54 pm

Are you running PHP exec or something? ‘curl‘ is a unix library for fetching/grokking URLs from the command line and PHP has wrapper functions around it.

Comments on this entry are closed.

Older post: The Problems with Windows Vista is Windows

Newer post: Great new blogs on 24