1. <?php
/*
Plugin Name: WordCamp Spain
Plugin URI: http://mecus.es
Description: Esto es una prueba
Author: Rocio Valdivia
Version: 0.1
Author URI: http://dorsvenabili.com
*/
//Función para mostrar una imagen al final del contenido de nuestros posts
function funcion_prueba($content) {
$options = get_option('wordcampspain_options');
//Le damos valores por defecto a los tres campos, en caso de no haber
rellenado alguno en la página de opciones
if($options['width'] != ''){
$width = $options['width'];
}else{
$width = 580;
}
if($options['height'] != ''){
$height = $options['height'];
}else{
$height = 250;
}
if($options['imagepath'] != ''){
$imagepath = $options['imagepath'];
}else{
$imagepath = 'http://prueba.com/wcspain2010voy.jpg';
}
//Mostramos la imagen con la ruta, alto y ancho seleccionados
return $content.'<img width="'.$width.'" height='.$height.' src="'.
$imagepath.'" alt="redaccion" />';
}
//Nuestra función se ejecutará modificando el valor de the_content() -> Gancho
tipo filter.
add_filter('the_content', 'funcion_prueba');
//Función para crear nuestra página de opciones
function wordcampspain_menu() {
add_options_page(__('WordCamp Spain Options',wordcampspain), __('WordCamp
Spain',wordcampspain), 'manage_options', 'wordcampspain', 'wordcampspain_options');
}
//Función que contiene el formulario de las opciones de nuestra página de
opciones
function wordcampspain_options() {
if (!current_user_can('manage_options')) {
wp_die( __('You do not have sufficient permissions to access this
page.',wordcampspain) );
}
2. $options = $newoptions = get_option('wordcampspain_options');
// if submitted, process results
if ( $_POST["wordcampspain_submit"] ) {
$newoptions['imagepath'] =
strip_tags(stripslashes($_POST["imagepath"]));
$newoptions['width'] = strip_tags(stripslashes($_POST["width"]));
$newoptions['height'] = strip_tags(stripslashes($_POST["height"]));
}
// any changes? save!
if ( $options != $newoptions ) {
$options = $newoptions;
update_option('wordcampspain_options', $options);
}
echo '<form method="post">';
echo "<div class="wrap"><h2>".__('My plugin
options',wordcampspain)."</h2>";
echo '<table class="form-table">';
//image
echo '<tr valign="top"><th scope="row">'.__('Image
path',wordcampspain).'</th>';
echo '<td><input type="text" name="imagepath" value="'.
$options['imagepath'].'" size="100"></input><br />'.__('Type the image path that
you want to show',wordcampspain).'</td></tr>';
// width
echo '<tr valign="top"><th scope="row">'.__('Width',wordcampspain).'</th>';
echo '<td><input type="text" name="width" value="'.$options['width'].'"
size="5"></input><br />'.__('Width in pixels',wordcampspain).'</td></tr>';
// height
echo '<tr valign="top"><th scope="row">Height</th>';
echo '<td><input type="text" name="height" value="'.$options['height'].'"
size="5"></input><br />'.__('Height in pixels',wordcampspain).'</td></tr>';
// close stuff
echo '<input type="hidden" name="wordcampspain_submit"
value="true"></input>';
echo '</table>';
echo '<p class="submit"><input type="submit" value="'.__('Update
Options',wordcampspain).' »"></input></p>';
echo "</div>";
echo '</form>';
}
//Nuestra función se ejecutará cada vez que se ejecute el gancho admin_menu ->
Gancho tipo action.
add_action('admin_menu', 'wordcampspain_menu');
//Widget
function widget_init_wordcampspain_widget() {
// Check for required functions
if (!function_exists('register_sidebar_widget'))
return;
//Función que mostrará nuestro widget
function wordcampspain_widget($args){
extract($args);
$options = get_option('wordcampspain_widget');
4. }
//Registramos nuestro widget
register_sidebar_widget( "WordCampSpain", wordcampspain_widget );
register_widget_control( "WordCampSpain", "wordcampspain_widget_control" );
}
//Nuestra función se ejecutará cada vez que se ejecute el gancho widgets_init ->
Gancho tipo action.
add_action('widgets_init', 'widget_init_wordcampspain_widget');
?>