| 1 |
<?php |
| 2 |
/** |
| 3 |
* Friend Posts Refresh |
| 4 |
* |
| 5 |
* A widget that allows you to refresh your friend posts. |
| 6 |
* |
| 7 |
* @package Friends |
| 8 |
* @since 0.3 |
| 9 |
*/ |
| 10 |
|
| 11 |
namespace Friends; |
| 12 |
|
| 13 |
/** |
| 14 |
* This is the class for the Friend Posts Refresh Widget. |
| 15 |
* |
| 16 |
* @package Friends |
| 17 |
* @author Alex Kirk |
| 18 |
*/ |
| 19 |
class Widget_Refresh extends \WP_Widget { |
| 20 |
/** |
| 21 |
* Constructor |
| 22 |
*/ |
| 23 |
public function __construct() { |
| 24 |
parent::__construct( |
| 25 |
'friends-widget-refresh', |
| 26 |
__( 'Friend Posts Refresh', 'friends' ), |
| 27 |
array( |
| 28 |
'description' => __( "Shows a refresh link to refetch your friends' posts.", 'friends' ), |
| 29 |
) |
| 30 |
); |
| 31 |
} |
| 32 |
|
| 33 |
/** |
| 34 |
* Render the widget. |
| 35 |
* |
| 36 |
* @param array $args Sidebar arguments. |
| 37 |
* @param array $instance Widget instance settings. |
| 38 |
*/ |
| 39 |
public function widget( $args, $instance ) { |
| 40 |
$instance = wp_parse_args( $instance, $this->defaults() ); |
| 41 |
|
| 42 |
$title = apply_filters( 'widget_title', $instance['title'] ); |
| 43 |
echo $args['before_widget']; |
| 44 |
if ( ! empty( $title ) ) { |
| 45 |
echo $args['before_title'] . $title . $args['after_title']; |
| 46 |
} |
| 47 |
|
| 48 |
echo '<h5><span class="dashicons dashicons-update"></span> <a href="' . esc_url( home_url( '/friends/?refresh' ) ) . '">' . esc_html__( 'Refresh', 'friends' ) . '</a></h5>'; |
| 49 |
|
| 50 |
echo $args['after_widget']; |
| 51 |
} |
| 52 |
|
| 53 |
|
| 54 |
/** |
| 55 |
* Update widget configuration. |
| 56 |
* |
| 57 |
* @param array $new_instance New settings. |
| 58 |
* @param array $old_instance Old settings. |
| 59 |
* @return array Sanitized instance settings. |
| 60 |
*/ |
| 61 |
public function update( $new_instance, $old_instance ) { |
| 62 |
$instance = $this->defaults(); |
| 63 |
|
| 64 |
return $instance; |
| 65 |
} |
| 66 |
|
| 67 |
/** |
| 68 |
* Return an associative array of default values |
| 69 |
* |
| 70 |
* These values are used in new widgets. |
| 71 |
* |
| 72 |
* @return array Array of default values for the Widget's options |
| 73 |
*/ |
| 74 |
public function defaults() { |
| 75 |
return array( |
| 76 |
'title' => '', |
| 77 |
); |
| 78 |
} |
| 79 |
|
| 80 |
/** |
| 81 |
* Register this widget. |
| 82 |
*/ |
| 83 |
public static function register() { |
| 84 |
register_widget( __CLASS__ ); |
| 85 |
} |
| 86 |
} |
| 87 |
|