Problem with WP custom fields and MarsEdit solved

With the help of MarsEdit developer we’ve managed to solve the annoying problem of not being able to write custom fields in a WordPress blog. This has caused me to change my workflow as I previously reported.

The problem is caused by some security changes introduced in WordPress 3.1.3 and above. According to the Red Sweater forum:

Currently the great developers at WordPress looking into this and hopefully they’ll come up with a solution that will fix it in an update to WordPress, or at least have advice for how the plugin developers should change their handling of custom fields.

A fix to this problem is to edit the meta.php file found in your WordPress installation under this path:

[WordPress_Installation_Folder]/www/wp-includes/meta.php

You will need to edit this function:

function is_protected_meta( $meta_key, $meta_type = null ) {
    $protected = (  '_' == $meta_key[0] );

    return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );
}

In order to be able to edit your blog custom fields from MarsEdit, you need to wihitelist them. I’ll include the solution for two popular SEO plugins:

  1. All in One SEO
  2. SEO by Yoast

All in One SEO

function is_protected_meta( $meta_key, $meta_type = null ) {
-   $protected = ( '_' == $meta_key[0] );
+   $protected = (( '_' == $meta_key[0] ) && ( strpos($meta_key, "_aioseop") !== 0));

return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );
}

SEO by Yoast

function is_protected_meta( $meta_key, $meta_type = null ) {
    -   $protected = ( '_' == $meta_key[0] );
    +   $protected = (( '_' == $meta_key[0] ) && ( strpos($meta_key, "_yoast_") !== 0));

return apply_filters( 'is_protected_meta', $protected, $meta_key, $meta_type );
}

The two solutions work provided that you added the custom fields in MarsEdit using respectively _aioseop and _yoast_ prefixes. I strongly advise to backup your meta.php file before editing it.

For your information, just yesterday I upgraded my WordPress installation to version 3.2.1 and the problem is still there. Every time you update WordPress you need to edit the meta.php file.

10 thoughts on “Problem with WP custom fields and MarsEdit solved

  1. Pingback:
  2. Hello,
    I am new to the whole blogging thing and while I feel like I would like to sink my teeth into modifying config files, etc I as yet have no experience (or knowledge) to do so.

    I’m just trying to get MarsEdit set up and I have completely surprised myself by being able to follow your instructions and actually fix this issue first go without stuffing anything up!

    So I just wanted to write to say thank you very much for the post, it has really helped me out, and thanks for the easy to follow instructions :)

    Jarratt

    Reply
  3. Hi Jarratt,

    Thanks a lot for your comment, I am happy to know that these instructions helped you fix the custom fields problem. Really happy indeed!

    You got a great blog by the way, congrats.

    Pietro

    Reply
  4. Is this still working for you with the new versions of wordpress — 3.3 & 3.4? When I make the meta.php edit on my 3.4 installation, it breaks the blog on the admin side, i.e. I can’t even pull up the login screen, much less get into the dashboard.

    Reply
    1. First of all apologies for not approving and replying to your comment earlier. My wife and I took a few days off in Sonoma and Napa Valley and decided to live it completely offline. 

      Thanks for your feedback. I am using WP 3.3.2 and the solution works perfectly fine for me. I haven’t tested it with 3.4 as I haven’t decided not to upgrade for the time being.

      I’ll leave some feedback if I manage to find the time to test 3.4 in the next future. Sorry for not being more helpful.

      Best regards,
      Pietro

      Reply
        1. Hi,

          This is to let you know that a few minutes ago I updated my WP to 3.4.1 and applied the solution in my post. MarsEdit manages to add the custom fields without any problems and my blog – luckily – is still up and running.

          Not sure what’s causing the problem you’ve experienced. Maybe a file corruption or even a stupid syntax error in one of the files.

          Best regards,
          Pietro

          Reply
          1. Thanks, I’ll see what I can figure out. I’ve checked my syntax so much, by eye and text editor, that I don’t think it’s that. Corruption makes sense in that there are some other problems I’m experiencing.

Leave a Reply