PluginProbe
Friends / 4.3.2
Friends v4.3.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-post-formats.php

class-widget-post-formats.php in Friends 4.3.2, at widgets/class-widget-post-formats.php

160 lines 5.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Friends Header Widget
4 *
5 * A widget that allows you to show post formats lins on the friends sidebar.
6 *
7 * @package Friends
8 * @since 1.0
9 */
10
11 namespace Friends;
12
13 /**
14 * This is the class for the Friends Post Formats Widget.
15 *
16 * @package Friends
17 * @author Alex Kirk
18 */
19 class Widget_Post_Formats extends \WP_Widget {
20 /**
21 * Constructor
22 */
23 public function __construct() {
24 parent::__construct(
25 'friends-widget-post-formats',
26 __( 'Post Formats', 'friends' ),
27 array(
28 'description' => __( 'Show post formats in the sidebar.', '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 $friends = Friends::get_instance();
42
43 echo wp_kses( $args['before_widget'], 'post' );
44 $open = true;
45 $widget_id = '';
46 if ( ! empty( $args['widget_id'] ) ) {
47 $widget_id = $args['widget_id'];
48 $open = Frontend::get_widget_open_state( $widget_id );
49 }
50 ?>
51 <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' ) ); ?>">
52 <summary class="accordion-header">
53 <?php
54 if ( ! empty( $instance['title'] ) ) {
55 echo wp_kses( $args['before_title'] . '<span class="dashicons dashicons-filter"></span> ' . $instance['title'] . $args['after_title'], 'post' );
56 }
57 ?>
58 </summary>
59 <ul class="friends-post-formats menu menu-nav accordion-body">
60 <li class="menu-item"><a href="<?php echo esc_attr( home_url( '/friends/' ) ); ?>"><?php _ex( 'All', 'all posts', 'friends' ); ?></a></li>
61 <?php
62 foreach ( get_post_format_strings() as $slug => $title ) :
63
64 if ( ! isset( $instance[ 'show_post_format_' . $slug ] ) || ! $instance[ 'show_post_format_' . $slug ] ) {
65 continue;
66 }
67 if ( ! isset( $instance[ 'post_format_title_' . $slug ] ) ) {
68 $instance[ 'post_format_title_' . $slug ] = $title;
69 }
70 ?>
71 <li class="menu-item"><a href="<?php echo esc_attr( home_url( '/friends/type/' . $slug . '/' ) ); ?>"> <?php echo esc_attr( $instance[ 'post_format_title_' . $slug ] ); ?></a></li>
72 <?php endforeach; ?>
73 </ul>
74 </details>
75 <?php
76
77 echo wp_kses( $args['after_widget'], 'post' );
78 }
79
80 /**
81 * Widget configuration form.
82 *
83 * @param array $instance The current settings.
84 */
85 public function form( $instance ) {
86 $instance = array_merge( $this->defaults(), $instance );
87 ?>
88 <p>
89 <label><?php /* phpcs:ignore WordPress.WP.I18n.MissingArgDomain */ esc_html_e( 'Title' ); ?><br/>
90 <input class="widefat" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo esc_attr( $instance['title'] ); ?>" />
91 </label>
92 </p>
93 <p><?php esc_html_e( 'Show Post Format Links:', 'friends' ); ?>
94 <ul>
95 <?php
96 foreach ( get_post_format_strings() as $slug => $title ) :
97 if ( ! isset( $instance[ 'post_format_title_' . $slug ] ) ) {
98 $instance[ 'post_format_title_' . $slug ] = $title;
99 }
100 ?>
101 <li><label><input id="<?php echo esc_attr( $this->get_field_id( 'show_post_format_' . $slug ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'show_post_format_' . $slug ) ); ?>" type="checkbox" value="1"<?php checked( isset( $instance[ 'show_post_format_' . $slug ] ) && $instance[ 'show_post_format_' . $slug ] ); ?> /> <?php echo esc_html( $title ); ?></label><br/>
102 <input id="<?php echo esc_attr( $this->get_field_id( 'post_format_title_' . $slug ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'post_format_title_' . $slug ) ); ?>" type="text" value="<?php echo esc_attr( $instance[ 'post_format_title_' . $slug ] ); ?>" placeholder="<?php echo esc_attr( $title ); ?>" /></li>
103 <?php endforeach; ?>
104 </ul></p>
105 <?php
106 }
107
108 /**
109 * Update widget configuration.
110 *
111 * @param array $new_instance New settings.
112 * @param array $old_instance Old settings.
113 * @return array Sanitized instance settings.
114 */
115 public function update( $new_instance, $old_instance ) {
116 $instance = array();
117 $instance['title'] = ( ! empty( $new_instance['title'] ) ) ? wp_strip_all_tags( $new_instance['title'] ) : '';
118 $instance['title'] = apply_filters( 'wptexturize', $instance['title'] );
119 $instance['title'] = apply_filters( 'convert_chars', $instance['title'] );
120
121 foreach ( get_post_format_strings() as $slug => $title ) {
122 $instance[ 'post_format_title_' . $slug ] = ( ! empty( $new_instance[ 'post_format_title_' . $slug ] ) ) ? wp_strip_all_tags( $new_instance[ 'post_format_title_' . $slug ] ) : $title;
123 if ( $new_instance[ 'show_post_format_' . $slug ] ) {
124 $instance[ 'show_post_format_' . $slug ] = true;
125 } else {
126 $instance[ 'show_post_format_' . $slug ] = false;
127 }
128 }
129 return $instance;
130 }
131
132 /**
133 * Return an associative array of default values
134 *
135 * These values are used in new widgets.
136 *
137 * @return array Array of default values for the Widget's options
138 */
139 public function defaults() {
140 $instance = array(
141 'title' => __( 'Filter', 'friends' ),
142 );
143
144 foreach ( get_post_format_strings() as $slug => $title ) {
145 $t = 'post_format_title_' . $slug;
146 $instance[ $t ] = ( ! empty( $new_instance[ $t ] ) ) ? wp_strip_all_tags( $new_instance[ $t ] ) : $title;
147 $instance[ 'show_post_format_' . $slug ] = in_array( $slug, array( 'standard', 'status', 'image', 'video' ) );
148 }
149
150 return $instance;
151 }
152
153 /**
154 * Register this widget.
155 */
156 public static function register() {
157 register_widget( __CLASS__ );
158 }
159 }
160