PluginProbe
Friends / 2.8.2
Friends v2.8.2
4.3.2 4.3.1 4.3.0 4.2.2 4.2.1 4.2.0 4.1.0 2.7.4 2.7.5 2.7.6 2.7.7 2.7.8 2.7.9 2.8.0 2.8.1 2.8.2 2.8.3 2.8.4 2.8.5 2.8.6 2.8.7 2.8.8 2.8.9 2.9.0 2.9.1 All 88 releases
friends / widgets / class-widget-base-friends-list.php

class-widget-base-friends-list.php in Friends 2.8.2, at widgets/class-widget-base-friends-list.php

149 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Friend List Widget
4 *
5 * A widget that displays a list of your friends.
6 *
7 * @package Friends
8 * @since 0.3
9 */
10
11 namespace Friends;
12
13 /**
14 * This is the class for the Friend List Widget.
15 *
16 * @package Friends
17 * @author Alex Kirk
18 */
19 abstract class Widget_Base_Friends_List extends \WP_Widget {
20 /**
21 * PHP5 constructor.
22 *
23 * @since 2.8.0
24 *
25 * @param string $id_base Optional. Base ID for the widget, lowercase and unique. If left empty,
26 * a portion of the widget's PHP class name will be used. Has to be unique.
27 * @param string $name Name for the widget displayed on the configuration page.
28 * @param array $widget_options Optional. Widget options. See wp_register_sidebar_widget() for
29 * information on accepted arguments. Default empty array.
30 * @param array $control_options Optional. Widget control options. See wp_register_widget_control() for
31 * information on accepted arguments. Default empty array.
32 */
33 public function __construct( $id_base, $name, $widget_options = array(), $control_options = array() ) {
34 parent::__construct( $id_base, $name, $widget_options, $control_options );
35 $this->friends = Friends::get_instance();
36 }
37
38 /**
39 * Render a friend list.
40 *
41 * @param array $args The widget arguments.
42 * @param string $title The list title.
43 * @param \WP_User_Query $friends The friends to list.
44 */
45 public function list_friends( $args, $title, \WP_User_Query $friends ) {
46 ?>
47 <details class="accordion" open>
48 <summary class="accordion-header">
49 <?php
50 echo $args['before_title'];
51 echo wp_kses(
52 $title,
53 array(
54 'span' => array( 'class' => array() ),
55 'a' => array(
56 'class' => array(),
57 'href' => array(),
58 ),
59 )
60 );
61 echo $args['after_title'];
62 ?>
63 </summary>
64 <ul class="friend-list menu menu-nav">
65 <?php
66 $this->get_list_items( $friends->get_results() );
67 ?>
68 </ul>
69 </details>
70 <?php
71 }
72
73 /**
74 * Gets a section of the list.
75 *
76 * @param array $users The users.
77 */
78 public function get_list_items( $users ) {
79 foreach ( $users as $friend_user ) {
80 if ( Friends::has_required_privileges() ) {
81 if ( $this->friends->frontend->post_format ) {
82 $url = $friend_user->get_local_friends_page_post_format_url( $this->friends->frontend->post_format );
83 } else {
84 $url = $friend_user->get_local_friends_page_url();
85 }
86 } else {
87 $url = $friend_user->user_url;
88 }
89 ?>
90 <li class="menu-item"><a href="<?php echo esc_url( $url ); ?>" style="display: inline-block"><?php echo esc_html( $friend_user->display_name ); ?></a>
91 <?php
92 if ( $friend_user->user_url ) {
93 ?>
94 <small class="label label-secondary">
95 <?php
96 $this->friends->frontend->link(
97 $friend_user->user_url,
98 '',
99 array(
100 'class' => 'dashicons dashicons-external',
101 'style' => 'display: inline',
102 ),
103 $friend_user
104 );
105 ?>
106 </small>
107 <?php
108 }
109 ?>
110 </li>
111 <?php
112 }
113 }
114
115 /**
116 * Update widget configuration.
117 *
118 * @param array $new_instance New settings.
119 * @param array $old_instance Old settings.
120 * @return array Sanitized instance settings.
121 */
122 public function update( $new_instance, $old_instance ) {
123 $instance = $this->defaults;
124
125 return $instance;
126 }
127
128 /**
129 * Return an associative array of default values
130 *
131 * These values are used in new widgets.
132 *
133 * @return array Array of default values for the Widget's options
134 */
135 public function defaults() {
136 return array(
137 'title' => '',
138 );
139 }
140
141 /**
142 * Register this widget.
143 */
144 public static function register() {
145 register_widget( get_called_class() );
146 }
147 }
148
149