Completed
Push — add/about-me-widget ( 6c3edc )
by
unknown
15:04
created

Aboutme_Widget   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 157
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 157
rs 10
c 0
b 0
f 0
wmc 10
lcom 0
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
B widget() 0 26 3
B form() 0 106 6
1
<?php
2
/**
3
 * [DEPRECATION]: This widget was deprecated on 2016-07-01.
4
 */
5
6
/**
7
 * Adds Aboutme_Widget widget.
8
 */
9
class Aboutme_Widget extends WP_Widget {
10
	/**
11
	 * Register widget with WordPress.
12
	 */
13
	public function __construct() {
14
		$widget_ops = array(
15
			'classname'   => 'aboutme_widget',
16
			'description' => __( 'Display your about.me profile with thumbnail', 'jetpack' )
17
		);
18
		parent::__construct( 'aboutme_widget', __( 'About.me Widget', 'jetpack' ), $widget_ops );
19
	}
20
21
	/**
22
	 * Front-end display of widget.
23
	 *
24
	 * @param array $args Widget arguments.
25
	 * @param array $instance Saved values from database.
26
	 */
27
	public function widget( $args, $instance ) {
28
		// [DEPRECATION]: Since we are after the dep. date show admins
29
		// the warning message, otherwise just display a link to their
30
		// about.me page
31
		if ( current_user_can( 'edit_theme_options' ) ) {
32
			?>
33
			<h2>
34
				<?php printf( wp_kses( __(
35
					'The about.me widget is no longer available. To remove this widget, ' .
36
					'<a href="%s">visit your settings</a>. This message is not shown to visitors to your site.',
37
					'jetpack' ),
38
					array( 'a' => array( 'href' => array() ) ) ), admin_url( 'widgets.php' )
39
				); ?>
40
			</h2>
41
			<?php
42
		}
43
		if ( ! empty( $data['profile_url'] ) ) {
0 ignored issues
show
Bug introduced by
The variable $data seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
44
			?>
45
			<h2>
46
				<a href="<?php echo esc_url( $data['profile_url'] ) ?>" target="_blank" rel="me">
47
					<?php echo esc_html( $data['profile_url'] ) ?>
48
				</a>
49
			</h2>
50
			<?php
51
		}
52
	}
53
54
	/**
55
	 * Back-end widget form.
56
	 *
57
	 * @param array $instance Previously saved values from database.
58
	 */
59
	public function form( $instance ) {
60
		$instance  = wp_parse_args( ( array ) $instance, array(
61
			'title'     => 'about.me',
62
			'fontsize'  => 'large',
63
			'photo'     => 'background',
64
			'client_id' => '',
65
			'error'     => 0,
66
			'debug_url' => '',
67
			'src_url'   => str_ireplace( array(
68
				'https://',
69
				'http://'
70
			), '', get_site_url() ),
71
			'username'  => '',
72
			'headline'  => '1',
73
			'biography' => 1,
74
			'apps'      => 1,
75
			'links'     => 1
76
		) );
77
		$title     = $instance['title'];
78
		$fontsize  = $instance['fontsize'];
79
		$photo     = 'no-photo' === $instance['photo'] ? 'no-photo' : 'background';
80
		$username  = array_key_exists( 'username', $instance ) ? $instance['username'] : '';
81
		$headline  = array_key_exists( 'headline', $instance ) ? $instance['headline'] : '1';
82
		$biography = array_key_exists( 'biography', $instance ) ? $instance['biography'] : '1';
83
		$apps      = array_key_exists( 'apps', $instance ) ? $instance['apps'] : '1';
84
85
		?>
86
		<p>
87
			<strong style="color: #ff6347;">
88
				<?php _e( 'The about.me widget will no longer be available after July 1, 2016. ' .
89
				          'After this date, the widget will display a simple text link to your about.me profile. ' .
90
				          'Please remove this widget.', 'jetpack' );
91
				?>
92
			</strong>
93
		</p>
94
		<p>
95
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Widget title', 'jetpack' ); ?>
96
				:</label>
97
			<input id="<?php echo $this->get_field_id( 'title' ); ?>"
98
			       name="<?php echo $this->get_field_name( 'title' ); ?>" type="text"
99
			       value="<?php echo esc_attr( $title ); ?>"/>
100
		</p>
101
		<p>
102
			<label for="<?php echo $this->get_field_id( 'username' ); ?>"><?php _e( 'Your about.me URL', 'jetpack' ); ?>
103
				:</label>
104
			<input id="<?php echo $this->get_field_id( 'username' ); ?>"
105
			       name="<?php echo $this->get_field_name( 'username' ); ?>" value="<?php echo esc_url( $username ); ?>"
106
			       style="width: 100%;" type="text"/>
107
		</p>
108
		<p>
109
			<label for="<?php echo $this->get_field_id( 'fontsize' ); ?>"><?php _e( 'Name', 'jetpack' ); ?>:</label>
110
			<select id="<?php echo $this->get_field_id( 'fontsize' ); ?>"
111
			        name="<?php echo $this->get_field_name( 'fontsize' ); ?>">
112
				<option
113
					value='x-large' <?php selected( $fontsize, 'x-large' ); ?>><?php _e( 'Display X-Large', 'jetpack' ) ?></option>
114
				<option
115
					value='large' <?php selected( $fontsize, 'large' ); ?>><?php _e( 'Display Large', 'jetpack' ) ?></option>
116
				<option
117
					value='medium' <?php selected( $fontsize, 'medium' ); ?>><?php _e( 'Display Medium', 'jetpack' ) ?></option>
118
				<option
119
					value='small' <?php selected( $fontsize, 'small' ); ?>><?php _e( 'Display Small', 'jetpack' ) ?></option>
120
				<option
121
					value='no-name' <?php selected( $fontsize, 'no-name' ); ?>><?php _e( "Don't Display Name", 'jetpack' ) ?></option>
122
			</select>
123
		</p>
124
		<p>
125
			<label for="<?php echo $this->get_field_id( 'photo' ); ?>"><?php _e( 'Photo', 'jetpack' ); ?>:
126
				<input type="checkbox" id="<?php echo $this->get_field_id( 'photo' ); ?>"
127
				       name="<?php echo $this->get_field_name( 'photo' ); ?>"
128
				       value="background" <?php checked( $photo, 'background' ); ?> />
129
			</label>
130
		</p>
131
		<p>
132
			<label for="<?php echo $this->get_field_id( 'headline' ); ?>"><?php _e( 'Headline', 'jetpack' ); ?>:
133
				<input type="checkbox" id="<?php echo $this->get_field_id( 'headline' ); ?>"
134
				       name="<?php echo $this->get_field_name( 'headline' ); ?>"
135
				       value="1" <?php checked( $headline, '1' ); ?> />
136
			</label>
137
		</p>
138
		<p>
139
			<label for="<?php echo $this->get_field_id( 'biography' ); ?>"><?php _e( 'Biography', 'jetpack' ); ?>:
140
				<input type="checkbox" id="<?php echo $this->get_field_id( 'biography' ); ?>"
141
				       name="<?php echo $this->get_field_name( 'biography' ); ?>"
142
				       value="1" <?php checked( $biography, '1' ); ?> />
143
			</label>
144
		</p>
145
		<p>
146
			<label for="<?php echo $this->get_field_id( 'apps' ); ?>"><?php _e( 'Apps', 'jetpack' ); ?>:
147
				<input type="checkbox" id="<?php echo $this->get_field_id( 'apps' ); ?>"
148
				       name="<?php echo $this->get_field_name( 'apps' ); ?>"
149
				       value="1" <?php checked( $apps, '1' ); ?> />
150
			</label>
151
		</p>
152
		<p>
153
			<input type="hidden" id="<?php echo $this->get_field_id( 'client_id' ); ?>"
154
			       name="<?php echo $this->get_field_name( 'client_id' ); ?>"
155
			       value="<?php echo esc_attr( $instance['client_id'] ); ?>">
156
			<input type="hidden" id="<?php echo $this->get_field_id( 'error' ); ?>"
157
			       name="<?php echo $this->get_field_name( 'error' ); ?>"
158
			       value="<?php echo esc_attr( $instance['error'] ); ?>">
159
			<input type="hidden" id="<?php echo $this->get_field_id( 'src_url' ); ?>"
160
			       name="<?php echo $this->get_field_name( 'src_url' ); ?>"
161
			       value="<?php echo esc_attr( $instance['src_url'] ); ?>">
162
		</p>
163
		<?php
164
	}
165
}
166
167
//register Aboutme_Widget widget
168
function aboutme_widget_init() {
169
	// [DEPRECATION]: Only register widget if active widget exists already
170
	$has_widget = is_active_widget( false, false, 'aboutme_widget', false );
171
	if ( false === $has_widget ) {
172
		return;
173
	}
174
175
	register_widget( 'Aboutme_Widget' );
176
}
177
178
add_action( 'widgets_init', 'aboutme_widget_init' );
179