Form.php
11 months ago
Init.php
5 years ago
TabbedWidget.php
4 years ago
TabbedWidgetDependency.php
1 year ago
UserPanel.php
2 years ago
index.php
5 years ago
UserPanel.php
116 lines
| 1 | <?php |
| 2 | |
| 3 | namespace ProfilePress\Core\Widgets; |
| 4 | |
| 5 | class UserPanel extends \WP_Widget |
| 6 | { |
| 7 | public function __construct() |
| 8 | { |
| 9 | parent::__construct( |
| 10 | 'pp_user_panel_widget', |
| 11 | esc_html__('ProfilePress User Panel', 'wp-user-avatar'), |
| 12 | array( |
| 13 | 'description' => esc_html__('Display currently logged in user\'s avatar and links to logout and edit the profile.', 'wp-user-avatar'), |
| 14 | ), |
| 15 | array('width' => 400, 'height' => 350)// Args |
| 16 | ); |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Display Widget. |
| 21 | * |
| 22 | * @param array $args |
| 23 | * @param array $instance |
| 24 | */ |
| 25 | public function widget($args, $instance) |
| 26 | { |
| 27 | if ( ! is_user_logged_in()) return; |
| 28 | |
| 29 | $edit_profile_label = ! empty($instance['edit_profile_label']) ? sanitize_text_field($instance['edit_profile_label']) : esc_html__('Edit your Profile', 'wp-user-avatar'); |
| 30 | $logout_label = ! empty($instance['logout_label']) ? sanitize_text_field($instance['logout_label']) : esc_html__('Log Out', 'wp-user-avatar'); |
| 31 | |
| 32 | echo $args['before_widget']; |
| 33 | |
| 34 | $user_data = wp_get_current_user(); |
| 35 | ?> |
| 36 | |
| 37 | <div class="pp-user-panel"> |
| 38 | <?php |
| 39 | do_action('ppress_before_user_panel_widget'); |
| 40 | |
| 41 | if (empty($instance['remove_avatar']) || $instance['remove_avatar'] != 'on') { |
| 42 | echo '<a href="' . ppress_profile_url() . '">'; |
| 43 | echo '<div class="pp-tab-widget-avatar">'; |
| 44 | echo get_avatar($user_data->ID, 500); |
| 45 | echo '</div>'; |
| 46 | echo '</a>'; |
| 47 | } |
| 48 | ?> |
| 49 | <h3 class="pp-user-panel-title"> |
| 50 | <?php printf(__('Welcome %s', 'wp-user-avatar'), ucfirst($user_data->display_name)); ?> |
| 51 | </h3> |
| 52 | <br/> |
| 53 | <p> |
| 54 | <a class="pp-tabbed-btn pp-tabbed-btn-inverse" href="<?php echo ppress_edit_profile_url(); ?>"><?= $edit_profile_label ?></a> |
| 55 | </p> |
| 56 | <p> |
| 57 | <a class="pp-tabbed-btn pp-tabbed-btn-inverse" href="<?php echo wp_logout_url(); ?>"><?= $logout_label ?></a> |
| 58 | </p> |
| 59 | <?php do_action('ppress_after_user_panel_widget'); ?> |
| 60 | </div> |
| 61 | <?php |
| 62 | echo $args['after_widget']; |
| 63 | } |
| 64 | |
| 65 | |
| 66 | public function form($instance) |
| 67 | { |
| 68 | $title = ! empty($instance['title']) ? sanitize_text_field($instance['title']) : esc_html__('User Panel', 'wp-user-avatar'); |
| 69 | $remove_avatar = ! empty($instance['remove_avatar']) ? sanitize_text_field($instance['remove_avatar']) : ''; |
| 70 | $edit_profile_label = ! empty($instance['edit_profile_label']) ? sanitize_text_field($instance['edit_profile_label']) : esc_html__('Edit your Profile', 'wp-user-avatar'); |
| 71 | $logout_label = ! empty($instance['logout_label']) ? sanitize_text_field($instance['logout_label']) : esc_html__('Log Out', 'wp-user-avatar'); |
| 72 | ?> |
| 73 | <p> |
| 74 | <label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></label> |
| 75 | <input class="widefat" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" type="text" value="<?php echo esc_attr($title); ?>"> |
| 76 | </p> |
| 77 | |
| 78 | <p> |
| 79 | <input class="widefat" id="<?php echo $this->get_field_id('remove_avatar'); ?>" name="<?php echo $this->get_field_name('remove_avatar'); ?>" type="checkbox" value="on" <?php checked($remove_avatar, 'on'); ?>> |
| 80 | <label for="<?php echo $this->get_field_id('remove_avatar'); ?>"><?php _e('Check to remove user profile picture from panel.'); ?></label> |
| 81 | </p> |
| 82 | |
| 83 | <p> |
| 84 | <label for="<?php echo $this->get_field_id('edit_profile_label'); ?>"><?php _e('Label for "edit profile" link:'); ?></label> |
| 85 | <input class="widefat" id="<?php echo $this->get_field_id('edit_profile_label'); ?>" name="<?php echo $this->get_field_name('edit_profile_label'); ?>" type="text" value="<?php echo esc_attr($edit_profile_label); ?>"> |
| 86 | </p> |
| 87 | |
| 88 | <p> |
| 89 | <label for="<?php echo $this->get_field_id('logout_label'); ?>"><?php _e('Label for logout link:'); ?></label> |
| 90 | <input class="widefat" id="<?php echo $this->get_field_id('logout_label'); ?>" name="<?php echo $this->get_field_name('logout_label'); ?>" type="text" value="<?php echo esc_attr($logout_label); ?>"> |
| 91 | </p> |
| 92 | |
| 93 | <?php |
| 94 | } |
| 95 | |
| 96 | /** |
| 97 | * Sanitize widget form values as they are saved. |
| 98 | * |
| 99 | * @param array $new_instance Values just sent to be saved. |
| 100 | * @param array $old_instance Previously saved values from database. |
| 101 | * |
| 102 | * @return array Updated safe values to be saved. |
| 103 | * @see WP_Widget::update() |
| 104 | * |
| 105 | */ |
| 106 | public function update($new_instance, $old_instance) |
| 107 | { |
| 108 | $instance = array(); |
| 109 | $instance['title'] = ( ! empty($new_instance['title'])) ? strip_tags($new_instance['title']) : ''; |
| 110 | $instance['remove_avatar'] = ( ! empty($new_instance['remove_avatar'])) ? strip_tags($new_instance['remove_avatar']) : ''; |
| 111 | $instance['edit_profile_label'] = ( ! empty($new_instance['edit_profile_label'])) ? strip_tags($new_instance['edit_profile_label']) : ''; |
| 112 | $instance['logout_label'] = ( ! empty($new_instance['logout_label'])) ? strip_tags($new_instance['logout_label']) : ''; |
| 113 | |
| 114 | return $instance; |
| 115 | } |
| 116 | } |