SlideShare a Scribd company logo
1 of 4
<?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) );
  }
$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).' &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="'.$width.'" height='.$height.' src="'.$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

What's hot

sfDay Cologne - Sonata Admin Bundle
sfDay Cologne - Sonata Admin BundlesfDay Cologne - Sonata Admin Bundle
sfDay Cologne - Sonata Admin Bundle
th0masr
 

What's hot (20)

Goodbye hook_menu() - Routing and Menus in Drupal 8
Goodbye hook_menu() - Routing and Menus in Drupal 8Goodbye hook_menu() - Routing and Menus in Drupal 8
Goodbye hook_menu() - Routing and Menus in Drupal 8
 
Routing in Drupal 8
Routing in Drupal 8Routing in Drupal 8
Routing in Drupal 8
 
Routing in Drupal 8
Routing in Drupal 8Routing in Drupal 8
Routing in Drupal 8
 
sfDay Cologne - Sonata Admin Bundle
sfDay Cologne - Sonata Admin BundlesfDay Cologne - Sonata Admin Bundle
sfDay Cologne - Sonata Admin Bundle
 
logic321
logic321logic321
logic321
 
Nashvile Symfony Routes Presentation
Nashvile Symfony Routes PresentationNashvile Symfony Routes Presentation
Nashvile Symfony Routes Presentation
 
Shortcodes In-Depth
Shortcodes In-DepthShortcodes In-Depth
Shortcodes In-Depth
 
WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3WordPress Theme Design and Development Workshop - Day 3
WordPress Theme Design and Development Workshop - Day 3
 
Андрей Юртаев - Improve theming with (Twitter) Bootstrap
Андрей Юртаев - Improve theming with (Twitter) BootstrapАндрей Юртаев - Improve theming with (Twitter) Bootstrap
Андрей Юртаев - Improve theming with (Twitter) Bootstrap
 
Drupal 8 Routing
Drupal 8 RoutingDrupal 8 Routing
Drupal 8 Routing
 
Componentization css angular
Componentization css angularComponentization css angular
Componentization css angular
 
RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”
 
Views notwithstanding
Views notwithstandingViews notwithstanding
Views notwithstanding
 
Apostrophe
ApostropheApostrophe
Apostrophe
 
Fields in Core: How to create a custom field
Fields in Core: How to create a custom fieldFields in Core: How to create a custom field
Fields in Core: How to create a custom field
 
Wynn Netherland: Accelerating Titanium Development with CoffeeScript, Compass...
Wynn Netherland: Accelerating Titanium Development with CoffeeScript, Compass...Wynn Netherland: Accelerating Titanium Development with CoffeeScript, Compass...
Wynn Netherland: Accelerating Titanium Development with CoffeeScript, Compass...
 
Connecting Custom Post Types
Connecting Custom Post TypesConnecting Custom Post Types
Connecting Custom Post Types
 
Bacbkone js
Bacbkone jsBacbkone js
Bacbkone js
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Daily notes
Daily notesDaily notes
Daily notes
 

Similar to Codigo taller-plugins

前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
Ting Lv
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
smueller_sandsmedia
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
references
 

Similar to Codigo taller-plugins (20)

Virtual Madness @ Etsy
Virtual Madness @ EtsyVirtual Madness @ Etsy
Virtual Madness @ Etsy
 
Building Your First Widget
Building Your First WidgetBuilding Your First Widget
Building Your First Widget
 
Aplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com BackboneAplicacoes dinamicas Rails com Backbone
Aplicacoes dinamicas Rails com Backbone
 
Mashing up JavaScript – Advanced Techniques for modern Web Apps
Mashing up JavaScript – Advanced Techniques for modern Web AppsMashing up JavaScript – Advanced Techniques for modern Web Apps
Mashing up JavaScript – Advanced Techniques for modern Web Apps
 
Javascript in Plone
Javascript in PloneJavascript in Plone
Javascript in Plone
 
Mashing up JavaScript
Mashing up JavaScriptMashing up JavaScript
Mashing up JavaScript
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
 
Beyond Posts & Pages - Structured Content in WordPress
Beyond Posts & Pages - Structured Content in WordPressBeyond Posts & Pages - Structured Content in WordPress
Beyond Posts & Pages - Structured Content in WordPress
 
Symfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technologySymfony2 Building on Alpha / Beta technology
Symfony2 Building on Alpha / Beta technology
 
laravel tricks in 50minutes
laravel tricks in 50minuteslaravel tricks in 50minutes
laravel tricks in 50minutes
 
50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes50 Laravel Tricks in 50 Minutes
50 Laravel Tricks in 50 Minutes
 
jQuery secrets
jQuery secretsjQuery secrets
jQuery secrets
 
前端MVC 豆瓣说
前端MVC 豆瓣说前端MVC 豆瓣说
前端MVC 豆瓣说
 
Hooks WCSD12
Hooks WCSD12Hooks WCSD12
Hooks WCSD12
 
Unit testing with zend framework tek11
Unit testing with zend framework tek11Unit testing with zend framework tek11
Unit testing with zend framework tek11
 
