So your WordPress plugin kills the Theme Editor?

You’ve created a plugin that worked happily since version 2.5 of WordPress. Then came version 2.9 and the users of your plugin complain that the theme editor does not work anymore! What the theme editor? What have I to do with the theme editor?

That were my thoughts when I received bug reports for the pagebar plugin. I had absolutely no idea why and first checked the usual suspects; with no success. So I tried a different approach and disabled all initialisation code. The theme editor worked. I enabled the first disabled line and Eureka! The theme editor failed. This has to be the
erroneous line:

$dir = trailingslashit(WP_CONTENT [...]

The $dir variable is global and that seemed to be the problem. A short look at theme-editor.php shows that’s there a global variable called $dir. So I changed the variable name in my plugin to a more unique name and voilà, everything works as expected.

There are some lessons I learned from this incident:

  • Use a unique name for your global variables.
  • Better: Never use global variables at all.
  • Even better: encapsulate everythin inside a class.

I hope his short story helped you to debug your plugin and leave some happy users behind.


Comments

6 responses to “So your WordPress plugin kills the Theme Editor?”

  1. […] de funcionar, puede que tengas que revisar los plugins instalados por si les pasa como a Pagebar y ha detectado su autor. (Gracias por el aviso […]

  2. Información Bitacoras.com…
    Valora en Bitacoras.com: Si de repente, al actualizar a WordPress 2.9, el editor de themes deja de funcionar, puede que tengas que revisar los plugins instalados por si les pasa como a Pagebar y ha detectado su autor. (Gracias por el aviso Alejandro)…..
    This comment was originally posted on Ayuda WordPress

  3. Social comments and analytics for this post…
    This post was mentioned on Twitter by fernandot: El editor de themes no funciona http://goo.gl/fb/mVct #wordpress…
    This comment was originally posted on Ayuda WordPress

  4. fernando:
    ayer realize una instalacion desde cero con WP 2.9 es_ES.
    Al instalar, el archivo wp-config.php no se escribió totalmente bien.
    Me explico, primero solicita los datos de coneccion a la base de datos (setup-config.php), ese paso se realizó con exito.
    En el siguiente paso, cuando cambia a wp-admin/install.php me decia que no se podia conectar a la bdd.
    Revise el archivo wp-config.php que se creó a partir del -sample.php, y solo se modifico el valor del host
    define(‘DB_NAME’, ‘nombredetubasededatos’); <<< quedó igual
    define('DB_USER', 'nombredeusuario'); <<< quedó igual
    define('DB_PASSWORD', 'contraseña'); <<< quedó igual
    define('DB_HOST', 'internal-db.xxxxxx.gridserver.com'); <<< Este es el unico valor modificado.
    Lo intenté un par de veces (borrado wp-config.php) y siempre lo mismo.
    El servidor es mediatemple, y no es la primera vez que instalo WP.
    Sera la traduccion? Si fuese un problema con los permisos de escritura, no se modificaria en absoluto el archivo, pero en este caso si se modifica un valor (el host).
    This comment was originally posted on Ayuda WordPress

  5. Que cosa más rara, máxime cuando en mediatemple el valor del host es hostname normalmente
    This comment was originally posted on Ayuda WordPress

  6. […] Continued here: So your WordPress plugin kills the Theme Editor? – elektroelch.net […]

Leave a Reply

Your email address will not be published. Required fields are marked *