This chapter ties together several of the core concepts from previous chapters, while investigating WordPress’ capabilities as a CMS. It also covers a few extra tricks, including shortcodes, creating a link to your plugin’s settings page, and how to clean up when someone uninstalls your plugin. The task before us is to tap into WordPress’ CMS abilities by using the register_post_type() function. Judging by the diffiulties tracked in the SVN repository
as WordPress 3.1 got ready for launch, it seems that we weren’t the only ones who experienced diffiulties in wrestling with WordPress’ CMS capabilities. A word of warning: this function is diffiult to use and lacks good documentation,
and exploring its full capabilities is beyond the scope of this chapter. If you want to examine a fuller implementation of custom post types and what they can do, have a look at one of our plugins (http://goo.gl/cgJDU)—this is the plugin we wrote for early drafts of this chapter, but the code quickly grew too complex for educational purposes. Our aim here is to demonstrate one use case of the register_post_type() function, so you can see how it works. We want a plugin that allows users to create their own reusable chunks of content that we can reference in other posts
via WordPress shortcodes, denoted by square brackets, for example, [exampleshortcode] . This is a great way to reuse content across many posts or pages.
Sin categoría
Descansa sabroso en la playita
Widget overview
Even if you are already familiar with widgets, take a moment to look at how they work in the WordPress manager under Appearance | Widgets. You know that they display content on the frontend of your site, usually in a sidebar, and they also have text and control forms that are displayed only when you view them inside the manager. If you put on your thinking cap, this should suggest to you at least two actions: an action that displays the content on the frontend, and an action that displays the form used to update the widget settings inside the manager. There are actually a total of four actions that determine the behavior of a standard widget, and you can think of these functions
as a unit because they all live together in a single widget object. In layman’s terms, there are four things that any widget can do. In programmatic terms, the WP_Widget object class has four functions that you may implement:
• The constructor: The constructor is the only function that you must implement. When you «construct» your widget, you give it a name, a description, and you defie what options it has. Its name is often __ construct() , but PHP still accepts the PHP 4 method of naming your constructor function using the name of the class.
• widget() : It displays content to users on the frontend.
• form() : It displays content to manager users on the backend, usually to
allow them to update the widget settings.
• update() : It prepares the updated widget settings for database storage.
Override this function if you require special form validation.
In order to make your widget actually work, you will need to tell WordPress about
it by registering it using the WordPress register_widget() function. If you
want to get a bit more information about the process, have a look at WordPress’
documentation here: http://codex.wordpress.org/Widgets_API.
Haciendo planos con los amigos
Crear la función que guarda y edita los datos en base de datos desde el wp-admin, es decir, con la que pondremos el banner, el link y el título del mismo, y luego desde el frontend home sacará esos datos. En esta función no nos vamos a complicar ahora mismo, primero caparemos el acceso a quien no pueda acceder y luego crearemos el formulario por el cual se accederá a los datos y se modificará si se quiere. Lo hacemos solo con la ruta de la imagen para que no sea excesivamente largo, pero podéis optar por hacerlo del mismo modo para el resto de campos.
Crear la función que guarda y edita los datos en base de datos desde el wp-admin, es decir, con la que pondremos el banner, el link y el título del mismo, y luego desde el frontend home sacará esos datos. En esta función no nos vamos a complicar ahora mismo, primero caparemos el acceso a quien no pueda acceder y luego crearemos el formulario por el cual se accederá a los datos y se modificará si se quiere. Lo hacemos solo con la ruta de la imagen para que no sea excesivamente largo, pero podéis optar por hacerlo del mismo modo para el resto de campos.
Crear la función que guarda y edita los datos en base de datos desde el wp-admin, es decir, con la que pondremos el banner, el link y el título del mismo, y luego desde el frontend home sacará esos datos. En esta función no nos vamos a complicar ahora mismo, primero caparemos el acceso a quien no pueda acceder y luego crearemos el formulario por el cual se accederá a los datos y se modificará si se quiere. Lo hacemos solo con la ruta de la imagen para que no sea excesivamente largo, pero podéis optar por hacerlo del mismo modo para el resto de campos.