Unit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBeneluxUnit testing with zend framework PHPBenelux
Unit testing with zend framework PHPBenelux
 
WordPress REST API hacking
WordPress REST API hackingWordPress REST API hacking
WordPress REST API hacking
 
HirshHorn theme: how I created it
HirshHorn theme: how I created itHirshHorn theme: how I created it
HirshHorn theme: how I created it
 
international PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secretsinternational PHP2011_Bastian Feder_jQuery's Secrets
international PHP2011_Bastian Feder_jQuery's Secrets
 
Gail villanueva add muscle to your wordpress site
Gail villanueva   add muscle to your wordpress siteGail villanueva   add muscle to your wordpress site
Gail villanueva add muscle to your wordpress site
 

More from Rocío Valdivia

Descubriendo las posibilidades de BuddyPress: Tu red social en WordPress
Descubriendo las posibilidades de BuddyPress: Tu red social en WordPressDescubriendo las posibilidades de BuddyPress: Tu red social en WordPress
Descubriendo las posibilidades de BuddyPress: Tu red social en WordPress
Rocío Valdivia
 

More from Rocío Valdivia (12)

WordCamp Mumbai 2017: How to get more involved with WordPress
WordCamp Mumbai 2017: How to get more involved with WordPressWordCamp Mumbai 2017: How to get more involved with WordPress
WordCamp Mumbai 2017: How to get more involved with WordPress
 
Cómo involucrarte (más) con WordPress - WordCamp Bilbao 2016
Cómo involucrarte (más) con WordPress - WordCamp Bilbao 2016Cómo involucrarte (más) con WordPress - WordCamp Bilbao 2016
Cómo involucrarte (más) con WordPress - WordCamp Bilbao 2016
 
WordCamp Denmark 2016: How to get (more) involved with WordPress
WordCamp Denmark 2016: How to get (more) involved with WordPressWordCamp Denmark 2016: How to get (more) involved with WordPress
WordCamp Denmark 2016: How to get (more) involved with WordPress
 
WordCamp Miami 2016: New and upcoming features - Rocío Valdivia
WordCamp Miami 2016: New and upcoming features - Rocío ValdiviaWordCamp Miami 2016: New and upcoming features - Rocío Valdivia
WordCamp Miami 2016: New and upcoming features - Rocío Valdivia
 
WordCamp Miami 2016: How to contribute to BuddyPress - Rocío Valdivia
WordCamp Miami 2016: How to contribute to BuddyPress - Rocío ValdiviaWordCamp Miami 2016: How to contribute to BuddyPress - Rocío Valdivia
WordCamp Miami 2016: How to contribute to BuddyPress - Rocío Valdivia
 
BuddyCamp Brighton 2015 - Rocío Valdivia - BuddyPress, much more than a plugin!
BuddyCamp Brighton 2015 - Rocío Valdivia - BuddyPress, much more than a plugin!BuddyCamp Brighton 2015 - Rocío Valdivia - BuddyPress, much more than a plugin!
BuddyCamp Brighton 2015 - Rocío Valdivia - BuddyPress, much more than a plugin!
 
WordCamp Barcelona 2015: Newsletters en WordPress con MailPoet
WordCamp Barcelona 2015: Newsletters en WordPress con MailPoetWordCamp Barcelona 2015: Newsletters en WordPress con MailPoet
WordCamp Barcelona 2015: Newsletters en WordPress con MailPoet
 
WordCamp Europe 2014 - How to be a WP freelancer and not die trying
WordCamp Europe 2014 - How to be a WP freelancer and not die tryingWordCamp Europe 2014 - How to be a WP freelancer and not die trying
WordCamp Europe 2014 - How to be a WP freelancer and not die trying
 
WordCamp Sevilla 2013 - Rocío Valdivia - Plugins WordPress Multisite & BuddyP...
WordCamp Sevilla 2013 - Rocío Valdivia - Plugins WordPress Multisite & BuddyP...WordCamp Sevilla 2013 - Rocío Valdivia - Plugins WordPress Multisite & BuddyP...
WordCamp Sevilla 2013 - Rocío Valdivia - Plugins WordPress Multisite & BuddyP...
 
MeetUp Marbella 2013 - BuddyPress. Mucho más que un plugin para WordPress po...
MeetUp Marbella 2013 - BuddyPress. Mucho más que un plugin para WordPress po...MeetUp Marbella 2013 - BuddyPress. Mucho más que un plugin para WordPress po...
MeetUp Marbella 2013 - BuddyPress. Mucho más que un plugin para WordPress po...
 
Descubriendo las posibilidades de BuddyPress: Tu red social en WordPress
Descubriendo las posibilidades de BuddyPress: Tu red social en WordPressDescubriendo las posibilidades de BuddyPress: Tu red social en WordPress
Descubriendo las posibilidades de BuddyPress: Tu red social en WordPress
 
Taller de plugins
Taller de pluginsTaller de plugins
Taller de plugins
 

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="'.$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).' &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="'.$width.'" height='.$height.' src="'.$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'); ?>