How to create a Wordpress plugin | Adrenalina

How to create a WordPress plugin

Publicado Por | 28 marzo , 2013 | Blog Adrenalina En, Technical SEO | No Comments

Ever since a while ago, WordPress has been becoming one of the most used CMS to publish content, develop small projects and testing of large projects which, before investing a lot in tech, they decide to carry a first test with a WordPress system and with its easiness to optimize SEO thanks to its SEO plugins

One of the successful things about WordPress is the great community behind it working to improve it by developing widgets, themes or plugins which generall are available as free downloads.

I’ll talk about the basics to create a WordPress plugin.

First things first is the idea, the hardest part in most of the cases since the plugin you’re aiming for already exists or ther’es a very similiar one: but you can always have a bright idea of need a specific requsite for your business which probably hasn’t been stumbled upon by another business or persons.

Once we’ve detected the need and having clear the goal we want our plugin to achieve we can start to work.

The first step is create a folder with the name of our plugin inside of the folder wp-content/plugins/plugin-name/ and inside of this folder a php file with the name of our plugin.

We’ll open this file and we’ll begin by inputting the plugin the data: this data will be interpreted by WordPress as plugin info. Here’s a sample:

/*
Plugin Name: name of the WordPress plugin.
Description: WordPress plugin description.
Author: Eduard Oliva
Version: 1.0
Author URL: http://www.adrenlaina.es/
*/

Now we can begin to work in the functions.

To begin with: if what we wish is to include a new menu option in our wordpress with different submenus then what we gotta do is…

// We build the menu-creation action
add_action('admin_menu', 'menu');
// We create the menu with a submenu using add_menu_page & add_submenu_page
function menu()
{
$blogs_menu_main = add_menu_page('Config', 'Menu', 'administrator', 'slug_menu', 'function_first_menu_option');
$blogs_external_menu = add_submenu_page('slug_menu', 'Submenu', 'Submenu', 'administrator', 'slug_second_menu_option', 'function_second_menu_option');
}
// We define the php files which will be shown when pressing the menu options
function function_first_menu_option()
{
require ('first_menu_option.php');
}
function function_second_menu_option()
{
require ('second_menu_option.php');
}

Now we have the choice of developing code inside of these menu options to manage, say, the database.

Another very useful option is the contents’ zone management where we might create a new box encompassing the pages or posts we’re requested to or that show additional information.

// We create the box-creation action
add_action('add_meta_boxes', 'box_1');
// With add_meta_box we create the box in the desired place.
function box_1($postType)
{
add_meta_box('box_1_id', 'Name Box', 'function_box_1', 'post', 'side', 'high');
}
// We define the php files which will be shown inside of the defined meta box.
function function_box_1()
{
echo "Box's contents";
}

If our plugin needs a js (java script) then we do this:

function our_scripts()
{
$wp_wall_plugin_url = trailingslashit(get_bloginfo('wpurl')) . PLUGINDIR . '/plugin-name/our-plugin.js';
wp_enqueue_script('my_awesome_script', $wp_wall_plugin_url, array('jquery'));
}
add_action('wp_print_scripts', 'our_scripts');

Our plugin may need to intercept events like post publishing

add_action('publish_post', 'publication_event');
function publication_event($post_id)
{
// What our WordPress would do when storing a post
}

During the plugin development we’ll find something very useful: some actions can only be done by users having special permits, something settled using current_user_can

if (current_user_can('administrator')){
// It'll only affect "admin" permit users
}

I hope that this simple guide is useful and saves up time to you guys when you start the first tests and create a WordPress plugin. If you need help to develop plugins or need some iPad app development services o link-building, then don’t hesitate on contacting us.

Autor: Eduard Oliva

Apasionado por el eCommerce, Negocios en Internet, SEM, SEO, Analítica, Usabilidad, APIs y Redes Sociales. CTO y Fundador en Adrenalina.es

Estudiamos y analizamos su negocio en profundidad, definimos objetivos y planteamos la estrategia de marketing más adecuada centrándonos en conseguir cada uno de los objetivos propuestos. Solicita Presupuesto Ahora

Uso de cookies

En este sitio web utilizamos cookies propias y de terceros para mejorar nuestros servicios, para que usted tenga la mejor experiencia de usuario y analizar su visita. Si continúa navegando está dando su consentimiento para la aceptación de las mencionadas cookies y la aceptación de nuestra política de cookies, pinche el enlace para mayor información.