How To: Add plugin function calls without breaking your theme Cómo agregar llamadas a funciones plugin sin romper con su tema

ADVERTISEMENT PUBLICIDAD
To get our software and web/tips via email, sign up for Para conseguir nuestro software y web / sugerencias por correo electrónico, para firmar daily email newsletter boletín diario por correo electrónico . .
Subscribe to RSS feed Suscribirse al feed RSS or o follow me me siguen on Twitter? en Twitter?

Haven't you come across some meaningless pile of text, after which nothing is displayed? ¿No has encontrado con algún montón de sentido del texto, tras lo cual se visualiza nada? It breaks down the whole theme, causing problems for visitors and search bots alike. Se desglosa el tema entero, causando problemas para los visitantes y los robots de búsqueda por igual.


Don't we all hate those error codes? No todos odiamos los códigos de error?

What are function calls? ¿Qué son las llamadas a función?

Function calls are bits of PHP code that looks like this: <?php ns_show_top_commentators(); ?> Las llamadas a funciones son trozos de código PHP que se parece a esto: <?php ns_show_top_commentators(); ?>
Most plugins have such tags for specific uses; the above-mentioned code is to list the top commentators using the Show Top Commentators plugin. La mayoría de estos plugins tienen etiquetas para usos específicos, el código mencionado arriba es a la lista de los comentaristas utilizan la Top comentaristas Mostrar plugin.

The reason La razón

PHP function calls are notorious for breaking the theme, if the requested function does not exist. Las llamadas a funciones PHP son conocidos por romper el tema, si la función solicitada no existe. This usually happens when you add a function call for a plugin that you have disabled. Esto sucede generalmente cuando se agrega una llamada a la función de un plugin que tiene discapacidad. The result will be unaccessible blogs, which are caused by the behaviour of broken function calls. El resultado será inaccesible blogs, que son causados por el comportamiento de las llamadas a funciones roto. WordPress cuts off the rendering of page when it stumbles over a broken function all. WordPress cortes fuera de la prestación de la página cuando se tropieza con una función roto todos. Thus, depending on where you placed the broken code(sidebar/header/footer), your content may not be displayed, sidebars hidden or footers gone awry. Así, dependiendo de dónde se coloca el código de partido (barra lateral / encabezado / pie de página), su contenido no puede ser mostrada, barras laterales ocultos o pies de página ido mal.

The solution La solución

This problem can be overcome by using an if function_exists check. Este problema se puede superar mediante un cheque, if function_exists What does it do? ¿Qué hacer? It checks whether the given function actually exists, and if it does, proceeds to call the function. Se comprueba si la función dada en realidad existe, y si lo hace, procede a llamar a la función. This way, your theme will work even when the function call is broken. De esta manera, el tema funcionará incluso cuando se rompe la llamada de función.

Let us see an example of the conditional code (for Alex King's Twitter Tools plugin, used here on the top navbar). Veamos un ejemplo del código condicional (por Alex King's Twitter plugin de Herramientas, utilizado aquí en la barra de navegación superior).

ADVERTISEMENT PUBLICIDAD

The normal code for the Twitter tools is this: El código normal para las herramientas de Twitter es la siguiente:
<?php aktt_latest_tweet (); ?>

The conditional code would be this: El código condicional sería la siguiente:
<?php if(function_exists(' aktt_latest_tweet ')) { aktt_latest_tweet (); } ?> <? php if (function_exists ( 'aktt_latest_tweet')) (aktt_latest_tweet ();)?>

To use it for any other plugin, find and copy the what you find in place of aktt_latest_tweet in the first code block. Para utilizarlo para cualquier otro plugin, encontrar y copiar el lo que encuentra en el lugar de aktt_latest_tweet en el primer bloque de código. Then, paste that part in places of the code in red in the second code block. A continuación, pega la parte en los lugares del código en rojo en el segundo bloque de código.

This is a bit tricky, but play with it in a Esto es un poco complicado, pero jugar con él en un test blog installed locally on your PC prueba de blog instalado localmente en su PC , and once you get it right, upload it to your server. , Y una vez que salga bien, subirlo a tu servidor. Feel free to leave a comment on any issues that crop up on the way. Siéntase libre de dejar un comentario sobre las cuestiones que surgen en el camino.

To get our latest articles, Para conseguir nuestros últimos artículos, click here to sign up haga clic aquí para registrarse for our free email newsletter or subscribe to a nuestro boletín de correo electrónico gratuito o suscribirse a RSS feed RSS feed

§ Comments § Comentarios
  • Monika @ The Writers Manifesto says: Monika @ The Writers Manifiesto dice:

    Hi Sumesh, Hola Sumesh,

    Interesting post. Interesante post. I really love tech related stuff, as I can always learn more. Me encanta cosas relacionadas con la tecnología, como siempre puede aprender más. PHP is one of my weak points as I never learned coding. PHP es uno de mis puntos débiles, como nunca me enteré de codificación. Only trial by doing kind of stuff and reading about solutions like this is fascinating for me. Sólo juicio por hacer tipo de cosas y de la lectura acerca de las soluciones de este tipo es fascinante para mí.

    Good luck with your entry.:-) Buena suerte con tu entrada. :-)

    Monika Monika

  • Sumesh says: Sumesh dice:

    @Monika: Thanks. @ Monika: Gracias. As regards PHP, neither did I – its just a matter of interest, time and En cuanto a PHP, yo tampoco, - su sólo una cuestión de interés, el tiempo y elbow grease grasa del codo effort, plus some cheat sheets to learn PHP (hint: codex.wordpress.org) esfuerzo, además de algunas hojas de trucos para aprender PHP (pista: codex.wordpress.org)

  • Andrew says: Andrew dice:

    That's a great tip Sumesh. Esa es una Sumesh gran punta. It can be really easy not to notice these errors at the time and come back a few days later to find errors where you least expect them. Puede ser muy fácil no darse cuenta de estos errores en el tiempo y volver unos días después de encontrar errores donde menos te lo esperas.

  • Sumesh says: Sumesh dice:

    @Andrew: Thanks. @ Andrew: Gracias. As a matter of fact, I hunted down this bug after I forgot to check my soccerblog.in, which had the error you see in screenshot above. Como cuestión de hecho, perseguidos después de este error se me olvidó revisar mi soccerblog.in, que tuvo el error que aparece en pantalla y de arriba.

  • Haroon says: Haroon dice:

    Thanks.. Gracias ..
    as im not expert in php… como no soy experto en PHP ...
    so it helped me alot… and my problem is solved by reading ur post… thanks once again.. por lo que me ayudó mucho ... y mi problema es resuelto mediante la lectura de post UR ... gracias una vez más ..

  • § Leave a Reply § Deje una contestación