This PHP document defines functions for a WordCamp Spain plugin. It includes functions to add an image to post content, create an options page for configuring the image settings, and register a widget to display the image. The options page and widget allow configuring the image path, width, and height. The plugin filters post content and registers a widget to display the configured image.
1 of 4
More Related Content
Codigo taller-plugins
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=/slideshow/codigo-tallerplugins/6162281/"&$width.'" height='.$height.' src=/slideshow/codigo-tallerplugins/6162281/"&
$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=/slideshow/codigo-tallerplugins/6162281/"&
$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=/slideshow/codigo-tallerplugins/6162281/"&$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=/slideshow/codigo-tallerplugins/6162281/"&$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=/slideshow/codigo-tallerplugins/6162281/"&__('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');
?>