PluginProbe
Friends / 4.3.0
Friends v4.3.0
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 4.3.0, at widgets/class-widget-base-friends-list.php

139 lines 3.8 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, $friends ) {
46 $open = true;
47 $widget_id = '';
48 if ( ! empty( $args['widget_id'] ) ) {
49 $widget_id = $args['widget_id'];
50 $open = Frontend::get_widget_open_state( $widget_id );
51 }
52 ?>
53 <details class="accordion" <?php echo esc_attr( $open ); ?> data-id="<?php echo esc_attr( $widget_id ); ?>" data-nonce="<?php echo esc_attr( wp_create_nonce( 'friends_widget_state' ) ); ?>">
54 <summary class="accordion-header">
55 <?php
56 echo $args['before_title'];
57 echo wp_kses(
58 $title,
59 array(
60 'span' => array( 'class' => array() ),
61 'a' => array(
62 'class' => array(),
63 'href' => array(),
64 ),
65 )
66 );
67 echo $args['after_title'];
68 ?>
69 </summary>
70 <ul class="friend-list menu menu-nav">
71 <?php
72 $this->get_list_items( $friends->get_results() );
73 ?>
74 </ul>
75 </details>
76 <?php
77 }
78
79 /**
80 * Gets a section of the list.
81 *
82 * @param array $users The users.
83 */
84 public function get_list_items( $users ) {
85 foreach ( $users as $friend_user ) {
86 if ( $friend_user instanceof Subscription && Subscription::is_folder( $friend_user->get_term_id() ) ) {
87 continue;
88 }
89 if ( Friends::has_required_privileges() ) {
90 if ( $this->friends->frontend->post_format ) {
91 $url = $friend_user->get_local_friends_page_post_format_url( $this->friends->frontend->post_format );
92 } else {
93 $url = $friend_user->get_local_friends_page_url();
94 }
95 } else {
96 $url = $friend_user->user_url;
97 }
98 $display_name = $friend_user->display_name ? $friend_user->display_name : $friend_user->user_login;
99 ?>
100 <li class="menu-item"><a href="<?php echo esc_url( $url ); ?>" style="display: inline-block"><?php echo esc_html( $display_name ); ?></a></li>
101 <?php
102 }
103 }
104
105 /**
106 * Update widget configuration.
107 *
108 * @param array $new_instance New settings.
109 * @param array $old_instance Old settings.
110 * @return array Sanitized instance settings.
111 */
112 public function update( $new_instance, $old_instance ) {
113 $instance = $this->defaults;
114
115 return $instance;
116 }
117
118 /**
119 * Return an associative array of default values
120 *
121 * These values are used in new widgets.
122 *
123 * @return array Array of default values for the Widget's options
124 */
125 public function defaults() {
126 return array(
127 'title' => '',
128 );
129 }
130
131 /**
132 * Register this widget.
133 */
134 public static function register() {
135 register_widget( get_called_class() );
136 }
137 }
138
139