<?php /* Plugin Name: Frase del día Plugin URI: https://es.wikiquote.org/wiki/Portada Description: Muestra una frase del día diferente Author: Jota Peich Version: 1.0 Author URI: http://intelisen.com */ function frase_getFrase() { $upload = wp_upload_dir(); $frases = file($upload['basedir'] . "/frases.txt"); return $frases[rand(0, count($frases) - 1)]; } function frase_ponFrase() { echo frase_getFrase(); } add_action('admin_notices', 'frase_ponFrase'); function frase_filtro($contenido) { return $contenido . "<br/>" . frase_getFrase(); } add_filter("the_content", 'frase_filtro'); class FraseWidget extends WP_Widget { function FraseWidget() { $widget_ops = array('classname' => 'FraseWidget', 'description' => 'Muestra una frase del día'); $this->WP_Widget('FraseWidget', 'Frase del día', $widget_ops); } function form($instance) { $instance = wp_parse_args((array) $instance, array('title' => '')); $title = $instance['title']; ?> <p><label for="<?php echo $this->get_field_id('title'); ?>"><?= _e('Title') ?>: <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo attribute_escape($title); ?>" /></label></p> <?php } function update($new_instance, $old_instance) { $instance = $old_instance; $instance['title'] = $new_instance['title']; return $instance; } function widget($args, $instance) { extract($args, EXTR_SKIP); echo $before_widget; $title = empty($instance['title']) ? ' ' : apply_filters('widget_title', $instance['title']); if (!empty($title)) echo $before_title . $title . $after_title;; echo frase_getFrase(); echo $after_widget; } } add_action('widgets_init', create_function('', 'return register_widget("FraseWidget");'));