Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
WordPress Plugin: T5 Log In Form Widget
<?php # -*- coding: utf-8 -*-
/**
* Plugin Name: T5 Log in form widget
* Plugin URI: https://gist.github.com/toscho/c7459ee439fd2491c1f6
* Description: Shows a log in form in a widget.
* Version: 13.10.15
* Required: 4.0
* Author: Thomas Scholz <info@toscho.de>
* Author URI: http://toscho.de
* License: MIT
* License URI: http://www.opensource.org/licenses/mit-license.php
*/
class T5_Login_Form_Widget extends WP_Widget {
/**
* Constructor
*/
public function __construct()
{
parent::__construct( strtolower( __CLASS__ ), __( 'Log In' ) );
}
/**
* Outputs the settings update form.
*
* @since 2.8.0
* @access public
*
* @param array $instance Current settings.
* @return string Default return is 'noform'.
*/
public function form( $instance )
{
$instance = wp_parse_args( $instance, array( 'title' => '' ) );
print $this->get_title( $instance[ 'title' ] );
return '';
}
/**
* @param string $title
*
* @return string
*/
private function get_title( $title )
{
$title = esc_attr( $title );
$field_id = $this->get_field_id( 'title' );
$name = $this->get_field_name( 'title' );
$label = __( 'Title:' );
return "<p>
<label for='$field_id'>$label
<input class='widefat' id='$field_id' name='$name' value='$title' type='text'>
</label>
</p>";
}
/**
* @param array $new_instance New settings for this instance as input by the user via
* WP_Widget::form().
* @param array $old_instance Old settings for this instance.
* @return array Settings to save or bool false to cancel saving.
*/
public function update( $new_instance, $old_instance )
{
$new_instance[ 'title' ] = esc_attr( $new_instance[ 'title' ] );
return $new_instance;
}
/**
* Echoes the widget content.
*
* @param array $args Display arguments including 'before_title', 'after_title',
* 'before_widget', and 'after_widget'.
* @param array $instance The settings for the particular instance of the widget.
*/
public function widget( $args, $instance )
{
$title = '';
if ( ! empty ( $instance['title' ] ) )
$title = $args['before_title'] . $instance['title'] . $args['after_title'];
print $args['before_widget'] . $title;
wp_login_form();
print $args['after_widget'];
}
/**
* @wp-hook widgets_init
* @return void
*/
public static function register()
{
register_widget( __CLASS__ );
}
}
add_action( 'widgets_init', array ( 'T5_Login_Form_Widget', 'register' ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.