ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
<?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) );
  }
$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).' &raquo;"></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');
$width = $options['width'];
           $height = $options['height'];
           $imagepath = $options['imagepath'];

           echo $before_widget;
           if( !empty($options['title']) ):
                       echo $before_title . $options['title'] . $after_title;
           endif;

            echo '<img width=/slideshow/codigo-tallerplugins/6162281/"&$width.'" height='.$height.' src=/slideshow/codigo-tallerplugins/6162281/"&$imagepath.'"
alt="redaccion" />';
            echo $after_widget;
      }

     //Funci??n que contiene el formulario de las opciones del widget
     function wordcampspain_widget_control() {
           $options = $newoptions = get_option('wordcampspain_widget');

            if ( $_POST["wordcampspain_widget_submit"] ) {
                  $newoptions['title'] =
strip_tags(stripslashes($_POST["wordcampspain_widget_title"]));
                  $newoptions['width'] =
strip_tags(stripslashes($_POST["wordcampspain_widget_width"]));
                  $newoptions['height'] =
strip_tags(stripslashes($_POST["wordcampspain_widget_height"]));
                  $newoptions['imagepath'] =
strip_tags(stripslashes($_POST["wordcampspain_widget_imagepath"]));
            }

           if ( $options != $newoptions ) {
                 $options = $newoptions;
                 update_option('wordcampspain_widget', $options);
           }

            $title = attribute_escape($options['title']);
            $width = attribute_escape($options['width']);
            $height = attribute_escape($options['height']);
            $imagepath = attribute_escape($options['imagepath']);
            ?>
                  <p><label for="wordcampspain_widget_title"><?php _e('Title:'); ?>
<input class="widefat" id="wordcampspain_widget_title"
name="wordcampspain_widget_title" type="text" value="<?php echo $title; ?>"
/></label></p>
                  <p><label for="wordcampspain_widget_width"><?php _e('Width:'); ?>
<input class="widefat" id="wordcampspain_widget_width"
name="wordcampspain_widget_width" type="text" value="<?php echo $width; ?>"
/></label></p>
                  <p><label for="wordcampspain_widget_height"><?php
_e('Height:'); ?> <input class="widefat" id="wordcampspain_widget_height"
name="wordcampspain_widget_height" type="text" value="<?php echo $height; ?>"
/></label></p>
                  <p><label for="wordcampspain_widget_imagepath"><?php _e('Image
path:'); ?> <input class="widefat" id="wordcampspain_widget_imagepath"
name="wordcampspain_widget_imagepath" type="text" value="<?php echo $imagepath; ?>"
/></label></p>
                  <input type="hidden" id="wordcampspain_widget_submit"
name="wordcampspain_widget_submit" value="1" />
            <?php
}

     //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');
?>

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).' &raquo;"></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');
  • 3. $width = $options['width']; $height = $options['height']; $imagepath = $options['imagepath']; echo $before_widget; if( !empty($options['title']) ): echo $before_title . $options['title'] . $after_title; endif; echo '<img width=/slideshow/codigo-tallerplugins/6162281/"&$width.'" height='.$height.' src=/slideshow/codigo-tallerplugins/6162281/"&$imagepath.'" alt="redaccion" />'; echo $after_widget; } //Funci??n que contiene el formulario de las opciones del widget function wordcampspain_widget_control() { $options = $newoptions = get_option('wordcampspain_widget'); if ( $_POST["wordcampspain_widget_submit"] ) { $newoptions['title'] = strip_tags(stripslashes($_POST["wordcampspain_widget_title"])); $newoptions['width'] = strip_tags(stripslashes($_POST["wordcampspain_widget_width"])); $newoptions['height'] = strip_tags(stripslashes($_POST["wordcampspain_widget_height"])); $newoptions['imagepath'] = strip_tags(stripslashes($_POST["wordcampspain_widget_imagepath"])); } if ( $options != $newoptions ) { $options = $newoptions; update_option('wordcampspain_widget', $options); } $title = attribute_escape($options['title']); $width = attribute_escape($options['width']); $height = attribute_escape($options['height']); $imagepath = attribute_escape($options['imagepath']); ?> <p><label for="wordcampspain_widget_title"><?php _e('Title:'); ?> <input class="widefat" id="wordcampspain_widget_title" name="wordcampspain_widget_title" type="text" value="<?php echo $title; ?>" /></label></p> <p><label for="wordcampspain_widget_width"><?php _e('Width:'); ?> <input class="widefat" id="wordcampspain_widget_width" name="wordcampspain_widget_width" type="text" value="<?php echo $width; ?>" /></label></p> <p><label for="wordcampspain_widget_height"><?php _e('Height:'); ?> <input class="widefat" id="wordcampspain_widget_height" name="wordcampspain_widget_height" type="text" value="<?php echo $height; ?>" /></label></p> <p><label for="wordcampspain_widget_imagepath"><?php _e('Image path:'); ?> <input class="widefat" id="wordcampspain_widget_imagepath" name="wordcampspain_widget_imagepath" type="text" value="<?php echo $imagepath; ?>" /></label></p> <input type="hidden" id="wordcampspain_widget_submit" name="wordcampspain_widget_submit" value="1" /> <?php
  • 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'); ?>